1 //////////////////////////////////////////////////////////////////////////////
2 // oxygenmdiwindowdata.cpp
3 // mdi window data container for window titlebar buttons
4 // -------------------
5 //
6 // SPDX-FileCopyrightText: 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
7 //
8 // SPDX-License-Identifier: MIT
9 //////////////////////////////////////////////////////////////////////////////
10 
11 #include "oxygenmdiwindowdata.h"
12 
13 namespace Oxygen
14 {
15 
16     //________________________________________________
MdiWindowData(QObject * parent,QWidget * target,int duration)17     MdiWindowData::MdiWindowData( QObject* parent, QWidget* target, int duration ):
18         AnimationData( parent, target )
19     {
20         _currentData._animation = new Animation( duration, this );
21         _previousData._animation = new Animation( duration, this );
22         setupAnimation( currentAnimation(), "currentOpacity" );
23         setupAnimation( previousAnimation(), "previousOpacity" );
24 
25         currentAnimation().data()->setDirection( Animation::Forward );
26         previousAnimation().data()->setDirection( Animation::Backward );
27     }
28 
29     //______________________________________________
updateState(int primitive,bool state)30     bool MdiWindowData::updateState( int primitive, bool state )
31     {
32 
33         if( state )
34         {
35 
36             if( primitive != _currentData._primitive )
37             {
38 
39                 _previousData.updateSubControl( _currentData._primitive );
40                 _currentData.updateSubControl( primitive );
41                 return true;
42 
43             } else return false;
44 
45         } else {
46 
47             bool changed( false );
48             if( primitive == _currentData._primitive )
49             {
50                 changed |= _currentData.updateSubControl( 0 );
51                 changed |= _previousData.updateSubControl( primitive );
52             }
53 
54             return changed;
55 
56         }
57 
58     }
59 
60     //______________________________________________
updateSubControl(int value)61     bool MdiWindowData::Data::updateSubControl( int value )
62     {
63         if( _primitive == value ) return false;
64         else {
65 
66             _primitive = value;
67             if( _animation.data()->isRunning() ) _animation.data()->stop();
68             if( _primitive != 0 ) _animation.data()->start();
69             return true;
70 
71         }
72     }
73 
74 }
75