libyui-qt  2.46.13
YQBarGraph.h
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YQBarGraph.h
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 
26 #ifndef YQBarGraph_h
27 #define YQBarGraph_h
28 
29 #include "qframe.h"
30 #include "qevent.h"
31 #include "qtooltip.h"
32 #include <yui/YBarGraph.h>
33 #include <map>
34 
35 using namespace std;
36 
37 class QPainter;
38 
39 class YQBarGraph : public QFrame, public YBarGraph
40 {
41  Q_OBJECT
42  Q_PROPERTY(QString BackgroundColors READ getBackgroundColors WRITE setBackgroundColors DESIGNABLE true)
43  Q_PROPERTY(QString ForegroundColors READ getForegroundColors WRITE setForegroundColors DESIGNABLE true)
44 
45 public:
46 
47  /**
48  * Constructor.
49  **/
50  YQBarGraph( YWidget * parent );
51 
52  /**
53  * Destructor.
54  **/
55  virtual ~YQBarGraph();
56 
57  /**
58  * Perform a visual update on the screen.
59  *
60  * Implemented from YBarGraph.
61  **/
62  virtual void doUpdate();
63 
64  /**
65  * Set enabled/disabled state.
66  *
67  * Reimplemented from YWidget.
68  **/
69  virtual void setEnabled( bool enabled );
70 
71  /**
72  * Preferred width of the widget.
73  *
74  * Reimplemented from YWidget.
75  **/
76  virtual int preferredWidth();
77 
78  /**
79  * Preferred height of the widget.
80  *
81  * Reimplemented from YWidget.
82  **/
83  virtual int preferredHeight();
84 
85  /**
86  * Set the new size of the widget.
87  *
88  * Reimplemented from YWidget.
89  **/
90  virtual void setSize( int newWidth, int newHeight );
91 
92 
93 protected:
94 
95  virtual bool event( QEvent * event );
96  /**
97  * Draw the contents.
98  *
99  * Reimplemented from QFrame.
100  **/
101  virtual void paintEvent( QPaintEvent * painter );
102 
103  /**
104  * Return one from a set of default segment background colors.
105  **/
106  YColor defaultSegmentColor( unsigned index );
107 
108  /**
109  * Return one from a set of default text colors. This text color is
110  * guaranteed to contrast with the defaultSegmentColor with the same index.
111  **/
112  YColor defaultTextColor( unsigned index );
113 
114 private:
115  map <int, QString> toolTips ;
116 
117  // QSS doesn't allow to store a list of QColors, that's the reason
118  // why we use QString and store the colors in following format:
119  //
120  // YQBarGraph
121  // {
122  // qproperty-BackgroundColors: "#aabbcc,#bbccdd,#eeff00"";
123  // qproperty-ForegroundColors: "black,yellow,white";
124  // }
125 
126  QString _backgroundColors;
127  QString getBackgroundColors();
128  void setBackgroundColors( QString colors );
129  QString _foregroundColors;
130  QString getForegroundColors();
131  void setForegroundColors( QString colors );
132 };
133 
134 
135 #endif // YQBarGraph_h
STL namespace.