forked from qt-creator/qt-creator
QmlInspector: changed crumblepath appearance
Reviewed-by: Kai Koehne
This commit is contained in:
@@ -37,11 +37,14 @@
|
|||||||
#include <QtCore/QList>
|
#include <QtCore/QList>
|
||||||
#include <QtGui/QHBoxLayout>
|
#include <QtGui/QHBoxLayout>
|
||||||
#include <QtGui/QPushButton>
|
#include <QtGui/QPushButton>
|
||||||
|
#include <QtGui/QMenu>
|
||||||
#include <QtGui/QStyle>
|
#include <QtGui/QStyle>
|
||||||
#include <QtGui/QResizeEvent>
|
#include <QtGui/QResizeEvent>
|
||||||
#include <QtGui/QPainter>
|
#include <QtGui/QPainter>
|
||||||
#include <QtGui/QImage>
|
#include <QtGui/QImage>
|
||||||
|
|
||||||
|
#include <qtcassert.h>
|
||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
||||||
static const int ArrowBorderSize = 12;
|
static const int ArrowBorderSize = 12;
|
||||||
@@ -82,6 +85,7 @@ private:
|
|||||||
QImage m_segmentSelectedEnd;
|
QImage m_segmentSelectedEnd;
|
||||||
QImage m_segmentHover;
|
QImage m_segmentHover;
|
||||||
QImage m_segmentHoverEnd;
|
QImage m_segmentHoverEnd;
|
||||||
|
QImage m_triangleIcon;
|
||||||
QPoint m_textPos;
|
QPoint m_textPos;
|
||||||
|
|
||||||
QVariant m_data;
|
QVariant m_data;
|
||||||
@@ -105,6 +109,7 @@ CrumblePathButton::CrumblePathButton(const QString &title, QWidget *parent)
|
|||||||
m_segmentEnd = QImage(":/utils/images/crumblepath-segment-end.png");
|
m_segmentEnd = QImage(":/utils/images/crumblepath-segment-end.png");
|
||||||
m_segmentSelectedEnd = QImage(":/utils/images/crumblepath-segment-selected-end.png");
|
m_segmentSelectedEnd = QImage(":/utils/images/crumblepath-segment-selected-end.png");
|
||||||
m_segmentHoverEnd = QImage(":/utils/images/crumblepath-segment-hover-end.png");
|
m_segmentHoverEnd = QImage(":/utils/images/crumblepath-segment-hover-end.png");
|
||||||
|
m_triangleIcon = QImage(":/utils/images/triangle_vert.png");
|
||||||
|
|
||||||
tintImages();
|
tintImages();
|
||||||
}
|
}
|
||||||
@@ -141,6 +146,10 @@ void CrumblePathButton::paintEvent(QPaintEvent *)
|
|||||||
QString textToDraw = fm.elidedText(text(), Qt::ElideRight, geom.width() - m_textPos.x());
|
QString textToDraw = fm.elidedText(text(), Qt::ElideRight, geom.width() - m_textPos.x());
|
||||||
|
|
||||||
p.drawText(QRectF(m_textPos.x(), 4, geom.width(), geom.height()), textToDraw);
|
p.drawText(QRectF(m_textPos.x(), 4, geom.width(), geom.height()), textToDraw);
|
||||||
|
|
||||||
|
if (menu()) {
|
||||||
|
p.drawImage(geom.width() - m_triangleIcon.width() - 6, geom.center().y() - m_triangleIcon.height()/2, m_triangleIcon);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CrumblePathButton::tintImages()
|
void CrumblePathButton::tintImages()
|
||||||
@@ -204,6 +213,8 @@ QVariant CrumblePathButton::data() const
|
|||||||
return m_data;
|
return m_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
struct CrumblePathPrivate {
|
struct CrumblePathPrivate {
|
||||||
explicit CrumblePathPrivate(CrumblePath *q);
|
explicit CrumblePathPrivate(CrumblePath *q);
|
||||||
|
|
||||||
@@ -261,7 +272,6 @@ void CrumblePath::pushElement(const QString &title, const QVariant data)
|
|||||||
CrumblePathButton *newButton = new CrumblePathButton(title, this);
|
CrumblePathButton *newButton = new CrumblePathButton(title, this);
|
||||||
newButton->hide();
|
newButton->hide();
|
||||||
connect(newButton, SIGNAL(clicked()), SLOT(mapClickToIndex()));
|
connect(newButton, SIGNAL(clicked()), SLOT(mapClickToIndex()));
|
||||||
connect(newButton, SIGNAL(customContextMenuRequested(QPoint)), SLOT(mapContextMenuRequestToIndex()));
|
|
||||||
|
|
||||||
int segType = CrumblePathButton::MiddleSegment;
|
int segType = CrumblePathButton::MiddleSegment;
|
||||||
if (!d->m_buttons.isEmpty()) {
|
if (!d->m_buttons.isEmpty()) {
|
||||||
@@ -278,6 +288,23 @@ void CrumblePath::pushElement(const QString &title, const QVariant data)
|
|||||||
resizeButtons();
|
resizeButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CrumblePath::addChild(const QString &title, const QVariant data)
|
||||||
|
{
|
||||||
|
QTC_ASSERT(d->m_buttons.count()>0,return);
|
||||||
|
|
||||||
|
QPushButton *lastButton = d->m_buttons.last();
|
||||||
|
|
||||||
|
QMenu *childList = lastButton->menu();
|
||||||
|
if (childList == 0)
|
||||||
|
childList = new QMenu(lastButton);
|
||||||
|
|
||||||
|
QAction *childAction = new QAction(title, lastButton);
|
||||||
|
childAction->setData(data);
|
||||||
|
connect(childAction, SIGNAL(triggered()), this, SLOT(mapClickToIndex()));
|
||||||
|
childList->addAction(childAction);
|
||||||
|
lastButton->setMenu(childList);
|
||||||
|
}
|
||||||
|
|
||||||
void CrumblePath::popElement()
|
void CrumblePath::popElement()
|
||||||
{
|
{
|
||||||
QWidget *last = d->m_buttons.last();
|
QWidget *last = d->m_buttons.last();
|
||||||
@@ -358,22 +385,11 @@ void CrumblePath::resizeButtons()
|
|||||||
void CrumblePath::mapClickToIndex()
|
void CrumblePath::mapClickToIndex()
|
||||||
{
|
{
|
||||||
QObject *element = sender();
|
QObject *element = sender();
|
||||||
for (int i = 0; i < d->m_buttons.length(); ++i) {
|
if (QString("QAction") == element->metaObject()->className()) {
|
||||||
if (d->m_buttons[i] == element) {
|
emit elementClicked(static_cast<QAction *>(element)->data().toInt());
|
||||||
emit elementClicked(i);
|
} else
|
||||||
return;
|
if (QString("QPushButton") == element->metaObject()->className()) {
|
||||||
}
|
emit elementClicked(static_cast<CrumblePathButton *>(element)->data().toInt());
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CrumblePath::mapContextMenuRequestToIndex()
|
|
||||||
{
|
|
||||||
QObject *element = sender();
|
|
||||||
for (int i = 0; i < d->m_buttons.length(); ++i) {
|
|
||||||
if (d->m_buttons[i] == element) {
|
|
||||||
emit elementContextMenuRequested(i);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,12 +56,12 @@ public:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void pushElement(const QString &title, const QVariant data = QVariant());
|
void pushElement(const QString &title, const QVariant data = QVariant());
|
||||||
|
void addChild(const QString &title, const QVariant data = QVariant());
|
||||||
void popElement();
|
void popElement();
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void elementClicked(int index);
|
void elementClicked(int debugId);
|
||||||
void elementContextMenuRequested(int index);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent(QResizeEvent *);
|
void resizeEvent(QResizeEvent *);
|
||||||
@@ -69,7 +69,6 @@ protected:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void mapClickToIndex();
|
void mapClickToIndex();
|
||||||
void mapContextMenuRequestToIndex();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void resizeButtons();
|
void resizeButtons();
|
||||||
|
|||||||
BIN
src/libs/utils/images/triangle_vert.png
Normal file
BIN
src/libs/utils/images/triangle_vert.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 216 B |
@@ -8,5 +8,6 @@
|
|||||||
<file>images/crumblepath-segment-hover.png</file>
|
<file>images/crumblepath-segment-hover.png</file>
|
||||||
<file>images/crumblepath-segment-selected-end.png</file>
|
<file>images/crumblepath-segment-selected-end.png</file>
|
||||||
<file>images/crumblepath-segment-selected.png</file>
|
<file>images/crumblepath-segment-selected.png</file>
|
||||||
|
<file>images/triangle_vert.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|||||||
@@ -56,19 +56,22 @@ void ContextCrumblePath::updateContextPath(const QStringList &path, const QList<
|
|||||||
|
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
for (int i=0; i<path.count(); i++) {
|
|
||||||
pushElement(path[i],QVariant(debugIds[i]));
|
|
||||||
}
|
|
||||||
|
|
||||||
m_isEmpty = path.isEmpty();
|
m_isEmpty = path.isEmpty();
|
||||||
if (m_isEmpty) {
|
if (m_isEmpty) {
|
||||||
pushElement(tr("[no context]"));
|
pushElement(tr("[no context]"));
|
||||||
|
} else {
|
||||||
|
for (int i=0; i<path.count(); i++) {
|
||||||
|
pushElement(path[i],QVariant(debugIds[i]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContextCrumblePath::selectIndex(int index)
|
void ContextCrumblePath::addChildren(const QStringList &childrenNames, const QList<int> &childrenDebugIds)
|
||||||
{
|
{
|
||||||
CrumblePath::selectIndex(index);
|
Q_ASSERT(childrenNames.count() == childrenDebugIds.count());
|
||||||
|
for (int i=0; i<childrenNames.count(); i++) {
|
||||||
|
addChild(childrenNames[i],QVariant(childrenDebugIds[i]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ContextCrumblePath::isEmpty() const
|
bool ContextCrumblePath::isEmpty() const
|
||||||
|
|||||||
@@ -50,7 +50,8 @@ public:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateContextPath(const QStringList &path, const QList<int> &debugIds);
|
void updateContextPath(const QStringList &path, const QList<int> &debugIds);
|
||||||
void selectIndex(int index);
|
void addChildren(const QStringList &childrenNames, const QList<int> &childrenDebugIds);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_isEmpty;
|
bool m_isEmpty;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -576,7 +576,9 @@ void InspectorUi::populateCrumblePath(const QDeclarativeDebugObjectReference &ob
|
|||||||
crumbleStrings.push_front( displayName(ref) );
|
crumbleStrings.push_front( displayName(ref) );
|
||||||
}
|
}
|
||||||
|
|
||||||
int itemIndex = crumbleData.length()-1;
|
m_crumblePath->updateContextPath(crumbleStrings, crumbleData);
|
||||||
|
crumbleStrings.clear();
|
||||||
|
crumbleData.clear();
|
||||||
|
|
||||||
// now append the children
|
// now append the children
|
||||||
foreach (const QDeclarativeDebugObjectReference &child, objRef.children()) {
|
foreach (const QDeclarativeDebugObjectReference &child, objRef.children()) {
|
||||||
@@ -584,8 +586,7 @@ void InspectorUi::populateCrumblePath(const QDeclarativeDebugObjectReference &ob
|
|||||||
crumbleStrings.push_back( displayName(child) );
|
crumbleStrings.push_back( displayName(child) );
|
||||||
}
|
}
|
||||||
|
|
||||||
m_crumblePath->updateContextPath(crumbleStrings, crumbleData);
|
m_crumblePath->addChildren(crumbleStrings, crumbleData);
|
||||||
m_crumblePath->selectIndex(itemIndex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InspectorUi::selectItems(const QList<int> &objectIds)
|
void InspectorUi::selectItems(const QList<int> &objectIds)
|
||||||
@@ -710,8 +711,9 @@ void InspectorUi::setupDockWidgets()
|
|||||||
wlay->setSpacing(0);
|
wlay->setSpacing(0);
|
||||||
observerWidget->setLayout(wlay);
|
observerWidget->setLayout(wlay);
|
||||||
wlay->addWidget(m_toolBar->widget());
|
wlay->addWidget(m_toolBar->widget());
|
||||||
wlay->addWidget(m_propertyInspector);
|
|
||||||
wlay->addWidget(m_crumblePath);
|
wlay->addWidget(m_crumblePath);
|
||||||
|
wlay->addWidget(m_propertyInspector);
|
||||||
|
|
||||||
|
|
||||||
Debugger::DebuggerMainWindow *mw = Debugger::DebuggerPlugin::mainWindow();
|
Debugger::DebuggerMainWindow *mw = Debugger::DebuggerPlugin::mainWindow();
|
||||||
QDockWidget *dock = mw->createDockWidget(Debugger::QmlLanguage, observerWidget);
|
QDockWidget *dock = mw->createDockWidget(Debugger::QmlLanguage, observerWidget);
|
||||||
@@ -719,10 +721,10 @@ void InspectorUi::setupDockWidgets()
|
|||||||
dock->setTitleBarWidget(new QWidget(dock));
|
dock->setTitleBarWidget(new QWidget(dock));
|
||||||
}
|
}
|
||||||
|
|
||||||
void InspectorUi::crumblePathElementClicked(int pathIndex)
|
void InspectorUi::crumblePathElementClicked(int debugId)
|
||||||
{
|
{
|
||||||
QList <int> l;
|
QList <int> l;
|
||||||
l << m_crumblePath->debugIdForIndex(pathIndex);
|
l << debugId;
|
||||||
selectItems(l);
|
selectItems(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user