rock_widget_collection  0.1
Public Types | Public Slots | Public Member Functions | Protected Attributes | Properties | List of all members
WidgetButton Class Reference

#include <WidgetButton.h>

Inherits QPushButton.

Public Types

enum  Position {
  Default =0, Left, Top, Right,
  Bottom
}
 

Public Slots

void setWidget (const QString &name, QWidget *widget, bool shown=true)
 
void showWidget (bool shown)
 
QWidget * getWidget ()
 
QString getWidgetName ()
 
void widgetUpdate (int type=0)
 
void changePalette ()
 
void setIconAlternative (const QIcon &icon, bool isAlternative=false)
 
void printStatus ()
 
void setActive (bool active)
 
void corrcetName ()
 

Public Member Functions

 WidgetButton (QWidget *widget=0, Qt::Orientations dir=Qt::Horizontal, int width=150, int height=150)
 
virtual ~WidgetButton ()
 
const Position getPosition () const
 
const Position getPosition ()
 
void setPosition (const Position pos)
 

Protected Attributes

QWidget * mainWidget
 
QString name
 
QBoxLayout * layout
 
QPalette defaultPalette
 
QPalette redPalette
 
QTimer paletteTimer
 
QIcon icon
 
bool isAlternative
 
bool isActive
 
Qt::Orientations dir
 

Properties

Position position
 

Detailed Description

QPushButton which can display another widget or a text/icon alternatively. The widget can be showable and if not shown an icon or text will be displayed. when configured without widget display, only the icon or text will be shown.

All widgets which have a notifyUpdate(int) method will blink in red if the method is called and the widget is currently shown. When clicked the widget will stop blinking. This can be used to indicate that something has changed on the widget.

Author
Bjoern Lueck
Version
0.1

Definition at line 31 of file WidgetButton.h.

Member Enumeration Documentation

Enum to determine the position of the thumbnails

Enumerator
Default 
Left 
Top 
Right 
Bottom 

Definition at line 41 of file WidgetButton.h.

Constructor & Destructor Documentation

WidgetButton::WidgetButton ( QWidget *  widget = 0,
Qt::Orientations  dir = Qt::Horizontal,
int  width = 150,
int  height = 150 
)

Constructor

Definition at line 23 of file WidgetButton.cc.

23  :
24  QPushButton(widget),
25  redPalette(QPalette(Qt::red)),
26  dir(dir)
27 {
28  if(dir == Qt::Horizontal){
29  layout = new QHBoxLayout(this);
30  }else{
31  layout = new QVBoxLayout(this);
32  }
33  mainWidget=0;
34 
35  setSizePolicy(QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed));
36 
37 
38  setFixedSize(width,height);
39  isAlternative = false;
40  paletteTimer.setInterval(750);
41  connect(&paletteTimer, SIGNAL(timeout()), this, SLOT(changePalette()));
42  defaultPalette = this->palette();
43  layout->setContentsMargins(3,3,3,3);
44  position = Left;
45  qRegisterMetaType<WidgetButton::Position>("WidgetButton::Position");
46 }
QBoxLayout * layout
Definition: WidgetButton.h:126
QPalette redPalette
Definition: WidgetButton.h:130
Qt::Orientations dir
Definition: WidgetButton.h:140
bool isAlternative
Definition: WidgetButton.h:136
void changePalette()
QPalette defaultPalette
Definition: WidgetButton.h:128
Position position
Definition: WidgetButton.h:35
QTimer paletteTimer
Definition: WidgetButton.h:132
QWidget * mainWidget
Definition: WidgetButton.h:117
WidgetButton::~WidgetButton ( )
virtual

Destructor

Definition at line 48 of file WidgetButton.cc.

49 {
50 }

Member Function Documentation

void WidgetButton::changePalette ( )
slot

Changes the palette of the widget from red to the default scheme and the other way around, is called by a timer automatically

Definition at line 263 of file WidgetButton.cc.

264 {
265  if(palette().color(QPalette::Background).red() == 255)
266  {
267  setPalette(defaultPalette);
268  }
269  else
270  {
271  setPalette(redPalette);
272  }
273 }
QPalette redPalette
Definition: WidgetButton.h:130
QPalette defaultPalette
Definition: WidgetButton.h:128
void WidgetButton::corrcetName ( )
slot

Definition at line 76 of file WidgetButton.cc.

