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