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