76  {
77  //The next lines will fail if the objects was constructed by rubqt ui loder because all objects are recognized as qwidget
78  MultiWidget *w = dynamic_cast<MultiWidget*>(mainWidget);
79  if(w > 0){
80  name = w->getMinimizedLabel();
81  }
82 
83  if(isActive)
84  {
85  if(isAlternative == false)
86  {
87  setIcon(QIcon());
88  }
89  else
90  {
91  if(!icon.isNull())
92  {
93  setText("");
94  setIcon(icon);
95  }
96  else
97  {
98  setText(name);
99  setIcon(QIcon());
100  }
101  }
102  }
103  else
104  {
105  if(icon.isNull() || isAlternative == false)
106  {
107  setText(name);
108  }
109  else
110  {
111  setText("");
112  setIcon(icon);
113  }
114  setPalette(QPalette(QColor(0, 255, 0)));
115  }
116  /*
117  const QMetaObject* meta = mainWidget->metaObject();
118  int index = meta->indexOfMethod("notifyUpdate(int)");
119  if(index > -1)
120  {
121  connect(mainWidget, SIGNAL(notifyUpdate(int)), this, SLOT(widgetUpdate(int)));
122  }
123  else
124  {
125  std::cout << "No notifyUpdate(int) method found, updates will not be displayed for: " << name.toStdString() << std::endl;
126  }
127  */
128 }
bool isAlternative
Definition: WidgetButton.h:136
QString getMinimizedLabel()
Definition: MultiWidget.h:50
QString name
Definition: WidgetButton.h:124
QWidget * mainWidget
Definition: WidgetButton.h:117
const WidgetButton::Position WidgetButton::getPosition ( ) const

Definition at line 53 of file WidgetButton.cc.

53  {
54  return position;
55 }
Position position
Definition: WidgetButton.h:35
const Position WidgetButton::getPosition ( )
inline

Definition at line 55 of file WidgetButton.h.

55 {return position;}
Position position
Definition: WidgetButton.h:35
QWidget * WidgetButton::getWidget ( )
slot

Returns the widget

Returns
the widget on the button

Definition at line 244 of file WidgetButton.cc.

245 {
246  return mainWidget;
247 }
QWidget * mainWidget
Definition: WidgetButton.h:117
QString WidgetButton::getWidgetName ( )
slot

Returns the name of the widget

Returns
teh anme of the widget

Definition at line 249 of file WidgetButton.cc.

250 {
251  return name;
252 }
QString name
Definition: WidgetButton.h:124
void WidgetButton::printStatus ( )
slot

Definition at line 57 of file WidgetButton.cc.

58 {
59  std::cout << (this == NULL) << std::endl;
60  std::cout << "Alt: " << isAlternative << std::endl;
61 }
bool isAlternative
Definition: WidgetButton.h:136
void WidgetButton::setActive ( bool  active)
slot

Definition at line 64 of file WidgetButton.cc.

64  {
65  isActive=false;
66  MultiWidget *widget = dynamic_cast<MultiWidget*>(mainWidget);
67  if(widget > 0){
68  widget->setActive(active);
69  }else{
70  //printf("Not updateing from class: %s %i\n",typeid(mainWidget).name(),widget);
71  }
72 
73 }
void setActive(bool b)
Definition: MultiWidget.h:27
QWidget * mainWidget
Definition: WidgetButton.h:117
void WidgetButton::setIconAlternative ( const QIcon &  icon,
bool  isAlternative = false 
)
slot

Sets an alternative Icon which can be used instead of the widget (e.g. if the widget is badly visible if sized down). If the icon is not used as alternative to the widget it is displayed instead of teh text if the widget is not shown

Parameters
iconthe icon alternative
isAlternativeif the icon is the alternative to the widget or to the text, defaults to false

Definition at line 238 of file WidgetButton.cc.

239 {
240  this->icon = icon;
242 }
bool isAlternative
Definition: WidgetButton.h:136
void WidgetButton::setPosition ( const Position  pos)
inline

Definition at line 56 of file WidgetButton.h.

56 {position = pos;}
Position position
Definition: WidgetButton.h:35
void WidgetButton::setWidget ( const QString &  name,
QWidget *  widget,
bool  shown = true 
)
slot

Sets the widget for the button The given name will be used if the widget is not shown

Parameters
namethe name to show when the widget is not shown
widgetthe widget to be shown
showntrue if the widget shall be shown on the button immediately, false otherwise, defaults to true

Definition at line 130 of file WidgetButton.cc.

