]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QFloat.C
another fix
[lyx.git] / src / frontends / qt2 / QFloat.C
1 /**
2  * \file QFloat.C
3  * Copyright 2002 the LyX Team
4  * Read the file COPYING
5  *
6  * \author Edwin Leuven <leuven@fee.uva.nl>
7  */
8
9 #include <config.h>
10
11 #ifdef __GNUG__
12 #pragma implementation
13 #endif
14
15 #include "ControlFloat.h"
16 #include "QFloatDialog.h"
17 #include "QFloat.h"
18 #include "Qt2BC.h"
19 #include "gettext.h"
20
21 #include "support/lstrings.h"
22
23 #include <qpushbutton.h>
24 #include <qcheckbox.h>
25
26 typedef Qt2CB<ControlFloat, Qt2DB<QFloatDialog> > base_class;
27
28 QFloat::QFloat()
29         : base_class(_("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         string const placement(controller().params().placement);
65
66         if (placement.empty()) {
67                 def_placement = true;
68         } else if (contains(placement, "H")) {
69                 here_definitely = true;
70         } else {
71                 if (contains(placement, "!")) {
72                         force = true;
73                 }
74                 if (contains(placement, "t")) {
75                         top = true;
76                 }
77                 if (contains(placement, "b")) {
78                         bottom = true;
79                 }
80                 if (contains(placement, "p")) {
81                         page = true;
82                 }
83                 if (contains(placement, "h")) {
84                         here = true;
85                 }
86         }
87  
88         dialog_->defaultsCB->setChecked(def_placement);
89         dialog_->topCB->setChecked(top);
90         dialog_->bottomCB->setChecked(bottom);
91         dialog_->pageCB->setChecked(page);
92         dialog_->herepossiblyCB->setChecked(here);
93         dialog_->ignoreCB->setChecked(force);
94         dialog_->ignoreCB->setEnabled(top || bottom || page || here);
95         dialog_->heredefinitelyCB->setChecked(here_definitely);
96  
97         if (controller().params().wide) {
98                 dialog_->herepossiblyCB->setChecked(false);
99                 dialog_->bottomCB->setChecked(false);
100         }
101  
102         dialog_->spanCB->setChecked(controller().params().wide);
103 }
104
105  
106 void QFloat::apply()
107 {
108         controller().params().wide = dialog_->spanCB->isChecked(); 
109
110         if (dialog_->defaultsCB->isChecked()) {
111                 controller().params().placement = "";
112                 return;
113         }
114  
115         string placement;
116
117         if (dialog_->heredefinitelyCB->isChecked()) {
118                 placement += "H";
119         } else {
120                 if (dialog_->ignoreCB->isChecked()) {
121                         placement += "!";
122                 }
123                 if (dialog_->topCB->isChecked()) {
124                         placement += "t";
125                 }
126                 if (dialog_->bottomCB->isChecked()) {
127                         placement += "b";
128                 }
129                 if (dialog_->pageCB->isChecked()) {
130                         placement += "p";
131                 }
132                 if (dialog_->herepossiblyCB->isChecked()) {
133                         placement += "h";
134                 }
135         }
136         controller().params().placement = placement;
137 }