2014-09-10 17:27:45 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vcolorproperty.cpp
|
|
|
|
** @author hedgeware <internal(at)hedgeware.net>
|
|
|
|
** @date
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** All rights reserved. This program and the accompanying materials
|
|
|
|
** are made available under the terms of the GNU Lesser General Public License
|
|
|
|
** (LGPL) version 2.1 which accompanies this distribution, and is available at
|
|
|
|
** http://www.gnu.org/licenses/lgpl-2.1.html
|
|
|
|
**
|
|
|
|
** This library is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
** Lesser General Public License for more details.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "vcolorproperty.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
|
|
|
#include <QColor>
|
|
|
|
#include <QLocale>
|
|
|
|
#include <QPixmap>
|
|
|
|
#include <QWidget>
|
2014-09-10 17:27:45 +02:00
|
|
|
|
2014-09-14 11:16:59 +02:00
|
|
|
#include "../vproperty_p.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "vcolorpropertyeditor.h"
|
|
|
|
|
2016-12-21 13:02:55 +01:00
|
|
|
VPE::VColorProperty::VColorProperty(const QString &name) :
|
2014-09-10 17:27:45 +02:00
|
|
|
VProperty(name, QVariant::Color)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! Get the data how it should be displayed
|
2016-12-21 13:02:55 +01:00
|
|
|
QVariant VPE::VColorProperty::data (int column, int role) const
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
2014-09-10 19:57:08 +02:00
|
|
|
if (column == DPC_Data && (Qt::DisplayRole == role))
|
|
|
|
{
|
2015-02-03 11:17:04 +01:00
|
|
|
return VColorPropertyEditor::GetColorString(d_ptr->VariantValue.value<QColor>());
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
|
|
|
else if (Qt::EditRole == role)
|
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
return QVariant();
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
|
|
|
else if (column == DPC_Data && (Qt::DecorationRole == role))
|
|
|
|
{
|
2015-02-03 11:17:04 +01:00
|
|
|
return VColorPropertyEditor::GetColorPixmap(d_ptr->VariantValue.value<QColor>());
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
2014-09-10 17:27:45 +02:00
|
|
|
else
|
|
|
|
return VProperty::data(column, role);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Returns an editor widget, or NULL if it doesn't supply one
|
2016-12-21 13:02:55 +01:00
|
|
|
QWidget* VPE::VColorProperty::createEditor(QWidget* parent, const QStyleOptionViewItem& options,
|
|
|
|
const QAbstractItemDelegate* delegate)
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
2016-12-20 20:19:21 +01:00
|
|
|
Q_UNUSED(options)
|
|
|
|
Q_UNUSED(delegate)
|
2014-09-10 17:27:45 +02:00
|
|
|
|
|
|
|
VColorPropertyEditor* tmpWidget = new VColorPropertyEditor(parent);
|
2015-02-11 11:33:13 +01:00
|
|
|
tmpWidget->setLocale(parent->locale());
|
2015-02-03 11:17:04 +01:00
|
|
|
tmpWidget->SetColor(d_ptr->VariantValue.value<QColor>());
|
2014-09-10 17:27:45 +02:00
|
|
|
return tmpWidget;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Sets the property's data to the editor (returns false, if the standard delegate should do that)
|
2016-12-21 13:02:55 +01:00
|
|
|
bool VPE::VColorProperty::setEditorData(QWidget* editor)
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
VColorPropertyEditor* tmpWidget = qobject_cast<VColorPropertyEditor*>(editor);
|
2014-09-10 19:57:08 +02:00
|
|
|
if (tmpWidget)
|
|
|
|
{
|
2015-02-03 11:17:04 +01:00
|
|
|
tmpWidget->SetColor(d_ptr->VariantValue.value<QColor>());
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
2014-09-10 17:27:45 +02:00
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Gets the data from the widget
|
2016-12-21 13:02:55 +01:00
|
|
|
QVariant VPE::VColorProperty::getEditorData(const QWidget *editor) const
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
2014-09-14 11:16:59 +02:00
|
|
|
const VColorPropertyEditor* tmpWidget = qobject_cast<const VColorPropertyEditor*>(editor);
|
2014-09-10 19:57:08 +02:00
|
|
|
if (tmpWidget)
|
|
|
|
{
|
2015-02-03 11:17:04 +01:00
|
|
|
return tmpWidget->GetColor();
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
2014-09-10 17:27:45 +02:00
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
2016-12-21 13:02:55 +01:00
|
|
|
QString VPE::VColorProperty::type() const
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
return "color";
|
|
|
|
}
|
|
|
|
|
2016-12-21 13:02:55 +01:00
|
|
|
VPE::VProperty *VPE::VColorProperty::clone(bool include_children, VProperty *container) const
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
return VProperty::clone(include_children, container ? container : new VColorProperty(getName()));
|
|
|
|
}
|