1 /************************************************************************
3 * Copyright 2010 Jakob Leben (jakob.leben@gmail.com)
5 * This file is part of SuperCollider Qt GUI.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ************************************************************************/
23 #include "../painting.h"
24 #include "../Common.h"
28 QcCanvas::QcCanvas( QWidget
*parent
)
31 _repaintNeeded( true ),
32 _clearOnRefresh( true ),
43 //_bkgColor = palette().color( QPalette::Background );
46 float QcCanvas::frameRate() const
51 void QcCanvas::setFrameRate( float rate
)
55 if( _animating
&& _fps
> 0 ) {
56 // restart animation timer with new frame rate
57 killTimer( _timerId
);
58 _timerId
= startTimer( 1000.f
/ _fps
);
63 void QcCanvas::refresh()
65 _repaintNeeded
= true;
69 void QcCanvas::clear()
74 void QcCanvas::animate( bool on
)
77 if( !_animating
&& _fps
> 0 ) {
81 _timerId
= startTimer( 1000.f
/ _fps
);
82 _fpsTimer
.start( _meterPeriod
, this );
85 else if( _animating
) {
86 killTimer( _timerId
);
92 void QcCanvas::customEvent( QEvent
*e
)
94 if( e
->type() == (QEvent::Type
) QtCollider::Event_Refresh
) {
100 void QcCanvas::resizeEvent( QResizeEvent
* )
106 void QcCanvas::paintEvent( QPaintEvent
* )
108 if( _paint
&& _repaintNeeded
) {
110 _pixmap
= QPixmap( size() );
115 if( _clearOnRefresh
|| _clearOnce
) {
116 _pixmap
.fill( QColor(0,0,0,0) );
120 QPainter
pixPainter( &_pixmap
);
121 Q_EMIT( painting(&pixPainter
) );
122 _repaintNeeded
= false;
126 if( _bkgColor
.isValid() ) p
.fillRect( rect(), _bkgColor
);
127 if( _paint
) p
.drawPixmap( rect(), _pixmap
);
130 void QcCanvas::timerEvent( QTimerEvent
*e
)
132 if( e
->timerId() == _timerId
) {
135 _repaintNeeded
= true;
138 else if( e
->timerId() == _fpsTimer
.timerId() ) {
140 float dTime
= _meterTime
.elapsed();
141 _fpsActual
= (dTime
> 0) ? (_meterFrames
* 1000.f
/ dTime
) : 0.f
;
143 _meterTime
.restart();