]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QFloat.C
Lots and lots of little trivial bits.
[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 QFloat::QFloat()
31         : base_class(_("Float Settings"))
32 {
33 }
34
35
36 void QFloat::build_dialog()
37 {
38         dialog_.reset(new QFloatDialog(this));
39
40         bc().setCancel(dialog_->closePB);
41         bc().setApply(dialog_->applyPB);
42         bc().setOK(dialog_->okPB);
43         bc().setRestore(dialog_->restorePB);
44
45         bc().addReadOnly(dialog_->topCB);
46         bc().addReadOnly(dialog_->bottomCB);
47         bc().addReadOnly(dialog_->herepossiblyCB);
48         bc().addReadOnly(dialog_->heredefinitelyCB);
49         bc().addReadOnly(dialog_->pageCB);
50         bc().addReadOnly(dialog_->ignoreCB);
51         bc().addReadOnly(dialog_->defaultsCB);
52         bc().addReadOnly(dialog_->spanCB);
53 }
54
55
56 void QFloat::update_contents()
57 {
58         bool def_placement = false;
59         bool top = false;
60         bool bottom = false;
61         bool page = false;
62         bool here = false;
63         bool force = false;
64         bool here_definitely = false;
65
66         string const placement(controller().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 (controller().params().wide) {
100                 dialog_->herepossiblyCB->setChecked(false);
101                 dialog_->bottomCB->setChecked(false);
102         }
103  
104         dialog_->spanCB->setChecked(controller().params().wide);
105 }
106
107  
108 void QFloat::apply()
109 {
110         controller().params().wide = dialog_->spanCB->isChecked(); 
111
112         if (dialog_->defaultsCB->isChecked()) {
113                 controller().params().placement = "";
114                 return;
115         }
116  
117         string placement;
118
119         if (dialog_->heredefinitelyCB->isChecked()) {
120                 placement += "H";
121         } else {
122                 if (dialog_->ignoreCB->isChecked()) {
123                         placement += "!";
124                 }
125                 if (dialog_->topCB->isChecked()) {
126                         placement += "t";
127                 }
128                 if (dialog_->bottomCB->isChecked()) {
129                         placement += "b";
130                 }
131                 if (dialog_->pageCB->isChecked()) {
132                         placement += "p";
133                 }
134                 if (dialog_->herepossiblyCB->isChecked()) {
135                         placement += "h";
136                 }
137         }
138         controller().params().placement = placement;
139 }