QtiPlot
0.9.8.2
|
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 <QPen> 00034 #include <qwt_plot.h> 00035 00036 class Graph; 00037 00038 class FrameWidget: public QWidget 00039 { 00040 Q_OBJECT 00041 00042 public: 00044 enum Unit{Inch, Millimeter, Centimeter, Point, Pixel, Scale}; 00045 00046 FrameWidget(Graph *); 00047 00048 Graph *plot(){return d_plot;}; 00049 00051 enum FrameStyle{None = 0, Line = 1, Shadow = 2}; 00053 enum AttachPolicy {Page, Scales}; 00054 00056 double xValue(){return d_x;}; 00058 double yValue(){return d_y;}; 00060 void setOriginCoord(double x, double y); 00062 void setOrigin(int x, int y){move(QPoint(x, y));}; 00063 void move(const QPoint& pos); 00064 00066 QRectF boundingRect() const; 00068 void setCoordinates(double left, double top, double right, double bottom); 00070 void setSize(int w, int h){setSize(QSize(w, h));}; 00072 void setSize(const QSize& newSize); 00074 void setRect(int x, int y, int w, int h); 00075 00076 double right(){return d_x_right;}; 00077 double bottom(){return d_y_bottom;}; 00078 00079 static double xIn(QWidget *w, Unit unit); 00080 static double yIn(QWidget *w, Unit unit); 00081 static double widthIn(QWidget *w, Unit unit); 00082 static double heightIn(QWidget *w, Unit unit); 00084 static void setRect(QWidget *, double x, double y, double w, double h, Unit unit = Pixel); 00085 00086 int frameStyle(){return d_frame;}; 00087 void setFrameStyle(int style); 00088 00089 QPen framePen(){return d_frame_pen;}; 00090 void setFramePen(const QPen& p){d_frame_pen = p;}; 00091 00092 Qt::PenStyle frameLineStyle(){return d_frame_pen.style();}; 00093 void setFrameLineStyle(const Qt::PenStyle& s){d_frame_pen.setStyle(s);}; 00094 00095 QColor frameColor(){return d_frame_pen.color();}; 00096 void setFrameColor(const QColor& c){d_frame_pen.setColor(c);}; 00097 00098 double frameWidth(){return d_frame_pen.widthF();}; 00099 void setFrameWidth(double w){d_frame_pen.setWidthF(w);}; 00100 00101 QColor backgroundColor(){return palette().color(QPalette::Window);}; 00102 void setBackgroundColor(const QColor& c){QPalette pal = palette(); pal.setColor(QPalette::Window, c); setPalette(pal);}; 00103 00104 QBrush brush(){return d_brush;}; 00105 void setBrush(const QBrush& b){d_brush = b;}; 00106 00107 int angle(){return d_angle;}; 00108 void setAngle(int ang){d_angle = ang;}; 00109 00110 void showContextMenu(){emit showMenu();}; 00111 void showPropertiesDialog(){emit showDialog();}; 00112 00113 virtual void print(QPainter *p, const QwtScaleMap map[QwtPlot::axisCnt]); 00114 void resetOrigin(){setOriginCoord(d_x, d_y);}; 00115 void resetCoordinates(){setCoordinates(d_x, d_y, d_x_right, d_y_bottom);}; 00116 00117 virtual void updateCoordinates(); 00118 virtual QString saveToString(); 00119 00120 void setAttachPolicy(AttachPolicy attachTo); 00121 AttachPolicy attachPolicy(){return d_attach_policy;}; 00122 00123 bool isOnTop(){return d_on_top;}; 00124 void setOnTop(bool on = true); 00125 00126 void mousePressEvent(QMouseEvent *); 00127 00128 signals: 00129 void showDialog(); 00130 void showMenu(); 00131 void changedCoordinates(const QRectF&); 00132 00133 protected: 00135 double calculateXValue(); 00137 double calculateYValue(); 00139 double calculateRightValue(); 00141 double calculateBottomValue(); 00142 00143 virtual void drawFrame(QPainter *p, const QRect& rect); 00144 virtual void paintEvent(QPaintEvent *e); 00145 void contextMenuEvent(QContextMenuEvent * ){emit showMenu();}; 00146 00148 Graph *d_plot; 00149 00151 int d_frame; 00153 QPen d_frame_pen; 00155 QBrush d_brush; 00156 00158 int d_angle; 00159 00161 double d_x; 00163 double d_y; 00165 double d_x_right; 00167 double d_y_bottom; 00169 int d_shadow_width; 00171 AttachPolicy d_attach_policy; 00172 bool d_on_top; 00173 }; 00174 00175 #endif