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