00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
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;
00084 friend class LegacyMode;
00085 friend class CanvasMode_NodeEdit;
00086 friend class FreehandMode;
00087
00088
00089
00090
00091
00092
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,
00109 RENDER_BUFFERED,
00110
00111 RENDER_SELECTION_SEPARATE,
00112 RENDER_SELECTION_BUFFERED,
00113 RENDER_LEGACY
00114 };
00115
00116 void setRenderMode(RenderMode m);
00117
00118 void clearBuffers();
00119
00120
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
00135 FPoint globalToCanvas(QPoint p) const;
00136
00137 QRectF globalToCanvas(QRect p) const;
00138
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
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