?? playerwindow.cpp
字號:
//if the user is on another desktop to Amarok, do nothing const KWin::WindowInfo info = KWin::windowInfo( winId() ); if( info.isMinimized() ) KWin::iconifyWindow( parentWidget()->winId(), false ); else //this may seem strange, but it is correct //we have a handler in eventFilter for all other eventualities dontChangeButtonState = false; } else //we caused Amarok to hide, so we should hide the Playlist Window //NOTE we "override" closeEvents and thus they count as non-spontaneous //hideEvents; which frankly is a huge relief! parentWidget()->hide(); } return false; default: return QWidget::event( e ); }}// bool// PlayerWidget::x11Event( XEvent *e )// {// if( e->type == ConfigureNotify )// {// kdDebug() << "CirculateNotify\n";// XRaiseWindow( x11Display(), playlistWindow()->winId() );// }//// return false;// }boolPlayerWidget::eventFilter( QObject *o, QEvent *e ){ //NOTE we only monitor for parent() - which is the PlaylistWindow if( o == m_pAnalyzer ) { //delete analyzer, create same one back in Player Window if( e->type() == QEvent::Close ) { createAnalyzer( 0 ); return true; } return false; } switch( e->type() ) { case QEvent::Close: static_cast<QCloseEvent*>(e)->accept(); //close the window! return true; //don't let PlaylistWindow have the event - see PlaylistWindow::closeEvent() case QEvent::Hide: if( dontChangeButtonState ) { //we keep the PlaylistButton set to "on" - see event() for more details //NOTE the Playlist Window will still be hidden dontChangeButtonState = false; break; } if( e->spontaneous() ) { //we want to avoid setting the button for most spontaneous events //since they are not user driven, two are however: KWin::WindowInfo info = KWin::windowInfo( parentWidget()->winId() ); if( !info.isMinimized() ) break; } //FALL THROUGH case QEvent::Show: if( isShown() ) { //only when shown means thaman:mkreiserfst using the global Show/Hide Playlist shortcut //when in the tray doesn't effect the state of the PlaylistButton //this is a good thing, but we have to set the state correctly when we are shown m_pPlaylistButton->blockSignals( true ); m_pPlaylistButton->setOn( e->type() == QEvent::Show ); m_pPlaylistButton->blockSignals( false ); } break; default: break; } return false;}void PlayerWidget::paintEvent( QPaintEvent* ){ //uses widget's font and foregroundColor() - see ctor QPainter p( this ); if( !m_minimalView ) p.drawText( 6, 68, m_rateString ); bitBlt( m_pScrollFrame, 0, 0, &m_scrollBuffer ); bitBlt( m_pTimeLabel, 0, 0, &m_timeBuffer );}void PlayerWidget::contextMenuEvent( QMouseEvent *e ){ Amarok::Menu::instance()->exec( e->globalPos() );}void PlayerWidget::mousePressEvent( QMouseEvent *e ){ if ( e->button() == QMouseEvent::RightButton ) { //Amarok::Menu::instance()->exec( e->globalPos() ); } else if ( m_pAnalyzer->geometry().contains( e->pos() ) ) { createAnalyzer( e->state() & Qt::ControlButton ? -1 : +1 ); } else { QRect rect = m_pTimeLabel->geometry(); rect |= m_pTimeSign->geometry(); if ( rect.contains( e->pos() ) ) { AmarokConfig::setLeftTimeDisplayRemaining( !AmarokConfig::leftTimeDisplayRemaining() ); timeDisplay( EngineController::engine()->position() ); } else m_startDragPos = e->pos(); }}void PlayerWidget::mouseMoveEvent( QMouseEvent *e ){ if( e->state() & Qt::LeftButton ) { const int distance = (e->pos() - m_startDragPos).manhattanLength(); if( distance > QApplication::startDragDistance() ) startDrag(); }}// SLOTS ---------------------------------------------------------------------void PlayerWidget::createAnalyzer( int increment ){ AmarokConfig::setCurrentAnalyzer( AmarokConfig::currentAnalyzer() + increment ); delete m_pAnalyzer; m_pAnalyzer = Analyzer::Factory::createAnalyzer( this ); m_pAnalyzer->setGeometry( 120,40, 168,56 ); QToolTip::add( m_pAnalyzer, i18n( "Click for more analyzers, press 'd' to detach." ) ); m_pAnalyzer->show();}void PlayerWidget::startDrag(){ QDragObject *d = new QTextDrag( EngineController::instance()->bundle().prettyTitle(), this ); d->dragCopy(); // Qt will delete d for us.}void PlayerWidget::slotShowEqualizer( bool show ) //SLOT{ if( show ) { m_pButtonEq->setOff(); if ( !EngineController::hasEngineProperty( "HasEqualizer" ) ) KMessageBox::sorry( 0, i18n( "Equalizer is not available with this engine." ) ); else QTimer::singleShot( 0, kapp, SLOT( slotConfigEqualizer() ) ); }}//////////////////////////////////////////////////////////////////////////////////////////// CLASS NavButton//////////////////////////////////////////////////////////////////////////////////////////#include <kiconeffect.h>#include <kimageeffect.h>NavButton::NavButton( QWidget *parent, const QString &icon, KAction *action ) : QToolButton( parent ) , m_glowIndex( 0 ){ // Prevent flicker setWFlags( Qt::WNoAutoErase ); QPixmap pixmap( getPNG( "b_" + icon ) ); KIconEffect ie; // Tint icon blueish for "off" state m_pixmapOff = ie.apply( pixmap, KIconEffect::Colorize, 0.5, QColor( 0x30, 0x10, 0xff ), false ); // Tint gray and make pseudo-transparent for "disabled" state m_pixmapDisabled = ie.apply( pixmap, KIconEffect::ToGray, 0.7, QColor(), true ); int r = 0x20, g = 0x10, b = 0xff; float percentRed = 0.0; QPixmap temp; // Precalculate pixmaps for "on" icon state for ( int i = 0; i < NUMPIXMAPS; i++ ) { QImage img = pixmap.convertToImage(); temp = KImageEffect::channelIntensity( img, percentRed, KImageEffect::Red ); temp = ie.apply( temp, KIconEffect::Colorize, 1.0, QColor( r, 0x10, 0x30 ), false ); temp = ie.apply( temp, KIconEffect::Colorize, 1.0, QColor( r, g, b ), false ); // Create new pixmap on the heap and add pointer to list m_glowPixmaps.append( temp ); percentRed = percentRed + 1.0 / NUMPIXMAPS; r += 14; g += 2; b -= 0; } // And the the same reversed for ( int i = NUMPIXMAPS - 1; i > 0; i-- ) { QPixmap temp = m_glowPixmaps[i]; m_glowPixmaps.append(temp); } // This is just for initialization QIconSet iconSet; iconSet.setPixmap( pixmap, QIconSet::Automatic, QIconSet::Normal, QIconSet::Off ); iconSet.setPixmap( pixmap, QIconSet::Automatic, QIconSet::Normal, QIconSet::On ); iconSet.setPixmap( pixmap, QIconSet::Automatic, QIconSet::Disabled, QIconSet::Off ); setIconSet( iconSet ); setFocusPolicy( QWidget::NoFocus ); setEnabled( action->isEnabled() ); connect( action, SIGNAL( enabled( bool ) ), SLOT( setEnabled( bool ) ) ); connect( this, SIGNAL( clicked() ), action, SLOT( activate() ) ); startTimer( GLOW_INTERVAL );}void NavButton::timerEvent( QTimerEvent* ){ if ( isOn() ) { m_glowIndex++; m_glowIndex %= NUMPIXMAPS * 2 - 1; // Repaint widget with new pixmap update(); }}void NavButton::drawButtonLabel( QPainter* p ){ int x = width() / 2 - m_pixmapOff.width() / 2; int y = height() / 2 - m_pixmapOff.height() / 2; if ( !isEnabled() ) p->drawPixmap( x, y, m_pixmapDisabled ); else if ( isOn() ) p->drawPixmap( x + 2, y + 1, m_glowPixmaps[m_glowIndex] ); else p->drawPixmap( x, y, m_pixmapOff );}//////////////////////////////////////////////////////////////////////////////////////////// CLASS IconButton//////////////////////////////////////////////////////////////////////////////////////////IconButton::IconButton( QWidget *parent, const QString &icon, const char *signal ) : QButton( parent ) , m_up( getPNG( icon + "_active2" ) ) //TODO rename files better (like the right way round for one!) , m_down( getPNG( icon + "_inactive2" ) ){ connect( this, SIGNAL(toggled( bool )), parent, signal ); setToggleButton( true ); setFocusPolicy( NoFocus ); //we have no way to show focus on these widgets currently}IconButton::IconButton( QWidget *parent, const QString &icon, QObject* receiver, const char *slot ) : QButton( parent ) , m_up( getPNG( icon + "_active2" ) ) //TODO rename files better (like the right way round for one!) , m_down( getPNG( icon + "_inactive2" ) ){ connect( this, SIGNAL(toggled( bool )), receiver, slot ); setToggleButton( true ); setFocusPolicy( NoFocus ); //we have no way to show focus on these widgets currently}void IconButton::drawButton( QPainter *p ){ p->drawPixmap( 0, 0, (isOn()||isDown()) ? m_down : m_up );}#include "playerwindow.moc"
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -