Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add stop/start and user default option for timeout of timed QgsMessag…
…eBars

- Add pause/start icons to timeout countdown progress bar
- Add user-defined option for general message timeouts
- [API] Add get/set methods for general message timeouts to QgisApp
  • Loading branch information
dakcarto committed Jan 13, 2013
1 parent 98d8d50 commit 3ea0a37
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 13 deletions.
2 changes: 2 additions & 0 deletions images/images.qrc
Expand Up @@ -225,6 +225,8 @@
<file>themes/default/mIconRenderingDisabled.png</file>
<file>themes/default/mIconSymbology.png</file>
<file>themes/default/mIconTableLayer.png</file>
<file>themes/default/mIconTimerPause.png</file>
<file>themes/default/mIconTimerContinue.png</file>
<file>themes/default/mIconUnknownLayerType.png</file>
<file>themes/default/mIconVectorLayer.png</file>
<file>themes/default/mIconWaitingForLayerType.png</file>
Expand Down
Binary file added images/themes/default/mIconTimerContinue.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/themes/default/mIconTimerPause.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -488,6 +488,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
mInfoBar = new QgsMessageBar( centralWidget );
mInfoBar->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
centralLayout->addWidget( mInfoBar, 0, 0, 1, 1 );
mInfoBarTimeout = settings.value( "/qgis/messageTimeout", 5 ).toInt();

//set the focus to the map canvas
mMapCanvas->setFocus();
Expand Down Expand Up @@ -4042,7 +4043,7 @@ void QgisApp::labeling()
messageBar()->pushMessage( tr( "Labeling Options" ),
tr( "Please select a vector layer first" ),
QgsMessageBar::INFO,
5 );
messageTimeout() );
return;
}

Expand Down
12 changes: 12 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -398,6 +398,10 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
* @note added in 1.9 */
QList<QgsMapLayer *> editableLayers( bool modified = false ) const;

/** Get timeout for timed messages: default of 5 seconds
* @note added in 1.9 */
int messageTimeout() { return mMessageTimeout; }

#ifdef Q_OS_WIN
//! ugly hack
void skipNextContextMenuEvent();
Expand Down Expand Up @@ -539,6 +543,11 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
//! layer selection changed
void legendLayerSelectionChanged( void );

/** Set timeout for timed messages
* @param t timeout in seconds
* @note added in 1.9 */
void setMessageTimeout( int t ) { mMessageTimeout = t; }

//! Watch for QFileOpenEvent.
virtual bool event( QEvent * event );

Expand Down Expand Up @@ -1333,6 +1342,9 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
QgsMessageBar *mInfoBar;
QWidget *mMacrosWarn;

//! timeout for timed messages
int mMessageTimeout;

#ifdef HAVE_TOUCH
bool gestureEvent( QGestureEvent *event );
void tapAndHoldTriggered( QTapAndHoldGesture *gesture );
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsmaptooledit.cpp
Expand Up @@ -127,7 +127,7 @@ void QgsMapToolEdit::notifyNotVectorLayer()
tr( "No active vector layer" ),
tr( "Choose a vector layer in the legend" ),
QgsMessageBar::INFO,
5 );
QgisApp::instance()->messageTimeout() );
}

void QgsMapToolEdit::notifyNotEditableLayer()
Expand All @@ -136,5 +136,5 @@ void QgsMapToolEdit::notifyNotEditableLayer()
tr( "Layer not editable" ),
tr( "Use 'Toggle Editing' to make it editable" ),
QgsMessageBar::INFO,
5 );
QgisApp::instance()->messageTimeout() );
}
2 changes: 1 addition & 1 deletion src/app/qgsmaptoolselectutils.cpp
Expand Up @@ -41,7 +41,7 @@ QgsVectorLayer* QgsMapToolSelectUtils::getCurrentVectorLayer( QgsMapCanvas* canv
QObject::tr( "No active vector layer" ),
QObject::tr( "To select features, choose a vector layer in the legend" ),
QgsMessageBar::INFO,
5 );
QgisApp::instance()->messageTimeout() );
}
return vlayer;
}
Expand Down
5 changes: 5 additions & 0 deletions src/app/qgsoptions.cpp
Expand Up @@ -462,6 +462,8 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
}
blockSignals( false );

mInfoBarTimeoutSpnBx->setValue( settings.value( "/qgis/messageTimeout", 5 ).toInt() );

QString name = QApplication::style()->objectName();
cmbStyle->setCurrentIndex( cmbStyle->findText( name, Qt::MatchFixedString ) );
//set the state of the checkboxes
Expand Down Expand Up @@ -1078,6 +1080,9 @@ void QgsOptions::saveOptions()
settings.setValue( "/fontFamily", fontFamily );
QgisApp::instance()->setAppStyleSheet();

settings.setValue( "/qgis/messageTimeout", mInfoBarTimeoutSpnBx->value() );
QgisApp::instance()->setMessageTimeout( mInfoBarTimeoutSpnBx->value() );

