Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[qtdeclarative] Allow QtQuick2 parameters to be configured. Contribut…
…es to MER#1361

Configuration via QtProject/QtQuick2.conf (system settings only)

The default behavior is equivalent to the following configuration settings:

[QuickMouseArea]
PressAndHoldDelay=800

[QuickFlickable]
FlickThreshold=15
FlickOvershoot=150
FlickOvershootFriction=8.0
FlickDefaultMaxVelocity=2500.0
FlickDefaultDeceleration=1500.0
FlickMultiflickThreshold=1250.0
FlickMultiflickRatio=10.0
FlickMultiflickMaxBoost=3.0
FlickMultiflickDuration=600
FlickMultiflickRapidDuration=300
RetainGrabVelocity=100

[QuickItemView]
DefaultCacheBuffer=320
DefaultHighlightMoveDuration=150

[QuickListView]
FlickSnapOneThreshold=30
DefaultHighlightMoveVelocity=400.0
DefaultHighlightResizeVelocity=400.0

[QuickGridView]
FlickSnapOneThreshold=30

[QuickPathView]
FlickDefaultDeceleration=100.0
MinimumFlickVelocity=75.0
DefaultHighlightMoveDuration=300
  • Loading branch information
matthewvogt committed Oct 16, 2015
1 parent 277b8cf commit 42c15a3
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 24 deletions.
106 changes: 93 additions & 13 deletions src/quick/items/qquickflickable.cpp
Expand Up @@ -55,17 +55,97 @@
#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.
static const int FlickThreshold = 15;
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());

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

}

QQuickFlickableVisibleArea::QQuickFlickableVisibleArea(QQuickFlickable *parent)
: QObject(parent), flickable(parent), m_xPosition(0.), m_widthRatio(0.)
Expand Down Expand Up @@ -224,8 +304,8 @@ QQuickFlickablePrivate::QQuickFlickablePrivate()
, pixelAligned(false), replayingPressEvent(false)
, lastPosTime(-1)
, lastPressTime(0)
, deceleration(QML_FLICK_DEFAULTDECELERATION)
, maxVelocity(QML_FLICK_DEFAULTMAXVELOCITY), reportedVelocitySmoothing(100)
, deceleration(FlickDefaultDeceleration)
, maxVelocity(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 @@ -256,7 +336,7 @@ qreal QQuickFlickablePrivate::overShootDistance(qreal size)
if (maxVelocity <= 0)
return 0.0;

return qMin(qreal(QML_FLICK_OVERSHOOT), size/3);
return qMin(qreal(FlickOvershoot), size/3);
}

void QQuickFlickablePrivate::AxisData::addVelocitySample(qreal v, qreal maxVelocity)
Expand Down Expand Up @@ -930,15 +1010,15 @@ void QQuickFlickablePrivate::handleMousePressEvent(QMouseEvent *event)
|| (qAbs(vData.smoothVelocity.value()) > RetainGrabVelocity && !vData.fixingUp && !vData.inOvershoot))) {
stealMouse = true; // If we've been flicked then steal the click.
int flickTime = timeline.time();
if (flickTime > 600) {
if (flickTime > 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 > 300) // slower flicking - reduce boost
if (flickTime > FlickMultiflickRapidDuration) // slower flicking - reduce boost
flickBoost = qMax(1.0, flickBoost - 0.5);
}
} else {
Expand Down Expand Up @@ -1164,9 +1244,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() > QML_FLICK_MULTIFLICK_RATIO
&& vData.viewSize/q->height() > FlickMultiflickRatio
&& ((vVelocity > 0) == (vData.continuousFlickVelocity > 0))
&& qAbs(vVelocity) > QML_FLICK_MULTIFLICK_THRESHOLD) {
&& qAbs(vVelocity) > FlickMultiflickThreshold) {
// accelerate flick for large view flicked quickly
canBoost = true;
}
Expand All @@ -1179,14 +1259,14 @@ 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() > QML_FLICK_MULTIFLICK_RATIO
&& hData.viewSize/q->width() > FlickMultiflickRatio
&& ((hVelocity > 0) == (hData.continuousFlickVelocity > 0))
&& qAbs(hVelocity) > QML_FLICK_MULTIFLICK_THRESHOLD) {
&& qAbs(hVelocity) > FlickMultiflickThreshold) {
// accelerate flick for large view flicked quickly
canBoost = true;
}

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

bool flickedVertically = false;
vVelocity *= flickBoost;
Expand Down Expand Up @@ -1488,7 +1568,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*QML_FLICK_OVERSHOOTFRICTION, maxDistance);
timeline.accel(data.move, -data.smoothVelocity.value(), deceleration*FlickOvershootFriction, maxDistance);
timeline.callback(QQuickTimeLineCallback(&data.move, fixupCallback, this));
}

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

Expand All @@ -60,6 +61,19 @@ QT_BEGIN_NAMESPACE

