24 #include <QStackedWidget>
25 #include <QProgressBar>
26 #include <QToolButton>
28 #include <QGridLayout>
30 #include <QMouseEvent>
34 : QFrame( parent ), mCurrentItem( NULL )
36 QPalette pal = palette();
37 pal.setBrush( backgroundRole(), pal.window() );
39 setAutoFillBackground(
true );
40 setFrameShape( QFrame::StyledPanel );
41 setFrameShadow( QFrame::Plain );
43 mLayout =
new QGridLayout(
this );
44 mLayout->setContentsMargins( 9, 1, 9, 1 );
47 mCountProgress =
new QProgressBar(
this );
48 mCountStyleSheet = QString(
"QProgressBar { border: 1px solid rgba(0, 0, 0, 75%);"
49 " border-radius: 2px; background: rgba(0, 0, 0, 0);"
50 " image: url(:/images/themes/default/%1) }"
51 "QProgressBar::chunk { background-color: rgba(0, 0, 0, 30%); width: 5px; }" );
53 mCountProgress->setStyleSheet( mCountStyleSheet.arg(
"mIconTimerPause.png" ) );
54 mCountProgress->setObjectName(
"mCountdown" );
55 mCountProgress->setFixedSize( 25, 14 );
56 mCountProgress->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
57 mCountProgress->setTextVisible(
false );
58 mCountProgress->setRange( 0, 5 );
59 mCountProgress->setHidden(
true );
60 mLayout->addWidget( mCountProgress, 0, 0, 1, 1 );
62 mItemCount =
new QLabel(
this );
63 mItemCount->setObjectName(
"mItemCount" );
64 mItemCount->setToolTip(
tr(
"Remaining messages" ) );
65 mItemCount->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Preferred );
66 mLayout->addWidget( mItemCount, 0, 2, 1, 1 );
68 mCloseMenu =
new QMenu(
this );
69 mCloseMenu->setObjectName(
"mCloseMenu" );
70 mActionCloseAll =
new QAction(
tr(
"Close all" ),
this );
71 mCloseMenu->addAction( mActionCloseAll );
72 connect( mActionCloseAll, SIGNAL( triggered() ),
this, SLOT(
clearWidgets() ) );
74 mCloseBtn =
new QToolButton(
this );
75 mCloseMenu->setObjectName(
"mCloseMenu" );
76 mCloseBtn->setToolTip(
tr(
"Close" ) );
77 mCloseBtn->setMinimumWidth( 40 );
78 mCloseBtn->setStyleSheet(
79 "QToolButton { background-color: rgba(0, 0, 0, 0); }"
80 "QToolButton::menu-button { background-color: rgba(0, 0, 0, 0); }" );
81 mCloseBtn->setCursor( Qt::PointingHandCursor );
83 mCloseBtn->setIconSize( QSize( 18, 18 ) );
84 mCloseBtn->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Maximum );
85 mCloseBtn->setMenu( mCloseMenu );
86 mCloseBtn->setPopupMode( QToolButton::MenuButtonPopup );
87 connect( mCloseBtn, SIGNAL( clicked() ),
this, SLOT(
popWidget() ) );
88 mLayout->addWidget( mCloseBtn, 0, 3, 1, 1 );
90 mCountdownTimer =
new QTimer(
this );
91 mCountdownTimer->setInterval( 1000 );
92 connect( mCountdownTimer, SIGNAL( timeout() ),
this, SLOT( updateCountdown() ) );
107 if ( mCountProgress == childAt( e->pos() ) && e->button() == Qt::LeftButton )
109 if ( mCountdownTimer->isActive() )
111 mCountdownTimer->stop();
112 mCountProgress->setStyleSheet( mCountStyleSheet.arg(
"mIconTimerContinue.png" ) );
116 mCountdownTimer->start();
117 mCountProgress->setStyleSheet( mCountStyleSheet.arg(
"mIconTimerPause.png" ) );
126 if ( item != mCurrentItem && !mItems.contains( item ) )
129 if ( item == mCurrentItem )
133 QWidget *widget =
dynamic_cast<QWidget*
>( mCurrentItem );
134 mLayout->removeWidget( widget );
135 mCurrentItem->hide();
136 disconnect( mCurrentItem, SIGNAL( styleChanged( QString ) ),
this, SLOT( setStyleSheet( QString ) ) );
141 if ( !mItems.isEmpty() )
143 showItem( mItems.first() );
152 mItems.removeOne( item );
160 if ( !item || !mCurrentItem )
163 if ( item == mCurrentItem )
165 popItem( mCurrentItem );
171 if ( existingItem == item )
173 mItems.removeOne( existingItem );
197 if ( !mCurrentItem && mItems.empty() )
200 while ( mItems.count() > 0 )
206 return !mCurrentItem && mItems.empty();
233 if ( mCurrentItem != 0 )
234 disconnect( mCurrentItem, SIGNAL( styleChanged( QString ) ),
this, SLOT( setStyleSheet( QString ) ) );
236 if ( item == mCurrentItem )
239 if ( mItems.contains( item ) )
240 mItems.removeOne( item );
244 mItems.prepend( mCurrentItem );
245 mLayout->removeWidget( mCurrentItem );
246 mCurrentItem->hide();
250 mLayout->addWidget( item, 0, 1, 1, 1 );
251 mCurrentItem->show();
255 mCountProgress->setRange( 0, item->
duration() );
256 mCountProgress->setValue( item->
duration() );
257 mCountProgress->setVisible(
true );
258 mCountdownTimer->start();
261 connect( mCurrentItem, SIGNAL( styleChanged( QString ) ),
this, SLOT( setStyleSheet( QString ) ) );
314 void QgsMessageBar::updateCountdown()
316 if ( !mCountdownTimer->isActive() )
321 if ( mCountProgress->value() < 2 )
327 mCountProgress->setValue( mCountProgress->value() - 1 );
331 void QgsMessageBar::resetCountdown()
333 if ( mCountdownTimer->isActive() )
334 mCountdownTimer->stop();
336 mCountProgress->setStyleSheet( mCountStyleSheet.arg(
"mIconTimerPause.png" ) );
337 mCountProgress->setVisible(
false );
340 void QgsMessageBar::updateItemCount()
342 mItemCount->setText( mItems.count() > 0 ?
tr(
"%n more",
"unread messages", mItems.count() ) : QString(
"" ) );
345 mCloseBtn->setMenu( mItems.count() > 0 ? mCloseMenu : 0 );
346 mCloseBtn->setPopupMode( mItems.count() > 0 ? QToolButton::MenuButtonPopup : QToolButton::DelayedPopup );