]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QMinipage.C
Resolve virtual function name clashes:
[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         LyXLength len(value, unit);
61  
62         controller().params().pageWidth = len.asString();
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.c_str());
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 }