|
|
|
@@ -1,24 +1,24 @@ |
|
|
|
/* |
|
|
|
* Carla Style, based on Qt5 fusion style |
|
|
|
* Copyright (C) 2013 Filipe Coelho <falktx@falktx.com> |
|
|
|
* Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies) |
|
|
|
* Copyright (C) 2013 Filipe Coelho <falktx@falktx.com> |
|
|
|
* |
|
|
|
* This program 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 any later version. |
|
|
|
* modify it under the terms of the GNU Lesser General Public |
|
|
|
* License as published by the Free Software Foundation. |
|
|
|
* |
|
|
|
* This program 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. |
|
|
|
* GNU Lesser General Public License for more details. |
|
|
|
* |
|
|
|
* For a full copy of the GNU General Public License see the GPL3.txt file |
|
|
|
* For a full copy of the license see the doc/LGPL.txt file |
|
|
|
*/ |
|
|
|
|
|
|
|
#include "CarlaStylePrivate.hpp" |
|
|
|
|
|
|
|
#include <QtCore/qmath.h> |
|
|
|
#include <QtCore/QSettings> |
|
|
|
#include <QtCore/QStringBuilder> |
|
|
|
|
|
|
|
#include <QtGui/QPainter> |
|
|
|
@@ -524,67 +524,12 @@ CarlaStyle::CarlaStyle() |
|
|
|
d(new CarlaStylePrivate(this)) |
|
|
|
{ |
|
|
|
setObjectName(QLatin1String("Carla")); |
|
|
|
} |
|
|
|
|
|
|
|
CarlaStyle::~CarlaStyle() |
|
|
|
{ |
|
|
|
} |
|
|
|
|
|
|
|
void CarlaStyle::setColorScheme(ColorScheme color) |
|
|
|
{ |
|
|
|
switch (color) |
|
|
|
{ |
|
|
|
case COLOR_BLACK: |
|
|
|
qApp->setPalette(fPalBlack); |
|
|
|
break; |
|
|
|
case COLOR_BLUE: |
|
|
|
qApp->setPalette(fPalBlue); |
|
|
|
break; |
|
|
|
case COLOR_SYSTEM: |
|
|
|
qApp->setPalette(fPalSystem); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void printPalette(const QPalette& pal) |
|
|
|
{ |
|
|
|
#define PAL "fPalBlue" |
|
|
|
QApplication* const app(qApp); |
|
|
|
|
|
|
|
#define PAL_PRINT(ROLE) \ |
|
|
|
{ \ |
|
|
|
QColor color1(pal.color(QPalette::Disabled, ROLE)); \ |
|
|
|
QColor color2(pal.color(QPalette::Active, ROLE)); \ |
|
|
|
QColor color3(pal.color(QPalette::Inactive, ROLE)); \ |
|
|
|
printf(PAL ".setColor(QPalette::Disabled, " #ROLE ", QColor(%i, %i, %i));\n", color1.red(), color1.green(), color1.blue()); \ |
|
|
|
printf(PAL ".setColor(QPalette::Active, " #ROLE ", QColor(%i, %i, %i));\n", color2.red(), color2.green(), color2.blue()); \ |
|
|
|
printf(PAL ".setColor(QPalette::Inactive, " #ROLE ", QColor(%i, %i, %i));\n", color3.red(), color3.green(), color3.blue()); \ |
|
|
|
} |
|
|
|
|
|
|
|
PAL_PRINT(QPalette::Window) |
|
|
|
PAL_PRINT(QPalette::WindowText) |
|
|
|
PAL_PRINT(QPalette::Base) |
|
|
|
PAL_PRINT(QPalette::AlternateBase) |
|
|
|
PAL_PRINT(QPalette::ToolTipBase) |
|
|
|
PAL_PRINT(QPalette::ToolTipText) |
|
|
|
PAL_PRINT(QPalette::Text) |
|
|
|
PAL_PRINT(QPalette::Button) |
|
|
|
PAL_PRINT(QPalette::ButtonText) |
|
|
|
PAL_PRINT(QPalette::BrightText) |
|
|
|
PAL_PRINT(QPalette::Light) |
|
|
|
PAL_PRINT(QPalette::Midlight) |
|
|
|
PAL_PRINT(QPalette::Dark) |
|
|
|
PAL_PRINT(QPalette::Mid) |
|
|
|
PAL_PRINT(QPalette::Shadow) |
|
|
|
PAL_PRINT(QPalette::Highlight) |
|
|
|
PAL_PRINT(QPalette::HighlightedText) |
|
|
|
PAL_PRINT(QPalette::Link) |
|
|
|
PAL_PRINT(QPalette::LinkVisited) |
|
|
|
|
|
|
|
#undef PAL |
|
|
|
} |
|
|
|
if (app == nullptr) |
|
|
|
return; |
|
|
|
|
|
|
|
void CarlaStyle::ready(QApplication* app) |
|
|
|
{ |
|
|
|
fPalSystem = app->palette(); |
|
|
|
|
|
|
|
fPalBlack.setColor(QPalette::Disabled, QPalette::Window, QColor(14, 14, 14)); |
|
|
|
@@ -702,6 +647,83 @@ void CarlaStyle::ready(QApplication* app) |
|
|
|
fPalBlue.setColor(QPalette::Disabled, QPalette::LinkVisited, QColor(51, 74, 118)); |
|
|
|
fPalBlue.setColor(QPalette::Active, QPalette::LinkVisited, QColor(64, 128, 255)); |
|
|
|
fPalBlue.setColor(QPalette::Inactive, QPalette::LinkVisited, QColor(64, 128, 255)); |
|
|
|
|
|
|
|
setColorSchemeAsNeeded(); |
|
|
|
} |
|
|
|
|
|
|
|
CarlaStyle::~CarlaStyle() |
|
|
|
{ |
|
|
|
delete d; |
|
|
|
} |
|
|
|
|
|
|
|
void CarlaStyle::setColorSchemeAsNeeded() |
|
|
|
{ |
|
|
|
QSettings settings("falkTX", "Carla"); |
|
|
|
|
|
|
|
if (! settings.value("Main/UseProTheme", true).toBool()) |
|
|
|
return; |
|
|
|
|
|
|
|
QString color(settings.value("Main/ProThemeColor", "Black").toString()); |
|
|
|
|
|
|
|
if (color == "System") |
|
|
|
setColorScheme(CarlaStyle::COLOR_SYSTEM); |
|
|
|
else if (color == "Blue") |
|
|
|
setColorScheme(CarlaStyle::COLOR_BLUE); |
|
|
|
else |
|
|
|
setColorScheme(CarlaStyle::COLOR_BLACK); |
|
|
|
} |
|
|
|
|
|
|
|
void CarlaStyle::setColorScheme(ColorScheme color) |
|
|
|
{ |
|
|
|
switch (color) |
|
|
|
{ |
|
|
|
case COLOR_BLACK: |
|
|
|
qApp->setPalette(fPalBlack); |
|
|
|
break; |
|
|
|
case COLOR_BLUE: |
|
|
|
qApp->setPalette(fPalBlue); |
|
|
|
break; |
|
|
|
case COLOR_SYSTEM: |
|
|
|
qApp->setPalette(fPalSystem); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void printPalette(const QPalette& pal) |
|
|
|
{ |
|
|
|
#define PAL "fPalBlue" |
|
|
|
|
|
|
|
#define PAL_PRINT(ROLE) \ |
|
|
|
{ \ |
|
|
|
QColor color1(pal.color(QPalette::Disabled, ROLE)); \ |
|
|
|
QColor color2(pal.color(QPalette::Active, ROLE)); \ |
|
|
|
QColor color3(pal.color(QPalette::Inactive, ROLE)); \ |
|
|
|
printf(PAL ".setColor(QPalette::Disabled, " #ROLE ", QColor(%i, %i, %i));\n", color1.red(), color1.green(), color1.blue()); \ |
|
|
|
printf(PAL ".setColor(QPalette::Active, " #ROLE ", QColor(%i, %i, %i));\n", color2.red(), color2.green(), color2.blue()); \ |
|
|
|
printf(PAL ".setColor(QPalette::Inactive, " #ROLE ", QColor(%i, %i, %i));\n", color3.red(), color3.green(), color3.blue()); \ |
|
|
|
} |
|
|
|
|
|
|
|
PAL_PRINT(QPalette::Window) |
|
|
|
PAL_PRINT(QPalette::WindowText) |
|
|
|
PAL_PRINT(QPalette::Base) |
|
|
|
PAL_PRINT(QPalette::AlternateBase) |
|
|
|
PAL_PRINT(QPalette::ToolTipBase) |
|
|
|
PAL_PRINT(QPalette::ToolTipText) |
|
|
|
PAL_PRINT(QPalette::Text) |
|
|
|
PAL_PRINT(QPalette::Button) |
|
|
|
PAL_PRINT(QPalette::ButtonText) |
|
|
|
PAL_PRINT(QPalette::BrightText) |
|
|
|
PAL_PRINT(QPalette::Light) |
|
|
|
PAL_PRINT(QPalette::Midlight) |
|
|
|
PAL_PRINT(QPalette::Dark) |
|
|
|
PAL_PRINT(QPalette::Mid) |
|
|
|
PAL_PRINT(QPalette::Shadow) |
|
|
|
PAL_PRINT(QPalette::Highlight) |
|
|
|
PAL_PRINT(QPalette::HighlightedText) |
|
|
|
PAL_PRINT(QPalette::Link) |
|
|
|
PAL_PRINT(QPalette::LinkVisited) |
|
|
|
|
|
|
|
#undef PAL |
|
|
|
} |
|
|
|
|
|
|
|
/*! |
|
|
|
@@ -1213,15 +1235,13 @@ void CarlaStyle::drawPrimitive(PrimitiveElement elem, |
|
|
|
r = rect.adjusted(0, 1, -1, 0); |
|
|
|
|
|
|
|
bool isEnabled = option->state & State_Enabled; |
|
|
|
bool hasFocus = (option->state & State_HasFocus && option->state & State_KeyboardFocusChange); |
|
|
|
QColor buttonColor = d->buttonColor(option->palette); |
|
|
|
QColor darkOutline = outline; |
|
|
|
|
|
|
|
#if 0 |
|
|
|
bool hasFocus = (option->state & State_HasFocus && option->state & State_KeyboardFocusChange); |
|
|
|
if (hasFocus | isDefault) { |
|
|
|
QColor darkOutline = outline; |
|
|
|
if (hasFocus || isDefault) { |
|
|
|
darkOutline = highlightedOutline; |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
|
if (isDefault) |
|
|
|
buttonColor = mergedColors(buttonColor, highlightedOutline.lighter(130), 90); |
|
|
|
@@ -1408,7 +1428,7 @@ void CarlaStyle::drawControl(ControlElement element, const QStyleOption *option, |
|
|
|
case CE_ToolBar: |
|
|
|
if (const QStyleOptionToolBar *toolBar = qstyleoption_cast<const QStyleOptionToolBar *>(option)) { |
|
|
|
// Reserve the beveled appearance only for mainwindow toolbars |
|
|
|
if (!(widget && qobject_cast<const QMainWindow*> (widget->parentWidget()))) |
|
|
|
if (widget && !(qobject_cast<const QMainWindow*> (widget->parentWidget()))) |
|
|
|
break; |
|
|
|
|
|
|
|
// Draws the light line above and the dark line below menu bars and |
|
|
|
@@ -1541,6 +1561,10 @@ void CarlaStyle::drawControl(ControlElement element, const QStyleOption *option, |
|
|
|
- titleRect.bottom(), |
|
|
|
r.top() + titleRect.left() - rect.left(), |
|
|
|
titleRect.height(), titleRect.width()); |
|
|
|
|
|
|
|
painter->translate(r.left(), r.top() + r.width()); |
|
|
|
painter->rotate(-90); |
|
|
|
painter->translate(-r.left(), -r.top()); |
|
|
|
} |
|
|
|
|
|
|
|
if (!dwOpt->title.isEmpty()) { |
|
|
|
@@ -2004,7 +2028,7 @@ void CarlaStyle::drawControl(ControlElement element, const QStyleOption *option, |
|
|
|
if (menuItem->menuItemType == QStyleOptionMenuItem::SubMenu) {// draw sub menu arrow |
|
|
|
int dim = (menuItem->rect.height() - 4) / 2; |
|
|
|
PrimitiveElement arrow; |
|
|
|
arrow = QApplication::isRightToLeft() ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight; |
|
|
|
arrow = option->direction == Qt::RightToLeft ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight; |
|
|
|
int xpos = menuItem->rect.left() + menuItem->rect.width() - 3 - dim; |
|
|
|
QRect vSubMenuRect = visualRect(option->direction, menuItem->rect, |
|
|
|
QRect(xpos, menuItem->rect.top() + menuItem->rect.height() / 2 - dim / 2, dim, dim)); |
|
|
|
@@ -3113,53 +3137,6 @@ void CarlaStyle::drawComplexControl(ComplexControl control, const QStyleOptionCo |
|
|
|
painter->restore(); |
|
|
|
} |
|
|
|
|
|
|
|
// draw handle |
|
|
|
if ((option->subControls & SC_SliderHandle) ) { |
|
|
|
QString handlePixmapName = uniqueName(QLatin1String("slider_handle"), option, handle.size()); |
|
|
|
if (!QPixmapCache::find(handlePixmapName, cache)) { |
|
|
|
cache = styleCachePixmap(handle.size()); |
|
|
|
cache.fill(Qt::transparent); |
|
|
|
QRect pixmapRect(0, 0, handle.width(), handle.height()); |
|
|
|
QPainter handlePainter(&cache); |
|
|
|
QRect gradRect = pixmapRect.adjusted(2, 2, -2, -2); |
|
|
|
|
|
|
|
// gradient fill |
|
|
|
QRect r = pixmapRect.adjusted(1, 1, -2, -2); |
|
|
|
QLinearGradient gradient = qt_fusion_gradient(gradRect, d->buttonColor(option->palette),horizontal ? TopDown : FromLeft); |
|
|
|
|
|
|
|
handlePainter.setRenderHint(QPainter::Antialiasing, true); |
|
|
|
handlePainter.translate(0.5, 0.5); |
|
|
|
|
|
|
|
handlePainter.setPen(Qt::NoPen); |
|
|
|
handlePainter.setBrush(QColor(0, 0, 0, 40)); |
|
|
|
handlePainter.drawRect(r.adjusted(-1, 2, 1, -2)); |
|
|
|
|
|
|
|
handlePainter.setPen(QPen(d->outline(option->palette), 1)); |
|
|
|
if (option->state & State_HasFocus && option->state & State_KeyboardFocusChange) |
|
|
|
handlePainter.setPen(QPen(d->highlightedOutline(option->palette), 1)); |
|
|
|
|
|
|
|
handlePainter.setBrush(gradient); |
|
|
|
handlePainter.drawRoundedRect(r, 2, 2); |
|
|
|
handlePainter.setBrush(Qt::NoBrush); |
|
|
|
handlePainter.setPen(d->innerContrastLine()); |
|
|
|
handlePainter.drawRoundedRect(r.adjusted(1, 1, -1, -1), 2, 2); |
|
|
|
|
|
|
|
QColor cornerAlpha = outline.darker(120); |
|
|
|
cornerAlpha.setAlpha(80); |
|
|
|
|
|
|
|
//handle shadow |
|
|
|
handlePainter.setPen(shadowAlpha); |
|
|
|
handlePainter.drawLine(QPoint(r.left() + 2, r.bottom() + 1), QPoint(r.right() - 2, r.bottom() + 1)); |
|
|
|
handlePainter.drawLine(QPoint(r.right() + 1, r.bottom() - 3), QPoint(r.right() + 1, r.top() + 4)); |
|
|
|
handlePainter.drawLine(QPoint(r.right() - 1, r.bottom()), QPoint(r.right() + 1, r.bottom() - 2)); |
|
|
|
|
|
|
|
handlePainter.end(); |
|
|
|
QPixmapCache::insert(handlePixmapName, cache); |
|
|
|
} |
|
|
|
|
|
|
|
painter->drawPixmap(handle.topLeft(), cache); |
|
|
|
|
|
|
|
} |
|
|
|
if (option->subControls & SC_SliderTickmarks) { |
|
|
|
painter->setPen(outline); |
|
|
|
int tickSize = proxy()->pixelMetric(PM_SliderTickmarkOffset, option, widget); |
|
|
|
@@ -3215,6 +3192,54 @@ void CarlaStyle::drawComplexControl(ComplexControl control, const QStyleOptionCo |
|
|
|
v = nextInterval; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// draw handle |
|
|
|
if ((option->subControls & SC_SliderHandle) ) { |
|
|
|
QString handlePixmapName = uniqueName(QLatin1String("slider_handle"), option, handle.size()); |
|
|
|
if (!QPixmapCache::find(handlePixmapName, cache)) { |
|
|
|
cache = styleCachePixmap(handle.size()); |
|
|
|
cache.fill(Qt::transparent); |
|
|
|
QRect pixmapRect(0, 0, handle.width(), handle.height()); |
|
|
|
QPainter handlePainter(&cache); |
|
|
|
QRect gradRect = pixmapRect.adjusted(2, 2, -2, -2); |
|
|
|
|
|
|
|
// gradient fill |
|
|
|
QRect r = pixmapRect.adjusted(1, 1, -2, -2); |
|
|
|
QLinearGradient gradient = qt_fusion_gradient(gradRect, d->buttonColor(option->palette),horizontal ? TopDown : FromLeft); |
|
|
|
|
|
|
|
handlePainter.setRenderHint(QPainter::Antialiasing, true); |
|
|
|
handlePainter.translate(0.5, 0.5); |
|
|
|
|
|
|
|
handlePainter.setPen(Qt::NoPen); |
|
|
|
handlePainter.setBrush(QColor(0, 0, 0, 40)); |
|
|
|
handlePainter.drawRect(r.adjusted(-1, 2, 1, -2)); |
|
|
|
|
|
|
|
handlePainter.setPen(QPen(d->outline(option->palette), 1)); |
|
|
|
if (option->state & State_HasFocus && option->state & State_KeyboardFocusChange) |
|
|
|
handlePainter.setPen(QPen(d->highlightedOutline(option->palette), 1)); |
|
|
|
|
|
|
|
handlePainter.setBrush(gradient); |
|
|
|
handlePainter.drawRoundedRect(r, 2, 2); |
|
|
|
handlePainter.setBrush(Qt::NoBrush); |
|
|
|
handlePainter.setPen(d->innerContrastLine()); |
|
|
|
handlePainter.drawRoundedRect(r.adjusted(1, 1, -1, -1), 2, 2); |
|
|
|
|
|
|
|
QColor cornerAlpha = outline.darker(120); |
|
|
|
cornerAlpha.setAlpha(80); |
|
|
|
|
|
|
|
//handle shadow |
|
|
|
handlePainter.setPen(shadowAlpha); |
|
|
|
handlePainter.drawLine(QPoint(r.left() + 2, r.bottom() + 1), QPoint(r.right() - 2, r.bottom() + 1)); |
|
|
|
handlePainter.drawLine(QPoint(r.right() + 1, r.bottom() - 3), QPoint(r.right() + 1, r.top() + 4)); |
|
|
|
handlePainter.drawLine(QPoint(r.right() - 1, r.bottom()), QPoint(r.right() + 1, r.bottom() - 2)); |
|
|
|
|
|
|
|
handlePainter.end(); |
|
|
|
QPixmapCache::insert(handlePixmapName, cache); |
|
|
|
} |
|
|
|
|
|
|
|
painter->drawPixmap(handle.topLeft(), cache); |
|
|
|
} |
|
|
|
|
|
|
|
painter->setBrush(oldBrush); |
|
|
|
painter->setPen(oldPen); |
|
|
|
} |
|
|
|
@@ -3236,6 +3261,8 @@ int CarlaStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, cons |
|
|
|
{ |
|
|
|
switch (metric) |
|
|
|
{ |
|
|
|
case PM_SliderTickmarkOffset: |
|
|
|
return 4; |
|
|
|
case PM_HeaderMargin: |
|
|
|
return 2; |
|
|
|
case PM_ToolTipLabelFrameWidth: |
|
|
|
@@ -3335,9 +3362,9 @@ QSize CarlaStyle::sizeFromContents(ContentsType type, const QStyleOption* option |
|
|
|
case CT_PushButton: |
|
|
|
if (const QStyleOptionButton* btn = qstyleoption_cast<const QStyleOptionButton *>(option)) |
|
|
|
{ |
|
|
|
if (newSize.width() < 80 && ! btn->text.isEmpty()) |
|
|
|
if (!btn->text.isEmpty() && newSize.width() < 80) |
|
|
|
newSize.setWidth(80); |
|
|
|
if (btn->iconSize.height() > 16 && ! btn->icon.isNull()) |
|
|
|
if (!btn->icon.isNull() && btn->iconSize.height() > 16) |
|
|
|
newSize -= QSize(0, 2); |
|
|
|
} |
|
|
|
break; |
|
|
|
@@ -3834,6 +3861,9 @@ QRect CarlaStyle::subElementRect(SubElement sr, const QStyleOption *opt, const Q |
|
|
|
return r; |
|
|
|
} |
|
|
|
|
|
|
|
#ifdef CARLA_EXPORT_STYLE |
|
|
|
# include "resources.cpp" |
|
|
|
|
|
|
|
CarlaStylePlugin::CarlaStylePlugin(QObject* parent) |
|
|
|
: QStylePlugin(parent) |
|
|
|
{ |
|
|
|
@@ -3849,7 +3879,5 @@ QStringList CarlaStylePlugin::keys() const |
|
|
|
return QStringList() << "Carla"; |
|
|
|
} |
|
|
|
|
|
|
|
#ifdef CARLA_EXPORT_STYLE |
|
|
|
# include "resources.cpp" |
|
|
|
Q_EXPORT_PLUGIN2(Carla, CarlaStylePlugin) |
|
|
|
#endif |