]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QWrap.C
Some string(widget->text()) fixes. Weirdness
[lyx.git] / src / frontends / qt2 / QWrap.C
1 /**
2  * \file QWrap.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Juergen Spitzmueller
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 "ControlWrap.h"
22
23 #include "QWrap.h"
24 #include "QWrapDialog.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<ControlWrap, Qt2DB<QWrapDialog> > base_class;
33
34
35 QWrap::QWrap()
36         : base_class(_("Wrap Options"))
37 {
38 }
39
40
41 void QWrap::build_dialog()
42 {
43         dialog_.reset(new QWrapDialog(this));
44
45         bc().setRestore(dialog_->restorePB);
46         bc().setOK(dialog_->okPB);
47         bc().setApply(dialog_->applyPB);
48         bc().setCancel(dialog_->closePB);
49
50         bc().addReadOnly(dialog_->widthED);
51         bc().addReadOnly(dialog_->unitsLC);
52         bc().addReadOnly(dialog_->valignCO);
53 }
54
55
56 void QWrap::apply()
57 {
58         double const value = strToDbl(dialog_->widthED->text().latin1());
59         LyXLength::UNIT unit = dialog_->unitsLC->currentLengthItem();
60         if (string(dialog_->widthED->text().latin1()).empty())
61                 unit = LyXLength::UNIT_NONE;
62
63         WrapParams & params = controller().params();
64
65         params.pageWidth = LyXLength(value, unit);
66
67         switch (dialog_->valignCO->currentItem()) {
68         case 0:
69                 params.placement.erase();
70                 break;
71         case 1:
72                 params.placement = "l";
73                 break;
74         case 2:
75                 params.placement = "r";
76                 break;
77         case 3:
78                 params.placement = "p";
79                 break;
80         }
81 }
82
83
84 namespace {
85
86 string const numtostr(double val) {
87         string a(tostr(val));
88         if (a == "0")
89                 a.erase();
90         return a;
91 }
92
93 } // namespace anon
94
95
96 void QWrap::update_contents()
97 {
98         WrapParams & params = controller().params();
99
100         LyXLength len(params.pageWidth);
101         dialog_->widthED->setText(numtostr(len.value()).c_str());
102         dialog_->unitsLC->setCurrentItem(len.unit());
103
104         int item = 0;
105         if (params.placement == "l")
106                 item = 1;
107         else if (params.placement == "r")
108                 item = 2;
109         else if (params.placement == "p")
110                 item = 3;
111
112         dialog_->valignCO->setCurrentItem(item);
113 }