]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QMinipage.C
add minipage dialog
[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 <qradiobutton.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 typedef Qt2CB<ControlMinipage, Qt2DB<QMinipageDialog> > base_class;
30
31 QMinipage::QMinipage(ControlMinipage & c)
32         : base_class(c, _("Minipage"))
33 {
34 }
35
36
37 void QMinipage::build_dialog()
38 {
39         dialog_.reset(new QMinipageDialog(this));
40
41         bc().setRestore(dialog_->restorePB);
42         bc().setOK(dialog_->okPB);
43         bc().setApply(dialog_->applyPB);
44         bc().setCancel(dialog_->closePB);
45
46         bc().addReadOnly(dialog_->widthED);
47         bc().addReadOnly(dialog_->unitsLC);
48         bc().addReadOnly(dialog_->topRB); 
49         bc().addReadOnly(dialog_->bottomRB); 
50         bc().addReadOnly(dialog_->middleRB); 
51 }
52
53
54 void QMinipage::apply()
55 {
56         double value = strToDbl(dialog_->widthED->text().latin1());
57         LyXLength::UNIT unit = dialog_->unitsLC->currentLengthItem();
58         if (string(dialog_->widthED->text().latin1()).empty())
59                 unit = LyXLength::UNIT_NONE;
60
61         LyXLength len(value, unit);
62  
63         controller().params().width = len.asString();
64
65         if (dialog_->topRB->isChecked())
66                 controller().params().pos = InsetMinipage::top;
67         else if (dialog_->middleRB->isChecked())
68                 controller().params().pos = InsetMinipage::center;
69         else
70                 controller().params().pos = InsetMinipage::bottom;
71 }
72
73  
74 namespace {
75         string const numtostr(double val) {
76                 string a(tostr(val));
77                 if (a == "0")
78                         a = "";
79                 return a;
80         }
81 } // namespace anon
82  
83  
84 void QMinipage::update_contents()
85 {
86         LyXLength len(controller().params().width.c_str());
87         dialog_->widthED->setText(numtostr(len.value()).c_str());
88         dialog_->unitsLC->setCurrentItem(len.unit());
89  
90         QRadioButton * button = dialog_->topRB;
91  
92         switch (controller().params().pos) {
93                 case InsetMinipage::center:
94                         button = dialog_->middleRB; 
95                         break;
96                 case InsetMinipage::bottom:
97                         button = dialog_->bottomRB;
98                         break;
99         }
100         button->setChecked(true);
101 }