]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiHyperlink.cpp
On Linux show in crash message box the backtrace
[lyx.git] / src / frontends / qt4 / GuiHyperlink.cpp
1 /**
2  * \file GuiHyperlink.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  * \author John Levon
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "GuiHyperlink.h"
15
16 #include "qt_helpers.h"
17
18 #include "insets/InsetHyperlink.h"
19
20 #if defined(LYX_MERGE_FILES) && !defined(Q_CC_MSVC)
21 // GCC couldn't find operator==
22 namespace lyx {
23         bool operator==(lyx::docstring const & d, char const * c);
24         namespace frontend {
25                 bool operator==(lyx::docstring const & d, char const * c)
26                   { return lyx::operator ==(d, c); }
27         }
28 }
29 #endif
30
31
32 namespace lyx {
33 namespace frontend {
34
35 GuiHyperlink::GuiHyperlink(QWidget * parent) : InsetParamsWidget(parent)
36 {
37         setupUi(this);
38
39         connect(targetED, SIGNAL(textChanged(const QString &)),
40                 this, SIGNAL(changed()));
41         connect(nameED, SIGNAL(textChanged(const QString &)),
42                 this, SIGNAL(changed()));
43         connect(webRB, SIGNAL(clicked()),
44                 this, SIGNAL(changed()));
45         connect(emailRB, SIGNAL(clicked()),
46                 this, SIGNAL(changed()));
47         connect(fileRB, SIGNAL(clicked()),
48                 this, SIGNAL(changed()));
49
50         setFocusProxy(targetED);
51 }
52
53
54 void GuiHyperlink::paramsToDialog(Inset const * inset)
55 {
56         InsetHyperlink const * hlink = static_cast<InsetHyperlink const *>(inset);
57         InsetCommandParams const & params = hlink->params();
58
59         targetED->setText(toqstr(params["target"]));
60         nameED->setText(toqstr(params["name"]));
61         docstring const & type = params["type"];
62         if (type.empty())
63                 webRB->setChecked(true);
64         else if (type == "mailto:")
65                 emailRB->setChecked(true);
66         else if (type == "file:")
67                 fileRB->setChecked(true);
68 }
69
70
71 bool GuiHyperlink::initialiseParams(std::string const & data)
72 {
73         InsetCommandParams params(insetCode());
74         if (!InsetCommand::string2params(data, params))
75                 return false;
76         targetED->setText(toqstr(params["target"]));
77         nameED->setText(toqstr(params["name"]));
78         if (params["type"] == from_utf8("mailto:"))
79                 emailRB->setChecked(true);
80         else if (params["type"] == from_utf8("file:"))
81                 fileRB->setChecked(true);
82         else
83                 webRB->setChecked(true);
84         return true;
85 }
86
87
88 docstring GuiHyperlink::dialogToParams() const
89 {
90         InsetCommandParams params(insetCode());
91
92         params["target"] = qstring_to_ucs4(targetED->text());
93         params["name"] = qstring_to_ucs4(nameED->text());
94         if (webRB->isChecked())
95                 params["type"] = from_utf8("");
96         else if (emailRB->isChecked())
97                 params["type"] = from_utf8("mailto:");
98         else if (fileRB->isChecked())
99                 params["type"] = from_utf8("file:");
100         params.setCmdName("href");
101         return from_utf8(InsetHyperlink::params2string(params));
102 }
103
104
105 bool GuiHyperlink::checkWidgets() const
106 {
107         if (!InsetParamsWidget::checkWidgets())
108                 return false;
109         return !targetED->text().isEmpty() || !nameED->text().isEmpty();
110 }
111
112
113 } // namespace frontend
114 } // namespace lyx
115
116
117 #include "moc_GuiHyperlink.cpp"