File indexing completed on 2024-05-12 16:39:50

0001 /* This file is part of the KDE project
0002    Copyright (C) 2005-2006 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 KEXIFORMEVENTHANDLER_H
0021 #define KEXIFORMEVENTHANDLER_H
0022 
0023 #include "kformdesigner_export.h"
0024 
0025 #include <QAction>
0026 #include <QWidget>
0027 
0028 namespace KexiPart
0029 {
0030 class Info;
0031 }
0032 
0033 //! The KexiFormEventHandler class handles events defined within Kexi Forms
0034 /*! For now only "onClickAction" property of Push Button widget is handled:
0035  It's possible to connect this event to predefined global action.
0036 
0037  Note: This interface will be extended in the future!
0038 
0039  @see KexiFormPart::slotAssignAction()
0040  */
0041 class KFORMDESIGNER_EXPORT KexiFormEventHandler
0042 {
0043 public:
0044     KexiFormEventHandler();
0045     virtual ~KexiFormEventHandler();
0046 
0047     /*! Sets \a mainWidget to be a main widget for this handler.
0048      Also find widgets having action assigned and connects them
0049      to appropriate actions.
0050      For now, all of them must be KexiPushButton). */
0051     void setMainWidgetForEventHandling(QWidget* mainWidget);
0052 
0053 private:
0054     class Private;
0055 
0056     Private* const d;
0057 };
0058 
0059 //! @internal form-level action for handling "on click" actions
0060 class KFORMDESIGNER_EXPORT KexiFormEventAction : public QAction
0061 {
0062     Q_OBJECT
0063 public:
0064     //! A structure used in currentActionName()
0065     class KFORMDESIGNER_EXPORT ActionData
0066     {
0067     public:
0068         ActionData();
0069 
0070         /*! Decodes action string into action type/action argument parts.
0071          Action string has to be in a form of "actiontype:actionarg"
0072          - Action type is passed to \a actionType on success. Action type can be "kaction"
0073           or any of the part names (see KexiPart::Info::objectName()), e.g. "table", "query", etc.
0074          - Action argument can be an action name in case of "kaction" type or object name
0075           in case of action of type "table", "query", etc.
0076          \a ok is set to true on success and to false on failure. On failure no other
0077          values are passed.
0078          \return part info if action type is "table", "query", etc., or 0 for "kaction" type. */
0079         KexiPart::Info* decodeString(QString& actionType, QString& actionArg, bool *ok) const;
0080 
0081         //! \return true if the action is empty
0082         bool isEmpty() const;
0083 
0084         QString string; //!< action string with prefix, like "kaction:edit_copy" or "table:<tableName>"
0085 
0086         QString option; //!< option used when name is "table/query/etc.:\<objectName\>" is set;
0087         //!< can be set to "open", "design", "editText", etc.
0088         //!< @see ActionToExecuteListView::showActionsForPluginId()
0089     };
0090 
0091     KexiFormEventAction(QObject* parent, const QString& actionName,
0092                         const QString& objectName, const QString& actionOption);
0093     virtual ~KexiFormEventAction();
0094 
0095 public Q_SLOTS:
0096     //! Activates the action. If the object supports executing (macro, script),
0097     //! it is executed; otherwise (table, query, form,...) it is opened in its data view.
0098     void slotTrigger();
0099 
0100 private:
0101     class Private;
0102 
0103     Private* const d;
0104 };
0105 
0106 #endif