changeset 722:b0929968562a

(Issue31) Add textoverlaybutton to show a text in the button.
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 02 Jul 2014 18:35:30 +0200
parents abc76948d8e5
children 3777482dc306
files ui/CMakeLists.txt ui/mainwindow.cpp ui/mainwindow.h ui/textoverlaybutton.cpp ui/textoverlaybutton.h
diffstat 5 files changed, 96 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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}
 )
--- 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));
+    }
+}
--- 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
--- /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 <QPaintEvent>
+#include <QPainter>
+#include <QFont>
+#include <QApplication>
+
+#include <QDebug>
+
+#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;
+}
--- /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 <QToolButton>
+#include <QString>
+
+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

http://wald.intevation.org/projects/trustbridge/