]> git.lyx.org Git - features.git/blob - src/frontends/qt2/floatplacement.C
3cd0245bc4ea2c4100e9a5b5ff46755cdc236565
[features.git] / src / frontends / qt2 / floatplacement.C
1 /**
2  * \file floatplacement.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Edwin Leuven
7  * \author John Levon
8  *
9  * Full author contact details are available in file CREDITS
10  */
11
12 #include <config.h>
13
14 #include "floatplacement.h"
15 #include "qt_helpers.h"
16
17 #include "insets/insetfloat.h"
18 #include "support/lstrings.h"
19
20 #include <qcheckbox.h>
21 #include <qlayout.h>
22 #include <qgroupbox.h>
23
24 // FIXME: set disabled doesn't work properly
25
26 FloatPlacement::FloatPlacement(QWidget * parent, char * name)
27         : QWidget(parent, name)
28 {
29         QHBoxLayout * toplayout = new QHBoxLayout(this, 11, 6);
30         layout = new QVBoxLayout(0, 0, 6);
31         QGroupBox * options = new QGroupBox(qt_("Advanced Placement Options"), this);
32
33         defaultsCB = new QCheckBox(qt_("Use &default placement"), this);
34         topCB = new QCheckBox(qt_("&Top of page"), options);
35         bottomCB = new QCheckBox(qt_("&Bottom of page"), options);
36         pageCB = new QCheckBox(qt_("&Page of floats"), options);
37         herepossiblyCB = new QCheckBox(qt_("&Here if possible"), options);
38         heredefinitelyCB = new QCheckBox(qt_("Here definitely"), options);
39         ignoreCB = new QCheckBox(qt_("&Ignore LaTeX rules"), options);
40         spanCB = 0;
41
42         layout->addWidget(defaultsCB);
43
44         QVBoxLayout * optlay = new QVBoxLayout(options, 10, 6);
45         optlay->addSpacing(6);
46         optlay->addWidget(topCB);
47         optlay->addWidget(bottomCB);
48         optlay->addWidget(pageCB);
49         optlay->addWidget(herepossiblyCB);
50         optlay->addWidget(heredefinitelyCB);
51         optlay->addWidget(ignoreCB);
52
53         layout->addWidget(options);
54
55         toplayout->addLayout(layout);
56
57         connect(defaultsCB, SIGNAL(toggled(bool)), options, SLOT(setDisabled(bool)));
58         connect(defaultsCB, SIGNAL(toggled(bool)), ignoreCB, SLOT(setDisabled(bool)));
59         connect(defaultsCB, SIGNAL(toggled(bool)), pageCB, SLOT(setDisabled(bool)));
60         connect(defaultsCB, SIGNAL(toggled(bool)), heredefinitelyCB, SLOT(setDisabled(bool)));
61         connect(defaultsCB, SIGNAL(toggled(bool)), herepossiblyCB, SLOT(setDisabled(bool)));
62         connect(defaultsCB, SIGNAL(toggled(bool)), bottomCB, SLOT(setDisabled(bool)));
63         connect(defaultsCB, SIGNAL(toggled(bool)), topCB, SLOT(setDisabled(bool)));
64
65         connect(heredefinitelyCB, SIGNAL(clicked()), this, SLOT(heredefinitelyClicked()));
66         connect(topCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
67         connect(bottomCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
68         connect(pageCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
69         connect(herepossiblyCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
70         connect(defaultsCB, SIGNAL(clicked()), this, SLOT(tbhpClicked()));
71
72         connect(defaultsCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
73         connect(ignoreCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
74         connect(pageCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
75         connect(heredefinitelyCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
76         connect(herepossiblyCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
77         connect(bottomCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
78         connect(topCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
79 }
80
81
82 void FloatPlacement::useWide()
83 {
84         spanCB = new QCheckBox(qt_("&Span columns"), this);
85         layout->addWidget(spanCB);
86         setTabOrder(ignoreCB, spanCB);
87         connect(spanCB, SIGNAL(clicked()), this, SLOT(spanClicked()));
88         connect(spanCB, SIGNAL(toggled(bool)), this, SLOT(changedSlot()));
89 }
90
91
92 void FloatPlacement::changedSlot()
93 {
94         emit changed();
95 }
96
97
98 void FloatPlacement::set(string const & placement)
99 {
100         bool def_placement = false;
101         bool top = false;
102         bool bottom = false;
103         bool page = false;
104         bool here = false;
105         bool force = false;
106         bool here_definitely = false;
107
108         if (placement.empty()) {
109                 def_placement = true;
110         } else if (contains(placement, "H")) {
111                 here_definitely = true;
112         } else {
113                 if (contains(placement, "!")) {
114                         force = true;
115                 }
116                 if (contains(placement, "t")) {
117                         top = true;
118                 }
119                 if (contains(placement, "b")) {
120                         bottom = true;
121                 }
122                 if (contains(placement, "p")) {
123                         page = true;
124                 }
125                 if (contains(placement, "h")) {
126                         here = true;
127                 }
128         }
129
130         defaultsCB->setChecked(def_placement);
131         topCB->setChecked(top);
132         bottomCB->setChecked(bottom);
133         pageCB->setChecked(page);
134         herepossiblyCB->setChecked(here);
135         ignoreCB->setChecked(force);
136         ignoreCB->setEnabled(top || bottom || page || here);
137         heredefinitelyCB->setChecked(here_definitely);
138 }
139
140
141 void FloatPlacement::set(InsetFloatParams const & params)
142 {
143         set(params.placement);
144
145         if (params.wide) {
146                 herepossiblyCB->setChecked(false);
147                 bottomCB->setChecked(false);
148         }
149
150         spanCB->setChecked(params.wide);
151 }
152
153
154 string const FloatPlacement::get(bool & wide) const
155 {
156         wide = spanCB->isChecked();
157
158         return get();
159 }
160
161
162 string const FloatPlacement::get() const
163 {
164         string placement;
165
166         if (defaultsCB->isChecked())
167                 return placement;
168
169         if (heredefinitelyCB->isChecked()) {
170                 placement += 'H';
171         } else {
172                 if (ignoreCB->isChecked()) {
173                         placement += '!';
174                 }
175                 if (topCB->isChecked()) {
176                         placement += 't';
177                 }
178                 if (bottomCB->isChecked()) {
179                         placement += 'b';
180                 }
181                 if (pageCB->isChecked()) {
182                         placement += 'p';
183                 }
184                 if (herepossiblyCB->isChecked()) {
185                         placement += 'h';
186                 }
187         }
188         return placement;
189 }
190
191
192 void FloatPlacement::tbhpClicked()
193 {
194         heredefinitelyCB->setChecked(false);
195         bool allow(topCB->isChecked());
196         allow |= bottomCB->isChecked();
197         allow |= pageCB->isChecked();
198         allow |= herepossiblyCB->isChecked();
199         ignoreCB->setEnabled(allow);
200 }
201
202
203 void FloatPlacement::heredefinitelyClicked()
204 {
205         if (heredefinitelyCB->isChecked());
206                 ignoreCB->setEnabled(false);
207
208         topCB->setChecked(false);
209         bottomCB->setChecked(false);
210         pageCB->setChecked(false);
211         herepossiblyCB->setChecked(false);
212         ignoreCB->setChecked(false);
213 }
214
215
216 void FloatPlacement::spanClicked()
217 {
218         bool const span(spanCB->isChecked());
219
220         if (!defaultsCB->isChecked()) {
221                 herepossiblyCB->setEnabled(!span);
222                 heredefinitelyCB->setEnabled(!span);
223         }
224
225         if (!span)
226                 return;
227
228         herepossiblyCB->setChecked(false);
229         heredefinitelyCB->setChecked(false);
230 }