2014-09-10 17:27:45 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vpropertydelegate.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 "vpropertydelegate.h"
|
|
|
|
#include "vproperty.h"
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QStyle>
|
|
|
|
#include <QPen>
|
|
|
|
#include <QPainter>
|
|
|
|
|
|
|
|
using namespace VPE;
|
|
|
|
|
|
|
|
VPropertyDelegate::VPropertyDelegate(QObject *parent) :
|
|
|
|
QStyledItemDelegate(parent), RowHeight(0), AddRowHeight(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
VPropertyDelegate::~VPropertyDelegate()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
2014-09-10 19:57:08 +02:00
|
|
|
QWidget* VPropertyDelegate::createEditor (QWidget* parent, const QStyleOptionViewItem& option,
|
|
|
|
const QModelIndex& index) const
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
QWidget* tmpWidget = nullptr;
|
2014-09-10 19:57:08 +02:00
|
|
|
if (index.isValid())
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
VProperty* tmpProperty = reinterpret_cast<VProperty*>(index.internalPointer());
|
|
|
|
tmpWidget = tmpProperty->createEditor(parent, option, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
return tmpWidget ? tmpWidget : QStyledItemDelegate::createEditor(parent, option, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! Sets the index data to the editor
|
|
|
|
void VPropertyDelegate::setEditorData (QWidget * editor, const QModelIndex & index) const
|
|
|
|
{
|
|
|
|
bool done = false;
|
2014-09-10 19:57:08 +02:00
|
|
|
if (index.isValid() && editor)
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
VProperty* tmpProperty = reinterpret_cast<VProperty*>(index.internalPointer());
|
|
|
|
done = tmpProperty->setEditorData(editor);
|
|
|
|
}
|
|
|
|
|
2014-09-10 19:57:08 +02:00
|
|
|
if (!done)
|
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
QStyledItemDelegate::setEditorData(editor, index);
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
2014-09-10 17:27:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//! Updates the index data
|
|
|
|
void VPropertyDelegate::setModelData (QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const
|
|
|
|
{
|
|
|
|
QVariant tmpData;
|
2014-09-10 19:57:08 +02:00
|
|
|
if (index.isValid() && editor)
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
VProperty* tmpProperty = reinterpret_cast<VProperty*>(index.internalPointer());
|
|
|
|
tmpData = tmpProperty->getEditorData(editor);
|
|
|
|
}
|
|
|
|
|
2014-09-10 19:57:08 +02:00
|
|
|
if (tmpData.isNull())
|
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
QStyledItemDelegate::setModelData(editor, model, index);
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
2014-09-10 17:27:45 +02:00
|
|
|
else
|
|
|
|
model->setData(index, tmpData);
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize VPropertyDelegate::sizeHint (const QStyleOptionViewItem& option, const QModelIndex& index) const
|
|
|
|
{
|
|
|
|
QSize tmpStandardSizeHint = QStyledItemDelegate::sizeHint(option, index);
|
|
|
|
tmpStandardSizeHint.setHeight(tmpStandardSizeHint.height() + 1);
|
|
|
|
|
2014-09-10 19:57:08 +02:00
|
|
|
if (RowHeight > 0)
|
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
return QSize(tmpStandardSizeHint.width(), AddRowHeight ? tmpStandardSizeHint.height() + RowHeight : RowHeight);
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
2014-09-10 17:27:45 +02:00
|
|
|
else
|
|
|
|
return tmpStandardSizeHint;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VPropertyDelegate::setRowHeight(int height, bool add_to_standard)
|
|
|
|
{
|
|
|
|
RowHeight = height;
|
|
|
|
AddRowHeight = add_to_standard;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VPropertyDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
|
|
|
|
{
|
|
|
|
bool done = false;
|
2014-09-10 19:57:08 +02:00
|
|
|
if (index.isValid() && index.column() == 1)
|
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
done = reinterpret_cast<VProperty*>(index.internalPointer())->paint(painter, option, index, this);
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
2014-09-10 17:27:45 +02:00
|
|
|
|
2014-09-10 19:57:08 +02:00
|
|
|
if (!done)
|
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
QStyledItemDelegate::paint(painter, option, index);
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
2014-09-10 17:27:45 +02:00
|
|
|
|
|
|
|
QColor tmpPenColor = static_cast<QRgb>(QApplication::style()->styleHint(QStyle::SH_Table_GridLineColor, &option));
|
|
|
|
|
|
|
|
QPen tmpOldPen = painter->pen();
|
|
|
|
painter->setPen(QPen(tmpPenColor));
|
|
|
|
painter->drawLine(option.rect.right(), option.rect.y(), option.rect.right(), option.rect.bottom());
|
|
|
|
painter->drawLine(option.rect.x(), option.rect.bottom(), option.rect.right(), option.rect.bottom());
|
|
|
|
painter->setPen(tmpOldPen);
|
|
|
|
}
|