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