~ubuntu-branches/ubuntu/trusty/tomahawk/trusty-proposed

« back to all changes in this revision

Viewing changes to src/widgets/SlideSwitchButton.h

  • Committer: Package Import Robot
  • Author(s): Harald Sitter
  • Date: 2013-03-07 21:50:13 UTC
  • Revision ID: package-import@ubuntu.com-20130307215013-6gdjkdds7i9uenvs
Tags: upstream-0.6.0+dfsg
ImportĀ upstreamĀ versionĀ 0.6.0+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
 
2
 *
 
3
 *   Copyright 2012 Teo Mrnjavac <teo@kde.org>
 
4
 *   Copyright 2012 Leo Franchi <lfranchi@kde.org>
 
5
 *
 
6
 *   Tomahawk is free software: you can redistribute it and/or modify
 
7
 *   it under the terms of the GNU General Public License as published by
 
8
 *   the Free Software Foundation, either version 3 of the License, or
 
9
 *   (at your option) any later version.
 
10
 *
 
11
 *   Tomahawk is distributed in the hope that it will be useful,
 
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
14
 *   GNU General Public License for more details.
 
15
 *
 
16
 *   You should have received a copy of the GNU General Public License
 
17
 *   along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
#ifndef SLIDESWITCHBUTTON_H
 
21
#define SLIDESWITCHBUTTON_H
 
22
 
 
23
#include <QPushButton>
 
24
#include <QColor>
 
25
#include <QPixmap>
 
26
#include <QFont>
 
27
#include <QWeakPointer>
 
28
 
 
29
class QMouseEvent;
 
30
class QMouseEvent;
 
31
class QPropertyAnimation;
 
32
 
 
33
class SlideSwitchButton : public QPushButton
 
34
{
 
35
    Q_OBJECT
 
36
    Q_PROPERTY( qreal knobX READ knobX WRITE setKnobX )
 
37
    Q_PROPERTY( QColor baseColorTop READ baseColorTop WRITE setBaseColorTop )
 
38
    Q_PROPERTY( QColor baseColorBottom READ baseColorBottom WRITE setBaseColorBottom )
 
39
public:
 
40
    explicit SlideSwitchButton( QWidget* parent = 0 );
 
41
    explicit SlideSwitchButton( const QString& checkedText,
 
42
                                const QString& uncheckedText,
 
43
                                QWidget* parent = 0 );
 
44
 
 
45
    void init();
 
46
 
 
47
    virtual QSize sizeHint() const;
 
48
    virtual QSize minimumSizeHint() const;
 
49
 
 
50
    //the back check-state cannot be changed by the user, only programmatically
 
51
    //to notify that the user-requested operation has completed
 
52
    void setBackChecked( bool state );
 
53
    bool backChecked() const;
 
54
 
 
55
    void setKnobX( qreal x );
 
56
    qreal knobX() const;
 
57
 
 
58
    void setBaseColorTop( const QColor& color );
 
59
    QColor baseColorTop() const;
 
60
 
 
61
    void setBaseColorBottom( const QColor& color );
 
62
    QColor baseColorBottom() const;
 
63
 
 
64
protected:
 
65
    void paintEvent( QPaintEvent* event );
 
66
 
 
67
    virtual void mousePressEvent( QMouseEvent* e );
 
68
    virtual void mouseReleaseEvent( QMouseEvent* e );
 
69
    virtual void mouseMoveEvent(QMouseEvent* e);
 
70
private slots:
 
71
    void onCheckedStateChanged();
 
72
 
 
73
private:
 
74
    void createKnob();
 
75
 
 
76
    QPixmap m_knob;
 
77
 
 
78
    QString m_checkedText;
 
79
    QString m_uncheckedText;
 
80
    QColor m_baseColorTop, m_baseColorBottom;
 
81
    QColor m_textColor;
 
82
    QColor m_backUncheckedColorTop, m_backUncheckedColorBottom;
 
83
    QColor m_backCheckedColorTop, m_backCheckedColorBottom;
 
84
    QFont m_textFont; //needed for sizeHint
 
85
    bool m_backChecked;
 
86
    qreal m_knobX;
 
87
 
 
88
    QPoint m_mouseDownPos;
 
89
 
 
90
    QWeakPointer<QPropertyAnimation> m_backTopAnimation;
 
91
    QWeakPointer<QPropertyAnimation> m_backBottomAnimation;
 
92
    QWeakPointer<QPropertyAnimation> m_knobAnimation;
 
93
};
 
94
 
 
95
#endif // SLIDESWITCHBUTTON_H