]> git.lyx.org Git - features.git/blob - src/frontends/qt2/QWrap.C
Remove all unnecessary #includes from header files.
[features.git] / src / frontends / qt2 / QWrap.C
1 /**
2  * \file QWrap.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Jürgen Spitzmüller
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "qt_helpers.h"
14 #include "support/tostr.h"
15 #include "support/lstrings.h"
16 #include "ControlWrap.h"
17
18 #include "QWrap.h"
19 #include "QWrapDialog.h"
20 #include "Qt2BC.h"
21 #include "lengthcombo.h"
22
23 #include "insets/insetwrap.h"
24
25 #include <qpushbutton.h>
26 #include <qlineedit.h>
27
28 using namespace lyx::support;
29
30 typedef QController<ControlWrap, QView<QWrapDialog> > base_class;
31
32
33 QWrap::QWrap(Dialog & parent)
34         : base_class(parent, _("LyX: Text Wrap Settings"))
35 {
36 }
37
38
39 void QWrap::build_dialog()
40 {
41         dialog_.reset(new QWrapDialog(this));
42
43         bcview().setRestore(dialog_->restorePB);
44         bcview().setOK(dialog_->okPB);
45         bcview().setApply(dialog_->applyPB);
46         bcview().setCancel(dialog_->closePB);
47
48         bcview().addReadOnly(dialog_->widthED);
49         bcview().addReadOnly(dialog_->unitsLC);
50         bcview().addReadOnly(dialog_->valignCO);
51 }
52
53
54 void QWrap::apply()
55 {
56         double const value = strToDbl(fromqstr(dialog_->widthED->text()));
57         LyXLength::UNIT unit = dialog_->unitsLC->currentLengthItem();
58         if (dialog_->widthED->text().isEmpty())
59                 unit = LyXLength::UNIT_NONE;
60
61         InsetWrapParams & params = controller().params();
62
63         params.width = LyXLength(value, unit);
64
65         switch (dialog_->valignCO->currentItem()) {
66         case 0:
67                 params.placement.erase();
68                 break;
69         case 1:
70                 params.placement = "l";
71                 break;
72         case 2:
73                 params.placement = "r";
74                 break;
75         case 3:
76                 params.placement = "p";
77                 break;
78         }
79 }
80
81
82 namespace {
83
84 string const numtostr(double val) {
85         string a(tostr(val));
86         if (a == "0")
87                 a.erase();
88         return a;
89 }
90
91 } // namespace anon
92
93
94 void QWrap::update_contents()
95 {
96         InsetWrapParams & params = controller().params();
97
98         LyXLength len(params.width);
99         dialog_->widthED->setText(toqstr(numtostr(len.value())));
100         dialog_->unitsLC->setCurrentItem(len.unit());
101
102         int item = 0;
103         if (params.placement == "l")
104                 item = 1;
105         else if (params.placement == "r")
106                 item = 2;
107         else if (params.placement == "p")
108                 item = 3;
109
110         dialog_->valignCO->setCurrentItem(item);
111 }