diff --git a/qtest.pro b/qtest.pro index 63ef85f..303f059 100644 --- a/qtest.pro +++ b/qtest.pro @@ -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" 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 RC_ICONS += assets/logo.ico diff --git a/src/qt/meterslider.h b/src/qt/meterslider.h new file mode 100644 index 0000000..a59e16e --- /dev/null +++ b/src/qt/meterslider.h @@ -0,0 +1,19 @@ +#include + +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; +}; diff --git a/src/qt/qtclasses.cpp b/src/qt/qtclasses.cpp index 6e90375..d0141ea 100644 --- a/src/qt/qtclasses.cpp +++ b/src/qt/qtclasses.cpp @@ -1,4 +1,5 @@ #include "qtclasses.h" +#include "meterslider.h" #define POLLING_RATE 2 template @@ -103,7 +104,6 @@ void MeterSlider::paintEvent(QPaintEvent *event) { QPainter painter(this); QStyle* stle = QApplication::style(); stle->drawComplexControl((QStyle::ComplexControl)CC_MeterSlider, &sliderComplex2, &painter, this); - //Q_D(QSlider); diff --git a/src/qt/qtclasses.h b/src/qt/qtclasses.h index 47216be..6a5e9aa 100644 --- a/src/qt/qtclasses.h +++ b/src/qt/qtclasses.h @@ -1,50 +1,10 @@ #pragma once -#include -#include -#include - -#include -#include -#include -//#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -//#include -/* - * #else - * class QSlider; - * class QLabel; - * class QGridLayout; - * class QPushButton; - * class QWidget; - * class QMainWindow; - * #endif - */ - -#include "global.h" +#include "qtcommon.h" #include "contclasses.h" +class MeterSlider; + enum SpawnPos { LEFT = (1 << 1), RIGHT = (0 << 1), @@ -70,26 +30,9 @@ public: }; //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. -#include "qtvisuals.h" +//#include "qtvisuals.h" class ExtendedCheckBox : public QCheckBox { Q_OBJECT diff --git a/src/qt/qtcommon.h b/src/qt/qtcommon.h new file mode 100644 index 0000000..8c9119c --- /dev/null +++ b/src/qt/qtcommon.h @@ -0,0 +1,165 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +//#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//#include +/* + * #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; + } +} + diff --git a/src/qt/qtvisuals.h b/src/qt/qtvisuals.h index bad98bb..f88c025 100644 --- a/src/qt/qtvisuals.h +++ b/src/qt/qtvisuals.h @@ -1,28 +1,9 @@ #pragma once -#include -#include -#include -#include -//#include "qstylehelper.cpp" - -//repeats. bruh. -//#include -//#include - -enum CustomComplexControl { - CC_MeterSlider = 0xf0000001 -}; - - -namespace qt64 { - static inline QLatin1String operator""_L1(const char* ch, uint64_t) { - return QLatin1String(ch); - } -} - -using namespace qt64; +#include "qtcommon.h" +#include "meterslider.h" +using namespace StylingHelper; class MixerStyle : public QProxyStyle { public: @@ -38,50 +19,6 @@ public: 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, SubControl subControl, const QWidget *widget) const { QRect rect = QCommonStyle::subControlRect(CC_Slider, option, subControl, widget); @@ -122,7 +59,7 @@ public: case SC_SliderGroove: { QPoint grooveCenter = slider->rect.center(); //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; if (slider->orientation == Qt::Horizontal) { rect.setHeight(grooveThickness); @@ -165,14 +102,14 @@ public: case CC_MeterSlider: if (const QStyleOptionSlider *slider = qstyleoption_cast(option)) { 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(CC_MeterSlider), option, SC_SliderGroove, widget); QRect handle = this->subControlRect(static_cast(CC_MeterSlider), option, SC_SliderHandle, widget); bool horizontal = slider->orientation == Qt::Horizontal; bool ticksAbove = slider->tickPosition & QSlider::TicksAbove; bool ticksBelow = slider->tickPosition & QSlider::TicksBelow; - QColor activeHighlight = this->highlight(option->palette); + QColor activeHighlight = highlight(option->palette); QPixmap cache; QBrush oldBrush = painter->brush(); QPen oldPen = painter->pen(); @@ -180,7 +117,7 @@ public: shadowAlpha.setAlpha(10); QColor outline; 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()) { QColor grooveColor; @@ -192,7 +129,7 @@ public: // draw background groove if (!QPixmapCache::find(groovePixmapName, &cache)) { - cache = this->styleCachePixmap(pixmapRect.size(), dpr); + cache = styleCachePixmap(pixmapRect.size(), dpr); QPainter groovePainter(&cache); groovePainter.setRenderHint(QPainter::Antialiasing, true); groovePainter.translate(0.5, 0.5); @@ -250,7 +187,7 @@ public: 1, 1, -pixmapRect.width() + (pixmapRect.width() * peakValue), -2), 1, 1); - groovePainter.setPen(this->innerContrastLine()); + groovePainter.setPen(innerContrastLine()); groovePainter.setBrush(Qt::green); double stepWidth = (double)widgetCast->width() * ((double)widgetCast->singleStep() / (widgetCast->maximum() - widgetCast->minimum())); groovePainter.drawRoundedRect(pixmapRect.adjusted( @@ -351,7 +288,7 @@ public: // gradient fill 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.translate(0.5, 0.5); @@ -360,14 +297,14 @@ public: handlePainter.setBrush(QColor(0, 0, 0, 40)); 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) - handlePainter.setPen(QPen(this->highlightedOutline(option->palette))); + handlePainter.setPen(QPen(highlightedOutline(option->palette))); handlePainter.setBrush(gradient); handlePainter.drawRoundedRect(r, 2, 2); handlePainter.setBrush(Qt::NoBrush); - handlePainter.setPen(this->innerContrastLine()); + handlePainter.setPen(innerContrastLine()); handlePainter.drawRoundedRect(r.adjusted(1, 1, -1, -1), 2, 2); QColor cornerAlpha = outline.darker(120); @@ -404,57 +341,7 @@ private: 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) { diff --git a/src/qtestmain.cpp b/src/qtestmain.cpp index f37e337..6c435c3 100644 --- a/src/qtestmain.cpp +++ b/src/qtestmain.cpp @@ -1,17 +1,9 @@ -#include -#include - -#include -#include -#include -#include -#include -#include -#include //#include "contclasses.h" #define INIT_FILELOG +#include "qtcommon.h" #include "qtclasses.h" -#include "global.h" +#include "qtvisuals.h" +//#include "global.h" OverseerHandler *osh = nullptr;