]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiLine.cpp
GuiLine.cpp: set default values
[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         OffsetLE->setText("0.5");
63         OffsetUnitCO->setCurrentItem(Length::EX);
64         WidthLE->setText("100");
65         WidthUnitCO->setCurrentItem(Length::PCW);
66         HeightLE->setText("1");
67         HeightUnitCO->setCurrentItem(Length::PT);
68         setFocusProxy(WidthLE);
69 }
70
71
72 docstring GuiLine::dialogToParams() const
73 {
74         InsetCommandParams params(insetCode());
75         params["offset"] = from_utf8(widgetsToLength(OffsetLE, OffsetUnitCO));;
76         params["width"] = from_utf8(widgetsToLength(WidthLE, WidthUnitCO));
77         params["height"] = from_utf8(widgetsToLength(HeightLE, HeightUnitCO));
78         params.setCmdName("rule");
79         return from_ascii(InsetLine::params2string("line", params));
80 }
81
82
83 void GuiLine::paramsToDialog(Inset const * inset)
84 {
85         InsetLine const * line = static_cast<InsetLine const *>(inset);
86         InsetCommandParams const & params = line->params();
87         lengthToWidgets(OffsetLE,
88                         OffsetUnitCO,
89                         params["offset"],
90                         Length::defaultUnit());
91         lengthToWidgets(WidthLE,
92                         WidthUnitCO,
93                         params["width"],
94                         Length::defaultUnit());
95         lengthToWidgets(HeightLE,
96                         HeightUnitCO,
97                         params["height"],
98                         Length::defaultUnit());
99 }
100
101
102 bool GuiLine::checkWidgets() const
103 {
104         if (!InsetParamsWidget::checkWidgets())
105                 return false;
106         // FIXME: this should be handled in unsignedGlueLengthValidator!
107         if (WidthLE->text().startsWith('-'))
108                 return false;
109         // FIXME: this should be handled in unsignedGlueLengthValidator!
110         if (HeightLE->text().startsWith('-'))
111                 return false;
112         return true;
113 }
114
115 } // namespace frontend
116 } // namespace lyx
117
118
119 #include "moc_GuiLine.cpp"