Subversion Repositories Scribus

Rev

Rev 23474 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4430 cbradney 1
/*
2
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
to the COPYING file provided with the program. Following this notice may exist
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
for which a new license (GPL+exception) is in place.
6
*/
1209 cbradney 7
/***************************************************************************
8
    begin                : Jan 2005
9
    copyright            : (C) 2005 by Craig Bradney
10
    email                : cbradney@zip.com.au
11
 ***************************************************************************/
12
 
13
/***************************************************************************
14
 *                                                                         *
15
 *   This program is free software; you can redistribute it and/or modify  *
16
 *   it under the terms of the GNU General Public License as published by  *
17
 *   the Free Software Foundation; either version 2 of the License, or     *
18
 *   (at your option) any later version.                                   *
19
 *                                                                         *
20
 ***************************************************************************/
9768 cbradney 21
#include <QMenu>
8528 cbradney 22
#include <QIcon>
20518 craig 23
#include <QSysInfo>
15461 craig 24
#include <QVector>
23474 jghali 25
 
26
#include "iconmanager.h"
1209 cbradney 27
#include "scraction.h"
5781 cbradney 28
#include "scribus.h"
23474 jghali 29
#include "scribusapp.h"
5781 cbradney 30
#include "scribusdoc.h"
1209 cbradney 31
 
9857 cbradney 32
ScrAction::ScrAction( QObject * parent ) : QAction( parent )
1209 cbradney 33
{
1770 cbradney 34
        initScrAction();
1209 cbradney 35
}
36
 
23474 jghali 37
ScrAction::ScrAction(const QString & menuText, QKeySequence accel, QObject * parent ) : QAction(menuText, parent)
1209 cbradney 38
{
9857 cbradney 39
        setShortcut(accel);
1770 cbradney 40
        initScrAction();
1209 cbradney 41
}
42
 
23474 jghali 43
ScrAction::ScrAction(ActionType aType, const QString & menuText, QKeySequence accel, QObject * parent, QVariant d) : QAction(menuText, parent)
17118 craig 44
{
45
        setShortcut(accel);
46
        initScrAction();
19100 craig 47
        setData(d);
48
 
20838 jghali 49
        m_actionType = aType;
50
        if (m_actionType != Normal)
17118 craig 51
                connect (this, SIGNAL(triggered()), this, SLOT(triggeredToTriggeredData()));
52
}
53
 
23474 jghali 54
ScrAction::ScrAction(ActionType aType, const QPixmap& icon16, const QPixmap& icon22, const QString & menuText, QKeySequence accel, QObject * parent, QVariant d)
55
          : QAction(QIcon(icon16), menuText, parent)
1209 cbradney 56
{
9857 cbradney 57
        setShortcut(accel);
1770 cbradney 58
        initScrAction();
15462 craig 59
        icon().addPixmap(icon22, QIcon::Normal, QIcon::On);
19100 craig 60
 
20838 jghali 61
        m_actionType = aType;
19100 craig 62
        setData(d);
20838 jghali 63
        if (m_actionType != Normal)
10728 cbradney 64
                connect (this, SIGNAL(triggered()), this, SLOT(triggeredToTriggeredData()));
1209 cbradney 65
}
66
 
23474 jghali 67
ScrAction::ScrAction(ActionType aType, const QString& icon16Path, const QString& icon22Path, const QString & menuText, QKeySequence accel, QObject * parent, QVariant d)
68
         : QAction(menuText, parent), m_iconPath16(icon16Path), m_iconPath22(icon22Path)
1209 cbradney 69
{
9857 cbradney 70
        setShortcut(accel);
23474 jghali 71
        initScrAction();
72
        loadIcon();
73
 
74
        m_actionType = aType;
75
        setData(d);
76
        if (m_actionType != Normal)
77
                connect (this, SIGNAL(triggered()), this, SLOT(triggeredToTriggeredData()));
78
        if (!m_iconPath16.isEmpty() || !m_iconPath22.isEmpty())
79
                connect(ScQApp, SIGNAL(iconSetChanged()), this, SLOT(loadIcon()));
80
}
81
 
