FrameWidget.h

Go to the documentation of this file.
00001 /***************************************************************************
00002     File                 : FrameWidget.h
00003     Project              : QtiPlot
00004     --------------------------------------------------------------------
00005     Copyright            : (C) 2008 by Ion Vasilief
00006     Email (use @ for *)  : ion_vasilief*yahoo.fr
00007     Description          : Base class for tool widgets in 2D plots
00008 
00009  ***************************************************************************/
00010 
00011 /***************************************************************************
00012  *                                                                         *
00013  *  This program is free software; you can redistribute it and/or modify   *
00014  *  it under the terms of the GNU General Public License as published by   *
00015  *  the Free Software Foundation; either version 2 of the License, or      *
00016  *  (at your option) any later version.                                    *
00017  *                                                                         *
00018  *  This program is distributed in the hope that it will be useful,        *
00019  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
00020  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
00021  *  GNU General Public License for more details.                           *
00022  *                                                                         *
00023  *   You should have received a copy of the GNU General Public License     *
00024  *   along with this program; if not, write to the Free Software           *
00025  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
00026  *   Boston, MA  02110-1301  USA                                           *
00027  *                                                                         *
00028  ***************************************************************************/
00029 #ifndef FRAMEWIDGET_H
00030 #define FRAMEWIDGET_H
00031 
00032 #include <QWidget>
00033 #include <qwt_plot.h>
00034 
00035 #include "Graph.h"
00036 
00037 class FrameWidget: public QWidget
00038 {
00039     Q_OBJECT
00040 
00041 public:
00042     enum Unit{Inch, Millimeter, Centimeter, Point, Pixel, Scale};
00043 
00044     FrameWidget(Graph *);
00045 
00046     Graph *plot(){return d_plot;};
00047 
00049     enum FrameStyle{None = 0, Line = 1, Shadow = 2};
00050 
00052     double xValue(){return d_x;};
00054     double yValue(){return d_y;};
00056     void setOriginCoord(double x, double y);
00058     void setOrigin(int x, int y){move(QPoint(x, y));};
00059     void move(const QPoint& pos);
00060 
00062     QRectF boundingRect() const;
00064     void setCoordinates(double left, double top, double right, double bottom);
00066     void setSize(int w, int h){setSize(QSize(w, h));};
00068     void setSize(const QSize& newSize);
00070     void setRect(int x, int y, int w, int h);
00071 
00072     double right(){return d_x_right;};
00073     double bottom(){return d_y_bottom;};
00074 
00075     static double xIn(QWidget *w, Unit unit);
00076     static double yIn(QWidget *w, Unit unit);
00077     static double widthIn(QWidget *w, Unit unit);
00078     static double heightIn(QWidget *w, Unit unit);
00080     static void setRect(QWidget *, double x, double y, double w, double h, Unit unit = Pixel);
00081 
00082     int frameStyle(){return d_frame;};
00083     void setFrameStyle(int style);
00084 
00085     QPen framePen(){return d_frame_pen;};
00086     void setFramePen(const QPen& p){d_frame_pen = p;};
00087 
00088     Qt::PenStyle frameLineStyle(){return d_frame_pen.style();};
00089     void setFrameLineStyle(const Qt::PenStyle& s){d_frame_pen.setStyle(s);};
00090 
00091     QColor frameColor(){return d_frame_pen.color();};
00092     void setFrameColor(const QColor& c){d_frame_pen.setColor(c);};
00093 
00094     QColor frameWidth(){return d_frame_pen.width();};
00095     void setFrameWidth(int w){d_frame_pen.setWidth(w);};
00096 
00097     QColor backgroundColor(){return palette().color(QPalette::Window);};
00098     void setBackgroundColor(const QColor& c){QPalette pal = palette(); pal.setColor(QPalette::Window, c); setPalette(pal);};
00099 
00100     QBrush brush(){return d_brush;};
00101     void setBrush(const QBrush& b){d_brush = b;};
00102 
00103     int angle(){return d_angle;};
00104     void setAngle(int ang){d_angle = ang;};
00105 
00106     void showContextMenu(){emit showMenu();};
00107     void showPropertiesDialog(){emit showDialog();};
00108 
00109     virtual void print(QPainter *p, const QwtScaleMap map[QwtPlot::axisCnt]);
00110     void resetOrigin(){setOriginCoord(d_x, d_y);};
00111     void resetCoordinates(){setCoordinates(d_x, d_y, d_x_right, d_y_bottom);};
00112 
00113     virtual void updateCoordinates();
00114     virtual QString saveToString();
00115 
00116 signals:
00117     void showDialog();
00118     void showMenu();
00119     void changedCoordinates(const QRectF&);
00120 
00121 protected:
00123     double calculateXValue();
00125     double calculateYValue();
00127     double calculateRightValue();
00129     double calculateBottomValue();
00130 
00131     void drawFrame(QPainter *p, const QRect& rect);
00132     virtual void paintEvent(QPaintEvent *e);
00133     void mousePressEvent(QMouseEvent *);
00134     void contextMenuEvent(QContextMenuEvent * ){emit showMenu();};
00135 
00137     Graph *d_plot;
00138 
00140     int d_frame;
00142     QPen d_frame_pen;
00144     QBrush d_brush;
00145 
00147     int d_angle;
00148 
00150     double d_x;
00152     double d_y;
00154     double d_x_right;
00156     double d_y_bottom;
00158     int d_shadow_width;
00159 };
00160 
00161 #endif

Generated on Tue Nov 3 10:48:51 2009 for QtiPlot by  doxygen 1.6.1