units.longDuration and units.shortDuration properties

These centralize the duration of animations, currently set to 250 and 50
milliseconds. They're notifiable since we want to be able to switch off
animations at runtime.

CCMAIL:plasma-devel@kde.org
This commit is contained in:
Sebastian Kügler 2014-02-03 16:30:50 +01:00
parent 210a224bd3
commit 30e98ba8f7
3 changed files with 42 additions and 3 deletions

View File

@ -33,7 +33,8 @@
Units::Units (QObject *parent)
: QObject(parent),
m_gridUnit(-1),
m_devicePixelRatio(-1)
m_devicePixelRatio(-1),
m_longDuration(250)
{
m_iconSizes = new QQmlPropertyMap(this);
updateDevicePixelRatio();
@ -163,6 +164,17 @@ void Units::updateSpacing()
}
}
int Units::longDuration() const
{
return m_longDuration;
}
int Units::shortDuration() const
{
return m_longDuration / 5;
}
bool Units::eventFilter(QObject *watched, QEvent *event)
{
if (watched == QCoreApplication::instance()) {

View File

@ -83,6 +83,18 @@ class Units : public QObject
*/
Q_PROPERTY(qreal devicePixelRatio READ devicePixelRatio NOTIFY devicePixelRatioChanged)
/**
* units.longDuration should be used for longer, screen-covering animations, for opening and
* closing of dialogs and other "not too small" animations
*/
Q_PROPERTY(int longDuration READ longDuration NOTIFY durationChanged)
/**
* units.longDuration should be used for short animations, such as accentuating a UI event,
* hover events, etc..
*/
Q_PROPERTY(int shortDuration READ shortDuration NOTIFY durationChanged)
public:
Units(QObject *parent = 0);
~Units();
@ -116,11 +128,24 @@ public:
*/
int largeSpacing() const;
/**
* @return Duration for long animations, in milliseconds.
* @since 5.0
*/
int longDuration() const;
/**
* @return Duration for short animations, in milliseconds.
* @since 5.0
*/
int shortDuration() const;
Q_SIGNALS:
void devicePixelRatioChanged();
void gridUnitChanged();
void iconSizesChanged();
void spacingChanged();
void durationChanged();
private Q_SLOTS:
void themeChanged();
@ -144,6 +169,8 @@ private:
int m_smallSpacing;
int m_largeSpacing;
int m_longDuration;
};
#endif //UNITS_H

View File

@ -2,7 +2,7 @@
.pragma library
// a normal animation
var normalDuration = 250;
var normalDuration = units.longDuration;
// for direct feedback, such as tapping
var feedbackDuration = 50;
var feedbackDuration = units.shortDuration;