]> git.lyx.org Git - features.git/blob - src/frontends/qt/GuiHyperlink.cpp
Fix broken Apple speller interface
[features.git] / src / frontends / qt / 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         } // namespace frontend
28 } // namespace lyx
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(literalCB, SIGNAL(clicked()),
44                 this, SIGNAL(changed()));
45         connect(webRB, SIGNAL(clicked()),
46                 this, SIGNAL(changed()));
47         connect(emailRB, SIGNAL(clicked()),
48                 this, SIGNAL(changed()));
49         connect(fileRB, SIGNAL(clicked()),
50                 this, SIGNAL(changed()));
51
52         setFocusProxy(targetED);
53 }
54
55
56 void GuiHyperlink::paramsToDialog(Inset const * inset)
57 {
58         InsetHyperlink const * hlink = static_cast<InsetHyperlink const *>(inset);
59         InsetCommandParams const & params = hlink->params();
60
61         targetED->setText(toqstr(params["target"]));
62         nameED->setText(toqstr(params["name"]));
63         literalCB->setChecked(params["literal"] == "true");
64         docstring const & type = params["type"];
65         if (type.empty())
66                 webRB->setChecked(true);
67         else if (type == "mailto:")
68                 emailRB->setChecked(true);
69         else if (type == "file:")
70                 fileRB->setChecked(true);
71 }
72
73
74 bool GuiHyperlink::initialiseParams(std::string const & sdata)
75 {
76         InsetCommandParams params(insetCode());
77         if (!InsetCommand::string2params(sdata, params))
78                 return false;
79         targetED->setText(toqstr(params["target"]));
80         nameED->setText(toqstr(params["name"]));
81         literalCB->setChecked(params["literal"] == "true");
82         if (params["type"] == from_utf8("mailto:"))
83                 emailRB->setChecked(true);
84         else if (params["type"] == from_utf8("file:"))
85                 fileRB->setChecked(true);
86         else
87                 webRB->setChecked(true);
88         return true;
89 }
90
91
92 docstring GuiHyperlink::dialogToParams() const
93 {
94         InsetCommandParams params(insetCode());
95
96         params["target"] = qstring_to_ucs4(targetED->text());
97         params["name"] = qstring_to_ucs4(nameED->text());
98         if (webRB->isChecked())
99                 params["type"] = from_utf8("");
100         else if (emailRB->isChecked())
101                 params["type"] = from_utf8("mailto:");
102         else if (fileRB->isChecked())
103                 params["type"] = from_utf8("file:");
104         params["literal"] = literalCB->isChecked()
105                         ? from_ascii("true") : from_ascii("false");
106         params.setCmdName("href");
107         return from_utf8(InsetHyperlink::params2string(params));
108 }
109
110
111 bool GuiHyperlink::checkWidgets(bool readonly) const
112 {
113         targetED->setReadOnly(readonly);
114         nameED->setReadOnly(readonly);
115         typeGB->setEnabled(!readonly);
116         if (!InsetParamsWidget::checkWidgets())
117                 return false;
118         return !targetED->text().isEmpty() || !nameED->text().isEmpty();
119 }
120
121
122 } // namespace frontend
123 } // namespace lyx
124
125
126 #include "moc_GuiHyperlink.cpp"