Skip to content

Commit 3ea0a37

Browse files
committedJan 13, 2013
Add stop/start and user default option for timeout of timed QgsMessageBars
- 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
1 parent 98d8d50 commit 3ea0a37

File tree

11 files changed

+103
-13
lines changed

11 files changed

+103
-13
lines changed
 

‎images/images.qrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@
225225
<file>themes/default/mIconRenderingDisabled.png</file>
226226
<file>themes/default/mIconSymbology.png</file>
227227
<file>themes/default/mIconTableLayer.png</file>
228+
<file>themes/default/mIconTimerPause.png</file>
229+
<file>themes/default/mIconTimerContinue.png</file>
228230
<file>themes/default/mIconUnknownLayerType.png</file>
229231
<file>themes/default/mIconVectorLayer.png</file>
230232
<file>themes/default/mIconWaitingForLayerType.png</file>
207 Bytes
Loading
199 Bytes
Loading

‎src/app/qgisapp.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
488488
mInfoBar = new QgsMessageBar( centralWidget );
489489
mInfoBar->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
490490
centralLayout->addWidget( mInfoBar, 0, 0, 1, 1 );
491+
mInfoBarTimeout = settings.value( "/qgis/messageTimeout", 5 ).toInt();
491492

492493
//set the focus to the map canvas
493494
mMapCanvas->setFocus();
@@ -4042,7 +4043,7 @@ void QgisApp::labeling()
40424043
messageBar()->pushMessage( tr( "Labeling Options" ),
40434044
tr( "Please select a vector layer first" ),
40444045
QgsMessageBar::INFO,
4045-
5 );
4046+
messageTimeout() );
40464047
return;
40474048
}
40484049

‎src/app/qgisapp.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,10 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
398398
* @note added in 1.9 */
399399
QList<QgsMapLayer *> editableLayers( bool modified = false ) const;
400400

401+
/** Get timeout for timed messages: default of 5 seconds
402+
* @note added in 1.9 */
403+
int messageTimeout() { return mMessageTimeout; }
404+
401405
#ifdef Q_OS_WIN
402406
//! ugly hack
403407
void skipNextContextMenuEvent();
@@ -539,6 +543,11 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
539543
//! layer selection changed
540544
void legendLayerSelectionChanged( void );
541545

546+
/** Set timeout for timed messages
547+
* @param t timeout in seconds
548+
* @note added in 1.9 */
549+
void setMessageTimeout( int t ) { mMessageTimeout = t; }
550+
542551
//! Watch for QFileOpenEvent.
543552
virtual bool event( QEvent * event );
544553

@@ -1333,6 +1342,9 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
13331342
QgsMessageBar *mInfoBar;
13341343
QWidget *mMacrosWarn;
13351344

1345+
//! timeout for timed messages
1346+
int mMessageTimeout;
1347+
13361348
#ifdef HAVE_TOUCH
13371349
bool gestureEvent( QGestureEvent *event );
13381350
void tapAndHoldTriggered( QTapAndHoldGesture *gesture );

‎src/app/qgsmaptooledit.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ void QgsMapToolEdit::notifyNotVectorLayer()
127127
tr( "No active vector layer" ),
128128
tr( "Choose a vector layer in the legend" ),
129129
QgsMessageBar::INFO,
130-
5 );
130+
QgisApp::instance()->messageTimeout() );
131131
}
132132

133133
void QgsMapToolEdit::notifyNotEditableLayer()
@@ -136,5 +136,5 @@ void QgsMapToolEdit::notifyNotEditableLayer()
136136
tr( "Layer not editable" ),
137137
tr( "Use 'Toggle Editing' to make it editable" ),
138138
QgsMessageBar::INFO,
139-
5 );
139+
QgisApp::instance()->messageTimeout() );
140140
}

‎src/app/qgsmaptoolselectutils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ QgsVectorLayer* QgsMapToolSelectUtils::getCurrentVectorLayer( QgsMapCanvas* canv
4141
QObject::tr( "No active vector layer" ),
4242
QObject::tr( "To select features, choose a vector layer in the legend" ),
4343
QgsMessageBar::INFO,
44-
5 );
44+
QgisApp::instance()->messageTimeout() );
4545
}
4646
return vlayer;
4747
}

‎src/app/qgsoptions.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,8 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
462462
}
463463
blockSignals( false );
464464

465+
mInfoBarTimeoutSpnBx->setValue( settings.value( "/qgis/messageTimeout", 5 ).toInt() );
466+
465467
QString name = QApplication::style()->objectName();
466468
cmbStyle->setCurrentIndex( cmbStyle->findText( name, Qt::MatchFixedString ) );
467469
//set the state of the checkboxes
@@ -1078,6 +1080,9 @@ void QgsOptions::saveOptions()
10781080
settings.setValue( "/fontFamily", fontFamily );
10791081
QgisApp::instance()->setAppStyleSheet();
10801082

1083+
settings.setValue( "/qgis/messageTimeout", mInfoBarTimeoutSpnBx->value() );
1084+
QgisApp::instance()->setMessageTimeout( mInfoBarTimeoutSpnBx->value() );
1085+
10811086
// rasters settings
10821087
settings.setValue( "/Raster/defaultRedBand", spnRed->value() );
10831088
settings.setValue( "/Raster/defaultGreenBand", spnGreen->value() );

‎src/gui/qgsmessagebar.cpp

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <QTimer>
2828
#include <QGridLayout>
2929
#include <QMenu>
30+
#include <QMouseEvent>
3031

3132

3233
QgsMessageBar::QgsMessageBar( QWidget *parent )
@@ -45,15 +46,14 @@ QgsMessageBar::QgsMessageBar( QWidget *parent )
4546

