QmlDesigner.navigator: New and cleaner look

This commit is contained in:
Christiaan Janssen
2010-01-29 12:10:08 +01:00
parent c35f7bbfcb
commit 913410c66a
9 changed files with 138 additions and 15 deletions

View File

@@ -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()