]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlTabular.C
move some stuff from the qt dialog into the controller.
[lyx.git] / src / frontends / controllers / ControlTabular.C
1 // -*- C++ -*-
2 /**
3  * \file ControlTabular.C
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author John Levon
8  *
9  * Full author contact details are available in file CREDITS
10  */
11
12 #include <config.h>
13
14 #include "ControlTabular.h"
15 #include "funcrequest.h"
16 #include "lyxrc.h"
17 #include "insets/insettabular.h"
18 #include "support/LAssert.h"
19
20
21
22 ControlTabular::ControlTabular(Dialog & parent)
23         : Dialog::Controller(parent), active_cell_(-1)
24 {}
25
26
27 bool ControlTabular::initialiseParams(string const & data)
28 {
29         Buffer * buffer = kernel().buffer();
30         if (!buffer)
31                 return false;
32
33         InsetTabular tmp(*buffer);
34         int cell = InsetTabularMailer::string2params(data, tmp);
35         if (cell != -1) {
36                 params_.reset(new LyXTabular(*tmp.tabular.get()));
37                 active_cell_ = cell;
38         }
39         return true;
40 }
41
42
43 void ControlTabular::clearParams()
44 {
45         params_.reset();
46         active_cell_ = -1;
47 }
48
49
50 int ControlTabular::getActiveCell() const
51 {
52         return active_cell_;
53 }
54
55
56 LyXTabular const & ControlTabular::tabular() const
57 {
58         lyx::Assert(params_.get());
59         return *params_.get();
60 }
61
62
63 void ControlTabular::set(LyXTabular::Feature f, string const & arg)
64 {
65         string const data = featureAsString(f) + ' ' + arg;
66         kernel().dispatch(FuncRequest(LFUN_TABULAR_FEATURE, data));
67 }
68
69
70 bool ControlTabular::useMetricUnits() const
71 {
72         return lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER;
73 }
74
75
76 void ControlTabular::toggleTopLine()
77 {
78         if (tabular().IsMultiColumn(getActiveCell()))
79                 set(LyXTabular::M_TOGGLE_LINE_TOP);
80         else
81                 set(LyXTabular::TOGGLE_LINE_TOP);
82 }
83
84
85 void ControlTabular::toggleBottomLine()
86 {
87         if (tabular().IsMultiColumn(getActiveCell()))
88                 set(LyXTabular::M_TOGGLE_LINE_BOTTOM);
89         else
90                 set(LyXTabular::TOGGLE_LINE_BOTTOM);
91 }
92
93
94 void ControlTabular::toggleLeftLine()
95 {
96         if (tabular().IsMultiColumn(getActiveCell()))
97                 set(LyXTabular::M_TOGGLE_LINE_LEFT);
98         else
99                 set(LyXTabular::TOGGLE_LINE_LEFT);
100 }
101
102
103 void ControlTabular::toggleRightLine()
104 {
105         if (tabular().IsMultiColumn(getActiveCell()))
106                 set(LyXTabular::M_TOGGLE_LINE_RIGHT);
107         else
108                 set(LyXTabular::TOGGLE_LINE_RIGHT);
109 }
110
111
112 void ControlTabular::setSpecial(string const & special)
113 {
114         if (tabular().IsMultiColumn(getActiveCell()))
115                 set(LyXTabular::SET_SPECIAL_MULTI, special);
116         else
117                 set(LyXTabular::SET_SPECIAL_COLUMN, special);
118 }
119
120
121 void ControlTabular::setWidth(string const & width)
122 {
123         if (tabular().IsMultiColumn(getActiveCell()))
124                 set(LyXTabular::SET_MPWIDTH, width);
125         else
126                 set(LyXTabular::SET_PWIDTH, width);
127
128         dialog().view().update();
129 }
130
131
132 void ControlTabular::toggleMultiColumn()
133 {
134         set(LyXTabular::MULTICOLUMN);
135         dialog().view().update();
136 }
137
138
139 void ControlTabular::rotateTabular(bool yes)
140 {
141         if (yes)
142                 set(LyXTabular::SET_ROTATE_TABULAR);
143         else
144                 set(LyXTabular::UNSET_ROTATE_TABULAR);
145 }
146
147
148 void ControlTabular::rotateCell(bool yes)
149 {
150         if (yes)
151                 set(LyXTabular::SET_ROTATE_CELL);
152         else
153                 set(LyXTabular::UNSET_ROTATE_CELL);
154 }
155
156
157 void ControlTabular::halign(ControlTabular::HALIGN h)
158 {
159         LyXTabular::Feature num = LyXTabular::ALIGN_LEFT;
160         LyXTabular::Feature multi_num = LyXTabular::M_ALIGN_LEFT;
161
162         switch (h) {
163                 case LEFT:
164                         num = LyXTabular::ALIGN_LEFT;
165                         multi_num = LyXTabular::M_ALIGN_LEFT;
166                         break;
167                 case CENTER:
168                         num = LyXTabular::ALIGN_CENTER;
169                         multi_num = LyXTabular::M_ALIGN_CENTER;
170                         break;
171                 case RIGHT:
172                         num = LyXTabular::ALIGN_RIGHT;
173                         multi_num = LyXTabular::M_ALIGN_RIGHT;
174                         break;
175                 case BLOCK:
176                         num = LyXTabular::ALIGN_BLOCK;
177                         //multi_num: no equivalent
178                         break;
179         }
180
181         if (tabular().IsMultiColumn(getActiveCell()))
182                 set(multi_num);
183         else
184                 set(num);
185 }
186
187
188 void ControlTabular::valign(ControlTabular::VALIGN v)
189 {
190         LyXTabular::Feature num = LyXTabular::VALIGN_CENTER;
191         LyXTabular::Feature multi_num = LyXTabular::M_VALIGN_CENTER;
192
193         switch (v) {
194                 case TOP:
195                         num = LyXTabular::VALIGN_TOP;
196                         multi_num = LyXTabular::M_VALIGN_TOP;
197                         break;
198                 case VCENTER:
199                         num = LyXTabular::VALIGN_CENTER;
200                         multi_num = LyXTabular::M_VALIGN_CENTER;
201                         break;
202                 case BOTTOM:
203                         num = LyXTabular::VALIGN_BOTTOM;
204                         multi_num = LyXTabular::M_VALIGN_BOTTOM;
205                         break;
206         }
207
208         if (tabular().IsMultiColumn(getActiveCell()))
209                 set(multi_num);
210         else
211                 set(num);
212 }
213
214
215 void ControlTabular::longTabular(bool yes)
216 {
217         if (yes)
218                 set(LyXTabular::SET_LONGTABULAR);
219         else
220                 set(LyXTabular::UNSET_LONGTABULAR);
221 }