aboutsummaryrefslogtreecommitdiff
path: root/src/views/msliderview_p.h
blob: bb87bc05558ce365a356fb41c59509343c1e64d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (directui@nokia.com)
**
** This file is part of libmeegotouch.
**
** If you have questions regarding the use of this file, please contact
** Nokia at directui@nokia.com.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/

#ifndef MSLIDERVIEW_P_H
#define MSLIDERVIEW_P_H

#include "msliderview.h"

#include <MWidget>
#include <QTime>
#include "mslidermodel.h"

class MSlider;
class QPixmap;
class MScalableImage;
class MLabel;
class MImageWidget;
class QGraphicsAnchorLayout;
class MLinearLayoutPolicy;
class MSliderView;
class QPropertyAnimation;

class MSliderHandle : public MWidget
{
public:
    MSliderHandle(QGraphicsItem *parent = 0);
    virtual ~MSliderHandle();

    void setOrientation(Qt::Orientation);
    void setPixmaps(const QPixmap *handle,
                    const QPixmap *handlePressed,
                    const QPixmap *handleVertical,
                    const QPixmap *handleVerticalPressed);

    void setSliderState(MSliderModel::SliderState state);

    virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);

    virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;

private:
    Qt::Orientation orientation;

    const QPixmap *handlePixmap;
    const QPixmap *handlePressedPixmap;
    const QPixmap *handleVerticalPixmap;
    const QPixmap *handleVerticalPressedPixmap;

    MSliderModel::SliderState sliderState;

#ifdef UNIT_TEST
    friend class Ut_MSliderView;
#endif // UNIT_TEST
};

class MSliderHandleIndicatorArrow : public MWidget
{
public:
    MSliderHandleIndicatorArrow(QGraphicsItem *parent = 0);
    virtual ~MSliderHandleIndicatorArrow();

    void setOrientation(Qt::Orientation);
    void setPixmaps(const QPixmap *handleLabelArrowLeft,
                    const QPixmap *handleLabelArrowRight,
                    const QPixmap *handleLabelArrowUp,
                    const QPixmap *handleLabelArrowDown);

    virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);

    virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;

private:
    Qt::Orientation orientation;

    const QPixmap *handleLabelArrowLeftPixmap;
    const QPixmap *handleLabelArrowRightPixmap;
    const QPixmap *handleLabelArrowUpPixmap;
    const QPixmap *handleLabelArrowDownPixmap;

#ifdef UNIT_TEST
    friend class Ut_MSliderView;
#endif // UNIT_TEST
};

class MSliderIndicator : public MWidget
{
    Q_OBJECT
public:
    MSliderIndicator(bool isMinMax, QGraphicsItem *parent = 0);
    virtual ~MSliderIndicator();

    void setLabelStyleName(const QString &stylename);
    void setText(const QString &text);
    void setImage(const QString &id);

    bool isEmpty() const;

protected:
    virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;

private:
    MLabel *label;
    MImageWidget *image;
    QString imageName;

    QGraphicsAnchorLayout *layout;

#ifdef UNIT_TEST
    friend class Ut_MSliderView;
#endif // UNIT_TEST
};

class MSliderHandleIndicator : public MWidget
{
    Q_OBJECT
public:
    MSliderHandleIndicator(QGraphicsItem *parent = 0);
    virtual ~MSliderHandleIndicator();

    void setOrientation(Qt::Orientation);
    void setPixmaps(const QPixmap *handleLabelArrowLeft,
                    const QPixmap *handleLabelArrowRight,
                    const QPixmap *handleLabelArrowUp,
                    const QPixmap *handleLabelArrowDown);

    void setStyleName(const QString &stylename);
    void setText(const QString &text);
    void setImage(const QString &id);
    void setArrowPos(qreal pos);
    void setArrowMargin(qreal margin);

    void moveOnTopAllSiblings();

    virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;

private:
    qreal arrowPos;
    qreal arrowMargin;
    Qt::Orientation orientation;
    MSliderHandleIndicatorArrow* indicatorArrow;
    MSliderIndicator* indicator;
};

class MSliderGroove : public MWidget
{
    Q_OBJECT
public:
    MSliderGroove(QGraphicsItem *parent = 0);
    virtual ~MSliderGroove();

    void init(MSlider *controller);

    void setOrientation(Qt::Orientation);

