]> git.sur5r.net Git - minitube/blobdiff - src/segmentedcontrol.cpp
Use normal font
[minitube] / src / segmentedcontrol.cpp
index 418d3c8287241e805969a0971825f6c70ed9d88f..7ed895c3eb65c02a0bd5eaf4975290a180162ec4 100644 (file)
@@ -1,6 +1,26 @@
+/* $BEGIN_LICENSE
+
+This file is part of Minitube.
+Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
+
+Minitube is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+Minitube is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Minitube.  If not, see <http://www.gnu.org/licenses/>.
+
+$END_LICENSE */
+
 #include "segmentedcontrol.h"
-#include "fontutils.h"
 #include "mainwindow.h"
+#include "painterutils.h"
 
 static const QColor borderColor = QColor(0x26, 0x26, 0x26);
 
@@ -128,8 +148,8 @@ void SegmentedControl::mouseReleaseEvent(QMouseEvent *event) {
 
 void SegmentedControl::leaveEvent(QEvent *event) {
     QWidget::leaveEvent(event);
-    // status tip    
-    MainWindow::instance()->statusBar()->clearMessage();
+    // status tip
+    // static_cast<QMainWindow*>(window())->statusBar()->clearMessage();
     d->hoveredAction = 0;
     d->pressedAction = 0;
     update();
@@ -154,8 +174,7 @@ QAction *SegmentedControl::hoveredAction(const QPoint& pos) const {
 }
 
 int SegmentedControl::calculateButtonWidth (void) const {
-    QFont smallerBoldFont = FontUtils::smallBold();
-    QFontMetrics fontMetrics(smallerBoldFont);
+    QFontMetrics fontMetrics(font());
     int tmpItemWidth, itemWidth = 0;
     foreach (QAction *action, d->actionList) {
         tmpItemWidth = fontMetrics.width(action->text());
@@ -231,15 +250,22 @@ void SegmentedControl::paintButton(QPainter *painter, const QRect& rect, const Q
     painter->drawRect(0, 0, width, height - 1);
 #endif
 
-    painter->setFont(FontUtils::smallBold());
+    const QString text = action->text();
 
     // text shadow
     painter->setPen(QColor(0, 0, 0, 128));
-    painter->drawText(0, -1, width, height, Qt::AlignCenter, action->text());
+    painter->drawText(0, -1, width, height, Qt::AlignCenter, text);
 
     painter->setPen(QPen(Qt::white, 1));
-    painter->drawText(0, 0, width, height, Qt::AlignCenter, action->text());
+    painter->drawText(0, 0, width, height, Qt::AlignCenter, text);
+
+    if (action->property("notifyCount").isValid()) {
+        QRect textBox = painter->boundingRect(rect,
+                                              Qt::AlignCenter,
+                                              text);
+        painter->translate((width + textBox.width()) / 2 + 10, (height - 20) / 2);
+        PainterUtils::paintBadge(painter, action->property("notifyCount").toString());
+    }
 
     painter->restore();
 }
-