Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Tobias Hunger
qt-creator
Commits
913410c6
Commit
913410c6
authored
Jan 29, 2010
by
Christiaan Janssen
Browse files
QmlDesigner.navigator: New and cleaner look
parent
c35f7bbf
Changes
9
Hide whitespace changes
Inline
Side-by-side
src/plugins/qmldesigner/components/navigator/navigatortreemodel.cpp
View file @
913410c6
...
...
@@ -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
.
type
Item
->
setT
ext
(
node
.
simplifiedTypeName
());
items
.
id
Item
->
setT
oolTip
(
!
node
.
id
().
isEmpty
()
?
node
.
simplifiedTypeName
()
:
""
);
items
.
visibilityItem
->
setCheckState
(
node
.
auxiliaryData
(
"invisible"
).
toBool
()
?
Qt
::
Unchecked
:
Qt
::
Checked
);
blockItemChangedSignal
(
blockSignal
);
...
...
src/plugins/qmldesigner/components/navigator/navigatortreemodel.h
View file @
913410c6
...
...
@@ -46,20 +46,36 @@ class NavigatorTreeModel : public QStandardItemModel
{
Q_OBJECT
#ifdef _LOCK_ITEMS_
struct
ItemRow
{
ItemRow
()
:
idItem
(
0
),
type
Item
(
0
),
visibilityItem
(
0
)
{}
ItemRow
(
QStandardItem
*
id
,
QStandardItem
*
type
,
QStandardItem
*
visibility
)
:
idItem
(
id
),
type
Item
(
type
),
visibilityItem
(
visibility
)
{}
:
idItem
(
0
),
lock
Item
(
0
),
visibilityItem
(
0
)
{}
ItemRow
(
QStandardItem
*
id
,
QStandardItem
*
lock
,
QStandardItem
*
visibility
)
:
idItem
(
id
),
lock
Item
(
lock
),
visibilityItem
(
visibility
)
{}
QList
<
QStandardItem
*>
toList
()
const
{
return
QList
<
QStandardItem
*>
()
<<
idItem
<<
type
Item
<<
visibilityItem
;
return
QList
<
QStandardItem
*>
()
<<
idItem
<<
lock
Item
<<
visibilityItem
;
}
QStandardItem
*
idItem
;
QStandardItem
*
type
Item
;
QStandardItem
*
lock
Item
;
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
);
...
...
src/plugins/qmldesigner/components/navigator/navigatorview.cpp
View file @
913410c6
...
...
@@ -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
()
...
...
src/plugins/qmldesigner/components/navigator/navigatorwidget.cpp
View file @
913410c6
...
...
@@ -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
()
...
...
src/plugins/qmldesigner/components/resources/images/eye_crossed.png
0 → 100644
View file @
913410c6
715 Bytes
src/plugins/qmldesigner/components/resources/images/eye_open.png
0 → 100644
View file @
913410c6
587 Bytes
src/plugins/qmldesigner/components/resources/images/hole.png
0 → 100644
View file @
913410c6
288 Bytes
src/plugins/qmldesigner/components/resources/images/lock.png
0 → 100644
View file @
913410c6
562 Bytes
src/plugins/qmldesigner/components/resources/resources.qrc
View file @
913410c6
...
...
@@ -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>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment