24 #include <QStackedWidget> 25 #include <QProgressBar> 26 #include <QToolButton> 28 #include <QGridLayout> 30 #include <QMouseEvent> 35 , mCurrentItem( nullptr )
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; }" );
54 mCountProgress->
setStyleSheet( mCountStyleSheet.
arg(
"mIconTimerPause.png" ) );
57 mCountProgress->
setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
61 mLayout->
addWidget( mCountProgress, 0, 0, 1, 1 );
63 mItemCount =
new QLabel(
this );
66 mItemCount->
setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Preferred );
67 mLayout->
addWidget( mItemCount, 0, 2, 1, 1 );
69 mCloseMenu =
new QMenu(
this );
71 mActionCloseAll =
new QAction(
tr(
"Close all" ),
this );
80 "QToolButton { background-color: rgba(0, 0, 0, 0); }" 81 "QToolButton::menu-button { background-color: rgba(0, 0, 0, 0); }" );
82 mCloseBtn->
setCursor( Qt::PointingHandCursor );
85 mCloseBtn->
setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Maximum );
86 mCloseBtn->
setMenu( mCloseMenu );
89 mLayout->
addWidget( mCloseBtn, 0, 3, 1, 1 );
91 mCountdownTimer =
new QTimer(
this );
93 connect( mCountdownTimer, SIGNAL( timeout() ),
this, SLOT( updateCountdown() ) );
108 if ( mCountProgress ==
childAt( e->
pos() ) && e->
button() == Qt::LeftButton )
112 mCountdownTimer->
stop();
113 mCountProgress->
setStyleSheet( mCountStyleSheet.
arg(
"mIconTimerContinue.png" ) );
117 mCountdownTimer->
start();
118 mCountProgress->
setStyleSheet( mCountStyleSheet.
arg(
"mIconTimerPause.png" ) );
127 if ( item != mCurrentItem && !mItems.
contains( item ) )
130 if ( item == mCurrentItem )
134 QWidget *widget = mCurrentItem;
136 mCurrentItem->
hide();
139 mCurrentItem =
nullptr;
144 showItem( mItems.
at( 0 ) );
161 if ( !item || !mCurrentItem )
164 if ( item == mCurrentItem )
166 popItem( mCurrentItem );
172 if ( existingItem == item )
198 if ( !mCurrentItem && mItems.
empty() )
207 return !mCurrentItem && mItems.
empty();
237 if ( item == mCurrentItem )
245 mItems.
prepend( mCurrentItem );
247 mCurrentItem->
hide();
252 mCurrentItem->
show();
259 mCountdownTimer->
start();
315 void QgsMessageBar::updateCountdown()
322 if ( mCountProgress->
value() < 2 )
332 void QgsMessageBar::resetCountdown()
335 mCountdownTimer->
stop();
337 mCountProgress->
setStyleSheet( mCountStyleSheet.
arg(
"mIconTimerPause.png" ) );
341 void QgsMessageBar::updateItemCount()
347 mCloseBtn->
setPopupMode( !mItems.
isEmpty() ? QToolButton::MenuButtonPopup : QToolButton::DelayedPopup );
void setInterval(int msec)
void setBrush(ColorRole role, const QBrush &brush)
QgsMessageBar(QWidget *parent=nullptr)
void setContentsMargins(int left, int top, int right, int bottom)
void mousePressEvent(QMouseEvent *e) override
void pushInfo(const QString &title, const QString &message)
Pushes a information message with default timeout to the message bar.
void setFrameShape(Shape)
void widgetRemoved(QgsMessageBarItem *item)
emitted when a message widget was removed from the bar
static QIcon getThemeIcon(const QString &theName)
Helper to get a theme icon.
const T & at(int i) const
bool clearWidgets()
Remove all items from the bar's widget list.
int duration() const
returns the duration in second of the message
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
QString tr(const char *sourceText, const char *disambiguation, int n)
void pushSuccess(const QString &title, const QString &message)
Pushes a success message with default timeout to the message bar.
static QgsMessageBarItem * createMessage(const QString &text, QWidget *parent=nullptr)
make out a widget containing a message to be displayed on the bar
void pushMessage(const QString &text, MessageLevel level=INFO, int duration=5)
convenience method for pushing a message to the bar
void pushWarning(const QString &title, const QString &message)
Pushes a warning with default timeout to the message bar.
int count(const T &value) const
void setObjectName(const QString &name)
void widgetAdded(QgsMessageBarItem *item)
emitted when a message widget is added to the bar
void setText(const QString &)
bool contains(const T &value) const
void setFrameShadow(Shadow)
QgsMessageBarItem * pushWidget(QWidget *widget, MessageLevel level=INFO, int duration=0)
Display a widget as a message on the bar after hiding the currently visible one and putting it in a s...
QString getStyleSheet()
returns the styleSheet
void pushItem(QgsMessageBarItem *item)
Display a message item on the bar after hiding the currently visible one and putting it in a stack...
QgsMessageBarItem * setLevel(QgsMessageBar::MessageLevel level)
QgsMessageBarItem * setDuration(int duration)
void prepend(const T &value)
const QPoint & pos() const
const QBrush & window() const
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setTextVisible(bool visible)
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
void setRange(int minimum, int maximum)
bool removeOne(const T &value)
bool popWidget()
Remove the currently displayed widget from the bar and display the next in the stack if any or hide t...
void pushCritical(const QString &title, const QString &message)
Pushes a critical warning with default timeout to the message bar.