libyui-qt  2.47.1.1
YQBusyIndicator.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: YQBusyIndicator.h
20 
21  Author: Thomas Goettlicher <tgoettlicher@suse.de>
22 
23 /-*/
24 
25 
26 #ifndef YQBusyIndicator_h
27 #define YQBusyIndicator_h
28 
29 #include <QFrame>
30 #include <QTimer>
31 #include <QLabel>
32 #include <yui/YBusyIndicator.h>
33 
34 
35 class QString;
36 class YQWidgetCaption;
37 class BusyBar;
38 
39 class YQBusyIndicator : public QFrame, public YBusyIndicator
40 {
41  Q_OBJECT
42 
43 public:
44  /**
45  * Constructor.
46  **/
47  YQBusyIndicator( YWidget * parent,
48  const std::string & label,
49  int timeout = 1000 );
50  /**
51  * Destructor.
52  **/
53  virtual ~YQBusyIndicator();
54 
55  /**
56  * Set the label (the caption above the progress bar).
57  *
58  * Reimplemented from YBusyIndicator.
59  **/
60  virtual void setLabel( const std::string & label );
61 
62  /**
63  * Set the timeout is ms after that the widget shows 'stalled' when no
64  * new tick is received.
65  *
66  * Reimplemented from YBusyIndicator.
67  **/
68  virtual void setTimeout( int newTimeout );
69 
70  /**
71  * Return the timeout is ms after that the widget shows 'stalled' when no
72  * new tick is received.
73  *
74  * Reimplemented from YBusyIndicator.
75  **/
76  int timeout() const { return _timeout; }
77 
78  /**
79  * Send a keep allive message.
80  *
81  * Reimplemented from YBusyIndicator.
82  **/
83  virtual void setAlive( bool newAlive );
84 
85  /**
86  * Set enabled/disabled state.
87  *
88  * Reimplemented from YWidget.
89  **/
90  virtual void setEnabled( bool enabled );
91 
92  /**
93  * Preferred width of the widget.
94  *
95  * Reimplemented from YWidget.
96  **/
97  virtual int preferredWidth();
98 
99  /**
100  * Preferred height of the widget.
101  *
102  * Reimplemented from YWidget.
103  **/
104  virtual int preferredHeight();
105 
106  /**
107  * Set the new size of the widget.
108  *
109  * Reimplemented from YWidget.
110  **/
111  virtual void setSize( int newWidth, int newHeight );
112 
113  /**
114  * Accept the keyboard focus.
115  **/
116  virtual bool setKeyboardFocus();
117 
118 protected:
119 
120  YQWidgetCaption * _caption;
121  BusyBar * _bar;
122  QTimer * _timer;
123  int _timeout;
124 
125 private slots:
126  void setStalled();
127 
128 };
129 
130 
131 
132 
133 
134 class BusyBar : public QFrame
135 {
136  Q_OBJECT
137 public:
138  BusyBar(QWidget * parent);
139 
140 
141  /**
142  * start moving bar animation
143  **/
144  void run();
145 
146  /**
147  * stop moving bar animation
148  **/
149  void stop();
150 
151 protected:
152  void paintEvent(QPaintEvent *event);
153 
154 private:
155  double _position; // the position of the bar
156  bool _rightwards; // direction the bar moves
157  QTimer * _timer;
158  bool _alive;
159 
160 private slots:
161  void update();
162 
163 };
164 
165 
166 #endif // YQBusyIndicator_h
virtual void setLabel(const std::string &label)
Set the label (the caption above the progress bar).
virtual int preferredHeight()
Preferred height of the widget.
virtual void setEnabled(bool enabled)
Set enabled/disabled state.
virtual int preferredWidth()
Preferred width of the widget.
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
virtual void setAlive(bool newAlive)
Send a keep allive message.
virtual void setTimeout(int newTimeout)
Set the timeout is ms after that the widget shows &#39;stalled&#39; when no new tick is received.
Helper class for captions (labels) above a widget: Takes care of hiding itself when its text is empty...
int timeout() const
Return the timeout is ms after that the widget shows &#39;stalled&#39; when no new tick is received...
virtual bool setKeyboardFocus()
Accept the keyboard focus.
YQBusyIndicator(YWidget *parent, const std::string &label, int timeout=1000)
Constructor.
virtual ~YQBusyIndicator()
Destructor.