82
ScrAction::ScrAction(const QString& icon16Path, const QString& icon22Path, const QString & menuText, QKeySequence accel, QObject * parent )
83
         : QAction(menuText, parent), m_iconPath16(icon16Path), m_iconPath22(icon22Path)
84
{
85
        setShortcut(accel);
11158 avox 86
        setMenuRole(QAction::NoRole);
1770 cbradney 87
        initScrAction();
23474 jghali 88
        loadIcon();
89
        if (!m_iconPath16.isEmpty() || !m_iconPath22.isEmpty())
90
                connect(ScQApp, SIGNAL(iconSetChanged()), this, SLOT(loadIcon()));
1770 cbradney 91
}
92
 
11791 cbradney 93
 
19100 craig 94
ScrAction::ScrAction(QKeySequence accel, QObject * parent, QVariant d)
11791 cbradney 95
        : QAction( QIcon(QPixmap()), "", parent )
96
{
97
        setShortcut(accel);
98
        initScrAction();
99
        icon().addPixmap(QPixmap(), QIcon::Normal, QIcon::On);
20838 jghali 100
        m_actionType = UnicodeChar;
19100 craig 101
        setData(d);
11791 cbradney 102
        connect (this, SIGNAL(triggered()), this, SLOT(triggeredToTriggeredData()));
103
}
104
 
19100 craig 105
 
1770 cbradney 106
void ScrAction::initScrAction()
107
{
20838 jghali 108
        m_actionType = ScrAction::Normal;
109
        m_menuIndex = -1;
22518 craig 110
        m_popupMenuAddedTo = nullptr;
20838 jghali 111
        m_savedKeySequence = QKeySequence("");
112
        m_shortcutSaved = false;
113
        m_fakeToggle = false;
1209 cbradney 114
}
115
 
116
ScrAction::~ScrAction()
117
{
118
}
119
 
10728 cbradney 120
void ScrAction::triggeredToTriggeredData()
1209 cbradney 121
{
23474 jghali 122
        if (m_actionType == ScrAction::DataInt)
19100 craig 123
                emit triggeredData(data().toInt());
23474 jghali 124
        if (m_actionType == ScrAction::DataDouble)
19100 craig 125
                emit triggeredData(data().toDouble());
23474 jghali 126
        if (m_actionType == ScrAction::DataQString)
19100 craig 127
                emit triggeredData(data().toString());
23474 jghali 128
        if (m_actionType == ScrAction::DLL)
19100 craig 129
                qDebug()<<"if (_actionType==ScrAction::DLL): please fix in ScrAction::triggeredToTriggeredData()";
130
//              emit triggeredData(pluginID);
23474 jghali 131
        if (m_actionType == ScrAction::Window)
19102 craig 132
                emit triggeredData(data().toInt());
23474 jghali 133
        if (m_actionType == ScrAction::RecentFile)
19100 craig 134
                emit triggeredData(data().toString());
23474 jghali 135
        if (m_actionType == ScrAction::RecentPaste)
19100 craig 136
                emit triggeredData(data().toString());
23474 jghali 137
        if (m_actionType == ScrAction::RecentScript)
19150 craig 138
                emit triggeredData(data().toString());
23474 jghali 139
        if (m_actionType == ScrAction::UnicodeChar)
19100 craig 140
                emit triggeredUnicodeShortcut(data().toInt());
23474 jghali 141
        if (m_actionType == ScrAction::Layer)
19101 craig 142
                emit triggeredData(data().toInt());
23474 jghali 143
        if (m_actionType == ScrAction::ActionDLL)
10728 cbradney 144
                emit triggeredData(((ScribusMainWindow*)parent())->doc);
1269 cbradney 145
}
146
 
