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

« back to all changes in this revision

Viewing changes to kstyles/oxygen/transitions/oxygencomboboxdata.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
// krazy:excludeall=qclasses
 
2
 
 
3
//////////////////////////////////////////////////////////////////////////////
 
4
// oxygencomboboxdata.cpp
 
5
// data container for QComboBox transition
 
6
// -------------------
 
7
//
 
8
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo@oxygen-icons.org>
 
9
//
 
10
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
11
// of this software and associated documentation files (the "Software"), to
 
12
// deal in the Software without restriction, including without limitation the
 
13
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 
14
// sell copies of the Software, and to permit persons to whom the Software is
 
15
// furnished to do so, subject to the following conditions:
 
16
//
 
17
// The above copyright notice and this permission notice shall be included in
 
18
// all copies or substantial portions of the Software.
 
19
//
 
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
21
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
22
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
23
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
24
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
25
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 
26
// IN THE SOFTWARE.
 
27
//////////////////////////////////////////////////////////////////////////////
 
28
 
 
29
#include "oxygencomboboxdata.h"
 
30
#include "oxygencomboboxdata.moc"
 
31
 
 
32
namespace Oxygen
 
33
{
 
34
 
 
35
    //______________________________________________________
 
36
    ComboBoxData::ComboBoxData( QObject* parent, QComboBox* target, int duration ):
 
37
        TransitionData( parent, target, duration ),
 
38
        _target( target )
 
39
    {
 
40
        _target.data()->installEventFilter( this );
 
41
        connect( _target.data(), SIGNAL( destroyed() ), SLOT( targetDestroyed() ) );
 
42
        connect( _target.data(), SIGNAL( currentIndexChanged( int ) ), SLOT( indexChanged() ) );
 
43
    }
 
44
 
 
45
    //___________________________________________________________________
 
46
    void ComboBoxData::indexChanged( void )
 
47
    {
 
48
 
 
49
        if( recursiveCheck() ) return;
 
50
 
 
51
        if( transition().data()->isAnimated() )
 
52
        { transition().data()->endAnimation(); }
 
53
 
 
54
        if( initializeAnimation() ) animate();
 
55
        else transition().data()->hide();
 
56
 
 
57
    }
 
58
 
 
59
    //___________________________________________________________________
 
60
    bool ComboBoxData::eventFilter( QObject* object, QEvent* event )
 
61
    {
 
62
 
 
63
        // make sure engine is enabled
 
64
        if( !( enabled() && object == _target.data() ) )
 
65
        { return TransitionData::eventFilter( object, event ); }
 
66
 
 
67
        // make sure that target is not editable
 
68
        if( _target.data()->isEditable() )
 
69
        { return TransitionData::eventFilter( object, event ); }
 
70
 
 
71
        switch( event->type() )
 
72
        {
 
73
 
 
74
            case QEvent::Show:
 
75
            case QEvent::Resize:
 
76
            case QEvent::Move:
 
77
            if( !recursiveCheck() && _target.data()->isVisible() )
 
78
            { _timer.start( 0, this ); }
 
79
            break;
 
80
 
 
81
            default: break;
 
82
        }
 
83
 
 
84
        return TransitionData::eventFilter( object, event );
 
85
 
 
86
    }
 
87
 
 
88
    //___________________________________________________________________
 
89
    void ComboBoxData::timerEvent( QTimerEvent* event )
 
90
    {
 
91
        if( event->timerId() == _timer.timerId() )
 
92
        {
 
93
 
 
94
            _timer.stop();
 
95
            if( enabled() && transition() && _target && !_target.data()->isVisible() )
 
96
            {
 
97
                setRecursiveCheck( true );
 
98
                transition().data()->setEndPixmap( transition().data()->grab( _target.data(), targetRect() ) );
 
99
                setRecursiveCheck( false );
 
100
            }
 
101
 
 
102
        } else return TransitionData::timerEvent( event );
 
103
 
 
104
    }
 
105
 
 
106
    //___________________________________________________________________
 
107
    bool ComboBoxData::initializeAnimation( void )
 
108
    {
 
109
        if( !( enabled() && _target && _target.data()->isVisible() ) ) return false;
 
110
        if( _target.data()->isEditable() )
 
111
        {
 
112
            /*
 
113
            do nothing for editable comboboxes because
 
114
            lineEditor animations are handled directly
 
115
            */
 
116
            return false;
 
117
        }
 
118
 
 
119
        transition().data()->setOpacity(0);
 
120
        transition().data()->setGeometry( targetRect() );
 
121
        transition().data()->setStartPixmap( transition().data()->currentPixmap() );
 
122
        transition().data()->show();
 
123
        transition().data()->raise();
 
124
        return true;
 
125
    }
 
126
 
 
127
    //___________________________________________________________________
 
128
    bool ComboBoxData::animate( void )
 
129
    {
 
130
 
 
131
        // check enability
 
132
        if( !enabled() ) return false;
 
133
 
 
134
        // grab
 
135
        setRecursiveCheck( true );
 
136
        transition().data()->setEndPixmap( transition().data()->grab( _target.data(), targetRect() ) );
 
137
        setRecursiveCheck( false );
 
138
 
 
139
        // start animation
 
140
        transition().data()->animate();
 
141
 
 
142
        return true;
 
143
 
 
144
    }
 
145
 
 
146
    //___________________________________________________________________
 
147
    void ComboBoxData::targetDestroyed( void )
 
148
    {
 
149
        setEnabled( false );
 
150
        _target.clear();
 
151
    }
 
152
 
 
153
}