00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef _BARCHART_H_
00031 #define _BARCHART_H_
00032
00033
00034
00035
00036 #include <vector>
00037
00038
00039 #include <qframe.h>
00040
00041
00042
00043
00044 class QGridLayout;
00045 class QLabel;
00046
00047
00048
00049 namespace OSB_GUI {
00050
00051
00052
00053
00054
00055
00056
00057
00058
00062 class BarChartInfo : public QObject {
00063 Q_OBJECT
00064 public:
00066 typedef std::map<double, std::string> Ticks;
00067 protected:
00069 explicit BarChartInfo(
00070 double minX = 0.0,
00071 double maxX = 0.0
00072 );
00073
00074 public:
00076 virtual ~BarChartInfo();
00077
00078 private:
00080 BarChartInfo(const BarChartInfo& rhs);
00082 BarChartInfo& operator=(const BarChartInfo& rhs);
00083
00084 public:
00086 virtual double scaleX(double x) = 0;
00087
00089 double min() const
00090 {
00091 return min_;
00092 }
00093
00095 double max() const
00096 {
00097 return max_;
00098 }
00099
00101 const Ticks& ticks() const
00102 {
00103 return ticks_;
00104 }
00105
00107
00108
00109 int minLabelWidth() const
00110 {
00111 return minLabelWidth_;
00112 }
00114 int minBarWidth() const
00115 {
00116 return minBarWidth_;
00117 }
00119 int leftOff() const
00120 {
00121 return leftOff_;
00122 }
00124 int rightOff() const
00125 {
00126 return rightOff_;
00127 }
00129
00131
00132
00137 virtual void resetGeometry();
00144 void setMinLabelWidth(int minWidth);
00146 void setMinBarWidth(int minWidth);
00151 void setLeftOff(int leftOff);
00156 void setRightOff(int rightOff);
00158
00159 signals:
00161 void minLabelWidth(int minWidth);
00162
00163 protected:
00165 double min_;
00167 double max_;
00169 Ticks ticks_;
00170
00172
00173
00174 int minLabelWidth_;
00176 int minBarWidth_;
00178 int leftOff_;
00180 int rightOff_;
00182 };
00183
00187 class BarChart : public QFrame {
00188 Q_OBJECT
00189 public:
00190
00191 struct Range {
00193 explicit Range(
00194 double low = 0,
00195 double high = 0,
00196 QColor color = QColor()
00197 );
00198
00199 public:
00201 double low_;
00203 double high_;
00205 QColor color_;
00206 };
00207
00209 typedef std::vector<Range> Ranges;
00210 private:
00211
00212 class Bar;
00213
00214 class Ruler;
00215
00216 public:
00220 explicit BarChart(
00221 BarChartInfo& info,
00222 QWidget* parent,
00223 const char* name = 0,
00224 WFlags flags = 0
00225 );
00226
00228 virtual ~BarChart() = 0;
00229
00230 public:
00238 std::pair<QLabel*, QWidget*> add(
00239 const std::string& label,
00240 const Ranges& ranges
00241 );
00242
00243 public slots:
00252 void setMinLabelWidth(int minWidth);
00253
00254 signals:
00260 void minLabelWidth(int minWidth);
00261
00262 protected:
00264 QLabel* header_;
00265 private:
00267 BarChartInfo& info_;
00269 Ruler* ruler_;
00271 QGridLayout* layout_;
00272 };
00273
00277 class BarChart::Bar : public QWidget {
00278 public:
00282 Bar(
00283 BarChartInfo& info,
00284 QWidget* parent,
00285 const char* name = 0,
00286 WFlags flags = 0
00287 );
00288
00289 public:
00291 void show(const Ranges& ranges);
00292
00293 private:
00295 void paintEvent(QPaintEvent* e);
00296
00297 private:
00299 BarChartInfo& info_;
00301 Ranges ranges_;
00302 };
00303
00307 class BarChart::Ruler : public QWidget {
00308 public:
00312 Ruler(
00313 BarChartInfo& info,
00314 QWidget* parent,
00315 const char* name = 0,
00316 WFlags flags = 0
00317 );
00318 public:
00320 QSize sizeHint () const;
00321 private:
00323 void paintEvent(QPaintEvent* e);
00325 void calcSize();
00327 void fontChange(const QFont&);
00328 private:
00330 BarChartInfo& info_;
00332 int height_;
00333 };
00334 }
00335
00336
00337
00338 namespace OSB_GUI {
00339 }
00340 #endif // #ifndef _BARCHART_H_