]> git.lyx.org Git - lyx.git/blob - src/frontends/qt/LengthCombo.cpp
Do not forceLTR in InsetHyperlink (#12044)
[lyx.git] / src / frontends / qt / LengthCombo.cpp
1 /**
2  * \file LengthCombo.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  * \author Jürgen Spitzmüller
8  * \author Herbert Voß
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "LengthCombo.h"
16
17 #include "support/qstring_helpers.h"
18
19 #include "qt_helpers.h"
20
21 #include <string>
22
23
24 namespace lyx {
25 namespace frontend {
26
27 LengthCombo::LengthCombo(QWidget * parent)
28         : QComboBox(parent)
29 {
30         for (int i = 0; i < lyx::num_units; i++) {
31                 // mu does not make sense usually
32                 // so it must be added manually, if needed
33                 if (QLatin1String(lyx::unit_name[i]) == "mu")
34                         continue;
35                 QComboBox::addItem(lyx::qt_(lyx::unit_name_gui[i]),
36                         lyx::toqstr(lyx::unit_name[i]));
37         }
38
39         connect(this, SIGNAL(activated(int)),
40                 this, SLOT(hasActivated(int)));
41 }
42
43
44 lyx::Length::UNIT LengthCombo::currentLengthItem() const
45 {
46         QString const val = itemData(currentIndex()).toString();
47         return lyx::unitFromString(lyx::fromqstr(val));
48 }
49
50
51 void LengthCombo::hasActivated(int)
52 {
53   // emit signal
54         selectionChanged(currentLengthItem());
55 }
56
57
58 void LengthCombo::setCurrentItem(lyx::Length::UNIT unit)
59 {
60         setCurrentItem(lyx::toqstr(lyx::stringFromUnit(unit)));
61 }
62
63
64 void LengthCombo::setCurrentItem(QString const & item)
65 {
66         int num = QComboBox::count();
67         for (int i = 0; i < num; i++) {
68                 if (QComboBox::itemData(i).toString() == item) {
69                         QComboBox::setCurrentIndex(i);
70                         break;
71                 }
72         }
73 }
74
75
76 void LengthCombo::setCurrentItem(int item)
77 {
78         QComboBox::setCurrentIndex(item);
79 }
80
81
82 void LengthCombo::setEnabled(bool b)
83 {
84         QComboBox::setEnabled(b);
85 }
86
87
88 void LengthCombo::noPercents()
89 {
90         int num = QComboBox::count();
91         for (int i = 0; i < num; i++) {
92                 if (QComboBox::itemData(i).toString().contains('%')) {
93                         QComboBox::removeItem(i);
94                         --i;
95                         --num;
96                 }
97         }
98 }
99
100
101 void LengthCombo::removeFontDependent()
102 {
103         removeUnit(Length::EM);
104         removeUnit(Length::EX);
105         removeUnit(Length::MU);
106 }
107
108
109 void LengthCombo::removeUnit(lyx::Length::UNIT unit)
110 {
111         QString const val = lyx::toqstr(lyx::stringFromUnit(unit));
112         int num = QComboBox::count();
113         for (int i = 0; i < num; i++) {
114                 if (QComboBox::itemData(i).toString() == val) {
115                         QComboBox::removeItem(i);
116                         break;
117                 }
118         }
119 }
120
121
122 void LengthCombo::addUnit(lyx::Length::UNIT unit)
123 {
124         QString const val = lyx::toqstr(lyx::stringFromUnit(unit));
125         int num = QComboBox::count();
126         for (int i = 0; i < num; i++) {
127                 if (QComboBox::itemData(i).toString() == val) {
128                         // already there, nothing to do
129                         return;
130                 }
131         }
132         insertItem(int(unit), lyx::qt_(lyx::unit_name_gui[int(unit)]),
133                    lyx::toqstr(lyx::unit_name[int(unit)]));
134 }
135
136 } // namespace frontend
137 } // namespace lyx
138
139 #include "moc_LengthCombo.cpp"