]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QMinipage.C
Get rid of the static_casts.
[lyx.git] / src / frontends / qt2 / QMinipage.C
1 /**
2  * \file QMinipage.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
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 "LyXView.h"
18 #include "ControlMinipage.h"
19
20 #include "QMinipage.h"
21 #include "QMinipageDialog.h"
22 #include "Qt2BC.h"
23 #include "lengthcombo.h"
24
25 #include <qpushbutton.h>
26 #include <qcombobox.h>
27 #include <qlineedit.h>
28
29 typedef QController<ControlMinipage, QView<QMinipageDialog> > base_class;
30
31
32 QMinipage::QMinipage(Dialog & parent)
33         : base_class(parent, _("LyX: Minipage Settings"))
34 {
35 }
36
37
38 void QMinipage::build_dialog()
39 {
40         dialog_.reset(new QMinipageDialog(this));
41
42         bcview().setRestore(dialog_->restorePB);
43         bcview().setOK(dialog_->okPB);
44         bcview().setApply(dialog_->applyPB);
45         bcview().setCancel(dialog_->closePB);
46
47         bcview().addReadOnly(dialog_->widthED);
48         bcview().addReadOnly(dialog_->unitsLC);
49         bcview().addReadOnly(dialog_->valignCO);
50 }
51
52
53 void QMinipage::apply()
54 {
55         double const value = strToDbl(fromqstr(dialog_->widthED->text()));
56         LyXLength::UNIT unit = dialog_->unitsLC->currentLengthItem();
57         if (dialog_->widthED->text().isEmpty())
58                 unit = LyXLength::UNIT_NONE;
59
60         InsetMinipage::Params & params = controller().params();
61
62         params.width = LyXLength(value, unit);
63
64         switch (dialog_->valignCO->currentItem()) {
65         case 0:
66                 params.pos = InsetMinipage::top;
67                 break;
68         case 1:
69                 params.pos = InsetMinipage::center;
70                 break;
71         case 2:
72                 params.pos = InsetMinipage::bottom;
73                 break;
74         }
75 }
76
77
78 namespace {
79
80 string const numtostr(double val)
81 {
82         string a(tostr(val));
83         if (a == "0")
84                 a.erase();
85         return a;
86 }
87
88 } // namespace anon
89
90
91 void QMinipage::update_contents()
92 {
93         InsetMinipage::Params const & params = controller().params();
94
95         LyXLength len(params.width);
96         dialog_->widthED->setText(toqstr(numtostr(len.value())));
97         dialog_->unitsLC->setCurrentItem(len.unit());
98
99         int item = 0;
100         switch (params.pos) {
101         case InsetMinipage::top:
102                 item = 0;
103                 break;
104         case InsetMinipage::center:
105                 item = 1;
106                 break;
107         case InsetMinipage::bottom:
108                 item = 2;
109                 break;
110         }
111         dialog_->valignCO->setCurrentItem(item);
112 }