forked from qt-creator/qt-creator
QmlDesigner.navigator: New and cleaner look
This commit is contained in:
@@ -45,9 +45,11 @@ NavigatorTreeModel::NavigatorTreeModel(QObject *parent)
|
|||||||
{
|
{
|
||||||
invisibleRootItem()->setFlags(Qt::NoItemFlags);
|
invisibleRootItem()->setFlags(Qt::NoItemFlags);
|
||||||
|
|
||||||
setHorizontalHeaderItem(0, new QStandardItem(tr("Name")));
|
#ifdef _LOCK_ITEMS_
|
||||||
setHorizontalHeaderItem(1, new QStandardItem(tr("Type")));
|
setColumnCount(3);
|
||||||
setHorizontalHeaderItem(2, new QStandardItem(tr("Show in Editor")));
|
#else
|
||||||
|
setColumnCount(2);
|
||||||
|
#endif
|
||||||
|
|
||||||
setSupportedDragActions(Qt::LinkAction);
|
setSupportedDragActions(Qt::LinkAction);
|
||||||
|
|
||||||
@@ -189,11 +191,14 @@ NavigatorTreeModel::ItemRow NavigatorTreeModel::createItemRow(const ModelNode &n
|
|||||||
idItem->setEditable(true);
|
idItem->setEditable(true);
|
||||||
idItem->setData(hash, Qt::UserRole);
|
idItem->setData(hash, Qt::UserRole);
|
||||||
|
|
||||||
QStandardItem *typeItem = new QStandardItem;
|
#ifdef _LOCK_ITEMS_
|
||||||
typeItem->setDragEnabled(true);
|
QStandardItem *lockItem = new QStandardItem;
|
||||||
idItem->setDropEnabled(node.metaInfo().isContainer());
|
lockItem->setDragEnabled(true);
|
||||||
typeItem->setEditable(false);
|
lockItem->setDropEnabled(node.metaInfo().isContainer());
|
||||||
typeItem->setData(hash, Qt::UserRole);
|
lockItem->setEditable(false);
|
||||||
|
lockItem->setCheckable(true);
|
||||||
|
lockItem->setData(hash, Qt::UserRole);
|
||||||
|
#endif
|
||||||
|
|
||||||
QStandardItem *visibilityItem = new QStandardItem;
|
QStandardItem *visibilityItem = new QStandardItem;
|
||||||
visibilityItem->setDropEnabled(node.metaInfo().isContainer());
|
visibilityItem->setDropEnabled(node.metaInfo().isContainer());
|
||||||
@@ -201,7 +206,11 @@ NavigatorTreeModel::ItemRow NavigatorTreeModel::createItemRow(const ModelNode &n
|
|||||||
visibilityItem->setEditable(false);
|
visibilityItem->setEditable(false);
|
||||||
visibilityItem->setData(hash, Qt::UserRole);
|
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)
|
void NavigatorTreeModel::updateItemRow(const ModelNode &node, ItemRow items)
|
||||||
@@ -209,7 +218,7 @@ void NavigatorTreeModel::updateItemRow(const ModelNode &node, ItemRow items)
|
|||||||
bool blockSignal = blockItemChangedSignal(true);
|
bool blockSignal = blockItemChangedSignal(true);
|
||||||
|
|
||||||
items.idItem->setText(node.id());
|
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);
|
items.visibilityItem->setCheckState(node.auxiliaryData("invisible").toBool() ? Qt::Unchecked : Qt::Checked);
|
||||||
|
|
||||||
blockItemChangedSignal(blockSignal);
|
blockItemChangedSignal(blockSignal);
|
||||||
|
|||||||
@@ -46,20 +46,36 @@ class NavigatorTreeModel : public QStandardItemModel
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
#ifdef _LOCK_ITEMS_
|
||||||
struct ItemRow {
|
struct ItemRow {
|
||||||
ItemRow()
|
ItemRow()
|
||||||
: idItem(0), typeItem(0), visibilityItem(0) {}
|
: idItem(0), lockItem(0), visibilityItem(0) {}
|
||||||
ItemRow(QStandardItem *id, QStandardItem *type, QStandardItem *visibility)
|
ItemRow(QStandardItem *id, QStandardItem *lock, QStandardItem *visibility)
|
||||||
: idItem(id), typeItem(type), visibilityItem(visibility) {}
|
: idItem(id), lockItem(lock), visibilityItem(visibility) {}
|
||||||
|
|
||||||
QList<QStandardItem*> toList() const {
|
QList<QStandardItem*> toList() const {
|
||||||
return QList<QStandardItem*>() << idItem << typeItem << visibilityItem;
|
return QList<QStandardItem*>() << idItem << lockItem << visibilityItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStandardItem *idItem;
|
QStandardItem *idItem;
|
||||||
QStandardItem *typeItem;
|
QStandardItem *lockItem;
|
||||||
QStandardItem *visibilityItem;
|
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:
|
public:
|
||||||
NavigatorTreeModel(QObject *parent = 0);
|
NavigatorTreeModel(QObject *parent = 0);
|
||||||
|
|||||||
@@ -32,10 +32,80 @@
|
|||||||
#include "navigatorwidget.h"
|
#include "navigatorwidget.h"
|
||||||
|
|
||||||
#include <nodeproperty.h>
|
#include <nodeproperty.h>
|
||||||
|
#include <QStyledItemDelegate>
|
||||||
|
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
namespace QmlDesigner {
|
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) :
|
NavigatorView::NavigatorView(QObject* parent) :
|
||||||
QmlModelView(parent),
|
QmlModelView(parent),
|
||||||
m_blockSelectionChangedSignal(false),
|
m_blockSelectionChangedSignal(false),
|
||||||
@@ -46,6 +116,25 @@ NavigatorView::NavigatorView(QObject* parent) :
|
|||||||
|
|
||||||
connect(treeWidget()->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(changeSelection(QItemSelection,QItemSelection)));
|
connect(treeWidget()->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(changeSelection(QItemSelection,QItemSelection)));
|
||||||
treeWidget()->setIndentation(treeWidget()->indentation() * 0.5);
|
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()
|
NavigatorView::~NavigatorView()
|
||||||
|
|||||||
@@ -79,6 +79,11 @@ void NavigatorWidget::setTreeModel(QAbstractItemModel* model)
|
|||||||
{
|
{
|
||||||
m_treeView->setModel(model);
|
m_treeView->setModel(model);
|
||||||
m_treeView->header()->setResizeMode(0, QHeaderView::Stretch);
|
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()
|
QTreeView *NavigatorWidget::treeView()
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 715 B |
BIN
src/plugins/qmldesigner/components/resources/images/eye_open.png
Normal file
BIN
src/plugins/qmldesigner/components/resources/images/eye_open.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 587 B |
BIN
src/plugins/qmldesigner/components/resources/images/hole.png
Normal file
BIN
src/plugins/qmldesigner/components/resources/images/hole.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 288 B |
BIN
src/plugins/qmldesigner/components/resources/images/lock.png
Normal file
BIN
src/plugins/qmldesigner/components/resources/images/lock.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 562 B |
@@ -10,6 +10,10 @@
|
|||||||
<file>images/checkbox_unchecked.png</file>
|
<file>images/checkbox_unchecked.png</file>
|
||||||
<file>images/checkbox_unchecked_hover.png</file>
|
<file>images/checkbox_unchecked_hover.png</file>
|
||||||
<file>images/checkbox_unchecked_pressed.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.png</file>
|
||||||
<file>images/down_arrow_disabled.png</file>
|
<file>images/down_arrow_disabled.png</file>
|
||||||
<file>images/frame.png</file>
|
<file>images/frame.png</file>
|
||||||
|
|||||||
Reference in New Issue
Block a user