|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the documentation of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 /*! |
|
43 \class QDesignerTaskMenuExtension |
|
44 \brief The QDesignerTaskMenuExtension class allows you to add custom |
|
45 menu entries to Qt Designer's task menu. |
|
46 \inmodule QtDesigner |
|
47 |
|
48 QDesignerTaskMenuExtension provides an interface for creating |
|
49 custom task menu extensions. It is typically used to create task |
|
50 menu entries that are specific to a plugin in \QD. |
|
51 |
|
52 \QD uses the QDesignerTaskMenuExtension to feed its task |
|
53 menu. Whenever a task menu is requested, \QD will query |
|
54 for the selected widget's task menu extension. |
|
55 |
|
56 \image taskmenuextension-example-faded.png |
|
57 |
|
58 A task menu extension is a collection of QActions. The actions |
|
59 appear as entries in the task menu when the plugin with the |
|
60 specified extension is selected. The image above shows the custom |
|
61 \gui {Edit State...} action which appears in addition to \QD's |
|
62 default task menu entries: \gui Cut, \gui Copy, \gui Paste etc. |
|
63 |
|
64 To create a custom task menu extension, your extension class must |
|
65 inherit from both QObject and QDesignerTaskMenuExtension. For |
|
66 example: |
|
67 |
|
68 \snippet doc/src/snippets/code/doc_src_qtdesigner.qdoc 9 |
|
69 |
|
70 Since we are implementing an interface, we must ensure that it |
|
71 is made known to the meta-object system using the Q_INTERFACES() |
|
72 macro. This enables \QD to use the qobject_cast() function to |
|
73 query for supported interfaces using nothing but a QObject |
|
74 pointer. |
|
75 |
|
76 You must reimplement the taskActions() function to return a list |
|
77 of actions that will be included in \QD task menu. Optionally, you |
|
78 can reimplement the preferredEditAction() function to set the |
|
79 action that is invoked when selecting your plugin and pressing |
|
80 \key F2. The preferred edit action must be one of the actions |
|
81 returned by taskActions() and, if it's not defined, pressing the |
|
82 \key F2 key will simply be ignored. |
|
83 |
|
84 In \QD, extensions are not created until they are required. A |
|
85 task menu extension, for example, is created when you click the |
|
86 right mouse button over a widget in \QD's workspace. For that |
|
87 reason you must also construct an extension factory, using either |
|
88 QExtensionFactory or a subclass, and register it using \QD's |
|
89 \l {QExtensionManager}{extension manager}. |
|
90 |
|
91 When a task menu extension is required, \QD's \l |
|
92 {QExtensionManager}{extension manager} will run through all its |
|
93 registered factories calling QExtensionFactory::createExtension() |
|
94 for each until it finds one that is able to create a task menu |
|
95 extension for the selected widget. This factory will then make an |
|
96 instance of the extension. |
|
97 |
|
98 There are four available types of extensions in \QD: |
|
99 QDesignerContainerExtension, QDesignerMemberSheetExtension, |
|
100 QDesignerPropertySheetExtension, and QDesignerTaskMenuExtension. |
|
101 \QD's behavior is the same whether the requested extension is |
|
102 associated with a container, a member sheet, a property sheet or a |
|
103 task menu. |
|
104 |
|
105 The QExtensionFactory class provides a standard extension factory, |
|
106 and can also be used as an interface for custom extension |
|
107 factories. You can either create a new QExtensionFactory and |
|
108 reimplement the QExtensionFactory::createExtension() function. For |
|
109 example: |
|
110 |
|
111 \snippet doc/src/snippets/code/doc_src_qtdesigner.qdoc 10 |
|
112 |
|
113 Or you can use an existing factory, expanding the |
|
114 QExtensionFactory::createExtension() function to make the factory |
|
115 able to create a task menu extension as well. For example: |
|
116 |
|
117 \snippet doc/src/snippets/code/doc_src_qtdesigner.qdoc 11 |
|
118 |
|
119 For a complete example using the QDesignerTaskMenuExtension class, |
|
120 see the \l {designer/taskmenuextension}{Task Menu Extension |
|
121 example}. The example shows how to create a custom widget plugin |
|
122 for \QD, and how to to use the QDesignerTaskMenuExtension |
|
123 class to add custom items to \QD's task menu. |
|
124 |
|
125 \sa QExtensionFactory, QExtensionManager, {Creating Custom Widget |
|
126 Extensions} |
|
127 */ |
|
128 |
|
129 /*! |
|
130 \fn QDesignerTaskMenuExtension::~QDesignerTaskMenuExtension() |
|
131 |
|
132 Destroys the task menu extension. |
|
133 */ |
|
134 |
|
135 /*! |
|
136 \fn QAction *QDesignerTaskMenuExtension::preferredEditAction() const |
|
137 |
|
138 Returns the action that is invoked when selecting a plugin with |
|
139 the specified extension and pressing \key F2. |
|
140 |
|
141 The action must be one of the actions returned by taskActions(). |
|
142 */ |
|
143 |
|
144 /*! |
|
145 \fn QList<QAction*> QDesignerTaskMenuExtension::taskActions() const |
|
146 |
|
147 Returns the task menu extension as a list of actions which will be |
|
148 included in \QD's task menu when a plugin with the specified |
|
149 extension is selected. |
|
150 |
|
151 The function must be reimplemented to add actions to the list. |
|
152 */ |