//#define DEBUG_DELEGATE_LIFECYCLE

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 @@ -934,9 +948,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 > QML_FLICK_SNAPONETHRESHOLD && dist < rowSize()/2)
if (data.velocity > 0 && dist > FlickSnapOneThreshold && dist < rowSize()/2)
bias = rowSize()/2;
else if (data.velocity < 0 && dist < -QML_FLICK_SNAPONETHRESHOLD && dist > -rowSize()/2)
else if (data.velocity < 0 && dist < -FlickSnapOneThreshold && dist > -rowSize()/2)
bias = -rowSize()/2;
if (isContentFlowReversed())
bias = -bias;
Expand Down
25 changes: 23 additions & 2 deletions src/quick/items/qquickitemview.cpp
Expand Up @@ -42,6 +42,7 @@
#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 @@ -51,6 +52,26 @@ QT_BEGIN_NAMESPACE
#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)
: item(i)
, view(v)
Expand Down Expand Up @@ -1478,7 +1499,7 @@ void QQuickItemView::componentComplete()

QQuickItemViewPrivate::QQuickItemViewPrivate()
: itemCount(0)
, buffer(QML_VIEW_DEFAULTCACHEBUFFER), bufferMode(BufferBefore | BufferAfter)
, buffer(DefaultCacheBuffer), bufferMode(BufferBefore | BufferAfter)
, displayMarginBeginning(0), displayMarginEnd(0)
, layoutDirection(Qt::LeftToRight), verticalLayoutDirection(QQuickItemView::TopToBottom)
, moveReason(Other)
Expand All @@ -1488,7 +1509,7 @@ QQuickItemViewPrivate::QQuickItemViewPrivate()
, highlightComponent(0), highlight(0)
, highlightRange(QQuickItemView::NoHighlightRange)
, highlightRangeStart(0), highlightRangeEnd(0)
, highlightMoveDuration(150)
, highlightMoveDuration(DefaultHighlightMoveDuration)
, headerComponent(0), header(0), footerComponent(0), footer(0)
, transitioner(0)
, minExtent(0), maxExtent(0)
Expand Down
34 changes: 31 additions & 3 deletions src/quick/items/qquicklistview.cpp
Expand Up @@ -49,6 +49,7 @@
#include <QtGui/qevent.h>
#include <QtCore/qmath.h>
#include <QtCore/qcoreapplication.h>
#include <QtCore/qsettings.h>

#include <private/qquicksmoothedanimation_p_p.h>
#include "qplatformdefs.h"
Expand All @@ -61,6 +62,33 @@ QT_BEGIN_NAMESPACE

//#define DEBUG_DELEGATE_LIFECYCLE

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 @@ -171,7 +199,7 @@ class QQuickListViewPrivate : public QQuickItemViewPrivate
, averageSize(100.0), spacing(0.0)
, snapMode(QQuickListView::NoSnap)
, highlightPosAnimator(0), highlightWidthAnimator(0), highlightHeightAnimator(0)
, highlightMoveVelocity(400), highlightResizeVelocity(400), highlightResizeDuration(-1)
, highlightMoveVelocity(DefaultHighlightMoveVelocity), highlightResizeVelocity(DefaultHighlightResizeVelocity), highlightResizeDuration(-1)
, sectionCriteria(0), currentSectionItem(0), nextSectionItem(0)
, overshootDist(0.0), correctFlick(false), inFlickCorrection(false)
{
Expand Down Expand Up @@ -1439,9 +1467,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 > QML_FLICK_SNAPONETHRESHOLD && dist < averageSize/2)
if (data.velocity > 0 && dist > FlickSnapOneThreshold && dist < averageSize/2)
bias = averageSize/2;
else if (data.velocity < 0 && dist < -QML_FLICK_SNAPONETHRESHOLD && dist > -averageSize/2)
else if (data.velocity < 0 && dist < -FlickSnapOneThreshold && dist > -averageSize/2)
bias = -averageSize/2;
if (isContentFlowReversed())
bias = -bias;
Expand Down
14 changes: 13 additions & 1 deletion src/quick/items/qquickmousearea.cpp
Expand Up @@ -49,14 +49,26 @@

#include <QtGui/private/qguiapplication_p.h>
#include <QtGui/qevent.h>
#include <QtCore/qsettings.h>

#include <float.h>

QT_BEGIN_NAMESPACE

DEFINE_BOOL_CONFIG_OPTION(qmlVisualTouchDebugging, QML_VISUAL_TOUCH_DEBUGGING)

static const int PressAndHoldDelay = 800;
extern const QSettings &quickSettings();

namespace {

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

const int PressAndHoldDelay(getPressAndHoldDelay());

}

QQuickMouseAreaPrivate::QQuickMouseAreaPrivate()
: enabled(true), hovered(false), longPress(false),
Expand Down

0 comments on commit 42c15a3

Please sign in to comment.