Back to index

scribus-ng  1.3.4.dfsg+svn20071115
scraction.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 /***************************************************************************
00008     begin                : Jan 2005
00009     copyright            : (C) 2005 by Craig Bradney
00010     email                : cbradney@zip.com.au
00011  ***************************************************************************/
00012 
00013 /***************************************************************************
00014  *                                                                         *
00015  *   This program is free software; you can redistribute it and/or modify  *
00016  *   it under the terms of the GNU General Public License as published by  *
00017  *   the Free Software Foundation; either version 2 of the License, or     *
00018  *   (at your option) any later version.                                   *
00019  *                                                                         *
00020  ***************************************************************************/
00021 #include <qpopupmenu.h>
00022 #include <qiconset.h>
00023 #include "scraction.h"
00024 #include "scraction.moc"
00025 #include "scribus.h"
00026 #include "scribusdoc.h"
00027 
00028 ScrAction::ScrAction( QObject * parent, const char * name ) : QAction( parent, name )
00029 {
00030        initScrAction();
00031 }
00032 
00033 ScrAction::ScrAction( const QString & menuText, QKeySequence accel, QObject * parent, const char * name ) : QAction( menuText, accel, parent, name )
00034 {
00035        initScrAction();
00036 }
00037 
00038 ScrAction::ScrAction( ActionType aType, const QIconSet & icon, const QString & menuText, QKeySequence accel, QObject * parent, const char * name, int extraInt, double extraDouble, QString extraQString ) : QAction( icon, menuText, accel, parent, name )
00039 {
00040        initScrAction();
00041        setIconSizes();
00042        _actionType=aType;
00043 
00044        if (_actionType!=Normal)
00045               connect (this, SIGNAL(activated()), this, SLOT(activatedToActivatedData()));
00046        switch (_actionType)
00047        {
00048               case DataInt:
00049                      _dataInt=extraInt;
00050                      break;
00051               case DataDouble:
00052                      _dataDouble=extraDouble;
00053                      break;
00054               case DataQString:
00055                      _dataQString=extraQString;
00056                      break;
00057               case RecentFile:
00058                      _dataQString=extraQString;
00059                      break;
00060               case RecentPaste:
00061                      _dataQString=extraQString;
00062                      break;
00063               case DLL:
00064                      pluginID=extraInt;
00065                      break;
00066               case Window:
00067                      windowID=extraInt;
00068                      break;
00069               case RecentScript:
00070                      break;
00071               case UnicodeChar:
00072                      _dataInt=extraInt;
00073                      break;
00074               case Layer:
00075                      layerID=extraInt;
00076                      break;
00077               case Normal:
00078               default:
00079                      break;
00080        }
00081 }
00082 
00083 ScrAction::ScrAction( const QIconSet & icon, const QString & menuText, QKeySequence accel, QObject * parent, const char * name ) : QAction( icon, menuText, accel, parent, name )
00084 {
00085        initScrAction();
00086        setIconSizes();
00087 }
00088 
00089 void ScrAction::initScrAction()
00090 {
00091        _actionType=ScrAction::Normal;
00092        menuIndex=-1;
00093        widgetAddedTo=0;
00094        containerWidgetAddedTo=0;
00095        savedKeySequence=QKeySequence("");
00096        shortcutSaved=false;
00097        fakeToggle=false;
00098 }
00099 
00100 ScrAction::~ScrAction()
00101 {
00102 }
00103 
00104 void ScrAction::setIconSizes()
00105 {
00106        QIconSet iconset=iconSet();
00107        if (!iconset.isNull())
00108        {
00109               iconset.setIconSize(QIconSet::Small, QSize(16,16));
00110               iconset.setIconSize(QIconSet::Large, QSize(22,22));
00111        }
00112 }
00113 
00114 void ScrAction::activatedToActivatedData()
00115 {
00116        if (_actionType==ScrAction::DataInt)
00117               emit activatedData(_dataInt);
00118        if (_actionType==ScrAction::DataDouble)
00119               emit activatedData(_dataDouble);
00120        if (_actionType==ScrAction::DataQString)
00121               emit activatedData(_dataQString);
00122        if (_actionType==ScrAction::DLL)
00123               emit activatedData(pluginID);
00124        if (_actionType==ScrAction::Window)
00125               emit activatedData(windowID);
00126        if (_actionType==ScrAction::RecentFile)
00127               emit activatedData(_dataQString);
00128        if (_actionType==ScrAction::RecentPaste)
00129               emit activatedData(_dataQString);
00130        if (_actionType==ScrAction::RecentScript)
00131               emit activatedData(menuText());
00132        if (_actionType==ScrAction::UnicodeChar)
00133               activatedUnicodeShortcut(name(), _dataInt);
00134        if (_actionType==ScrAction::Layer)
00135               emit activatedData(layerID);
00136        if (_actionType==ScrAction::ActionDLL)
00137               emit activatedData(((ScribusMainWindow*)parent())->doc);
00138 }
00139 
00140 void ScrAction::toggledToToggledData(bool ison)
00141 {
00142        if (isToggleAction())
00143        {
00144               if (_actionType==ScrAction::DataInt)
00145                      emit toggledData(ison, _dataInt);
00146               if (_actionType==ScrAction::DataDouble)
00147                      emit toggledData(ison, _dataDouble);
00148               if (_actionType==ScrAction::DataQString)
00149                      emit toggledData(ison, _dataQString);
00150               if (_actionType==ScrAction::DLL)
00151                      emit toggledData(ison, pluginID);
00152               if (_actionType==ScrAction::Window)
00153                      emit toggledData(ison, windowID);
00154               if (_actionType==ScrAction::RecentFile)
00155                      emit toggledData(ison, _dataQString);
00156               if (_actionType==ScrAction::RecentPaste)
00157                      emit toggledData(ison, _dataQString);
00158               if (_actionType==ScrAction::RecentScript)
00159                      emit toggledData(ison, menuText());
00160               if (_actionType==ScrAction::Layer)
00161                      emit toggledData(ison, layerID);
00162               // no toggle for UnicodeChar
00163        }
00164 }
00165 
00166 void ScrAction::addedTo ( int index, QPopupMenu * menu )
00167 {
00168        if (menuIndex==-1) // Add the first time, not for secondary popups.
00169        {
00170               menuIndex=index;
00171               popupMenuAddedTo=menu;
00172        }
00173 }
00174 
00175 
00176 void ScrAction::addedTo( QWidget * actionWidget, QWidget * container )
00177 {
00178        if (actionWidget)
00179               widgetAddedTo = actionWidget;
00180        if (containerWidgetAddedTo)
00181               containerWidgetAddedTo = container;
00182 }
00183 
00184 
00185 QWidget* ScrAction::getWidgetAddedTo()
00186 {
00187        return widgetAddedTo;
00188 }
00189 
00190 QString ScrAction::cleanMenuText()
00191 {
00192        return menuText().remove('&').remove("...");
00193 }
00194 
00195 const int ScrAction::getMenuIndex()
00196 {
00197        return menuIndex;
00198 }
00199 
00200 bool ScrAction::addTo ( QWidget * w )
00201 {
00202        widgetAddedTo=w;
00203        return (QAction::addTo(w));
00204 }
00205 
00206 const bool ScrAction::isDLLAction()
00207 {
00208        return _actionType==ScrAction::DLL;
00209 }
00210 
00211 const int ScrAction::dllID()
00212 {
00213        if (_actionType==ScrAction::DLL)
00214               return pluginID;
00215        return -1;
00216 }
00217 
00218 void ScrAction::setToggleAction(bool isToggle, bool isFakeToggle)
00219 {
00220        if (_actionType!=Normal)
00221        {
00222               if (isToggle)
00223                      connect(this, SIGNAL(toggled(bool)), this, SLOT(toggledToToggledData(bool)));
00224               else
00225                      disconnect(this, SIGNAL(toggled(bool)), this, SLOT(toggledToToggledData(bool)));
00226        }
00227        QAction::setToggleAction(isToggle);
00228        fakeToggle=isFakeToggle;
00229        //if (fakeToggle)
00230               //connect(this, toggled(bool), this, activated());
00231 }
00232 
00233 void ScrAction::saveShortcut()
00234 {
00235        if(!shortcutSaved)
00236        {
00237               savedKeySequence=accel();
00238               setAccel(QKeySequence(""));
00239               shortcutSaved=true;
00240        }
00241 }
00242 
00243 void ScrAction::restoreShortcut()
00244 {
00245        if (shortcutSaved)
00246        {
00247               setAccel(savedKeySequence);
00248               savedKeySequence=QKeySequence("");
00249               shortcutSaved=false;
00250        }
00251 }
00252 
00253 ScrAction::ActionType ScrAction::actionType()
00254 {
00255        return _actionType;
00256 }
00257 
00258 const int ScrAction::actionInt()
00259 {
00260        return _dataInt;
00261 }
00262 
00263 const double ScrAction::actionDouble()
00264 {
00265        return _dataDouble;
00266 }
00267 
00268 const QString ScrAction::actionQString()
00269 {
00270        return _dataQString;
00271 }
00272 
00273 void ScrAction::setTexts(const QString &newText, bool setTextToo)
00274 {
00275        QAction::setMenuText(newText);
00276        if (setTextToo)
00277               QAction::setText(cleanMenuText());
00278 }
00279 
00280 void ScrAction::toggle()
00281 {
00282        QAction::toggle();
00283        if (fakeToggle)
00284               emit activated();
00285 }