/************************************************************************ ** ** @file vcolorproperty.cpp ** @author hedgeware ** @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" #include #include #include #include #include "../vproperty_p.h" #include "vcolorpropertyeditor.h" VPE::VColorProperty::VColorProperty(const QString &name) : VProperty(name, #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) QMetaType::QColor) #else QVariant::Color) #endif { } //! Get the data how it should be displayed auto VPE::VColorProperty::data(int column, int role) const -> QVariant { if (column == DPC_Data && (Qt::DisplayRole == role)) { return VColorPropertyEditor::GetColorString(d_ptr->VariantValue.value()); } if (Qt::EditRole == role) { return {}; } if (column == DPC_Data && (Qt::DecorationRole == role)) { return VColorPropertyEditor::GetColorPixmap(d_ptr->VariantValue.value()); } return VProperty::data(column, role); } //! Returns an editor widget, or NULL if it doesn't supply one auto VPE::VColorProperty::createEditor(QWidget *parent, const QStyleOptionViewItem &options, const QAbstractItemDelegate *delegate) -> QWidget * { Q_UNUSED(options) Q_UNUSED(delegate) VColorPropertyEditor* tmpWidget = new VColorPropertyEditor(parent); tmpWidget->setLocale(parent->locale()); tmpWidget->SetColor(d_ptr->VariantValue.value()); return tmpWidget; } //! Sets the property's data to the editor (returns false, if the standard delegate should do that) auto VPE::VColorProperty::setEditorData(QWidget *editor) -> bool { VColorPropertyEditor* tmpWidget = qobject_cast(editor); if (tmpWidget) { tmpWidget->SetColor(d_ptr->VariantValue.value()); } else return false; return true; } //! Gets the data from the widget auto VPE::VColorProperty::getEditorData(const QWidget *editor) const -> QVariant { const VColorPropertyEditor* tmpWidget = qobject_cast(editor); if (tmpWidget) { return tmpWidget->GetColor(); } return QVariant(); } auto VPE::VColorProperty::type() const -> QString { return "color"; } auto VPE::VColorProperty::clone(bool include_children, VProperty *container) const -> VPE::VProperty * { return VProperty::clone(include_children, container ? container : new VColorProperty(getName())); }