Commit dcec6b12 authored by Christiaan Janssen's avatar Christiaan Janssen
Browse files

QmlDesigner.Navigator: New look of the navigator

parent 81f14bb2
VPATH += $$PWD
INCLUDEPATH += $$PWD
SOURCES += navigatorview.cpp \
navigatortreemodel.cpp \
navigatorwidget.cpp
HEADERS += navigatorview.h \
navigatortreemodel.h \
navigatorwidget.h
SOURCES += navigatorview.cpp \
navigatortreemodel.cpp \
navigatorwidget.cpp \
navigatortreeview.cpp
HEADERS += navigatorview.h \
navigatortreemodel.h \
navigatorwidget.h \
navigatortreeview.h
......@@ -280,6 +280,18 @@ void NavigatorTreeModel::handleChangedItem(QStandardItem *item)
bool invisible = (item->checkState() == Qt::Unchecked);
node.setAuxiliaryData("invisible", invisible);
propagateInvisible(node,invisible);
}
}
void NavigatorTreeModel::propagateInvisible(const ModelNode &node, const bool &invisible)
{
QList <ModelNode> children = node.allDirectSubModelNodes();
foreach (ModelNode child, children) {
child.setAuxiliaryData("childOfInvisible",invisible);
bool childIsInvisible = child.auxiliaryData("invisible").toBool();
if (!child.auxiliaryData("invisible").toBool())
propagateInvisible(child,invisible);
}
}
......@@ -343,6 +355,15 @@ bool NavigatorTreeModel::isInTree(const ModelNode &node) const
return m_nodeHash.keys().contains(qHash(node));
}
bool NavigatorTreeModel::isNodeInvisible(const QModelIndex &index) const
{
ModelNode node = nodeForIndex(index);
bool nodeInvisible = node.auxiliaryData("invisible").toBool();
if (node.hasAuxiliaryData("childOfInvisible"))
nodeInvisible = nodeInvisible || node.auxiliaryData("childOfInvisible").toBool();
return nodeInvisible;
}
/**
Adds node & all children to the visible tree hierarchy (if node should be visible at all).
......
......@@ -98,6 +98,8 @@ public:
ModelNode nodeForIndex(const QModelIndex &index) const;
bool isInTree(const ModelNode &node) const;
void propagateInvisible(const ModelNode &node, const bool &invisible);
bool isNodeInvisible(const QModelIndex &index) const;
void addSubTree(const ModelNode &node);
void removeSubTree(const ModelNode &node);
......
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "navigatortreeview.h"
#include "navigatorview.h"
#include "navigatortreemodel.h"
#include "navigatorwidget.h"
#include <nodeproperty.h>
namespace QmlDesigner {
QSize IconCheckboxItemDelegate::sizeHint(const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
return QSize(15,17);
}
void IconCheckboxItemDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option, const QModelIndex &index) const
{
painter->save();
if (option.state & QStyle::State_Selected)
painter->fillRect(option.rect, option.palette.highlight());
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()+1,onPix);
else
painter->drawPixmap(option.rect.x()+2,option.rect.y()+1,offPix);
painter->setOpacity(1.0);
painter->setPen(QColor("#4f4f4f"));
painter->drawLine(option.rect.topLeft(),option.rect.bottomLeft());
painter->restore();
}
void IdItemDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option, const QModelIndex &index) const
{
painter->save();
if (option.state & QStyle::State_Selected)
painter->fillRect(option.rect, option.palette.highlight());
ModelNode node = m_TreeModel->nodeForIndex(index);
// QIcon icon=node.metaInfo().icon();
// if (icon.isNull()) icon = QIcon(":/ItemLibrary/images/default-icon.png");
// QPixmap pixmap = icon.pixmap(option.rect.width(),option.rect.height());
// painter->drawPixmap(option.rect.x()+1,option.rect.y(),pixmap);
QString myString = node.id();
if (myString.isEmpty())
myString = node.simplifiedTypeName();
else
{
QFont font = painter->font();
font.setBold(true);
painter->setFont(font);
}
if (m_TreeModel->isNodeInvisible( index ))
painter->setOpacity(0.5);
// painter->drawText(option.rect.bottomLeft()+QPoint(4+pixmap.width(),-4),myString);
painter->drawText(option.rect.bottomLeft()+QPoint(4,-4),myString);
painter->restore();
}
void NavigatorTreeView::drawRow(QPainter *painter, const QStyleOptionViewItem &options, const QModelIndex &index) const
{
painter->save();
QTreeView::drawRow(painter,options,index);
painter->setPen(QColor("#4f4f4f"));
painter->drawLine(options.rect.bottomLeft(),options.rect.bottomRight());
// painter->drawLine(options.rect.topLeft(),options.rect.topRight());
painter->restore();
}
}
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef NAVIGATORTREEVIEW_H
#define NAVIGATORTREEVIEW_H
#include <QTreeView>
#include <QStyledItemDelegate>
#include <QPainter>
class QTreeView;
class QStandardItem;
class QItemSelection;
class QModelIndex;
namespace QmlDesigner {
class NavigatorWidget;
class NavigatorTreeModel;
class IconCheckboxItemDelegate : public QStyledItemDelegate
{
public:
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 IdItemDelegate : public QStyledItemDelegate
{
public:
IdItemDelegate(QObject *parent=0, NavigatorTreeModel *treeModel=NULL) : QStyledItemDelegate(parent),m_TreeModel(treeModel) {}
void paint(QPainter *painter,
const QStyleOptionViewItem &option, const QModelIndex &index) const;
private:
NavigatorTreeModel *m_TreeModel;
};
class NavigatorTreeView : public QTreeView
{
public:
NavigatorTreeView(QWidget *parent = 0)
: QTreeView(parent)
{
}
protected:
virtual void drawRow(QPainter *painter,
const QStyleOptionViewItem &options,
const QModelIndex &index) const;
};
}
#endif // NAVIGATORTREEVIEW_H
......@@ -32,81 +32,10 @@
#include "navigatorwidget.h"
#include <nodeproperty.h>
#include <QStyledItemDelegate>
#include <QPainter>
namespace QmlDesigner {
class IconCheckboxItemDelegate : public QStyledItemDelegate
{
public:
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 { return QSize(15,17); }
void paint(QPainter *painter,
const QStyleOptionViewItem &option, const QModelIndex &index) const
{
painter->save();
if (option.state & QStyle::State_Selected)
painter->fillRect(option.rect, option.palette.highlight());
bool isChecked= (m_TreeModel->itemFromIndex(index)->checkState() == Qt::Checked);
if (isChecked)
painter->drawPixmap(option.rect.x()+2,option.rect.y()+1,onPix);
else
painter->drawPixmap(option.rect.x()+2,option.rect.y()+1,offPix);
painter->restore();
}
private:
NavigatorTreeModel *m_TreeModel;
QPixmap offPix;
QPixmap onPix;
};
class IdItemDelegate : public QStyledItemDelegate {
public:
IdItemDelegate(QObject *parent=0, NavigatorTreeModel *treeModel=NULL) : QStyledItemDelegate(parent),m_TreeModel(treeModel) {}
void paint(QPainter *painter,
const QStyleOptionViewItem &option, const QModelIndex &index) const
{
painter->save();
if (option.state & QStyle::State_Selected)
painter->fillRect(option.rect, option.palette.highlight());
ModelNode node = m_TreeModel->nodeForIndex(index);
// QIcon icon=node.metaInfo().icon();
// if (icon.isNull()) icon = QIcon(":/ItemLibrary/images/default-icon.png");
// QPixmap pixmap = icon.pixmap(option.rect.width(),option.rect.height());
// painter->drawPixmap(option.rect.x()+1,option.rect.y(),pixmap);
QString myString = node.id();
if (myString.isEmpty())
myString = node.simplifiedTypeName();
else
{
QFont font = painter->font();
font.setBold(true);
painter->setFont(font);
}
// painter->drawText(option.rect.bottomLeft()+QPoint(4+pixmap.width(),-4),myString);
painter->drawText(option.rect.bottomLeft()+QPoint(4,-4),myString);
painter->restore();
}
private:
NavigatorTreeModel *m_TreeModel;
};
NavigatorView::NavigatorView(QObject* parent) :
QmlModelView(parent),
m_blockSelectionChangedSignal(false),
......@@ -120,7 +49,7 @@ NavigatorView::NavigatorView(QObject* parent) :
IdItemDelegate *idDelegate = new IdItemDelegate(this,m_treeModel.data());
IconCheckboxItemDelegate *showDelegate = new IconCheckboxItemDelegate(this,":/qmldesigner/images/eye_open.png",
":/qmldesigner/images/eye_crossed.png",m_treeModel.data());
":/qmldesigner/images/placeholder.png",m_treeModel.data());
#ifdef _LOCK_ITEMS_
IconCheckboxItemDelegate *lockDelegate = new IconCheckboxItemDelegate(this,":/qmldesigner/images/lock.png",
......@@ -220,7 +149,15 @@ void NavigatorView::auxiliaryDataChanged(const ModelNode &node, const QString &n
{
QmlModelView::auxiliaryDataChanged(node, name, data);
if (m_treeModel->isInTree(node))
{
// update model
m_treeModel->updateItemRow(node);
// repaint row (id and icon)
QModelIndex index = m_treeModel->indexForNode(node);
treeWidget()->update( index );
treeWidget()->update( index.sibling(index.row(),index.column()+1) );
}
}
void NavigatorView::nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &node, int oldIndex)
......
......@@ -43,6 +43,8 @@ namespace QmlDesigner {
class NavigatorWidget;
class NavigatorTreeModel;
class IconCheckboxItemDelegate;
class IdItemDelegate;
class NavigatorView : public QmlModelView
{
......
......@@ -40,7 +40,7 @@ namespace QmlDesigner {
NavigatorWidget::NavigatorWidget(QWidget* parent) :
QFrame(parent),
m_treeView(new QTreeView)
m_treeView(new NavigatorTreeView)
{
m_treeView->setDragEnabled(true);
m_treeView->setAcceptDrops(true);
......
......@@ -32,7 +32,8 @@
#include <QFrame>
#include <QAbstractItemModel>
#include <QTreeView>
#include "navigatortreeview.h"
namespace QmlDesigner {
......@@ -49,7 +50,7 @@ public:
QTreeView *treeView();
private:
QTreeView *m_treeView;
NavigatorTreeView *m_treeView;
};
}
......
<RCC>
<qresource prefix="/qmldesigner">
<qresource prefix="/qmldesigner" >
<file>templates/Standard/Form.xml</file>
<file>stylesheet.css</file>
<file>toolbutton.css</file>
......@@ -10,10 +10,10 @@
<file>images/checkbox_unchecked.png</file>
<file>images/checkbox_unchecked_hover.png</file>
<file>images/checkbox_unchecked_pressed.png</file>
<file>images/eye_open.png</file>
<file>images/eye_crossed.png</file>
<file>images/lock.png</file>
<file>images/hole.png</file>
<file>images/eye_open.png</file>
<file>images/eye_crossed.png</file>
<file>images/lock.png</file>
<file>images/hole.png</file>
<file>images/down_arrow.png</file>
<file>images/down_arrow_disabled.png</file>
<file>images/frame.png</file>
......@@ -37,9 +37,12 @@
<file>images/spinup_pressed.png</file>
<file>images/up_arrow.png</file>
<file>images/up_arrow_disabled.png</file>
<file>images/apply.png</file>
<file>images/cancel.png</file>
<file>images/applybright.png</file>
<file>images/cancelbright.png</file>
<file>images/apply.png</file>
<file>images/cancel.png</file>
<file>images/applybright.png</file>
<file>images/cancelbright.png</file>
<file>images/placeholder.png</file>
<file>images/triangle_horz.png</file>
<file>images/triangle_vert.png</file>
</qresource>
</RCC>
......@@ -45,25 +45,52 @@ QLineEdit
background-color: white;
selection-background-color: darkgray;
}
QTreeView {
color: white;
selection-color: white
}
QTreeView::item:selected {
color: white;
}
QTreeView::branch:has-siblings:!adjoins-item {
border-image: none;
image:none;
}
QTreeView::branch:has-siblings:adjoins-item {
border-image: none;
image:none;
}
QTreeView::branch:!has-children:!has-siblings:adjoins-item {
border-image: none;
image:none;
}
QTreeView::branch:has-children:!has-siblings:closed,
QTreeView::branch:closed:has-children:has-siblings {
border-image: none;
image: url(:/qmldesigner/images/triangle_horz.png);
}
QTreeView::branch:open:has-children:!has-siblings,
QTreeView::branch:open:has-children:has-siblings {
border-image: none;
image: url(:/qmldesigner/images/triangle_vert.png);
}
QListView {
color: white;
selection-color: white
}
QListView::item:selected {
color: white;
}
QComboBox QAbstractItemView {
show-decoration-selected: 1; /* make the selection span the entire width of the view */
background-color: #494949; /* sets background of the menu */
......@@ -74,4 +101,3 @@ QLineEdit
selection-color: #404040;
}
\ No newline at end of file
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