00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "kivio_protection_panel.h"
00020 #include "kivio_protection_panel.moc"
00021
00022 #include "kivio_doc.h"
00023 #include "kivio_layer.h"
00024 #include "kivio_page.h"
00025 #include "kivio_stencil.h"
00026 #include "kivio_view.h"
00027 #include "kivio_command.h"
00028
00029 #include <qbitarray.h>
00030 #include <qcheckbox.h>
00031 #include <kaction.h>
00032 #include <kdebug.h>
00033 #include <klocale.h>
00034
00035 KivioProtectionPanel::KivioProtectionPanel( KivioView *view, QWidget *parent, const char *name )
00036 : KivioProtectionPanelBase(parent, name), m_pView(view)
00037 {
00038 QObject::connect( m_checkWidth, SIGNAL(toggled(bool)), this, SLOT(togWidth(bool)) );
00039 QObject::connect( m_checkHeight, SIGNAL(toggled(bool)), this, SLOT(togHeight(bool)) );
00040 QObject::connect( m_checkAspect, SIGNAL(toggled(bool)), this, SLOT(togAspect(bool)) );
00041 QObject::connect( m_checkDeletion, SIGNAL(toggled(bool)), this, SLOT(togDelete(bool)) );
00042 QObject::connect( m_checkXPosition, SIGNAL(toggled(bool)), this, SLOT(togX(bool)) );
00043 QObject::connect( m_checkYPosition, SIGNAL(toggled(bool)), this, SLOT(togY(bool)) );
00044 }
00045
00046 KivioProtectionPanel::~KivioProtectionPanel()
00047 {
00048 }
00049
00050 void KivioProtectionPanel::togWidth(bool on)
00051 {
00052 KivioStencil* pStencil = m_pView->activePage()->selectedStencils()->first();
00053 KMacroCommand * macro = new KMacroCommand(i18n("Change Protection Attribute"));
00054 bool createMacro = false;
00055
00056 while(pStencil) {
00057 if(pStencil->canProtect()->at(kpWidth) == true) {
00058 KivioChangeStencilProtectCommand* cmd = new KivioChangeStencilProtectCommand(i18n("Change Protection Attribute"),
00059 m_pView->activePage(), pStencil, on, KivioChangeStencilProtectCommand::KV_WIDTH);
00060 macro->addCommand(cmd);
00061 createMacro = true;
00062 } else {
00063 kdDebug(43000) << "Attempt to set width-protection of a stencil which does not support it.\n";
00064 }
00065
00066 pStencil = m_pView->activePage()->selectedStencils()->next();
00067 }
00068
00069 if(createMacro) {
00070 macro->execute();
00071 m_pView->doc()->addCommand(macro);
00072 } else {
00073 delete macro;
00074 }
00075 }
00076
00077 void KivioProtectionPanel::togHeight(bool on)
00078 {
00079 KMacroCommand* macro = new KMacroCommand(i18n("Change Protection Attribute"));
00080 bool createMacro = false;
00081 KivioStencil* pStencil = m_pView->activePage()->selectedStencils()->first();
00082
00083 while(pStencil) {
00084 if(pStencil->canProtect()->at(kpHeight) == true) {
00085 KivioChangeStencilProtectCommand* cmd = new KivioChangeStencilProtectCommand(i18n("Change Protection Attribute"),
00086 m_pView->activePage(), pStencil, on, KivioChangeStencilProtectCommand::KV_HEIGHT);
00087 macro->addCommand(cmd);
00088 createMacro = true;
00089 } else {
00090 kdDebug(43000) << "Attempt to set height-protection of a stencil which does not support it.\n";
00091 }
00092
00093 pStencil = m_pView->activePage()->selectedStencils()->next();
00094 }
00095
00096 if(createMacro) {
00097 macro->execute();
00098 m_pView->doc()->addCommand(macro);
00099 } else {
00100 delete macro;
00101 }
00102 }
00103
00104 void KivioProtectionPanel::togAspect(bool on)
00105 {
00106 KMacroCommand* macro = new KMacroCommand(i18n("Change Protection Attribute"));
00107 bool createMacro = false;
00108 KivioStencil* pStencil = m_pView->activePage()->selectedStencils()->first();
00109
00110 while(pStencil) {
00111 if(pStencil->canProtect()->at(kpAspect) == true) {
00112 KivioChangeStencilProtectCommand* cmd = new KivioChangeStencilProtectCommand(i18n("Change Protection Attribute"),
00113 m_pView->activePage(), pStencil, on, KivioChangeStencilProtectCommand::KV_ASPECT);
00114 macro->addCommand(cmd);
00115 createMacro = true;
00116 } else {
00117 kdDebug(43000) << "Attempt to set height-protection of a stencil which does not support it.\n";
00118 }
00119
00120 pStencil = m_pView->activePage()->selectedStencils()->next();
00121 }
00122
00123 if(createMacro) {
00124 macro->execute();
00125 m_pView->doc()->addCommand(macro);
00126 } else {
00127 delete macro;
00128 }
00129 }
00130
00131 void KivioProtectionPanel::togDelete(bool on)
00132 {
00133 KMacroCommand * macro = new KMacroCommand(i18n("Change Protection Attribute"));
00134 bool createMacro=false;
00135 KivioStencil* pStencil = m_pView->activePage()->selectedStencils()->first();
00136
00137 while(pStencil) {
00138 if(pStencil->canProtect()->at(kpDeletion) == true) {
00139 KivioChangeStencilProtectCommand* cmd = new KivioChangeStencilProtectCommand(i18n("Change Protection Attribute"),
00140 m_pView->activePage(), pStencil, on, KivioChangeStencilProtectCommand::KV_DELETE);
00141 macro->addCommand(cmd);
00142 createMacro = true;
00143 } else {
00144 kdDebug(43000) << "Attempt to set delete-protection of a stencil which does not support it.\n";
00145 }
00146
00147 pStencil = m_pView->activePage()->selectedStencils()->next();
00148 }
00149
00150 if(createMacro) {
00151 macro->execute();
00152 m_pView->doc()->addCommand(macro);
00153 } else {
00154 delete macro;
00155 }
00156 }
00157
00158 void KivioProtectionPanel::togX(bool on)
00159 {
00160 KMacroCommand * macro = new KMacroCommand(i18n("Change Protection Attribute"));
00161 bool createMacro=false;
00162 KivioStencil* pStencil = m_pView->activePage()->selectedStencils()->first();
00163
00164 while(pStencil) {
00165 if(pStencil->canProtect()->at(kpX) == true) {
00166 KivioChangeStencilProtectCommand* cmd = new KivioChangeStencilProtectCommand(i18n("Change Protection Attribute"),
00167 m_pView->activePage(), pStencil, on, KivioChangeStencilProtectCommand::KV_POSX);
00168 macro->addCommand(cmd);
00169 createMacro = true;
00170 } else {
00171 kdDebug(43000) << "Attempt to set X-protection of a stencil which does not support it.\n";
00172 }
00173
00174 pStencil = m_pView->activePage()->selectedStencils()->next();
00175 }
00176
00177 if(createMacro) {
00178 macro->execute();
00179 m_pView->doc()->addCommand(macro);
00180 } else {
00181 delete macro;
00182 }
00183 }
00184
00185
00186 void KivioProtectionPanel::togY(bool on)
00187 {
00188 KMacroCommand * macro = new KMacroCommand(i18n("Change Protection Attribute"));
00189 bool createMacro=false;
00190 KivioStencil* pStencil = m_pView->activePage()->selectedStencils()->first();
00191
00192 while(pStencil) {
00193 if(pStencil->canProtect()->at(kpY) == true) {
00194 KivioChangeStencilProtectCommand* cmd = new KivioChangeStencilProtectCommand(i18n("Change Protection Attribute"),
00195 m_pView->activePage(), pStencil, on, KivioChangeStencilProtectCommand::KV_POSY);
00196 macro->addCommand(cmd);
00197 createMacro = true;
00198 } else {
00199 kdDebug(43000) << "Attempt to set Y-protection of a stencil which does not support it.\n";
00200 }
00201
00202 pStencil = m_pView->activePage()->selectedStencils()->next();
00203 }
00204
00205 if(createMacro) {
00206 macro->execute();
00207 m_pView->doc()->addCommand(macro);
00208 } else {
00209 delete macro;
00210 }
00211 }
00212
00213 void KivioProtectionPanel::updateCheckBoxes()
00214 {
00215
00216
00217 if(m_pView->activePage()->selectedStencils()->count() == 0)
00218 {
00219 m_checkAspect->setEnabled(false);
00220 m_checkXPosition->setEnabled(false);
00221 m_checkYPosition->setEnabled(false);
00222 m_checkDeletion->setEnabled(false);
00223 m_checkHeight->setEnabled(false);
00224 m_checkWidth->setEnabled(false);
00225
00226 m_checkAspect->setChecked(false);
00227 m_checkXPosition->setChecked(false);
00228 m_checkYPosition->setChecked(false);
00229 m_checkDeletion->setChecked(false);
00230 m_checkHeight->setChecked(false);
00231 m_checkWidth->setChecked(false);
00232
00233 return;
00234 }
00235
00236 QBitArray bits( NUM_PROTECTIONS );
00237 int i;
00238
00239
00240 for(i = 0; i < NUM_PROTECTIONS; i++) {
00241 bits.setBit(i);
00242 }
00243
00244
00245 KivioStencil* pStencil = m_pView->activePage()->selectedStencils()->first();
00246
00247 while(pStencil) {
00248
00249
00250
00251 for(i = 0; i < NUM_PROTECTIONS; i++) {
00252 if(pStencil->canProtect()->at(i) == false) {
00253 bits.clearBit(i);
00254 }
00255 }
00256
00257 pStencil = m_pView->activePage()->selectedStencils()->next();
00258 }
00259
00260 QObject::disconnect(m_checkWidth, SIGNAL(toggled(bool)), this, SLOT(togWidth(bool)));
00261 QObject::disconnect(m_checkHeight, SIGNAL(toggled(bool)), this, SLOT(togHeight(bool)));
00262 QObject::disconnect(m_checkAspect, SIGNAL(toggled(bool)), this, SLOT(togAspect(bool)));
00263 QObject::disconnect(m_checkDeletion, SIGNAL(toggled(bool)), this, SLOT(togDelete(bool)));
00264 QObject::disconnect(m_checkXPosition, SIGNAL(toggled(bool)), this, SLOT(togX(bool)));
00265 QObject::disconnect(m_checkYPosition, SIGNAL(toggled(bool)), this, SLOT(togY(bool)));
00266
00267
00268 for(i = 0; i < NUM_PROTECTIONS; i++) {
00269 bool on = bits.at(i);
00270
00271 switch(i) {
00272 case kpX:
00273 m_checkXPosition->setEnabled(on);
00274 break;
00275
00276 case kpY:
00277 m_checkYPosition->setEnabled(on);
00278 break;
00279
00280 case kpWidth:
00281 m_checkWidth->setEnabled(on);
00282 break;
00283
00284 case kpHeight:
00285 m_checkHeight->setEnabled(on);
00286 break;
00287
00288 case kpDeletion:
00289 m_checkDeletion->setEnabled(on);
00290 break;
00291
00292 case kpAspect:
00293 m_checkAspect->setEnabled(on);
00294 break;
00295
00296 default:
00297 break;
00298 }
00299 }
00300
00301
00302
00303
00304 if(m_pView->activePage()->selectedStencils()->count() > 1) {
00305 m_checkAspect->setChecked(false);
00306 m_checkXPosition->setChecked(false);
00307 m_checkYPosition->setChecked(false);
00308 m_checkDeletion->setChecked(false);
00309 m_checkHeight->setChecked(false);
00310 m_checkWidth->setChecked(false);
00311 } else {
00312 pStencil = m_pView->activePage()->selectedStencils()->first();
00313
00314 m_checkAspect->setChecked( pStencil->protection()->at(kpAspect) );
00315 m_checkDeletion->setChecked( pStencil->protection()->at(kpDeletion) );
00316 m_checkXPosition->setChecked( pStencil->protection()->at(kpX) );
00317 m_checkYPosition->setChecked( pStencil->protection()->at(kpY) );
00318 m_checkWidth->setChecked( pStencil->protection()->at(kpWidth) );
00319 m_checkHeight->setChecked( pStencil->protection()->at(kpHeight) );
00320 }
00321
00322 QObject::connect(m_checkWidth, SIGNAL(toggled(bool)), this, SLOT(togWidth(bool)));
00323 QObject::connect(m_checkHeight, SIGNAL(toggled(bool)), this, SLOT(togHeight(bool)));
00324 QObject::connect(m_checkAspect, SIGNAL(toggled(bool)), this, SLOT(togAspect(bool)));
00325 QObject::connect(m_checkDeletion, SIGNAL(toggled(bool)), this, SLOT(togDelete(bool)));
00326 QObject::connect(m_checkXPosition, SIGNAL(toggled(bool)), this, SLOT(togX(bool)));
00327 QObject::connect(m_checkYPosition, SIGNAL(toggled(bool)), this, SLOT(togY(bool)));
00328 }