File indexing completed on 2024-10-06 04:26:03
0001 /* 0002 SPDX-FileCopyrightText: 1998-2007 Sebastian Trueg <trueg@k3b.org> 0003 0004 Based on the effects in popupMessage.cpp 0005 SPDX-FileCopyrightText: 2005 Max Howell <max.howell@methylblue.com> 0006 SPDX-FileCopyrightText: 2005 Seb Ruiz <me@sebruiz.net> 0007 0008 Dissolve Mask (c) Kicker Authors kickertip.cpp, 2005/08/17 0009 0010 SPDX-License-Identifier: GPL-2.0-or-later 0011 */ 0012 0013 #include "k3bwidgetshoweffect.h" 0014 0015 #include <QTimerEvent> 0016 #include <QPainter> 0017 #include <QWidget> 0018 0019 0020 K3b::WidgetShowEffect::WidgetShowEffect( QWidget* widget, Effect e ) 0021 : QObject( widget ), 0022 m_effect( e ), 0023 m_widget( widget ), 0024 m_dissolveSize( 0 ), 0025 m_dissolveDelta( -1 ), 0026 m_offset( 0 ), 0027 m_deleteSelf( false ), 0028 m_bEffectOnly( false ) 0029 { 0030 } 0031 0032 0033 K3b::WidgetShowEffect::~WidgetShowEffect() 0034 { 0035 } 0036 0037 0038 void K3b::WidgetShowEffect::hide( bool effectOnly ) 0039 { 0040 m_bEffectOnly = effectOnly; 0041 m_bShow = false; 0042 m_offset = m_widget->height(); 0043 killTimer( m_timerId ); 0044 m_timerId = startTimer( 6 ); 0045 } 0046 0047 0048 void K3b::WidgetShowEffect::show( bool effectOnly ) 0049 { 0050 m_bShow = true; 0051 m_offset = 0; 0052 m_dissolveSize = 24; 0053 m_dissolveDelta = -1; 0054 0055 m_widget->ensurePolished(); 0056 0057 if( m_effect == Dissolve ) { 0058 // necessary to create the mask 0059 m_mask = QBitmap( m_widget->width(), m_widget->height() ); 0060 // make the mask empty and hence will not show widget with show() called below 0061 dissolveMask(); 0062 m_timerId = startTimer( 1000 / 30 ); 0063 } 0064 else { 0065 m_widget->move( 0, m_widget->parentWidget()->height() ); 0066 m_timerId = startTimer( 6 ); 0067 } 0068 0069 if( !effectOnly ) 0070 m_widget->show(); 0071 } 0072 0073 0074 void K3b::WidgetShowEffect::timerEvent( QTimerEvent* ) 0075 { 0076 switch( m_effect ) { 0077 case Slide: 0078 slideMask(); 0079 break; 0080 0081 case Dissolve: 0082 dissolveMask(); 0083 break; 0084 } 0085 } 0086 0087 0088 void K3b::WidgetShowEffect::dissolveMask() 0089 { 0090 if( m_bShow ) { 0091 m_widget->repaint(); 0092 QPainter maskPainter(&m_mask); 0093 0094 m_mask.fill(Qt::black); 0095 0096 maskPainter.setBrush(Qt::white); 0097 maskPainter.setPen(Qt::white); 0098 maskPainter.drawRect( m_mask.rect() ); 0099 0100 m_dissolveSize += m_dissolveDelta; 0101 0102 if( m_dissolveSize > 0 ) { 0103 //FIXME kde4 0104 //maskPainter.setRasterOp( Qt::EraseROP ); 0105 0106 int x, y, s; 0107 const int size = 16; 0108 0109 for( y = 0; y < m_widget->height() + size; y += size ) { 0110 x = m_widget->width(); 0111 s = m_dissolveSize * x / 128; 0112 0113 for( ; x > size; x -= size, s -= 2 ) { 0114 if( s < 0 ) 0115 break; 0116 0117 maskPainter.drawEllipse(x - s / 2, y - s / 2, s, s); 0118 } 0119 } 0120 } 0121 else if( m_dissolveSize < 0 ) { 0122 m_dissolveDelta = 1; 0123 killTimer( m_timerId ); 0124 0125 emit widgetShown( m_widget ); 0126 0127 if( m_deleteSelf ) 0128 deleteLater(); 0129 } 0130 0131 m_widget->setMask( m_mask ); 0132 } 0133 0134 else { 0135 // just hide it for now 0136 emit widgetHidden( m_widget ); 0137 if( !m_bEffectOnly ) 0138 m_widget->hide(); 0139 0140 if( m_deleteSelf ) 0141 deleteLater(); 0142 } 0143 } 0144 0145 0146 void K3b::WidgetShowEffect::slideMask() 0147 { 0148 if( m_bShow ) { 0149 m_widget->move( 0, m_widget->parentWidget()->height() - m_offset ); 0150 0151 m_offset++; 0152 if( m_offset > m_widget->height() ) { 0153 killTimer( m_timerId ); 0154 0155 emit widgetShown( m_widget ); 0156 0157 if( m_deleteSelf ) 0158 deleteLater(); 0159 } 0160 } 0161 else { 0162 m_offset--; 0163 m_widget->move( 0, m_widget->parentWidget()->height() - m_offset ); 0164 0165 if( m_offset < 0 ) { 0166 // finally hide the widget 0167 emit widgetHidden( m_widget ); 0168 if( !m_bEffectOnly ) 0169 m_widget->hide(); 0170 0171 if( m_deleteSelf ) 0172 deleteLater(); 0173 } 0174 } 0175 } 0176 0177 0178 0179 K3b::WidgetShowEffect* K3b::WidgetShowEffect::showWidget( QWidget* w, Effect m ) 0180 { 0181 K3b::WidgetShowEffect* e = new K3b::WidgetShowEffect( w, m ); 0182 e->m_deleteSelf = true; 0183 e->show(); 0184 return e; 0185 } 0186 0187 0188 K3b::WidgetShowEffect* K3b::WidgetShowEffect::hideWidget( QWidget* w, Effect m ) 0189 { 0190 K3b::WidgetShowEffect* e = new K3b::WidgetShowEffect( w, m ); 0191 e->m_deleteSelf = true; 0192 e->hide(); 0193 return e; 0194 } 0195 0196 #include "moc_k3bwidgetshoweffect.cpp"