]> git.lyx.org Git - lyx.git/blob - src/frontends/qt/GuiHyperlink.cpp
Master/Child: do not clean includeonly list while editing (part of #12470)
[lyx.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 #include "support/debug.h"
21
22 #if defined(LYX_MERGE_FILES) && !defined(Q_CC_MSVC)
23 // GCC couldn't find operator==
24 namespace lyx {
25         bool operator==(lyx::docstring const & d, char const * c);
26         namespace frontend {
27                 bool operator==(lyx::docstring const & d, char const * c)
28                   { return lyx::operator ==(d, c); }
29         } // namespace frontend
30 } // namespace lyx
31 #endif
32
33
34 namespace lyx {
35 namespace frontend {
36
37 GuiHyperlink::GuiHyperlink(QWidget * parent) : InsetParamsWidget(parent)
38 {
39         setupUi(this);
40
41         connect(targetED, SIGNAL(textChanged(const QString &)),
42                 this, SIGNAL(changed()));
43         connect(nameED, SIGNAL(textChanged(const QString &)),
44                 this, SIGNAL(changed()));
45         connect(literalCB, SIGNAL(clicked()),
46                 this, SIGNAL(changed()));
47         connect(webRB, SIGNAL(clicked()),
48                 this, SIGNAL(changed()));
49         connect(emailRB, SIGNAL(clicked()),
50                 this, SIGNAL(changed()));
51         connect(fileRB, SIGNAL(clicked()),
52                 this, SIGNAL(changed()));
53         connect(noneRB, SIGNAL(clicked()),
54                 this, SIGNAL(changed()));
55
56         setFocusProxy(targetED);
57 }
58
59
60 void GuiHyperlink::paramsToDialog(Inset const * inset)
61 {
62         InsetHyperlink const * hlink = static_cast<InsetHyperlink const *>(inset);
63         InsetCommandParams const & params = hlink->params();
64
65         targetED->setText(toqstr(params["target"]));
66         nameED->setText(toqstr(params["name"]));
67         literalCB->setChecked(params["literal"] == "true");
68         docstring const & type = params["type"];
69         if (type.empty())
70                 webRB->setChecked(true);
71         else if (type == "mailto:")
72                 emailRB->setChecked(true);
73         else if (type == "file:")
74                 fileRB->setChecked(true);
75         else if (type == "other")
76                 noneRB->setChecked(true);
77         else
78                 LYXERR0("Unknown hyperlink type: " << type);
79 }
80
81
82 bool GuiHyperlink::initialiseParams(std::string const & sdata)
83 {
84         InsetCommandParams params(insetCode());
85         if (!InsetCommand::string2params(sdata, params))
86                 return false;
87         targetED->setText(toqstr(params["target"]));
88         nameED->setText(toqstr(params["name"]));
89         literalCB->setChecked(params["literal"] == "true");
90         if (params["type"] == "mailto:")
91                 emailRB->setChecked(true);
92         else if (params["type"] == "file:")
93                 fileRB->setChecked(true);
94         else if (params["type"] == "other")
95                 noneRB->setChecked(true);
96         else
97                 webRB->setChecked(true);
98         return true;
99 }
100
101
102 docstring GuiHyperlink::dialogToParams() const
103 {
104         InsetCommandParams params(insetCode());
105
106         params["target"] = qstring_to_ucs4(targetED->text());
107         params["name"] = qstring_to_ucs4(nameED->text());
108         if (webRB->isChecked())
109                 params["type"] = from_utf8("");
110         else if (emailRB->isChecked())
111                 params["type"] = from_utf8("mailto:");
112         else if (fileRB->isChecked())
113                 params["type"] = from_utf8("file:");
114         else if (noneRB->isChecked())
115                 params["type"] = from_utf8("other");
116         params["literal"] = literalCB->isChecked()
117                         ? from_ascii("true") : from_ascii("false");
118         params.setCmdName("href");
119         return from_utf8(InsetHyperlink::params2string(params));
120 }
121
122
123 bool GuiHyperlink::checkWidgets(bool readonly) const
124 {
125         targetED->setReadOnly(readonly);
126         nameED->setReadOnly(readonly);
127         typeGB->setEnabled(!readonly);
128         if (!InsetParamsWidget::checkWidgets())
129                 return false;
130         return !targetED->text().isEmpty() || !nameED->text().isEmpty();
131 }
132
133
134 } // namespace frontend
135 } // namespace lyx
136
137
138 #include "moc_GuiHyperlink.cpp"