// rasters settings
settings.setValue( "/Raster/defaultRedBand", spnRed->value() );
settings.setValue( "/Raster/defaultGreenBand", spnGreen->value() );
Expand Down
36 changes: 28 additions & 8 deletions src/gui/qgsmessagebar.cpp
Expand Up @@ -27,6 +27,7 @@
#include <QTimer>
#include <QGridLayout>
#include <QMenu>
#include <QMouseEvent>


QgsMessageBar::QgsMessageBar( QWidget *parent )
Expand All @@ -45,15 +46,14 @@ QgsMessageBar::QgsMessageBar( QWidget *parent )

mCountProgress = new QProgressBar( this );

mCountProgress->setStyleSheet( "QProgressBar { border: 1px solid rgba(0, 0, 0, 75%);"
" border-radius: 2px; background: rgba(0, 0, 0, 0); }"
"QProgressBar::chunk { background-color: rgba(0, 0, 0, 50%); width: 5px; }" );
mCountStyleSheet = QString( "QProgressBar { border: 1px solid rgba(0, 0, 0, 75%);"
" border-radius: 2px; background: rgba(0, 0, 0, 0);"
" image: url(:/images/themes/default/%1) }"
"QProgressBar::chunk { background-color: rgba(0, 0, 0, 30%); width: 5px; }" );

mCountProgress->setStyleSheet( mCountStyleSheet.arg( "mIconTimerPause.png" ) );
mCountProgress->setObjectName( "mCountdown" );
mCountProgress->setToolTip( tr( "Countdown" ) );
mCountProgress->setMinimumWidth( 25 );
mCountProgress->setMaximumWidth( 25 );
mCountProgress->setMinimumHeight( 10 );
mCountProgress->setMaximumHeight( 10 );
mCountProgress->setFixedSize( 25, 14 );
mCountProgress->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
mCountProgress->setTextVisible( false );
mCountProgress->setRange( 0, 5 );
Expand Down Expand Up @@ -100,6 +100,25 @@ QgsMessageBar::~QgsMessageBar()
{
}

void QgsMessageBar::mousePressEvent( QMouseEvent * e )
{
// stop/start mCountdownTimer
QProgressBar *pb = static_cast<QProgressBar *>( childAt( e->pos() ) );
if ( pb && pb->objectName() == QString( "mCountdown" ) && e->button() == Qt::LeftButton )
{
if ( mCountdownTimer->isActive() )
{
mCountdownTimer->stop();
pb->setStyleSheet( mCountStyleSheet.arg( "mIconTimerContinue.png" ) );
}
else
{
mCountdownTimer->start();
pb->setStyleSheet( mCountStyleSheet.arg( "mIconTimerPause.png" ) );
}
}
}

void QgsMessageBar::popItem( QgsMessageBarItem *item )
{
Q_ASSERT( item );
Expand Down Expand Up @@ -340,6 +359,7 @@ void QgsMessageBar::resetCountdown()
if ( mCountdownTimer->isActive() )
mCountdownTimer->stop();

mCountProgress->setStyleSheet( mCountStyleSheet.arg( "mIconTimerPause.png" ) );
mCountProgress->setVisible( false );
}

Expand Down
4 changes: 4 additions & 0 deletions src/gui/qgsmessagebar.h
Expand Up @@ -101,6 +101,9 @@ class GUI_EXPORT QgsMessageBar: public QFrame
*/
bool clearWidgets();

protected:
void mousePressEvent( QMouseEvent * e );

private:
class QgsMessageBarItem
{
Expand Down Expand Up @@ -133,6 +136,7 @@ class GUI_EXPORT QgsMessageBar: public QFrame
QAction *mActionCloseAll;
QTimer *mCountdownTimer;
QProgressBar *mCountProgress;
QString mCountStyleSheet;

private slots:
//! updates count of items in widget list
Expand Down
48 changes: 47 additions & 1 deletion src/ui/qgsoptionsbase.ui
Expand Up @@ -258,7 +258,7 @@
<x>0</x>
<y>0</y>
<width>690</width>
<height>1036</height>
<height>1073</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
Expand Down Expand Up @@ -465,6 +465,52 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_28">
<item>
<widget class="QLabel" name="mInfoBarTimeoutLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Timeout for timed messages or dialogs</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_13">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QSpinBox" name="mInfoBarTimeoutSpnBx">
<property name="suffix">
<string> s</string>
</property>
<property name="minimum">
<number>2</number>
</property>
<property name="maximum">
<number>20</number>
</property>
<property name="value">
<number>5</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
Expand Down

2 comments on commit 3ea0a37

@dakcarto
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

The countdown progress bar that can be paused/started should look like this (here on Mac):

http://drive.dakotacarto.com/qgis/messagebar_timeout-running.png
http://drive.dakotacarto.com/qgis/messagebar_timeout-paused.png

If it doesn't, or the pause/start controls aren't showing up, please let me know. Thanks.

@dakcarto
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, the simplest way to test the countdown progress bar for the QgsMessageBar is to open a blank project and click the Adv Labeling Options tool button in the tool bar. That should give you a 5-second (default) timeout message about selecting a vector layer.

Please sign in to comment.