2 This file is part of Kig, a KDE program for Interactive Geometry...
3 Copyright (C) 2002 Dominique Devriese <devriese@kde.org>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program 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
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
28 #include <kparts/part.h>
32 #include "../objects/object_holder.h"
33 #include "../misc/rect.h"
34 #include "../misc/screeninfo.h"
43 * This class is the real widget showing the document. The other is a
44 * wrapper, that has the scrollbars... I'm not using QScrollView
45 * cause i've been having problems with that, and it's easier to do
47 * Internally, this is basically a dumb class, which is manipulated by
48 * KigMode's. All events are forwarded to them.
50 class KigWidget
: public QWidget
57 // we reimplement these from QWidget to suit our needs
58 void mousePressEvent( QMouseEvent
* e
);
59 void mouseMoveEvent( QMouseEvent
* e
);
60 void mouseReleaseEvent( QMouseEvent
* e
);
61 void paintEvent( QPaintEvent
* e
);
62 void wheelEvent( QWheelEvent
* e
);
63 void resizeEvent( QResizeEvent
* );
64 QSize
sizeHint() const;
66 // this is called to match a rect's dimensions to the dimensions of
67 // the window before we set mViewRect to it. This is done cause we
68 // always want circles to look like circles etc...
69 Rect
matchScreenShape( const Rect
& r
) const;
72 // what do the still objects look like
73 // wondering if this is appropriate, maybe it should be part of
76 // temporary, gets bitBlt'd (copied) onto the widget
77 // (to avoid flickering)
81 std::vector
<QRect
> oldOverlay
;
84 * this is a class that maps from our widget coordinates to the
85 * document's coordinates ( and back ).
90 * is this a full-screen widget ?
96 * standard qwidget constructor. if fullscreen is true, we're a
99 KigWidget( KigPart
* doc
,
102 const char* name
= 0,
103 bool fullscreen
= false
107 bool isFullScreen() const;
108 void setFullScreen( bool f
);
110 const KigView
* view() const {
119 * The following are functions used by KigMode's to tell us to draw
121 * i tried to optimise the drawing as much as possible, using
122 * much ideas from kgeo
124 * we don't draw on the widget directly, we draw on a QPixmap (
125 * curPix ), and bitBlt that onto the widget to avoid flickering.
127 * we also currently keep an extra pixmap of what the widget looks
128 * like without objects that are moving... i'm currently wondering
129 * whether this isn't a performance loss rather than a gain, but
130 * well, i haven't done any measurements (yet ?), so for now it
133 * Another thing: it turns out that working on the pixmaps isn't
134 * that slow, but working on the widget is. So we try to reduce the
135 * amount of work we spend on the widget. (i got this idea from
136 * kgeo, all credits for this go to marc.bartsch@web.de)
137 * on drawing, KigPainter tells us (appendOverlay) for everything it
138 * draws what rects it draws in, so we know on updating the widget (
139 * updateWidget() that the rest is still ok and doesn't need to be
140 * bitBlt'd again on the widget...
144 void clearStillPix();
145 // update curPix (bitBlt stillPix onto curPix..)
146 void updateCurPix( const std::vector
<QRect
>& = std::vector
<QRect
>());
148 // this means bitBlting curPix on the actual widget...
149 void updateWidget( const std::vector
<QRect
>& = std::vector
<QRect
>() );
150 void updateEntireWidget();
152 /** Mapping between Internal Coordinate Systems
153 * there are two coordinate systems:
154 * 1 the widget's coordinates: these are simple int's from (0,0) in
155 * the topleft of the widget to size() in the bottomRight...
156 * 2 the document's coordinates: these are the coordinates used by
157 * the KigDocument. Objects only know of their coordinates as
158 * related to this system.
159 * These are mapped by the KigView using the ScreenInfo class.
161 const Rect
showingRect() const;
162 void setShowingRect( const Rect
& r
);
164 const Coordinate
fromScreen( const QPoint
& p
);
165 const Rect
fromScreen( const QRect
& r
);
166 double pixelWidth() const;
168 // the part of the document we're currently showing
169 // i.e. a rectangle of the document (which has its own coordinate
170 // system) which is mapped onto the widget.
171 const ScreenInfo
& screenInfo() const;
173 Rect
entireDocumentRect() const;
175 void updateScrollBars();
177 void scrollSetBottom( double rhs
);
178 void scrollSetLeft( double rhs
);
180 const KigDocument
& document() const;
183 // this recenters the screen, that is, resets the shown rect to
184 // mpart->document().suggestedRect()..
185 void recenterScreen();
186 // this gets called if the user clicks the recenter screen button.
187 // It adds a KigCommand to the CommandHistory that recenters the
189 void slotRecenterScreen();
191 // called when the user clicks the appropriate buttons..
198 void redrawScreen( const std::vector
<ObjectHolder
*>& selection
, bool paintOnWidget
= true );
202 * This class is a wrapper for KigWidget. It has some actions
203 * that belong here, and not in the part. It also maintains the
204 * scrollbars, but it doesn't manipulate them itself. It forwards
205 * most of its functionality to KigWidget...
212 QGridLayout
* mlayout
;
213 QScrollBar
* mrightscroll
;
214 QScrollBar
* mbottomscroll
;
216 // apparently, QScrollBar also emits its signals when you update it
217 // manually, so we ignore them while we're in updateScrollBars()...
218 bool mupdatingscrollbars
;
220 KigWidget
* mrealwidget
;
224 KigView( KigPart
* part
,
225 bool fullscreen
= false,
233 const ScreenInfo
& screenInfo() const;
235 KigWidget
* realWidget() const;
236 void scrollHorizontal( int delta
);
237 void scrollVertical( int delta
);
240 void updateScrollBars();
245 void slotInternalRecenterScreen();
246 void slotRecenterScreen();
247 void toggleFullScreen();
250 void slotRightScrollValueChanged( int );
251 void slotBottomScrollValueChanged( int );