Commit 913410c6 authored by Christiaan Janssen's avatar Christiaan Janssen

QmlDesigner.navigator: New and cleaner look

parent c35f7bbf
......@@ -45,9 +45,11 @@ NavigatorTreeModel::NavigatorTreeModel(QObject *parent)
{
invisibleRootItem()->setFlags(Qt::NoItemFlags);
setHorizontalHeaderItem(0, new QStandardItem(tr("Name")));
setHorizontalHeaderItem(1, new QStandardItem(tr("Type")));
setHorizontalHeaderItem(2, new QStandardItem(tr("Show in Editor")));
#ifdef _LOCK_ITEMS_
setColumnCount(3);
#else
setColumnCount(2);
#endif
setSupportedDragActions(Qt::LinkAction);
......@@ -189,11 +191,14 @@ NavigatorTreeModel::ItemRow NavigatorTreeModel::createItemRow(const ModelNode &n
idItem->setEditable(true);
idItem->setData(hash, Qt::UserRole);
QStandardItem *typeItem = new QStandardItem;
typeItem->setDragEnabled(true);
idItem->setDropEnabled(node.metaInfo().isContainer());
typeItem->setEditable(false);
typeItem->setData(hash, Qt::UserRole);
#ifdef _LOCK_ITEMS_
QStandardItem *lockItem = new QStandardItem;
lockItem->setDragEnabled(true);
lockItem->setDropEnabled(node.metaInfo().isContainer());
lockItem->setEditable(false);
lockItem->setCheckable(true);
lockItem->setData(hash, Qt::UserRole);
#endif
QStandardItem *visibilityItem = new QStandardItem;
visibilityItem->setDropEnabled(node.metaInfo().isContainer());
......@@ -201,7 +206,11 @@ NavigatorTreeModel::ItemRow NavigatorTreeModel::createItemRow(const ModelNode &n
visibilityItem->setEditable(false);
visibilityItem->setData(hash, Qt::UserRole);
return ItemRow(idItem, typeItem, visibilityItem);
#ifdef _LOCK_ITEMS_
return ItemRow(idItem, lockItem, visibilityItem);
#else
return ItemRow(idItem, visibilityItem);
#endif
}
void NavigatorTreeModel::updateItemRow(const ModelNode &node, ItemRow items)
......@@ -209,7 +218,7 @@ void NavigatorTreeModel::updateItemRow(const ModelNode &node, ItemRow items)
bool blockSignal = blockItemChangedSignal(true);
items.idItem->setText(node.id());
items.typeItem->setText(node.simplifiedTypeName());
items.idItem->setToolTip(!node.id().isEmpty()?node.simplifiedTypeName():"");
items.visibilityItem->setCheckState(node.auxiliaryData("invisible").toBool() ? Qt::Unchecked : Qt::Checked);
blockItemChangedSignal(blockSignal);
......
......@@ -46,20 +46,36 @@ class NavigatorTreeModel : public QStandardItemModel
{
Q_OBJECT
#ifdef _LOCK_ITEMS_
struct ItemRow {
ItemRow()
: idItem(0), typeItem(0), visibilityItem(0) {}
ItemRow(QStandardItem *id, QStandardItem *type, QStandardItem *visibility)
: idItem(id), typeItem(type), visibilityItem(visibility) {}
: idItem(0), lockItem(0), visibilityItem(0) {}
ItemRow(QStandardItem *id, QStandardItem *lock, QStandardItem *visibility)
: idItem(id), lockItem(lock), visibilityItem(visibility) {}
QList<QStandardItem*> toList() const {
return QList<QStandardItem*>() << idItem << typeItem << visibilityItem;
return QList<QStandardItem*>() << idItem << lockItem << visibilityItem;
}
QStandardItem *idItem;
QStandardItem *typeItem;
QStandardItem *lockItem;
QStandardItem *visibilityItem;
};
#else
struct ItemRow {
ItemRow()
: idItem(0), visibilityItem(0) {}
ItemRow(QStandardItem *id, QStandardItem *visibility)
: idItem(id), visibilityItem(visibility) {}
QList<QStandardItem*> toList() const {
return QList<QStandardItem*>() << idItem << visibilityItem;
}
QStandardItem *idItem;
QStandardItem *visibilityItem;
};
#endif
public:
NavigatorTreeModel(QObject *parent = 0);
......
......@@ -32,10 +32,80 @@
#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(),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,-4),myString);
painter->restore();
}
private:
NavigatorTreeModel *m_TreeModel;
};
NavigatorView::NavigatorView(QObject* parent) :
QmlModelView(parent),
m_blockSelectionChangedSignal(false),
......@@ -46,6 +116,25 @@ NavigatorView::NavigatorView(QObject* parent) :
connect(treeWidget()->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(changeSelection(QItemSelection,QItemSelection)));
treeWidget()->setIndentation(treeWidget()->indentation() * 0.5);
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());
#ifdef _LOCK_ITEMS_
IconCheckboxItemDelegate *lockDelegate = new IconCheckboxItemDelegate(this,":/qmldesigner/images/lock.png",
":/qmldesigner/images/hole.png",m_treeModel.data());
#endif
treeWidget()->setItemDelegateForColumn(0,idDelegate);
#ifdef _LOCK_ITEMS_
treeWidget()->setItemDelegateForColumn(1,lockDelegate);
treeWidget()->setItemDelegateForColumn(2,showDelegate);
#else
treeWidget()->setItemDelegateForColumn(1,showDelegate);
#endif
}
NavigatorView::~NavigatorView()
......
......@@ -79,6 +79,11 @@ void NavigatorWidget::setTreeModel(QAbstractItemModel* model)
{
m_treeView->setModel(model);
m_treeView->header()->setResizeMode(0, QHeaderView::Stretch);
m_treeView->header()->resizeSection(1,20);
#ifdef _LOCK_ITEMS_
m_treeView->header()->resizeSection(2,20);
#endif
m_treeView->setHeaderHidden(true);
}
QTreeView *NavigatorWidget::treeView()
......
......@@ -10,6 +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/down_arrow.png</file>
<file>images/down_arrow_disabled.png</file>
<file>images/frame.png</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