File indexing completed on 2024-04-28 04:36:29
0001 /* 0002 SPDX-FileCopyrightText: 2009 David Nolden <david.nolden.kdevelop@art-master.de> 0003 0004 SPDX-License-Identifier: LGPL-2.0-only 0005 */ 0006 0007 #ifndef KDEVPLATFORM_IASSISTANT_H 0008 #define KDEVPLATFORM_IASSISTANT_H 0009 0010 #include <QIcon> 0011 #include <QExplicitlySharedDataPointer> 0012 #include "interfacesexport.h" 0013 #include <util/ksharedobject.h> 0014 0015 class QAction; 0016 0017 namespace KDevelop { 0018 0019 ///Represents a single assistant action. 0020 ///Subclass it to create your own actions. 0021 class KDEVPLATFORMINTERFACES_EXPORT IAssistantAction : public QObject, public KSharedObject 0022 { 0023 Q_OBJECT 0024 public: 0025 IAssistantAction(); 0026 0027 using Ptr = QExplicitlySharedDataPointer<IAssistantAction>; 0028 0029 ~IAssistantAction() override; 0030 0031 ///Creates a QAction that represents this exact assistant action. 0032 ///The caller owns the action, and is responsible for deleting it. 0033 virtual QAction* toQAction(QObject* parent = nullptr) const; 0034 0035 ///Should return a short description of the action. 0036 ///It may contain simple HTML formatting. 0037 ///Must be very short, so it nicely fits into the assistant popups. 0038 virtual QString description() const = 0; 0039 ///May return additional tooltip hover information. 0040 ///The default implementation returns an empty string. 0041 virtual QString toolTip() const; 0042 ///May return an icon for this action. 0043 ///The default implementation returns an invalid icon, which means that no icon is shown. 0044 virtual QIcon icon() const; 0045 0046 public Q_SLOTS: 0047 /** 0048 * Execute this action. 0049 * 0050 * NOTE: Implementations should properly emit executed(this) after being executed. 0051 */ 0052 virtual void execute() = 0; 0053 0054 Q_SIGNALS: 0055 /** 0056 * Gets emitted when this action was executed. 0057 */ 0058 void executed(IAssistantAction* action); 0059 }; 0060 0061 /** 0062 * A fake action that only shows a label. 0063 */ 0064 class KDEVPLATFORMINTERFACES_EXPORT AssistantLabelAction : public IAssistantAction 0065 { 0066 Q_OBJECT 0067 public: 0068 /** 0069 * @p description The label to show. 0070 */ 0071 explicit AssistantLabelAction(const QString& description); 0072 /** 0073 * @return the label contents. 0074 */ 0075 QString description() const override; 0076 /** 0077 * The label cannot be executed. 0078 */ 0079 void execute() override; 0080 /** 0081 * No action is returned. 0082 */ 0083 QAction* toQAction(QObject* parent = nullptr) const override; 0084 0085 private: 0086 QString m_description; 0087 }; 0088 0089 ///Represents a single assistant popup. 0090 ///Subclass it to create your own assistants. 0091 class KDEVPLATFORMINTERFACES_EXPORT IAssistant : public QObject, public KSharedObject 0092 { 0093 Q_OBJECT 0094 public: 0095 IAssistant(); 0096 ~IAssistant() override; 0097 0098 using Ptr = QExplicitlySharedDataPointer<IAssistant>; 0099 0100 ///Returns the stored list of actions 0101 QList<IAssistantAction::Ptr> actions() const; 0102 0103 ///Implement this and have it create the actions for your assistant. 0104 ///It will only be called if the assistant is displayed, which saves 0105 ///memory compared to creating the actions right away. 0106 ///Default implementation does nothing. 0107 virtual void createActions(); 0108 0109 ///Adds the given action to the list of actions. 0110 ///Does not emit actionsChanged(), you have to do that when you're ready. 0111 virtual void addAction(const IAssistantAction::Ptr& action); 0112 0113 ///Clears the stored list of actions. 0114 ///Does not emit actionsChanged(), you have to do that when you're ready. 0115 virtual void clearActions(); 0116 0117 ///May return an icon for this assistant 0118 virtual QIcon icon() const; 0119 0120 ///May return the title of this assistant 0121 ///The text may be html formatted. If it can be confused with HTML, 0122 ///use Qt::escape(..). 0123 virtual QString title() const; 0124 public Q_SLOTS: 0125 ///Emits hide(), which causes this assistant to be hidden 0126 virtual void doHide(); 0127 Q_SIGNALS: 0128 ///Can be emitted by the assistant when it should be hidden 0129 void hide(); 0130 ///Can be emitted by the assistant when its actions have changed and should be re-read 0131 void actionsChanged(); 0132 private: 0133 QList<IAssistantAction::Ptr> m_actions; 0134 }; 0135 0136 } 0137 0138 #endif // KDEVPLATFORM_IASSISTANT_H