~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kstyles/oxygen/demo/oxygensliderdemowidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//////////////////////////////////////////////////////////////////////////////
 
2
// oxygensliderdemowidget.cpp
 
3
// oxygen sliders demo widget
 
4
// -------------------
 
5
//
 
6
// Copyright (c) 2010 Hugo Pereira Da Costa <hugo@oxygen-icons.org>
 
7
//
 
8
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
9
// of this software and associated documentation files (the "Software"), to
 
10
// deal in the Software without restriction, including without limitation the
 
11
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 
12
// sell copies of the Software, and to permit persons to whom the Software is
 
13
// furnished to do so, subject to the following conditions:
 
14
//
 
15
// The above copyright notice and this permission notice shall be included in
 
16
// all copies or substantial portions of the Software.
 
17
//
 
18
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
19
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
20
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
21
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
22
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
23
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 
24
// IN THE SOFTWARE.
 
25
//////////////////////////////////////////////////////////////////////////////
 
26
 
 
27
#include "oxygensliderdemowidget.h"
 
28
#include "oxygensliderdemowidget.moc"
 
29
 
 
30
#include <QtGui/QMenu>
 
31
#include <QtGui/QStyleOptionSlider>
 
32
 
 
33
namespace Oxygen
 
34
{
 
35
 
 
36
    //_____________________________________________________________
 
37
    ProgressBar::ProgressBar( QObject* parent, QProgressBar* progressBar, QCheckBox* checkBox ):
 
38
        QObject( parent ),
 
39
        _progressBar( progressBar ),
 
40
        _checkBox( checkBox ),
 
41
        _value( 0 )
 
42
    { connect( _checkBox, SIGNAL( toggled( bool ) ), SLOT( toggleBusy( bool ) ) ); }
 
43
 
 
44
    //_____________________________________________________________
 
45
    void ProgressBar::toggleBusy( bool value )
 
46
    {
 
47
 
 
48
        if( value )
 
49
        {
 
50
            _value = _progressBar->value();
 
51
            _progressBar->setMinimum( 0 );
 
52
            _progressBar->setMaximum( 0 );
 
53
 
 
54
        } else {
 
55
 
 
56
            _progressBar->setMinimum( 0 );
 
57
            _progressBar->setMaximum( 100 );
 
58
            _progressBar->setValue( _value );
 
59
 
 
60
        }
 
61
 
 
62
        _progressBar->update();
 
63
 
 
64
    }
 
65
 
 
66
    //_____________________________________________________________
 
67
    void ProgressBar::setValue( int value )
 
68
    {
 
69
        if( !_checkBox->isChecked() )
 
70
        { _progressBar->setValue( value ); }
 
71
    }
 
72
 
 
73
    //_____________________________________________________________
 
74
    SliderDemoWidget::SliderDemoWidget( QWidget* parent ):
 
75
        DemoWidget( parent ),
 
76
        _locked( false )
 
77
    {
 
78
 
 
79
        ui.setupUi( this );
 
80
 
 
81
        _progressBar1 = new ProgressBar( this, ui.progressBar, ui.checkBox );
 
82
        _progressBar2 = new ProgressBar( this, ui.progressBar_2, ui.checkBox_2 );
 
83
        ui.checkBox_2->setChecked( true );
 
84
 
 
85
        connect( ui.horizontalSlider, SIGNAL( valueChanged( int ) ), SLOT( updateSliders( int ) ) );
 
86
        connect( ui.horizontalScrollBar, SIGNAL( valueChanged( int ) ), SLOT( updateSliders( int ) ) );
 
87
        connect( ui.verticalSlider, SIGNAL( valueChanged( int ) ), SLOT( updateSliders( int ) ) );
 
88
        connect( ui.verticalScrollBar, SIGNAL( valueChanged( int ) ), SLOT( updateSliders( int ) ) );
 
89
        connect( ui.dial, SIGNAL( valueChanged( int ) ), SLOT( updateSliders( int ) ) );
 
90
 
 
91
    }
 
92
 
 
93
    //_____________________________________________________________
 
94
    void SliderDemoWidget::benchmark( void )
 
95
    {
 
96
 
 
97
        if( !isVisible() ) return;
 
98
 
 
99
        // horizontal
 
100
        simulator().slide( ui.horizontalSlider, QPoint( 50, 0 ) );
 
101
        simulator().slide( ui.horizontalSlider, QPoint( -50, 0 ) );
 
102
 
 
103
        simulator().slide( ui.horizontalScrollBar, QPoint( 50, 0 ) );
 
104
        simulator().slide( ui.horizontalScrollBar, QPoint( -50, 0 ) );
 
105
 
 
106
        // vertical
 
107
        simulator().slide( ui.verticalScrollBar, QPoint( 0, 50 ) );
 
108
        simulator().slide( ui.verticalScrollBar, QPoint( 0, -50 ) );
 
109
 
 
110
        simulator().slide( ui.verticalSlider, QPoint( 0, 50 ) );
 
111
        simulator().slide( ui.verticalSlider, QPoint( 0, -50 ) );
 
112
 
 
113
        // dial button
 
114
        // nothing for now.
 
115
 
 
116
        simulator().run();
 
117
    }
 
118
 
 
119
    //_____________________________________________________________
 
120
    void SliderDemoWidget::updateSliders( int value )
 
121
    {
 
122
        if( _locked ) return;
 
123
 
 
124
        _locked = true;
 
125
        _progressBar1->setValue( value );
 
126
        _progressBar2->setValue( value );
 
127
 
 
128
        ui.horizontalSlider->setValue( value );
 
129
        ui.verticalSlider->setValue( value );
 
130
        ui.progressBar_3->setValue( value );
 
131
        ui.horizontalScrollBar->setValue( value );
 
132
        ui.verticalScrollBar->setValue( value );
 
133
        ui.dial->setValue( value );
 
134
 
 
135
        _locked = false;
 
136
 
 
137
    }
 
138
}