diff --git a/articleview.cc b/articleview.cc index f166ba31..9e0ed6eb 100644 --- a/articleview.cc +++ b/articleview.cc @@ -1225,7 +1225,8 @@ void ArticleView::resourceDownloadFinished() } if ( !QDesktopServices::openUrl( QUrl::fromLocalFile( desktopOpenedTempFile ) ) ) - QMessageBox::critical( this, tr( "GoldenDict" ), tr( "Failed to auto-open resource file, try opening manually: %1." ).arg( desktopOpenedTempFile ) ); + QMessageBox::critical( this, tr( "GoldenDict" ), + tr( "Failed to auto-open resource file, try opening manually: %1." ).arg( desktopOpenedTempFile ) ); } // Ok, whatever it was, it's finished. Remove this and any other @@ -1247,8 +1248,9 @@ void ArticleView::resourceDownloadFinished() if ( resourceDownloadRequests.empty() ) { - // No requests suceeded. - QMessageBox::critical( this, tr( "GoldenDict" ), tr( "The referenced resource failed to download." ) ); + emit statusBarMessage( + tr( "WARNING: %1" ).arg( tr( "The referenced resource failed to download." ) ), + 10000, QPixmap( ":/icons/error.png" ) ); } } diff --git a/articleview.hh b/articleview.hh index 1342577d..6f205f2e 100644 --- a/articleview.hh +++ b/articleview.hh @@ -178,7 +178,7 @@ signals: /// switch focus to word input. void typingEvent( QString const & text ); - void statusBarMessage( QString const & message ); + void statusBarMessage( QString const & message, int timeout = 0, QPixmap const & pixmap = QPixmap()); /// Emitted when an article becomes active, /// typically in response to user actions diff --git a/icons/error.png b/icons/error.png new file mode 100644 index 00000000..c8454bfb Binary files /dev/null and b/icons/error.png differ diff --git a/mainstatusbar.cc b/mainstatusbar.cc index 8b905b08..99fe1b47 100644 --- a/mainstatusbar.cc +++ b/mainstatusbar.cc @@ -10,41 +10,46 @@ #include #include -MainStatusBar::MainStatusBar(QWidget *parent) : QWidget(parent) +MainStatusBar::MainStatusBar( QWidget *parent ) : QWidget( parent ) { - textWidget = new QLabel(QString(), this); - textWidget->setObjectName("text"); - textWidget->setFont(QApplication::font("QStatusBar")); - textWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + textWidget = new QLabel( QString(), this ); + textWidget->setObjectName( "text" ); + textWidget->setFont( QApplication::font( "QStatusBar" ) ); + textWidget->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); - picWidget = new QLabel(QString(), this); - picWidget->setObjectName("icon"); - picWidget->setPixmap(QPixmap()); - picWidget->setScaledContents(true); - picWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + picWidget = new QLabel( QString(), this ); + picWidget->setObjectName( "icon" ); + picWidget->setPixmap( QPixmap() ); + picWidget->setScaledContents( true ); + picWidget->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Ignored ); - timer = new QTimer(this); - timer->setSingleShot(true); + timer = new QTimer( this ); + timer->setSingleShot( true ); // layout QHBoxLayout * layout = new QHBoxLayout; - layout->setSpacing(0); - layout->setSizeConstraint(QLayout::SetFixedSize); - layout->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); - layout->setContentsMargins(0, 0, 0, 0); - layout->addWidget(picWidget); - layout->addWidget(textWidget); - setLayout(layout); + layout->setSpacing( 0 ); + layout->setSizeConstraint( QLayout::SetFixedSize ); + layout->setAlignment( Qt::AlignLeft | Qt::AlignVCenter ); + layout->setContentsMargins( 0, 0, 0, 0 ); + layout->addWidget( picWidget ); + layout->addWidget( textWidget ); + setLayout( layout ); parentWidget()->installEventFilter( this ); connect( timer, SIGNAL( timeout() ), SLOT( clearMessage() ) ); } +bool MainStatusBar::hasImage() const +{ + return !picWidget->pixmap()->isNull(); +} + void MainStatusBar::clearMessage() { - textWidget->setText(QString()); - picWidget->setPixmap(QPixmap()); + textWidget->setText( QString() ); + picWidget->setPixmap( QPixmap() ); timer->stop(); refresh(); } @@ -59,6 +64,9 @@ void MainStatusBar::showMessage(const QString & str, int timeout, const QPixmap textWidget->setText( str ); picWidget->setPixmap( pixmap ); + // reload stylesheet + setStyleSheet( styleSheet() ); + if ( timeout > 0 ) { timer->start( timeout ); @@ -71,13 +79,15 @@ void MainStatusBar::refresh() { if ( !currentMessage().isEmpty() ) { + adjustSize(); + if ( !picWidget->pixmap()->isNull() ) { picWidget->setFixedSize( textWidget->height(), textWidget->height() ); } else { - picWidget->setFixedSize( 0, 0); + picWidget->setFixedSize( 0, 0 ); } adjustSize(); @@ -98,7 +108,7 @@ void MainStatusBar::mousePressEvent ( QMouseEvent * ) clearMessage(); } -bool MainStatusBar::eventFilter(QObject *, QEvent * e) +bool MainStatusBar::eventFilter( QObject *, QEvent * e ) { switch ( e->type() ) { case QEvent::Resize: diff --git a/mainstatusbar.hh b/mainstatusbar.hh index 6aa13291..8aaaa46d 100644 --- a/mainstatusbar.hh +++ b/mainstatusbar.hh @@ -12,6 +12,7 @@ class MainStatusBar : public QWidget { Q_OBJECT + Q_PROPERTY(bool hasImage READ hasImage) public: explicit MainStatusBar(QWidget * parent); @@ -36,6 +37,7 @@ private: QTimer * timer; bool eventFilter(QObject *obj, QEvent * event); void refresh(); + bool hasImage() const; }; #endif // MAINSTATUSBAR_HH diff --git a/mainwindow.cc b/mainwindow.cc index 9f828813..d0175a2e 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -918,8 +918,8 @@ ArticleView * MainWindow::createNewTab( bool switchToIt, connect( view, SIGNAL( activeArticleChanged( const QString & ) ), this, SLOT( activeArticleChanged( const QString & ) ) ); - connect( view, SIGNAL( statusBarMessage( const QString & ) ), - this, SLOT( showStatusBarMessage( const QString & ) ) ); + connect( view, SIGNAL( statusBarMessage( QString const &, int, QPixmap const & ) ), + this, SLOT( showStatusBarMessage( QString const &, int, QPixmap const & ) ) ); int index = cfg.preferences.newTabsOpenAfterCurrentOne ? ui.tabWidget->currentIndex() + 1 : ui.tabWidget->count(); @@ -1056,9 +1056,9 @@ void MainWindow::pageLoaded( ArticleView * view ) updateFoundInDictsList(); } -void MainWindow::showStatusBarMessage( const QString & message ) +void MainWindow::showStatusBarMessage( QString const & message, int timeout, QPixmap const & icon ) { - mainStatusBar->showMessage( message, 5000 ); + mainStatusBar->showMessage( message, timeout, icon ); } void MainWindow::tabSwitched( int ) diff --git a/mainwindow.hh b/mainwindow.hh index 740a884b..7a2393e6 100644 --- a/mainwindow.hh +++ b/mainwindow.hh @@ -45,7 +45,7 @@ public: public slots: void messageFromAnotherInstanceReceived( QString const & ); - void showStatusBarMessage ( const QString & ); + void showStatusBarMessage ( QString const &, int, QPixmap const & ); private: diff --git a/qt-style.css b/qt-style.css index b6629a25..1ea522ca 100644 --- a/qt-style.css +++ b/qt-style.css @@ -14,16 +14,6 @@ ArticleView #searchText[noResults="true"] background: #febb7d; } -.ScanPopup #outerFrame -{ - border: 1px solid palette(dark); -} - -.ScanPopup MainStatusBar #text -{ - border: 1px solid palette(dark); -} - MainStatusBar #text { border-top-right-radius: 3px; @@ -41,3 +31,24 @@ MainStatusBar #icon padding-left: 4px; padding-right: 0px; } + +.ScanPopup #outerFrame +{ + border: 1px solid palette(dark); +} + +.ScanPopup MainStatusBar #text +{ + border-bottom: 1px solid palette(dark); +} + +.ScanPopup MainStatusBar[hasImage="false"] #text +{ + border-left: 1px solid palette(dark); +} + +.ScanPopup MainStatusBar #icon +{ + border-left: 1px solid palette(dark); + border-bottom: 1px solid palette(dark); +} diff --git a/resources.qrc b/resources.qrc index a195f678..205b28bd 100644 --- a/resources.qrc +++ b/resources.qrc @@ -45,5 +45,6 @@ icons/windows-list.png CREDITS.txt icons/highlighter.png + icons/error.png diff --git a/scanpopup.cc b/scanpopup.cc index 6e0f9c3b..4aaa0dac 100644 --- a/scanpopup.cc +++ b/scanpopup.cc @@ -126,8 +126,8 @@ ScanPopup::ScanPopup( QWidget * parent, connect( definition, SIGNAL( pageLoaded( ArticleView * ) ), this, SLOT( pageLoaded( ArticleView * ) ) ); - connect( definition, SIGNAL( statusBarMessage( const QString & ) ), - this, SLOT( showStatusBarMessage( const QString & ) ) ); + connect( definition, SIGNAL( statusBarMessage( QString const &, int, QPixmap const & ) ), + this, SLOT( showStatusBarMessage( QString const &, int, QPixmap const & ) ) ); connect( QApplication::clipboard(), SIGNAL( changed( QClipboard::Mode ) ), this, SLOT( clipboardChanged( QClipboard::Mode ) ) ); @@ -705,9 +705,9 @@ void ScanPopup::pageLoaded( ArticleView * ) definition->playSound(); } -void ScanPopup::showStatusBarMessage( const QString & message ) +void ScanPopup::showStatusBarMessage( QString const & message, int timeout, QPixmap const & icon ) { - mainStatusBar->showMessage( message, 10000 ); + mainStatusBar->showMessage( message, timeout, icon ); } void ScanPopup::escapePressed() diff --git a/scanpopup.hh b/scanpopup.hh index 8eb90959..8bd0c32d 100644 --- a/scanpopup.hh +++ b/scanpopup.hh @@ -131,7 +131,7 @@ private slots: void on_pronounceButton_clicked(); void pinButtonClicked( bool checked ); void on_showDictionaryBar_clicked( bool checked ); - void showStatusBarMessage ( const QString & ); + void showStatusBarMessage ( QString const &, int, QPixmap const & ); void hideTimerExpired(); void altModeExpired();