131 {
132 
133  //The next lines will fail if the objects was constructed by rubqt ui loder because all objects are recognized as qwidget
134  QString name = name_;
135  MultiWidget *w = dynamic_cast<MultiWidget*>(widget);
136  if(w > 0){
137  name = w->getMinimizedLabel();
138  }
139 
140 
141  this->name = name;
142  mainWidget = widget;
143  if(shown)
144  {
145  setEnabled(true);
146  if(isAlternative == false)
147  {
148  setIcon(QIcon());
149  layout->addWidget(mainWidget);
150  }
151  else
152  {
153  if(!icon.isNull())
154  {
155  setText("");
156  setIcon(icon);
157  }
158  else
159  {
160  setText(name);
161  setIcon(QIcon());
162  }
163  }
164  mainWidget->setEnabled(false);
165  }
166  else
167  {
168  if(icon.isNull() || isAlternative == false)
169  {
170  setText(name);
171  }
172  else
173  {
174  setText("");
175  setIcon(icon);
176  }
177  setEnabled(false);
178  setPalette(QPalette(QColor(0, 255, 0)));
179  }
180  const QMetaObject* meta = widget->metaObject();
181  int index = meta->indexOfMethod("notifyUpdate(int)");
182  if(index > -1)
183  {
184  connect(widget, SIGNAL(notifyUpdate(int)), this, SLOT(widgetUpdate(int)));
185  }
186  else
187  {
188  std::cout << "No notifyUpdate(int) method found, updates will not be displayed for: " << name.toStdString() << std::endl;
189  }
190 
191  setActive(shown);
192 }
QBoxLayout * layout
Definition: WidgetButton.h:126
void widgetUpdate(int type=0)
bool isAlternative
Definition: WidgetButton.h:136
void setActive(bool active)
Definition: WidgetButton.cc:64
QString getMinimizedLabel()
Definition: MultiWidget.h:50
QString name
Definition: WidgetButton.h:124
QWidget * mainWidget
Definition: WidgetButton.h:117
void WidgetButton::showWidget ( bool  shown)
slot

Show or hides the widget

Parameters
showntrue if the widget shall be shown

Definition at line 194 of file WidgetButton.cc.

195 {
196  if(shown)
197  {
198  setText("");
199  setPalette(defaultPalette);
200  if(isAlternative == false)
201  {
202  layout->addWidget(mainWidget);
203  }
204  else
205  {
206  if(!icon.isNull())
207  {
208  setText("");
209  setIcon(icon);
210  }
211  else
212  {
213  setText(name);
214  setIcon(QIcon());
215  }
216  }
217  mainWidget->setEnabled(false);
218  setEnabled(true);
219  }
220  else
221  {
222  paletteTimer.stop();
223  setPalette(QPalette(QColor(0, 255, 0)));
224  layout->removeWidget(mainWidget);
225  if(icon.isNull())
226  {
227  setText(name);
228  }
229  else
230  {
231  setIcon(icon);
232  }
233  setEnabled(false);
234  }
235  repaint();
236 }
QBoxLayout * layout
Definition: WidgetButton.h:126
bool isAlternative
Definition: WidgetButton.h:136
QPalette defaultPalette
Definition: WidgetButton.h:128
QString name
Definition: WidgetButton.h:124
QTimer paletteTimer
Definition: WidgetButton.h:132
QWidget * mainWidget
Definition: WidgetButton.h:117
void WidgetButton::widgetUpdate ( int  type = 0)
slot

Slot called when an notifyUpdate from the widget was signaled.

Parameters
typethe type, currently ignored, defaults to 0

Definition at line 254 of file WidgetButton.cc.

255 {
256  if(!mainWidget->isEnabled())
257  {
258  setPalette(redPalette);
259  paletteTimer.start();
260  }
261 }
QPalette redPalette
Definition: WidgetButton.h:130
QTimer paletteTimer
Definition: WidgetButton.h:132
QWidget * mainWidget
Definition: WidgetButton.h:117

Member Data Documentation

QPalette WidgetButton::defaultPalette
protected

The default palette of teh button

Definition at line 128 of file WidgetButton.h.

Qt::Orientations WidgetButton::dir
protected

Definition at line 140 of file WidgetButton.h.

QIcon WidgetButton::icon
protected

Icon used as alternative

Definition at line 134 of file WidgetButton.h.

bool WidgetButton::isActive
protected

True if this Widget is Active (not minimized)

Definition at line 138 of file WidgetButton.h.

bool WidgetButton::isAlternative
protected

If the icon is an alternative to the widget or only the text

Definition at line 136 of file WidgetButton.h.

QBoxLayout* WidgetButton::layout
protected

The layout of the button

Definition at line 126 of file WidgetButton.h.

QWidget* WidgetButton::mainWidget
protected

The main widget

Definition at line 117 of file WidgetButton.h.

QString WidgetButton::name
protected

The name of the widget

Definition at line 124 of file WidgetButton.h.

QTimer WidgetButton::paletteTimer
protected

Timer for blinking red palette usage

Definition at line 132 of file WidgetButton.h.

QPalette WidgetButton::redPalette
protected

A red palette

Definition at line 130 of file WidgetButton.h.

Property Documentation

Position WidgetButton::position
readwrite

Position for the button

Definition at line 35 of file WidgetButton.h.


The documentation for this class was generated from the following files: