Support badge on output panel buttons.

These are used to indicate number of issues and todos.

Change-Id: I320b6c0f5835570f0b5e5898fb140bd8266090c8
Reviewed-by: Daniel Teske <daniel.teske@nokia.com>
This commit is contained in:
Francois Ferrand
2012-06-14 16:33:10 +02:00
committed by Daniel Teske
parent 54569d5931
commit 8a57b7bcbf
6 changed files with 112 additions and 1 deletions

View File

@@ -86,6 +86,7 @@ public slots:
void toggle(bool withFocusIfShown) { emit togglePage(withFocusIfShown); } void toggle(bool withFocusIfShown) { emit togglePage(withFocusIfShown); }
void navigateStateChanged() { emit navigateStateUpdate(); } void navigateStateChanged() { emit navigateStateUpdate(); }
void flash() { emit flashButton(); } void flash() { emit flashButton(); }
void setIconBadgeNumber(int number) { emit setBadgeNumber(number); }
signals: signals:
void showPage(bool withFocus, bool ensureSizeHint); void showPage(bool withFocus, bool ensureSizeHint);
@@ -93,6 +94,7 @@ signals:
void togglePage(bool withFocusIfShown); void togglePage(bool withFocusIfShown);
void navigateStateUpdate(); void navigateStateUpdate();
void flashButton(); void flashButton();
void setBadgeNumber(int number);
}; };
} // namespace Core } // namespace Core

View File

@@ -68,6 +68,7 @@
#include <QStackedWidget> #include <QStackedWidget>
#include <QToolButton> #include <QToolButton>
#include <QTimeLine> #include <QTimeLine>
#include <QLabel>
namespace Core { namespace Core {
namespace Internal { namespace Internal {
@@ -263,6 +264,7 @@ void OutputPaneManager::init()
connect(outPane, SIGNAL(togglePage(bool)), this, SLOT(togglePage(bool))); connect(outPane, SIGNAL(togglePage(bool)), this, SLOT(togglePage(bool)));
connect(outPane, SIGNAL(navigateStateUpdate()), this, SLOT(updateNavigateState())); connect(outPane, SIGNAL(navigateStateUpdate()), this, SLOT(updateNavigateState()));
connect(outPane, SIGNAL(flashButton()), this, SLOT(flashButton())); connect(outPane, SIGNAL(flashButton()), this, SLOT(flashButton()));
connect(outPane, SIGNAL(setBadgeNumber(int)), this, SLOT(setBadgeNumber(int)));
QWidget *toolButtonsContainer = new QWidget(m_opToolBarWidgets); QWidget *toolButtonsContainer = new QWidget(m_opToolBarWidgets);
QHBoxLayout *toolButtonsLayout = new QHBoxLayout; QHBoxLayout *toolButtonsLayout = new QHBoxLayout;
@@ -453,6 +455,14 @@ void OutputPaneManager::flashButton()
m_buttons.value(idx)->flash(); 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 // Slot connected to showPage signal of each page
void OutputPaneManager::showPage(bool focus, bool ensureSizeHint) void OutputPaneManager::showPage(bool focus, bool ensureSizeHint)
{ {
@@ -617,6 +627,15 @@ OutputPaneToggleButton::OutputPaneToggleButton(int number, const QString &text,
m_flashTimer->setFrameRange(0, 92); m_flashTimer->setFrameRange(0, 92);
connect(m_flashTimer, SIGNAL(valueChanged(qreal)), this, SLOT(update())); connect(m_flashTimer, SIGNAL(valueChanged(qreal)), this, SLOT(update()));
connect(m_flashTimer, SIGNAL(finished()), 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() void OutputPaneToggleButton::updateToolTip()
@@ -635,9 +654,21 @@ QSize OutputPaneToggleButton::sizeHint() const
s.rwidth() += 19 + 5 + 2; s.rwidth() += 19 + 5 + 2;
s.rheight() += 2 + 2; s.rheight() += 2 + 2;
if (!m_label->text().isNull())
s.rwidth() += m_label->width();
return s.expandedTo(QApplication::globalStrut()); 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) void OutputPaneToggleButton::paintEvent(QPaintEvent *event)
{ {
// For drawing the style sheet stuff // For drawing the style sheet stuff
@@ -658,7 +689,8 @@ void OutputPaneToggleButton::paintEvent(QPaintEvent *event)
if (!isChecked()) if (!isChecked())
p.setPen(Qt::black); p.setPen(Qt::black);
int leftPart = 22; 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() void OutputPaneToggleButton::checkStateSet()
@@ -666,6 +698,11 @@ void OutputPaneToggleButton::checkStateSet()
//Stop flashing when button is checked //Stop flashing when button is checked
QToolButton::checkStateSet(); QToolButton::checkStateSet();
m_flashTimer->stop(); 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) 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();
}
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
// //

View File

@@ -45,6 +45,7 @@ class QLabel;
class QSplitter; class QSplitter;
class QStackedWidget; class QStackedWidget;
class QTimeLine; class QTimeLine;
class QLabel;
QT_END_NAMESPACE QT_END_NAMESPACE
namespace Core { namespace Core {
@@ -88,6 +89,7 @@ private slots:
void popupMenu(); void popupMenu();
void saveSettings() const; void saveSettings() const;
void flashButton(); void flashButton();
void setBadgeNumber(int number);
private: private:
// the only class that is allowed to create and destroy // the only class that is allowed to create and destroy
@@ -143,8 +145,10 @@ public:
OutputPaneToggleButton(int number, const QString &text, QAction *action, OutputPaneToggleButton(int number, const QString &text, QAction *action,
QWidget *parent = 0); QWidget *parent = 0);
QSize sizeHint() const; QSize sizeHint() const;
void resizeEvent(QResizeEvent *event);
void paintEvent(QPaintEvent *event); void paintEvent(QPaintEvent *event);
void flash(int count = 3); void flash(int count = 3);
void setIconBadgeNumber(int number);
private slots: private slots:
void updateToolTip(); void updateToolTip();
@@ -156,6 +160,7 @@ private:
QString m_text; QString m_text;
QAction *m_action; QAction *m_action;
QTimeLine *m_flashTimer; QTimeLine *m_flashTimer;
QLabel *m_label;
}; };
class OutputPaneManageButton : public QToolButton class OutputPaneManageButton : public QToolButton

View File

@@ -220,6 +220,7 @@ public:
QToolButton *m_categoriesButton; QToolButton *m_categoriesButton;
QMenu *m_categoriesMenu; QMenu *m_categoriesMenu;
TaskHub *m_taskHub; TaskHub *m_taskHub;
int m_badgeCount;
}; };
static QToolButton *createFilterButton(QIcon icon, const QString &toolTip, static QToolButton *createFilterButton(QIcon icon, const QString &toolTip,
@@ -256,6 +257,7 @@ TaskWindow::TaskWindow(TaskHub *taskhub) : d(new TaskWindowPrivate)
d->m_taskWindowContext = new Internal::TaskWindowContext(d->m_listview); d->m_taskWindowContext = new Internal::TaskWindowContext(d->m_listview);
d->m_taskHub = taskhub; d->m_taskHub = taskhub;
d->m_badgeCount = 0;
Core::ICore::addContextObject(d->m_taskWindowContext); Core::ICore::addContextObject(d->m_taskWindowContext);
@@ -336,11 +338,22 @@ QWidget *TaskWindow::outputWidget(QWidget *)
void TaskWindow::clearTasks(const Core::Id &categoryId) void TaskWindow::clearTasks(const Core::Id &categoryId)
{ {
if (categoryId.uniqueIdentifier() != 0 && !d->m_filter->filteredCategories().contains(categoryId)) {
if (d->m_filter->filterIncludesErrors())
d->m_badgeCount -= d->m_model->errorTaskCount(categoryId);
if (d->m_filter->filterIncludesWarnings())
d->m_badgeCount -= d->m_model->warningTaskCount(categoryId);
} else {
d->m_badgeCount = 0;
}
d->m_model->clearTasks(categoryId); d->m_model->clearTasks(categoryId);
emit tasksChanged(); emit tasksChanged();
emit tasksCleared(); emit tasksCleared();
navigateStateChanged(); navigateStateChanged();
setBadgeNumber(d->m_badgeCount);
} }
void TaskWindow::setCategoryVisibility(const Core::Id &categoryId, bool visible) void TaskWindow::setCategoryVisibility(const Core::Id &categoryId, bool visible)
@@ -357,6 +370,17 @@ void TaskWindow::setCategoryVisibility(const Core::Id &categoryId, bool visible)
} }
d->m_filter->setFilteredCategories(categories); d->m_filter->setFilteredCategories(categories);
int count = 0;
if (d->m_filter->filterIncludesErrors())
count += d->m_model->errorTaskCount(categoryId);
if (d->m_filter->filterIncludesWarnings())
count += d->m_model->warningTaskCount(categoryId);
if (visible)
d->m_badgeCount += count;
else
d->m_badgeCount -= count;
setBadgeNumber(d->m_badgeCount);
} }
void TaskWindow::visibilityChanged(bool /* b */) void TaskWindow::visibilityChanged(bool /* b */)
@@ -383,6 +407,11 @@ void TaskWindow::addTask(const Task &task)
if (task.type == Task::Error && d->m_filter->filterIncludesErrors() && if (task.type == Task::Error && d->m_filter->filterIncludesErrors() &&
!d->m_filter->filteredCategories().contains(task.category)) { !d->m_filter->filteredCategories().contains(task.category)) {
flash(); flash();
setBadgeNumber(++d->m_badgeCount);
}
if (task.type == Task::Warning && d->m_filter->filterIncludesWarnings() &&
!d->m_filter->filteredCategories().contains(task.category)) {
setBadgeNumber(++d->m_badgeCount);
} }
} }
@@ -392,6 +421,15 @@ void TaskWindow::removeTask(const Task &task)
emit tasksChanged(); emit tasksChanged();
navigateStateChanged(); navigateStateChanged();
if (task.type == Task::Error && d->m_filter->filterIncludesErrors() &&
!d->m_filter->filteredCategories().contains(task.category)) {
setBadgeNumber(--d->m_badgeCount);
}
if (task.type == Task::Warning && d->m_filter->filterIncludesWarnings() &&
!d->m_filter->filteredCategories().contains(task.category)) {
setBadgeNumber(--d->m_badgeCount);
}
} }
void TaskWindow::updatedTaskFileName(unsigned int id, const QString &fileName) void TaskWindow::updatedTaskFileName(unsigned int id, const QString &fileName)
@@ -500,6 +538,7 @@ void TaskWindow::setShowWarnings(bool show)
{ {
d->m_filter->setFilterIncludesWarnings(show); d->m_filter->setFilterIncludesWarnings(show);
d->m_filter->setFilterIncludesUnknowns(show); // "Unknowns" are often associated with warnings d->m_filter->setFilterIncludesUnknowns(show); // "Unknowns" are often associated with warnings
setBadgeNumber(d->m_filter->rowCount());
} }
void TaskWindow::updateCategoriesMenu() void TaskWindow::updateCategoriesMenu()

View File

@@ -52,6 +52,7 @@ TodoOutputPane::TodoOutputPane(TodoItemsModel *todoItemsModel, QObject *parent)
createScopeButtons(); createScopeButtons();
setScanningScope(ScanningScopeCurrentFile); // default setScanningScope(ScanningScopeCurrentFile); // default
connect(m_todoItemsModel, SIGNAL(layoutChanged()), SIGNAL(navigateStateUpdate())); connect(m_todoItemsModel, SIGNAL(layoutChanged()), SIGNAL(navigateStateUpdate()));
connect(m_todoItemsModel, SIGNAL(layoutChanged()), SLOT(updateTodoCount()));
} }
TodoOutputPane::~TodoOutputPane() TodoOutputPane::~TodoOutputPane()
@@ -149,6 +150,7 @@ void TodoOutputPane::scopeButtonClicked(QAbstractButton* button)
emit scanningScopeChanged(ScanningScopeCurrentFile); emit scanningScopeChanged(ScanningScopeCurrentFile);
else if (button == m_wholeProjectButton) else if (button == m_wholeProjectButton)
emit scanningScopeChanged(ScanningScopeProject); emit scanningScopeChanged(ScanningScopeProject);
setBadgeNumber(m_todoItemsModel->rowCount());
} }
void TodoOutputPane::todoTreeViewClicked(const QModelIndex &index) void TodoOutputPane::todoTreeViewClicked(const QModelIndex &index)
@@ -167,6 +169,11 @@ void TodoOutputPane::todoTreeViewClicked(const QModelIndex &index)
emit todoItemClicked(item); emit todoItemClicked(item);
} }
void TodoOutputPane::updateTodoCount()
{
setBadgeNumber(m_todoItemsModel->rowCount());
}
void TodoOutputPane::createTreeView() void TodoOutputPane::createTreeView()
{ {
m_todoTreeView = new QTreeView(); m_todoTreeView = new QTreeView();

View File

@@ -84,6 +84,7 @@ signals:
private slots: private slots:
void scopeButtonClicked(QAbstractButton *button); void scopeButtonClicked(QAbstractButton *button);
void todoTreeViewClicked(const QModelIndex &index); void todoTreeViewClicked(const QModelIndex &index);
void updateTodoCount();
private: private:
QTreeView *m_todoTreeView; QTreeView *m_todoTreeView;