diff --git a/src/plugins/qmldesigner/components/navigator/iconcheckboxitemdelegate.cpp b/src/plugins/qmldesigner/components/navigator/iconcheckboxitemdelegate.cpp new file mode 100644 index 0000000000000000000000000000000000000000..db74812d8b5db812d9dc32b996d1da1dfed83880 --- /dev/null +++ b/src/plugins/qmldesigner/components/navigator/iconcheckboxitemdelegate.cpp @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** 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 diff --git a/src/plugins/qmldesigner/components/navigator/iconcheckboxitemdelegate.h b/src/plugins/qmldesigner/components/navigator/iconcheckboxitemdelegate.h new file mode 100644 index 0000000000000000000000000000000000000000..ed6576fb2da981828332f4015236d1015c0bc812 --- /dev/null +++ b/src/plugins/qmldesigner/components/navigator/iconcheckboxitemdelegate.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** 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 diff --git a/src/plugins/qmldesigner/components/navigator/navigator.pri b/src/plugins/qmldesigner/components/navigator/navigator.pri index c261403ce3acef8f5c04d38651c0120ab82a1f30..02ebc62939551513270ee0659ec45f3260cf3a89 100644 --- a/src/plugins/qmldesigner/components/navigator/navigator.pri +++ b/src/plugins/qmldesigner/components/navigator/navigator.pri @@ -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 diff --git a/src/plugins/qmldesigner/components/navigator/navigatortreeview.cpp b/src/plugins/qmldesigner/components/navigator/navigatortreeview.cpp index 665d0058c296a58db8b25f7b762a25e343406f15..1eacd49fe1949db161fec6d5de622437975532d3 100644 --- a/src/plugins/qmldesigner/components/navigator/navigatortreeview.cpp +++ b/src/plugins/qmldesigner/components/navigator/navigatortreeview.cpp @@ -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(); -} - } diff --git a/src/plugins/qmldesigner/components/navigator/navigatortreeview.h b/src/plugins/qmldesigner/components/navigator/navigatortreeview.h index 6ca780bbec74dc6f1d57798ea451d591a00a506f..a87b6b801a6efd39cf46dd8f75d004f787347fc6 100644 --- a/src/plugins/qmldesigner/components/navigator/navigatortreeview.h +++ b/src/plugins/qmldesigner/components/navigator/navigatortreeview.h @@ -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: diff --git a/src/plugins/qmldesigner/components/navigator/navigatorview.cpp b/src/plugins/qmldesigner/components/navigator/navigatorview.cpp index 8410da3d4df82a6bf519b13ece877e50c3d05b98..f9382701e0ff0a4fcbbd126aaf89352b06367487 100644 --- a/src/plugins/qmldesigner/components/navigator/navigatorview.cpp +++ b/src/plugins/qmldesigner/components/navigator/navigatorview.cpp @@ -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",