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 (QString(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(hasActivated(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::hasActivated(int)
51 selectionChanged(currentLengthItem());
55 void LengthCombo::setCurrentItem(lyx::Length::UNIT unit)
57 setCurrentItem(lyx::toqstr(lyx::stringFromUnit(unit)));
61 void LengthCombo::setCurrentItem(QString const item)
63 int num = QComboBox::count();
64 for (int i = 0; i < num; i++) {
65 if (QComboBox::itemData(i).toString() == item) {
66 QComboBox::setCurrentIndex(i);
73 void LengthCombo::setCurrentItem(int item)
75 QComboBox::setCurrentIndex(item);
79 void LengthCombo::setEnabled(bool b)
81 QComboBox::setEnabled(b);
85 void LengthCombo::noPercents()
87 int num = QComboBox::count();
88 for (int i = 0; i < num; i++) {
89 if (QComboBox::itemData(i).toString().contains('%')) {
90 QComboBox::removeItem(i);
98 void LengthCombo::removeUnit(lyx::Length::UNIT unit)
100 QString const val = lyx::toqstr(lyx::stringFromUnit(unit));
101 int num = QComboBox::count();
102 for (int i = 0; i < num; i++) {
103 if (QComboBox::itemData(i).toString() == val) {
104 QComboBox::removeItem(i);
111 void LengthCombo::addUnit(lyx::Length::UNIT unit)
113 QString const val = lyx::toqstr(lyx::stringFromUnit(unit));
114 int num = QComboBox::count();
115 for (int i = 0; i < num; i++) {
116 if (QComboBox::itemData(i).toString() == val) {
117 // already there, nothing to do
121 insertItem(int(unit), lyx::qt_(lyx::unit_name_gui[int(unit)]),
122 lyx::toqstr(lyx::unit_name[int(unit)]));
126 #include "moc_LengthCombo.cpp"