Scribus Developer Documentation - API
logo-pen

Scribus Developer Documentation - API

canvas.h

Go to the documentation of this file.
00001 /*
00002  For general Scribus (>=1.3.2) copyright and licensing information please refer
00003  to the COPYING file provided with the program. Following this notice may exist
00004  a copyright and/or license notice that predates the release of Scribus 1.3.2
00005  for which a new license (GPL+exception) is in place.
00006  */
00007 /***************************************************************************
00008 scribusview.h  -  description
00009 -------------------
00010     begin                : Fre Apr  6 21:47:55 CEST 2001
00011     copyright            : (C) 2001 by Franz Schmid
00012     email                : Franz.Schmid@altmuehlnet.de
00013     ***************************************************************************/
00014 
00015 /***************************************************************************
00016 *                                                                         *
00017 *   This program is free software; you can redistribute it and/or modify  *
00018 *   it under the terms of the GNU General Public License as published by  *
00019 *   the Free Software Foundation; either version 2 of the License, or     *
00020 *   (at your option) any later version.                                   *
00021 *                                                                         *
00022 ***************************************************************************/
00023 
00024 #ifndef CANVAS_H
00025 #define CANVAS_H
00026 
00027 #include <QApplication>
00028 #include <QDebug>
00029 #include <QPolygon>
00030 #include <QRect>
00031 #include <QWidget>
00032 
00033 #include "scribusapi.h"
00034 
00035 #include "commonstrings.h"
00036 #include "fpoint.h"
00037 #include "fpointarray.h"
00038 
00039 
00040 class Page;
00041 class PageItem;
00042 class ScPainter;
00043 class ScribusDoc;
00044 class ScribusView;
00045 
00046 struct CanvasViewMode
00047 {
00048     void init();
00049     
00050     double scale;
00051 
00052     bool previewMode;
00053     bool viewAsPreview;
00054     int previewVisual;
00055 
00056     bool m_MouseButtonPressed;
00057     bool operItemMoving;
00058     bool operItemResizing;
00059     bool operItemResizeInEditMode;
00060     QPolygon redrawPolygon;
00061     QList<PageItem*> linkedFramesToShow;
00062     
00064     bool drawSelectedItemsWithControls;
00066     bool drawFramelinksWithContents;
00067     
00068     // used for buffering:
00069     bool forceRedraw;
00070 };
00071 
00072 
00073 class SCRIBUS_API Canvas : public QWidget
00074 {
00075     Q_OBJECT
00076     
00077 public: 
00078     static const uint moveWithFullOutlinesThreshold = 21;
00079     static const uint moveWithBoxesOnlyThreshold = 41;
00080 
00081     Canvas(ScribusDoc* doc, ScribusView* parent);
00082     
00083     friend class ScribusView; // for now...
00084     friend class LegacyMode;
00085     friend class CanvasMode_NodeEdit;
00086     friend class FreehandMode;
00087     
00088     /* Dont rely on these codes!
00089      * 283
00090      * 7 6
00091      * 451
00092      * But always OUTSIDE < 0, INSIDE >= 0 and any specific handle > 0.
00093      */
00094     enum FrameHandle { 
00095         OUTSIDE = -1,
00096         INSIDE = 0,
00097         NORTHWEST = 2,
00098         NORTH = 8,
00099         NORTHEAST = 3,
00100         EAST = 6,
00101         SOUTHEAST = 1,
00102         SOUTH = 5,
00103         SOUTHWEST = 4,
00104         WEST = 7
00105     };
00106     
00107     enum RenderMode {
00108         RENDER_NORMAL,                // update buffer, paint buffer: expensive for large regions
00109         RENDER_BUFFERED,              // just paint buffer: fast, but only controls may change (eg. resize mode)
00110         // in the following two modes, only the selected objects are updated. Might not be exact.
00111         RENDER_SELECTION_SEPARATE,    // paint buffer w/o selection, then paint selection (eg. img edit, nodeedit, rotate, beziercurve)
00112         RENDER_SELECTION_BUFFERED,    // paint buffer w/o selection, update selection buffer, then paint selection buffer (eg. move, text edit)
00113         RENDER_LEGACY
00114     };
00115     
00116     void setRenderMode(RenderMode m);
00117     
00118     void clearBuffers();              // very expensive
00119     
00120     // deprecated:
00121     void resetRenderMode() { m_renderMode = RENDER_NORMAL; clearBuffers(); }
00122     void setRenderModeFillBuffer() { m_renderMode = RENDER_BUFFERED; }
00123     void setRenderModeUseBuffer(bool use) { m_renderMode = (use ? RENDER_BUFFERED : RENDER_NORMAL) ; }
00124 
00125     double scale() const { return m_viewMode.scale; }
00126     void setScale(double scale) { if (m_viewMode.scale != scale) { m_viewMode.scale = scale; clearBuffers(); update(); } }
00127     QPoint canvasToLocal(FPoint p) const;
00128     QPoint canvasToGlobal(FPoint p) const;
00129     QPoint canvasToLocal(QPointF p) const;
00130     QPoint canvasToGlobal(QPointF p) const;
00131     QRect canvasToLocal(QRectF p) const;
00132     QRect canvasToGlobal(QRectF p) const;
00133     FPoint localToCanvas(QPoint p) const;
00134 //  FPoint localToCanvas(QPointF p) const;
00135     FPoint globalToCanvas(QPoint p) const;
00136 //  FPoint globalToCanvas(QPointF p) const;
00137     QRectF globalToCanvas(QRect p) const;
00138 //  QRectF globalToCanvas(QRectF p) const;
00139     bool hitsCanvasPoint(QPoint globalPoint, FPoint canvasPoint) const;
00140     bool hitsCanvasPoint(QPoint globalPoint, QPointF canvasPoint) const;
00142     FrameHandle frameHitTest(QPointF canvasPoint, PageItem* frame) const;
00143     FrameHandle frameHitTest(QPointF point, QRectF frame) const;
00152     PageItem* itemUnderCursor(QPoint globalPos, PageItem* itemAbove=NULL, bool allowInGroup=false, bool allowMasterItems=false) const;
00153     const QPolygon& redrawPolygon() const { return m_viewMode.redrawPolygon; }
00154     QPolygon& newRedrawPolygon() 
00155     {
00156         m_viewMode.redrawPolygon.clear();
00157         return m_viewMode.redrawPolygon;
00158     }
00159     void setPreviewMode(bool on) { m_viewMode.previewMode = on; }
00160     bool isPreviewMode() const { return m_viewMode.previewMode || m_viewMode.viewAsPreview; }
00161     bool usePreviewVisual() const { return m_viewMode.viewAsPreview && m_viewMode.previewVisual != 0; }
00162     int previewVisual() const { return m_viewMode.previewVisual; }
00163     void setPreviewVisual(int mode) { m_viewMode.previewVisual = qMax(0, mode); m_viewMode.viewAsPreview = (mode >= 0); }
00164     
00165     void DrawMasterItems(ScPainter *painter, Page *page, QRect clip);
00166     void DrawPageItems(ScPainter *painter, QRect clip);
00167     virtual void paintEvent ( QPaintEvent * p );
00168     
00169 private:
00170     void DrawPageMarks(ScPainter *p, Page* page, QRect clip);
00171     void drawLinkFrameLine(ScPainter* painter, FPoint &start, FPoint &end);
00172     void PaintSizeRect(QRect neu);
00173     void PaintSizeRect(QPolygon neu);
00174     void Transform(PageItem *currItem, QPainter *p);
00175     void Transform(PageItem *currItem, QMatrix& m);
00176     void TransformM(PageItem *currItem, QPainter *p);
00177     void getGroupRectScreen(double *x, double *y, double *w, double *h);
00178 
00182     void adjustBuffer();
00187     void fillBuffer(QPaintDevice* buffer, QPoint bufferOrigin, QRect clipRect);
00188     void drawContents(QPainter *p, int clipx, int clipy, int clipw, int cliph);
00189     void drawBackgroundMasterpage(ScPainter* painter, int clipx, int clipy, int clipw, int cliph);
00190     void drawBackgroundPageOutlines(ScPainter* painter, int clipx, int clipy, int clipw, int cliph);
00191     void drawGuides(ScPainter* painter, int clipx, int clipy, int clipw, int cliph);
00192     void drawFrameLinks(ScPainter* painter);
00193     void drawControls(QPainter* p);
00194     void drawControlsMovingItemsRect(QPainter* pp);
00195 //  void drawControlsHighlightRect(QPainter* pp);
00196     void drawControlsGradientVectors(QPainter* psx, PageItem *currItem);
00197     void drawControlsBezierCurve(QPainter* pp, PageItem* currItem);
00198     void drawControlsMeasurementLine(QPainter* pp);
00199     void drawControlsDrawLine(QPainter* pp);
00200     void drawControlsFreehandLine(QPainter* pp);
00201     void getClipPathForPages(FPointArray* PoLine);
00202     void calculateFrameLinkPoints(PageItem* pi1, PageItem* pi2, FPoint& start, FPoint& end);
00203         
00204 private:
00205     ScribusDoc* m_doc;
00206     ScribusView* m_view;
00207     CanvasViewMode m_viewMode;
00208     
00209     RenderMode m_renderMode;
00210     QPixmap m_buffer;
00211     QRect m_bufferRect;
00212     QPixmap m_selectionBuffer;
00213     QRect m_selectionRect;
00214     FPoint m_oldMinCanvasCoordinate;
00215 };
00216 
00217 
00218 #endif
00219 
Created with personalized Doxygen. This is documentation for GPL software Scribus - Open Source Desktop Publishing.