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