]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QWrap.C
enable Font cache only for MacOSX and inline width() for other platform.
[lyx.git] / src / frontends / qt4 / 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 Jürgen Spitzmüller
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "QWrap.h"
14 #include "QWrapDialog.h"
15 #include "Qt2BC.h"
16
17 #include "lengthcombo.h"
18 #include "qt_helpers.h"
19
20 #include "controllers/ControlWrap.h"
21
22 #include "insets/insetwrap.h"
23
24 #include "support/convert.h"
25 #include "support/lstrings.h"
26
27 #include <QLineEdit>
28 #include <QPushButton>
29
30
31 using std::string;
32
33 namespace lyx {
34 namespace frontend {
35
36 typedef QController<ControlWrap, QView<QWrapDialog> > base_class;
37
38 QWrap::QWrap(Dialog & parent)
39         : base_class(parent, lyx::to_utf8(_("Text Wrap Settings")))
40 {
41 }
42
43
44 void QWrap::build_dialog()
45 {
46         dialog_.reset(new QWrapDialog(this));
47
48         bcview().setRestore(dialog_->restorePB);
49         bcview().setOK(dialog_->okPB);
50         bcview().setApply(dialog_->applyPB);
51         bcview().setCancel(dialog_->closePB);
52
53         bcview().addReadOnly(dialog_->widthED);
54         bcview().addReadOnly(dialog_->unitsLC);
55         bcview().addReadOnly(dialog_->valignCO);
56 }
57
58
59 void QWrap::apply()
60 {
61         double const value = convert<double>(fromqstr(dialog_->widthED->text()));
62         LyXLength::UNIT unit = dialog_->unitsLC->currentLengthItem();
63         if (dialog_->widthED->text().isEmpty())
64                 unit = LyXLength::UNIT_NONE;
65
66         InsetWrapParams & params = controller().params();
67
68         params.width = LyXLength(value, unit);
69
70         switch (dialog_->valignCO->currentIndex()) {
71         case 0:
72                 params.placement.erase();
73                 break;
74         case 1:
75                 params.placement = "l";
76                 break;
77         case 2:
78                 params.placement = "r";
79                 break;
80         case 3:
81                 params.placement = "p";
82                 break;
83         }
84 }
85
86
87 namespace {
88
89 string const numtostr(double val) {
90         string a(convert<string>(val));
91 #ifdef WITH_WARNINGS
92 #warning Will this test ever trigger? (Lgb)
93 #endif
94         if (a == "0")
95                 a.erase();
96         return a;
97 }
98
99 } // namespace anon
100
101
102 void QWrap::update_contents()
103 {
104         InsetWrapParams & params = controller().params();
105
106         LyXLength len(params.width);
107         dialog_->widthED->setText(toqstr(numtostr(len.value())));
108         dialog_->unitsLC->setCurrentItem(len.unit());
109
110         int item = 0;
111         if (params.placement == "l")
112                 item = 1;
113         else if (params.placement == "r")
114                 item = 2;
115         else if (params.placement == "p")
116                 item = 3;
117
118         dialog_->valignCO->setCurrentIndex(item);
119 }
120
121 } // namespace frontend
122 } // namespace lyx