]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/lengthcombo.C
Extracted from r14281
[lyx.git] / src / frontends / qt4 / lengthcombo.C
1 /**
2  * \file lengthcombo.C
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 Herbert Voß
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "lengthcombo.h"
15
16 #include "lengthcommon.h"
17
18
19 LengthCombo::LengthCombo(QWidget * parent, char * name)
20         : QComboBox(parent, name)
21 {
22         for (int i = 0; i < num_units; i++)
23                 insertItem(unit_name_gui[i]);
24
25         connect(this, SIGNAL(activated(int)),
26                 this, SLOT(has_activated(int)));
27 }
28
29 LengthCombo::LengthCombo(QWidget * parent)
30         : QComboBox(parent)
31 {
32         for (int i = 0; i < num_units; i++)
33                 insertItem(unit_name_gui[i]);
34
35         connect(this, SIGNAL(activated(int)),
36                 this, SLOT(has_activated(int)));
37 }
38
39 LyXLength::UNIT LengthCombo::currentLengthItem() const
40 {
41         return static_cast<LyXLength::UNIT>(currentItem());
42 }
43
44
45 void LengthCombo::has_activated(int)
46 {
47         // emit signal
48         selectionChanged(currentLengthItem());
49 }
50
51
52 void LengthCombo::setCurrentItem(LyXLength::UNIT unit)
53 {
54         QComboBox::setCurrentItem(int(unit));
55 }
56
57
58 void LengthCombo::setCurrentItem(int item)
59 {
60         QComboBox::setCurrentItem(item);
61 }
62
63
64 void LengthCombo::setEnabled(bool b)
65 {
66         QComboBox::setEnabled(b);
67 }
68
69
70 void LengthCombo::noPercents()
71 {
72         int num = QComboBox::count();
73         for (int i = 0; i < num; i++) {
74                 if (QComboBox::text(i).contains('%') > 0) {
75                         QComboBox::removeItem(i);
76                         i -= 1;
77                         num -= 1;
78                 }
79         }
80 }
81
82 #include "lengthcombo_moc.cpp"