4647
mCountProgress = new QProgressBar( this );
4748

48-
mCountProgress->setStyleSheet( "QProgressBar { border: 1px solid rgba(0, 0, 0, 75%);"
49-
" border-radius: 2px; background: rgba(0, 0, 0, 0); }"
50-
"QProgressBar::chunk { background-color: rgba(0, 0, 0, 50%); width: 5px; }" );
49+
mCountStyleSheet = QString( "QProgressBar { border: 1px solid rgba(0, 0, 0, 75%);"
50+
" border-radius: 2px; background: rgba(0, 0, 0, 0);"
51+
" image: url(:/images/themes/default/%1) }"
52+
"QProgressBar::chunk { background-color: rgba(0, 0, 0, 30%); width: 5px; }" );
53+
54+
mCountProgress->setStyleSheet( mCountStyleSheet.arg( "mIconTimerPause.png" ) );
5155
mCountProgress->setObjectName( "mCountdown" );
52-
mCountProgress->setToolTip( tr( "Countdown" ) );
53-
mCountProgress->setMinimumWidth( 25 );
54-
mCountProgress->setMaximumWidth( 25 );
55-
mCountProgress->setMinimumHeight( 10 );
56-
mCountProgress->setMaximumHeight( 10 );
56+
mCountProgress->setFixedSize( 25, 14 );
5757
mCountProgress->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
5858
mCountProgress->setTextVisible( false );
5959
mCountProgress->setRange( 0, 5 );
@@ -100,6 +100,25 @@ QgsMessageBar::~QgsMessageBar()
100100
{
101101
}
102102

103+
void QgsMessageBar::mousePressEvent( QMouseEvent * e )
104+
{
105+
// stop/start mCountdownTimer
106+
QProgressBar *pb = static_cast<QProgressBar *>( childAt( e->pos() ) );
107+
if ( pb && pb->objectName() == QString( "mCountdown" ) && e->button() == Qt::LeftButton )
108+
{
109+
if ( mCountdownTimer->isActive() )
110+
{
111+
mCountdownTimer->stop();
112+
pb->setStyleSheet( mCountStyleSheet.arg( "mIconTimerContinue.png" ) );
113+
}
114+
else
115+
{
116+
mCountdownTimer->start();
117+
pb->setStyleSheet( mCountStyleSheet.arg( "mIconTimerPause.png" ) );
118+
}
119+
}
120+
}
121+
103122
void QgsMessageBar::popItem( QgsMessageBarItem *item )
104123
{
105124
Q_ASSERT( item );
@@ -340,6 +359,7 @@ void QgsMessageBar::resetCountdown()
340359
if ( mCountdownTimer->isActive() )
341360
mCountdownTimer->stop();
342361

362+
mCountProgress->setStyleSheet( mCountStyleSheet.arg( "mIconTimerPause.png" ) );
343363
mCountProgress->setVisible( false );
344364
}
345365

‎src/gui/qgsmessagebar.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ class GUI_EXPORT QgsMessageBar: public QFrame
101101
*/
102102
bool clearWidgets();
103103

104+
protected:
105+
void mousePressEvent( QMouseEvent * e );
106+
104107
private:
105108
class QgsMessageBarItem
106109
{
@@ -133,6 +136,7 @@ class GUI_EXPORT QgsMessageBar: public QFrame
133136
QAction *mActionCloseAll;
134137
QTimer *mCountdownTimer;
135138
QProgressBar *mCountProgress;
139+
QString mCountStyleSheet;
136140

137141
private slots:
138142
//! updates count of items in widget list

‎src/ui/qgsoptionsbase.ui

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@
258258
<x>0</x>
259259
<y>0</y>
260260
<width>690</width>
261-
<height>1036</height>
261+
<height>1073</height>
262262
</rect>
263263
</property>
264264
<layout class="QGridLayout" name="gridLayout">
@@ -465,6 +465,52 @@
465465
</item>
466466
</layout>
467467
</item>
468+
<item>
469+
<layout class="QHBoxLayout" name="horizontalLayout_28">
470+
<item>
471+
<widget class="QLabel" name="mInfoBarTimeoutLabel">
472+
<property name="sizePolicy">
473+
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
474+
<horstretch>0</horstretch>
475+
<verstretch>0</verstretch>
476+
</sizepolicy>
477+
</property>
478+
<property name="text">
479+
<string>Timeout for timed messages or dialogs</string>
480+
</property>
481+
</widget>
482+
</item>
483+
<item>
484+
<spacer name="horizontalSpacer_13">
485+
<property name="orientation">
486+
<enum>Qt::Horizontal</enum>
487+
</property>
488+
<property name="sizeHint" stdset="0">
489+
<size>
490+
<width>40</width>
491+
<height>20</height>
492+
</size>
493+
</property>
494+
</spacer>
495+
</item>
496+
<item>
497+
<widget class="QSpinBox" name="mInfoBarTimeoutSpnBx">
498+
<property name="suffix">
499+
<string> s</string>
500+
</property>
501+
<property name="minimum">
502+
<number>2</number>
503+
</property>
504+
<property name="maximum">
505+
<number>20</number>
506+
</property>
507+
<property name="value">
508+
<number>5</number>
509+
</property>
510+
</widget>
511+
</item>
512+
</layout>
513+
</item>
468514
<item>
469515
<layout class="QHBoxLayout" name="horizontalLayout_8">
470516
<item>

2 commit comments

Comments
 (2)

dakcarto commented on Jan 13, 2013

@dakcarto
MemberAuthor

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 commented on Jan 13, 2013

@dakcarto
MemberAuthor

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.