1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
3 Copyright (C) 2007 Thomas Zander <zander@kde.org>
4 Copyright (C) 2010 Benjamin Port <port.benjamin@gmail.com>
5
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 as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20*/
21#ifndef __koView_h__
22#define __koView_h__
23
24#include <QWidget>
25#include <kxmlguiclient.h>
26#include "komain_export.h"
27
28class KoPart;
29class KoDocument;
30class KoMainWindow;
31class KoPrintJob;
32class KoViewPrivate;
33class KoZoomController;
34struct KoPageLayout;
35
36// KDE classes
37class KStatusBar;
38class KXmlGuiWindow;
39class KAction;
40
41// Qt classes
42class QToolBar;
43class QDragEnterEvent;
44class QDropEvent;
45class QPrintDialog;
46
47/**
48 * This class is used to display a @ref KoDocument.
49 *
50 * Multiple views can be attached to one document at a time.
51 */
52class KOMAIN_EXPORT KoView : public QWidget, public KXMLGUIClient
53{
54 Q_OBJECT
55
56public:
57 /**
58 * Creates a new view for the document. Usually you don't create views yourself
59 * since the Calligra components come with their own view classes which inherit
60 * KoView.
61 *
62 * The standard way to retrieve a KoView is to call @ref KoPart::createView.
63 *
64 * @param document is the document which should be displayed in this view. This pointer
65 * must not be zero.
66 * @param parent parent widget for this view.
67 */
68 KoView(KoPart *part, KoDocument *document, QWidget *parent = 0);
69
70 /**
71 * Destroys the view and unregisters at the document.
72 */
73 virtual ~KoView();
74
75 // QWidget overrides
76protected:
77
78 virtual void dragEnterEvent(QDragEnterEvent * event);
79
80 /**
81 * dropEvent by default calls addImages. Your KoView subclass might
82 * override dropEvent and if your app can also handle images, call this
83 * method.
84 */
85 virtual void dropEvent(QDropEvent * event);
86
87 // KoView api
88
89 /**
90 * Adds the given list of QImages as imageshapes to the view's document.
91 *
92 * @param imageList: a list of QImages that can be inserted
93 * @param insertPosition: the position in screen pixels where the images
94 * can be inserted.
95 */
96 virtual void addImages(const QList<QImage> &imageList, const QPoint &insertAt);
97
98public:
99
100 /**
101 * Retrieves the document object of this view.
102 */
103 KoDocument *koDocument() const;
104
105 /**
106 * Tells this view that its document has got deleted (called internally)
107 */
108 void setDocumentDeleted();
109
110 /**
111 * In order to print the document represented by this view a new print job should
112 * be constructed that is capable of doing the printing.
113 * The default implementation returns 0, which silently cancels printing.
114 */
115 virtual KoPrintJob * createPrintJob();
116
117 /**
118 * In order to export the document represented by this view a new print job should
119 * be constructed that is capable of doing the printing.
120 * The default implementation call createPrintJob.
121 */
122 virtual KoPrintJob * createPdfPrintJob();
123
124 /**
125 * @return the page layout to be used for printing.
126 * Default is the documents layout.
127 * Reimplement if your application needs to use a different layout.
128 */
129 virtual KoPageLayout pageLayout() const;
130
131 /**
132 * Create a QPrintDialog based on the @p printJob
133 */
134 virtual QPrintDialog *createPrintDialog(KoPrintJob *printJob, QWidget *parent);
135
136 /**
137 * @return the KoMainWindow in which this view is currently.
138 */
139 KoMainWindow * mainWindow() const;
140
141 /**
142 * @return the statusbar of the KoMainWindow in which this view is currently.
143 */
144 KStatusBar * statusBar() const;
145
146 /**
147 * This adds a widget to the statusbar for this view.
148 * If you use this method instead of using statusBar() directly,
149 * KoView will take care of removing the items when the view GUI is deactivated
150 * and readding them when it is reactivated.
151 * The parameters are the same as QStatusBar::addWidget().
152 *
153 * Note that you can't use KStatusBar methods (inserting text items by id).
154 * But you can create a KStatusBarLabel with a dummy id instead, and use
155 * it directly, to get the same look and feel.
156 */
157 void addStatusBarItem(QWidget * widget, int stretch = 0, bool permanent = false);
158
159 /**
160 * Remove a widget from the statusbar for this view.
161 */
162 void removeStatusBarItem(QWidget * widget);
163
164 /**
165 * You have to implement this method and disable/enable certain functionality (actions for example) in
166 * your view to allow/disallow editing of the document.
167 */
168 virtual void updateReadWrite(bool readwrite) = 0;
169
170 /**
171 * Return the zoomController for this view.
172 */
173 virtual KoZoomController *zoomController() const = 0;
174
175 /// create a list of actions that when activated will change the unit on the document.
176 QList<QAction*> createChangeUnitActions(bool addPixelUnit = false);
177
178 /**
179 * @brief guiActivateEvent is called when the window activates a view. Reimplement this for any special behaviour.
180 */
181 virtual void guiActivateEvent(bool activated);
182
183public slots:
184
185 /**
186 * Display a message in the status bar (calls QStatusBar::message())
187 * @todo rename to something more generic
188 */
189 void slotActionStatusText(const QString &text);
190
191 /**
192 * End of the message in the status bar (calls QStatusBar::clear())
193 * @todo rename to something more generic
194 */
195 void slotClearStatusText();
196
197 /**
198 * Updates the author profile actions from configuration.
199 */
200 void slotUpdateAuthorProfileActions();
201
202protected:
203
204 /**
205 * Generate a name for this view.
206 */
207 QString newObjectName();
208
209protected slots:
210
211 virtual void changeAuthorProfile(const QString &profileName);
212
213private:
214 virtual void setupGlobalActions(void);
215 KoViewPrivate * const d;
216};
217
218#endif
219