00001
00002
00014 #ifndef FIGUREEDITOR_H
00015 #define FIGUREEDITOR_H
00016
00017 #include "libqthippo.h"
00018
00019 #ifdef _MSC_VER
00020 #include <msdevstudio/MSconfig.h>
00021 #endif
00022
00023 #include <qglobal.h>
00024 #if QT_VERSION < 0x040000
00025 #include <qcanvas.h>
00026 #else
00027
00028 #include <QtCore/QCustomEvent>
00029 #include <q3canvas.h>
00030 #endif
00031
00032 #include <string>
00033 #include <vector>
00034
00035 class QMouseEvent;
00036 class QResizeEvent;
00037
00038 namespace hippodraw {
00039
00040 class PickTable;
00041
00072 #if QT_VERSION < 0x040000
00073 class MDL_QTHIPPOPLOT_API FigureEditor : public QCanvasView
00074 #else
00075 class MDL_QTHIPPOPLOT_API FigureEditor : public Q3CanvasView
00076 #endif
00077 {
00078
00079 private:
00080
00084 class CanvasEvent : public QCustomEvent
00085 {
00086 private:
00089 #if QT_VERSION < 0x040000
00090 const QCanvasItem * m_item;
00091 #else
00092 const Q3CanvasItem * m_item;
00093 #endif
00094
00095 public:
00096
00099 #if QT_VERSION < 0x040000
00100 CanvasEvent ( const QCanvasItem * item )
00101 #else
00102 CanvasEvent ( const Q3CanvasItem * item )
00103 #endif
00104 : QCustomEvent ( 1000 ),
00105 m_item ( item )
00106 {}
00107
00110 #if QT_VERSION < 0x040000
00111 const QCanvasItem * item () const
00112 #else
00113 const Q3CanvasItem * item () const
00114 #endif
00115 {
00116 return m_item;
00117 }
00118 };
00119
00122 virtual void customEvent ( QCustomEvent * event );
00123
00124 protected:
00125
00127 int m_apage_w;
00128
00130 int m_apage_h;
00131
00136 double m_scale_factor;
00137
00140 bool m_zoom_mode;
00141
00143 static QPrinter * s_printer;
00144
00148 bool m_printer_bounds;
00149
00153 bool m_ignore_margin;
00154
00158 #if QT_VERSION < 0x040000
00159 void resizeCanvasToFit ( QCanvasItem * item );
00160 #else
00161 void resizeCanvasToFit ( Q3CanvasItem * item );
00162 #endif
00163
00165 void savePrinterSettings ();
00166
00170 void initPrinter ();
00171
00175 void addPageMargin ( int x, int y );
00176
00183 void calcPrinterMetrics ( QPaintDevice * );
00184
00189 double maximumZ () const;
00190
00193 void setUnselectedVisible ( bool yes );
00194
00197 void mouseMoveMultiItem( QMouseEvent * e );
00198
00199
00202 void
00203 #if QT_VERSION < 0X040000
00204 movePlotterWithText ( QCanvasItem * item, float dx, float dy );
00205 #else
00206 movePlotterWithText ( Q3CanvasItem * item, float dx, float dy );
00207 #endif
00208
00209
00212 QPixmap * createPixmap ( const QRect & rectangle ) const;
00213
00217 QImage createImage ( const QRect & rectange ) const;
00218
00219 protected:
00220
00222 int m_upage_w;
00223
00225 int m_upage_h;
00226
00237 #if QT_VERSION < 0x040000
00238 std::vector < QCanvasItem * > m_items;
00239 #else
00240 std::vector < Q3CanvasItem * > m_items;
00241 #endif
00242
00243
00244
00251 #if QT_VERSION < 0x040000
00252 QCanvasItem * m_rightItem;
00253 #else
00254 Q3CanvasItem * m_rightItem;
00255 #endif
00256
00257
00262 #if QT_VERSION < 0x040000
00263 QCanvasItem * m_preSelected;
00264 #else
00265 Q3CanvasItem * m_preSelected;
00266 #endif
00267
00268
00272 static QString s_app_key;
00273
00277 static QString s_registry;
00278
00282 #if QT_VERSION < 0x040000
00283 QCanvas * m_canvas;
00284 #else
00285 Q3Canvas * m_canvas;
00286 #endif
00287
00289 #if QT_VERSION < 0x040000
00290 std::vector < QCanvasItem * > m_selected_list;
00291 #else
00292 std::vector < Q3CanvasItem * > m_selected_list;
00293 #endif
00294
00296 QPoint m_moving_start;
00297
00299 QPoint m_zoom_start;
00300
00302 QPoint m_mouse_down;
00303
00305 bool m_isMouseDown;
00306
00309 enum Location { none, invalid,
00310 upper_left, upper_middle, upper_right,
00311 middle_left, middle_right,
00312 lower_left, lower_middle, lower_right };
00313
00315 Location m_whereClicked;
00316
00318 virtual void notifyObservers () = 0;
00319
00322 #if QT_VERSION < 0x040000
00323 void makeVisible ( const QCanvasItem * item );
00324 #else
00325 void makeVisible ( const Q3CanvasItem * item );
00326 #endif
00327
00328 virtual void contentsMousePressEvent(QMouseEvent*);
00329
00331 virtual void controlMousePressEvent () = 0;
00332
00338 void contentsMouseMoveEvent ( QMouseEvent *, double aspect );
00339
00341 void contentsMouseReleaseEvent (QMouseEvent *);
00342
00343
00345 void whereClicked ( );
00346
00348 #if QT_VERSION < 0x040000
00349 void placeGraphOnSelected ( QCanvasRectangle * item );
00350 #else
00351 void placeGraphOnSelected ( Q3CanvasRectangle * item );
00352 #endif
00353
00357 void setSelectedItems ( bool state );
00358
00360 QRect getSelectedBounds () const;
00361
00363 void clearSelectedList ();
00364
00368 #if QT_VERSION < 0x040000
00369 void setCollidingSelected ( const QCanvasItem * target );
00370 #else
00371 void setCollidingSelected ( const Q3CanvasItem * target );
00372 #endif
00373
00376 void saveSelectedAsPixmap ( const std::string & filename );
00377
00380 void saveAreaAsPixmap ( const QRect & area, const std::string & filename );
00381
00384 void copySelectedToClipboard ();
00385
00388 void print ( QPrinter * printer );
00389
00392 #if QT_VERSION < 0x040000
00393 void removeFromItemList ( QCanvasItem * item );
00394 #else
00395 void removeFromItemList ( Q3CanvasItem * item );
00396 #endif
00397
00398 #if QT_VERSION < 0x040000
00399 void addToItemList ( QCanvasItem * item );
00400 #else
00401 void addToItemList ( Q3CanvasItem * item );
00402 #endif
00403
00404 public:
00405
00407 #if QT_VERSION < 0x040000
00408 FigureEditor ( QCanvas *, QWidget * parent = 0,
00409 const char * name = 0, Qt::WFlags f = 0 );
00410 #else
00411 FigureEditor ( Q3Canvas *, QWidget * parent = 0,
00412 const char * name = 0, Qt::WFlags f = 0 );
00413 #endif
00414
00416 void static setAppKey ( const std::string & );
00417
00420 void showPrinterMargins ( bool on );
00421
00423 void setPrinterSettings ();
00424
00427 virtual void print ();
00428
00431 virtual void print ( const std::string & filename );
00432
00436 void resizeEvent ( QResizeEvent * e );
00437
00439 void addPage ();
00440
00442 #if QT_VERSION < 0x040000
00443 QCanvasItem * selectedItem () const;
00444 #else
00445 Q3CanvasItem * selectedItem () const;
00446 #endif
00447
00450 #if QT_VERSION < 0x040000
00451 void setSelectedItem ( QCanvasItem * );
00452 #else
00453 void setSelectedItem ( Q3CanvasItem * );
00454 #endif
00455
00456
00458 #if QT_VERSION < 0x040000
00459 QCanvasItem * getRightItem ();
00460 #else
00461 Q3CanvasItem * getRightItem ();
00462 #endif
00463
00465 void setAllSelected ( bool flag = true );
00466
00468 void setLocked ( bool flag );
00469
00470
00472 void setZoomMode ( bool flag );
00473
00475 bool getZoomMode ( ) const;
00476
00479 void clear();
00480
00485 #if QT_VERSION < 0x040000
00486 void placeGraph ( QCanvasRectangle * );
00487 #else
00488 void placeGraph ( Q3CanvasRectangle * );
00489 #endif
00490
00492 #if QT_VERSION < 0x040000
00493 void add ( QCanvasItem * item );
00494 #else
00495 void add ( Q3CanvasItem * item );
00496 #endif
00497
00500 #if QT_VERSION < 0x040000
00501 void paste ( QCanvasItem * item );
00502 #else
00503 void paste ( Q3CanvasItem * item );
00504 #endif
00505
00510 #if QT_VERSION < 0x040000
00511 void remove ( QCanvasItem * item );
00512 #else
00513 void remove ( Q3CanvasItem * item );
00514 #endif
00515
00521 #if QT_VERSION < 0x040000
00522 void hide ( QCanvasItem * item );
00523 #else
00524 void hide ( Q3CanvasItem * item );
00525 #endif
00526
00528 #if QT_VERSION < 0x040000
00529 std::vector < QCanvasItem * > & getSelectedItems ();
00530 #else
00531 std::vector < Q3CanvasItem * > & getSelectedItems ();
00532 #endif
00533
00535 bool isSingleItemSelected () const;
00536
00538 #if QT_VERSION < 0x040000
00539 void addSelectedItem ( QCanvasItem * item );
00540 #else
00541 void addSelectedItem ( Q3CanvasItem * item );
00542 #endif
00543
00546 #if QT_VERSION < 0x040000
00547 void removeSelectedItem ( QCanvasItem * item );
00548 #else
00549 void removeSelectedItem ( Q3CanvasItem * item );
00550 #endif
00551
00553 void setSelectedFlags ();
00554
00559 void scaleBy ( double factor );
00560
00562 void viewZoomIn();
00563
00565 void viewZoomOut();
00566
00569 void viewZoomReset ();
00570
00572 virtual void viewShowPickTable() = 0;
00573
00576 #if QT_VERSION < 0x040000
00577 void ensureVisible ( const QCanvasItem * item );
00578 #else
00579 void ensureVisible ( const Q3CanvasItem * item );
00580 #endif
00581
00584 const QString & getAppKey () const;
00585
00588 const QString & getRegistry () const;
00589
00592 void enterEvent ( QEvent * );
00593
00596 void leaveEvent ( QEvent * );
00597
00598
00599 };
00600
00601 }
00602
00603 #endif // FIGUREEDITOR_H