~bzoltan/kubuntu-packaging/decouple_cmake_plugin

« back to all changes in this revision

Viewing changes to src/plugins/qmldesigner/components/formeditor/formeditoritem.cpp

  • Committer: Timo Jyrinki
  • Date: 2013-11-15 12:25:23 UTC
  • mfrom: (1.1.28)
  • Revision ID: timo.jyrinki@canonical.com-20131115122523-i2kyamsu4gs2mu1m
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#include "formeditorscene.h"
32
32
 
33
33
#include <modelnode.h>
34
 
 
 
34
#include <nodemetainfo.h>
35
35
 
36
36
#include <QDebug>
37
37
#include <QPainter>
40
40
 
41
41
#include <cmath>
42
42
 
43
 
 
44
43
namespace QmlDesigner {
45
44
 
46
45
 
54
53
    m_qmlItemNode(qmlItemNode),
55
54
    m_borderWidth(1.0),
56
55
    m_highlightBoundingRect(false),
 
56
    m_blurContent(false),
57
57
    m_isContentVisible(true),
58
58
    m_isFormEditorVisible(true)
59
59
{
92
92
    m_boundingRect = qmlItemNode().instanceBoundingRect().adjusted(0, 0, 1., 1.);
93
93
    m_paintedBoundingRect = qmlItemNode().instancePaintedBoundingRect().united(m_boundingRect);
94
94
    setTransform(qmlItemNode().instanceTransformWithContentTransform());
95
 
    setTransform(m_attentionTransform, true);
96
95
    //the property for zValue is called z in QGraphicsObject
97
96
    if (qmlItemNode().instanceValue("z").isValid())
98
97
        setZValue(qmlItemNode().instanceValue("z").toDouble());
104
103
//    setOpacity(nodeInstance().opacity());
105
104
}
106
105
 
107
 
void FormEditorItem::showAttention()
108
 
{
109
 
    if (m_attentionTimeLine.isNull()) {
110
 
        m_attentionTimeLine = new QTimeLine(500, this);
111
 
        m_attentionTimeLine->setCurveShape(QTimeLine::SineCurve);
112
 
        connect(m_attentionTimeLine.data(), SIGNAL(valueChanged(qreal)), SLOT(changeAttention(qreal)));
113
 
        connect(m_attentionTimeLine.data(), SIGNAL(finished()), m_attentionTimeLine.data(), SLOT(deleteLater()));
114
 
 
115
 
        m_attentionTimeLine->start();
116
 
    }
117
 
}
118
 
 
119
 
void FormEditorItem::changeAttention(qreal value)
120
 
{
121
 
    if (QGraphicsItem::parentItem() == scene()->formLayerItem()) {
122
 
        setAttentionHighlight(value);
123
 
    } else {
124
 
        setAttentionHighlight(value);
125
 
        setAttentionScale(value);
126
 
    }
127
 
}
128
106
 
129
107
FormEditorView *FormEditorItem::formEditorView() const
130
108
{
131
109
    return scene()->editorView();
132
110
}
133
111
 
134
 
void FormEditorItem::setAttentionScale(double sinusScale)
135
 
{
136
 
    if (!qFuzzyIsNull(sinusScale)) {
137
 
        double scale = std::sqrt(sinusScale);
138
 
        m_attentionTransform.reset();
139
 
        QPointF centerPoint(qmlItemNode().instanceBoundingRect().center());
140
 
        m_attentionTransform.translate(centerPoint.x(), centerPoint.y());
141
 
        m_attentionTransform.scale(scale * 0.15 + 1.0, scale * 0.15 + 1.0);
142
 
        m_attentionTransform.translate(-centerPoint.x(), -centerPoint.y());
143
 
        m_inverseAttentionTransform = m_attentionTransform.inverted();
144
 
        prepareGeometryChange();
145
 
        setTransform(qmlItemNode().instanceTransformWithContentTransform());
146
 
        setTransform(m_attentionTransform, true);
147
 
    } else {
148
 
        m_attentionTransform.reset();
149
 
        prepareGeometryChange();
150
 
        setTransform(qmlItemNode().instanceTransform());
151
 
    }
152
 
}
153
 
 
154
 
void FormEditorItem::setAttentionHighlight(double value)
155
 
{
156
 
    if (QGraphicsItem::parentItem() == scene()->formLayerItem())
157
 
        m_borderWidth = value * 4;
158
 
    else
159
 
        m_borderWidth = 1. + value * 3;
160
 
 
161
 
    update();
162
 
}
163
 
 
164
112
void FormEditorItem::setHighlightBoundingRect(bool highlight)
165
113
{
166
114
    if (m_highlightBoundingRect != highlight) {
169
117
    }
170
118
}
171
119
 
 
120
void FormEditorItem::blurContent(bool blurContent)
 
121
{
 
122
    if (m_blurContent != blurContent) {
 
123
        m_blurContent = blurContent;
 
124
        update();
 
125
    }
 
126
}
 
127
 
172
128
void FormEditorItem::setContentVisible(bool visible)
173
129
{
174
130
    if (visible == m_isContentVisible)
235
191
 
236
192
    QPen pen;
237
193
    pen.setJoinStyle(Qt::MiterJoin);
238
 
    pen.setStyle(Qt::DotLine);
239
194
 
240
195
    QColor frameColor("#AAAAAA");
241
196
 
242
197
    if (scene()->showBoundingRects()) {
243
 
        if (m_highlightBoundingRect)
 
198
        if (m_highlightBoundingRect) {
244
199
            pen.setColor(frameColor);
245
 
        else
 
200
        } else {
246
201
            pen.setColor(frameColor.darker(150));
 
202
            pen.setStyle(Qt::DotLine);
 
203
        }
247
204
    } else {
248
 
        if (m_highlightBoundingRect)
 
205
        if (m_highlightBoundingRect) {
249
206
            pen.setColor(frameColor);
250
 
        else
 
207
        } else {
251
208
            pen.setColor(Qt::transparent);
 
209
            pen.setStyle(Qt::DotLine);
 
210
        }
252
211
    }
253
212
 
254
213
    painter->setPen(pen);
308
267
    }
309
268
}
310
269
 
 
270
void FormEditorItem::paintComponentContentVisualisation(QPainter *painter, const QRectF &clippinRectangle) const
 
