Qt code refactor w/ functional style
This commit is contained in:
parent
f8171f12f3
commit
f7de5ef803
7 changed files with 207 additions and 201 deletions
|
|
@ -11,7 +11,7 @@ DESTPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back" "$$PWD\src\back\reimpl"
|
||||||
VPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back" "$$PWD\src\back\reimpl" "$$PWD\src\cont"
|
VPATH += "$$PWD\src" "$$PWD\src\qt" "$$PWD\src\back" "$$PWD\src\back\reimpl" "$$PWD\src\cont"
|
||||||
|
|
||||||
SOURCES += qtestmain.cpp qtclasses.cpp backlasses.cpp backsessionclasses.cpp contclasses.cpp contsessionclasses.cpp
|
SOURCES += qtestmain.cpp qtclasses.cpp backlasses.cpp backsessionclasses.cpp contclasses.cpp contsessionclasses.cpp
|
||||||
HEADERS += qtclasses.h backlasses.h backsessionclasses.h contclasses.h contsessionclasses.h global.h debug.h backfuncs.h ipolicyconfig.h msinclude.h
|
HEADERS += qtclasses.h backlasses.h backsessionclasses.h contclasses.h contsessionclasses.h global.h debug.h backfuncs.h ipolicyconfig.h msinclude.h meterslider.h qtvisuals.h
|
||||||
RESOURCES = assets.qrc
|
RESOURCES = assets.qrc
|
||||||
RC_ICONS += assets/logo.ico
|
RC_ICONS += assets/logo.ico
|
||||||
|
|
||||||
|
|
|
||||||
19
src/qt/meterslider.h
Normal file
19
src/qt/meterslider.h
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
#include <QSlider>
|
||||||
|
|
||||||
|
class MeterSlider : public QSlider {
|
||||||
|
Q_OBJECT
|
||||||
|
private:
|
||||||
|
~MeterSlider();
|
||||||
|
float peakValue;
|
||||||
|
|
||||||
|
friend class MixerStyle;
|
||||||
|
protected:
|
||||||
|
bool event(QEvent* ev) override;
|
||||||
|
void paintEvent(QPaintEvent *event) override;
|
||||||
|
|
||||||
|
public:
|
||||||
|
//MeterSlider(Qt::Orientation orientation, QWidget *parent = nullptr);
|
||||||
|
//MeterSlider(QWidget* parent = nullptr) : MeterSlider(Qt::Vertical, parent){};
|
||||||
|
void setPeakValue(float peakValue);
|
||||||
|
using QSlider::QSlider;
|
||||||
|
};
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#include "qtclasses.h"
|
#include "qtclasses.h"
|
||||||
|
#include "meterslider.h"
|
||||||
#define POLLING_RATE 2
|
#define POLLING_RATE 2
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|
@ -105,7 +106,6 @@ void MeterSlider::paintEvent(QPaintEvent *event) {
|
||||||
stle->drawComplexControl((QStyle::ComplexControl)CC_MeterSlider, &sliderComplex2, &painter, this);
|
stle->drawComplexControl((QStyle::ComplexControl)CC_MeterSlider, &sliderComplex2, &painter, this);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Q_D(QSlider);
|
//Q_D(QSlider);
|
||||||
/*
|
/*
|
||||||
* QStylePainter p(this);
|
* QStylePainter p(this);
|
||||||
|
|
|
||||||
|
|
@ -1,50 +1,10 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include "qtcommon.h"
|
||||||
#include <QApplication>
|
|
||||||
#include <QCloseEvent>
|
|
||||||
|
|
||||||
#include <QIcon>
|
|
||||||
#include <QSystemTrayIcon>
|
|
||||||
#include <QMenu>
|
|
||||||
//#include <QMessageBox>
|
|
||||||
|
|
||||||
#include <QLabel>
|
|
||||||
#include <QSlider>
|
|
||||||
#include <QGridLayout>
|
|
||||||
#include <QPushButton>
|
|
||||||
#include <QCheckBox>
|
|
||||||
#include <QTimer>
|
|
||||||
#include <QScrollArea>
|
|
||||||
#include <QScrollBar>
|
|
||||||
#include <QSize>
|
|
||||||
#include <QMenuBar>
|
|
||||||
#include <QMenu>
|
|
||||||
#include <QScreen>
|
|
||||||
#include <QToolBar>
|
|
||||||
#include <QWindow>
|
|
||||||
#include <QPainter>
|
|
||||||
#include <QStyle>
|
|
||||||
#include <QStyleOptionComplex>
|
|
||||||
#include <QStyleOptionSlider>
|
|
||||||
#include <QStylePainter>
|
|
||||||
#include <QStyleOptionSlider>
|
|
||||||
#include <QFontMetrics>
|
|
||||||
//#include <QScrollBar>
|
|
||||||
/*
|
|
||||||
* #else
|
|
||||||
* class QSlider;
|
|
||||||
* class QLabel;
|
|
||||||
* class QGridLayout;
|
|
||||||
* class QPushButton;
|
|
||||||
* class QWidget;
|
|
||||||
* class QMainWindow;
|
|
||||||
* #endif
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "global.h"
|
|
||||||
#include "contclasses.h"
|
#include "contclasses.h"
|
||||||
|
|
||||||
|
class MeterSlider;
|
||||||
|
|
||||||
enum SpawnPos {
|
enum SpawnPos {
|
||||||
LEFT = (1 << 1),
|
LEFT = (1 << 1),
|
||||||
RIGHT = (0 << 1),
|
RIGHT = (0 << 1),
|
||||||
|
|
@ -70,26 +30,9 @@ public:
|
||||||
};
|
};
|
||||||
//Q_DECLARE_METATYPE(EndpointWidgetEvent)
|
//Q_DECLARE_METATYPE(EndpointWidgetEvent)
|
||||||
|
|
||||||
class MeterSlider : public QSlider {
|
|
||||||
Q_OBJECT
|
|
||||||
private:
|
|
||||||
~MeterSlider();
|
|
||||||
float peakValue;
|
|
||||||
|
|
||||||
friend class MixerStyle;
|
|
||||||
protected:
|
|
||||||
bool event(QEvent* ev) override;
|
|
||||||
void paintEvent(QPaintEvent *event) override;
|
|
||||||
|
|
||||||
public:
|
|
||||||
//MeterSlider(Qt::Orientation orientation, QWidget *parent = nullptr);
|
|
||||||
//MeterSlider(QWidget* parent = nullptr) : MeterSlider(Qt::Vertical, parent){};
|
|
||||||
void setPeakValue(float peakValue);
|
|
||||||
using QSlider::QSlider;
|
|
||||||
};
|
|
||||||
|
|
||||||
//todo: TEST. TEST.
|
//todo: TEST. TEST.
|
||||||
#include "qtvisuals.h"
|
//#include "qtvisuals.h"
|
||||||
|
|
||||||
class ExtendedCheckBox : public QCheckBox {
|
class ExtendedCheckBox : public QCheckBox {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
|
||||||
165
src/qt/qtcommon.h
Normal file
165
src/qt/qtcommon.h
Normal file
|
|
@ -0,0 +1,165 @@
|
||||||
|
#pragma once
|
||||||
|
#include <QLocalSocket>
|
||||||
|
#include <QLocalServer>
|
||||||
|
#include <QString>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QStringList>
|
||||||
|
#include <QStyleFactory>
|
||||||
|
#include <QPalette>
|
||||||
|
|
||||||
|
#include <QMainWindow>
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QCloseEvent>
|
||||||
|
|
||||||
|
#include <QIcon>
|
||||||
|
#include <QSystemTrayIcon>
|
||||||
|
#include <QMenu>
|
||||||
|
//#include <QMessageBox>
|
||||||
|
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QSlider>
|
||||||
|
#include <QGridLayout>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QCheckBox>
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QScrollArea>
|
||||||
|
#include <QScrollBar>
|
||||||
|
#include <QSize>
|
||||||
|
#include <QMenuBar>
|
||||||
|
#include <QMenu>
|
||||||
|
#include <QScreen>
|
||||||
|
#include <QToolBar>
|
||||||
|
#include <QWindow>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QStyle>
|
||||||
|
#include <QStyleOptionComplex>
|
||||||
|
#include <QStyleOptionSlider>
|
||||||
|
#include <QStylePainter>
|
||||||
|
#include <QStyleOptionSlider>
|
||||||
|
#include <QFontMetrics>
|
||||||
|
#include <QProxyStyle>
|
||||||
|
#include <QPixmapCache>
|
||||||
|
#include <QLatin1Char>
|
||||||
|
#include <QLatin1String>
|
||||||
|
|
||||||
|
//#include <QScrollBar>
|
||||||
|
/*
|
||||||
|
* #else
|
||||||
|
* class QSlider;
|
||||||
|
* class QLabel;
|
||||||
|
* class QGridLayout;
|
||||||
|
* class QPushButton;
|
||||||
|
* class QWidget;
|
||||||
|
* class QMainWindow;
|
||||||
|
* #endif
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "global.h"
|
||||||
|
|
||||||
|
enum CustomComplexControl {
|
||||||
|
CC_MeterSlider = 0xf0000001
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace StylingHelper {
|
||||||
|
static inline QLatin1String operator""_L1(const char* ch, uint64_t) {
|
||||||
|
return QLatin1String(ch);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline qreal dpi(const QStyleOption *option) {
|
||||||
|
#ifndef Q_OS_DARWIN
|
||||||
|
// Prioritize the application override, except for on macOS where
|
||||||
|
// we have historically not supported the AA_Use96Dpi flag.
|
||||||
|
if (QCoreApplication::testAttribute(Qt::AA_Use96Dpi))
|
||||||
|
return 96;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Expect that QStyleOption::QFontMetrics::QFont has the correct DPI set
|
||||||
|
if (option)
|
||||||
|
return option->fontMetrics.fontDpi();
|
||||||
|
|
||||||
|
// Fall back to historical Qt behavior: hardocded 72 DPI on mac,
|
||||||
|
// primary screen DPI on other platforms.
|
||||||
|
#ifdef Q_OS_DARWIN
|
||||||
|
return qstyleBaseDpi;
|
||||||
|
#else
|
||||||
|
return QGuiApplication::primaryScreen()->physicalDotsPerInch();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* #ifdef Q_OS_DARWIN
|
||||||
|
* static const qreal qstyleBaseDpi = 72;
|
||||||
|
* #else
|
||||||
|
* static const qreal qstyleBaseDpi = 96;
|
||||||
|
* #endif
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Q_GUI_EXPORT int qt_defaultDpiX() const;
|
||||||
|
|
||||||
|
|
||||||
|
static inline qreal dpiScaled(qreal value, qreal dpi) {
|
||||||
|
static const qreal qstyleBaseDpi = 96;
|
||||||
|
return value * dpi / qstyleBaseDpi;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline qreal dpiScaled(qreal value, const QPaintDevice *device) {
|
||||||
|
return dpiScaled(value, device->logicalDpiX());
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline qreal dpiScaled(qreal value, const QStyleOption *option) {
|
||||||
|
return dpiScaled(value, dpi(option));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool isMacSystemPalette(const QPalette &pal) {
|
||||||
|
Q_UNUSED(pal);
|
||||||
|
#if defined(Q_OS_MACOS)
|
||||||
|
const QPalette *themePalette = QGuiApplicationPrivate::platformTheme()->palette();
|
||||||
|
if (themePalette && themePalette->color(QPalette::Normal, QPalette::Highlight) ==
|
||||||
|
pal.color(QPalette::Normal, QPalette::Highlight) &&
|
||||||
|
themePalette->color(QPalette::Normal, QPalette::HighlightedText) ==
|
||||||
|
pal.color(QPalette::Normal, QPalette::HighlightedText))
|
||||||
|
return true;
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline QColor highlight(const QPalette &pal) {
|
||||||
|
if (isMacSystemPalette(pal))
|
||||||
|
return QColor(60, 140, 230);
|
||||||
|
return pal.color(QPalette::Highlight);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline QColor highlightedOutline(const QPalette &pal) {
|
||||||
|
QColor highlightedOutline = highlight(pal).darker(125);
|
||||||
|
if (highlightedOutline.value() > 160)
|
||||||
|
highlightedOutline.setHsl(highlightedOutline.hue(), highlightedOutline.saturation(), 160);
|
||||||
|
return highlightedOutline;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline QColor getOutline(const QPalette &pal) {
|
||||||
|
if (pal.window().style() == Qt::TexturePattern)
|
||||||
|
return QColor(0, 0, 0, 160);
|
||||||
|
return pal.window().color().darker(140);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline QColor getButtonColor(const QPalette &pal) {
|
||||||
|
QColor buttonColor = pal.button().color();
|
||||||
|
int val = qGray(buttonColor.rgb());
|
||||||
|
buttonColor = buttonColor.lighter(100 + qMax(1, (180 - val)/6));
|
||||||
|
buttonColor.setHsv(buttonColor.hue(), buttonColor.saturation() * 0.75, buttonColor.value());
|
||||||
|
return buttonColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline QColor innerContrastLine() {
|
||||||
|
return QColor(255, 255, 255, 30);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline QPixmap styleCachePixmap(const QSize &size, qreal pixelRatio) {
|
||||||
|
//not api
|
||||||
|
QPixmap cachePixmap = QPixmap(size * pixelRatio);
|
||||||
|
cachePixmap.setDevicePixelRatio(pixelRatio);
|
||||||
|
cachePixmap.fill(Qt::transparent);
|
||||||
|
return cachePixmap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -1,28 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QProxyStyle>
|
#include "qtcommon.h"
|
||||||
#include <QPixmapCache>
|
#include "meterslider.h"
|
||||||
#include <QLatin1Char>
|
|
||||||
#include <QLatin1String>
|
|
||||||
//#include "qstylehelper.cpp"
|
|
||||||
|
|
||||||
//repeats. bruh.
|
|
||||||
//#include <QStyleOptionSlider>
|
|
||||||
//#include <QPainter>
|
|
||||||
|
|
||||||
enum CustomComplexControl {
|
|
||||||
CC_MeterSlider = 0xf0000001
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
namespace qt64 {
|
|
||||||
static inline QLatin1String operator""_L1(const char* ch, uint64_t) {
|
|
||||||
return QLatin1String(ch);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
using namespace qt64;
|
|
||||||
|
|
||||||
|
using namespace StylingHelper;
|
||||||
|
|
||||||
class MixerStyle : public QProxyStyle {
|
class MixerStyle : public QProxyStyle {
|
||||||
public:
|
public:
|
||||||
|
|
@ -38,50 +19,6 @@ public:
|
||||||
return QProxyStyle::styleHint(hint, option, widget, returnData);
|
return QProxyStyle::styleHint(hint, option, widget, returnData);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* #ifdef Q_OS_DARWIN
|
|
||||||
* static const qreal qstyleBaseDpi = 72;
|
|
||||||
* #else
|
|
||||||
* static const qreal qstyleBaseDpi = 96;
|
|
||||||
* #endif
|
|
||||||
*/
|
|
||||||
|
|
||||||
//Q_GUI_EXPORT int qt_defaultDpiX() const;
|
|
||||||
|
|
||||||
qreal dpi(const QStyleOption *option) const {
|
|
||||||
#ifndef Q_OS_DARWIN
|
|
||||||
// Prioritize the application override, except for on macOS where
|
|
||||||
// we have historically not supported the AA_Use96Dpi flag.
|
|
||||||
if (QCoreApplication::testAttribute(Qt::AA_Use96Dpi))
|
|
||||||
return 96;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Expect that QStyleOption::QFontMetrics::QFont has the correct DPI set
|
|
||||||
if (option)
|
|
||||||
return option->fontMetrics.fontDpi();
|
|
||||||
|
|
||||||
// Fall back to historical Qt behavior: hardocded 72 DPI on mac,
|
|
||||||
// primary screen DPI on other platforms.
|
|
||||||
#ifdef Q_OS_DARWIN
|
|
||||||
return qstyleBaseDpi;
|
|
||||||
#else
|
|
||||||
return QGuiApplication::primaryScreen()->physicalDotsPerInch();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
qreal dpiScaled(qreal value, qreal dpi) const {
|
|
||||||
static const qreal qstyleBaseDpi = 96;
|
|
||||||
return value * dpi / qstyleBaseDpi;
|
|
||||||
}
|
|
||||||
|
|
||||||
qreal dpiScaled(qreal value, const QPaintDevice *device) const {
|
|
||||||
return dpiScaled(value, device->logicalDpiX());
|
|
||||||
}
|
|
||||||
|
|
||||||
qreal dpiScaled(qreal value, const QStyleOption *option) const {
|
|
||||||
return dpiScaled(value, dpi(option));
|
|
||||||
}
|
|
||||||
|
|
||||||
QRect subControlRect(ComplexControl control, const QStyleOptionComplex *option,
|
QRect subControlRect(ComplexControl control, const QStyleOptionComplex *option,
|
||||||
SubControl subControl, const QWidget *widget) const {
|
SubControl subControl, const QWidget *widget) const {
|
||||||
QRect rect = QCommonStyle::subControlRect(CC_Slider, option, subControl, widget);
|
QRect rect = QCommonStyle::subControlRect(CC_Slider, option, subControl, widget);
|
||||||
|
|
@ -122,7 +59,7 @@ public:
|
||||||
case SC_SliderGroove: {
|
case SC_SliderGroove: {
|
||||||
QPoint grooveCenter = slider->rect.center();
|
QPoint grooveCenter = slider->rect.center();
|
||||||
//rect.setWidth(std::abs(grooveCenter.x()) * 2);
|
//rect.setWidth(std::abs(grooveCenter.x()) * 2);
|
||||||
const int grooveThickness = this->dpiScaled(7, option); //QStyleHelper::dpiScaled(7, option);
|
const int grooveThickness = dpiScaled(7, option); //QStyleHelper::dpiScaled(7, option);
|
||||||
const bool bothTicks = (slider->tickPosition & QSlider::TicksBothSides) == QSlider::TicksBothSides;
|
const bool bothTicks = (slider->tickPosition & QSlider::TicksBothSides) == QSlider::TicksBothSides;
|
||||||
if (slider->orientation == Qt::Horizontal) {
|
if (slider->orientation == Qt::Horizontal) {
|
||||||
rect.setHeight(grooveThickness);
|
rect.setHeight(grooveThickness);
|
||||||
|
|
@ -165,14 +102,14 @@ public:
|
||||||
case CC_MeterSlider:
|
case CC_MeterSlider:
|
||||||
if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
|
if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
|
||||||
const qreal dpr = painter->device()->devicePixelRatio();
|
const qreal dpr = painter->device()->devicePixelRatio();
|
||||||
const QColor buttonColor = this->buttonColor(option->palette);
|
const QColor buttonColor = getButtonColor(option->palette);
|
||||||
QRect groove = this->subControlRect(static_cast<QStyle::ComplexControl>(CC_MeterSlider), option, SC_SliderGroove, widget);
|
QRect groove = this->subControlRect(static_cast<QStyle::ComplexControl>(CC_MeterSlider), option, SC_SliderGroove, widget);
|
||||||
QRect handle = this->subControlRect(static_cast<QStyle::ComplexControl>(CC_MeterSlider), option, SC_SliderHandle, widget);
|
QRect handle = this->subControlRect(static_cast<QStyle::ComplexControl>(CC_MeterSlider), option, SC_SliderHandle, widget);
|
||||||
|
|
||||||
bool horizontal = slider->orientation == Qt::Horizontal;
|
bool horizontal = slider->orientation == Qt::Horizontal;
|
||||||
bool ticksAbove = slider->tickPosition & QSlider::TicksAbove;
|
bool ticksAbove = slider->tickPosition & QSlider::TicksAbove;
|
||||||
bool ticksBelow = slider->tickPosition & QSlider::TicksBelow;
|
bool ticksBelow = slider->tickPosition & QSlider::TicksBelow;
|
||||||
QColor activeHighlight = this->highlight(option->palette);
|
QColor activeHighlight = highlight(option->palette);
|
||||||
QPixmap cache;
|
QPixmap cache;
|
||||||
QBrush oldBrush = painter->brush();
|
QBrush oldBrush = painter->brush();
|
||||||
QPen oldPen = painter->pen();
|
QPen oldPen = painter->pen();
|
||||||
|
|
@ -180,7 +117,7 @@ public:
|
||||||
shadowAlpha.setAlpha(10);
|
shadowAlpha.setAlpha(10);
|
||||||
QColor outline;
|
QColor outline;
|
||||||
if (option->state & State_HasFocus && option->state & State_KeyboardFocusChange)
|
if (option->state & State_HasFocus && option->state & State_KeyboardFocusChange)
|
||||||
outline = this->highlightedOutline(option->palette);
|
outline = highlightedOutline(option->palette);
|
||||||
|
|
||||||
if ((option->subControls & SC_SliderGroove) && groove.isValid()) {
|
if ((option->subControls & SC_SliderGroove) && groove.isValid()) {
|
||||||
QColor grooveColor;
|
QColor grooveColor;
|
||||||
|
|
@ -192,7 +129,7 @@ public:
|
||||||
|
|
||||||
// draw background groove
|
// draw background groove
|
||||||
if (!QPixmapCache::find(groovePixmapName, &cache)) {
|
if (!QPixmapCache::find(groovePixmapName, &cache)) {
|
||||||
cache = this->styleCachePixmap(pixmapRect.size(), dpr);
|
cache = styleCachePixmap(pixmapRect.size(), dpr);
|
||||||
QPainter groovePainter(&cache);
|
QPainter groovePainter(&cache);
|
||||||
groovePainter.setRenderHint(QPainter::Antialiasing, true);
|
groovePainter.setRenderHint(QPainter::Antialiasing, true);
|
||||||
groovePainter.translate(0.5, 0.5);
|
groovePainter.translate(0.5, 0.5);
|
||||||
|
|
@ -250,7 +187,7 @@ public:
|
||||||
1, 1,
|
1, 1,
|
||||||
-pixmapRect.width() + (pixmapRect.width() * peakValue),
|
-pixmapRect.width() + (pixmapRect.width() * peakValue),
|
||||||
-2), 1, 1);
|
-2), 1, 1);
|
||||||
groovePainter.setPen(this->innerContrastLine());
|
groovePainter.setPen(innerContrastLine());
|
||||||
groovePainter.setBrush(Qt::green);
|
groovePainter.setBrush(Qt::green);
|
||||||
double stepWidth = (double)widgetCast->width() * ((double)widgetCast->singleStep() / (widgetCast->maximum() - widgetCast->minimum()));
|
double stepWidth = (double)widgetCast->width() * ((double)widgetCast->singleStep() / (widgetCast->maximum() - widgetCast->minimum()));
|
||||||
groovePainter.drawRoundedRect(pixmapRect.adjusted(
|
groovePainter.drawRoundedRect(pixmapRect.adjusted(
|
||||||
|
|
@ -351,7 +288,7 @@ public:
|
||||||
|
|
||||||
// gradient fill
|
// gradient fill
|
||||||
QRect r = pixmapRect.adjusted(1, 1, -2, -2);
|
QRect r = pixmapRect.adjusted(1, 1, -2, -2);
|
||||||
QLinearGradient gradient = qt_fusion_gradient(gradRect, this->buttonColor(option->palette),horizontal ? TopDown : FromLeft);
|
QLinearGradient gradient = qt_fusion_gradient(gradRect, getButtonColor(option->palette),horizontal ? TopDown : FromLeft);
|
||||||
|
|
||||||
handlePainter.setRenderHint(QPainter::Antialiasing, true);
|
handlePainter.setRenderHint(QPainter::Antialiasing, true);
|
||||||
handlePainter.translate(0.5, 0.5);
|
handlePainter.translate(0.5, 0.5);
|
||||||
|
|
@ -360,14 +297,14 @@ public:
|
||||||
handlePainter.setBrush(QColor(0, 0, 0, 40));
|
handlePainter.setBrush(QColor(0, 0, 0, 40));
|
||||||
handlePainter.drawRect(horizontal ? r.adjusted(-1, 2, 1, -2) : r.adjusted(2, -1, -2, 1));
|
handlePainter.drawRect(horizontal ? r.adjusted(-1, 2, 1, -2) : r.adjusted(2, -1, -2, 1));
|
||||||
|
|
||||||
handlePainter.setPen(QPen(this->outline(option->palette)));
|
handlePainter.setPen(QPen(getOutline(option->palette)));
|
||||||
if (option->state & State_HasFocus && option->state & State_KeyboardFocusChange)
|
if (option->state & State_HasFocus && option->state & State_KeyboardFocusChange)
|
||||||
handlePainter.setPen(QPen(this->highlightedOutline(option->palette)));
|
handlePainter.setPen(QPen(highlightedOutline(option->palette)));
|
||||||
|
|
||||||
handlePainter.setBrush(gradient);
|
handlePainter.setBrush(gradient);
|
||||||
handlePainter.drawRoundedRect(r, 2, 2);
|
handlePainter.drawRoundedRect(r, 2, 2);
|
||||||
handlePainter.setBrush(Qt::NoBrush);
|
handlePainter.setBrush(Qt::NoBrush);
|
||||||
handlePainter.setPen(this->innerContrastLine());
|
handlePainter.setPen(innerContrastLine());
|
||||||
handlePainter.drawRoundedRect(r.adjusted(1, 1, -1, -1), 2, 2);
|
handlePainter.drawRoundedRect(r.adjusted(1, 1, -1, -1), 2, 2);
|
||||||
|
|
||||||
QColor cornerAlpha = outline.darker(120);
|
QColor cornerAlpha = outline.darker(120);
|
||||||
|
|
@ -404,57 +341,7 @@ private:
|
||||||
FromRight
|
FromRight
|
||||||
};
|
};
|
||||||
|
|
||||||
QColor highlightedOutline(const QPalette &pal) const {
|
|
||||||
QColor highlightedOutline = highlight(pal).darker(125);
|
|
||||||
if (highlightedOutline.value() > 160)
|
|
||||||
highlightedOutline.setHsl(highlightedOutline.hue(), highlightedOutline.saturation(), 160);
|
|
||||||
return highlightedOutline;
|
|
||||||
}
|
|
||||||
|
|
||||||
QColor outline(const QPalette &pal) const {
|
|
||||||
if (pal.window().style() == Qt::TexturePattern)
|
|
||||||
return QColor(0, 0, 0, 160);
|
|
||||||
return pal.window().color().darker(140);
|
|
||||||
}
|
|
||||||
|
|
||||||
QColor buttonColor(const QPalette &pal) const {
|
|
||||||
QColor buttonColor = pal.button().color();
|
|
||||||
int val = qGray(buttonColor.rgb());
|
|
||||||
buttonColor = buttonColor.lighter(100 + qMax(1, (180 - val)/6));
|
|
||||||
buttonColor.setHsv(buttonColor.hue(), buttonColor.saturation() * 0.75, buttonColor.value());
|
|
||||||
return buttonColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
QColor highlight(const QPalette &pal) const {
|
|
||||||
if (isMacSystemPalette(pal))
|
|
||||||
return QColor(60, 140, 230);
|
|
||||||
return pal.color(QPalette::Highlight);
|
|
||||||
}
|
|
||||||
|
|
||||||
QColor innerContrastLine() const {
|
|
||||||
return QColor(255, 255, 255, 30);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isMacSystemPalette(const QPalette &pal) const {
|
|
||||||
Q_UNUSED(pal);
|
|
||||||
#if defined(Q_OS_MACOS)
|
|
||||||
const QPalette *themePalette = QGuiApplicationPrivate::platformTheme()->palette();
|
|
||||||
if (themePalette && themePalette->color(QPalette::Normal, QPalette::Highlight) ==
|
|
||||||
pal.color(QPalette::Normal, QPalette::Highlight) &&
|
|
||||||
themePalette->color(QPalette::Normal, QPalette::HighlightedText) ==
|
|
||||||
pal.color(QPalette::Normal, QPalette::HighlightedText))
|
|
||||||
return true;
|
|
||||||
#endif
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline QPixmap styleCachePixmap(const QSize &size, qreal pixelRatio) const {
|
|
||||||
//not api
|
|
||||||
QPixmap cachePixmap = QPixmap(size * pixelRatio);
|
|
||||||
cachePixmap.setDevicePixelRatio(pixelRatio);
|
|
||||||
cachePixmap.fill(Qt::transparent);
|
|
||||||
return cachePixmap;
|
|
||||||
}
|
|
||||||
|
|
||||||
static QLinearGradient qt_fusion_gradient(const QRect &rect, const QBrush &baseColor, Direction direction = TopDown)
|
static QLinearGradient qt_fusion_gradient(const QRect &rect, const QBrush &baseColor, Direction direction = TopDown)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,9 @@
|
||||||
#include <QApplication>
|
|
||||||
#include <QMainWindow>
|
|
||||||
|
|
||||||
#include <QLocalSocket>
|
|
||||||
#include <QLocalServer>
|
|
||||||
#include <QString>
|
|
||||||
#include <QFile>
|
|
||||||
#include <QStringList>
|
|
||||||
#include <QStyleFactory>
|
|
||||||
#include <QPalette>
|
|
||||||
//#include "contclasses.h"
|
//#include "contclasses.h"
|
||||||
#define INIT_FILELOG
|
#define INIT_FILELOG
|
||||||
|
#include "qtcommon.h"
|
||||||
#include "qtclasses.h"
|
#include "qtclasses.h"
|
||||||
#include "global.h"
|
#include "qtvisuals.h"
|
||||||
|
//#include "global.h"
|
||||||
|
|
||||||
OverseerHandler *osh = nullptr;
|
OverseerHandler *osh = nullptr;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue