statusbarbase.cpp

来自「Amarok是一款在LINUX或其他类UNIX操作系统中运行的音频播放器软件。 」· C++ 代码 · 共 679 行 · 第 1/2 页

CPP
679
字号
/*************************************************************************** *   Copyright (C) 2005 by Max Howell <max.howell@methylblue.com>          * *   Copyright (C) 2005 by Ian Monroe <ian@monroe.nu>                      * *                                                                         * *   This program is free software; you can redistribute it and/or modify  * *   it under the terms of the GNU General Public License as published by  * *   the Free Software Foundation; either version 2 of the License, or     * *   (at your option) any later version.                                   * *                                                                         * *   This program is distributed in the hope that it will be useful,       * *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * *   GNU General Public License for more details.                          * *                                                                         * *   You should have received a copy of the GNU General Public License     * *   along with this program; if not, write to the                         * *   Free Software Foundation, Inc.,                                       * *   51 Franklin Steet, Fifth Floor, Boston, MA  02111-1307, USA.             * ***************************************************************************/#define DEBUG_PREFIX "StatusBar"#include "amarok.h"#include "debug.h"#include "squeezedtextlabel.h"#include "statusBarBase.h"#include "threadmanager.h"#include "enginecontroller.h"#include <kio/job.h>#include <kiconloader.h>#include <klocale.h>#include <kstdguiitem.h>#include <qapplication.h>#include <qdatetime.h>      //writeLogFile()#include <qfile.h>          //writeLogFile()#include <qpushbutton.h>#include <qlabel.h>#include <qlayout.h>#include <qmessagebox.h>#include <qobjectlist.h> //polish()#include <qpainter.h>#include <qpalette.h>#include <qprogressbar.h>#include <qstyle.h>   //class CloseButton#include <qtimer.h>#include <qtoolbutton.h>#include <qtooltip.h> //QToolTip::palette()#include <qvbox.h>//segregated classes#include "popupMessage.h"#include "progressBar.h"namespace KDE {namespace SingleShotPool{    static void startTimer( int timeout, QObject *receiver, const char *slot )    {        QTimer *timer = static_cast<QTimer*>( receiver->child( slot ) );        if( !timer ) {            timer = new QTimer( receiver, slot );            receiver->connect( timer, SIGNAL(timeout()), slot );        }        timer->start( timeout, true );    }    static inline bool isActive( QObject *parent, const char *slot )    {        QTimer *timer = static_cast<QTimer*>( parent->child( slot ) );        return timer && timer->isA( "QTimer" ) && timer->isActive();    }}//TODO allow for uncertain progress periodsStatusBar::StatusBar( QWidget *parent, const char *name )        : QWidget( parent, name )        , m_logCounter( -1 ){    QBoxLayout *mainlayout = new QHBoxLayout( this, 2, /*spacing*/5 );    //we need extra spacing due to the way we paint the surrounding boxes    QBoxLayout *layout = new QHBoxLayout( mainlayout, /*spacing*/5 );    QHBox *statusBarTextBox = new QHBox( this, "statusBarTextBox" );    m_mainTextLabel = new KDE::SqueezedTextLabel( statusBarTextBox, "mainTextLabel" );    QToolButton *shortLongButton = new QToolButton( statusBarTextBox, "shortLongButton" );    shortLongButton->hide();    QHBox *mainProgressBarBox = new QHBox( this, "progressBox" );    QToolButton *b1 = new QToolButton( mainProgressBarBox, "cancelButton" );    m_mainProgressBar  = new QProgressBar( mainProgressBarBox, "mainProgressBar" );    QToolButton *b2 = new QToolButton( mainProgressBarBox, "showAllProgressDetails" );    mainProgressBarBox->setSpacing( 2 );    mainProgressBarBox->hide();    layout->add( statusBarTextBox );    layout->add( mainProgressBarBox );    layout->setStretchFactor( statusBarTextBox, 3 );    layout->setStretchFactor( mainProgressBarBox, 1 );    m_otherWidgetLayout = new QHBoxLayout( mainlayout, /*spacing*/5 );    mainlayout->setStretchFactor( layout, 6 );    mainlayout->setStretchFactor( m_otherWidgetLayout, 4 );    shortLongButton->setIconSet( SmallIconSet( "edit_add" ) );    QToolTip::add( shortLongButton, i18n( "Show details" ) );    connect( shortLongButton, SIGNAL(clicked()), SLOT(showShortLongDetails()) );    b1->setIconSet( SmallIconSet( "cancel" ) );    b2->setIconSet( SmallIconSet( "2uparrow") );    b2->setToggleButton( true );    QToolTip::add( b1, i18n( "Abort all background-operations" ) );    QToolTip::add( b2, i18n( "Show progress detail" ) );    connect( b1, SIGNAL(clicked()), SLOT(abortAllProgressOperations()) );    connect( b2, SIGNAL(toggled( bool )), SLOT(toggleProgressWindow( bool )) );    m_popupProgress = new OverlayWidget( this, mainProgressBarBox, "popupProgress" );    m_popupProgress->setMargin( 1 );    m_popupProgress->setFrameStyle( QFrame::Panel | QFrame::Raised );    m_popupProgress->setFrameShape( QFrame::StyledPanel );    m_popupProgress->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );   (new QGridLayout( m_popupProgress, 1 /*rows*/, 3 /*cols*/, 6, 3 ))->setAutoAdd( true );}voidStatusBar::addWidget( QWidget *widget ){    m_otherWidgetLayout->add( widget );}/// reimplemented functionsvoidStatusBar::polish(){    QWidget::polish();    int h = 0;    QObjectList *list = queryList( "QWidget", 0, false, false );    for( QObject * o = list->first(); o; o = list->next() ) {        int _h = static_cast<QWidget*>( o ) ->minimumSizeHint().height();        if ( _h > h )            h = _h;//         debug() << o->className() << ", " << o->name() << ": " << _h << ": " << static_cast<QWidget*>(o)->minimumHeight() << endl;        if ( o->inherits( "QLabel" ) )            static_cast<QLabel*>(o)->setIndent( 4 );    }    h -= 4; // it's too big usually    for ( QObject * o = list->first(); o; o = list->next() )        static_cast<QWidget*>(o)->setFixedHeight( h );    delete list;}voidStatusBar::paintEvent( QPaintEvent* ){    QObjectList *list = queryList( "QWidget", 0, false, false );    QPainter p( this );    for( QObject * o = list->first(); o; o = list->next() ) {        QWidget *w = static_cast<QWidget*>( o );        if ( !w->isVisible() )            continue;        style().drawPrimitive(                QStyle::PE_StatusBarSection,                &p,                QRect( w->x() - 1, w->y() - 1, w->width() + 2, w->height() + 2 ),                colorGroup(),                QStyle::Style_Default,                QStyleOption( w ) );    }    delete list;}boolStatusBar::event( QEvent *e ){    if ( e->type() == QEvent::LayoutHint )        update();    return QWidget::event( e );}/// Messaging systemvoidStatusBar::setMainText( const QString &text ){    SHOULD_BE_GUI    m_mainText = text;    // it may not be appropriate for us to set the mainText yet    resetMainText();}voidStatusBar::shortMessage( const QString &text, bool longShort ){    SHOULD_BE_GUI    m_mainTextLabel->setText( text );    m_mainTextLabel->setPalette( QToolTip::palette() );    SingleShotPool::startTimer( longShort ? 8000 : 5000, this, SLOT(resetMainText()) );    writeLogFile( text );}voidStatusBar::resetMainText(){//     if( sender() )//         debug() << sender()->name() << endl;    // don't reset if we are showing a shortMessage    if( SingleShotPool::isActive( this, SLOT(resetMainText()) ) )        return;    m_mainTextLabel->unsetPalette();    shortLongButton()->hide();    if( allDone() )        m_mainTextLabel->setText( m_mainText );    else {        ProgressBar *bar = 0;        uint count = 0;        foreachType( ProgressMap, m_progressMap )            if( !(*it)->m_done ) {                bar = *it;                count++;            }        if( count == 1 )            m_mainTextLabel->setText( bar->description() + i18n("...") );        else            m_mainTextLabel->setText( i18n("Multiple background-tasks running") );    }}voidStatusBar::shortLongMessage( const QString &_short, const QString &_long, int type ){    SHOULD_BE_GUI    m_shortLongType = type;    if( !_short.isEmpty() )        shortMessage( _short, true );    if ( !_long.isEmpty() ) {        m_shortLongText = _long;        shortLongButton()->show();        writeLogFile( _long );    }}voidStatusBar::longMessage( const QString &text, int type ){    SHOULD_BE_GUI    if( text.isEmpty() )        return;    PopupMessage *message;    message = new PopupMessage( this, m_mainTextLabel );    connect( message, SIGNAL(destroyed(QObject *)), this, SLOT(popupDeleted(QObject *)) );    message->setText( text );    QString image;    switch( type )    {        case Information:        case Question:            image = KGlobal::iconLoader()->iconPath( "messagebox_info", -KIcon::SizeHuge );            break;        case Sorry:        case Warning:            image = KGlobal::iconLoader()->iconPath( "messagebox_warning", -KIcon::SizeHuge );            break;        case Error:            image = KGlobal::iconLoader()->iconPath( "messagebox_critical", -KIcon::SizeHuge );            // don't hide error messages.//             message->setTimeout( 0 );            break;    }    if( !image.isEmpty() )        message->setImage( image );    if ( !m_messageQueue.isEmpty() )         message->stackUnder( m_messageQueue.last() );    message->display();    raise();    m_messageQueue += message;    writeLogFile( text );}voidStatusBar::popupDeleted( QObject *obj ){    m_messageQueue.remove( static_cast<QWidget*>( obj ) );}voidStatusBar::longMessageThreadSafe( const QString &text, int /*type*/ ){    QCustomEvent * e = new QCustomEvent( 1000 );    e->setData( new QString( text ) );

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?