diff options
Diffstat (limited to 'src/plugins/coreplugin')
-rw-r--r-- | src/plugins/coreplugin/ioutputpane.h | 2 | ||||
-rw-r--r-- | src/plugins/coreplugin/outputpanemanager.cpp | 59 | ||||
-rw-r--r-- | src/plugins/coreplugin/outputpanemanager.h | 5 |
3 files changed, 65 insertions, 1 deletions
diff --git a/src/plugins/coreplugin/ioutputpane.h b/src/plugins/coreplugin/ioutputpane.h index 95999a7b56..e68e05de40 100644 --- a/src/plugins/coreplugin/ioutputpane.h +++ b/src/plugins/coreplugin/ioutputpane.h @@ -86,6 +86,7 @@ public slots: void toggle(bool withFocusIfShown) { emit togglePage(withFocusIfShown); } void navigateStateChanged() { emit navigateStateUpdate(); } void flash() { emit flashButton(); } + void setIconBadgeNumber(int number) { emit setBadgeNumber(number); } signals: void showPage(bool withFocus, bool ensureSizeHint); @@ -93,6 +94,7 @@ signals: void togglePage(bool withFocusIfShown); void navigateStateUpdate(); void flashButton(); + void setBadgeNumber(int number); }; } // namespace Core diff --git a/src/plugins/coreplugin/outputpanemanager.cpp b/src/plugins/coreplugin/outputpanemanager.cpp index 1fafdb2adb..33024b7c99 100644 --- a/src/plugins/coreplugin/outputpanemanager.cpp +++ b/src/plugins/coreplugin/outputpanemanager.cpp @@ -68,6 +68,7 @@ #include <QStackedWidget> #include <QToolButton> #include <QTimeLine> +#include <QLabel> namespace Core { namespace Internal { @@ -263,6 +264,7 @@ void OutputPaneManager::init() connect(outPane, SIGNAL(togglePage(bool)), this, SLOT(togglePage(bool))); connect(outPane, SIGNAL(navigateStateUpdate()), this, SLOT(updateNavigateState())); connect(outPane, SIGNAL(flashButton()), this, SLOT(flashButton())); + connect(outPane, SIGNAL(setBadgeNumber(int)), this, SLOT(setBadgeNumber(int))); QWidget *toolButtonsContainer = new QWidget(m_opToolBarWidgets); QHBoxLayout *toolButtonsLayout = new QHBoxLayout; @@ -453,6 +455,14 @@ void OutputPaneManager::flashButton() m_buttons.value(idx)->flash(); } +void OutputPaneManager::setBadgeNumber(int number) +{ + IOutputPane* pane = qobject_cast<IOutputPane*>(sender()); + int idx = findIndexForPage(pane); + if (pane) + m_buttons.value(idx)->setIconBadgeNumber(number); +} + // Slot connected to showPage signal of each page void OutputPaneManager::showPage(bool focus, bool ensureSizeHint) { @@ -617,6 +627,15 @@ OutputPaneToggleButton::OutputPaneToggleButton(int number, const QString &text, m_flashTimer->setFrameRange(0, 92); connect(m_flashTimer, SIGNAL(valueChanged(qreal)), this, SLOT(update())); connect(m_flashTimer, SIGNAL(finished()), this, SLOT(update())); + + m_label = new QLabel(this); + fnt.setBold(true); + fnt.setPixelSize(11); + m_label->setFont(fnt); + m_label->setAlignment(Qt::AlignCenter); + m_label->setStyleSheet("background-color: #818181; color: white; border-radius: 6; padding-left: 4; padding-right: 4;"); + m_label->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + m_label->hide(); } void OutputPaneToggleButton::updateToolTip() @@ -635,9 +654,21 @@ QSize OutputPaneToggleButton::sizeHint() const s.rwidth() += 19 + 5 + 2; s.rheight() += 2 + 2; + if (!m_label->text().isNull()) + s.rwidth() += m_label->width(); + return s.expandedTo(QApplication::globalStrut()); } +void OutputPaneToggleButton::resizeEvent(QResizeEvent *event) +{ + QToolButton::resizeEvent(event); + if (!m_label->text().isNull()) { + m_label->move(width() - m_label->width() - 3, (height() - m_label->height() + 1) / 2); + m_label->show(); + } +} + void OutputPaneToggleButton::paintEvent(QPaintEvent *event) { // For drawing the style sheet stuff @@ -658,7 +689,8 @@ void OutputPaneToggleButton::paintEvent(QPaintEvent *event) if (!isChecked()) p.setPen(Qt::black); int leftPart = 22; - p.drawText(leftPart, baseLine, fm.elidedText(m_text, Qt::ElideRight, width() - leftPart - 1)); + int labelWidth = m_label->isVisible() ? m_label->width() + 3 : 0; + p.drawText(leftPart, baseLine, fm.elidedText(m_text, Qt::ElideRight, width() - leftPart - 1 - labelWidth)); } void OutputPaneToggleButton::checkStateSet() @@ -666,6 +698,11 @@ void OutputPaneToggleButton::checkStateSet() //Stop flashing when button is checked QToolButton::checkStateSet(); m_flashTimer->stop(); + + if (isChecked()) + m_label->setStyleSheet("background-color: #e1e1e1; color: #606060; border-radius: 6; padding-left: 4; padding-right: 4;"); + else + m_label->setStyleSheet("background-color: #818181; color: white; border-radius: 6; padding-left: 4; padding-right: 4;"); } void OutputPaneToggleButton::flash(int count) @@ -679,6 +716,26 @@ void OutputPaneToggleButton::flash(int count) } } +void OutputPaneToggleButton::setIconBadgeNumber(int number) +{ + if (number) { + const QString text = QString::number(number); + m_label->setText(text); + + QSize size = m_label->sizeHint(); + if (size.width() < size.height()) + //Ensure we increase size by an even number of pixels + size.setWidth(size.height() + ((size.width() - size.height()) & 1)); + m_label->resize(size); + + //Do not show yet, we wait until the button has been resized + } else { + m_label->setText(QString()); + m_label->hide(); + } + updateGeometry(); +} + /////////////////////////////////////////////////////////////////////// // diff --git a/src/plugins/coreplugin/outputpanemanager.h b/src/plugins/coreplugin/outputpanemanager.h index 1f3900fce7..cbd427f017 100644 --- a/src/plugins/coreplugin/outputpanemanager.h +++ b/src/plugins/coreplugin/outputpanemanager.h @@ -45,6 +45,7 @@ class QLabel; class QSplitter; class QStackedWidget; class QTimeLine; +class QLabel; QT_END_NAMESPACE namespace Core { @@ -88,6 +89,7 @@ private slots: void popupMenu(); void saveSettings() const; void flashButton(); + void setBadgeNumber(int number); private: // the only class that is allowed to create and destroy @@ -143,8 +145,10 @@ public: OutputPaneToggleButton(int number, const QString &text, QAction *action, QWidget *parent = 0); QSize sizeHint() const; + void resizeEvent(QResizeEvent *event); void paintEvent(QPaintEvent *event); void flash(int count = 3); + void setIconBadgeNumber(int number); private slots: void updateToolTip(); @@ -156,6 +160,7 @@ private: QString m_text; QAction *m_action; QTimeLine *m_flashTimer; + QLabel *m_label; }; class OutputPaneManageButton : public QToolButton |