// $Id: fgl_widget.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. // ================================================================= // // 19.11.13 <-- Date of Last Modification. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ---------------------------------------------------------------- // // **** Module : fgl_widget // ~~~~~~~~~ // **** Project : QtLibs/FGL - plotting in Qt // ~~~~~~~~~ // **** Classes : fgl::Widget // ~~~~~~~~~ // // (C) E. Krissinel 2012-2013 // // ================================================================= // #ifndef FGL_WIDGET_H #define FGL_WIDGET_H #include #include #include QT_BEGIN_NAMESPACE class QSlider; class QToolButton; class QHBoxLayout; QT_END_NAMESPACE namespace fgl { class Canvas; class Plot; class XYFrame; class Widget : public QLabel { Q_OBJECT public: Widget ( QWidget *parent=0 ); ~Widget(); /// \brief returns drawing canvas. /// Canvas exists always. inline Canvas *getCanvas() { return canvas; } void clearCanvas(); /// \brief Configuration of X-zoom slider behaviour. /// \param[in] range total control range (number of smallest /// discrete changes, which may be done by /// +/- control buttons of the slider) /// \param[in] step size of 'slider page', (number of smallest /// discrete changes when PgUp/PgDown or /// equivalent mouse clicks are performed) /// \param[in] value initial value of the slider /// \param[in] focus relative position (0..1) of point which will /// be kept invariant at zooming. For example, /// 0.5 will zoom around the centre of X-axis, /// 0.0 will zoom to higher X, and 1.0 will zoom /// to lower X void configureXZoom ( int range, int step, int value, double focus ); /// \brief Configuration of Y-zoom slider behaviour. /// \param[in] range total control range (number of smallest /// discrete changes, which may be done by /// +/- control buttons of the slider) /// \param[in] step size of 'slider page', (number of smallest /// discrete changes when PgUp/PgDown or /// equivalent mouse clicks are performed) /// \param[in] value initial value of the slider /// \param[in] focus relative position (0..1) of point which will /// be kept invariant at zooming. For example, /// 0.5 will zoom around the centre of Y-axis, /// 0.0 will zoom to higher Y, and 1.0 will zoom /// to lower Y void configureYZoom ( int range, int step, int value, double focus ); /// \brief Zooms plot to the specified area. /// \param[in] x1 minimum X-coordinate of area to zoom to /// \param[in] y1 minimum Y-coordinate of area to zoom to /// \param[in] x2 maximum X-coordinate of area to zoom to /// \param[in] y2 maximum Y-coordinate of area to zoom to /// /// All parameters are physical coordinates (i.e. those in which /// plotted data are expressed). The function will work only after /// the plot is drawn. void zoomToArea ( qreal x1, qreal y1, qreal x2, qreal y2 ); /// \brief Adds plot to canvas and returns its pointer. /// \return pointer to newly allocated Plot. Plot *addPlot (); void removePlot ( Plot *plot ); Plot *getPlot ( int n ); inline QHBoxLayout *getControlPanel() { return controlPanel; } // signals: public slots: void resizeCanvas(); virtual void setVisible ( bool visible ); void print(); protected: int flags; double minDLogX,minDLogY; // experimental double zoomXfocus; //!< 0..1 relative mass center at X-zooming double zoomYfocus; //!< 0..1 relative mass center at Y-zooming Canvas *canvas; QHBoxLayout *controlPanel; QSlider *x_zoom_sld; QToolButton *x_plus_btn; QToolButton *x_minus_btn; QLabel *x_coor_lbl; QLabel *coor_sepxy_lbl; QLabel *coor_sepyz_lbl; QSlider *y_zoom_sld; QToolButton *y_plus_btn; QToolButton *y_minus_btn; QLabel *y_coor_lbl; QLabel *z_coor_lbl; QToolButton *print_btn; QToolButton *zoom_full_btn; QToolButton *grab_btn; QToolButton *rect_sel_btn; QToolButton *makeZoomButton ( const char *icon_file ); QLabel *makeFixedLabel ( int nSymbols ); QLabel *setLabelWidth ( QLabel *lbl, int nSymbols ); void checkZoomButtons (); void connectSliders (); void disconnectSliders(); bool zoomToArea ( XYFrame *f, qreal mx0, qreal my0, qreal mx1, qreal my1 ); void setXYRange ( XYFrame *f, qreal x1, qreal x2, qreal y1, qreal y2 ); protected slots: void cursorValuesChanged ( qreal valueX , qreal valueY, int baseDigX, int baseDigY, fgl::XYFrame *frame ); void cursorVisibilityChanged ( bool visible ); void zoomInXClicked (); void zoomOutXClicked (); void zoomInYClicked (); void zoomOutYClicked (); void zoomChanged ( int value ); void zoomFullBtnClicked(); void grabBtnClicked (); void rectSelBtnClicked (); void mouseWasPressed ( fgl::XYFrame *f, qreal mx, qreal my ); void mouseWasDoubleClicked ( fgl::XYFrame *f, qreal mx, qreal my ); void mouseWasMoved ( fgl::XYFrame *f, qreal mx0, qreal my0, qreal mx1, qreal my1 ); void mouseWasReleased ( fgl::XYFrame *f, qreal mx0, qreal my0, qreal mx1, qreal my1 ); private: int validate; }; } #endif // FGL_WIDGET_H