]> git.lyx.org Git - features.git/blob - src/frontends/qt2/QWrap.C
0780f285c8844c650eec5f888a327e67f5badc81
[features.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 #include "debug.h"
14 #include "qt_helpers.h"
15 #include "support/tostr.h"
16 #include "support/lstrings.h"
17 #include "LyXView.h"
18 #include "ControlWrap.h"
19
20 #include "QWrap.h"
21 #include "QWrapDialog.h"
22 #include "Qt2BC.h"
23 #include "lengthcombo.h"
24
25 #include "insets/insetwrap.h"
26
27 #include <qpushbutton.h>
28 #include <qcombobox.h>
29 #include <qlineedit.h>
30
31
32 typedef QController<ControlWrap, QView<QWrapDialog> > base_class;
33
34
35 QWrap::QWrap(Dialog & parent)
36         : base_class(parent, _("LyX: Text Wrap Settings"))
37 {
38 }
39
40
41 void QWrap::build_dialog()
42 {
43         dialog_.reset(new QWrapDialog(this));
44
45         bcview().setRestore(dialog_->restorePB);
46         bcview().setOK(dialog_->okPB);
47         bcview().setApply(dialog_->applyPB);
48         bcview().setCancel(dialog_->closePB);
49
50         bcview().addReadOnly(dialog_->widthED);
51         bcview().addReadOnly(dialog_->unitsLC);
52         bcview().addReadOnly(dialog_->valignCO);
53 }
54
55
56 void QWrap::apply()
57 {
58         double const value = strToDbl(fromqstr(dialog_->widthED->text()));
59         LyXLength::UNIT unit = dialog_->unitsLC->currentLengthItem();
60         if (dialog_->widthED->text().isEmpty())
61                 unit = LyXLength::UNIT_NONE;
62
63         InsetWrapParams & params = controller().params();
64
65         params.width = 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         InsetWrapParams & params = controller().params();
99
100         LyXLength len(params.width);
101         dialog_->widthED->setText(toqstr(numtostr(len.value())));
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 }