Seamly2D
Code documentation
vcolorproperty.cpp
Go to the documentation of this file.
1 /************************************************************************
2  **
3  ** @file vcolorproperty.cpp
4  ** @author hedgeware <internal(at)hedgeware.net>
5  ** @date
6  **
7  ** @brief
8  ** @copyright
9  ** All rights reserved. This program and the accompanying materials
10  ** are made available under the terms of the GNU Lesser General Public License
11  ** (LGPL) version 2.1 which accompanies this distribution, and is available at
12  ** http://www.gnu.org/licenses/lgpl-2.1.html
13  **
14  ** This library is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  ** Lesser General Public License for more details.
18  **
19  *************************************************************************/
20 
21 #include "vcolorproperty.h"
22 
23 #include <QColor>
24 #include <QLocale>
25 #include <QPixmap>
26 #include <QWidget>
27 
28 #include "../vproperty_p.h"
29 #include "vcolorpropertyeditor.h"
30 
32  VProperty(name, QVariant::Color)
33 {
34 }
35 
36 
37 //! Get the data how it should be displayed
38 QVariant VPE::VColorProperty::data (int column, int role) const
39 {
40  if (column == DPC_Data && (Qt::DisplayRole == role))
41  {
42  return VColorPropertyEditor::GetColorString(d_ptr->VariantValue.value<QColor>());
43  }
44  else if (Qt::EditRole == role)
45  {
46  return QVariant();
47  }
48  else if (column == DPC_Data && (Qt::DecorationRole == role))
49  {
50  return VColorPropertyEditor::GetColorPixmap(d_ptr->VariantValue.value<QColor>());
51  }
52  else
53  return VProperty::data(column, role);
54 }
55 
56 //! Returns an editor widget, or NULL if it doesn't supply one
57 QWidget *VPE::VColorProperty::createEditor(QWidget *parent, const QStyleOptionViewItem& options,
58  const QAbstractItemDelegate *delegate)
59 {
60  Q_UNUSED(options)
61  Q_UNUSED(delegate)
62 
63  VColorPropertyEditor *tmpWidget = new VColorPropertyEditor(parent);
64  tmpWidget->setLocale(parent->locale());
65  tmpWidget->setLineColor(d_ptr->VariantValue.value<QColor>());
66  return tmpWidget;
67 }
68 
69 //! Sets the property's data to the editor (returns false, if the standard delegate should do that)
71 {
72  VColorPropertyEditor *tmpWidget = qobject_cast<VColorPropertyEditor*>(editor);
73  if (tmpWidget)
74  {
75  tmpWidget->setLineColor(d_ptr->VariantValue.value<QColor>());
76  }
77  else
78  return false;
79 
80  return true;
81 }
82 
83 //! Gets the data from the widget
84 QVariant VPE::VColorProperty::getEditorData(const QWidget *editor) const
85 {
86  const VColorPropertyEditor *tmpWidget = qobject_cast<const VColorPropertyEditor*>(editor);
87  if (tmpWidget)
88  {
89  return tmpWidget->getLineColor();
90  }
91 
92  return QVariant();
93 }
94 
96 {
97  return "color";
98 }
99 
100 VPE::VProperty *VPE::VColorProperty::clone(bool include_children, VProperty *container) const
101 {
102  return VProperty::clone(include_children, container ? container : new VColorProperty(getName()));
103 }
static QString GetColorString(const QColor &color)
A helper function to convert a color into a string.
static QPixmap GetColorPixmap(const QColor &color, quint32 size=16)
A little helper function generating an image to represent a color.
QColor getLineColor() const
Returns the color currently set.
void setLineColor(const QColor &color_)
Sets the color of the widget.
virtual QVariant data(int column=DPC_Name, int role=Qt::DisplayRole) const Q_DECL_OVERRIDE
Get the data how it should be displayed.
virtual QString type() const Q_DECL_OVERRIDE
Returns a string containing the type of the property.
virtual VProperty * clone(bool include_children=true, VProperty *container=NULL) const Q_DECL_OVERRIDE
Clones this property.
virtual QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &options, const QAbstractItemDelegate *delegate) Q_DECL_OVERRIDE
Returns an editor widget, or NULL if it doesn't supply one.
virtual bool setEditorData(QWidget *editor) Q_DECL_OVERRIDE
Sets the property's data to the editor (returns false, if the standard delegate should do that)
virtual QVariant getEditorData(const QWidget *editor) const Q_DECL_OVERRIDE
Gets the data from the widget.
VColorProperty(const QString &name)
virtual Q_REQUIRED_RESULT VProperty * clone(bool include_children=true, VProperty *container=nullptr) const
Clones this property.
Definition: vproperty.cpp:372
virtual QVariant data(int column=DPC_Name, int role=Qt::DisplayRole) const
Get the data how it should be displayed.
Definition: vproperty.cpp:68