~ubuntu-branches/ubuntu/edgy/koffice/edgy-updates

« back to all changes in this revision

Viewing changes to kontour/Canvas.h

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20040509113300-xi5t1z4yxe7n03x7
Tags: upstream-1.3.1
ImportĀ upstreamĀ versionĀ 1.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- C++ -*-
2
 
 
3
 
  $Id: Canvas.h,v 1.41 2001/07/25 12:23:49 rm Exp $
4
 
 
5
 
  This file is part of KIllustrator.
6
 
  Copyright (C) 1998-99 Kai-Uwe Sattler (kus@iti.cs.uni-magdeburg.de)
7
 
  Copyright (C) 2000-2001 Igor Janssen (rm@linux.ru.net)
8
 
 
9
 
  This program is free software; you can redistribute it and/or modify
10
 
  it under the terms of the GNU Library General Public License as
11
 
  published by
12
 
  the Free Software Foundation; either version 2 of the License, or
13
 
  (at your option) any later version.
14
 
 
15
 
  This program is distributed in the hope that it will be useful,
16
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 
  GNU General Public License for more details.
19
 
 
20
 
  You should have received a copy of the GNU Library General Public License
21
 
  along with this program; if not, write to the Free Software
22
 
  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23
 
 
24
 
*/
25
 
 
26
 
#ifndef Canvas_h_
27
 
#define Canvas_h_
28
 
 
29
 
#include <qwidget.h>
30
 
#include <qvaluelist.h>
31
 
#include <qscrollview.h>
32
 
#include <koprinter.h>
33
 
 
34
 
#include "Coord.h"
35
 
 
36
 
class GDocument;
37
 
class GObject;
38
 
class ToolController;
39
 
class QPixmap;
40
 
class QPainter;
41
 
class Rect;
42
 
class QColor;
43
 
class QSize;
44
 
class QScrollBar;
45
 
class KPrinter;
46
 
 
47
 
class Canvas : public QWidget {
48
 
  Q_OBJECT
49
 
public:
50
 
  Canvas (GDocument *doc, float res, QScrollBar *hb, QScrollBar *vb, QWidget *parent = 0, const char *name = 0);
51
 
  ~Canvas ();
52
 
 
53
 
  void setDocument (GDocument* doc);
54
 
  GDocument* getDocument () const { return document; };
55
 
 
56
 
  void setZoomFactor (float factor, int centerX, int centerY);
57
 
  void setZoomFactor (float factor);
58
 
  float getZoomFactor () const { return zoomFactor; };
59
 
 
60
 
  float scaleFactor () const { return resolution * zoomFactor / 72.0; };
61
 
 
62
 
  //int xOffset () const {return mXOffset; };
63
 
  //int yOffset () const {return mYOffset; };
64
 
 
65
 
  //put the given point in the center of the canvas
66
 
  //x and y are relative to the center of the paper
67
 
  void center(int x=0, int y=0);
68
 
 
69
 
  //return the rectangle covered by the paper in points on the screen
70
 
  //upper left corner is always (0,0)
71
 
  //it changes only when zooming or chaning the paper size
72
 
  QRect paperArea()             {return m_paperArea;};
73
 
  //return the currently visible rectangle
74
 
  //coordinates are relative to the upper left corner of the paper
75
 
  //it changes when scrolling, zooming, resizing, alex
76
 
  QRect visibleArea()           {return m_visibleArea;};
77
 
 
78
 
  //return the coordinates of the paper relative to current canvas size
79
 
  //((-10,-10),(-10,-10)) means that the paper is on every edge
80
 
  //10 points bigger than the current canvas
81
 
  //it changes when scrolling, zooming, resizing and changing the paper size, alex
82
 
  QRect relativePaperArea()     {return m_relativePaperArea;};
83
 
 
84
 
  void snapPositionToGrid (float& x, float& y);
85
 
  Rect snapTranslatedBoxToGrid (const Rect& r);
86
 
