aboutsummaryrefslogtreecommitdiff
path: root/src/views/msliderview_p.h
blob: 67ca06c8d5fe5d7d57ff5ed11dd57bfd10cfdf3c (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
/***************************************************************************
**
** 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 "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 MSliderIndicator : public MWidget
{
    Q_OBJECT
public:
    MSliderIndicator(bool isMinMax, QGraphicsItem *parent = 0);
    virtual ~MSliderIndicator();

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

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

private:
    MLabel *label;
    MImageWidget *image;
    QString imageName;
    //bool visibility;

    QGraphicsAnchorLayout *layout;

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

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 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 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;
    MSliderIndicator *sliderHandleIndicator;

    QRectF sliderBoundingRect;

    qreal preferredLength;
    qreal minimumLength;
    qreal maximumLength;

#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 *valueAnimation;

    int pressTimerId;

    int valueWhenPressed;

    void init(MSlider *contoller);

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

    void updateOrientation();
    bool isCollision(QGraphicsSceneMouseEvent *event) const;
    void updateValue(QGraphicsSceneMouseEvent *event);
    void updateSliderGroove();
    void updateSeekBar();

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

#endif