1525 cbradney 147
void ScrAction::toggledToToggledData(bool ison)
1260 cbradney 148
{
24723 craig 149
 
150
        if (!isCheckable())
151
                return;
152
        if (m_actionType == ScrAction::DataInt)
153
                emit toggledData(ison, data().toInt());
154
        if (m_actionType == ScrAction::DataDouble)
155
                emit toggledData(ison, data().toDouble());
156
        if (m_actionType == ScrAction::DataQString)
157
                emit toggledData(ison, data().toString());
158
        if (m_actionType == ScrAction::DLL)
159
                qDebug()<<"if (_actionType==ScrAction::DLL): please fix in ScrAction::toggledToToggledData(bool ison)";
160
        //                      emit toggledData(ison, pluginID);
161
        if (m_actionType == ScrAction::Window)
162
                emit toggledData(ison, data().toInt());
163
        if (m_actionType == ScrAction::RecentFile)
164
                emit toggledData(ison, data().toString());
165
        if (m_actionType == ScrAction::RecentPaste)
166
                emit toggledData(ison, data().toString());
167
        if (m_actionType == ScrAction::RecentScript)
168
                emit toggledData(ison, text());
169
        if (m_actionType == ScrAction::Layer)
170
                emit toggledData(ison, data().toInt());
171
        // no toggle for UnicodeChar
1260 cbradney 172
}
173
 
23474 jghali 174
void ScrAction::addedTo(int index, QMenu * menu)
1209 cbradney 175
{
23474 jghali 176
        if (m_menuIndex == -1) // Add the first time, not for secondary popups.
1334 cbradney 177
        {
23474 jghali 178
                m_menuIndex = index;
179
                m_popupMenuAddedTo =menu;
1334 cbradney 180
        }
1209 cbradney 181
}
182
 
1230 cbradney 183
QString ScrAction::cleanMenuText()
184
{
10562 fschmid 185
        return text().remove('&').remove("...");
1230 cbradney 186
}
187
 
17723 craig 188
void ScrAction::setToolTipFromTextAndShortcut()
189
{
20519 craig 190
        QString sct(shortcut().toString(QKeySequence::NativeText));
17723 craig 191
        if (sct.isEmpty())
192
                QAction::setToolTip("<qt>" + cleanMenuText() + "</qt>");
193
        else
17724 gpittman 194
                QAction::setToolTip("<qt>" + cleanMenuText() + " (" + sct + ")" + "</qt>");
17723 craig 195
}
196
 
18466 craig 197
void ScrAction::setStatusTextAndShortcut(const QString& statusText)
198
{
20519 craig 199
        QString sct(shortcut().toString(QKeySequence::NativeText));
18466 craig 200
        if (sct.isEmpty())
19009 craig 201
                QAction::setStatusTip(statusText);
18466 craig 202
        else
19009 craig 203
                QAction::setStatusTip(statusText + " (" + sct + ")");
18466 craig 204
}
205
 
10558 cbradney 206
int ScrAction::getMenuIndex() const
1209 cbradney 207
{
20691 craig 208
        return m_menuIndex;
1209 cbradney 209
}
210
 
10558 cbradney 211
bool ScrAction::isDLLAction() const
1260 cbradney 212
{
23474 jghali 213
        return m_actionType == ScrAction::DLL;
1260 cbradney 214
}
1209 cbradney 215
 
10558 cbradney 216
int ScrAction::dllID() const
1260 cbradney 217
{
23474 jghali 218
        if (m_actionType == ScrAction::DLL)
19100 craig 219
                return data().toInt();
1260 cbradney 220
        return -1;
221
}
222
 
