From 4171bc4c7057365812731cb0625421123531c2e7 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Wed, 24 Apr 2019 23:44:04 +0200 Subject: [PATCH] Delete old stylehelper --- src/widgets/stylehelper.cpp | 228 ------------------------------------ src/widgets/stylehelper.h | 81 ------------- 2 files changed, 309 deletions(-) delete mode 100644 src/widgets/stylehelper.cpp delete mode 100644 src/widgets/stylehelper.h diff --git a/src/widgets/stylehelper.cpp b/src/widgets/stylehelper.cpp deleted file mode 100644 index f4884d78e..000000000 --- a/src/widgets/stylehelper.cpp +++ /dev/null @@ -1,228 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** Commercial Usage -** -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://qt.nokia.com/contact. -** -**************************************************************************/ - -#include "config.h" - -#include "stylehelper.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "core/qt_blurimage.h" - -// Clamps float color values within (0, 255) -static int clamp(float x) { - const int val = x > 255 ? 255 : static_cast(x); - return val < 0 ? 0 : val; -} - -namespace Utils { - -qreal StyleHelper::sidebarFontSize() { -#if defined(Q_OS_MACOS) - return 10; -#else - return 7.5; -#endif -} - -QColor StyleHelper::panelTextColor(bool lightColored) { - if (!lightColored) - return Qt::white; - else - return Qt::black; -} - -// Invalid by default, setBaseColor needs to be called at least once -QColor StyleHelper::m_baseColor; -QColor StyleHelper::m_requestedBaseColor; - -QColor StyleHelper::baseColor(bool lightColored) { - if (!lightColored) - return m_baseColor; - else - return m_baseColor.lighter(230); -} - -QColor StyleHelper::highlightColor(bool lightColored) { - QColor result = baseColor(lightColored); - if (!lightColored) - result.setHsv(result.hue(), clamp(result.saturation()), clamp(result.value() * 1.16)); - else - result.setHsv(result.hue(), clamp(result.saturation()), clamp(result.value() * 1.06)); - return result; -} - -QColor StyleHelper::shadowColor(bool lightColored) -{ - QColor result = baseColor(lightColored); - result.setHsv(result.hue(), clamp(result.saturation() * 1.1), clamp(result.value() * 0.70)); - return result; -} - -QColor StyleHelper::borderColor(bool lightColored) { - QColor result = baseColor(lightColored); - result.setHsv(result.hue(), result.saturation(), result.value() / 2); - return result; -} - -// We try to ensure that the actual color used are within reasonalbe bounds while generating the actual baseColor from the users request. -void StyleHelper::setBaseColor(const QColor &newcolor) { - m_requestedBaseColor = newcolor; - - QColor color; - color.setHsv(newcolor.hue(), newcolor.saturation() * 0.7, 64 + newcolor.value() / 3); - - if (color.isValid() && color != m_baseColor) { - m_baseColor = color; - for (QWidget* w : QApplication::topLevelWidgets()) { - w->update(); - } - } -} - -static void verticalGradientHelper(QPainter *p, const QRect &spanRect, const QRect &rect, bool lightColored) { - QColor highlight = StyleHelper::highlightColor(lightColored); - QColor shadow = StyleHelper::shadowColor(lightColored); - QLinearGradient grad(spanRect.topRight(), spanRect.topLeft()); - grad.setColorAt(0, highlight.lighter(117)); - grad.setColorAt(1, shadow.darker(109)); - p->fillRect(rect, grad); - - QColor light(255, 255, 255, 80); - p->setPen(light); - p->drawLine(rect.topRight() - QPoint(1, 0), rect.bottomRight() - QPoint(1, 0)); - QColor dark(0, 0, 0, 90); - p->setPen(dark); - p->drawLine(rect.topLeft(), rect.bottomLeft()); -} - -void StyleHelper::verticalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect, bool lightColored) { - if (StyleHelper::usePixmapCache()) { - QString key; - QColor keyColor = baseColor(lightColored); - key.sprintf("mh_vertical %d %d %d %d %d", spanRect.width(), spanRect.height(), clipRect.width(), clipRect.height(), keyColor.rgb()); - - QPixmap pixmap; - if (!QPixmapCache::find(key, pixmap)) { - pixmap = QPixmap(clipRect.size()); - QPainter p(&pixmap); - QRect rect(0, 0, clipRect.width(), clipRect.height()); - verticalGradientHelper(&p, spanRect, rect, lightColored); - p.end(); - QPixmapCache::insert(key, pixmap); - } - - painter->drawPixmap(clipRect.topLeft(), pixmap); - } - else { - verticalGradientHelper(painter, spanRect, clipRect, lightColored); - } -} - -// Draws a cached pixmap with shadow -void StyleHelper::drawIconWithShadow(const QIcon &icon, const QRect &rect, QPainter *p, QIcon::Mode iconMode, int radius, const QColor &color, const QPoint &offset) { - QPixmap cache; - QString pixmapName = QString("icon %0 %1 %2").arg(icon.cacheKey()).arg(iconMode).arg(rect.height()); - - if (!QPixmapCache::find(pixmapName, cache)) { - QPixmap px = icon.pixmap(rect.size()); - cache = QPixmap(px.size() + QSize(radius * 2, radius * 2)); - cache.fill(Qt::transparent); - - QPainter cachePainter(&cache); - if (iconMode == QIcon::Disabled) { - QImage im = px.toImage().convertToFormat(QImage::Format_ARGB32); - for (int y=0; ydrawPixmap(targetRect.topLeft() - offset, cache); -} - -} // namespace Utils diff --git a/src/widgets/stylehelper.h b/src/widgets/stylehelper.h deleted file mode 100644 index d3616b2dd..000000000 --- a/src/widgets/stylehelper.h +++ /dev/null @@ -1,81 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** Commercial Usage -** -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://qt.nokia.com/contact. -** -**************************************************************************/ - -#ifndef STYLEHELPER_H -#define STYLEHELPER_H - -#include - -#include -#include -#include -#include -#include -#include - -// Helper class holding all custom color values - -namespace Utils { -class StyleHelper -{ -public: - static const unsigned int DEFAULT_BASE_COLOR = 0x666666; - - // Height of the project explorer navigation bar - static qreal sidebarFontSize(); - - // This is our color table, all colors derive from baseColor - static QColor requestedBaseColor() { return m_requestedBaseColor; } - static QColor baseColor(bool lightColored = false); - static QColor panelTextColor(bool lightColored = false); - static QColor highlightColor(bool lightColored = false); - static QColor shadowColor(bool lightColored = false); - static QColor borderColor(bool lightColored = false); - - static QColor sidebarHighlight() { return QColor(255, 255, 255, 40); } - static QColor sidebarShadow() { return QColor(0, 0, 0, 40); } - - // Sets the base color and makes sure all top level widgets are updated - static void setBaseColor(const QColor &color); - - // Gradients used for panels - static void verticalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect, bool lightColored = false); - static bool usePixmapCache() { return true; } - - static void drawIconWithShadow(const QIcon &icon, const QRect &rect, QPainter *p, QIcon::Mode iconMode, int radius = 3, const QColor &color = QColor(0, 0, 0, 130), const QPoint &offset = QPoint(1, -2)); - -private: - static QColor m_baseColor; - static QColor m_requestedBaseColor; -}; - -} // namespace Utils - -using Utils::StyleHelper; -#endif // STYLEHELPER_H