]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiInfo.cpp
Properly track the lifetime of signals2::slots (#8261)
[lyx.git] / src / frontends / qt4 / GuiInfo.cpp
1 /**
2  * \file GuiInfo.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Abdelrazak Younes
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "GuiInfo.h"
14
15 #include "qt_helpers.h"
16
17 #include "Buffer.h"
18 #include "buffer_funcs.h"
19 #include "BufferParams.h"
20 #include "BufferView.h"
21 #include "Cursor.h"
22
23 #include "insets/InsetInfo.h"
24
25 #include "support/debug.h"
26 #include "support/gettext.h"
27 #include "support/lstrings.h"
28
29
30 using namespace std;
31 using namespace lyx::support;
32
33 namespace lyx {
34 namespace frontend {
35
36 /////////////////////////////////////////////////////////////////
37 //
38 // GuiInfo
39 //
40 /////////////////////////////////////////////////////////////////
41
42 char const * info_types[] =
43 { "unknown", "shortcut", "shortcuts", "lyxrc", "package", "textclass", "menu", "icon", "buffer", "lyxinfo", "" };
44
45 char const * info_types_gui[] =
46 { N_("unknown"), N_("shortcut"), N_("shortcuts"), N_("lyxrc"), N_("package"), N_("textclass"),
47   N_("menu"), N_("icon"), N_("buffer"), N_("lyxinfo"), ""};
48
49
50 GuiInfo::GuiInfo(QWidget * parent) : InsetParamsWidget(parent)
51 {
52         setupUi(this);
53
54         typeCO->blockSignals(true);
55         for (int n = 0; info_types[n][0]; ++n)
56                 typeCO->addItem(qt_(info_types_gui[n]));
57         typeCO->blockSignals(false);
58
59         connect(typeCO, SIGNAL(currentIndexChanged(int)), this, SIGNAL(changed()));
60         connect(nameLE, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
61 }
62
63
64 void GuiInfo::paramsToDialog(Inset const * inset)
65 {
66         InsetInfo const * ii = static_cast<InsetInfo const *>(inset);
67         QString const type = toqstr(ii->infoType());
68         QString const name = toqstr(ii->infoName());
69         typeCO->blockSignals(true);
70         nameLE->blockSignals(true);
71         int type_index = findToken(info_types, fromqstr(type));
72         typeCO->setCurrentIndex(type_index >= 0 ? type_index : 0);
73         // Without this test, 'math-insert' (name) will replace 'math-insert '
74         // in nameLE and effectively disallow the input of spaces after a LFUN.
75         if (nameLE->text().trimmed() != name)
76                 nameLE->setText(name);
77         typeCO->blockSignals(false);
78         nameLE->blockSignals(false);
79 }
80
81
82 docstring GuiInfo::dialogToParams() const
83 {
84         int type_index = typeCO->currentIndex();
85         QString type;
86         if (type_index != -1)
87                 type = info_types[type_index];
88         QString const name = nameLE->text();
89         return qstring_to_ucs4(type + ' ' + name);
90 }
91
92
93 bool GuiInfo::checkWidgets(bool readonly) const
94 {
95         nameLE->setReadOnly(readonly);
96         typeCO->setEnabled(!readonly);
97         if (!InsetParamsWidget::checkWidgets())
98                 return false;
99         return !nameLE->text().isEmpty();
100 }
101
102
103 } // namespace frontend
104 } // namespace lyx
105
106 #include "moc_GuiInfo.cpp"