1 /***************************************************************************
2 * Copyright (C) 2005 by Max Howell <max.howell@methylblue.com> *
3 * 2005 by Seb Ruiz <me@sebruiz.net> *
5 * Dissolve Mask (c) Kicker Authors kickertip.cpp, 2005/08/17 *
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 2 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, write to the *
19 * Free Software Foundation, Inc., *
20 * 51 Franklin Steet, Fifth Floor, Boston, MA 02111-1307, USA. *
21 ***************************************************************************/
23 #include "popupMessage.h"
26 #include <kpushbutton.h>
27 #include <kstandardguiitem.h>
32 #include <QMessageBox>
38 #include <QTimerEvent>
44 PopupMessage::PopupMessage( QWidget
*parent
, QWidget
*anchor
, int timeout
, const char *name
)
45 : OverlayWidget( parent
, anchor
, name
)
48 , m_maskEffect( Slide
)
50 , m_dissolveDelta( -1 )
54 , m_timeout( timeout
)
55 , m_showCounter( true )
57 setFrameStyle( QFrame::Panel
| QFrame::Raised
);
58 setFrameShape( QFrame::StyledPanel
);
59 setWindowFlags( Qt::WX11BypassWM
);
61 QPalette p
= QToolTip::palette();
68 m_layout
= new QVBoxLayout( this );
69 m_layout
->setMargin( 9 );
70 m_layout
->setSpacing( 6 );
72 hbox
= new QHBoxLayout
;
73 hbox
->setParent( m_layout
);
74 hbox
->setSpacing( 12 );
76 m_countdownFrame
= new QFrame( this );
77 m_countdownFrame
->setObjectName( "counterVisual" );
78 hbox
->addWidget( m_countdownFrame
);
79 m_countdownFrame
->setFixedWidth( fontMetrics().width( "X" ) );
80 m_countdownFrame
->setFrameStyle( QFrame::Plain
| QFrame::Box
);
81 m_countdownFrame
->setPaletteForegroundColor( paletteBackgroundColor().dark() );
83 label
= new QLabel( this );
84 label
->setObjectName( "image" );
85 hbox
->addWidget( label
);
88 alabel
->setParent( this );
89 alabel
->setObjectName( "label" );
90 alabel
->setTextFormat( Qt::RichText
);
91 alabel
->setSizePolicy( QSizePolicy::MinimumExpanding
, QSizePolicy::Preferred
);
92 alabel
->setPalette( p
);
94 hbox
->addWidget( alabel
);
96 hbox
= new QHBoxLayout
;
97 hbox
->setParent( m_layout
);
99 hbox
->addItem( new QSpacerItem( 4, 4, QSizePolicy::Expanding
, QSizePolicy::Preferred
) );
100 KPushButton
*button
= new KPushButton( KStandardGuiItem::close(), this );
101 button
->setObjectName( "closeButton" );
102 hbox
->addWidget( button
);
104 connect( button
, SIGNAL(clicked()), SLOT(close()) );
107 void PopupMessage::addWidget( QWidget
*widget
)
109 m_layout
->addWidget( widget
);
113 void PopupMessage::setShowCloseButton( const bool show
)
115 findChild
<KPushButton
*>( "closeButton" )->setVisible( show
);
119 void PopupMessage::setShowCounter( const bool show
)
121 m_showCounter
= show
;
122 findChild
<QFrame
*>( "counterVisual" )->setVisible( show
);
126 void PopupMessage::setText( const QString
&text
)
128 findChild
<QLabel
*>( "label" )->setText( text
);
132 void PopupMessage::setImage( const QString
&location
)
134 findChild
<QLabel
*>( "image" )->setPixmap( QPixmap( location
) );
138 void PopupMessage::setImage( const QPixmap
&pix
)
140 findChild
<QLabel
*>( "image" )->setPixmap( pix
);
145 ////////////////////////////////////////////////////////////////////////
147 ////////////////////////////////////////////////////////////////////////
149 void PopupMessage::close() //SLOT
152 killTimer( m_timerId
);
153 m_timerId
= startTimer( 6 );
156 void PopupMessage::display() //SLOT
159 m_dissolveDelta
= -1;
161 if( m_maskEffect
== Dissolve
)
163 // necessary to create the mask
164 m_mask
.resize( width(), height() );
165 // make the mask empty and hence will not show widget with show() called below
167 m_timerId
= startTimer( 1000 / 30 );
171 m_timerId
= startTimer( 6 );
176 ////////////////////////////////////////////////////////////////////////
178 ////////////////////////////////////////////////////////////////////////
180 void PopupMessage::timerEvent( QTimerEvent
* )
182 switch( m_maskEffect
)
198 void PopupMessage::countDown()
202 killTimer( m_timerId
);
206 QFrame
*&h
= m_countdownFrame
;
208 if( m_counter
< h
->height() - 3 )
209 QPainter( h
).fillRect( 2, 2, h
->width() - 4, m_counter
, palette().active().highlight() );
211 if( !testAttribute(Qt::WA_UnderMouse
))
214 if( m_counter
> h
->height() )
217 killTimer( m_timerId
);
218 m_timerId
= startTimer( 6 );
222 killTimer( m_timerId
);
223 m_timerId
= startTimer( m_timeout
/ h
->height() );
227 void PopupMessage::dissolveMask()
232 QPainter
maskPainter(&m_mask
);
234 m_mask
.fill(Qt::black
);
236 maskPainter
.setBrush(Qt::white
);
237 maskPainter
.setPen(Qt::white
);
238 maskPainter
.drawRect( m_mask
.rect() );
240 m_dissolveSize
+= m_dissolveDelta
;
242 if( m_dissolveSize
> 0 )
244 maskPainter
.setCompositionMode( QPainter::CompositionMode_SourceOut
);
249 for (y
= 0; y
< height() + size
; y
+= size
)
252 s
= m_dissolveSize
* x
/ 128;
254 for ( ; x
> size
; x
-= size
, s
-= 2 )
259 maskPainter
.drawEllipse(x
- s
/ 2, y
- s
/ 2, s
, s
);
263 else if( m_dissolveSize
< 0 )
266 killTimer( m_timerId
);
270 m_timerId
= startTimer( 40 );
277 else if ( m_stage
== 2 )
288 void PopupMessage::plainMask()
293 killTimer( m_timerId
);
296 m_timerId
= startTimer( 40 );
306 case 3: // Lower/Remove
312 void PopupMessage::slideMask()
317 move( 0, m_parent
->y() - m_offset
);
320 if( m_offset
> height() )
322 killTimer( m_timerId
);
326 m_timerId
= startTimer( 40 );
333 case 2: //fill in pause timer bar
339 move( 0, m_parent
->y() - m_offset
);
349 #include "popupMessage.moc"