2 * \file LengthCombo.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Jürgen Spitzmüller
10 * Full author contact details are available in file CREDITS.
15 #include "support/qstring_helpers.h"
17 #include "LengthCombo.h"
19 #include "qt_helpers.h"
24 LengthCombo::LengthCombo(QWidget * parent)
27 for (int i = 0; i < lyx::num_units; i++) {
28 // mu does not make sense usually
29 // so it must be added manually, if needed
30 if (lyx::unit_name[i] == "mu")
32 QComboBox::addItem(lyx::qt_(lyx::unit_name_gui[i]),
33 lyx::toqstr(lyx::unit_name[i]));
36 connect(this, SIGNAL(activated(int)),
37 this, SLOT(has_activated(int)));
41 lyx::Length::UNIT LengthCombo::currentLengthItem() const
43 QString const val = itemData(currentIndex()).toString();
44 return lyx::unitFromString(lyx::fromqstr(val));
48 void LengthCombo::has_activated(int)
51 selectionChanged(currentLengthItem());
55 void LengthCombo::setCurrentItem(lyx::Length::UNIT unit)
57 QString const val = lyx::toqstr(lyx::stringFromUnit(unit));
58 int num = QComboBox::count();
59 for (int i = 0; i < num; i++) {
60 if (QComboBox::itemData(i).toString() == val) {
61 QComboBox::setCurrentIndex(i);
68 void LengthCombo::setCurrentItem(int item)
70 QComboBox::setCurrentIndex(item);
74 void LengthCombo::setEnabled(bool b)
76 QComboBox::setEnabled(b);
80 void LengthCombo::noPercents()
82 int num = QComboBox::count();
83 for (int i = 0; i < num; i++) {
84 if (QComboBox::itemData(i).toString().contains('%')) {
85 QComboBox::removeItem(i);
93 void LengthCombo::removeItem(lyx::Length::UNIT unit)
95 QString const val = lyx::toqstr(lyx::stringFromUnit(unit));
96 int num = QComboBox::count();
97 for (int i = 0; i < num; i++) {
98 if (QComboBox::itemData(i).toString() == val) {
99 QComboBox::removeItem(i);
106 void LengthCombo::removeItem(int item)
108 QComboBox::removeItem(item);
112 void LengthCombo::addItem(lyx::Length::UNIT unit)
114 QString const val = lyx::toqstr(lyx::stringFromUnit(unit));
115 int num = QComboBox::count();
116 for (int i = 0; i < num; i++) {
117 if (QComboBox::itemData(i).toString() == val) {
118 // already there, nothing to do
122 insertItem(int(unit), lyx::qt_(lyx::unit_name_gui[int(unit)]),
123 lyx::toqstr(lyx::unit_name[int(unit)]));
127 void LengthCombo::addItem(QString const item)
129 QComboBox::addItem(item);
132 #include "moc_LengthCombo.cpp"