File indexing completed on 2024-04-28 15:29:22
0001 /* 0002 This file is part of the KDE project 0003 SPDX-FileCopyrightText: 1999 Simon Hausmann <hausmann@kde.org> 0004 SPDX-FileCopyrightText: 1999 David Faure <faure@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #ifndef __kpartmanager_h__ 0010 #define __kpartmanager_h__ 0011 0012 #include <kparts/kparts_export.h> 0013 0014 #include <QWidget> 0015 #include <memory> 0016 0017 namespace KParts 0018 { 0019 class Part; 0020 0021 class PartManagerPrivate; 0022 0023 /** 0024 * @class PartManager partmanager.h <KParts/PartManager> 0025 * 0026 * @short The part manager is an object which knows about a collection of parts 0027 * (even nested ones) and handles activation/deactivation. 0028 * 0029 * Applications that want to embed parts without merging GUIs 0030 * only use a KParts::PartManager. Those who want to merge GUIs use a 0031 * KParts::MainWindow for example, in addition to a part manager. 0032 * 0033 * Parts know about the part manager to add nested parts to it. 0034 * See also KParts::Part::manager() and KParts::Part::setManager(). 0035 */ 0036 class KPARTS_EXPORT PartManager : public QObject 0037 { 0038 Q_OBJECT 0039 Q_PROPERTY(SelectionPolicy selectionPolicy READ selectionPolicy WRITE setSelectionPolicy) 0040 Q_PROPERTY(bool allowNestedParts READ allowNestedParts WRITE setAllowNestedParts) 0041 Q_PROPERTY(bool ignoreScrollBars READ ignoreScrollBars WRITE setIgnoreScrollBars) 0042 public: 0043 /// Selection policy. The default policy of a PartManager is Direct. 0044 enum SelectionPolicy { Direct, TriState }; 0045 Q_ENUM(SelectionPolicy) 0046 0047 /** 0048 * This extends QFocusEvent::Reason with the non-focus-event reasons for partmanager to activate a part. 0049 * To test for "any focusin reason", use < ReasonLeftClick 0050 * NoReason usually means: explicit activation with @ref setActivePart. 0051 */ 0052 enum Reason { ReasonLeftClick = 100, ReasonMidClick, ReasonRightClick, NoReason }; 0053 0054 /** 0055 * Constructs a part manager. 0056 * 0057 * @param parent The toplevel widget (window / dialog) the 0058 * partmanager should monitor for activation/selection 0059 * events 0060 */ 0061 PartManager(QWidget *parent); 0062 /** 0063 * Constructs a part manager. 0064 * 0065 * @param topLevel The toplevel widget (window / dialog ) the 0066 * partmanager should monitor for activation/selection 0067 * events 0068 * @param parent The parent QObject. 0069 */ 0070 PartManager(QWidget *topLevel, QObject *parent); 0071 ~PartManager() override; 0072 0073 /** 0074 * Sets the selection policy of the partmanager. 0075 */ 0076 void setSelectionPolicy(SelectionPolicy policy); 0077 /** 0078 * Returns the current selection policy. 0079 */ 0080 SelectionPolicy selectionPolicy() const; 0081 0082 /** 0083 * Specifies whether the partmanager should handle/allow nested parts 0084 * or not. 0085 * 0086 * This is a property the shell has to set/specify. Per 0087 * default we assume that the shell cannot handle nested 0088 * parts. However in case of a KOffice shell for example we allow 0089 * nested parts. A Part is nested (a child part) if its parent 0090 * object inherits KParts::Part. If a child part is activated and 0091 * nested parts are not allowed/handled, then the top parent part in 0092 * the tree is activated. 0093 */ 0094 void setAllowNestedParts(bool allow); 0095 /** 0096 * @see setAllowNestedParts 0097 */ 0098 bool allowNestedParts() const; 0099 0100 /** 0101 * Specifies whether the partmanager should ignore mouse click events for 0102 * scrollbars or not. If the partmanager ignores them, then clicking on the 0103 * scrollbars of a non-active/non-selected part will not change the selection 0104 * or activation state. 0105 * 0106 * The default value is false (read: scrollbars are NOT ignored). 0107 */ 0108 void setIgnoreScrollBars(bool ignore); 0109 /** 0110 * @see setIgnoreScrollBars 0111 */ 0112 bool ignoreScrollBars() const; 0113 0114 /** 0115 * Specifies which mouse buttons the partmanager should react upon. 0116 * By default it reacts on all mouse buttons (LMB/MMB/RMB). 0117 * @param buttonMask a combination of Qt::ButtonState values e.g. Qt::LeftButton | Qt::MiddleButton 0118 */ 0119 void setActivationButtonMask(short int buttonMask); 0120 /** 0121 * @see setActivationButtonMask 0122 */ 0123 short int activationButtonMask() const; 0124 0125 /** 0126 * @internal 0127 */ 0128 bool eventFilter(QObject *obj, QEvent *ev) override; 0129 0130 /** 0131 * Adds a part to the manager. 0132 * 0133 * Sets it to the active part automatically if @p setActive is true (default). 0134 */ 0135 virtual void addPart(Part *part, bool setActive = true); 0136 0137 /** 0138 * Removes a part from the manager (this does not delete the object) . 0139 * 0140 * Sets the active part to 0 if @p part is the activePart() . 0141 */ 0142 virtual void removePart(Part *part); 0143 0144 /** 0145 * Replaces @p oldPart with @p newPart, and sets @p newPart as active if 0146 * @p setActive is true. 0147 * This is an optimised version of removePart + addPart 0148 */ 0149 virtual void replacePart(Part *oldPart, Part *newPart, bool setActive = true); 0150 0151 /** 0152 * Sets the active part. 0153 * 0154 * The active part receives activation events. 0155 * 0156 * @p widget can be used to specify which widget was responsible for the activation. 0157 * This is important if you have multiple views for a document/part , like in KOffice . 0158 */ 0159 virtual void setActivePart(Part *part, QWidget *widget = nullptr); 0160 0161 /** 0162 * Returns the active part. 0163 **/ 0164 virtual Part *activePart() const; 0165 0166 /** 0167 * Returns the active widget of the current active part (see activePart ). 0168 */ 0169 virtual QWidget *activeWidget() const; 0170 0171 #if KPARTS_BUILD_DEPRECATED_SINCE(5, 72) 0172 /** 0173 * Sets the selected part. 0174 * 0175 * The selected part receives selection events. 0176 * 0177 * @p widget can be used to specify which widget was responsible for the selection. 0178 * This is important if you have multiple views for a document/part , like in KOffice . 0179 * 0180 * @deprecated Since 5.72, for lack of usage. 0181 */ 0182 KPARTS_DEPRECATED_VERSION(5, 72, "Deprecated for lack of usage") 0183 virtual void setSelectedPart(Part *part, QWidget *widget = nullptr); 0184 #endif 0185 0186 #if KPARTS_BUILD_DEPRECATED_SINCE(5, 72) 0187 /** 0188 * Returns the current selected part. 0189 * 0190 * @deprecated Since 5.72, for lack of usage. 0191 */ 0192 KPARTS_DEPRECATED_VERSION(5, 72, "Deprecated for lack of usage") 0193 virtual Part *selectedPart() const; 0194 #endif 0195 0196 #if KPARTS_BUILD_DEPRECATED_SINCE(5, 72) 0197 /** 0198 * Returns the selected widget of the current selected part (see selectedPart ). 0199 * 0200 * @deprecated Since 5.72, for lack of usage. 0201 */ 0202 KPARTS_DEPRECATED_VERSION(5, 72, "Deprecated for lack of usage") 0203 virtual QWidget *selectedWidget() const; 0204 #endif 0205 0206 /** 0207 * Returns the list of parts being managed by the partmanager. 0208 */ 0209 const QList<Part *> parts() const; 0210 0211 /** 0212 * Adds the @p topLevel widget to the list of managed toplevel widgets. 0213 * Usually a PartManager only listens for events (for activation/selection) 0214 * for one toplevel widget (and its children) , the one specified in the 0215 * constructor. Sometimes however (like for example when using the KDE dockwidget 0216 * library) , it is necessary to extend this. 0217 */ 0218 void addManagedTopLevelWidget(const QWidget *topLevel); 0219 /** 0220 * Removes the @p topLevel widget from the list of managed toplevel widgets. 0221 * @see addManagedTopLevelWidget 0222 */ 0223 void removeManagedTopLevelWidget(const QWidget *topLevel); 0224 0225 /** 0226 * @return the reason for the last activePartChanged signal emitted. 0227 * @see Reason 0228 */ 0229 int reason() const; 0230 0231 Q_SIGNALS: 0232 /** 0233 * Emitted when a new part has been added. 0234 * @see addPart() 0235 **/ 0236 void partAdded(KParts::Part *part); 0237 /** 0238 * Emitted when a part has been removed. 0239 * @see removePart() 0240 **/ 0241 void partRemoved(KParts::Part *part); 0242 /** 0243 * Emitted when the active part has changed. 0244 * @see setActivePart() 0245 **/ 0246 void activePartChanged(KParts::Part *newPart); 0247 0248 protected: 0249 /** 0250 * Sets whether the PartManager ignores explicit set focus requests 0251 * from the part. 0252 * 0253 * By default this option is set to false. Set it to true to prevent 0254 * the part from sending explicit set focus requests to the client 0255 * application. 0256 * 0257 * @since 4.10 0258 */ 0259 void setIgnoreExplictFocusRequests(bool); 0260 0261 protected Q_SLOTS: 0262 /** 0263 * Removes a part when it is destroyed. 0264 **/ 0265 void slotObjectDestroyed(); 0266 0267 /** 0268 * @internal 0269 */ 0270 void slotWidgetDestroyed(); 0271 0272 /** 0273 * @internal 0274 */ 0275 void slotManagedTopLevelWidgetDestroyed(); 0276 0277 private: 0278 KPARTS_NO_EXPORT Part *findPartFromWidget(QWidget *widget, const QPoint &pos); 0279 KPARTS_NO_EXPORT Part *findPartFromWidget(QWidget *widget); 0280 0281 private: 0282 std::unique_ptr<PartManagerPrivate> const d; 0283 }; 0284 0285 } 0286 0287 #endif