  Rect snapScaledBoxToGrid (const Rect& r, int hmask);
87
 
 
88
 
  void setToolController (ToolController *tc);
89
 
 
90
 
  /* Printing */
91
 
  void setupPrinter( KPrinter &printer );
92
 
  void print( KPrinter &printer );
93
 
 
94
 
  void showBasePoints (bool flag = true);
95
 
  void setOutlineMode (bool flag);
96
 
 
97
 
  void setXimPosition(int x, int y, int w, int h);
98
 
 
99
 
protected:
100
 
  QRect m_paperArea;
101
 
  QRect m_visibleArea;
102
 
  QRect m_relativePaperArea;
103
 
 
104
 
  //if you call more than one of them, thy should be called in the order
105
 
  //of the prepended numbers, since they depend on each other
106
 
  //(this doesn't mean you have to call all of them), alex
107
 
  //none of the adjust*() functions emits any signal to avoid multiple signals
108
 
  void adjustPaperArea1();
109
 
  void adjustScrollBarRanges2();
110
 
  void adjustScrollBarPositions3(int x, int y);
111
 
  void adjustVisibleArea4();
112
 
  void adjustRelativePaperArea5();
113
 
 
114
 
  float snapXPositionToGrid (float pos);
115
 
  float snapYPositionToGrid (float pos);
116
 
 
117
 
  bool eventFilter (QObject *, QEvent *);
118
 
  /* Events */
119
 
  void mousePressEvent (QMouseEvent *e);
120
 
  void mouseReleaseEvent (QMouseEvent *e);
121
 
  void mouseMoveEvent (QMouseEvent *e);
122
 
  void wheelEvent (QWheelEvent *e);
123
 
  void keyPressEvent (QKeyEvent *e);
124
 
  void paintEvent (QPaintEvent *e);
125
 
  void moveEvent (QMoveEvent *e);
126
 
  void resizeEvent (QResizeEvent *e);
127
 
 
128
 
signals:
129
 
  void rightButtonAtObjectClicked (int x, int y, GObject *obj);
130
 
  void rightButtonAtSelectionClicked (int x, int y);
131
 
  void rightButtonClicked (int x, int y);
132
 
 
133
 
  void visibleAreaChanged (const QRect& area);
134
 
  //void visibleAreaChanged (int x, int y);
135
 
  void zoomFactorChanged (float zoom);
136
 
 
137
 
  void mousePositionChanged (int x, int y);
138
 
 
139
 
    void backSpaceCalled();
140
 
public slots:
141
 
  void updateRegion (const Rect& r);
142
 
  void ensureVisibility (bool flag);
143
 
  void docSizeChanged();
144
 
 
145
 
  void addHelpline (int x, int y, bool horizH);
146
 
  void drawTmpHelpline (int x, int y, bool horizH);
147
 
 
148
 
private slots:
149
 
  void retryUpdateRegion ();
150
 
  void scroll();
151
 
 
152
 
private:
153
 
  GDocument *document;
154
 
 
155
 
 
156
 
  void propagateMouseEvent (QMouseEvent *e);
157
 
  void drawGrid (QPainter& p);
158
 
  void drawHelplines (QPainter& p);
159
 
 
160
 
  QPixmap *buffer;
161
 
  QScrollBar *hBar;
162
 
  QScrollBar *vBar;
163
 
 
164
 
  int m_width, m_height;
165
 
  int xPaper, yPaper;
166
 
  float resolution;
167
 
  float zoomFactor;
168
 
  ToolController *toolController;
169
 
  int pendingRedraws;
170
 
  Rect regionForUpdate, region;
171
 
 
172
 
  float tmpHorizHelpline, tmpVertHelpline;
173
 
 
174
 
 
175
 
  bool dragging:1;
176
 
  bool ensureVisibilityFlag:1;
177
 
  bool drawBasePoints:1;
178
 
  bool outlineMode:1;
179
 
  bool guiActive:1;
180
 
};
181
 
 
182
 
#endif