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