QtiPlot  0.9.8.2
FrameWidget.h
Go to the documentation of this file.
1 /***************************************************************************
2  File : FrameWidget.h
3  Project : QtiPlot
4  --------------------------------------------------------------------
5  Copyright : (C) 2008 by Ion Vasilief
6  Email (use @ for *) : ion_vasilief*yahoo.fr
7  Description : Base class for tool widgets in 2D plots
8 
9  ***************************************************************************/
10 
11 /***************************************************************************
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * *
18  * This program is distributed in the hope that it will be useful, *
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
21  * GNU General Public License for more details. *
22  * *
23  * You should have received a copy of the GNU General Public License *
24  * along with this program; if not, write to the Free Software *
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
26  * Boston, MA 02110-1301 USA *
27  * *
28  ***************************************************************************/
29 #ifndef FRAMEWIDGET_H
30 #define FRAMEWIDGET_H
31 
32 #include <QWidget>
33 #include <QPen>
34 #include <qwt_plot.h>
35 
36 class Graph;
37 
38 class FrameWidget: public QWidget
39 {
40  Q_OBJECT
41 
42 public:
45 
46  FrameWidget(Graph *);
47 
48  Graph *plot(){return d_plot;};
49 
51  enum FrameStyle{None = 0, Line = 1, Shadow = 2};
54 
56  double xValue(){return d_x;};
58  double yValue(){return d_y;};
60  void setOriginCoord(double x, double y);
62  void setOrigin(int x, int y){move(QPoint(x, y));};
63  void move(const QPoint& pos);
64 
66  QRectF boundingRect() const;
68  void setCoordinates(double left, double top, double right, double bottom);
70  void setSize(int w, int h){setSize(QSize(w, h));};
72  void setSize(const QSize& newSize);
74  void setRect(int x, int y, int w, int h);
75 
76  double right(){return d_x_right;};
77  double bottom(){return d_y_bottom;};
78 
79  static double xIn(QWidget *w, Unit unit);
80  static double yIn(QWidget *w, Unit unit);
81  static double widthIn(QWidget *w, Unit unit);
82  static double heightIn(QWidget *w, Unit unit);
84  static void setRect(QWidget *, double x, double y, double w, double h, Unit unit = Pixel);
85 
86  int frameStyle(){return d_frame;};
87  void setFrameStyle(int style);
88 
89  QPen framePen(){return d_frame_pen;};
90  void setFramePen(const QPen& p){d_frame_pen = p;};
91 
92  Qt::PenStyle frameLineStyle(){return d_frame_pen.style();};
93  void setFrameLineStyle(const Qt::PenStyle& s){d_frame_pen.setStyle(s);};
94 
95  QColor frameColor(){return d_frame_pen.color();};
96  void setFrameColor(const QColor& c){d_frame_pen.setColor(c);};
97 
98  double frameWidth(){return d_frame_pen.widthF();};
99  void setFrameWidth(double w){d_frame_pen.setWidthF(w);};
100 
101  QColor backgroundColor(){return palette().color(QPalette::Window);};
102  void setBackgroundColor(const QColor& c){QPalette pal = palette(); pal.setColor(QPalette::Window, c); setPalette(pal);};
103 
104  QBrush brush(){return d_brush;};
105  void setBrush(const QBrush& b){d_brush = b;};
106 
107  int angle(){return d_angle;};
108  void setAngle(int ang){d_angle = ang;};
109 
110  void showContextMenu(){emit showMenu();};
112 
113  virtual void print(QPainter *p, const QwtScaleMap map[QwtPlot::axisCnt]);
116 
117  virtual void updateCoordinates();
118  virtual QString saveToString();
119 
120  void setAttachPolicy(AttachPolicy attachTo);
122 
123  bool isOnTop(){return d_on_top;};
124  void setOnTop(bool on = true);
125 
126  void mousePressEvent(QMouseEvent *);
127 
128 signals:
129  void showDialog();
130  void showMenu();
131  void changedCoordinates(const QRectF&);
132 
133 protected:
135  double calculateXValue();
137  double calculateYValue();
139  double calculateRightValue();
141  double calculateBottomValue();
142 
143  virtual void drawFrame(QPainter *p, const QRect& rect);
144  virtual void paintEvent(QPaintEvent *e);
145  void contextMenuEvent(QContextMenuEvent * ){emit showMenu();};
146 
148  Graph *d_plot;
149 
151  int d_frame;
155  QBrush d_brush;
156 
158  int d_angle;
159 
161  double d_x;
163  double d_y;
165  double d_x_right;
167  double d_y_bottom;
172  bool d_on_top;
173 };
174 
175 #endif
void showDialog()
Definition: FrameWidget.h:44
Definition: FrameWidget.h:44
void showPropertiesDialog()
Definition: FrameWidget.h:111
int d_angle
Rotation angle: not implemented yet.
Definition: FrameWidget.h:158
double frameWidth()
Definition: FrameWidget.h:98
void setOriginCoord(double x, double y)
Sets the position of the top left corner in axis coordinates.
Definition: FrameWidget.cpp:116
double calculateXValue()
Returns the x axis coordinate of the top left corner based on the pixel value.
Definition: FrameWidget.cpp:175
Qt::PenStyle frameLineStyle()
Definition: FrameWidget.h:92
void setFrameColor(const QColor &c)
Definition: FrameWidget.h:96
int angle()
Definition: FrameWidget.h:107
virtual void print(QPainter *p, const QwtScaleMap map[QwtPlot::axisCnt])
Definition: FrameWidget.cpp:81
double yValue()
Returns the y axis coordiante of the top left corner.
Definition: FrameWidget.h:58
Definition: FrameWidget.h:53
virtual void paintEvent(QPaintEvent *e)
Definition: FrameWidget.cpp:74
double calculateBottomValue()
Returns the y axis coordinate of the bottom right corner based on the pixel value.
Definition: FrameWidget.cpp:193
void showContextMenu()
Definition: FrameWidget.h:110
void mousePressEvent(QMouseEvent *)
Definition: FrameWidget.cpp:255
QBrush brush()
Definition: FrameWidget.h:104
A 2D-plotting widget.
Definition: Graph.h:123
QPen d_frame_pen
Pen used to draw the frame.
Definition: FrameWidget.h:153
Definition: FrameWidget.h:53
void setFramePen(const QPen &p)
Definition: FrameWidget.h:90
void move(const QPoint &pos)
Definition: FrameWidget.cpp:126
double d_x
X axis coordinate of the top left corner.
Definition: FrameWidget.h:161
void setAngle(int ang)
Definition: FrameWidget.h:108
void setFrameWidth(double w)
Definition: FrameWidget.h:99
Definition: FrameWidget.h:44
void setRect(int x, int y, int w, int h)
Set geometry, giving everything in paint coordinates.
Definition: FrameWidget.cpp:156
void setOnTop(bool on=true)
Definition: FrameWidget.cpp:455
bool isOnTop()
Definition: FrameWidget.h:123
QColor backgroundColor()
Definition: FrameWidget.h:101
double d_y_bottom
The bottom side position in scale coordinates.
Definition: FrameWidget.h:167
double xValue()
Returns the x axis coordiante of the top left corner.
Definition: FrameWidget.h:56
FrameWidget(Graph *)
Definition: FrameWidget.cpp:43
double calculateRightValue()
Returns the x axis coordinate of the bottom right corner based on the pixel value.
Definition: FrameWidget.cpp:187
Graph * plot()
Definition: FrameWidget.h:48
void setBrush(const QBrush &b)
Definition: FrameWidget.h:105
int d_frame
Frame type.
Definition: FrameWidget.h:151
QRectF boundingRect() const
Return bounding rectangle in plot coordinates.
Definition: FrameWidget.cpp:199
double d_y
Y axis coordinate of the top left corner.
Definition: FrameWidget.h:163
static double xIn(QWidget *w, Unit unit)
Definition: FrameWidget.cpp:279
double right()
Definition: FrameWidget.h:76
void setFrameStyle(int style)
Definition: FrameWidget.cpp:91
double bottom()
Definition: FrameWidget.h:77
double calculateYValue()
Returns the y axis coordinate of the top left corner based on the pixel value.
Definition: FrameWidget.cpp:181
Definition: FrameWidget.h:51
Definition: FrameWidget.h:38
void resetCoordinates()
Definition: FrameWidget.h:115
void changedCoordinates(const QRectF &)
Definition: FrameWidget.h:51
Unit
Length units.
Definition: FrameWidget.h:44
AttachPolicy
The attach to policy.
Definition: FrameWidget.h:53
Definition: FrameWidget.h:44
void showMenu()
virtual void updateCoordinates()
Definition: FrameWidget.cpp:108
void setSize(int w, int h)
Set size in paint coordinates (pixels).
Definition: FrameWidget.h:70
void setOrigin(int x, int y)
Sets the position of the top left corner in paint coordinates.
Definition: FrameWidget.h:62
static double yIn(QWidget *w, Unit unit)
Definition: FrameWidget.cpp:308
int frameStyle()
Definition: FrameWidget.h:86
AttachPolicy attachPolicy()
Definition: FrameWidget.h:121
int d_shadow_width
Frame width in pixels.
Definition: FrameWidget.h:169
Graph * d_plot
Parent plot.
Definition: FrameWidget.h:145
Definition: FrameWidget.h:44
void setAttachPolicy(AttachPolicy attachTo)
Definition: FrameWidget.cpp:449
void setBackgroundColor(const QColor &c)
Definition: FrameWidget.h:102
Definition: FrameWidget.h:44
QColor frameColor()
Definition: FrameWidget.h:95
QBrush d_brush
Background brush.
Definition: FrameWidget.h:155
static double heightIn(QWidget *w, Unit unit)
Definition: FrameWidget.cpp:366
void setFrameLineStyle(const Qt::PenStyle &s)
Definition: FrameWidget.h:93
QPen framePen()
Definition: FrameWidget.h:89
Definition: FrameWidget.h:51
FrameStyle
The kinds of frame a FrameWidget can draw around.
Definition: FrameWidget.h:51
AttachPolicy d_attach_policy
The attach to policy.
Definition: FrameWidget.h:171
void resetOrigin()
Definition: FrameWidget.h:114
bool d_on_top
Definition: FrameWidget.h:172
void contextMenuEvent(QContextMenuEvent *)
Definition: FrameWidget.h:145
double d_x_right
The right side position in scale coordinates.
Definition: FrameWidget.h:165
virtual void drawFrame(QPainter *p, const QRect &rect)
Definition: FrameWidget.cpp:204
virtual QString saveToString()
Definition: FrameWidget.cpp:262
void setCoordinates(double left, double top, double right, double bottom)
Set position (xValue() and yValue()), right and bottom values giving everything in plot coordinates...
Definition: FrameWidget.cpp:132
static double widthIn(QWidget *w, Unit unit)
Definition: FrameWidget.cpp:337