    void setHandlePixmaps(const QPixmap *handle,
                          const QPixmap *handlePressed,
                          const QPixmap *handleVertical,
                          const QPixmap *handleVerticalPressed);
    void setHandleIndicatorPixmaps(const QPixmap *handleLabelArrowLeft,
                                   const QPixmap *handleLabelArrowRight,
                                   const QPixmap *handleLabelArrowUp,
                                   const QPixmap *handleLabelArrowDown);
    void setImages(const MScalableImage *background,
                   const MScalableImage *backgroundElapsed,
                   const MScalableImage *backgroundReceived,
                   const MScalableImage *backgroundVertical,
                   const MScalableImage *backgroundVerticalElapsed,
                   const MScalableImage *backgroundVerticalReceived);
    void setGrooveThickness(qreal thickness);
    void setGrooveLength(qreal prefLength, qreal minLength, qreal maxLength);
    void setIndicatorMargin(qreal margin);

    void setHandleIndicatorArrowMargin(qreal margin);

    void setElapsedOffset(qreal offset);
    void setIndicatorOffset(qreal offset);

    void setIndicatorStyleName(const QString &stylename);

    void setSliderValues(int min, int max, int val);
    void setSeekBarValues(bool show, int loadedContentMin = 0, int loadedContentMax = 0);
    void setSliderState(MSliderModel::SliderState state);

    void setIndicatorText(const QString &text);
    void setIndicatorImage(const QString &id);

    int screenPointToValue(const QPointF &point) const;

    QRectF clickableArea() const;
    QRectF clickableHandleArea() const;

    QRectF boundingRect() const;

    void raiseHandleIndicator();
    void lowerHandleIndicator();

    void ensureSafeClosing();

    virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);

protected:
    virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;

    virtual void setGeometry(const QRectF &rect);
    virtual void resizeEvent(QGraphicsSceneResizeEvent *event);

private:
    void updateHandlePos(const QPointF &position);
    void updateHandleIndicatorPos();

    MSlider *controller;

    Qt::Orientation orientation;

    qreal valueToScreenCoordinate(int value) const;

    const MScalableImage *backgroundBaseImage;
    const MScalableImage *backgroundElapsedImage;
    const MScalableImage *backgroundReceivedImage;
    const MScalableImage *backgroundVerticalBaseImage;
    const MScalableImage *backgroundVerticalElapsedImage;
    const MScalableImage *backgroundVerticalReceivedImage;

    qreal grooveThickness;

    int minimum;
    int maximum;
    int value;

    int loadedContentMinimum;
    int loadedContentMaximum;
    bool showSeekBar;

    MSliderHandle *sliderHandle;
    MSliderHandleIndicator *sliderHandleIndicator;

    QRectF sliderBoundingRect;

    qreal preferredLength;
    qreal minimumLength;
    qreal maximumLength;
    qreal indicatorMargin;
    qreal elapsedOffset;
    qreal indicatorOffset;

    QString indicatorStyleName;

#ifdef UNIT_TEST
    friend class Ut_MSliderView;
#endif // UNIT_TEST
};

class MSliderViewPrivate
{
    Q_DECLARE_PUBLIC(MSliderView)

protected:
    MSliderView *q_ptr;

public:
    MSliderViewPrivate();
    virtual ~MSliderViewPrivate();

    MSlider *controller;

    MSliderGroove *sliderGroove;

    MSliderIndicator *minIndicator;
    MSliderIndicator *maxIndicator;

    MLinearLayoutPolicy *horizontalPolicy;
    MLinearLayoutPolicy *verticalPolicy;

    QPropertyAnimation *positionAnimation;

    QTime feedbackTimer;
    int valueWhenFeedback;

    int pressTimerId;

    int valueWhenPressed;

    int position;

    void init(MSlider *contoller);

    void insertMinIndicatorToLayout();
    void insertMaxIndicatorToLayout();
    void removeMinIndicatorFromLayout();
    void removeMaxIndicatorFromLayout();

    void updateOrientation();
    bool isCollision(QGraphicsSceneMouseEvent *event) const;
    int updateValue(QGraphicsSceneMouseEvent *event);
    void updateSliderGroove();
    void updateSeekBar();
    void playSliderMoveFeedback(int newValue);
    QPropertyAnimation* createPositionAnimation();

#ifdef UNIT_TEST
    friend class Ut_MSliderView;
#endif // UNIT_TEST
};

#endif