Commit e401248c authored by Marco Bubke's avatar Marco Bubke

QmlDesigner: Refactor IconCheckboxItemDelegate

Change-Id: I947b3f928a8a83e2930a0f996f9d04a8fe85ff0b
Reviewed-by: default avatarTim Jenssen <tim.jenssen@digia.com>
parent f9fe75a5
......@@ -50,46 +50,53 @@ IconCheckboxItemDelegate::IconCheckboxItemDelegate(QObject *parent,
QString uncheckedPixmapURL,
NavigatorTreeModel *treeModel)
: QStyledItemDelegate(parent),
offPix(uncheckedPixmapURL),
onPix(checkedPixmapURL),
m_TreeModel(treeModel)
offPixmap(uncheckedPixmapURL),
onPixmap(checkedPixmapURL),
m_navigatorTreeModel(treeModel)
{}
QSize IconCheckboxItemDelegate::sizeHint(const QStyleOptionViewItem &option,
const QModelIndex &index) const
static bool indexIsHolingModelNode(const QModelIndex &modelIndex)
{
Q_UNUSED(option);
Q_UNUSED(index);
return modelIndex.data(NavigatorTreeModel::InternalIdRole).isValid();
}
if (!index.data(Qt::UserRole).isValid())
return QSize();
QSize IconCheckboxItemDelegate::sizeHint(const QStyleOptionViewItem & /*option*/,
const QModelIndex &modelIndex) const
{
if (indexIsHolingModelNode(modelIndex))
return QSize(15, 20);
return QSize(15, 20);
return QSize();
}
void IconCheckboxItemDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option, const QModelIndex &index) const
static bool isChecked(NavigatorTreeModel *navigatorTreeMode, const QModelIndex &modelIndex)
{
if (!index.data(Qt::UserRole).isValid())
return;
return navigatorTreeMode->itemFromIndex(modelIndex)->checkState() == Qt::Checked;
}
painter->save();
if (option.state & QStyle::State_Selected)
drawSelectionBackground(painter, option);
void IconCheckboxItemDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &styleOption,
const QModelIndex &modelIndex) const
{
const int offset = 2;
if (indexIsHolingModelNode(modelIndex)) {
painter->save();
if (styleOption.state & QStyle::State_Selected)
drawSelectionBackground(painter, styleOption);
if (!m_TreeModel->nodeForIndex(index).isRootNode()) {
if (!m_navigatorTreeModel->nodeForIndex(modelIndex).isRootNode()) {
bool isChecked= (m_TreeModel->itemFromIndex(index)->checkState() == Qt::Checked);
if (m_navigatorTreeModel->isNodeInvisible(modelIndex))
painter->setOpacity(0.5);
if (m_TreeModel->isNodeInvisible( index ))
painter->setOpacity(0.5);
if (isChecked(m_navigatorTreeModel, modelIndex))
painter->drawPixmap(styleOption.rect.x() + offset, styleOption.rect.y() + offset, onPixmap);
else
painter->drawPixmap(styleOption.rect.x() + offset, styleOption.rect.y() + offset, offPixmap);
}
if (isChecked)
painter->drawPixmap(option.rect.x()+2,option.rect.y()+2,onPix);
else
painter->drawPixmap(option.rect.x()+2,option.rect.y()+2,offPix);
painter->restore();
}
painter->restore();
}
} // namespace QmlDesigner
......@@ -52,9 +52,9 @@ public:
const QModelIndex &index) const;
private:
QPixmap offPix;
QPixmap onPix;
NavigatorTreeModel *m_TreeModel;
QPixmap offPixmap;
QPixmap onPixmap;
NavigatorTreeModel *m_navigatorTreeModel;
};
} // namespace QmlDesigner
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment