Skip to content
Snippets Groups Projects
Commit ddf360d4 authored by Thomas Hartmann's avatar Thomas Hartmann
Browse files

QMlDesigner.navigator: visualize unknown types

Types unknown to the metasystem get the red line now and a questionmark icon.
parent 9092d2da
No related branches found
No related tags found
No related merge requests found
src/plugins/qmldesigner/components/itemlibrary/images/item-default-icon.png

590 B | W: | H:

src/plugins/qmldesigner/components/itemlibrary/images/item-default-icon.png

317 B | W: | H:

src/plugins/qmldesigner/components/itemlibrary/images/item-default-icon.png
src/plugins/qmldesigner/components/itemlibrary/images/item-default-icon.png
src/plugins/qmldesigner/components/itemlibrary/images/item-default-icon.png
src/plugins/qmldesigner/components/itemlibrary/images/item-default-icon.png
  • 2-up
  • Swipe
  • Onion skin
src/plugins/qmldesigner/components/itemlibrary/images/item-invalid-icon.png

603 B

......@@ -8,6 +8,7 @@
<file>qml/Selector.qml</file>
<file>images/item-default-icon.png</file>
<file>images/item-invalid-icon.png</file>
</qresource>
</RCC>
......@@ -189,6 +189,10 @@ NavigatorTreeModel::ItemRow NavigatorTreeModel::createItemRow(const ModelNode &n
idItem->setDropEnabled(dropEnabled);
idItem->setEditable(true);
idItem->setData(hash, NavigatorRole);
if (node.metaInfo().isValid())
idItem->setToolTip(node.type());
else
idItem->setToolTip(tr("unkown item: ") + node.type());
# ifdef _LOCK_ITEMS_
QStandardItem *lockItem = new QStandardItem;
......@@ -233,6 +237,10 @@ void NavigatorTreeModel::updateItemRow(const ModelNode &node, ItemRow items)
items.idItem->setText(node.id());
items.visibilityItem->setCheckState(node.auxiliaryData("invisible").toBool() ? Qt::Unchecked : Qt::Checked);
if (node.metaInfo().isValid())
items.idItem->setToolTip(node.type());
else
items.idItem->setToolTip(tr("unkown item: ") + node.type());
blockItemChangedSignal(blockSignal);
}
......
......@@ -29,6 +29,8 @@
#include "navigatortreeview.h"
#include <qmath.h>
#include "navigatorview.h"
#include "navigatortreemodel.h"
#include "navigatorwidget.h"
......@@ -37,6 +39,58 @@
#include <nodeproperty.h>
#include "metainfo.h"
#include <QLineEdit>
#include <QPen>
#include <QPixmapCache>
static QPixmap generateWavyPixmap(qreal maxRadius, const QPen &pen)
{
const qreal radiusBase = qMax(qreal(1), maxRadius);
QString key = QLatin1String("WaveUnderline-Bauhaus");
QPixmap pixmap;
if (QPixmapCache::find(key, pixmap))
return pixmap;
const qreal halfPeriod = qMax(qreal(2), qreal(radiusBase * 1.61803399)); // the golden ratio
const int width = qCeil(100 / (2 * halfPeriod)) * (2 * halfPeriod);
const int radius = qFloor(radiusBase);
QPainterPath path;
qreal xs = 0;
qreal ys = radius;
while (xs < width) {
xs += halfPeriod;
ys = -ys;
path.quadTo(xs - halfPeriod / 2, ys, xs, 0);
}
pixmap = QPixmap(width, radius * 2);
pixmap.fill(Qt::transparent);
{
QPen wavePen = pen;
wavePen.setCapStyle(Qt::SquareCap);
// This is to protect against making the line too fat, as happens on Mac OS X
// due to it having a rather thick width for the regular underline.
const qreal maxPenWidth = .8 * radius;
if (wavePen.widthF() > maxPenWidth)
wavePen.setWidth(maxPenWidth);
QPainter imgPainter(&pixmap);
imgPainter.setPen(wavePen);
imgPainter.setRenderHint(QPainter::Antialiasing);
imgPainter.translate(0, radius);
imgPainter.drawPath(path);
}
QPixmapCache::insert(key, pixmap);
return pixmap;
}
namespace QmlDesigner {
......@@ -169,7 +223,8 @@ void NameItemDelegate::paint(QPainter *painter,
QPoint displayStringOffset;
painter->save();
QFontMetrics fm(option.font);
int width;
if (index.data(Qt::UserRole).isValid()) {
int pixmapSide = 16;
......@@ -196,6 +251,8 @@ void NameItemDelegate::paint(QPainter *painter,
// if the library was also empty, use the default icon
if (icon.isNull())
icon = QIcon(QLatin1String(":/ItemLibrary/images/item-default-icon.png"));
if (!node.metaInfo().isValid())
icon = QIcon(QLatin1String(":/ItemLibrary/images/item-invalid-icon.png"));
// If no icon is present, leave an empty space of 24 pixels anyway
QPixmap pixmap = icon.pixmap(pixmapSide, pixmapSide);
......@@ -207,16 +264,33 @@ void NameItemDelegate::paint(QPainter *painter,
// Check text length does not exceed available space
int extraSpace=12+pixmapSide;
QFontMetrics fm(option.font);
displayString = fm.elidedText(displayString,Qt::ElideMiddle,option.rect.width()-extraSpace);
displayStringOffset = QPoint(5+pixmapSide,-5);
width = fm.width(displayString);
}
else {
displayString = index.data(Qt::DisplayRole).toString();
displayStringOffset = QPoint(0, -2);
}
painter->drawText(option.rect.bottomLeft()+displayStringOffset,displayString);
QPoint pos = option.rect.bottomLeft() + displayStringOffset;
painter->drawText(pos, displayString);
ModelNode node = m_TreeModel->nodeForIndex(index);
if (!node.isValid() ||!node.metaInfo().isValid()) {
painter->translate(0, pos.y() + 1);
QPen pen;
pen.setColor(Qt::red);
const qreal underlineOffset = fm.underlinePos();
const QPixmap wave = generateWavyPixmap(qMax(underlineOffset, pen.widthF()), pen);
const int descent = fm.descent();
painter->setBrushOrigin(painter->brushOrigin().x(), 0);
painter->fillRect(pos.x(), 0, qCeil(width), qMin(wave.height(), descent), wave);
}
painter->restore();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment