]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QFloat.C
better selection and scrolling behaviour
[lyx.git] / src / frontends / qt2 / QFloat.C
1 /**
2  * \file QFloat.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  *
8  * Full author contact details are available in file CREDITS
9  */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "ControlFloat.h"
18 #include "QFloatDialog.h"
19 #include "QFloat.h"
20 #include "Qt2BC.h"
21 #include "gettext.h"
22
23 #include "support/lstrings.h"
24
25 #include <qpushbutton.h>
26 #include <qcheckbox.h>
27
28 typedef Qt2CB<ControlFloat, Qt2DB<QFloatDialog> > base_class;
29
30
31 QFloat::QFloat()
32         : base_class(_("Float Settings"))
33 {
34 }
35
36
37 void QFloat::build_dialog()
38 {
39         dialog_.reset(new QFloatDialog(this));
40
41         bc().setCancel(dialog_->closePB);
42         bc().setApply(dialog_->applyPB);
43         bc().setOK(dialog_->okPB);
44         bc().setRestore(dialog_->restorePB);
45
46         bc().addReadOnly(dialog_->topCB);
47         bc().addReadOnly(dialog_->bottomCB);
48         bc().addReadOnly(dialog_->herepossiblyCB);
49         bc().addReadOnly(dialog_->heredefinitelyCB);
50         bc().addReadOnly(dialog_->pageCB);
51         bc().addReadOnly(dialog_->ignoreCB);
52         bc().addReadOnly(dialog_->defaultsCB);
53         bc().addReadOnly(dialog_->spanCB);
54 }
55
56
57 void QFloat::update_contents()
58 {
59         bool def_placement = false;
60         bool top = false;
61         bool bottom = false;
62         bool page = false;
63         bool here = false;
64         bool force = false;
65         bool here_definitely = false;
66
67         FloatParams const & params = controller().params();
68
69         string const & placement = params.placement;
70
71         if (placement.empty()) {
72                 def_placement = true;
73         } else if (contains(placement, "H")) {
74                 here_definitely = true;
75         } else {
76                 if (contains(placement, "!")) {
77                         force = true;
78                 }
79                 if (contains(placement, "t")) {
80                         top = true;
81                 }
82                 if (contains(placement, "b")) {
83                         bottom = true;
84                 }
85                 if (contains(placement, "p")) {
86                         page = true;
87                 }
88                 if (contains(placement, "h")) {
89                         here = true;
90                 }
91         }
92
93         dialog_->defaultsCB->setChecked(def_placement);
94         dialog_->topCB->setChecked(top);
95         dialog_->bottomCB->setChecked(bottom);
96         dialog_->pageCB->setChecked(page);
97         dialog_->herepossiblyCB->setChecked(here);
98         dialog_->ignoreCB->setChecked(force);
99         dialog_->ignoreCB->setEnabled(top || bottom || page || here);
100         dialog_->heredefinitelyCB->setChecked(here_definitely);
101
102         if (params.wide) {
103                 dialog_->herepossiblyCB->setChecked(false);
104                 dialog_->bottomCB->setChecked(false);
105         }
106
107         dialog_->spanCB->setChecked(params.wide);
108 }
109
110
111 void QFloat::apply()
112 {
113         FloatParams & params = controller().params();
114
115         params.wide = dialog_->spanCB->isChecked();
116
117         if (dialog_->defaultsCB->isChecked()) {
118                 params.placement.erase();
119                 return;
120         }
121
122         string placement;
123
124         if (dialog_->heredefinitelyCB->isChecked()) {
125                 placement += 'H';
126         } else {
127                 if (dialog_->ignoreCB->isChecked()) {
128                         placement += '!';
129                 }
130                 if (dialog_->topCB->isChecked()) {
131                         placement += 't';
132                 }
133                 if (dialog_->bottomCB->isChecked()) {
134                         placement += 'b';
135                 }
136                 if (dialog_->pageCB->isChecked()) {
137                         placement += 'p';
138                 }
139                 if (dialog_->herepossiblyCB->isChecked()) {
140                         placement += 'h';
141                 }
142         }
143         params.placement = placement;
144 }