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