Skip to content

Commit

Permalink
Merge branch 'dpi_scaled_configuration' into 'mer-5.6'
Browse files Browse the repository at this point in the history
Dpi scaled configuration

See merge request mer-core/qtdeclarative!24
  • Loading branch information
pvuorela committed Feb 15, 2019
2 parents b63ee00 + ed876ce commit f906aba
Show file tree
Hide file tree
Showing 9 changed files with 323 additions and 239 deletions.
153 changes: 43 additions & 110 deletions src/quick/items/qquickflickable.cpp
Expand Up @@ -47,97 +47,27 @@
#include <QtGui/private/qguiapplication_p.h>
#include <QtGui/qstylehints.h>
#include <QtCore/qmath.h>
#include <QtCore/qsettings.h>
#include "qplatformdefs.h"

QT_BEGIN_NAMESPACE

extern const QSettings &quickSettings();

namespace {

int getFlickThreshold()
{
return quickSettings().value(QStringLiteral("QuickFlickable/FlickThreshold"), 15).toInt();
}

int getFlickOvershoot()
{
return quickSettings().value(QStringLiteral("QuickFlickable/FlickOvershoot"), QML_FLICK_OVERSHOOT).toInt();
}

qreal getFlickOvershootFriction()
{
return quickSettings().value(QStringLiteral("QuickFlickable/FlickOvershootFriction"), QML_FLICK_OVERSHOOTFRICTION).toReal();
}

qreal getFlickDefaultMaxVelocity()
{
return quickSettings().value(QStringLiteral("QuickFlickable/FlickDefaultMaxVelocity"), QML_FLICK_DEFAULTMAXVELOCITY).toReal();
}

qreal getFlickDefaultDeceleration()
{
return quickSettings().value(QStringLiteral("QuickFlickable/FlickDefaultDeceleration"), QML_FLICK_DEFAULTDECELERATION).toReal();
}

int getFlickMultiflickThreshold()
{
return quickSettings().value(QStringLiteral("QuickFlickable/FlickMultiflickThreshold"), QML_FLICK_MULTIFLICK_THRESHOLD).toInt();
}

qreal getFlickMultiflickRatio()
{
return quickSettings().value(QStringLiteral("QuickFlickable/FlickMultiflickRatio"), QML_FLICK_MULTIFLICK_RATIO).toReal();
}

double getFlickMultiflickMaxBoost()
{
return quickSettings().value(QStringLiteral("QuickFlickable/FlickMultiflickMaxBoost"), QML_FLICK_MULTIFLICK_MAXBOOST).toDouble();
}

int getFlickMultiflickDuration()
{
return quickSettings().value(QStringLiteral("QuickFlickable/FlickMultiflickDuration"), 600).toInt();
}

int getFlickMultiflickRapidDuration()
{
return quickSettings().value(QStringLiteral("QuickFlickable/FlickMultiflickRapidDuration"), 300).toInt();
}

qreal getRetainGrabVelocity()
{
return quickSettings().value(QStringLiteral("QuickFlickable/RetainGrabVelocity"), 100).toReal();
}

// FlickThreshold determines how far the "mouse" must have moved
// before we perform a flick.
const int FlickThreshold(getFlickThreshold());

const int FlickOvershoot(getFlickOvershoot());

const qreal FlickOvershootFriction(getFlickOvershootFriction());

const qreal FlickDefaultMaxVelocity(getFlickDefaultMaxVelocity());

const qreal FlickDefaultDeceleration(getFlickDefaultDeceleration());

const int FlickMultiflickThreshold(getFlickMultiflickThreshold());

const qreal FlickMultiflickRatio(getFlickMultiflickRatio());

const double FlickMultiflickMaxBoost(getFlickMultiflickMaxBoost());

const int FlickMultiflickDuration(getFlickMultiflickDuration());

const int FlickMultiflickRapidDuration(getFlickMultiflickRapidDuration());
// Mer: these moved to QuickConf
// static const int FlickThreshold = 15;

// RetainGrabVelocity is the maxmimum instantaneous velocity that
// will ensure the Flickable retains the grab on consecutive flicks.
const qreal RetainGrabVelocity(getRetainGrabVelocity());
//static const int RetainGrabVelocity = 100;

}
// Mer: undefine other constants that should now come from configuration to make sure new additions get migrated too.
#undef QML_FLICK_OVERSHOOT
#undef QML_FLICK_DEFAULTMAXVELOCITY
#undef QML_FLICK_DEFAULTDECELERATION
#undef QML_FLICK_OVERSHOOTFRICTION
#undef QML_FLICK_MULTIFLICK_THRESHOLD
#undef QML_FLICK_MULTIFLICK_RATIO
#undef QML_FLICK_MULTIFLICK_MAXBOOST