4695 cbradney 223
void ScrAction::setToggleAction(bool isToggle, bool isFakeToggle)
1525 cbradney 224
{
23474 jghali 225
        if (m_actionType != Normal)
1525 cbradney 226
        {
2256 cbradney 227
                if (isToggle)
228
                        connect(this, SIGNAL(toggled(bool)), this, SLOT(toggledToToggledData(bool)));
1525 cbradney 229
                else
2256 cbradney 230
                        disconnect(this, SIGNAL(toggled(bool)), this, SLOT(toggledToToggledData(bool)));
1525 cbradney 231
        }
10562 fschmid 232
        QAction::setCheckable(isToggle);
10969 subik 233
        setChecked(isToggle); // set default state of the action's checkbox - PV
23474 jghali 234
        m_fakeToggle = isFakeToggle;
4695 cbradney 235
        //if (fakeToggle)
10725 jghali 236
                //connect(this, toggled(bool), this, triggered());
1525 cbradney 237
}
1770 cbradney 238
 
239
void ScrAction::saveShortcut()
240
{
23474 jghali 241
        if (!m_shortcutSaved)
1770 cbradney 242
        {
23474 jghali 243
                m_savedKeySequence = shortcut();
10562 fschmid 244
                setShortcut(QKeySequence(""));
23474 jghali 245
                m_shortcutSaved = true;
1770 cbradney 246
        }
247
}
248
 
249
void ScrAction::restoreShortcut()
250
{
20691 craig 251
        if (m_shortcutSaved)
1770 cbradney 252
        {
20691 craig 253
                setShortcut(m_savedKeySequence);
254
                m_savedKeySequence=QKeySequence("");
255
                m_shortcutSaved=false;
1770 cbradney 256
        }
257
}
1903 cbradney 258
 
259
ScrAction::ActionType ScrAction::actionType()
260
{
20691 craig 261
        return m_actionType;
1903 cbradney 262
}
263
 
10558 cbradney 264
int ScrAction::actionInt() const
1903 cbradney 265
{
19100 craig 266
        return data().toInt();
1903 cbradney 267
}
268
 
10558 cbradney 269
double ScrAction::actionDouble() const
1903 cbradney 270
{
19100 craig 271
        return data().toDouble();
1903 cbradney 272
}
273
 
274
const QString ScrAction::actionQString()
275
{
19100 craig 276
        return data().toString();
1903 cbradney 277
}
2240 cbradney 278
 
15287 cbradney 279
void ScrAction::setTexts(const QString &newText)//#9114, qt3-qt4 change of behaviour bug:, bool setTextToo)
2240 cbradney 280
{
10427 cbradney 281
        QAction::setText(newText);
15287 cbradney 282
//      if (setTextToo)
283
        QAction::setIconText(cleanMenuText());
2240 cbradney 284
}
4695 cbradney 285
 
286
void ScrAction::toggle()
287
{
288
        QAction::toggle();
20691 craig 289
        if (m_fakeToggle)
10562 fschmid 290
                emit triggered();
4695 cbradney 291
}
10325 cbradney 292
 
293
void ScrAction::setActionQString(const QString &s)
294
{
19100 craig 295
        setData(s);
10369 cbradney 296
}
11791 cbradney 297
 
23474 jghali 298
void ScrAction::loadIcon()
299
{
300
        if (m_iconPath16.isEmpty() && m_iconPath22.isEmpty())
301
                return;
302
 
303
        IconManager& iconManager = IconManager::instance();
304
        QIcon newIcon;
305
 
306
        if (!m_iconPath16.isEmpty())
307
        {
308
                QPixmap pix = iconManager.loadPixmap(m_iconPath16);
309
                if (!pix.isNull())
310
                        newIcon.addPixmap(pix, QIcon::Normal, QIcon::On);
311
        }
312
 
313
        if (!m_iconPath22.isEmpty())
314
        {
315
                QPixmap pix = iconManager.loadPixmap(m_iconPath22);
316
                if (!pix.isNull())
317
                        newIcon.addPixmap(pix, QIcon::Normal, QIcon::On);
318
        }
319
 
320
        setIcon(newIcon);
321
}