File: standardaction.cpp

package info (click to toggle)
ktikz 0.10-4
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,676 kB
  • ctags: 879
  • sloc: cpp: 7,513; xml: 416; perl: 394; sh: 162; makefile: 28
file content (289 lines) | stat: -rw-r--r-- 11,848 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
/***************************************************************************
 *   Copyright (C) 2009 by Glad Deschrijver                                *
 *     <glad.deschrijver@gmail.com>                                        *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, see <http://www.gnu.org/licenses/>.  *
 ***************************************************************************/

#include "standardaction.h"

#ifdef KTIKZ_USE_KDE
#include <KActionCollection>
#include <KRecentFilesAction>
#include <KStandardAction>
#else
#include <QCoreApplication>
#endif
#include "icon.h"

namespace StandardAction
{
#ifdef KTIKZ_USE_KDE
// XXX the following is an ugly hack, but I don't know how to promote a KAction to an Action
Action *copyAction(KAction *action, const QObject *recvr, const char *slot)
{
	Action *newAction = new Action(action->icon(), action->text(), action->parent());
	newAction->setShortcut(action->shortcut());
	newAction->setData(action->data());
	newAction->setObjectName(action->objectName());
	QObject::connect(newAction, SIGNAL(triggered()), recvr, slot);
	Action::actionCollection()->addAction(newAction->objectName(), newAction);
	return newAction;
}

Action *openNew(const QObject *recvr, const char *slot, QObject *parent)
{
	return copyAction(KStandardAction::openNew(recvr, slot, parent), recvr, slot);
}
/*
KAction *openNew(const QObject *recvr, const char *slot, QObject *parent)
{
	KAction *action = KStandardAction::openNew(recvr, slot, parent);
	Action::actionCollection()->addAction(action->objectName(), action);
	return action;
}
*/
Action *open(const QObject *recvr, const char *slot, QObject *parent)
{
	return copyAction(KStandardAction::open(recvr, slot, parent), recvr, slot);
}
RecentFilesAction *openRecent(const QObject *recvr, const char *slot, QObject *parent)
{
	KRecentFilesAction *action = KStandardAction::openRecent(recvr, slot, parent);
	RecentFilesAction *newAction = new RecentFilesAction(action->icon(), action->text(), action->parent());
	newAction->setShortcut(action->shortcut());
	newAction->setData(action->data());
	newAction->setObjectName(action->objectName());
	newAction->setToolBarMode(KRecentFilesAction::MenuMode);
	newAction->setToolButtonPopupMode(QToolButton::MenuButtonPopup);
	QObject::connect(newAction, SIGNAL(urlSelected(Url)), recvr, slot);
	Action::actionCollection()->addAction(newAction->objectName(), newAction);
	return newAction;
}
/*
KRecentFilesAction *openRecent(const QObject *recvr, const char *slot, QObject *parent)
{
	KRecentFilesAction *action = KStandardAction::openRecent(recvr, slot, parent);
	action->setToolBarMode(KRecentFilesAction::MenuMode);
	action->setToolButtonPopupMode(QToolButton::MenuButtonPopup);
	Action::actionCollection()->addAction(action->objectName(), action);
	return action;
}
*/
Action *save(const QObject *recvr, const char *slot, QObject *parent)
{
	return copyAction(KStandardAction::save(recvr, slot, parent), recvr, slot);
}
Action *saveAs(const QObject *recvr, const char *slot, QObject *parent)
{
	return copyAction(KStandardAction::saveAs(recvr, slot, parent), recvr, slot);
}
Action *close(const QObject *recvr, const char *slot, QObject *parent)
{
	return copyAction(KStandardAction::close(recvr, slot, parent), recvr, slot);
}
Action *quit(const QObject *recvr, const char *slot, QObject *parent)
{
	return copyAction(KStandardAction::quit(recvr, slot, parent), recvr, slot);
}
Action *undo(const QObject *recvr, const char *slot, QObject *parent)
{
	return copyAction(KStandardAction::undo(recvr, slot, parent), recvr, slot);
}
Action *redo(const QObject *recvr, const char *slot, QObject *parent)
{
	return copyAction(KStandardAction::redo(recvr, slot, parent), recvr, slot);
}
Action *cut(const QObject *recvr, const char *slot, QObject *parent)
{
	return copyAction(KStandardAction::cut(recvr, slot, parent), recvr, slot);
}
Action *copy(const QObject *recvr, const char *slot, QObject *parent)
{
	return copyAction(KStandardAction::copy(recvr, slot, parent), recvr, slot);
}
Action *paste(const QObject *recvr, const char *slot, QObject *parent)
{
	return copyAction(KStandardAction::paste(recvr, slot, parent), recvr, slot);
}
Action *selectAll(const QObject *recvr, const char *slot, QObject *parent)
{
	return copyAction(KStandardAction::selectAll(recvr, slot, parent), recvr, slot);
}
Action *find(const QObject *recvr, const char *slot, QObject *parent)
{
	return copyAction(KStandardAction::find(recvr, slot, parent), recvr, slot);
}
Action *findNext(const QObject *recvr, const char *slot, QObject *parent)
{
	return copyAction(KStandardAction::findNext(recvr, slot, parent), recvr, slot);
}
Action *findPrev(const QObject *recvr, const char *slot, QObject *parent)
{
	return copyAction(KStandardAction::findPrev(recvr, slot, parent), recvr, slot);
}
Action *replace(const QObject *recvr, const char *slot, QObject *parent)
{
	return copyAction(KStandardAction::replace(recvr, slot, parent), recvr, slot);
}
Action *gotoLine(const QObject *recvr, const char *slot, QObject *parent)
{
	return copyAction(KStandardAction::gotoLine(recvr, slot, parent), recvr, slot);
}
Action *zoomIn(const QObject *recvr, const char *slot, QObject *parent)
{
	return copyAction(KStandardAction::zoomIn(recvr, slot, parent), recvr, slot);
}
Action *zoomOut(const QObject *recvr, const char *slot, QObject *parent)
{
	return copyAction(KStandardAction::zoomOut(recvr, slot, parent), recvr, slot);
}
Action *preferences(const QObject *recvr, const char *slot, QObject *parent)
{
	return copyAction(KStandardAction::preferences(recvr, slot, parent), recvr, slot);
}
#else
Action *createAction(int which, const QObject *recvr, const char *slot, QObject *parent)
{
	QString iconName;
	QString text;
	QKeySequence::StandardKey key = QKeySequence::UnknownKey;

	switch (which)
	{
		case 0: iconName = "document-new"; text = QObject::tr("&New"); key = QKeySequence::New; break;
		case 1: iconName = "document-open"; text = QObject::tr("&Open..."); key = QKeySequence::Open; break;
		case 2: iconName = "document-save"; text = QObject::tr("&Save"); key = QKeySequence::Save; break;
		case 3: iconName = "document-save-as"; text = QObject::tr("Save &As..."); break;
		case 4: iconName = "window-close"; text = QObject::tr("&Close"); key = QKeySequence::Close; break;
		case 5: iconName = "application-exit"; text = QObject::tr("&Quit"); break;
		case 6: iconName = "edit-undo"; text = QObject::tr("&Undo"); key = QKeySequence::Undo; break;
		case 7: iconName = "edit-redo"; text = QObject::tr("Re&do"); key = QKeySequence::Redo; break;
		case 8: iconName = "edit-cut"; text = QObject::tr("Cu&t"); key = QKeySequence::Cut; break;
		case 9: iconName = "edit-copy"; text = QObject::tr("&Copy"); key = QKeySequence::Copy; break;
		case 10: iconName = "edit-paste"; text = QObject::tr("&Paste"); key = QKeySequence::Paste; break;
		case 11: text = QObject::tr("Select &All"); key = QKeySequence::SelectAll; break;
		case 12: iconName = "edit-find"; text = QObject::tr("&Find..."); key = QKeySequence::Find; break;
		case 13: iconName = "go-down"; text = QObject::tr("Find &Next"); key = QKeySequence::FindNext; break;
		case 14: iconName = "go-up"; text = QObject::tr("Find Pre&vious"); key = QKeySequence::FindPrevious; break;
		case 15: text = QObject::tr("&Replace..."); key = QKeySequence::Replace; break;
		case 16: iconName = "go-jump"; text = QObject::tr("&Go to Line..."); break;
		case 17: iconName = "zoom-in"; text = QObject::tr("Zoom &In"); key = QKeySequence::ZoomIn; break;
		case 18: iconName = "zoom-out"; text = QObject::tr("Zoom &Out"); key = QKeySequence::ZoomOut; break;
		case 19: iconName = "configure"; text = QObject::tr("&Configure %1...").arg(QCoreApplication::applicationName()); break;
	}

	Action *action;
	if (!iconName.isEmpty())
		action = new Action(Icon(iconName), text, parent);
	else
		action = new Action(text, parent);

	if (which == 5)
		action->setShortcut(QObject::tr("Ctrl+Q", "File|Quit"));
	else if (which == 16)
		action->setShortcut(QObject::tr("Ctrl+G", "Edit|Go to Line"));
	else if (which != 3 && which != 19)
		action->setShortcut(key);
	QObject::connect(action, SIGNAL(triggered()), recvr, slot);
	return action;
}
Action *openNew(const QObject *recvr, const char *slot, QObject *parent)
{
	return createAction(0, recvr, slot, parent);
}
Action *open(const QObject *recvr, const char *slot, QObject *parent)
{
	return createAction(1, recvr, slot, parent);
}
RecentFilesAction *openRecent(const QObject *recvr, const char *slot, QObject *parent)
{
	RecentFilesAction *action = new RecentFilesAction(Icon("document-open-recent"), QObject::tr("&Open Recent"), parent);
	QObject::connect(action, SIGNAL(urlSelected(Url)), recvr, slot);
	return action;
}
Action *save(const QObject *recvr, const char *slot, QObject *parent)
{
	return createAction(2, recvr, slot, parent);
}
Action *saveAs(const QObject *recvr, const char *slot, QObject *parent)
{
	return createAction(3, recvr, slot, parent);
}
Action *close(const QObject *recvr, const char *slot, QObject *parent)
{
	return createAction(4, recvr, slot, parent);
}
Action *quit(const QObject *recvr, const char *slot, QObject *parent)
{
	return createAction(5, recvr, slot, parent);
}
Action *undo(const QObject *recvr, const char *slot, QObject *parent)
{
	return createAction(6, recvr, slot, parent);
}
Action *redo(const QObject *recvr, const char *slot, QObject *parent)
{
	return createAction(7, recvr, slot, parent);
}
Action *cut(const QObject *recvr, const char *slot, QObject *parent)
{
	return createAction(8, recvr, slot, parent);
}
Action *copy(const QObject *recvr, const char *slot, QObject *parent)
{
	return createAction(9, recvr, slot, parent);
}
Action *paste(const QObject *recvr, const char *slot, QObject *parent)
{
	return createAction(10, recvr, slot, parent);
}
Action *selectAll(const QObject *recvr, const char *slot, QObject *parent)
{
	return createAction(11, recvr, slot, parent);
}
Action *find(const QObject *recvr, const char *slot, QObject *parent)
{
	return createAction(12, recvr, slot, parent);
}
Action *findNext(const QObject *recvr, const char *slot, QObject *parent)
{
	return createAction(13, recvr, slot, parent);
}
Action *findPrev(const QObject *recvr, const char *slot, QObject *parent)
{
	return createAction(14, recvr, slot, parent);
}
Action *replace(const QObject *recvr, const char *slot, QObject *parent)
{
	return createAction(15, recvr, slot, parent);
}
Action *gotoLine(const QObject *recvr, const char *slot, QObject *parent)
{
	return createAction(16, recvr, slot, parent);
}
Action *zoomIn(const QObject *recvr, const char *slot, QObject *parent)
{
	return createAction(17, recvr, slot, parent);
}
Action *zoomOut(const QObject *recvr, const char *slot, QObject *parent)
{
	return createAction(18, recvr, slot, parent);
}
Action *preferences(const QObject *recvr, const char *slot, QObject *parent)
{
	return createAction(19, recvr, slot, parent);
}
#endif
}