kivio

kivio_protection_panel.cpp
1/*
2 * Kivio - Visual Modelling and Flowcharting
3 * Copyright (C) 2000-2001 theKompany.com & Dave Marotti
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19#include "kivio_protection_panel.h"
20#include "kivio_protection_panel.moc"
21
22#include "kivio_doc.h"
23#include "kivio_layer.h"
24#include "kivio_page.h"
25#include "kivio_stencil.h"
26#include "kivio_view.h"
27#include "kivio_command.h"
28
29#include <tqbitarray.h>
30#include <tqcheckbox.h>
31#include <tdeaction.h>
32#include <kdebug.h>
33#include <tdelocale.h>
34
35KivioProtectionPanel::KivioProtectionPanel( KivioView *view, TQWidget *parent, const char *name )
36 : KivioProtectionPanelBase(parent, name), m_pView(view)
37{
38 TQObject::connect( m_checkWidth, TQ_SIGNAL(toggled(bool)), this, TQ_SLOT(togWidth(bool)) );
39 TQObject::connect( m_checkHeight, TQ_SIGNAL(toggled(bool)), this, TQ_SLOT(togHeight(bool)) );
40 TQObject::connect( m_checkAspect, TQ_SIGNAL(toggled(bool)), this, TQ_SLOT(togAspect(bool)) );
41 TQObject::connect( m_checkDeletion, TQ_SIGNAL(toggled(bool)), this, TQ_SLOT(togDelete(bool)) );
42 TQObject::connect( m_checkXPosition, TQ_SIGNAL(toggled(bool)), this, TQ_SLOT(togX(bool)) );
43 TQObject::connect( m_checkYPosition, TQ_SIGNAL(toggled(bool)), this, TQ_SLOT(togY(bool)) );
44}
45
46KivioProtectionPanel::~KivioProtectionPanel()
47{
48}
49
50void KivioProtectionPanel::togWidth(bool on)
51{
52 KivioStencil* pStencil = m_pView->activePage()->selectedStencils()->first();
53 KMacroCommand * macro = new KMacroCommand(i18n("Change Protection Attribute"));
54 bool createMacro = false;
55
56 while(pStencil) {
57 if(pStencil->canProtect()->at(kpWidth) == true) {
58 KivioChangeStencilProtectCommand* cmd = new KivioChangeStencilProtectCommand(i18n("Change Protection Attribute"),
59 m_pView->activePage(), pStencil, on, KivioChangeStencilProtectCommand::KV_WIDTH);
60 macro->addCommand(cmd);
61 createMacro = true;
62 } else {
63 kdDebug(43000) << "Attempt to set width-protection of a stencil which does not support it.\n";
64 }
65
66 pStencil = m_pView->activePage()->selectedStencils()->next();
67 }
68
69 if(createMacro) {
70 macro->execute();
71 m_pView->doc()->addCommand(macro);
72 } else {
73 delete macro;
74 }
75}
76
77void KivioProtectionPanel::togHeight(bool on)
78{
79 KMacroCommand* macro = new KMacroCommand(i18n("Change Protection Attribute"));
80 bool createMacro = false;
81 KivioStencil* pStencil = m_pView->activePage()->selectedStencils()->first();
82
83 while(pStencil) {
84 if(pStencil->canProtect()->at(kpHeight) == true) {
85 KivioChangeStencilProtectCommand* cmd = new KivioChangeStencilProtectCommand(i18n("Change Protection Attribute"),
86 m_pView->activePage(), pStencil, on, KivioChangeStencilProtectCommand::KV_HEIGHT);
87 macro->addCommand(cmd);
88 createMacro = true;
89 } else {
90 kdDebug(43000) << "Attempt to set height-protection of a stencil which does not support it.\n";
91 }
92
93 pStencil = m_pView->activePage()->selectedStencils()->next();
94 }
95
96 if(createMacro) {
97 macro->execute();
98 m_pView->doc()->addCommand(macro);
99 } else {
100 delete macro;
101 }
102}
103
104void KivioProtectionPanel::togAspect(bool on)
105{
106 KMacroCommand* macro = new KMacroCommand(i18n("Change Protection Attribute"));
107 bool createMacro = false;
108 KivioStencil* pStencil = m_pView->activePage()->selectedStencils()->first();
109
110 while(pStencil) {
111 if(pStencil->canProtect()->at(kpAspect) == true) {
112 KivioChangeStencilProtectCommand* cmd = new KivioChangeStencilProtectCommand(i18n("Change Protection Attribute"),
113 m_pView->activePage(), pStencil, on, KivioChangeStencilProtectCommand::KV_ASPECT);
114 macro->addCommand(cmd);
115 createMacro = true;
116 } else {
117 kdDebug(43000) << "Attempt to set height-protection of a stencil which does not support it.\n";
118 }
119
120 pStencil = m_pView->activePage()->selectedStencils()->next();
121 }
122
123 if(createMacro) {
124 macro->execute();
125 m_pView->doc()->addCommand(macro);
126 } else {
127 delete macro;
128 }
129}
130
131void KivioProtectionPanel::togDelete(bool on)
132{
133 KMacroCommand * macro = new KMacroCommand(i18n("Change Protection Attribute"));
134 bool createMacro=false;
135 KivioStencil* pStencil = m_pView->activePage()->selectedStencils()->first();
136
137 while(pStencil) {
138 if(pStencil->canProtect()->at(kpDeletion) == true) {
139 KivioChangeStencilProtectCommand* cmd = new KivioChangeStencilProtectCommand(i18n("Change Protection Attribute"),
140 m_pView->activePage(), pStencil, on, KivioChangeStencilProtectCommand::KV_DELETE);
141 macro->addCommand(cmd);
142 createMacro = true;
143 } else {
144 kdDebug(43000) << "Attempt to set delete-protection of a stencil which does not support it.\n";
145 }
146
147 pStencil = m_pView->activePage()->selectedStencils()->next();
148 }
149
150 if(createMacro) {
151 macro->execute();
152 m_pView->doc()->addCommand(macro);
153 } else {
154 delete macro;
155 }
156}
157
158void KivioProtectionPanel::togX(bool on)
159{
160 KMacroCommand * macro = new KMacroCommand(i18n("Change Protection Attribute"));
161 bool createMacro=false;
162 KivioStencil* pStencil = m_pView->activePage()->selectedStencils()->first();
163
164 while(pStencil) {
165 if(pStencil->canProtect()->at(kpX) == true) {
166 KivioChangeStencilProtectCommand* cmd = new KivioChangeStencilProtectCommand(i18n("Change Protection Attribute"),
167 m_pView->activePage(), pStencil, on, KivioChangeStencilProtectCommand::KV_POSX);
168 macro->addCommand(cmd);
169 createMacro = true;
170 } else {
171 kdDebug(43000) << "Attempt to set X-protection of a stencil which does not support it.\n";
172 }
173
174 pStencil = m_pView->activePage()->selectedStencils()->next();
175 }
176
177 if(createMacro) {
178 macro->execute();
179 m_pView->doc()->addCommand(macro);
180 } else {
181 delete macro;
182 }
183}
184
185
186void KivioProtectionPanel::togY(bool on)
187{
188 KMacroCommand * macro = new KMacroCommand(i18n("Change Protection Attribute"));
189 bool createMacro=false;
190 KivioStencil* pStencil = m_pView->activePage()->selectedStencils()->first();
191
192 while(pStencil) {
193 if(pStencil->canProtect()->at(kpY) == true) {
194 KivioChangeStencilProtectCommand* cmd = new KivioChangeStencilProtectCommand(i18n("Change Protection Attribute"),
195 m_pView->activePage(), pStencil, on, KivioChangeStencilProtectCommand::KV_POSY);
196 macro->addCommand(cmd);
197 createMacro = true;
198 } else {
199 kdDebug(43000) << "Attempt to set Y-protection of a stencil which does not support it.\n";
200 }
201
202 pStencil = m_pView->activePage()->selectedStencils()->next();
203 }
204
205 if(createMacro) {
206 macro->execute();
207 m_pView->doc()->addCommand(macro);
208 } else {
209 delete macro;
210 }
211}
212
213void KivioProtectionPanel::updateCheckBoxes()
214{
215 // If there are no selected stencils, then disable all checkboxes,
216 // and uncheck them
217 if(m_pView->activePage()->selectedStencils()->count() == 0)
218 {
219 m_checkAspect->setEnabled(false);
220 m_checkXPosition->setEnabled(false);
221 m_checkYPosition->setEnabled(false);
222 m_checkDeletion->setEnabled(false);
223 m_checkHeight->setEnabled(false);
224 m_checkWidth->setEnabled(false);
225
226 m_checkAspect->setChecked(false);
227 m_checkXPosition->setChecked(false);
228 m_checkYPosition->setChecked(false);
229 m_checkDeletion->setChecked(false);
230 m_checkHeight->setChecked(false);
231 m_checkWidth->setChecked(false);
232
233 return;
234 }
235
236 TQBitArray bits( NUM_PROTECTIONS );
237 int i;
238
239 // Assume all protections are valid by default
240 for(i = 0; i < NUM_PROTECTIONS; i++) {
241 bits.setBit(i);
242 }
243
244
245 KivioStencil* pStencil = m_pView->activePage()->selectedStencils()->first();
246
247 while(pStencil) {
248 // Now build an array representing which protection fields are valid
249 // since there could be multiple types of stencils selected with varying
250 // protection abilities
251 for(i = 0; i < NUM_PROTECTIONS; i++) {
252 if(pStencil->canProtect()->at(i) == false) {
253 bits.clearBit(i);
254 }
255 }
256
257 pStencil = m_pView->activePage()->selectedStencils()->next();
258 }
259
260 TQObject::disconnect(m_checkWidth, TQ_SIGNAL(toggled(bool)), this, TQ_SLOT(togWidth(bool)));
261 TQObject::disconnect(m_checkHeight, TQ_SIGNAL(toggled(bool)), this, TQ_SLOT(togHeight(bool)));
262 TQObject::disconnect(m_checkAspect, TQ_SIGNAL(toggled(bool)), this, TQ_SLOT(togAspect(bool)));
263 TQObject::disconnect(m_checkDeletion, TQ_SIGNAL(toggled(bool)), this, TQ_SLOT(togDelete(bool)));
264 TQObject::disconnect(m_checkXPosition, TQ_SIGNAL(toggled(bool)), this, TQ_SLOT(togX(bool)));
265 TQObject::disconnect(m_checkYPosition, TQ_SIGNAL(toggled(bool)), this, TQ_SLOT(togY(bool)));
266
267 // Enable and disable the check boxes based on what protections are available
268 for(i = 0; i < NUM_PROTECTIONS; i++) {
269 bool on = bits.at(i);
270
271 switch(i) {
272 case kpX:
273 m_checkXPosition->setEnabled(on);
274 break;
275
276 case kpY:
277 m_checkYPosition->setEnabled(on);
278 break;
279
280 case kpWidth:
281 m_checkWidth->setEnabled(on);
282 break;
283
284 case kpHeight:
285 m_checkHeight->setEnabled(on);
286 break;
287
288 case kpDeletion:
289 m_checkDeletion->setEnabled(on);
290 break;
291
292 case kpAspect:
293 m_checkAspect->setEnabled(on);
294 break;
295
296 default:
297 break;
298 }
299 }
300
301
302
303 // If we have more than one stencil selected, then clear all checkboxes
304 if(m_pView->activePage()->selectedStencils()->count() > 1) {
305 m_checkAspect->setChecked(false);
306 m_checkXPosition->setChecked(false);
307 m_checkYPosition->setChecked(false);
308 m_checkDeletion->setChecked(false);
309 m_checkHeight->setChecked(false);
310 m_checkWidth->setChecked(false);
311 } else { // Otherwise fill in the checkboxes with the single selection
312 pStencil = m_pView->activePage()->selectedStencils()->first();
313
314 m_checkAspect->setChecked( pStencil->protection()->at(kpAspect) );
315 m_checkDeletion->setChecked( pStencil->protection()->at(kpDeletion) );
316 m_checkXPosition->setChecked( pStencil->protection()->at(kpX) );
317 m_checkYPosition->setChecked( pStencil->protection()->at(kpY) );
318 m_checkWidth->setChecked( pStencil->protection()->at(kpWidth) );
319 m_checkHeight->setChecked( pStencil->protection()->at(kpHeight) );
320 }
321
322 TQObject::connect(m_checkWidth, TQ_SIGNAL(toggled(bool)), this, TQ_SLOT(togWidth(bool)));
323 TQObject::connect(m_checkHeight, TQ_SIGNAL(toggled(bool)), this, TQ_SLOT(togHeight(bool)));
324 TQObject::connect(m_checkAspect, TQ_SIGNAL(toggled(bool)), this, TQ_SLOT(togAspect(bool)));
325 TQObject::connect(m_checkDeletion, TQ_SIGNAL(toggled(bool)), this, TQ_SLOT(togDelete(bool)));
326 TQObject::connect(m_checkXPosition, TQ_SIGNAL(toggled(bool)), this, TQ_SLOT(togX(bool)));
327 TQObject::connect(m_checkYPosition, TQ_SIGNAL(toggled(bool)), this, TQ_SLOT(togY(bool)));
328}