Commit f9fe75a5 authored by Marco Bubke's avatar Marco Bubke

QmlDesigner: Move IconCheckboxItemDelegate in own file

Change-Id: I9b3d3fc6f9be382b6141a736b5d063eebecf8364
Reviewed-by: default avatarTim Jenssen <tim.jenssen@digia.com>
parent aaaea73b
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "iconcheckboxitemdelegate.h"
#include <qmath.h>
#include "navigatorview.h"
#include "navigatortreeview.h"
#include "navigatortreemodel.h"
#include "qproxystyle.h"
#include "metainfo.h"
#include <QLineEdit>
#include <QPen>
#include <QPixmapCache>
#include <QMouseEvent>
#include <QPainter>
namespace QmlDesigner {
IconCheckboxItemDelegate::IconCheckboxItemDelegate(QObject *parent,
QString checkedPixmapURL,
QString uncheckedPixmapURL,
NavigatorTreeModel *treeModel)
: QStyledItemDelegate(parent),
offPix(uncheckedPixmapURL),
onPix(checkedPixmapURL),
m_TreeModel(treeModel)
{}
QSize IconCheckboxItemDelegate::sizeHint(const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
Q_UNUSED(option);
Q_UNUSED(index);
if (!index.data(Qt::UserRole).isValid())
return QSize();
return QSize(15, 20);
}
void IconCheckboxItemDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if (!index.data(Qt::UserRole).isValid())
return;
painter->save();
if (option.state & QStyle::State_Selected)
drawSelectionBackground(painter, option);
if (!m_TreeModel->nodeForIndex(index).isRootNode()) {
bool isChecked= (m_TreeModel->itemFromIndex(index)->checkState() == Qt::Checked);
if (m_TreeModel->isNodeInvisible( index ))
painter->setOpacity(0.5);
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();
}
} // namespace QmlDesigner
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef QMLDESIGNER_ICONCHECKBOXITEMDELEGATE_H
#define QMLDESIGNER_ICONCHECKBOXITEMDELEGATE_H
#include <QStyledItemDelegate>
namespace QmlDesigner {
class NavigatorTreeModel;
class IconCheckboxItemDelegate : public QStyledItemDelegate
{
public:
explicit IconCheckboxItemDelegate(QObject *parent,
QString checkedPixmapURL,
QString uncheckedPixmapURL,
NavigatorTreeModel *treeModel);
QSize sizeHint(const QStyleOptionViewItem &option,
const QModelIndex &index) const;
void paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index) const;
private:
QPixmap offPix;
QPixmap onPix;
NavigatorTreeModel *m_TreeModel;
};
} // namespace QmlDesigner
#endif // QMLDESIGNER_ICONCHECKBOXITEMDELEGATE_H
......@@ -4,12 +4,14 @@ SOURCES += navigatorview.cpp \
navigatortreemodel.cpp \
navigatorwidget.cpp \
nameitemdelegate.cpp \
iconcheckboxitemdelegate.cpp \
navigatortreeview.cpp
HEADERS += navigatorview.h \
navigatortreemodel.h \
navigatorwidget.h \
nameitemdelegate.h \
iconcheckboxitemdelegate.h \
navigatortreeview.h
RESOURCES += navigator.qrc
......@@ -40,6 +40,7 @@
#include <QPen>
#include <QPixmapCache>
#include <QMouseEvent>
#include <QPainter>
namespace QmlDesigner {
......@@ -125,41 +126,4 @@ NavigatorTreeView::NavigatorTreeView(QWidget *parent)
style->setParent(this);
}
QSize IconCheckboxItemDelegate::sizeHint(const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
Q_UNUSED(option);
Q_UNUSED(index);
if (!index.data(Qt::UserRole).isValid())
return QSize();
return QSize(15, 20);
}
void IconCheckboxItemDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if (!index.data(Qt::UserRole).isValid())
return;
painter->save();
if (option.state & QStyle::State_Selected)
drawSelectionBackground(painter, option);
if (!m_TreeModel->nodeForIndex(index).isRootNode()) {
bool isChecked= (m_TreeModel->itemFromIndex(index)->checkState() == Qt::Checked);
if (m_TreeModel->isNodeInvisible( index ))
painter->setOpacity(0.5);
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();
}
}
......@@ -33,44 +33,10 @@
#include <QTreeView>
#include <QStyledItemDelegate>
#include <QPainter>
QT_BEGIN_NAMESPACE
class QTreeView;
class QStandardItem;
class QItemSelection;
class QModelIndex;
QT_END_NAMESPACE
namespace QmlDesigner {
class NavigatorWidget;
class NavigatorTreeModel;
void drawSelectionBackground(QPainter *painter, const QStyleOption &option);
class IconCheckboxItemDelegate : public QStyledItemDelegate
{
public:
explicit IconCheckboxItemDelegate(QObject *parent = 0, QString checkedPixmapURL="", QString uncheckedPixmapURL="", NavigatorTreeModel *treeModel=NULL)
: QStyledItemDelegate(parent),offPix(uncheckedPixmapURL),onPix(checkedPixmapURL),m_TreeModel(treeModel)
{}
QSize sizeHint(const QStyleOptionViewItem &option,
const QModelIndex &index) const;
void paint(QPainter *painter,
const QStyleOptionViewItem &option, const QModelIndex &index) const;
private:
QPixmap offPix;
QPixmap onPix;
NavigatorTreeModel *m_TreeModel;
};
class NavigatorTreeView : public QTreeView
{
public:
......
......@@ -31,6 +31,7 @@
#include "navigatortreemodel.h"
#include "navigatorwidget.h"
#include "nameitemdelegate.h"
#include "iconcheckboxitemdelegate.h"
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/icore.h>
......@@ -74,9 +75,12 @@ NavigatorView::NavigatorView(QObject* parent) :
treeWidget()->setIndentation(treeWidget()->indentation() * 0.5);
NameItemDelegate *idDelegate = new NameItemDelegate(this,m_treeModel.data());
IconCheckboxItemDelegate *showDelegate = new IconCheckboxItemDelegate(this,":/qmldesigner/images/eye_open.png",
":/qmldesigner/images/placeholder.png",m_treeModel.data());
NameItemDelegate *idDelegate = new NameItemDelegate(this,
m_treeModel.data());
IconCheckboxItemDelegate *showDelegate = new IconCheckboxItemDelegate(this,
":/qmldesigner/images/eye_open.png",
":/qmldesigner/images/placeholder.png",
m_treeModel.data());
#ifdef _LOCK_ITEMS_
IconCheckboxItemDelegate *lockDelegate = new IconCheckboxItemDelegate(this,":/qmldesigner/images/lock.png",
......
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