// $Id: fgl_canvas.h $ // ================================================================= // This code is distributed under the terms and conditions of the // CCP4 Program Suite Licence Agreement as 'Part 2' (Annex 2) // software. A copy of the CCP4 licence can be obtained by writing // to CCP4, Research Complex at Harwell, Rutherford Appleton // Laboratory, Didcot OX11 0FA, UK, or from // http://www.ccp4.ac.uk/ccp4license.php. // ================================================================= // // 29.08.13 <-- Date of Last Modification. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ---------------------------------------------------------------- // // **** Module : fgl_canvas // ~~~~~~~~~ // **** Project : QtLibs/FGL - plotting in Qt // ~~~~~~~~~ // **** Classes : fgl::Canvas // ~~~~~~~~~ // // (C) E. Krissinel 2012-2013 // // ================================================================= // #ifndef FGL_CANVAS_H #define FGL_CANVAS_H #include #include #include "fgl_plot.h" #include "fgl_starplot.h" QT_BEGIN_NAMESPACE class QMouseEvent; class QMenu; class QAction; class QPainter; QT_END_NAMESPACE namespace fgl { class Scene; class XYFrame; class Canvas : public QLabel { Q_OBJECT public: Canvas ( QWidget *parent=0 ); ~Canvas(); void setMargins ( qreal left, qreal top, qreal right, qreal bottom ); inline qreal left_margin () { return leftMargin; } inline qreal top_margin () { return topMargin; } inline qreal right_margin () { return rightMargin; } inline qreal bottom_margin() { return bottomMargin; } inline Scene *canvasScene() { return scene; } Plot *addPlot(); void removePlot ( Plot *plot ); inline int getNPlots() { return plots.count(); } Plot *getPlot ( int i ); StarPlot *addStarPlot(); void removeStarPlot ( StarPlot *plot ); inline int getNStarPlots() { return starPlots.count(); } StarPlot *getStarPlot ( int i ); void makeContextMenu ( QList actions ); bool isCursorOn (); bool isCursorVisible (); void setCursorVisible ( bool visible ); bool isRectSelOn (); bool isRectSelVisible (); void setRectSelVisible ( bool visible ); void setRectSelOn ( bool on ); void makePicture(); signals: void cursorValuesChanged ( qreal valueX, qreal valueY, int digX, int digY, fgl::XYFrame *frame ); void cursorVisibilityChanged ( bool visible ); void mousePressed ( fgl::XYFrame *f, qreal x, qreal y ); void mouseDoubleClicked ( fgl::XYFrame *f, qreal x, qreal y ); void mouseMoved ( fgl::XYFrame *f, qreal x0, qreal y0, qreal x1, qreal y1 ); void mouseReleased ( fgl::XYFrame *f, qreal x0, qreal y0, qreal x1, qreal y1 ); void canvasResized(); public slots: void clear(); void clearScene(); void invalidateScene(); virtual void print (); virtual void print ( QWidget *parent ); virtual void exportImage (); virtual void exportImage ( QWidget *parent ); virtual void clipCopy (); virtual void paintCanvas ( QPainter *painter ); virtual void resizeEvent ( QResizeEvent *event ); virtual void resizeToCanvas ( qreal sizeFactor=3.5 ); protected: Scene *scene; QList plots; QList starPlots; QMenu *contextMenu; qreal leftMargin,rightMargin,topMargin,bottomMargin; bool cursorVisible; XYFrame *mouseFrame; int mouseTracking; qreal mouseX0; //!< in physical coordinates of mouseFrame qreal mouseY0; //!< in physical coordinates of mouseFrame QSize minimumSizeHint() const; QSize sizeHint() const; void paintEvent ( QPaintEvent *event ); void mousePressEvent ( QMouseEvent *event ); void mouseMoveEvent ( QMouseEvent *event ); void mouseDoubleClickEvent ( QMouseEvent *event ); void mouseReleaseEvent ( QMouseEvent *event ); void contextMenuEvent ( QContextMenuEvent *event ); }; } #endif // FGL_CANVAS_H