]> git.sur5r.net Git - minitube/blobdiff - src/segmentedcontrol.cpp
Merge tag 'upstream/2.5.1'
[minitube] / src / segmentedcontrol.cpp
index a896fbd0517f6af9d6405c8d103b08f8f6075cff..a355152ef6a89c037ae85d70a4fe2ca52c7d3fb6 100644 (file)
@@ -1,8 +1,29 @@
+/* $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"
+#include "fontutils.h"
 
-static const QColor borderColor = QColor(0x26, 0x26, 0x26);
+static const QColor borderColor = QColor(158, 157, 159);
 
 class SegmentedControl::Private {
 public:
@@ -15,6 +36,8 @@ public:
 SegmentedControl::SegmentedControl (QWidget *parent)
     : QWidget(parent), d(new SegmentedControl::Private) {
 
+    setFont(FontUtils::small());
+
     setMouseTracking(true);
 
     d->hoveredAction = 0;
@@ -66,8 +89,8 @@ void SegmentedControl::paintEvent (QPaintEvent * /*event*/) {
     QPainter p(this);
 
     QLinearGradient linearGrad(rect().topLeft(), rect().bottomLeft());
-    linearGrad.setColorAt(0, borderColor);
-    linearGrad.setColorAt(1, QColor(0x3c, 0x3c, 0x3c));
+    linearGrad.setColorAt(0, QColor(185, 183, 185));
+    linearGrad.setColorAt(1, QColor(176, 176, 178));
     p.fillRect(rect(), QBrush(linearGrad));
 
     // Calculate Buttons Size & Location
@@ -78,7 +101,6 @@ void SegmentedControl::paintEvent (QPaintEvent * /*event*/) {
     const int actionCount = d->actionList.size();
     for (int i = 0; i < actionCount; i++) {
         QAction *action = d->actionList.at(i);
-
         if (i + 1 == actionCount) {
             rect.setWidth(width - buttonWidth * (actionCount-1));
             drawButton(&p, rect, action);
@@ -86,9 +108,7 @@ void SegmentedControl::paintEvent (QPaintEvent * /*event*/) {
             drawButton(&p, rect, action);
             rect.moveLeft(rect.x() + rect.width());
         }
-
     }
-
 }
 
 void SegmentedControl::mouseMoveEvent (QMouseEvent *event) {
@@ -129,7 +149,7 @@ void SegmentedControl::mouseReleaseEvent(QMouseEvent *event) {
 void SegmentedControl::leaveEvent(QEvent *event) {
     QWidget::leaveEvent(event);
     // status tip
-    // static_cast<QMainWindow*>(window())->statusBar()->clearMessage();
+    MainWindow::instance()->statusBar()->clearMessage();
     d->hoveredAction = 0;
     d->pressedAction = 0;
     update();
@@ -153,9 +173,8 @@ QAction *SegmentedControl::hoveredAction(const QPoint& pos) const {
     return(d->actionList[buttonIndex]);
 }
 
-int SegmentedControl::calculateButtonWidth (void) const {
-    QFont smallerBoldFont = FontUtils::smallBold();
-    QFontMetrics fontMetrics(smallerBoldFont);
+int SegmentedControl::calculateButtonWidth() const {
+    QFontMetrics fontMetrics(font());
     int tmpItemWidth, itemWidth = 0;
     foreach (QAction *action, d->actionList) {
         tmpItemWidth = fontMetrics.width(action->text());
@@ -176,6 +195,7 @@ void SegmentedControl::drawButton (QPainter *painter,
 void SegmentedControl::drawUnselectedButton (QPainter *painter,
                                         const QRect& rect,
                                         const QAction *action) {
+    painter->setPen(QColor(0, 0, 0, 128));
     paintButton(painter, rect, action);
 }
 
@@ -191,11 +211,12 @@ void SegmentedControl::drawSelectedButton (QPainter *painter,
     QRadialGradient gradient(hCenter, 0,
                              width,
                              hCenter, 0);
-    gradient.setColorAt(1, Qt::black);
-    gradient.setColorAt(0, QColor(0x33, 0x33, 0x33));
+    gradient.setColorAt(1, QColor(212, 210, 212));
+    gradient.setColorAt(0, QColor(203, 203, 205));
     painter->fillRect(0, 0, width, height, QBrush(gradient));
 
     painter->restore();
+    painter->setPen(palette().windowText().color());
     paintButton(painter, rect, action);
 }
 
@@ -206,40 +227,50 @@ void SegmentedControl::paintButton(QPainter *painter, const QRect& rect, const Q
     const int height = rect.height();
     const int width = rect.width();
 
+    painter->save();
+    painter->setPen(QPen(borderColor, 1.0 / qApp->devicePixelRatio()));
+#if defined(APP_MAC) | defined(APP_WIN)
+    painter->drawRect(-1, -1, width, height);
+#else
+    painter->drawRect(0, 0, width, height - 1);
+#endif
+    painter->restore();
+
+    const QString text = action->text();
+
+    // text shadow
+    /*
+    painter->setPen(QColor(0, 0, 0, 128));
+    painter->drawText(0, -1, width, height, Qt::AlignCenter, 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());
+    }
+
     if (action == d->pressedAction && action != d->checkedAction) {
         const int hCenter = width * .5;
         QRadialGradient gradient(hCenter, 0,
                                  width,
                                  hCenter, 0);
         gradient.setColorAt(1, QColor(0x00, 0x00, 0x00, 0));
-        gradient.setColorAt(0, QColor(0x00, 0x00, 0x00, 16));
+        gradient.setColorAt(0, QColor(0x00, 0x00, 0x00, 32));
         painter->fillRect(0, 0, width, height, QBrush(gradient));
     } else if (action == d->hoveredAction && action != d->checkedAction) {
         const int hCenter = width * .5;
         QRadialGradient gradient(hCenter, 0,
                                  width,
                                  hCenter, 0);
-        gradient.setColorAt(1, QColor(0xff, 0xff, 0xff, 0));
-        gradient.setColorAt(0, QColor(0xff, 0xff, 0xff, 16));
+        gradient.setColorAt(1, QColor(0x00, 0x00, 0x00, 0));
+        gradient.setColorAt(0, QColor(0x00, 0x00, 0x00, 16));
         painter->fillRect(0, 0, width, height, QBrush(gradient));
     }
 
-    painter->setPen(borderColor);
-#if defined(APP_MAC) | defined(APP_WIN)
-    painter->drawRect(-1, -1, width, height);
-#else
-    painter->drawRect(0, 0, width, height - 1);
-#endif
-
-    painter->setFont(FontUtils::smallBold());
-
-    // text shadow
-    painter->setPen(QColor(0, 0, 0, 128));
-    painter->drawText(0, -1, width, height, Qt::AlignCenter, action->text());
-
-    painter->setPen(QPen(Qt::white, 1));
-    painter->drawText(0, 0, width, height, Qt::AlignCenter, action->text());
-
     painter->restore();
 }
-