271
{
 
272
    painter->setBrush(QColor(0, 0, 0, 150));
 
273
    painter->fillRect(clippinRectangle, Qt::BDiagPattern);
 
274
}
311
275
 
312
276
void FormEditorItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
313
277
{
323
287
        if (scene()->showBoundingRects() && m_boundingRect.width() > 15 && m_boundingRect.height() > 15)
324
288
            paintPlaceHolderForInvisbleItem(painter);
325
289
    } else {
326
 
        qmlItemNode().paintInstance(painter);
 
290
        if (m_blurContent)
 
291
            painter->drawPixmap(boundingRect().topLeft(), qmlItemNode().instanceBlurredRenderPixmap());
 
292
        else
 
293
            painter->drawPixmap(boundingRect().topLeft(), qmlItemNode().instanceRenderPixmap());
327
294
    }
328
295
 
329
296
    if (!qmlItemNode().isRootModelNode())
330
297
        paintBoundingRect(painter);
331
298
 
 
299
//    if (qmlItemNode().modelNode().metaInfo().isSubclassOf("QtQuick.Loader", -1, -1))
 
300
//        paintComponentContentVisualisation(painter, boundingRect());
 
301
 
332
302
    painter->restore();
333
303
}
334
304
 
410
380
 
411
381
bool FormEditorItem::isContainer() const
412
382
{
 
383
    NodeMetaInfo nodeMetaInfo = qmlItemNode().modelNode().metaInfo();
 
384
 
 
385
    if (nodeMetaInfo.isValid())
 
386
        return !nodeMetaInfo.defaultPropertyIsComponent();
 
387
 
413
388
    return true;
414
389
}
415
390