3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
15 #include "LengthCombo.h"
16 #include "qt_helpers.h"
17 #include "Validator.h"
19 #include "FuncRequest.h"
21 #include "insets/InsetLine.h"
23 #include "support/debug.h"
24 #include "support/gettext.h"
25 #include "support/lstrings.h"
28 #include <QPushButton>
36 GuiLine::GuiLine(QWidget * parent) : InsetParamsWidget(parent)
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()));
53 // initialize the length validator
54 addCheckedWidget(OffsetLE, OffsetValueL);
55 addCheckedWidget(WidthLE, WidthValueL);
56 addCheckedWidget(HeightLE, HeightValueL);
58 OffsetLE->setValidator(unsignedGlueLengthValidator(OffsetLE));
59 WidthLE->setValidator(unsignedGlueLengthValidator(WidthLE));
60 HeightLE->setValidator(unsignedGlueLengthValidator(HeightLE));
64 docstring GuiLine::dialogToParams() const
66 docstring offset = from_utf8(widgetsToLength(OffsetLE, OffsetUnitCO));
67 InsetCommandParams params(insetCode());
68 params["offset"] = offset;
70 // negative widths are senseless
71 string width_str = fromqstr(WidthLE->text());
72 if (width_str[0] == '-')
74 WidthLE->setText(toqstr(width_str));
75 docstring width = from_utf8(widgetsToLength(WidthLE, WidthUnitCO));
76 params["width"] = width;
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;
86 params.setCmdName("rule");
87 return from_ascii(InsetLine::params2string("line", params));
91 void GuiLine::paramsToDialog(Inset const * inset)
93 InsetLine const * line = static_cast<InsetLine const *>(inset);
94 InsetCommandParams const & params = line->params();
95 lengthToWidgets(OffsetLE,
98 Length::defaultUnit());
99 lengthToWidgets(WidthLE,
102 Length::defaultUnit());
103 lengthToWidgets(HeightLE,
106 Length::defaultUnit());
110 bool GuiLine::checkWidgets() const
112 if (!InsetParamsWidget::checkWidgets())
114 // FIXME: Is there something else to check?
115 // Transfer some code from dialogToParams()?
119 } // namespace frontend
123 #include "moc_GuiLine.cpp"