From b4fe7ac7e2433f4659f8197cd36a84d53626255f Mon Sep 17 00:00:00 2001 From: Arun Narayanankutty Date: Wed, 13 Jan 2016 22:05:31 -0600 Subject: [PATCH] move duplicated code to annonymous namespace static function update --- src/widgets/fancytabwidget.cpp | 88 +++++++++++++--------------------- 1 file changed, 34 insertions(+), 54 deletions(-) diff --git a/src/widgets/fancytabwidget.cpp b/src/widgets/fancytabwidget.cpp index c61d3fe83..ccc93b119 100644 --- a/src/widgets/fancytabwidget.cpp +++ b/src/widgets/fancytabwidget.cpp @@ -55,6 +55,38 @@ using namespace Internal; const int FancyTabBar::m_rounding = 22; const int FancyTabBar::m_textPadding = 4; + +namespace { +static void selectTab(QPainter* p, const QRect& rect) { + // background + p->save(); + QLinearGradient grad(rect.topLeft(), rect.topRight()); + grad.setColorAt(0, QColor(255, 255, 255, 140)); + grad.setColorAt(1, QColor(255, 255, 255, 210)); + p->fillRect(rect.adjusted(0, 0, 0, -1), grad); + p->restore(); + + // shadows + p->setPen(QColor(0, 0, 0, 110)); + p->drawLine(rect.topLeft() + QPoint(1, -1), rect.topRight() - QPoint(0, 1)); + p->drawLine(rect.bottomLeft(), rect.bottomRight()); + p->setPen(QColor(0, 0, 0, 40)); + p->drawLine(rect.topLeft(), rect.bottomLeft()); + + // highlights + p->setPen(QColor(255, 255, 255, 50)); + p->drawLine(rect.topLeft() + QPoint(0, -2), rect.topRight() - QPoint(0, 2)); + p->drawLine(rect.bottomLeft() + QPoint(0, 1), + rect.bottomRight() + QPoint(0, 1)); + p->setPen(QColor(255, 255, 255, 40)); + p->drawLine(rect.topLeft() + QPoint(0, 0), rect.topRight()); + p->drawLine(rect.topRight() + QPoint(0, 1), + rect.bottomRight() - QPoint(0, 1)); + p->drawLine(rect.bottomLeft() + QPoint(0, -1), + rect.bottomRight() - QPoint(0, 1)); +} +} + void FancyTabProxyStyle::drawControl(ControlElement element, const QStyleOption* option, QPainter* p, const QWidget* widget) const { @@ -73,32 +105,7 @@ void FancyTabProxyStyle::drawControl(ControlElement element, const QString text = v_opt->text; if (selected) { - // background - p->save(); - QLinearGradient grad(rect.topLeft(), rect.topRight()); - grad.setColorAt(0, QColor(255, 255, 255, 140)); - grad.setColorAt(1, QColor(255, 255, 255, 210)); - p->fillRect(rect.adjusted(0, 0, 0, -1), grad); - p->restore(); - - // shadows - p->setPen(QColor(0, 0, 0, 110)); - p->drawLine(rect.topLeft() + QPoint(1, -1), rect.topRight() - QPoint(0, 1)); - p->drawLine(rect.bottomLeft(), rect.bottomRight()); - p->setPen(QColor(0, 0, 0, 40)); - p->drawLine(rect.topLeft(), rect.bottomLeft()); - - // highlights - p->setPen(QColor(255, 255, 255, 50)); - p->drawLine(rect.topLeft() + QPoint(0, -2), rect.topRight() - QPoint(0, 2)); - p->drawLine(rect.bottomLeft() + QPoint(0, 1), - rect.bottomRight() + QPoint(0, 1)); - p->setPen(QColor(255, 255, 255, 40)); - p->drawLine(rect.topLeft() + QPoint(0, 0), rect.topRight()); - p->drawLine(rect.topRight() + QPoint(0, 1), - rect.bottomRight() - QPoint(0, 1)); - p->drawLine(rect.bottomLeft() + QPoint(0, -1), - rect.bottomRight() - QPoint(0, 1)); + selectTab(p, rect); } QTransform m; @@ -394,34 +401,7 @@ void FancyTabBar::paintTab(QPainter* painter, int tabIndex) const { bool selected = (tabIndex == m_currentIndex); if (selected) { - // background - painter->save(); - QLinearGradient grad(rect.topLeft(), rect.topRight()); - grad.setColorAt(0, QColor(255, 255, 255, 140)); - grad.setColorAt(1, QColor(255, 255, 255, 210)); - painter->fillRect(rect.adjusted(0, 0, 0, -1), grad); - painter->restore(); - - // shadows - painter->setPen(QColor(0, 0, 0, 110)); - painter->drawLine(rect.topLeft() + QPoint(1, -1), - rect.topRight() - QPoint(0, 1)); - painter->drawLine(rect.bottomLeft(), rect.bottomRight()); - painter->setPen(QColor(0, 0, 0, 40)); - painter->drawLine(rect.topLeft(), rect.bottomLeft()); - - // highlights - painter->setPen(QColor(255, 255, 255, 50)); - painter->drawLine(rect.topLeft() + QPoint(0, -2), - rect.topRight() - QPoint(0, 2)); - painter->drawLine(rect.bottomLeft() + QPoint(0, 1), - rect.bottomRight() + QPoint(0, 1)); - painter->setPen(QColor(255, 255, 255, 40)); - painter->drawLine(rect.topLeft() + QPoint(0, 0), rect.topRight()); - painter->drawLine(rect.topRight() + QPoint(0, 1), - rect.bottomRight() - QPoint(0, 1)); - painter->drawLine(rect.bottomLeft() + QPoint(0, -1), - rect.bottomRight() - QPoint(0, 1)); + selectTab(painter, rect); } QString tabText(painter->fontMetrics().elidedText(this->tabText(tabIndex),