#ifdef Q_OS_OSX
static const int MovementEndingTimerInterval = 100;
Expand Down Expand Up @@ -305,8 +235,8 @@ QQuickFlickablePrivate::QQuickFlickablePrivate()
, pixelAligned(false)
, lastPosTime(-1)
, lastPressTime(0)
, deceleration(FlickDefaultDeceleration)
, maxVelocity(FlickDefaultMaxVelocity), reportedVelocitySmoothing(100)
, deceleration(QuickConf::flickDefaultDeceleration())
, maxVelocity(QuickConf::flickDefaultMaxVelocity()), reportedVelocitySmoothing(100)
, delayedPressEvent(0), pressDelay(0), fixupDuration(400)
, flickBoost(1.0), fixupMode(Normal), vTime(0), visibleArea(0)
, flickableDirection(QQuickFlickable::AutoFlickDirection)
Expand Down Expand Up @@ -339,7 +269,7 @@ qreal QQuickFlickablePrivate::overShootDistance(qreal size)
if (maxVelocity <= 0)
return 0.0;

return qMin(qreal(FlickOvershoot), size/3);
return qMin(qreal(QuickConf::flickOvershoot()), size/3);
}

void QQuickFlickablePrivate::AxisData::addVelocitySample(qreal v, qreal maxVelocity)
Expand Down Expand Up @@ -1025,19 +955,19 @@ void QQuickFlickablePrivate::handleMousePressEvent(QMouseEvent *event)
Q_Q(QQuickFlickable);
timer.start();
if (interactive && timeline.isActive()
&& ((qAbs(hData.smoothVelocity.value()) > RetainGrabVelocity && !hData.fixingUp && !hData.inOvershoot)
|| (qAbs(vData.smoothVelocity.value()) > RetainGrabVelocity && !vData.fixingUp && !vData.inOvershoot))) {
&& ((qAbs(hData.smoothVelocity.value()) > QuickConf::flickRetainGrabVelocity() && !hData.fixingUp && !hData.inOvershoot)
|| (qAbs(vData.smoothVelocity.value()) > QuickConf::flickRetainGrabVelocity() && !vData.fixingUp && !vData.inOvershoot))) {
stealMouse = true; // If we've been flicked then steal the click.
int flickTime = timeline.time();
if (flickTime > FlickMultiflickDuration) {
if (flickTime > QuickConf::flickMultiflickDuration()) {
// too long between flicks - cancel boost
hData.continuousFlickVelocity = 0;
vData.continuousFlickVelocity = 0;
flickBoost = 1.0;
} else {
hData.continuousFlickVelocity = -hData.smoothVelocity.value();
vData.continuousFlickVelocity = -vData.smoothVelocity.value();
if (flickTime > FlickMultiflickRapidDuration) // slower flicking - reduce boost
if (flickTime > QuickConf::flickMultiflickRapidDuration()) // slower flicking - reduce boost
flickBoost = qMax(1.0, flickBoost - 0.5);
}
} else {
Expand Down Expand Up @@ -1116,6 +1046,9 @@ void QQuickFlickablePrivate::drag(qint64 currentTimestamp, QEvent::Type eventTyp
bool prevVMoved = vMoved;

qint64 elapsedSincePress = currentTimestamp - lastPressTime;
qreal overshootFriction = QuickConf::flickOvershootFriction();
qreal defaultMaxVelocity = QuickConf::flickDefaultMaxVelocity();
int flickOvershoot = QuickConf::flickOvershoot();

if (q->yflick()) {
qreal dy = deltas.y();
Expand All @@ -1138,11 +1071,11 @@ void QQuickFlickablePrivate::drag(qint64 currentTimestamp, QEvent::Type eventTyp
rejectY |= vData.pressPos == minY && vData.move.value() == minY && dy > 0;
}
} else {
qreal vel = velocity.y() / QML_FLICK_OVERSHOOTFRICTION;
qreal vel = velocity.y() / overshootFriction;
if (vel > 0. && vel > vData.velocity)
vData.velocity = qMin(velocity.y() / QML_FLICK_OVERSHOOTFRICTION, float(QML_FLICK_DEFAULTMAXVELOCITY));
vData.velocity = qMin(velocity.y() / overshootFriction, float(defaultMaxVelocity));
else if (vel < 0. && vel < vData.velocity)
vData.velocity = qMax(velocity.y() / QML_FLICK_OVERSHOOTFRICTION, -float(QML_FLICK_DEFAULTMAXVELOCITY));
vData.velocity = qMax(velocity.y() / overshootFriction, -float(defaultMaxVelocity));
if (newY > minY) {
// Overshoot beyond the top. But don't wait for momentum phase to end before returning to bounds.
if (momentum && vData.atBeginning) {
Expand All @@ -1153,8 +1086,8 @@ void QQuickFlickablePrivate::drag(qint64 currentTimestamp, QEvent::Type eventTyp
return;
}
if (velocitySensitiveOverBounds) {
qreal overshoot = (newY - minY) * vData.velocity / QML_FLICK_DEFAULTMAXVELOCITY / QML_FLICK_OVERSHOOTFRICTION;
overshoot = QML_FLICK_OVERSHOOT * devicePixelRatio() * EaseOvershoot(overshoot / QML_FLICK_OVERSHOOT / devicePixelRatio());
qreal overshoot = (newY - minY) * vData.velocity / defaultMaxVelocity / overshootFriction;
overshoot = flickOvershoot * devicePixelRatio() * EaseOvershoot(overshoot / flickOvershoot / devicePixelRatio());
newY = minY + overshoot;
} else {
newY = minY + (newY - minY) / 2;
Expand All @@ -1169,8 +1102,8 @@ void QQuickFlickablePrivate::drag(qint64 currentTimestamp, QEvent::Type eventTyp
return;
}
if (velocitySensitiveOverBounds) {
qreal overshoot = (newY - maxY) * vData.velocity / QML_FLICK_DEFAULTMAXVELOCITY / QML_FLICK_OVERSHOOTFRICTION;
overshoot = QML_FLICK_OVERSHOOT * devicePixelRatio() * EaseOvershoot(overshoot / QML_FLICK_OVERSHOOT / devicePixelRatio());
qreal overshoot = (newY - maxY) * vData.velocity / defaultMaxVelocity / overshootFriction;
overshoot = flickOvershoot * devicePixelRatio() * EaseOvershoot(overshoot / flickOvershoot / devicePixelRatio());
newY = maxY - overshoot;
} else {
newY = maxY + (newY - maxY) / 2;
Expand Down Expand Up @@ -1211,11 +1144,11 @@ void QQuickFlickablePrivate::drag(qint64 currentTimestamp, QEvent::Type eventTyp
rejectX |= hData.pressPos == minX && hData.move.value() == minX && dx > 0;
}
} else {
qreal vel = velocity.x() / QML_FLICK_OVERSHOOTFRICTION;
qreal vel = velocity.x() / overshootFriction;
if (vel > 0. && vel > hData.velocity)
hData.velocity = qMin(velocity.x() / QML_FLICK_OVERSHOOTFRICTION, float(QML_FLICK_DEFAULTMAXVELOCITY));
hData.velocity = qMin(velocity.x() / overshootFriction, float(defaultMaxVelocity));
else if (vel < 0. && vel < hData.velocity)
hData.velocity = qMax(velocity.x() / QML_FLICK_OVERSHOOTFRICTION, -float(QML_FLICK_DEFAULTMAXVELOCITY));
hData.velocity = qMax(velocity.x() / overshootFriction, -float(defaultMaxVelocity));
if (newX > minX) {
// Overshoot beyond the left. But don't wait for momentum phase to end before returning to bounds.
if (momentum && hData.atBeginning) {
Expand All @@ -1226,8 +1159,8 @@ void QQuickFlickablePrivate::drag(qint64 currentTimestamp, QEvent::Type eventTyp
return;
}
if (velocitySensitiveOverBounds) {
qreal overshoot = (newX - minX) * hData.velocity / QML_FLICK_DEFAULTMAXVELOCITY / QML_FLICK_OVERSHOOTFRICTION;
overshoot = QML_FLICK_OVERSHOOT * devicePixelRatio() * EaseOvershoot(overshoot / QML_FLICK_OVERSHOOT / devicePixelRatio());
qreal overshoot = (newX - minX) * hData.velocity / defaultMaxVelocity / overshootFriction;
overshoot = flickOvershoot * devicePixelRatio() * EaseOvershoot(overshoot / flickOvershoot / devicePixelRatio());
newX = minX + overshoot;
} else {
newX = minX + (newX - minX) / 2;
Expand All @@ -1242,8 +1175,8 @@ void QQuickFlickablePrivate::drag(qint64 currentTimestamp, QEvent::Type eventTyp
return;
}
if (velocitySensitiveOverBounds) {
qreal overshoot = (newX - maxX) * hData.velocity / QML_FLICK_DEFAULTMAXVELOCITY / QML_FLICK_OVERSHOOTFRICTION;
overshoot = QML_FLICK_OVERSHOOT * devicePixelRatio() * EaseOvershoot(overshoot / QML_FLICK_OVERSHOOT / devicePixelRatio());
qreal overshoot = (newX - maxX) * hData.velocity / defaultMaxVelocity / overshootFriction;
overshoot = flickOvershoot * devicePixelRatio() * EaseOvershoot(overshoot / flickOvershoot / devicePixelRatio());
newX = maxX - overshoot;
} else {
newX = maxX + (newX - maxX) / 2;
Expand Down Expand Up @@ -1356,9 +1289,9 @@ void QQuickFlickablePrivate::handleMouseReleaseEvent(QMouseEvent *event)
if ((vData.atBeginning && vVelocity > 0.) || (vData.atEnd && vVelocity < 0.)) {
vVelocity /= 2;
} else if (vData.continuousFlickVelocity != 0.0
&& vData.viewSize/q->height() > FlickMultiflickRatio
&& vData.viewSize/q->height() > QuickConf::flickMultiflickRatio()
&& ((vVelocity > 0) == (vData.continuousFlickVelocity > 0))
&& qAbs(vVelocity) > FlickMultiflickThreshold) {
&& qAbs(vVelocity) > QuickConf::flickMultiflickThreshold()) {
// accelerate flick for large view flicked quickly
canBoost = true;
}
Expand All @@ -1371,18 +1304,18 @@ void QQuickFlickablePrivate::handleMouseReleaseEvent(QMouseEvent *event)
if ((hData.atBeginning && hVelocity > 0.) || (hData.atEnd && hVelocity < 0.)) {
hVelocity /= 2;
} else if (hData.continuousFlickVelocity != 0.0
&& hData.viewSize/q->width() > FlickMultiflickRatio
&& hData.viewSize/q->width() > QuickConf::flickMultiflickRatio()
&& ((hVelocity > 0) == (hData.continuousFlickVelocity > 0))
&& qAbs(hVelocity) > FlickMultiflickThreshold) {
&& qAbs(hVelocity) > QuickConf::flickMultiflickThreshold()) {
// accelerate flick for large view flicked quickly
canBoost = true;
}

flickBoost = canBoost ? qBound(1.0, flickBoost+0.25, FlickMultiflickMaxBoost) : 1.0;
flickBoost = canBoost ? qBound(1.0, flickBoost+0.25, QuickConf::flickMultiflickMaxBoost()) : 1.0;

bool flickedVertically = false;
vVelocity *= flickBoost;
bool isVerticalFlickAllowed = q->yflick() && qAbs(vVelocity) > MinimumFlickVelocity && qAbs(event->localPos().y() - pressPos.y()) > FlickThreshold;
bool isVerticalFlickAllowed = q->yflick() && qAbs(vVelocity) > MinimumFlickVelocity && qAbs(event->localPos().y() - pressPos.y()) > QuickConf::flickThreshold();
if (isVerticalFlickAllowed) {
velocityTimeline.reset(vData.smoothVelocity);
vData.smoothVelocity.setValue(-vVelocity);
Expand All @@ -1391,7 +1324,7 @@ void QQuickFlickablePrivate::handleMouseReleaseEvent(QMouseEvent *event)

bool flickedHorizontally = false;
hVelocity *= flickBoost;
bool isHorizontalFlickAllowed = q->xflick() && qAbs(hVelocity) > MinimumFlickVelocity && qAbs(event->localPos().x() - pressPos.x()) > FlickThreshold;
bool isHorizontalFlickAllowed = q->xflick() && qAbs(hVelocity) > MinimumFlickVelocity && qAbs(event->localPos().x() - pressPos.x()) > QuickConf::flickThreshold();
if (isHorizontalFlickAllowed) {
velocityTimeline.reset(hData.smoothVelocity);
hData.smoothVelocity.setValue(-hVelocity);
Expand Down Expand Up @@ -1730,7 +1663,7 @@ void QQuickFlickablePrivate::viewportAxisMoved(AxisData &data, qreal minExtent,
qreal maxDistance = overShootDistance(vSize) - overBound;
resetTimeline(data);
if (maxDistance > 0)
timeline.accel(data.move, -data.smoothVelocity.value(), deceleration*FlickOvershootFriction, maxDistance);
timeline.accel(data.move, -data.smoothVelocity.value(), deceleration*QuickConf::flickOvershootFriction(), maxDistance);
timeline.callback(QQuickTimeLineCallback(&data.move, fixupCallback, this));
}

Expand Down
18 changes: 2 additions & 16 deletions src/quick/items/qquickgridview.cpp
Expand Up @@ -41,7 +41,6 @@
#include <QtGui/qevent.h>
#include <QtCore/qmath.h>
#include <QtCore/qcoreapplication.h>
#include <QtCore/qsettings.h>
#include "qplatformdefs.h"

#include <cmath>
Expand All @@ -52,19 +51,6 @@ QT_BEGIN_NAMESPACE
#define QML_FLICK_SNAPONETHRESHOLD 30
#endif

extern const QSettings &quickSettings();

namespace {

int getFlickSnapOneThreshold()
{
return quickSettings().value(QStringLiteral("QuickGridView/FlickSnapOneThreshold"), QML_FLICK_SNAPONETHRESHOLD).toInt();
}

const int FlickSnapOneThreshold(getFlickSnapOneThreshold());

}

//----------------------------------------------------------------------------

class FxGridItemSG : public FxViewItem
Expand Down Expand Up @@ -928,9 +914,9 @@ void QQuickGridViewPrivate::fixup(AxisData &data, qreal minExtent, qreal maxExte
// if we've been dragged < rowSize()/2 then bias towards the next row
qreal dist = data.move.value() - (data.pressPos - data.dragStartOffset);
qreal bias = 0;
if (data.velocity > 0 && dist > FlickSnapOneThreshold && dist < rowSize()/2)
if (data.velocity > 0 && dist > QuickConf::gridViewSnapOneThreshold() && dist < rowSize()/2)
bias = rowSize()/2;
else if (data.velocity < 0 && dist < -FlickSnapOneThreshold && dist > -rowSize()/2)
else if (data.velocity < 0 && dist < -QuickConf::gridViewSnapOneThreshold() && dist > -rowSize()/2)
bias = -rowSize()/2;
if (isContentFlowReversed())
bias = -bias;
Expand Down
25 changes: 2 additions & 23 deletions src/quick/items/qquickitemview.cpp
Expand Up @@ -34,7 +34,6 @@
#include "qquickitemview_p_p.h"
#include <QtQuick/private/qquicktransition_p.h>
#include <QtQml/QQmlInfo>
#include <QtCore/QSettings>
#include "qplatformdefs.h"

QT_BEGIN_NAMESPACE
Expand All @@ -46,26 +45,6 @@ Q_LOGGING_CATEGORY(lcItemViewDelegateLifecycle, "qt.quick.itemview.lifecycle")
#define QML_VIEW_DEFAULTCACHEBUFFER 320
#endif

extern const QSettings &quickSettings();

namespace {

int getDefaultCacheBuffer()
{
return quickSettings().value(QStringLiteral("QuickItemView/DefaultCacheBuffer"), QML_VIEW_DEFAULTCACHEBUFFER).toInt();
}

int getDefaultHighlightMoveDuration()
{
return quickSettings().value(QStringLiteral("QuickItemView/DefaultHighlightMoveDuration"), 150).toInt();
}

const int DefaultCacheBuffer(getDefaultCacheBuffer());

const int DefaultHighlightMoveDuration(getDefaultHighlightMoveDuration());

}

FxViewItem::FxViewItem(QQuickItem *i, QQuickItemView *v, bool own, QQuickItemViewAttached *attached)
: item(i)
, view(v)
Expand Down Expand Up @@ -1532,7 +1511,7 @@ void QQuickItemView::componentComplete()

QQuickItemViewPrivate::QQuickItemViewPrivate()
: itemCount(0)
, buffer(DefaultCacheBuffer), bufferMode(BufferBefore | BufferAfter)
, buffer(QuickConf::itemViewDefaultCacheBuffer()), bufferMode(BufferBefore | BufferAfter)
, displayMarginBeginning(0), displayMarginEnd(0)
, layoutDirection(Qt::LeftToRight), verticalLayoutDirection(QQuickItemView::TopToBottom)
, moveReason(Other)
Expand All @@ -1542,7 +1521,7 @@ QQuickItemViewPrivate::QQuickItemViewPrivate()
, highlightComponent(0), highlight(0)
, highlightRange(QQuickItemView::NoHighlightRange)
, highlightRangeStart(0), highlightRangeEnd(0)
, highlightMoveDuration(DefaultHighlightMoveDuration)
, highlightMoveDuration(QuickConf::itemViewDefaultHighlightMoveDuration())
, headerComponent(0), header(0), footerComponent(0), footer(0)
, transitioner(0)
, minExtent(0), maxExtent(0)
Expand Down

0 comments on commit f906aba

Please sign in to comment.