~bpierre/ubuntu-ui-toolkit/gallery-section

« back to all changes in this revision

Viewing changes to src/Ubuntu/Components/plugin/ucabstractbutton.cpp

  • Committer: Pierre Bertet
  • Date: 2016-03-15 18:23:19 UTC
  • mfrom: (1867.2.27 staging)
  • Revision ID: pierre.bertet@canonical.com-20160315182319-9czda7bqthy60nhh
[sync] merge staging

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#define MIN_SENSING_WIDTH_GU    4
27
27
#define MIN_SENSING_HEIGHT_GU   4
28
28
 
 
29
//#define SENSING_DEBUG
 
30
 
29
31
UCAbstractButtonPrivate::UCAbstractButtonPrivate()
30
32
    : UCActionItemPrivate()
31
33
    , mouseArea(new QQuickMouseArea)
137
139
    QQuickAnchors *anchors = QQuickItemPrivate::get(d->mouseArea)->anchors();
138
140
    anchors->setFill(this);
139
141
    d->mouseArea->setHoverEnabled(true);
 
142
 
 
143
#ifdef SENSING_DEBUG
 
144
    // keep this code for visual debugging purposes to track sensing area changes
 
145
    QQmlComponent component(qmlEngine(this));
 
146
    QString data = "import QtQuick 2.4; Rectangle { anchors.fill: parent; color: '#19b6ee'; opacity: 0.3 }";
 
147
    component.setData(data.toLocal8Bit(), QUrl());
 
148
    if (component.isError()) {
 
149
        qDebug() << "ERROR" << component.errorString();
 
150
    } else {
 
151
        QQuickItem *item = qobject_cast<QQuickItem*>(component.beginCreate(qmlContext(this)));
 
152
        if (item) {
 
153
            item->setParent(d->mouseArea);
 
154
            item->setParentItem(d->mouseArea);
 
155
            component.completeCreate();
 
156
        }
 
157
    }
 
158
#endif
140
159
}
141
160
 
142
161
void UCAbstractButtonPrivate::completeComponentInitialization()
234
253
        // the horizontal size is still smaller than the minimum
235
254
        mouseAreaAnchors->setLeftMargin(-(hDelta / 2 + (sensingMargins ? sensingMargins->left() : 0.0)));
236
255
        mouseAreaAnchors->setRightMargin(-(hDelta / 2 + (sensingMargins ? sensingMargins->right() : 0.0)));
237
 
    } else if (sensingMargins) {
238
 
        mouseAreaAnchors->setLeftMargin(-sensingMargins->left());
239
 
        mouseAreaAnchors->setRightMargin(-sensingMargins->right());
 
256
    } else {
 
257
        mouseAreaAnchors->setLeftMargin(sensingMargins ? -sensingMargins->left() : 0.0);
 
258
        mouseAreaAnchors->setRightMargin(sensingMargins ? -sensingMargins->right() : 0.0);
240
259
    }
241
260
    if (vDelta >= 0) {
242
261
        // the vertical size is still smaller than the minimum
243
262
        mouseAreaAnchors->setTopMargin(-(vDelta / 2 + (sensingMargins ? sensingMargins->top() : 0.0)));
244
263
        mouseAreaAnchors->setBottomMargin(-(vDelta / 2 + (sensingMargins ? sensingMargins->bottom() : 0.0)));
245
 
    } else if (sensingMargins) {
246
 
        mouseAreaAnchors->setTopMargin(-sensingMargins->top());
247
 
        mouseAreaAnchors->setBottomMargin(-sensingMargins->bottom());
 
264
    } else {
 
265
        mouseAreaAnchors->setTopMargin(sensingMargins ? -sensingMargins->top() : 0.0);
 
266
        mouseAreaAnchors->setBottomMargin(sensingMargins ? -sensingMargins->bottom() : 0.0);
248
267
    }
249
268
}
250
269