00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <QMenu>
00022 #include <QIcon>
00023 #include "scraction.h"
00024 #include "scribus.h"
00025 #include "scribusdoc.h"
00026
00027 ScrAction::ScrAction( QObject * parent ) : QAction( parent )
00028 {
00029 initScrAction();
00030 }
00031
00032 ScrAction::ScrAction( const QString & menuText, QKeySequence accel, QObject * parent ) : QAction( menuText, parent )
00033 {
00034 setShortcut(accel);
00035 initScrAction();
00036 }
00037
00038 ScrAction::ScrAction( ActionType aType, const QPixmap & icon16, const QPixmap & icon22, const QString & menuText, QKeySequence accel, QObject * parent, int extraInt, double extraDouble, QString extraQString ) : QAction( QIcon(icon16), menuText, parent )
00039 {
00040 setShortcut(accel);
00041 initScrAction();
00042 icon().addPixmap(icon22, QIcon::Normal, QIcon::On);
00043 _actionType=aType;
00044
00045 if (_actionType!=Normal)
00046 connect (this, SIGNAL(triggered()), this, SLOT(triggeredToTriggeredData()));
00047 switch (_actionType)
00048 {
00049 case DataInt:
00050 _dataInt=extraInt;
00051 break;
00052 case DataDouble:
00053 _dataDouble=extraDouble;
00054 break;
00055 case DataQString:
00056 _dataQString=extraQString;
00057 break;
00058 case RecentFile:
00059 _dataQString=extraQString;
00060 break;
00061 case RecentPaste:
00062 _dataQString=extraQString;
00063 break;
00064 case DLL:
00065 pluginID=extraInt;
00066 break;
00067 case Window:
00068 windowID=extraInt;
00069 break;
00070 case RecentScript:
00071 break;
00072 case UnicodeChar:
00073 _dataInt=extraInt;
00074 _dataQString=extraQString;
00075 break;
00076 case Layer:
00077 layerID=extraInt;
00078 break;
00079 case Normal:
00080 default:
00081 break;
00082 }
00083 }
00084
00085 ScrAction::ScrAction( const QPixmap & icon16, const QPixmap & icon22, const QString & menuText, QKeySequence accel, QObject * parent ) : QAction( QIcon(icon16), menuText, parent )
00086 {
00087 setShortcut(accel);
00088 setMenuRole(QAction::NoRole);
00089 initScrAction();
00090 icon().addPixmap(icon22, QIcon::Normal, QIcon::On);
00091 }
00092
00093 void ScrAction::initScrAction()
00094 {
00095 _actionType=ScrAction::Normal;
00096 menuIndex=-1;
00097 savedKeySequence=QKeySequence("");
00098 shortcutSaved=false;
00099 fakeToggle=false;
00100 }
00101
00102 ScrAction::~ScrAction()
00103 {
00104 }
00105
00106 void ScrAction::triggeredToTriggeredData()
00107 {
00108 if (_actionType==ScrAction::DataInt)
00109 emit triggeredData(_dataInt);
00110 if (_actionType==ScrAction::DataDouble)
00111 emit triggeredData(_dataDouble);
00112 if (_actionType==ScrAction::DataQString)
00113 emit triggeredData(_dataQString);
00114 if (_actionType==ScrAction::DLL)
00115 emit triggeredData(pluginID);
00116 if (_actionType==ScrAction::Window)
00117 emit triggeredData(windowID);
00118 if (_actionType==ScrAction::RecentFile)
00119 emit triggeredData(_dataQString);
00120 if (_actionType==ScrAction::RecentPaste)
00121 emit triggeredData(_dataQString);
00122 if (_actionType==ScrAction::RecentScript)
00123 emit triggeredData(text());
00124 if (_actionType==ScrAction::UnicodeChar)
00125 triggeredUnicodeShortcut(_dataQString, _dataInt);
00126 if (_actionType==ScrAction::Layer)
00127 emit triggeredData(layerID);
00128 if (_actionType==ScrAction::ActionDLL)
00129 emit triggeredData(((ScribusMainWindow*)parent())->doc);
00130 }
00131
00132 void ScrAction::toggledToToggledData(bool ison)
00133 {
00134 if (isCheckable())
00135 {
00136 if (_actionType==ScrAction::DataInt)
00137 emit toggledData(ison, _dataInt);
00138 if (_actionType==ScrAction::DataDouble)
00139 emit toggledData(ison, _dataDouble);
00140 if (_actionType==ScrAction::DataQString)
00141 emit toggledData(ison, _dataQString);
00142 if (_actionType==ScrAction::DLL)
00143 emit toggledData(ison, pluginID);
00144 if (_actionType==ScrAction::Window)
00145 emit toggledData(ison, windowID);
00146 if (_actionType==ScrAction::RecentFile)
00147 emit toggledData(ison, _dataQString);
00148 if (_actionType==ScrAction::RecentPaste)
00149 emit toggledData(ison, _dataQString);
00150 if (_actionType==ScrAction::RecentScript)
00151 emit toggledData(ison, text());
00152 if (_actionType==ScrAction::Layer)
00153 emit toggledData(ison, layerID);
00154
00155 }
00156 }
00157
00158 void ScrAction::addedTo ( int index, QMenu * menu )
00159 {
00160 if (menuIndex==-1)
00161 {
00162 menuIndex=index;
00163 popupMenuAddedTo=menu;
00164 }
00165 }
00166
00167 QString ScrAction::cleanMenuText()
00168 {
00169 return text().remove('&').remove("...");
00170 }
00171
00172 int ScrAction::getMenuIndex() const
00173 {
00174 return menuIndex;
00175 }
00176
00177 bool ScrAction::isDLLAction() const
00178 {
00179 return _actionType==ScrAction::DLL;
00180 }
00181
00182 int ScrAction::dllID() const
00183 {
00184 if (_actionType==ScrAction::DLL)
00185 return pluginID;
00186 return -1;
00187 }
00188
00189 void ScrAction::setToggleAction(bool isToggle, bool isFakeToggle)
00190 {
00191 if (_actionType!=Normal)
00192 {
00193 if (isToggle)
00194 connect(this, SIGNAL(toggled(bool)), this, SLOT(toggledToToggledData(bool)));
00195 else
00196 disconnect(this, SIGNAL(toggled(bool)), this, SLOT(toggledToToggledData(bool)));
00197 }
00198 QAction::setCheckable(isToggle);
00199 setChecked(isToggle);
00200 fakeToggle=isFakeToggle;
00201
00202
00203 }
00204
00205 void ScrAction::saveShortcut()
00206 {
00207 if(!shortcutSaved)
00208 {
00209 savedKeySequence=shortcut();
00210 setShortcut(QKeySequence(""));
00211 shortcutSaved=true;
00212 }
00213 }
00214
00215 void ScrAction::restoreShortcut()
00216 {
00217 if (shortcutSaved)
00218 {
00219 setShortcut(savedKeySequence);
00220 savedKeySequence=QKeySequence("");
00221 shortcutSaved=false;
00222 }
00223 }
00224
00225 ScrAction::ActionType ScrAction::actionType()
00226 {
00227 return _actionType;
00228 }
00229
00230 int ScrAction::actionInt() const
00231 {
00232 return _dataInt;
00233 }
00234
00235 double ScrAction::actionDouble() const
00236 {
00237 return _dataDouble;
00238 }
00239
00240 const QString ScrAction::actionQString()
00241 {
00242 return _dataQString;
00243 }
00244
00245 void ScrAction::setTexts(const QString &newText, bool setTextToo)
00246 {
00247 QAction::setText(newText);
00248 if (setTextToo)
00249 QAction::setText(cleanMenuText());
00250 }
00251
00252 void ScrAction::toggle()
00253 {
00254 QAction::toggle();
00255 if (fakeToggle)
00256 emit triggered();
00257 }
00258
00259 void ScrAction::setActionQString(const QString &s)
00260 {
00261 _dataQString=s;
00262 }