# HG changeset patch # User Andre Heinecke # Date 1404318930 -7200 # Node ID b0929968562a82f27384e63561d4c7af765bcdf8 # Parent abc76948d8e571e1a40788f05ddad418eee19bab (Issue31) Add textoverlaybutton to show a text in the button. diff -r abc76948d8e5 -r b0929968562a ui/CMakeLists.txt --- a/ui/CMakeLists.txt Wed Jul 02 17:04:02 2014 +0200 +++ b/ui/CMakeLists.txt Wed Jul 02 18:35:30 2014 +0200 @@ -41,6 +41,7 @@ ${CMAKE_CURRENT_SOURCE_DIR}/processhelp_win.cpp ${CMAKE_CURRENT_SOURCE_DIR}/processhelp_linux.cpp ${CMAKE_CURRENT_SOURCE_DIR}/processwaitdialog.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/textoverlaybutton.cpp ${CERTIFICATELIST_SOURCES} ${DOWNLOADER_SOURCES} ) diff -r abc76948d8e5 -r b0929968562a ui/mainwindow.cpp --- a/ui/mainwindow.cpp Wed Jul 02 17:04:02 2014 +0200 +++ b/ui/mainwindow.cpp Wed Jul 02 18:35:30 2014 +0200 @@ -466,7 +466,7 @@ ***********************************/ mButtonGroup = new QButtonGroup; - QToolButton *updatesButton = new QToolButton; + TextOverlayButton *updatesButton = new TextOverlayButton; updatesButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); updatesButton->setIcon(QIcon(":/img/view-refresh.png")); updatesButton->setIconSize(QSize(40, 40)); @@ -476,6 +476,9 @@ updatesButton->setCheckable(true); updatesButton->setChecked(true); + connect(this, SIGNAL(changesChanged(const QString&)), + updatesButton, SLOT(setOverlay(const QString&))); + QToolButton *allInstallButton = new QToolButton; allInstallButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); allInstallButton->setIcon(QIcon(":/img/document-encrypt.png")); @@ -831,8 +834,8 @@ void MainWindow::listChanged(int selected) { Q_UNUSED (selected); - mChangeCount = mUpdatesRemove->selectedCertCount() + - mUpdatesNew->selectedCertCount() + mUpdatesManual->certificates().size(); + setChangeCount(mUpdatesRemove->selectedCertCount() + + mUpdatesNew->selectedCertCount() + mUpdatesManual->certificates().size()); /* Show a different tip in case of manual changes, updates aviailable, updates and manual * changes available */ @@ -1169,7 +1172,7 @@ if (!mUpdatesNew->isVisible()) { mUpdatesDetailsNew->setText(tr("Hide details")); mUpdatesNew->show(); - mUpdatesNew->setSelected(0); + mUpdatesNew->setSelected(mUpdatesNew->selected()); } else { mUpdatesNew->hide(); @@ -1233,3 +1236,11 @@ { return mChangeCount; } + +void MainWindow::setChangeCount(int cnt) +{ + if (mChangeCount != cnt) { + mChangeCount = cnt; + emit changesChanged(QString("%1").arg(cnt)); + } +} diff -r abc76948d8e5 -r b0929968562a ui/mainwindow.h --- a/ui/mainwindow.h Wed Jul 02 17:04:02 2014 +0200 +++ b/ui/mainwindow.h Wed Jul 02 18:35:30 2014 +0200 @@ -27,6 +27,7 @@ #include "downloader.h" #include "certificatelist.h" #include "certificatelistwidget.h" +#include "textoverlaybutton.h" class QMenu; class QAction; class QTimer; @@ -161,10 +162,17 @@ * the application. */ void installNewSW(const QString& fileName, const QDateTime& modDate); +signals: + /** @brief emits the changecount as a string when it changes */ + void changesChanged(const QString& cnt); + private: /** @brief the combined number of changes made in all lists */ int changeCount(); + /** @brief use this to set the change count */ + void setChangeCount(int cnt); + /** @brief check the integrity of available certificate lists. * * Note: Do not use this as a local trust check as this only works on diff -r abc76948d8e5 -r b0929968562a ui/textoverlaybutton.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/textoverlaybutton.cpp Wed Jul 02 18:35:30 2014 +0200 @@ -0,0 +1,37 @@ +/* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU GPL (v>=2) + * and comes with ABSOLUTELY NO WARRANTY! + * See LICENSE.txt for details. + */ + +#include +#include +#include +#include + +#include + +#include "textoverlaybutton.h" + +void TextOverlayButton::paintEvent(QPaintEvent *e) +{ + QToolButton::paintEvent(e); + QPainter painter(this); + QFont font; + QRect myRect = e->rect().translated(0, 10); + + //font.setFamily("Comic Sans MS"); + + font.setPixelSize(14); + font.setWeight(QFont::DemiBold); + painter.setFont(font); + + //painter.setPen(Qt::white); + //painter.drawText(myRect.translated(1,1), Qt::AlignCenter, "20"); + painter.setPen(qApp->palette().color(QPalette::ButtonText)); + painter.drawText(myRect, Qt::AlignCenter | Qt::AlignVCenter, mOverlay); + + return; +} diff -r abc76948d8e5 -r b0929968562a ui/textoverlaybutton.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/textoverlaybutton.h Wed Jul 02 18:35:30 2014 +0200 @@ -0,0 +1,35 @@ +#ifndef UI_TEXTOVERLAYBUTTON_H +#define UI_TEXTOVERLAYBUTTON_H +/* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU GPL (v>=2) + * and comes with ABSOLUTELY NO WARRANTY! + * See LICENSE.txt for details. + */ + +/** @file A tool button that overlays a text over the icon */ + +#include +#include + +class QPaintEvent; + +class TextOverlayButton : public QToolButton +{ + Q_OBJECT + +public: + QString overlay() {return mOverlay;} + +protected: + virtual void paintEvent(QPaintEvent *); + +public slots: + void setOverlay (const QString& text) {mOverlay = text; repaint();} + +private: + QString mOverlay; +}; + +#endif // UI_TEXTOVERLAYBUTTON_H