libs/flake

KoCanvasController.h

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002  * Copyright (C) 2006, 2008 Thomas Zander <zander@kde.org>
00003  * Copyright (C) 2007 Boudewijn Rempt <boud@valdyas.org>
00004  * Copyright (C) 2007-2008 Casper Boemann <cbr@boemann.dk>
00005  * Copyright (C) 2006-2007 Jan Hambrecht <jaham@gmx.net>
00006  * Copyright (C) 2009 Thorsten Zachmann <zachmann@kde.org>
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Library General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2 of the License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Library General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Library General Public License
00019  * along with this library; see the file COPYING.LIB.  If not, write to
00020  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00021  * Boston, MA 02110-1301, USA.
00022  */
00023 
00024 #ifndef KOCANVASCONTROLLER_H
00025 #define KOCANVASCONTROLLER_H
00026 
00027 #include "flake_export.h"
00028 
00029 #include <QAbstractScrollArea>
00030 
00031 class KoShape;
00032 class KoCanvasBase;
00033 class KoView;
00034 
00055 class FLAKE_EXPORT KoCanvasController : public QAbstractScrollArea
00056 {
00057     Q_OBJECT
00058 public:
00060     enum CanvasMode {
00061         AlignTop,     
00062         Centered,     
00063         Infinite,     
00064         Presentation  
00065     };
00066 
00071     explicit KoCanvasController(QWidget *parent = 0);
00072     virtual ~KoCanvasController();
00076     void scrollContentsBy(int dx, int dy);
00077 
00085     void setDrawShadow(bool drawShadow);
00086 
00094     void setCanvas(KoCanvasBase *canvas);
00099     KoCanvasBase* canvas() const;
00100 
00107     void changeCanvasWidget(QWidget *widget);
00108 
00113     int visibleHeight() const;
00118     int visibleWidth() const;
00123     int canvasOffsetX() const;
00128     int canvasOffsetY() const;
00129 
00134     void setCanvasMode(CanvasMode mode);
00135 
00137     CanvasMode canvasMode() const;
00138 
00140     bool isCanvasOpenGL() const;
00141 
00143     virtual bool eventFilter(QObject *watched, QEvent *event);
00144 
00154     void ensureVisible(const QRectF &rect, bool smooth = false);
00155 
00163     void ensureVisible(KoShape *shape);
00164 
00174     void setToolOptionWidgets(const QMap<QString, QWidget *> &);
00175 
00184     void zoomIn(const QPoint &center);
00185 
00194     void zoomOut(const QPoint &center);
00195 
00205     void zoomBy(const QPoint &center, qreal zoom);
00206 
00215     void zoomTo(const QRect &rect);
00216 
00226     void recenterPreferred();
00227 
00232     void setPreferredCenter(const QPoint &viewPoint);
00233 
00235     QPoint preferredCenter() const;
00236 
00241     void pan(const QPoint &distance);
00242 
00247     int margin() const;
00248 
00252     void setMargin(int margin);
00253 
00257     QPoint scrollBarValue() const;
00258 
00263     void setScrollBarValue(const QPoint &value);
00264 
00265 signals:
00270     void canvasRemoved(KoCanvasController *cv);
00275     void canvasSet(KoCanvasController *cv);
00276 
00281     void canvasOffsetXChanged(int offset);
00282 
00287     void canvasOffsetYChanged(int offset);
00288 
00293     void canvasMousePositionChanged(const QPoint &pos);
00294 
00299     void documentMousePositionChanged(const QPointF &pos);
00300 
00305     void sizeChanged(const QSize &size);
00306 
00310     void toolOptionWidgetsChanged(const QMap<QString, QWidget *> &, QWidget *);
00311 
00315     void toolOptionWidgetsChanged(const QMap<QString, QWidget *> &);
00316 
00323     void moveDocumentOffset(const QPoint &point);
00324 
00332     void zoomBy(const qreal factor);
00333 
00334 public slots:
00335 
00343     void setDocumentSize(const QSize &newSize, bool recalculateCenter = true);
00344 
00350     void addGuideLine(Qt::Orientation orientation, int viewPosition);
00351 
00352 protected slots:
00353 
00355     void updateCanvasOffsetX();
00356 
00358     void updateCanvasOffsetY();
00359 
00360 protected:
00362     virtual void paintEvent(QPaintEvent *event);
00364     virtual void resizeEvent(QResizeEvent *resizeEvent);
00366     virtual void dragEnterEvent(QDragEnterEvent *event);
00368     virtual void dropEvent(QDropEvent *event);
00370     virtual void dragMoveEvent(QDragMoveEvent *event);
00372     virtual void dragLeaveEvent(QDragLeaveEvent *event);
00374     virtual void wheelEvent(QWheelEvent *event);
00376     virtual void keyPressEvent(QKeyEvent *event);
00378     virtual bool focusNextPrevChild(bool next);
00379 
00380 
00381 private:
00382 
00383     void setDocumentOffset();
00384 
00385     void resetScrollBars();
00386     void emitPointerPositionChangedSignals(QEvent *event);
00387 
00388     friend class KoToolManager;
00389 
00390 private slots:
00394     void activate();
00395 
00396 private:
00397 
00398     class Private;
00399     Private * const d;
00400 };
00401 
00402 #endif