Skip to content

Commit

Permalink
[qtdeclarative] Allow configuration to scale with dpi. Contributes to…
Browse files Browse the repository at this point in the history
… JB#43710

On runtime the active dpi is compared to "General/BaseDPI" on
QtQuick2.conf file to multiply configuration items value marked as
scalable. That is done by having configuration item name appended with
"Scaled", e.g.
[QuickFlickable]
FlickThresholdScaled=15

On MouseArea the old, not anymore used, configuration for press and
hold timeout was removed.

This commit can be squashed with earlier configuration support commit
when rebased to newer Qt releasese:
"Allow QtQuick2 parameters to be configured".
  • Loading branch information
pvuorela committed Jan 11, 2019
1 parent b63ee00 commit 7b129e0
Show file tree
Hide file tree
Showing 9 changed files with 298 additions and 225 deletions.
114 changes: 18 additions & 96 deletions src/quick/items/qquickflickable.cpp
Expand Up @@ -47,97 +47,19 @@
#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;

}

#ifdef Q_OS_OSX
static const int MovementEndingTimerInterval = 100;
Expand Down Expand Up @@ -305,8 +227,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 +261,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 +947,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 @@ -1356,9 +1278,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 +1293,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 +1313,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 +1652,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
34 changes: 3 additions & 31 deletions src/quick/items/qquicklistview.cpp
Expand Up @@ -41,7 +41,6 @@
#include <QtGui/qevent.h>
#include <QtCore/qcoreapplication.h>
#include <QtCore/qmath.h>
#include <QtCore/qsettings.h>

#include <private/qquicksmoothedanimation_p_p.h>
#include "qplatformdefs.h"
Expand All @@ -52,33 +51,6 @@ QT_BEGIN_NAMESPACE
#define QML_FLICK_SNAPONETHRESHOLD 30
#endif

extern const QSettings &quickSettings();

namespace {

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

qreal getDefaultHighlightMoveVelocity()
{
return quickSettings().value(QStringLiteral("QuickListView/DefaultHighlightMoveVelocity"), 400.0).toReal();
}

qreal getDefaultHighlightResizeVelocity()
{
return quickSettings().value(QStringLiteral("QuickListView/DefaultHighlightResizeVelocity"), 400.0).toReal();
}

const int FlickSnapOneThreshold(getFlickSnapOneThreshold());

const qreal DefaultHighlightMoveVelocity(getDefaultHighlightMoveVelocity());

const qreal DefaultHighlightResizeVelocity(getDefaultHighlightResizeVelocity());

}

class FxListItemSG;

class QQuickListViewPrivate : public QQuickItemViewPrivate
Expand Down Expand Up @@ -198,7 +170,7 @@ class QQuickListViewPrivate : public QQuickItemViewPrivate
, headerPositioning(QQuickListView::InlineHeader)
, footerPositioning(QQuickListView::InlineFooter)
, highlightPosAnimator(0), highlightWidthAnimator(0), highlightHeightAnimator(0)
, highlightMoveVelocity(DefaultHighlightMoveVelocity), highlightResizeVelocity(DefaultHighlightResizeVelocity), highlightResizeDuration(-1)
, highlightMoveVelocity(QuickConf::listViewDefaultHighlightMoveVelocity()), highlightResizeVelocity(QuickConf::listViewDefaultHighlightResizeVelocity()), highlightResizeDuration(-1)
, sectionCriteria(0), currentSectionItem(0), nextSectionItem(0)
, overshootDist(0.0), correctFlick(false), inFlickCorrection(false)
{
Expand Down Expand Up @@ -1500,9 +1472,9 @@ void QQuickListViewPrivate::fixup(AxisData &data, qreal minExtent, qreal maxExte
// if we've been dragged < averageSize/2 then bias towards the next item
qreal dist = data.move.value() - (data.pressPos - data.dragStartOffset);
qreal bias = 0;
if (data.velocity > 0 && dist > FlickSnapOneThreshold && dist < averageSize/2)
if (data.velocity > 0 && dist > QuickConf::listViewSnapOneThreshold() && dist < averageSize/2)
bias = averageSize/2;
else if (data.velocity < 0 && dist < -FlickSnapOneThreshold && dist > -averageSize/2)
else if (data.velocity < 0 && dist < -QuickConf::listViewSnapOneThreshold() && dist > -averageSize/2)
bias = -averageSize/2;
if (isContentFlowReversed())
bias = -bias;
Expand Down
14 changes: 0 additions & 14 deletions src/quick/items/qquickmousearea.cpp
Expand Up @@ -42,27 +42,13 @@
#include <QtGui/private/qguiapplication_p.h>
#include <QtGui/qevent.h>
#include <QtGui/qstylehints.h>
#include <QtCore/qsettings.h>

#include <float.h>

QT_BEGIN_NAMESPACE

DEFINE_BOOL_CONFIG_OPTION(qmlVisualTouchDebugging, QML_VISUAL_TOUCH_DEBUGGING)

extern const QSettings &quickSettings();

namespace {

int getPressAndHoldDelay()
{
return quickSettings().value(QStringLiteral("QuickMouseArea/PressAndHoldDelay"), 800).toInt();
}

const int PressAndHoldDelay(getPressAndHoldDelay());

}

QQuickMouseAreaPrivate::QQuickMouseAreaPrivate()
: enabled(true), scrollGestureEnabled(true), hovered(false), longPress(false),
moved(false), stealMouse(false), doubleClick(false), preventStealing(false),
Expand Down

0 comments on commit 7b129e0

Please sign in to comment.