]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiLine.cpp
Revert a6e42e50791d.
[lyx.git] / src / frontends / qt4 / GuiLine.cpp
1 /**
2  * \file GuiLine.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  * \author Uwe Stöhr
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "GuiLine.h"
15
16 #include "LengthCombo.h"
17 #include "qt_helpers.h"
18 #include "Validator.h"
19
20 #include "FuncRequest.h"
21
22 #include "insets/InsetLine.h"
23
24 #include "support/debug.h"
25 #include "support/gettext.h"
26 #include "support/lstrings.h"
27
28 #include <QLineEdit>
29 #include <QPushButton>
30 #include <QValidator>
31
32 using namespace std;
33
34 namespace lyx {
35 namespace frontend {
36
37 GuiLine::GuiLine(QWidget * parent) : InsetParamsWidget(parent)
38 {
39         setupUi(this);
40
41         connect(OffsetLE, SIGNAL(textChanged(QString)),
42                 this, SIGNAL(changed()));
43         connect(OffsetUnitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
44                 this, SIGNAL(changed()));
45         connect(WidthLE, SIGNAL(textChanged(QString)),
46                 this, SIGNAL(changed()));
47         connect(WidthUnitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
48                 this, SIGNAL(changed()));
49         connect(HeightLE, SIGNAL(textChanged(QString)),
50                 this, SIGNAL(changed()));
51         connect(HeightUnitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
52                 this, SIGNAL(changed()));
53
54         // initialize the length validator
55         addCheckedWidget(OffsetLE, OffsetValueL);
56         addCheckedWidget(WidthLE, WidthValueL);
57         addCheckedWidget(HeightLE, HeightValueL);
58
59         OffsetLE->setValidator(unsignedGlueLengthValidator(OffsetLE));
60         WidthLE->setValidator(unsignedGlueLengthValidator(WidthLE));
61         HeightLE->setValidator(unsignedGlueLengthValidator(HeightLE));
62
63         OffsetLE->setText("0.5");
64         OffsetUnitCO->setCurrentItem(Length::EX);
65         WidthLE->setText("100");
66         WidthUnitCO->setCurrentItem(Length::PCW);
67         HeightLE->setText("1");
68         HeightUnitCO->setCurrentItem(Length::PT);
69         setFocusProxy(WidthLE);
70 }
71
72
73 docstring GuiLine::dialogToParams() const
74 {
75         InsetCommandParams params(insetCode());
76         params["offset"] = from_utf8(widgetsToLength(OffsetLE, OffsetUnitCO));
77         params["width"] = from_utf8(widgetsToLength(WidthLE, WidthUnitCO));
78         params["height"] = from_utf8(widgetsToLength(HeightLE, HeightUnitCO));
79         params.setCmdName("rule");
80         return from_ascii(InsetLine::params2string(params));
81 }
82
83
84 void GuiLine::paramsToDialog(Inset const * inset)
85 {
86         InsetLine const * line = static_cast<InsetLine const *>(inset);
87         InsetCommandParams const & params = line->params();
88         lengthToWidgets(OffsetLE,
89                         OffsetUnitCO,
90                         params["offset"],
91                         Length::defaultUnit());
92         lengthToWidgets(WidthLE,
93                         WidthUnitCO,
94                         params["width"],
95                         Length::defaultUnit());
96         lengthToWidgets(HeightLE,
97                         HeightUnitCO,
98                         params["height"],
99                         Length::defaultUnit());
100 }
101
102
103 bool GuiLine::checkWidgets() const
104 {
105         if (!InsetParamsWidget::checkWidgets())
106                 return false;
107         // FIXME: this should be handled in unsignedGlueLengthValidator!
108         if (WidthLE->text().startsWith('-'))
109                 return false;
110         // FIXME: this should be handled in unsignedGlueLengthValidator!
111         if (HeightLE->text().startsWith('-'))
112                 return false;
113         return true;
114 }
115
116 } // namespace frontend
117 } // namespace lyx
118
119
120 #include "moc_GuiLine.cpp"