File indexing completed on 2024-05-12 16:39:41
0001 /* This file is part of the KDE project 0002 Copyright (C) 2004 Jarosław Staniek <staniek@kde.org> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #ifndef KEXISHAREDACTIONHOST_H 0021 #define KEXISHAREDACTIONHOST_H 0022 0023 #include <KStandardAction> 0024 0025 #include <QAction> 0026 0027 #include "kexicore_export.h" 0028 0029 class QKeySequence; 0030 class KGuiItem; 0031 class KActionCollection; 0032 class KexiMainWindowIface; 0033 class KexiActionProxy; 0034 class KexiSharedActionHostPrivate; 0035 0036 namespace KexiPart 0037 { 0038 class Part; 0039 } 0040 0041 //! Acts as application-wide host that offers shared actions. 0042 /*! 0043 You can inherit this class together with KexiMainWindow. 0044 Call setAsDefaultHost() to make the host default for all shared actions that have 0045 not explicitly specified host. 0046 0047 For example how all this is done, see KexiMainWindow implementation. 0048 0049 \sa KexiActionProxy, KexiMainWindow */ 0050 class KEXICORE_EXPORT KexiSharedActionHost 0051 { 0052 public: 0053 0054 /*! Constructs host for main window \a mainWin. */ 0055 explicit KexiSharedActionHost(KexiMainWindowIface* mainWin); 0056 0057 virtual ~KexiSharedActionHost(); 0058 0059 /*! Performs lookup like in KexiSharedActionHost::focusWindow() 0060 but starting from \a w instead of a widget returned by QWidget::focusWidget(). 0061 \return NULL if no widget matches acceptsSharedActions() or if \a w is NULL. */ 0062 virtual QWidget* findWindow(QWidget *w); 0063 0064 /*! \return window widget that is currently focused (using QWidget::focusWidget()) 0065 and matches acceptsSharedActions(). If focused widget does not match, 0066 it's parent, grandparent, and so on is checked. If all this fails, 0067 or no widget has focus, 0 is returned. */ 0068 QWidget* focusWindow(); 0069 0070 /*! Sets this host as default shared actions host. */ 0071 void setAsDefaultHost(); 0072 0073 /*! \return default shared actions host, used when no host 0074 is explicitly specified for shared actions. 0075 There can be exactly one deault shared actions host. */ 0076 static KexiSharedActionHost* defaultHost(); 0077 0078 /*! \return shared actions list. */ 0079 QList<QAction *> sharedActions() const; 0080 0081 /*! PROTOTYPE, DO NOT USE YET */ 0082 void setActionVolatile(QAction *a, bool set); 0083 0084 protected: 0085 /*! Invalidates all shared actions declared using createSharedAction(). 0086 Any shared action will be enabled if \a o (typically: a child window or a dock window) 0087 has this action plugged _and_ it is available (i.e. enabled). 0088 Otherwise the action is disabled. 0089 0090 If \a o is not KexiWindow or its child, 0091 actions are only invalidated if these come from mainwindow's KActionCollection 0092 (thus part-actions are untouched when the focus is e.g. in the Property Editor. 0093 0094 Call this method when it is known that some actions need invalidation 0095 (e.g. when new window is activated). See how it is used in KexiMainWindow. */ 0096 virtual void invalidateSharedActions(QObject *o); 0097 0098 void setActionAvailable(const QString& action_name, bool avail); 0099 0100 /*! Plugs shared actions proxy \a proxy for this host. */ 0101 void plugActionProxy(KexiActionProxy *proxy); 0102 0103 /*! Updates availability of action \a action_name for object \a obj. 0104 Object is mainly the window. */ 0105 void updateActionAvailable(const QString& action_name, bool avail, QObject *obj); 0106 0107 /*! \return main window for which this host is defined. */ 0108 KexiMainWindowIface* mainWindow() const; 0109 0110 /*! Creates shared action using \a text, \a pix_name pixmap, shortcut \a cut, 0111 optional \a name. You can pass your own action collection as \a col. 0112 If \a col action collection is null, main window's action will be used. 0113 Pass desired QAction subclass with \a subclassName (e.g. "KToggleAction") to have 0114 that subclass allocated instead just QAction (what is the default). 0115 Created action's data is owned by the main window. */ 0116 QAction * createSharedAction(const QString &text, const QString &iconName, 0117 const QKeySequence &cut, const char *name, KActionCollection* col = 0, 0118 const char *subclassName = 0); 0119 0120 /*! Like above - creates shared action, but from standard action identified by \a id. 0121 Action's data is owned by the main window. */ 0122 QAction * createSharedAction(KStandardAction::StandardAction id, const char *name = 0, 0123 KActionCollection* col = 0); 0124 0125 /*! Creates shared action with name \a name and shortcut \a cut 0126 by copying all properties of \a guiItem. 0127 If \a col action collection is null, main window's action will be used. */ 0128 QAction * createSharedAction(const KGuiItem& guiItem, const QKeySequence &cut, const char *name, 0129 KActionCollection* col = 0); 0130 0131 /*! \return action proxy for object \a o, or NULL if this object has 0132 no plugged shared actions. */ 0133 KexiActionProxy* actionProxyFor(QObject *o) const; 0134 0135 /*! Like actionProxyFor(), but takes the proxy from the host completely. 0136 This is called by KExiActionProxy on its destruction. */ 0137 KexiActionProxy* takeActionProxyFor(QObject *o); 0138 0139 private: 0140 /*! Helper function for createSharedAction(). */ 0141 QAction * createSharedActionInternal(QAction *action); 0142 0143 KexiSharedActionHostPrivate *d; 0144 0145 friend class KexiActionProxy; 0146 friend class KexiPart::Part; 0147 friend class KexiView; 0148 friend class KexiWindow; 0149 }; 0150 0151 #endif