kword

KWViewMode.h
1/* This file is part of the KDE project
2 Copyright (C) 2001 David Faure <faure@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#ifndef kwviewmode_h
21#define kwviewmode_h
22
23#include <tqrect.h>
24class KWDocument;
25class TQPainter;
26class TQRegion;
27class KWTextFrameSet;
28class KWFrameSet;
29class KWCanvas;
30class KoRuler;
31class KoPageLayout;
32class KWPage;
33
47class KWViewMode
48{
49protected:
50 KWViewMode( KWDocument * doc, KWCanvas* canvas, bool drawFrameBorders )
51 : m_doc( doc ), m_canvas( canvas ), m_drawFrameBorders( drawFrameBorders )
52 {}
53public:
54 virtual ~KWViewMode() {}
55
57 virtual TQPoint normalToView( const TQPoint & nPoint ) = 0;
58
60 TQRect normalToView( const TQRect & nRect )
61 { return TQRect( normalToView( nRect.topLeft() ), nRect.size() ); }
62
64 virtual TQPoint viewToNormal( const TQPoint & vPoint ) = 0;
65
67 TQRect viewToNormal( const TQRect & nRect )
68 { return TQRect( viewToNormal( nRect.topLeft() ), viewToNormal( nRect.bottomRight() ) ); }
69
71 virtual TQRect viewPageRect( int pgNum ) = 0;
72
74 virtual TQSize contentsSize() = 0;
75
79 virtual TQSize availableSizeForText( KWTextFrameSet* textfs );
80
84 virtual TQPoint pageCorner();
87 virtual TQRect rulerFrameRect();
90 virtual void setPageLayout( KoRuler* hRuler, KoRuler* vRuler, const KoPageLayout& layout );
91
92 virtual void drawPageBorders( TQPainter * painter, const TQRect & crect, const TQRegion & emptySpaceRegion ) = 0;
93
95 virtual void setPagesPerRow(int) {}
96 virtual int pagesPerRow() { return 0; }
97
99 virtual bool drawSelections() { return true; }
100
102 virtual bool drawFrameBackground() { return true; }
103
105 bool drawFrameBorders() const { return m_drawFrameBorders; }
106 void setDrawFrameBorders(bool b) { m_drawFrameBorders = b; }
107
109 virtual bool isFrameSetVisible( const KWFrameSet* /*frameset*/ ) { return true; }
110
112 // TODO: maybe this should be more fine-grained.
113 virtual bool shouldFormatVertically() { return true; }
114
116 virtual bool shouldAdjustMargins() { return true; }
117
119 virtual bool hasFrames() { return true; }
120
122 virtual bool hasPages() { return true; }
123
125 virtual const TQString type() const = 0;
126
129 virtual bool isTextModeFrameset(KWFrameSet *) const { return false; }
130
131 static KWViewMode *create( const TQString& viewModeType, KWDocument* doc, KWCanvas* canvas );
132
133 KWCanvas * canvas() const { return m_canvas; }
134
135protected:
143 void drawOnePageBorder( TQPainter * painter, const TQRect & crect, const TQRect & pageRect,
144 const TQRegion & emptySpaceRegion );
145 TQRect drawRightShadow( TQPainter * painter, const TQRect & crect, const TQRect & pageRect, int topOffset );
146 TQRect drawBottomShadow( TQPainter * painter, const TQRect & crect, const TQRect & pageRect, int leftOffset );
147 static const unsigned short s_shadowOffset;
148
149 KWDocument * m_doc;
150 KWCanvas * m_canvas;
151 bool m_drawFrameBorders;
152};
153
155class KWViewModeNormal : public KWViewMode
156{
157public:
158 KWViewModeNormal( KWDocument * doc, KWCanvas* canvas, bool drawFrameBorders )
159 : KWViewMode( doc, canvas, drawFrameBorders ) {}
160 virtual ~KWViewModeNormal() {}
161
162 virtual TQPoint normalToView( const TQPoint & nPoint );
163 virtual TQPoint viewToNormal( const TQPoint & vPoint );
164 virtual TQRect viewPageRect( int pgNum );
165 virtual TQSize contentsSize();
166
167 virtual const TQString type() const { return "ModeNormal"; }
168
169 virtual void drawPageBorders( TQPainter * painter, const TQRect & crect, const TQRegion & emptySpaceRegion );
170
171protected:
172 virtual int xOffset(KWPage *page, int canvasWidth = -1);
173};
174
176class KWViewModePrint : public KWViewModeNormal // we inherit the "normal" viewmode
177{
178public:
179 KWViewModePrint( KWDocument * doc, KWCanvas* canvas )
180 : KWViewModeNormal( doc, canvas, false /*drawFrameBorders*/ ) {}
181 virtual ~KWViewModePrint() {}
182 virtual bool drawSelections() { return false; }
183protected:
184 virtual int xOffset(KWPage *page, int canvasWidth = -1);
185};
186
188class KWViewModeEmbedded : public KWViewMode
189{
190public:
191 KWViewModeEmbedded ( KWDocument * doc, KWCanvas* canvas )
192 : KWViewMode( doc, canvas, false /*drawFrameBorders*/ ),
193 mDrawFrameBackground( true ),
194 mDrawSelections( true )
195 {}
196 virtual ~ KWViewModeEmbedded() {}
197
198 void setDrawFrameBackground( bool b ) { mDrawFrameBackground = b; }
199 void setDrawSelections( bool b ) { mDrawSelections = b; }
200
201 // This view mode is very easy to implement ;-P
202 virtual TQPoint normalToView( const TQPoint & nPoint ) { return nPoint; }
203 virtual TQPoint viewToNormal( const TQPoint & vPoint ) { return vPoint; }
204 virtual TQRect viewPageRect( int pgNum );
205 virtual TQSize contentsSize() { return TQSize(); }
206 virtual bool hasPages() { return false; }
207
208 virtual void drawPageBorders( TQPainter *, const TQRect &, const TQRegion & ){}
209 virtual bool drawSelections() { return mDrawSelections; }
210
211 virtual const TQString type() const { return "ModeEmbedded"; }
212 virtual bool drawFrameBackground() { return mDrawFrameBackground; }
213
214private:
215 bool mDrawFrameBackground;
216 bool mDrawSelections;
217};
218
219
222class KWViewModePreview : public KWViewMode
223{
224public:
225 KWViewModePreview( KWDocument * doc, KWCanvas* canvas, bool drawFrameBorders, int _nbPagePerRow );
226 virtual ~KWViewModePreview() {}
227
228 virtual TQPoint normalToView( const TQPoint & nPoint );
229 virtual TQPoint viewToNormal( const TQPoint & vPoint );
230 virtual TQRect viewPageRect( int pgNum );
231 virtual TQSize contentsSize();
232 virtual void drawPageBorders( TQPainter * painter, const TQRect & crect, const TQRegion & emptySpaceRegion );
233
234 virtual void setPagesPerRow(int _nb) {m_pagesPerRow=_nb;}
235 virtual int pagesPerRow() {return m_pagesPerRow;}
236 virtual const TQString type() const { return "ModePreview"; }
237
238 int numRows() const;
239
240//protected:
242 int leftSpacing();
244 int topSpacing();
245
246private:
247 int m_pagesPerRow;
248 int m_spacing;
249};
250
252class KWViewModeText : public KWViewMode
253{
254public:
255
256 KWViewModeText( KWDocument * doc, KWCanvas* canvas, KWTextFrameSet* fs );
257 virtual ~KWViewModeText() {}
258
259 KWTextFrameSet *textFrameSet() const;
266 static KWTextFrameSet *determineTextFrameSet( KWDocument* doc );
267
268 virtual TQPoint normalToView( const TQPoint & nPoint );
269 virtual TQPoint viewToNormal( const TQPoint & vPoint );
270 virtual TQSize contentsSize();
271 virtual TQRect viewPageRect( int ) { return TQRect(); }
272 virtual TQSize availableSizeForText( KWTextFrameSet* textfs );
273 // There is no page concept. Keep everything relative to (0,0)
274 virtual TQPoint pageCorner() { return TQPoint( 0, 0 ); }
275 virtual TQRect rulerFrameRect();
276 virtual void setPageLayout( KoRuler* hRuler, KoRuler* vRuler, const KoPageLayout& layout );
277
278 virtual void drawPageBorders( TQPainter * painter, const TQRect & crect, const TQRegion & emptySpaceRegion );
279 virtual const TQString type() const { return "ModeText"; }
280 virtual bool shouldFormatVertically() { return false; }
281 virtual bool shouldAdjustMargins() { return false; }
282 virtual bool hasFrames() { return false; }
283 virtual bool hasPages() { return false; }
284
285 virtual bool isFrameSetVisible( const KWFrameSet* fs );
286
287 virtual bool isTextModeFrameset(KWFrameSet *fs) const;
288
290 static const int OFFSET = 10;
291
292
293private:
294 mutable KWTextFrameSet *m_textFrameSet;
295};
296
297#endif
Class: KWCanvas This class is responsible for the rendering of the frames to the screen as well as th...
Definition KWCanvas.h:61
Class: KWFrameSet Base type, a frameset holds content as well as frames to show that content.
Definition KWFrameSet.h:62
This class represents a printed page of the document.
Definition KWPage.h:30
Class: KWTextFrameSet Contains text (KoTextObject) and frames to display that text.
virtual bool hasPages()
Does this viewmode know anything about pages?
Definition KWViewMode.h:206
virtual bool drawSelections()
Should selected text be drawn as such?
Definition KWViewMode.h:209
virtual TQRect viewPageRect(int pgNum)
Return view coord for page rect.
virtual TQSize contentsSize()
Size of the contents area, in pixels.
Definition KWViewMode.h:205
virtual TQPoint viewToNormal(const TQPoint &vPoint)
View coord -> normal coord.
Definition KWViewMode.h:203
virtual const TQString type() const
Return the name of the viewmode, used for loading/saving.
Definition KWViewMode.h:211
virtual bool drawFrameBackground()
Should frame background be drawn?
Definition KWViewMode.h:212
virtual TQPoint normalToView(const TQPoint &nPoint)
Normal coord -> view coord.
Definition KWViewMode.h:202
virtual TQPoint viewToNormal(const TQPoint &vPoint)
View coord -> normal coord.
virtual TQSize contentsSize()
Size of the contents area, in pixels.
virtual const TQString type() const
Return the name of the viewmode, used for loading/saving.
Definition KWViewMode.h:167
virtual TQRect viewPageRect(int pgNum)
Return view coord for page rect.
virtual TQPoint normalToView(const TQPoint &nPoint)
Normal coord -> view coord.
virtual const TQString type() const
Return the name of the viewmode, used for loading/saving.
Definition KWViewMode.h:236
virtual void setPagesPerRow(int _nb)
Config option for KWViewModePreview (a bit of a hack).
Definition KWViewMode.h:234
int leftSpacing()
Return the spacing between the left border of the canvas and the page.
virtual TQRect viewPageRect(int pgNum)
Return view coord for page rect.
int topSpacing()
Return the spacing between the top border of the canvas and the page.
virtual TQPoint normalToView(const TQPoint &nPoint)
Normal coord -> view coord.
virtual TQPoint viewToNormal(const TQPoint &vPoint)
View coord -> normal coord.
virtual TQSize contentsSize()
Size of the contents area, in pixels.
virtual bool drawSelections()
Should selected text be drawn as such?
Definition KWViewMode.h:182
virtual TQSize contentsSize()
Size of the contents area, in pixels.
virtual TQRect rulerFrameRect()
The result of this is passed to setFrameStartEnd for both rulers (after adjustement with pageCorner()...
static KWTextFrameSet * determineTextFrameSet(KWDocument *doc)
Return a text frameset that the user has either selected or is currently editing, returning the main ...
virtual bool isFrameSetVisible(const KWFrameSet *fs)
Should this frameset be visible in this viewmode?
virtual TQPoint pageCorner()
"Topleft of current page" - concept used by the rulers.
Definition KWViewMode.h:274
virtual bool hasPages()
Does this viewmode know anything about pages?
Definition KWViewMode.h:283
virtual void setPageLayout(KoRuler *hRuler, KoRuler *vRuler, const KoPageLayout &layout)
Called when the page layout is set, or changes.
virtual TQPoint viewToNormal(const TQPoint &vPoint)
View coord -> normal coord.
virtual TQPoint normalToView(const TQPoint &nPoint)
Normal coord -> view coord.
virtual bool shouldAdjustMargins()
Should adjust[LR]Margin() happen (to run the text around frames on top etc.).
Definition KWViewMode.h:281
virtual TQRect viewPageRect(int)
Return view coord for page rect.
Definition KWViewMode.h:271
static const int OFFSET
hardcoded distance from the left side this viewmode starts its rendering
Definition KWViewMode.h:290
virtual TQSize availableSizeForText(KWTextFrameSet *textfs)
Size (in pixels) of the total area available for text in a given textframeset This is used by KWTextF...
virtual bool hasFrames()
Does this viewmode know anything about frames?
Definition KWViewMode.h:282
virtual const TQString type() const
Return the name of the viewmode, used for loading/saving.
Definition KWViewMode.h:279
virtual bool shouldFormatVertically()
Should formatVertically() happen (to skip frame bottom, frames on top, etc.).
Definition KWViewMode.h:280
virtual bool isTextModeFrameset(KWFrameSet *fs) const
Answers the question if argument frameset has to be drawn as a text-mode text area if true,...
Abstract base class for KWCanvas's view modes.
Definition KWViewMode.h:48
TQRect normalToView(const TQRect &nRect)
Normal coord -> view coord.
Definition KWViewMode.h:60
TQRect viewToNormal(const TQRect &nRect)
View coord -> normal coord.
Definition KWViewMode.h:67
virtual void setPagesPerRow(int)
Config option for KWViewModePreview (a bit of a hack).
Definition KWViewMode.h:95
virtual bool hasFrames()
Does this viewmode know anything about frames?
Definition KWViewMode.h:119
virtual void setPageLayout(KoRuler *hRuler, KoRuler *vRuler, const KoPageLayout &layout)
Called when the page layout is set, or changes.
virtual bool isTextModeFrameset(KWFrameSet *) const
Answers the question if argument frameset has to be drawn as a text-mode text area if true,...
Definition KWViewMode.h:129
virtual TQRect rulerFrameRect()
The result of this is passed to setFrameStartEnd for both rulers (after adjustement with pageCorner()...
virtual TQPoint pageCorner()
"Topleft of current page" - concept used by the rulers.
virtual TQSize availableSizeForText(KWTextFrameSet *textfs)
Size (in pixels) of the total area available for text in a given textframeset This is used by KWTextF...
virtual TQPoint normalToView(const TQPoint &nPoint)=0
Normal coord -> view coord.
virtual bool hasPages()
Does this viewmode know anything about pages?
Definition KWViewMode.h:122
virtual TQRect viewPageRect(int pgNum)=0
Return view coord for page rect.
virtual bool drawSelections()
Should selected text be drawn as such?
Definition KWViewMode.h:99
virtual bool shouldFormatVertically()
Should formatVertically() happen (to skip frame bottom, frames on top, etc.).
Definition KWViewMode.h:113
virtual bool shouldAdjustMargins()
Should adjust[LR]Margin() happen (to run the text around frames on top etc.).
Definition KWViewMode.h:116
bool drawFrameBorders() const
Should we see frame borders?
Definition KWViewMode.h:105
virtual TQSize contentsSize()=0
Size of the contents area, in pixels.
virtual TQPoint viewToNormal(const TQPoint &vPoint)=0
View coord -> normal coord.
virtual bool drawFrameBackground()
Should frame background be drawn?
Definition KWViewMode.h:102
virtual bool isFrameSetVisible(const KWFrameSet *)
Should this frameset be visible in this viewmode?
Definition KWViewMode.h:109
void drawOnePageBorder(TQPainter *painter, const TQRect &crect, const TQRect &pageRect, const TQRegion &emptySpaceRegion)
Draw the border around one page, and clear up the empty space in that page.
virtual const TQString type() const =0
Return the name of the viewmode, used for loading/saving.