| 1 | /* |
| 2 | This file is part of the KDE libraries |
| 3 | SPDX-FileCopyrightText: 1999, 2000 Kurt Granroth <granroth@kde.org> |
| 4 | |
| 5 | SPDX-License-Identifier: LGPL-2.0-only |
| 6 | */ |
| 7 | |
| 8 | #include "kstandardaction.h" |
| 9 | #include "kopenaction_p.h" |
| 10 | #include "kstandardaction_p.h" |
| 11 | #include "moc_kstandardaction_p.cpp" |
| 12 | |
| 13 | #include <KAboutData> |
| 14 | #include <KAcceleratorManager> |
| 15 | #include <KLocalizedString> |
| 16 | #include <KStandardShortcutWatcher> |
| 17 | #include <QGuiApplication> |
| 18 | #include <QLayout> |
| 19 | #include <QMainWindow> |
| 20 | #include <QMenuBar> |
| 21 | |
| 22 | namespace KStandardAction |
| 23 | { |
| 24 | AutomaticAction::AutomaticAction(const QIcon &icon, |
| 25 | const QString &text, |
| 26 | KStandardShortcut::StandardShortcut standardShortcut, |
| 27 | const char *slot, |
| 28 | QObject *parent) |
| 29 | : QAction(parent) |
| 30 | { |
| 31 | setText(text); |
| 32 | setIcon(icon); |
| 33 | |
| 34 | const QList<QKeySequence> shortcut = KStandardShortcut::shortcut(id: standardShortcut); |
| 35 | setShortcuts(shortcut); |
| 36 | setProperty(name: "defaultShortcuts" , value: QVariant::fromValue(value: shortcut)); |
| 37 | connect(sender: KStandardShortcut::shortcutWatcher(), |
| 38 | signal: &KStandardShortcut::StandardShortcutWatcher::shortcutChanged, |
| 39 | context: this, |
| 40 | slot: [standardShortcut, this](KStandardShortcut::StandardShortcut id, const QList<QKeySequence> &newShortcut) { |
| 41 | if (id != standardShortcut) { |
| 42 | return; |
| 43 | } |
| 44 | setShortcuts(newShortcut); |
| 45 | setProperty(name: "defaultShortcuts" , value: QVariant::fromValue(value: newShortcut)); |
| 46 | }); |
| 47 | |
| 48 | connect(sender: this, SIGNAL(triggered()), receiver: this, member: slot); |
| 49 | } |
| 50 | |
| 51 | QStringList stdNames() |
| 52 | { |
| 53 | return internal_stdNames(); |
| 54 | } |
| 55 | |
| 56 | QList<StandardAction> actionIds() |
| 57 | { |
| 58 | QList<StandardAction> result; |
| 59 | |
| 60 | for (uint i = 0; g_rgActionInfo[i].id != ActionNone; i++) { |
| 61 | result.append(t: g_rgActionInfo[i].id); |
| 62 | } |
| 63 | |
| 64 | return result; |
| 65 | } |
| 66 | |
| 67 | KStandardShortcut::StandardShortcut shortcutForActionId(StandardAction id) |
| 68 | { |
| 69 | const KStandardActionInfo *pInfo = infoPtr(id); |
| 70 | return (pInfo) ? pInfo->idAccel : KStandardShortcut::AccelNone; |
| 71 | } |
| 72 | |
| 73 | class ShowMenubarActionFilter : public QObject |
| 74 | { |
| 75 | public: |
| 76 | ShowMenubarActionFilter(QAction *parent) |
| 77 | : QObject(parent) |
| 78 | , wasNative(false) |
| 79 | , wasChecked(false) |
| 80 | , wasVisible(false) |
| 81 | { |
| 82 | } |
| 83 | |
| 84 | bool eventFilter(QObject * /*watched*/, QEvent *e) override |
| 85 | { |
| 86 | if (e->type() == QEvent::Show) { |
| 87 | updateAction(); |
| 88 | } |
| 89 | return false; |
| 90 | } |
| 91 | |
| 92 | void updateAction() |
| 93 | { |
| 94 | bool = true; |
| 95 | bool = false; |
| 96 | const auto lstWidget = qApp->topLevelWidgets(); |
| 97 | for (QWidget *w : lstWidget) { |
| 98 | QMainWindow *mw = qobject_cast<QMainWindow *>(object: w); |
| 99 | if (mw) { |
| 100 | mw->installEventFilter(filterObj: this); // this is just in case a new main window appeared |
| 101 | // if we were filtering it already it is almost a noop |
| 102 | if (mw->layout() && mw->layout()->menuBar()) { |
| 103 | QMenuBar *mb = qobject_cast<QMenuBar *>(object: mw->layout()->menuBar()); |
| 104 | if (mb) { |
| 105 | hasAnyMenuBar = true; |
| 106 | if (!mb->isNativeMenuBar()) { |
| 107 | allMenuBarsNative = false; |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | if (!hasAnyMenuBar) { |
| 115 | return; |
| 116 | } |
| 117 | |
| 118 | QAction * = static_cast<QAction *>(parent()); |
| 119 | if (allMenuBarsNative && !wasNative) { |
| 120 | wasNative = true; |
| 121 | wasChecked = showMenubarAction->isChecked(); |
| 122 | wasVisible = showMenubarAction->isVisible(); |
| 123 | |
| 124 | showMenubarAction->setChecked(true); |
| 125 | showMenubarAction->setVisible(false); |
| 126 | } else if (!allMenuBarsNative && wasNative) { |
| 127 | showMenubarAction->setChecked(wasChecked); |
| 128 | showMenubarAction->setVisible(wasVisible); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | bool wasNative; |
| 133 | bool wasChecked; |
| 134 | bool wasVisible; |
| 135 | }; |
| 136 | |
| 137 | QAction *_k_createInternal(StandardAction id, QObject *parent) |
| 138 | { |
| 139 | static bool stdNamesInitialized = false; |
| 140 | |
| 141 | if (!stdNamesInitialized) { |
| 142 | KAcceleratorManager::addStandardActionNames(names: stdNames()); |
| 143 | stdNamesInitialized = true; |
| 144 | } |
| 145 | |
| 146 | QAction *pAction = nullptr; |
| 147 | const KStandardActionInfo *pInfo = infoPtr(id); |
| 148 | |
| 149 | // qCDebug(KCONFIG_WIDGETS_LOG) << "KStandardAction::create( " << id << "=" << (pInfo ? pInfo->psName : (const char*)0) << ", " << parent << " )"; // ellis |
| 150 | |
| 151 | if (pInfo) { |
| 152 | QString sLabel; |
| 153 | QString iconName = pInfo->psIconName.toString(); |
| 154 | |
| 155 | switch (id) { |
| 156 | case Back: |
| 157 | sLabel = i18nc("go back" , "&Back" ); |
| 158 | if (QGuiApplication::isRightToLeft()) { |
| 159 | iconName = QStringLiteral("go-next" ); |
| 160 | } |
| 161 | break; |
| 162 | |
| 163 | case Forward: |
| 164 | sLabel = i18nc("go forward" , "&Forward" ); |
| 165 | if (QGuiApplication::isRightToLeft()) { |
| 166 | iconName = QStringLiteral("go-previous" ); |
| 167 | } |
| 168 | break; |
| 169 | |
| 170 | case Home: |
| 171 | sLabel = i18nc("home page" , "&Home" ); |
| 172 | break; |
| 173 | case Preferences: |
| 174 | case AboutApp: |
| 175 | case HelpContents: { |
| 176 | QString appDisplayName = QGuiApplication::applicationDisplayName(); |
| 177 | if (appDisplayName.isEmpty()) { |
| 178 | appDisplayName = QCoreApplication::applicationName(); |
| 179 | } |
| 180 | sLabel = pInfo->psLabel.subs(a: appDisplayName).toString(); |
| 181 | } break; |
| 182 | default: |
| 183 | sLabel = pInfo->psLabel.toString(); |
| 184 | } |
| 185 | |
| 186 | if (QGuiApplication::isRightToLeft()) { |
| 187 | switch (id) { |
| 188 | case Prior: |
| 189 | iconName = QStringLiteral("go-next-view-page" ); |
| 190 | break; |
| 191 | case Next: |
| 192 | iconName = QStringLiteral("go-previous-view-page" ); |
| 193 | break; |
| 194 | case FirstPage: |
| 195 | iconName = QStringLiteral("go-last-view-page" ); |
| 196 | break; |
| 197 | case LastPage: |
| 198 | iconName = QStringLiteral("go-first-view-page" ); |
| 199 | break; |
| 200 | case DocumentBack: |
| 201 | iconName = QStringLiteral("go-next" ); |
| 202 | break; |
| 203 | case DocumentForward: |
| 204 | iconName = QStringLiteral("go-previous" ); |
| 205 | break; |
| 206 | default: |
| 207 | break; |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | if (id == Donate) { |
| 212 | const QString currencyCode = QLocale().currencySymbol(QLocale::CurrencyIsoCode).toLower(); |
| 213 | if (!currencyCode.isEmpty()) { |
| 214 | iconName = QStringLiteral("help-donate-%1" ).arg(a: currencyCode); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | QIcon icon = iconName.isEmpty() ? QIcon() : QIcon::fromTheme(name: iconName); |
| 219 | |
| 220 | switch (id) { |
| 221 | case Open: |
| 222 | pAction = new KOpenAction(parent); |
| 223 | break; |
| 224 | case OpenRecent: |
| 225 | pAction = new KRecentFilesAction(parent); |
| 226 | break; |
| 227 | case ShowMenubar: { |
| 228 | pAction = new KToggleAction(parent); |
| 229 | pAction->setWhatsThis( |
| 230 | i18n("Show Menubar<p>" |
| 231 | "Shows the menubar again after it has been hidden</p>" )); |
| 232 | pAction->setChecked(true); |
| 233 | |
| 234 | ShowMenubarActionFilter *mf = new ShowMenubarActionFilter(pAction); |
| 235 | const auto lstWidget = qApp->topLevelWidgets(); |
| 236 | for (QWidget *w : lstWidget) { |
| 237 | if (qobject_cast<QMainWindow *>(object: w)) { |
| 238 | w->installEventFilter(filterObj: mf); |
| 239 | } |
| 240 | } |
| 241 | mf->updateAction(); |
| 242 | break; |
| 243 | } |
| 244 | case ShowToolbar: |
| 245 | pAction = new KToggleAction(parent); |
| 246 | pAction->setChecked(true); |
| 247 | break; |
| 248 | case ShowStatusbar: |
| 249 | pAction = new KToggleAction(parent); |
| 250 | pAction->setWhatsThis( |
| 251 | i18n("Show Statusbar<p>" |
| 252 | "Shows the statusbar, which is the bar at the bottom of the window used for status information.</p>" )); |
| 253 | pAction->setChecked(true); |
| 254 | break; |
| 255 | case FullScreen: |
| 256 | pAction = new KToggleFullScreenAction(parent); |
| 257 | pAction->setCheckable(true); |
| 258 | break; |
| 259 | // Same as default, but with the app icon |
| 260 | case AboutApp: { |
| 261 | pAction = new QAction(parent); |
| 262 | icon = qApp->windowIcon(); |
| 263 | break; |
| 264 | } |
| 265 | case HamburgerMenu: { |
| 266 | pAction = new KHamburgerMenu(parent); |
| 267 | break; |
| 268 | } |
| 269 | |
| 270 | default: |
| 271 | pAction = new QAction(parent); |
| 272 | break; |
| 273 | } |
| 274 | |
| 275 | // Set the text before setting the MenuRole, as on OS X setText will do some heuristic role guessing. |
| 276 | // This ensures user menu items get the intended role out of the list below. |
| 277 | pAction->setText(sLabel); |
| 278 | |
| 279 | switch (id) { |
| 280 | case Quit: |
| 281 | pAction->setMenuRole(QAction::QuitRole); |
| 282 | break; |
| 283 | |
| 284 | case Preferences: |
| 285 | pAction->setMenuRole(QAction::PreferencesRole); |
| 286 | break; |
| 287 | |
| 288 | case AboutApp: |
| 289 | pAction->setMenuRole(QAction::AboutRole); |
| 290 | break; |
| 291 | |
| 292 | default: |
| 293 | pAction->setMenuRole(QAction::NoRole); |
| 294 | break; |
| 295 | } |
| 296 | |
| 297 | if (!pInfo->psToolTip.isEmpty()) { |
| 298 | pAction->setToolTip(pInfo->psToolTip.toString()); |
| 299 | } |
| 300 | pAction->setIcon(icon); |
| 301 | |
| 302 | QList<QKeySequence> cut = KStandardShortcut::shortcut(id: pInfo->idAccel); |
| 303 | if (!cut.isEmpty()) { |
| 304 | // emulate KActionCollection::setDefaultShortcuts to allow the use of "configure shortcuts" |
| 305 | pAction->setShortcuts(cut); |
| 306 | pAction->setProperty(name: "defaultShortcuts" , value: QVariant::fromValue(value: cut)); |
| 307 | } |
| 308 | pAction->connect(sender: KStandardShortcut::shortcutWatcher(), |
| 309 | signal: &KStandardShortcut::StandardShortcutWatcher::shortcutChanged, |
| 310 | context: pAction, |
| 311 | slot: [pAction, shortcut = pInfo->idAccel](KStandardShortcut::StandardShortcut id, const QList<QKeySequence> &newShortcut) { |
| 312 | if (id != shortcut) { |
| 313 | return; |
| 314 | } |
| 315 | pAction->setShortcuts(newShortcut); |
| 316 | pAction->setProperty(name: "defaultShortcuts" , value: QVariant::fromValue(value: newShortcut)); |
| 317 | }); |
| 318 | |
| 319 | pAction->setObjectName(pInfo->psName.toString()); |
| 320 | } |
| 321 | |
| 322 | if (pAction && parent && parent->inherits(classname: "KActionCollection" )) { |
| 323 | QMetaObject::invokeMethod(obj: parent, member: "addAction" , Q_ARG(QString, pAction->objectName()), Q_ARG(QAction *, pAction)); |
| 324 | } |
| 325 | |
| 326 | return pAction; |
| 327 | } |
| 328 | |
| 329 | QAction *create(StandardAction id, const QObject *recvr, const char *slot, QObject *parent) |
| 330 | { |
| 331 | QAction *pAction = _k_createInternal(id, parent); |
| 332 | if (recvr && slot) { |
| 333 | if (id == OpenRecent) { |
| 334 | // FIXME QAction port: probably a good idea to find a cleaner way to do this |
| 335 | // Open Recent is a special case - provide the selected URL |
| 336 | QObject::connect(sender: pAction, SIGNAL(urlSelected(QUrl)), receiver: recvr, member: slot); |
| 337 | } else if (id == ConfigureToolbars) { // #200815 |
| 338 | QObject::connect(sender: pAction, SIGNAL(triggered(bool)), receiver: recvr, member: slot, Qt::QueuedConnection); |
| 339 | } else { |
| 340 | QObject::connect(sender: pAction, SIGNAL(triggered(bool)), receiver: recvr, member: slot); |
| 341 | } |
| 342 | } |
| 343 | return pAction; |
| 344 | } |
| 345 | |
| 346 | QString name(StandardAction id) |
| 347 | { |
| 348 | const KStandardActionInfo *pInfo = infoPtr(id); |
| 349 | return (pInfo) ? pInfo->psName.toString() : QString(); |
| 350 | } |
| 351 | |
| 352 | QAction *openNew(const QObject *recvr, const char *slot, QObject *parent) |
| 353 | { |
| 354 | return KStandardAction::create(id: New, recvr, slot, parent); |
| 355 | } |
| 356 | |
| 357 | QAction *open(const QObject *recvr, const char *slot, QObject *parent) |
| 358 | { |
| 359 | return KStandardAction::create(id: Open, recvr, slot, parent); |
| 360 | } |
| 361 | |
| 362 | KRecentFilesAction *openRecent(const QObject *recvr, const char *slot, QObject *parent) |
| 363 | { |
| 364 | return (KRecentFilesAction *)KStandardAction::create(id: OpenRecent, recvr, slot, parent); |
| 365 | } |
| 366 | |
| 367 | QAction *save(const QObject *recvr, const char *slot, QObject *parent) |
| 368 | { |
| 369 | return KStandardAction::create(id: Save, recvr, slot, parent); |
| 370 | } |
| 371 | |
| 372 | QAction *saveAs(const QObject *recvr, const char *slot, QObject *parent) |
| 373 | { |
| 374 | return KStandardAction::create(id: SaveAs, recvr, slot, parent); |
| 375 | } |
| 376 | |
| 377 | QAction *revert(const QObject *recvr, const char *slot, QObject *parent) |
| 378 | { |
| 379 | return KStandardAction::create(id: Revert, recvr, slot, parent); |
| 380 | } |
| 381 | |
| 382 | QAction *print(const QObject *recvr, const char *slot, QObject *parent) |
| 383 | { |
| 384 | return KStandardAction::create(id: Print, recvr, slot, parent); |
| 385 | } |
| 386 | |
| 387 | QAction *printPreview(const QObject *recvr, const char *slot, QObject *parent) |
| 388 | { |
| 389 | return KStandardAction::create(id: PrintPreview, recvr, slot, parent); |
| 390 | } |
| 391 | |
| 392 | QAction *close(const QObject *recvr, const char *slot, QObject *parent) |
| 393 | { |
| 394 | return KStandardAction::create(id: Close, recvr, slot, parent); |
| 395 | } |
| 396 | |
| 397 | QAction *mail(const QObject *recvr, const char *slot, QObject *parent) |
| 398 | { |
| 399 | return KStandardAction::create(id: Mail, recvr, slot, parent); |
| 400 | } |
| 401 | |
| 402 | QAction *quit(const QObject *recvr, const char *slot, QObject *parent) |
| 403 | { |
| 404 | return KStandardAction::create(id: Quit, recvr, slot, parent); |
| 405 | } |
| 406 | |
| 407 | QAction *undo(const QObject *recvr, const char *slot, QObject *parent) |
| 408 | { |
| 409 | return KStandardAction::create(id: Undo, recvr, slot, parent); |
| 410 | } |
| 411 | |
| 412 | QAction *redo(const QObject *recvr, const char *slot, QObject *parent) |
| 413 | { |
| 414 | return KStandardAction::create(id: Redo, recvr, slot, parent); |
| 415 | } |
| 416 | |
| 417 | QAction *cut(const QObject *recvr, const char *slot, QObject *parent) |
| 418 | { |
| 419 | return KStandardAction::create(id: Cut, recvr, slot, parent); |
| 420 | } |
| 421 | |
| 422 | QAction *copy(const QObject *recvr, const char *slot, QObject *parent) |
| 423 | { |
| 424 | return KStandardAction::create(id: Copy, recvr, slot, parent); |
| 425 | } |
| 426 | |
| 427 | QAction *paste(const QObject *recvr, const char *slot, QObject *parent) |
| 428 | { |
| 429 | return KStandardAction::create(id: Paste, recvr, slot, parent); |
| 430 | } |
| 431 | |
| 432 | QAction *clear(const QObject *recvr, const char *slot, QObject *parent) |
| 433 | { |
| 434 | return KStandardAction::create(id: Clear, recvr, slot, parent); |
| 435 | } |
| 436 | |
| 437 | QAction *selectAll(const QObject *recvr, const char *slot, QObject *parent) |
| 438 | { |
| 439 | return KStandardAction::create(id: SelectAll, recvr, slot, parent); |
| 440 | } |
| 441 | |
| 442 | QAction *deselect(const QObject *recvr, const char *slot, QObject *parent) |
| 443 | { |
| 444 | return KStandardAction::create(id: Deselect, recvr, slot, parent); |
| 445 | } |
| 446 | |
| 447 | QAction *find(const QObject *recvr, const char *slot, QObject *parent) |
| 448 | { |
| 449 | return KStandardAction::create(id: Find, recvr, slot, parent); |
| 450 | } |
| 451 | |
| 452 | QAction *findNext(const QObject *recvr, const char *slot, QObject *parent) |
| 453 | { |
| 454 | return KStandardAction::create(id: FindNext, recvr, slot, parent); |
| 455 | } |
| 456 | |
| 457 | QAction *findPrev(const QObject *recvr, const char *slot, QObject *parent) |
| 458 | { |
| 459 | return KStandardAction::create(id: FindPrev, recvr, slot, parent); |
| 460 | } |
| 461 | |
| 462 | QAction *replace(const QObject *recvr, const char *slot, QObject *parent) |
| 463 | { |
| 464 | return KStandardAction::create(id: Replace, recvr, slot, parent); |
| 465 | } |
| 466 | |
| 467 | QAction *actualSize(const QObject *recvr, const char *slot, QObject *parent) |
| 468 | { |
| 469 | return KStandardAction::create(id: ActualSize, recvr, slot, parent); |
| 470 | } |
| 471 | |
| 472 | QAction *fitToPage(const QObject *recvr, const char *slot, QObject *parent) |
| 473 | { |
| 474 | return KStandardAction::create(id: FitToPage, recvr, slot, parent); |
| 475 | } |
| 476 | |
| 477 | QAction *fitToWidth(const QObject *recvr, const char *slot, QObject *parent) |
| 478 | { |
| 479 | return KStandardAction::create(id: FitToWidth, recvr, slot, parent); |
| 480 | } |
| 481 | |
| 482 | QAction *fitToHeight(const QObject *recvr, const char *slot, QObject *parent) |
| 483 | { |
| 484 | return KStandardAction::create(id: FitToHeight, recvr, slot, parent); |
| 485 | } |
| 486 | |
| 487 | QAction *zoomIn(const QObject *recvr, const char *slot, QObject *parent) |
| 488 | { |
| 489 | return KStandardAction::create(id: ZoomIn, recvr, slot, parent); |
| 490 | } |
| 491 | |
| 492 | QAction *zoomOut(const QObject *recvr, const char *slot, QObject *parent) |
| 493 | { |
| 494 | return KStandardAction::create(id: ZoomOut, recvr, slot, parent); |
| 495 | } |
| 496 | |
| 497 | QAction *zoom(const QObject *recvr, const char *slot, QObject *parent) |
| 498 | { |
| 499 | return KStandardAction::create(id: Zoom, recvr, slot, parent); |
| 500 | } |
| 501 | |
| 502 | QAction *redisplay(const QObject *recvr, const char *slot, QObject *parent) |
| 503 | { |
| 504 | return KStandardAction::create(id: Redisplay, recvr, slot, parent); |
| 505 | } |
| 506 | |
| 507 | QAction *up(const QObject *recvr, const char *slot, QObject *parent) |
| 508 | { |
| 509 | return KStandardAction::create(id: Up, recvr, slot, parent); |
| 510 | } |
| 511 | |
| 512 | QAction *back(const QObject *recvr, const char *slot, QObject *parent) |
| 513 | { |
| 514 | return KStandardAction::create(id: Back, recvr, slot, parent); |
| 515 | } |
| 516 | |
| 517 | QAction *forward(const QObject *recvr, const char *slot, QObject *parent) |
| 518 | { |
| 519 | return KStandardAction::create(id: Forward, recvr, slot, parent); |
| 520 | } |
| 521 | |
| 522 | QAction *home(const QObject *recvr, const char *slot, QObject *parent) |
| 523 | { |
| 524 | return KStandardAction::create(id: Home, recvr, slot, parent); |
| 525 | } |
| 526 | |
| 527 | QAction *prior(const QObject *recvr, const char *slot, QObject *parent) |
| 528 | { |
| 529 | return KStandardAction::create(id: Prior, recvr, slot, parent); |
| 530 | } |
| 531 | |
| 532 | QAction *next(const QObject *recvr, const char *slot, QObject *parent) |
| 533 | { |
| 534 | return KStandardAction::create(id: Next, recvr, slot, parent); |
| 535 | } |
| 536 | |
| 537 | QAction *goTo(const QObject *recvr, const char *slot, QObject *parent) |
| 538 | { |
| 539 | return KStandardAction::create(id: Goto, recvr, slot, parent); |
| 540 | } |
| 541 | |
| 542 | QAction *gotoPage(const QObject *recvr, const char *slot, QObject *parent) |
| 543 | { |
| 544 | return KStandardAction::create(id: GotoPage, recvr, slot, parent); |
| 545 | } |
| 546 | |
| 547 | QAction *gotoLine(const QObject *recvr, const char *slot, QObject *parent) |
| 548 | { |
| 549 | return KStandardAction::create(id: GotoLine, recvr, slot, parent); |
| 550 | } |
| 551 | |
| 552 | QAction *firstPage(const QObject *recvr, const char *slot, QObject *parent) |
| 553 | { |
| 554 | return KStandardAction::create(id: FirstPage, recvr, slot, parent); |
| 555 | } |
| 556 | |
| 557 | QAction *lastPage(const QObject *recvr, const char *slot, QObject *parent) |
| 558 | { |
| 559 | return KStandardAction::create(id: LastPage, recvr, slot, parent); |
| 560 | } |
| 561 | |
| 562 | QAction *documentBack(const QObject *recvr, const char *slot, QObject *parent) |
| 563 | { |
| 564 | return KStandardAction::create(id: DocumentBack, recvr, slot, parent); |
| 565 | } |
| 566 | |
| 567 | QAction *documentForward(const QObject *recvr, const char *slot, QObject *parent) |
| 568 | { |
| 569 | return KStandardAction::create(id: DocumentForward, recvr, slot, parent); |
| 570 | } |
| 571 | |
| 572 | QAction *addBookmark(const QObject *recvr, const char *slot, QObject *parent) |
| 573 | { |
| 574 | return KStandardAction::create(id: AddBookmark, recvr, slot, parent); |
| 575 | } |
| 576 | |
| 577 | QAction *editBookmarks(const QObject *recvr, const char *slot, QObject *parent) |
| 578 | { |
| 579 | return KStandardAction::create(id: EditBookmarks, recvr, slot, parent); |
| 580 | } |
| 581 | |
| 582 | QAction *spelling(const QObject *recvr, const char *slot, QObject *parent) |
| 583 | { |
| 584 | return KStandardAction::create(id: Spelling, recvr, slot, parent); |
| 585 | } |
| 586 | |
| 587 | static QAction *buildAutomaticAction(QObject *parent, StandardAction id, const char *slot) |
| 588 | { |
| 589 | const KStandardActionInfo *p = infoPtr(id); |
| 590 | if (!p) { |
| 591 | return nullptr; |
| 592 | } |
| 593 | |
| 594 | AutomaticAction *action = new AutomaticAction(QIcon::fromTheme(name: p->psIconName.toString()), p->psLabel.toString(), p->idAccel, slot, parent); |
| 595 | |
| 596 | action->setObjectName(p->psName.toString()); |
| 597 | if (!p->psToolTip.isEmpty()) { |
| 598 | action->setToolTip(p->psToolTip.toString()); |
| 599 | } |
| 600 | |
| 601 | if (parent && parent->inherits(classname: "KActionCollection" )) { |
| 602 | QMetaObject::invokeMethod(obj: parent, member: "addAction" , Q_ARG(QString, action->objectName()), Q_ARG(QAction *, action)); |
| 603 | } |
| 604 | |
| 605 | return action; |
| 606 | } |
| 607 | |
| 608 | QAction *cut(QObject *parent) |
| 609 | { |
| 610 | return buildAutomaticAction(parent, id: Cut, SLOT(cut())); |
| 611 | } |
| 612 | |
| 613 | QAction *copy(QObject *parent) |
| 614 | { |
| 615 | return buildAutomaticAction(parent, id: Copy, SLOT(copy())); |
| 616 | } |
| 617 | |
| 618 | QAction *paste(QObject *parent) |
| 619 | { |
| 620 | return buildAutomaticAction(parent, id: Paste, SLOT(paste())); |
| 621 | } |
| 622 | |
| 623 | QAction *clear(QObject *parent) |
| 624 | { |
| 625 | return buildAutomaticAction(parent, id: Clear, SLOT(clear())); |
| 626 | } |
| 627 | |
| 628 | QAction *selectAll(QObject *parent) |
| 629 | { |
| 630 | return buildAutomaticAction(parent, id: SelectAll, SLOT(selectAll())); |
| 631 | } |
| 632 | |
| 633 | KToggleAction *showMenubar(const QObject *recvr, const char *slot, QObject *parent) |
| 634 | { |
| 635 | QAction *ret = KStandardAction::create(id: ShowMenubar, recvr, slot, parent); |
| 636 | Q_ASSERT(qobject_cast<KToggleAction *>(ret)); |
| 637 | return static_cast<KToggleAction *>(ret); |
| 638 | } |
| 639 | |
| 640 | KToggleAction *showStatusbar(const QObject *recvr, const char *slot, QObject *parent) |
| 641 | { |
| 642 | QAction *ret = KStandardAction::create(id: ShowStatusbar, recvr, slot, parent); |
| 643 | Q_ASSERT(qobject_cast<KToggleAction *>(ret)); |
| 644 | return static_cast<KToggleAction *>(ret); |
| 645 | } |
| 646 | |
| 647 | KToggleFullScreenAction *fullScreen(const QObject *recvr, const char *slot, QWidget *window, QObject *parent) |
| 648 | { |
| 649 | KToggleFullScreenAction *ret; |
| 650 | ret = static_cast<KToggleFullScreenAction *>(KStandardAction::create(id: FullScreen, recvr, slot, parent)); |
| 651 | ret->setWindow(window); |
| 652 | |
| 653 | return ret; |
| 654 | } |
| 655 | |
| 656 | QAction *keyBindings(const QObject *recvr, const char *slot, QObject *parent) |
| 657 | { |
| 658 | return KStandardAction::create(id: KeyBindings, recvr, slot, parent); |
| 659 | } |
| 660 | |
| 661 | QAction *preferences(const QObject *recvr, const char *slot, QObject *parent) |
| 662 | { |
| 663 | return KStandardAction::create(id: Preferences, recvr, slot, parent); |
| 664 | } |
| 665 | |
| 666 | QAction *configureToolbars(const QObject *recvr, const char *slot, QObject *parent) |
| 667 | { |
| 668 | return KStandardAction::create(id: ConfigureToolbars, recvr, slot, parent); |
| 669 | } |
| 670 | |
| 671 | QAction *configureNotifications(const QObject *recvr, const char *slot, QObject *parent) |
| 672 | { |
| 673 | return KStandardAction::create(id: ConfigureNotifications, recvr, slot, parent); |
| 674 | } |
| 675 | |
| 676 | QAction *helpContents(const QObject *recvr, const char *slot, QObject *parent) |
| 677 | { |
| 678 | return KStandardAction::create(id: HelpContents, recvr, slot, parent); |
| 679 | } |
| 680 | |
| 681 | QAction *whatsThis(const QObject *recvr, const char *slot, QObject *parent) |
| 682 | { |
| 683 | return KStandardAction::create(id: WhatsThis, recvr, slot, parent); |
| 684 | } |
| 685 | |
| 686 | QAction *reportBug(const QObject *recvr, const char *slot, QObject *parent) |
| 687 | { |
| 688 | return KStandardAction::create(id: ReportBug, recvr, slot, parent); |
| 689 | } |
| 690 | |
| 691 | QAction *switchApplicationLanguage(const QObject *recvr, const char *slot, QObject *parent) |
| 692 | { |
| 693 | return KStandardAction::create(id: SwitchApplicationLanguage, recvr, slot, parent); |
| 694 | } |
| 695 | |
| 696 | QAction *aboutApp(const QObject *recvr, const char *slot, QObject *parent) |
| 697 | { |
| 698 | return KStandardAction::create(id: AboutApp, recvr, slot, parent); |
| 699 | } |
| 700 | |
| 701 | QAction *aboutKDE(const QObject *recvr, const char *slot, QObject *parent) |
| 702 | { |
| 703 | return KStandardAction::create(id: AboutKDE, recvr, slot, parent); |
| 704 | } |
| 705 | |
| 706 | QAction *deleteFile(const QObject *recvr, const char *slot, QObject *parent) |
| 707 | { |
| 708 | return KStandardAction::create(id: DeleteFile, recvr, slot, parent); |
| 709 | } |
| 710 | |
| 711 | QAction *renameFile(const QObject *recvr, const char *slot, QObject *parent) |
| 712 | { |
| 713 | return KStandardAction::create(id: RenameFile, recvr, slot, parent); |
| 714 | } |
| 715 | |
| 716 | QAction *moveToTrash(const QObject *recvr, const char *slot, QObject *parent) |
| 717 | { |
| 718 | return KStandardAction::create(id: MoveToTrash, recvr, slot, parent); |
| 719 | } |
| 720 | |
| 721 | QAction *donate(const QObject *recvr, const char *slot, QObject *parent) |
| 722 | { |
| 723 | return KStandardAction::create(id: Donate, recvr, slot, parent); |
| 724 | } |
| 725 | |
| 726 | KHamburgerMenu *hamburgerMenu(const QObject *recvr, const char *slot, QObject *parent) |
| 727 | { |
| 728 | return static_cast<KHamburgerMenu *>(KStandardAction::create(id: HamburgerMenu, recvr, slot, parent)); |
| 729 | } |
| 730 | |
| 731 | } |
| 732 | |