PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/quassel-0.7.3/src/uisupport/action.cpp

#
C++ | 110 lines | 72 code | 17 blank | 21 comment | 9 complexity | 3765d74a8934f55079ffe1e1f9567d34 MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0
  1. /***************************************************************************
  2. * Copyright (C) 2005-09 by the Quassel Project *
  3. * devel@quassel-irc.org *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 2 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, write to the *
  17. * Free Software Foundation, Inc., *
  18. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  19. ***************************************************************************
  20. * Parts of this implementation are taken from KDE's kaction.cpp *
  21. ***************************************************************************/
  22. #include "action.h"
  23. #include <QApplication>
  24. Action::Action(QObject *parent)
  25. #ifdef HAVE_KDE
  26. : KAction(parent)
  27. #else
  28. : QWidgetAction(parent)
  29. #endif
  30. {
  31. init();
  32. }
  33. Action::Action(const QString &text, QObject *parent, const QObject *receiver, const char *slot, const QKeySequence &shortcut)
  34. #ifdef HAVE_KDE
  35. : KAction(parent)
  36. #else
  37. : QWidgetAction(parent)
  38. #endif
  39. {
  40. init();
  41. setText(text);
  42. setShortcut(shortcut);
  43. if(receiver && slot)
  44. connect(this, SIGNAL(triggered()), receiver, slot);
  45. }
  46. Action::Action(const QIcon &icon, const QString &text, QObject *parent, const QObject *receiver, const char *slot, const QKeySequence &shortcut)
  47. #ifdef HAVE_KDE
  48. : KAction(parent)
  49. #else
  50. : QWidgetAction(parent)
  51. #endif
  52. {
  53. init();
  54. setIcon(icon);
  55. setText(text);
  56. setShortcut(shortcut);
  57. if(receiver && slot)
  58. connect(this, SIGNAL(triggered()), receiver, slot);
  59. }
  60. #ifdef HAVE_KDE
  61. void Action::init() { }
  62. #else
  63. void Action::init() {
  64. connect(this, SIGNAL(triggered(bool)), this, SLOT(slotTriggered()));
  65. setProperty("isShortcutConfigurable", true);
  66. }
  67. void Action::slotTriggered() {
  68. emit triggered(QApplication::mouseButtons(), QApplication::keyboardModifiers());
  69. }
  70. bool Action::isShortcutConfigurable() const {
  71. return property("isShortcutConfigurable").toBool();
  72. }
  73. void Action::setShortcutConfigurable(bool b) {
  74. setProperty("isShortcutConfigurable", b);
  75. }
  76. QKeySequence Action::shortcut(ShortcutTypes type) const {
  77. Q_ASSERT(type);
  78. if(type == DefaultShortcut)
  79. return property("defaultShortcut").value<QKeySequence>();
  80. if(shortcuts().count()) return shortcuts().value(0);
  81. return QKeySequence();
  82. }
  83. void Action::setShortcut(const QShortcut &shortcut, ShortcutTypes type) {
  84. setShortcut(shortcut.key(), type);
  85. }
  86. void Action::setShortcut(const QKeySequence &key, ShortcutTypes type) {
  87. Q_ASSERT(type);
  88. if(type & DefaultShortcut)
  89. setProperty("defaultShortcut", key);
  90. if(type & ActiveShortcut)
  91. QAction::setShortcut(key);
  92. }
  93. #endif /* HAVE_KDE */