]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QMinipage.C
namespace grfx -> lyx::graphics
[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 using namespace lyx::support;
30
31 typedef QController<ControlMinipage, QView<QMinipageDialog> > base_class;
32
33
34 QMinipage::QMinipage(Dialog & parent)
35         : base_class(parent, _("LyX: Minipage Settings"))
36 {
37 }
38
39
40 void QMinipage::build_dialog()
41 {
42         dialog_.reset(new QMinipageDialog(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 QMinipage::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         InsetMinipage::Params & params = controller().params();
63
64         params.width = LyXLength(value, unit);
65
66         switch (dialog_->valignCO->currentItem()) {
67         case 0:
68                 params.pos = InsetMinipage::top;
69                 break;
70         case 1:
71                 params.pos = InsetMinipage::center;
72                 break;
73         case 2:
74                 params.pos = InsetMinipage::bottom;
75                 break;
76         }
77 }
78
79
80 namespace {
81
82 string const numtostr(double val)
83 {
84         string a(tostr(val));
85         if (a == "0")
86                 a.erase();
87         return a;
88 }
89
90 } // namespace anon
91
92
93 void QMinipage::update_contents()
94 {
95         InsetMinipage::Params const & params = controller().params();
96
97         LyXLength len(params.width);
98         dialog_->widthED->setText(toqstr(numtostr(len.value())));
99         dialog_->unitsLC->setCurrentItem(len.unit());
100
101         int item = 0;
102         switch (params.pos) {
103         case InsetMinipage::top:
104                 item = 0;
105                 break;
106         case InsetMinipage::center:
107                 item = 1;
108                 break;
109         case InsetMinipage::bottom:
110                 item = 2;
111                 break;
112         }
113         dialog_->valignCO->setCurrentItem(item);
114 }