1 /* This file is part of the KDE project
2 Copyright (C) 1999 Simon Hausmann <hausmann@kde.org>
3 (C) 1999 David Faure <faure@kde.org>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library 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 GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
20 #ifndef __kpartmanager_h__
21 #define __kpartmanager_h__
23 #include <QtGui/QWidget>
25 #include <kparts/kparts_export.h>
34 class PartManagerPrivate
;
37 * The part manager is an object which knows about a collection of parts
38 * (even nested ones) and handles activation/deactivation.
40 * Applications that want to embed parts without merging GUIs
41 * only use a KParts::PartManager. Those who want to merge GUIs use a
42 * KParts::MainWindow for example, in addition to a part manager.
44 * Parts know about the part manager to add nested parts to it.
45 * See also KParts::Part::manager() and KParts::Part::setManager().
47 class KPARTS_EXPORT PartManager
: public QObject
50 Q_ENUMS( SelectionPolicy
)
51 Q_PROPERTY( SelectionPolicy selectionPolicy READ selectionPolicy WRITE setSelectionPolicy
)
52 Q_PROPERTY( bool allowNestedParts READ allowNestedParts WRITE setAllowNestedParts
)
53 Q_PROPERTY( bool ignoreScrollBars READ ignoreScrollBars WRITE setIgnoreScrollBars
)
55 /// Selection policy. The default policy of a PartManager is Direct.
56 enum SelectionPolicy
{ Direct
, TriState
};
59 * This extends QFocusEvent::Reason with the non-focus-event reasons for partmanager to activate a part.
60 * To test for "any focusin reason", use < ReasonLeftClick
61 * NoReason usually means: explicit activation with @ref setActivePart.
63 enum Reason
{ ReasonLeftClick
= 100, ReasonMidClick
, ReasonRightClick
, NoReason
};
66 * Constructs a part manager.
68 * @param parent The toplevel widget (window / dialog) the
69 * partmanager should monitor for activation/selection
72 PartManager( QWidget
* parent
);
74 * Constructs a part manager.
76 * @param topLevel The toplevel widget (window / dialog ) the
77 * partmanager should monitor for activation/selection
79 * @param parent The parent QObject.
81 PartManager( QWidget
* topLevel
, QObject
*parent
);
82 virtual ~PartManager();
85 * Sets the selection policy of the partmanager.
87 void setSelectionPolicy( SelectionPolicy policy
);
89 * Returns the current selection policy.
91 SelectionPolicy
selectionPolicy() const;
94 * Specifies whether the partmanager should handle/allow nested parts
97 * This is a property the shell has to set/specify. Per
98 * default we assume that the shell cannot handle nested
99 * parts. However in case of a KOffice shell for example we allow
100 * nested parts. A Part is nested (a child part) if its parent
101 * object inherits KParts::Part. If a child part is activated and
102 * nested parts are not allowed/handled, then the top parent part in
103 * the tree is activated.
105 void setAllowNestedParts( bool allow
);
107 * @see setAllowNestedParts
109 bool allowNestedParts() const;
112 * Specifies whether the partmanager should ignore mouse click events for
113 * scrollbars or not. If the partmanager ignores them, then clicking on the
114 * scrollbars of a non-active/non-selected part will not change the selection
115 * or activation state.
117 * The default value is false (read: scrollbars are NOT ignored).
119 void setIgnoreScrollBars( bool ignore
);
121 * @see setIgnoreScrollBars
123 bool ignoreScrollBars() const;
126 * Specifies which mouse buttons the partmanager should react upon.
127 * By default it reacts on all mouse buttons (LMB/MMB/RMB).
128 * @param buttonMask a combination of Qt::ButtonState values e.g. Qt::LeftButton | Qt::MidButton
130 void setActivationButtonMask( short int buttonMask
);
132 * @see setActivationButtonMask
134 short int activationButtonMask() const;
139 virtual bool eventFilter( QObject
*obj
, QEvent
*ev
);
142 * Adds a part to the manager.
144 * Sets it to the active part automatically if @p setActive is true (default ).
145 * Behavior fix in KDE3.4: the part's widget is shown only if setActive is true,
146 * it used to be shown in all cases before.
148 virtual void addPart( Part
*part
, bool setActive
= true );
151 * Removes a part from the manager (this does not delete the object) .
153 * Sets the active part to 0 if @p part is the activePart() .
155 virtual void removePart( Part
*part
);
158 * Replaces @p oldPart with @p newPart, and sets @p newPart as active if
159 * @p setActive is true.
160 * This is an optimised version of removePart + addPart
162 virtual void replacePart( Part
* oldPart
, Part
* newPart
, bool setActive
= true );
165 * Sets the active part.
167 * The active part receives activation events.
169 * @p widget can be used to specify which widget was responsible for the activation.
170 * This is important if you have multiple views for a document/part , like in KOffice .
172 virtual void setActivePart( Part
*part
, QWidget
*widget
= 0 );
175 * Returns the active part.
177 virtual Part
*activePart() const;
180 * Returns the active widget of the current active part (see activePart ).
182 virtual QWidget
*activeWidget() const;
185 * Sets the selected part.
187 * The selected part receives selection events.
189 * @p widget can be used to specify which widget was responsible for the selection.
190 * This is important if you have multiple views for a document/part , like in KOffice .
192 virtual void setSelectedPart( Part
*part
, QWidget
*widget
= 0 );
195 * Returns the current selected part.
197 virtual Part
*selectedPart() const;
200 * Returns the selected widget of the current selected part (see selectedPart ).
202 virtual QWidget
*selectedWidget() const;
205 * Returns the list of parts being managed by the partmanager.
207 const QList
<Part
*> parts() const;
210 * Adds the @p topLevel widget to the list of managed toplevel widgets.
211 * Usually a PartManager only listens for events (for activation/selection)
212 * for one toplevel widget (and its children) , the one specified in the
213 * constructor. Sometimes however (like for example when using the KDE dockwidget
214 * library) , it is necessary to extend this.
216 void addManagedTopLevelWidget( const QWidget
*topLevel
);
218 * Removes the @p topLevel widget from the list of managed toplevel widgets.
219 * @see addManagedTopLevelWidget
221 void removeManagedTopLevelWidget( const QWidget
*topLevel
);
224 * @return the reason for the last activePartChanged signal emitted.
231 * Emitted when a new part has been added.
234 void partAdded( KParts::Part
*part
);
236 * Emitted when a part has been removed.
239 void partRemoved( KParts::Part
*part
);
241 * Emitted when the active part has changed.
242 * @see setActivePart()
244 void activePartChanged( KParts::Part
*newPart
);
248 * Changes the active instance when the active part changes.
249 * The active instance is used by KBugReport and KAboutDialog.
250 * Override if you really need to - usually you don't need to.
252 virtual void setActiveComponent(const KComponentData
&instance
);
256 * Removes a part when it is destroyed.
258 void slotObjectDestroyed();
263 void slotWidgetDestroyed();
268 void slotManagedTopLevelWidgetDestroyed();
270 Part
* findPartFromWidget( QWidget
* widget
, const QPoint
&pos
);
271 Part
* findPartFromWidget( QWidget
* widget
);
274 PartManagerPrivate
* const d
;