QGIS API Documentation  2.6.0-Brighton
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgscomposerview.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposerview.h
3  -------------------
4  begin : January 2005
5  copyright : (C) 2005 by Radim Blazek
6  email : [email protected]
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 #ifndef QGSCOMPOSERVIEW_H
18 #define QGSCOMPOSERVIEW_H
19 
20 #include <QGraphicsView>
22 #include "qgsprevieweffect.h" // for QgsPreviewEffect::PreviewMode
23 
24 class QDomDocument;
25 class QDomElement;
26 class QKeyEvent;
27 class QMainWindow;
28 class QMouseEvent;
29 class QgsComposition;
30 class QgsComposerArrow;
31 class QgsComposerItem;
32 class QgsComposerLabel;
33 class QgsComposerLegend;
34 class QgsComposerMap;
35 class QgsComposerPicture;
36 class QgsComposerRuler;
38 class QgsComposerShape;
40 
47 class GUI_EXPORT QgsComposerView: public QGraphicsView
48 {
49  Q_OBJECT
50 
51  public:
52 
54  enum Tool
55  {
56  Select = 0, // Select/Move item
57  AddArrow, //add arrow
59  AddMap, // add new map
60  AddLegend, // add vector legend
61  AddLabel, // add label
62  AddScalebar, // add scalebar
63  AddPicture, // add raster/vector picture
67  AddTable, //add table
69  MoveItemContent, //move content of item (e.g. content of map)
70  Pan,
71  Zoom
72  };
73 
75  {
77  ClipboardModeCopy
78  };
79 
80  enum PasteMode
81  {
84  PasteModeInPlace
85  };
86 
88  {
91  ActiveUntilMouseRelease
92  };
93 
94  QgsComposerView( QWidget* parent = 0, const char* name = 0, Qt::WindowFlags f = 0 );
95 
97  void groupItems();
98 
100  void ungroupItems();
101 
103  void copyItems( ClipboardMode mode );
104 
106  void pasteItems( PasteMode mode );
107 
109  void deleteSelectedItems();
110 
112  void selectAll();
113 
115  void selectNone();
116 
118  void selectInvert();
119 
120  QgsComposerView::Tool currentTool() const {return mCurrentTool;}
121  void setCurrentTool( QgsComposerView::Tool t );
122 
126  void setComposition( QgsComposition* c );
127 
129  QgsComposition* composition();
130 
132  QMainWindow* composerWindow();
133 
134  void setPaintingEnabled( bool enabled ) { mPaintingEnabled = enabled; }
135  bool paintingEnabled() const { return mPaintingEnabled; }
136 
138  void updateRulers();
139 
140  void setHorizontalRuler( QgsComposerRuler* r ) { mHorizontalRuler = r; }
141  void setVerticalRuler( QgsComposerRuler* r ) { mVerticalRuler = r; }
142 
144  void setZoomLevel( double zoomLevel );
145 
151  void setPreviewModeEnabled( bool enabled );
158  void setPreviewMode( QgsPreviewEffect::PreviewMode mode );
159 
160  protected:
161  void mousePressEvent( QMouseEvent* );
162  void mouseReleaseEvent( QMouseEvent* );
163  void mouseMoveEvent( QMouseEvent* );
164  void mouseDoubleClickEvent( QMouseEvent* e );
165 
166  void keyPressEvent( QKeyEvent * e );
167  void keyReleaseEvent( QKeyEvent * e );
168 
169  void wheelEvent( QWheelEvent* event );
170 
171  void paintEvent( QPaintEvent* event );
172 
173  void hideEvent( QHideEvent* e );
174  void showEvent( QShowEvent* e );
175 
176  void resizeEvent( QResizeEvent* event );
177  void scrollContentsBy( int dx, int dy );
178 
179  private:
181  QgsComposerView::Tool mCurrentTool;
183  QgsComposerView::Tool mPreviousTool;
184 
186  QGraphicsRectItem* mRubberBandItem;
188  QGraphicsLineItem* mRubberBandLineItem;
190  QgsComposerItem* mMoveContentItem;
192  QPointF mMoveContentStartPos;
194  QPointF mRubberBandStartPos;
195 
197  bool mMarqueeSelect;
199  bool mMarqueeZoom;
201  QgsComposerView::ToolStatus mTemporaryZoomStatus;
202 
203  bool mPaintingEnabled;
204 
205  QgsComposerRuler* mHorizontalRuler;
206  QgsComposerRuler* mVerticalRuler;
207 
209  void addShape( Tool currentTool );
210 
212  bool mToolPanning;
214  bool mMousePanning;
216  bool mKeyPanning;
217 
219  bool mMovingItemContent;
220 
221  QPoint mMouseLastXY;
222  QPoint mMouseCurrentXY;
223  QPoint mMousePressStartPos;
224 
225  QgsPreviewEffect* mPreviewEffect;
226 
228  QCursor defaultCursorForTool( Tool currentTool );
229 
231  void wheelZoom( QWheelEvent * event );
233  void updateRubberBandRect( QPointF & pos, const bool constrainSquare = false, const bool fromCenter = false );
235  void updateRubberBandLine( const QPointF & pos, const bool constrainAngles = false );
237  void removeRubberBand();
238 
240  void startMarqueeSelect( QPointF & scenePoint );
242  void endMarqueeSelect( QMouseEvent* e );
244  void startMarqueeZoom( QPointF & scenePoint );
246  void endMarqueeZoom( QMouseEvent* e );
247 
248  //void connectAddRemoveCommandSignals( QgsAddRemoveItemCommand* c );
249 
250  signals:
252  void selectedItemChanged( QgsComposerItem* selected );
254  void itemRemoved( QgsComposerItem* );
257  void actionFinished();
259  void cursorPosChanged( QPointF );
261  void zoomLevelChanged();
262 
264  void composerViewShow( QgsComposerView* );
266  void composerViewHide( QgsComposerView* );
267 
269  void compositionSet( QgsComposition* );
270 };
271 
272 #endif