1
/* This file is part of the KDE libraries
2
Copyright (C) 2007 Philippe Fremy (phil at freehackers dot org)
3
Copyright (C) 2008 Joseph Wenninger (jowenn@kde.org)
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Library General Public
8
License version 2 as published by the Free Software Foundation.
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.
21
#ifndef KDELIBS_KTEXTEDITOR_CONTAINER_INTERFACE_H
22
#define KDELIBS_KTEXTEDITOR_CONTAINER_INTERFACE_H
24
#include <ktexteditor/ktexteditor_export.h>
26
#include <QtCore/QObject>
36
* \brief Class that allows the kpart host to provide some extensions.
38
* \ingroup kte_group_editor_extensions
40
* The KTextEditor framework allows the kpart host to provide additional
41
* services to the kpart. Those services are provided through the
42
* ContainerInterface class.
44
* If the container supports those specific services, it should set an
45
* instance of the service class with ContainerInterface::setContainer(). That
46
* instance should inherit QObject, have the Q_OBJECT macro and declare a
47
* Q_INTERFACES(), in order for the qobject_cast mechanism to work.
49
* To obtain a ContainerInterface, in order to set a specific container
50
* extension, the kpart host should do:
52
* // inside the kpart host
53
* Editor * editor = KTextEditor::EditorChooser::editor();
54
* ContainerInterface * iface = qobject_cast<ContainerInterface *>( editor );
55
* if (iface != NULL) {
56
* iface->setContainer( myContainerExtension );
58
* // the kpart does not support ContainerInterface.
62
* It is then up to the kpart to use it.
65
class KTEXTEDITOR_EXPORT ContainerInterface
73
/** Virtual Destructor */
74
virtual ~ContainerInterface();
77
* Set the KTextEditor container.
79
* This method is used by the KTextEditor host to set an instance
80
* of a class providing optional container extensions.
84
virtual void setContainer( QObject * container ) = 0;
87
* Fetch the container extension.
89
* This method is used by the KTextEditor component to know
90
* which extensions are supported by the KTextEditor host.
92
* The kpart will cast the result with qobject_cast() to the right
93
* container extension to see if that particular extension is supported:
99
* Editor * editor = KTextEditor::EditorChooser::editor();
100
* ContainerInterface * iface = qobject_cast<ConainterInterace *>( editor );
101
* SomeContainerExtension * myExt =
102
* qobject_cast<SomeContainerExtension *>( iface->container() );
105
* // do some stuff with the specific container extension
108
* // too bad, that extension is not supported.
114
virtual QObject * container() = 0;
115
}; // class ContainerInterface
118
* A container for MDI-capable kpart hosts.
120
* The kpart container for the KTextEditor interface may have different
121
* capabilities. For example, inside KDevelop or Kate, the container can
122
* manage multiple views and multiple documents. However, if the kpart text
123
* is used inside konqueror as a replacement of the text entry in html
124
* forms, the container will only support one view with one document.
126
* This class allows the kpart component to create and delete views, create
127
* and delete documents, fetch and set the current view. Note that the
128
* ktexteditor framework already supports multiple document and views and
129
* that the kpart host can create them and delete them as it wishes. What
130
* this class provides is the ability for the <i>kpart component</i> being
131
* hosted to do the same.
133
* An instance of this extension should be set with
134
* ContainerInterface::setContainerExtension().Check ContainerInterface() to
135
* see how to obtain an instance of ContainerInterface. The instance should
136
* inherit QObject, inherit MdiContainer, declare the Q_OBJECT macro and
137
* declare a Q_INTERFACES(KTextEditor::MdiContainer) .
139
* Code example to support MdiContainer (in the kpart host):
141
* class MyMdiContainer : public QObject,
142
* public MdiContainer
145
* Q_INTERFACES( KTextEditor::MdiContainer )
153
* To check if the kpart hosts supports the MDI container:
155
* Editor * editor = KTextEditor::EditorChooser::editor();
156
* ContainerInterface * iface = qobject_cast<ContainerInterface *>( editor );
158
* MdiContainer * mdiContainer = qobject_cast<MdiContainer *>( iface->container() );
159
* if (MdiContainer != NULL ) {
160
* // great, I can create additional views
166
class KTEXTEDITOR_EXPORT MdiContainer
173
/** Virtual destructor */
174
virtual ~MdiContainer();
177
* Set the \p view requested by the part as the active view.
181
virtual void setActiveView( View * view )=0;
184
* Get the current activew view.
186
* \return the active view.
190
virtual View * activeView()=0;
193
* Create a new Document and return it to the kpart.
195
* Canonical implementation is:
197
* Document * createDocument()
200
* // set parentQObject to relevant value
201
* doc = editor->createDocument( parentQObject );
202
* // integrate the new document in the document list of the
208
* The signal documentCreated() will be emitted during the creation.
210
* \return a pointer to the new Document object.
212
virtual Document * createDocument()=0;
215
* Closes of document \p doc .
217
* The document is about to be closed but is still valid when this
218
* call is made. The Document does not contain any view when this
219
* call is made (closeView() has been called on all the views of the
220
* document previously).
222
* The signal aboutToClose() is emitted before this method is
225
* \return true if the removal is authorized and acted, or
226
* false if removing documents by the kpart is not supported
229
virtual bool closeDocument( Document * doc )=0;
232
* Creates a new View and return it to the kpart.
234
* Canonical implementation is:
236
* View * createView( Document * doc )
238
* // set parentWidget to relevant value
239
* return doc->createView( parentWidget );
243
* The signal viewCreated() will be emitted during the createView()
246
* \return a pointer to the new View created.
248
virtual View * createView( Document * doc )=0;
251
* Closes the View \p view .
253
* The view is still valid when this call is made but will be deleted
256
* \return true if the removal is authorized and acted, or
257
* false if the container does not support view removing from
260
virtual bool closeView( View * view )=0;
261
}; // class MdiContainer
265
* An application providing a centralized place for horizontal view bar containers (eg search bars) has
269
class KTEXTEDITOR_EXPORT ViewBarContainer
272
enum Position{LeftBar=0,TopBar=1,RightBar=2,BottomBar=3};
276
/** Virtual destructor */
277
virtual ~ViewBarContainer();
279
/** At this point the views parent window has to be already set, so this has to be called after any reparentings
280
* eg.: The implementation in Kate uses view->window() to determine where to place of the container
281
* if 0 is returned, the view has to handle the bar internally
283
virtual QWidget* getViewBarParent(View *view,enum Position position)=0;
285
/** It is advisable to store only QPointers to the bar and its children in the caller after this point.
286
* The container may at any point delete the bar, eg if the container is destroyed
287
* The caller has to ensure that bar->parentWidget() is the widget returned by the previous function
289
virtual void addViewBarToLayout(View *view,QWidget *bar,enum Position position)=0;
291
///show hide a view bar. The implementor of this interface has to take care for not showing
292
/// the bars of unfocused views, if needed
293
virtual void showViewBarForView(View *view,enum Position position)=0;
294
virtual void hideViewBarForView(View *view,enum Position position)=0;
297
* The view should not delete the bar by itself, but tell the container to delete the bar.
298
* This is for instance useful, in the destructor of the view. The bar must not life longer
301
virtual void deleteViewBarForView(View *view,enum Position position)=0;
305
} // namespace KTextEditor
307
Q_DECLARE_INTERFACE(KTextEditor::ContainerInterface, "org.kde.KTextEditor.ContainerInterface")
308
Q_DECLARE_INTERFACE(KTextEditor::MdiContainer, "org.kde.KTextEditor.MdiContainer")
309
Q_DECLARE_INTERFACE(KTextEditor::ViewBarContainer, "org.kde.KTextEditor.ViewBarContainer")
310
#endif // KDELIBS_KTEXTEDITOR_CONTAINER_EXTENSION_H