OpenWalnut  1.5.0dev
WPropertyColorWidget.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WPROPERTYCOLORWIDGET_H
26 #define WPROPERTYCOLORWIDGET_H
27 
28 #include <string>
29 
30 #include <QPushButton>
31 #include <QLabel>
32 #include <QAction>
33 #include <QHBoxLayout>
34 #include <QToolButton>
35 
36 #include "../guiElements/WScaleLabel.h"
37 
38 #include "WPropertyWidget.h"
39 
40 /**
41  * Implements a property widget for WPropColor.
42  */
44 {
45  Q_OBJECT
46 public:
47  /**
48  * Constructor. Creates a new widget appropriate for the specified property.
49  *
50  * \param property the property to handle
51  * \param parent the parent widget.
52  * \param propertyGrid the grid used to layout the labels and property widgets
53  */
54  WPropertyColorWidget( WPropColor property, QGridLayout* propertyGrid, QWidget* parent = 0 );
55 
56  /**
57  * Destructor.
58  */
59  virtual ~WPropertyColorWidget();
60 
61  /**
62  * Hide the button for a more compact layout.
63  *
64  * \param hide true to hide
65  */
66  void setColorPickerButtonHidden( bool hide = true );
67 
68 protected:
69  /**
70  * Internal helper, called to set the color
71  * \param color the new color
72  */
73  virtual void setColor( const QColor& color );
74 
75  /**
76  * Called whenever the widget should update.
77  */
78  virtual void update();
79 
80  /**
81  * Reimplemented to accept color drops
82  * \param event the handled event
83  */
84  virtual void dragEnterEvent( QDragEnterEvent* event );
85 
86  /**
87  * Reimplemented to accept color drops
88  * \param event the handled event
89  */
90  virtual void dropEvent( QDropEvent* event );
91 
92  /**
93  * The integer property represented by this widget.
94  */
95  WPropColor m_colorProperty;
96 
97  /**
98  * The button field showing the value
99  */
100  QWidget m_widget;
101 
102  /**
103  * Color display panel
104  */
105  QWidget* m_colPanel;
106 
107  /**
108  * Color picker button
109  */
110  QToolButton* m_colButton;
111 
112  /**
113  * Layout used to position the label and the checkbox
114  */
115  QHBoxLayout m_layout;
116 
117  /**
118  * Used to show the property as text.
119  */
121 
122  /**
123  * The layout used for the pure output (information properties)
124  */
125  QHBoxLayout m_infoLayout;
126 
127  /**
128  * Color picker
129  */
131 private:
132  /**
133  * Helper to convert between QColor and WColor.
134  *
135  * \param color a color
136  *
137  * \return the corresponding QColor.
138  */
139  static QColor toQColor( WColor color );
140 
141  /**
142  * Helper to convert between QColor and WColor.
143  *
144  * \param color a color
145  *
146  * \return the corresponding WColor.
147  */
148  static WColor toWColor( QColor color );
149 
150 public slots:
151 
152  /**
153  * Called when the m_button is clicked
154  */
155  void buttonClicked();
156 };
157 
158 #endif // WPROPERTYCOLORWIDGET_H
159 
Implements a property widget for WPropColor.
virtual void dropEvent(QDropEvent *event)
Reimplemented to accept color drops.
QWidget * m_colPanel
Color display panel.
QToolButton * m_colButton
Color picker button.
QHBoxLayout m_layout
Layout used to position the label and the checkbox.
QAction * m_colorPickerAction
Color picker.
WPropertyColorWidget(WPropColor property, QGridLayout *propertyGrid, QWidget *parent=0)
Constructor.
WScaleLabel m_asText
Used to show the property as text.
QWidget m_widget
The button field showing the value.
void buttonClicked()
Called when the m_button is clicked.
static WColor toWColor(QColor color)
Helper to convert between QColor and WColor.
WPropColor m_colorProperty
The integer property represented by this widget.
virtual ~WPropertyColorWidget()
Destructor.
virtual void setColor(const QColor &color)
Internal helper, called to set the color.
void setColorPickerButtonHidden(bool hide=true)
Hide the button for a more compact layout.
virtual void dragEnterEvent(QDragEnterEvent *event)
Reimplemented to accept color drops.
virtual void update()
Called whenever the widget should update.
static QColor toQColor(WColor color)
Helper to convert between QColor and WColor.
QHBoxLayout m_infoLayout
The layout used for the pure output (information properties)
Class building the base for all widgets representing properties.
virtual bool event(QEvent *event)
Custom event dispatcher.
Special Label that can shrink and expand in a layout.
Definition: WScaleLabel.h:37