]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QMinipage.C
Lots and lots of little trivial bits.
[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 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "debug.h"
18 #include "gettext.h"
19 #include "support/lstrings.h"
20 #include "LyXView.h"
21 #include "ControlMinipage.h"
22
23 #include "QMinipage.h"
24 #include "QMinipageDialog.h"
25 #include "Qt2BC.h"
26 #include "lengthcombo.h"
27  
28 #include <qpushbutton.h>
29 #include <qcombobox.h>
30 #include <qlineedit.h>
31
32 typedef Qt2CB<ControlMinipage, Qt2DB<QMinipageDialog> > base_class;
33
34 QMinipage::QMinipage()
35         : base_class(_("Minipage"))
36 {
37 }
38
39
40 void QMinipage::build_dialog()
41 {
42         dialog_.reset(new QMinipageDialog(this));
43
44         bc().setRestore(dialog_->restorePB);
45         bc().setOK(dialog_->okPB);
46         bc().setApply(dialog_->applyPB);
47         bc().setCancel(dialog_->closePB);
48
49         bc().addReadOnly(dialog_->widthED);
50         bc().addReadOnly(dialog_->unitsLC);
51         bc().addReadOnly(dialog_->valignCO);
52 }
53
54
55 void QMinipage::apply()
56 {
57         double value = strToDbl(dialog_->widthED->text().latin1());
58         LyXLength::UNIT unit = dialog_->unitsLC->currentLengthItem();
59         if (string(dialog_->widthED->text().latin1()).empty())
60                 unit = LyXLength::UNIT_NONE;
61
62         controller().params().pageWidth = LyXLength(value, unit);
63
64         switch (dialog_->valignCO->currentItem()) {
65         case 0:
66                 controller().params().pos = InsetMinipage::top;
67                 break;
68         case 1:
69                 controller().params().pos = InsetMinipage::center;
70                 break;
71         case 2:
72                 controller().params().pos = InsetMinipage::bottom;
73                 break;
74         }
75 }
76
77
78 namespace {
79         string const numtostr(double val) {
80                 string a(tostr(val));
81                 if (a == "0")
82                         a = "";
83                 return a;
84         }
85 } // namespace anon
86
87
88 void QMinipage::update_contents()
89 {
90         LyXLength len(controller().params().pageWidth);
91         dialog_->widthED->setText(numtostr(len.value()).c_str());
92         dialog_->unitsLC->setCurrentItem(len.unit());
93         lyxerr << "width " << numtostr(len.value()).c_str() << " units " << len.unit() << std::endl;
94
95         int item = 0;
96         switch (controller().params().pos) {
97                 case InsetMinipage::center:
98                         item = 1;
99                         break;
100                 case InsetMinipage::bottom:
101                         item = 2;
102                         break;
103         }
104         dialog_->valignCO->setCurrentItem(item);
105 }