krita

kobirdeyepanel.h

00001 /*
00002  * This file is part of the KDE project
00003  *
00004  * Copyright (c) 2005 Boudewijn Rempt <boud@valdyas.org>
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #ifndef KO_BIRD_EYE_PANEL
00022 #define KO_BIRD_EYE_PANEL
00023 
00024 #include <qrect.h>
00025 #include <qwidget.h>
00026 
00027 #include <KoPoint.h>
00028 #include <KoRect.h>
00029 
00030 class QPixmap;
00031 class KAction;
00032 class KoDocument;
00033 class WdgBirdEye;
00034 
00035 
00036 class KoCanvasAdapter {
00037 
00038 public:
00039     
00040     KoCanvasAdapter();
00041     virtual ~KoCanvasAdapter();
00042 
00046     virtual KoRect visibleArea() = 0;
00047     
00052     virtual QRect size() = 0;
00053     
00057     virtual double zoomFactor() = 0;
00058 
00062     virtual void setViewCenterPoint(double x, double y) = 0;
00063 };
00064 
00070 class KoZoomAdapter {
00071 
00072 public:
00073 
00074     KoZoomAdapter();
00075     virtual ~KoZoomAdapter();
00076 
00080     virtual void zoomTo(double x, double y, double factor ) = 0;
00081     
00085     virtual void zoomIn() = 0;
00086     
00090     virtual void zoomOut() = 0;
00091     
00095     virtual double getMinZoom() = 0;
00096 
00100     virtual double getMaxZoom() = 0;
00101 
00102 };
00103 
00104 
00105 class KoThumbnailAdapter
00106 {
00107     public:
00108     
00109         KoThumbnailAdapter();
00110         ~KoThumbnailAdapter();
00111         
00120         virtual QSize pixelSize() = 0;
00121         
00130         virtual QImage image(QRect r, QSize thumbnailSize) = 0;
00131 };
00132 
00138 class KoBirdEyePanel : public QWidget {
00139 
00140     Q_OBJECT
00141 
00142 public:
00143 
00155     KoBirdEyePanel( KoZoomAdapter * zoomListener, 
00156                     KoThumbnailAdapter * thumbnailProvider,
00157                     KoCanvasAdapter * canvas,
00158                     QWidget * parent,
00159                     const char * name = 0,
00160                     WFlags f = 0 );
00161 
00162     virtual ~KoBirdEyePanel();
00163 
00164     bool eventFilter(QObject*, QEvent*);
00165 
00166 public slots:
00167 
00168     void setZoomListener( KoZoomAdapter * zoomListener) { m_zoomListener = zoomListener; }
00169 
00173     void setThumbnailProvider( KoThumbnailAdapter * thumbnailProvider );
00174 
00179     void slotViewTransformationChanged();
00180     
00181     void cursorPosChanged(Q_INT32 xpos, Q_INT32 ypos);
00182 
00183     void zoomMinus();
00184     void zoomPlus();
00185 
00191     void slotUpdate(const QRect & r);
00192 
00193 protected slots:
00194 
00195     void updateVisibleArea();
00196     void zoomValueChanged(int zoom);
00197     void zoom100();
00198     void sliderChanged(int);
00199     
00200 protected:
00201     void setZoom(int zoom);
00202             
00203     void handleMouseMove(QPoint);
00204     void handleMouseMoveAction(QPoint);
00205     void handleMousePress(QPoint);
00206     void fitThumbnailToView();
00207     void renderView();
00208     void resizeViewEvent(QSize size);
00209     void paintViewEvent(QPaintEvent *e);
00210     void makeThumbnailRectVisible(const QRect& r);
00211 
00212     enum enumDragHandle {
00213         DragHandleNone,
00214         DragHandleLeft,
00215         DragHandleCentre,
00216         DragHandleRight,
00217         DragHandleTop,
00218         DragHandleBottom
00219     };
00220 
00221     /*
00222      * Returns the drag handle type at point p in thumbnail coordinates.
00223      */
00224     enumDragHandle dragHandleAt(QPoint p);
00225 
00229     QRect documentToThumbnail(const KoRect& docRect);
00230 
00234     KoRect thumbnailToDocument(const QRect& thumbnailRect);
00235 
00239     QPoint viewToThumbnail(const QPoint& viewPoint);
00240 
00241 private:
00242     
00243     WdgBirdEye * m_page;
00244     
00245     KoZoomAdapter * m_zoomListener;
00246     KoThumbnailAdapter * m_thumbnailProvider;
00247     KoCanvasAdapter * m_canvas;
00248     
00249     KAction* m_zoomIn;
00250     KAction* m_zoomOut;
00251     QPixmap m_viewBuffer;
00252     QPixmap m_thumbnail;
00253 
00254     QSize m_documentSize;
00255     QRect m_visibleAreaInThumbnail;
00256     bool m_dragging;
00257     enumDragHandle m_dragHandle;
00258     QPoint m_lastDragPos;
00259 
00260 };
00261 
00262 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys