Commit 31311a4d authored by Marco Bubke's avatar Marco Bubke
Browse files

QmlDesigner.NodeInstances: Show stripes for items without content

Change-Id: I6c737616d485445d77efd8b6d73b2d8259e5120b
Reviewed-on: http://codereview.qt.nokia.com/4288


Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@nokia.com>
Reviewed-by: default avatarQt Sanity Bot <qt_sanity_bot@ovi.com>
parent 9837dadb
......@@ -53,7 +53,7 @@
namespace QmlDesigner {
QPixmap FormEditorItem::s_invisibleItemPixmap = QPixmap();
FormEditorScene *FormEditorItem::scene() const {
return qobject_cast<FormEditorScene*>(QGraphicsItem::scene());
......@@ -242,6 +242,7 @@ void FormEditorItem::paintBoundingRect(QPainter *painter) const
QPen pen;
pen.setJoinStyle(Qt::MiterJoin);
pen.setStyle(Qt::DotLine);
switch(scene()->paintMode()) {
case FormEditorScene::AnchorMode: {
......@@ -280,8 +281,55 @@ void FormEditorItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *,
painter->save();
if (isContentVisible())
if (qmlItemNode().instanceIsRenderPixmapNull()) {
if (scene()->showBoundingRects()) {
if (s_invisibleItemPixmap.isNull()) {
QImage invisibleItemImage(14, 14, QImage::Format_ARGB32_Premultiplied);
invisibleItemImage.fill(0xFF999999);
QPainter fillPainter(&invisibleItemImage);
fillPainter.setCompositionMode(QPainter::CompositionMode_Source);
fillPainter.rotate(-45);
fillPainter.translate(-10, 0);
fillPainter.fillRect(0, -4, 20, 7, QColor(100, 100, 100, 0));
fillPainter.translate(0, 10);
fillPainter.fillRect(0, -4, 20, 7, QColor(100, 100, 100, 0));
fillPainter.translate(0, 9);
fillPainter.fillRect(0, -3, 20, 6, QColor(100, 100, 100, 0));
s_invisibleItemPixmap = QPixmap::fromImage(invisibleItemImage);
}
painter->drawTiledPixmap(boundingRect(), s_invisibleItemPixmap);
QString displayText = qmlItemNode().id();
if (displayText.isEmpty())
displayText = qmlItemNode().simplifiedTypeName();
QTextOption textOption;
textOption.setAlignment(Qt::AlignCenter);
textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
painter->save();
QFont font;
font.setPixelSize(18);
painter->setFont(font);
painter->drawText(boundingRect(), displayText, textOption);
painter->restore();
}
} else {
qmlItemNode().paintInstance(painter);
}
if (!qmlItemNode().isRootModelNode())
paintBoundingRect(painter);
......
......@@ -133,6 +133,7 @@ private: // variables
bool m_highlightBoundingRect;
bool m_isContentVisible;
bool m_isFormEditorVisible;
static QPixmap s_invisibleItemPixmap;
};
......
......@@ -285,6 +285,12 @@ FormEditorWidget *FormEditorView::widget() const
void FormEditorView::nodeIdChanged(const ModelNode& node, const QString& newId, const QString& oldId)
{
QmlModelView::nodeIdChanged(node, newId, oldId);
QmlItemNode itemNode(node);
if (itemNode.isValid()) {
FormEditorItem *item = m_scene->itemForQmlItemNode(itemNode);
item->update();
}
}
void FormEditorView::selectedNodesChanged(const QList<ModelNode> &selectedNodeList,
......
......@@ -112,7 +112,7 @@ FormEditorWidget::FormEditorWidget(FormEditorView *view)
addAction(separatorAction);
upperActions.append(separatorAction);
m_showBoundingRectAction = new QAction(tr("Show bounding rectangles (A)"), this);
m_showBoundingRectAction = new QAction(tr("Show bounding rectangles and stripes for empty items (Press Key A)"), this);
m_showBoundingRectAction->setShortcut(Qt::Key_A);
m_showBoundingRectAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
m_showBoundingRectAction->setCheckable(true);
......
......@@ -83,6 +83,8 @@ public:
qint32 parentId() const;
qint32 instanceId() const;
QPixmap renderPixmap() const;
protected:
void setProperty(const QString &name, const QVariant &value);
InformationName setInformation(InformationName name,
......@@ -108,7 +110,7 @@ protected:
InformationName setInformationHasBindingForProperty(const QString &property, bool hasProperty);
void setParentId(qint32 instanceId);
void setRenderImage(const QImage &image);
void setRenderPixmap(const QImage &image);
NodeInstance(ProxyNodeInstanceData *d);
private:
......
......@@ -84,6 +84,7 @@ public:
QPointF instancePosition() const;
QSizeF instanceSize() const;
int instancePenWidth() const;
bool instanceIsRenderPixmapNull() const;
void paintInstance(QPainter *painter);
......
......@@ -75,7 +75,7 @@ public:
QHash<QString, bool> hasAnchors;
QHash<QString, QString> instanceTypes;
QImage renderImage;
QPixmap renderPixmap;
QHash<QString, QPair<QString, qint32> > anchors;
};
......@@ -249,8 +249,8 @@ int NodeInstance::penWidth() const
void NodeInstance::paint(QPainter *painter)
{
if (isValid() && !d->renderImage.isNull())
painter->drawImage(boundingRect().topLeft(), d->renderImage);
if (isValid() && !d->renderPixmap.isNull())
painter->drawPixmap(boundingRect().topLeft(), d->renderPixmap);
}
QVariant NodeInstance::property(const QString &name) const
......@@ -307,9 +307,15 @@ void NodeInstance::setProperty(const QString &name, const QVariant &value)
d->propertyValues.insert(name, value);
}
void NodeInstance::setRenderImage(const QImage &image)
QPixmap NodeInstance::renderPixmap() const
{
d->renderImage = image;
return d->renderPixmap;
}
void NodeInstance::setRenderPixmap(const QImage &image)
{
if (!image.isNull())
d->renderPixmap = QPixmap::fromImage(image);
}
void NodeInstance::setParentId(qint32 instanceId)
......
......@@ -1069,7 +1069,7 @@ void NodeInstanceView::pixmapChanged(const PixmapChangedCommand &command)
if (hasInstanceForId(container.instanceId())) {
NodeInstance instance = instanceForId(container.instanceId());
if (instance.isValid()) {
instance.setRenderImage(container.image());
instance.setRenderPixmap(container.image());
renderImageChangeSet.insert(instance.modelNode());
}
}
......
......@@ -270,6 +270,11 @@ int QmlItemNode::instancePenWidth() const
return nodeInstance().penWidth();
}
bool QmlItemNode::instanceIsRenderPixmapNull() const
{
return nodeInstance().renderPixmap().isNull();
}
void QmlItemNode::paintInstance(QPainter *painter)
{
if (nodeInstance().isValid())
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment