diff --git a/qtest.pro b/qtest.pro index 303f059..63ef85f 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 meterslider.h qtvisuals.h +HEADERS += qtclasses.h backlasses.h backsessionclasses.h contclasses.h contsessionclasses.h global.h debug.h backfuncs.h ipolicyconfig.h msinclude.h RESOURCES = assets.qrc RC_ICONS += assets/logo.ico diff --git a/src/qt/meterslider.h b/src/qt/meterslider.h deleted file mode 100644 index a59e16e..0000000 --- a/src/qt/meterslider.h +++ /dev/null @@ -1,19 +0,0 @@ -#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 d0141ea..6e90375 100644 --- a/src/qt/qtclasses.cpp +++ b/src/qt/qtclasses.cpp @@ -1,5 +1,4 @@ #include "qtclasses.h" -#include "meterslider.h" #define POLLING_RATE 2 template @@ -104,6 +103,7 @@ 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 6a5e9aa..47216be 100644 --- a/src/qt/qtclasses.h +++ b/src/qt/qtclasses.h @@ -1,9 +1,49 @@ #pragma once -#include "qtcommon.h" -#include "contclasses.h" +#include +#include +#include -class MeterSlider; +#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 "contclasses.h" enum SpawnPos { LEFT = (1 << 1), @@ -30,9 +70,26 @@ 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 deleted file mode 100644 index 8c9119c..0000000 --- a/src/qt/qtcommon.h +++ /dev/null @@ -1,165 +0,0 @@ -#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 f88c025..f8b4b64 100644 --- a/src/qt/qtvisuals.h +++ b/src/qt/qtvisuals.h @@ -1,9 +1,31 @@ #pragma once -#include "qtcommon.h" -#include "meterslider.h" +#include +#include +#include +#include +//#include "qstylehelper.cpp" -using namespace StylingHelper; +//repeats. bruh. +#include +#include + +enum CustomComplexControl { + CC_MeterSlider = 0xf0000001 +}; + +//using namespace Qt::Literals::StringLiterals +//using namespace QtLiterals; + +/* + * namespace qt64 { + * QLatin1String operator""_L1(const char* ch) { + * return QLatin1String(ch); + * } + * } + * + * using namespace qt64; + */ class MixerStyle : public QProxyStyle { public: @@ -19,6 +41,50 @@ 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); @@ -43,8 +109,8 @@ public: } rect.moveTop(centerY); } else { - rect.setWidth(baseStyle()->pixelMetric(PM_SliderThickness, option, widget)); - rect.setHeight(baseStyle()->pixelMetric(PM_SliderLength, option, widget)); + rect.setWidth(proxy()->pixelMetric(PM_SliderThickness, option, widget)); + rect.setHeight(proxy()->pixelMetric(PM_SliderLength, option, widget)); int centerX = slider->rect.center().x() - rect.width() / 2; if (!bothTicks) { if (slider->tickPosition & QSlider::TicksAbove) @@ -59,7 +125,7 @@ public: case SC_SliderGroove: { QPoint grooveCenter = slider->rect.center(); //rect.setWidth(std::abs(grooveCenter.x()) * 2); - const int grooveThickness = dpiScaled(7, option); //QStyleHelper::dpiScaled(7, option); + const int grooveThickness = this->dpiScaled(7, option); //QStyleHelper::dpiScaled(7, option); const bool bothTicks = (slider->tickPosition & QSlider::TicksBothSides) == QSlider::TicksBothSides; if (slider->orientation == Qt::Horizontal) { rect.setHeight(grooveThickness); @@ -102,14 +168,14 @@ public: case CC_MeterSlider: if (const QStyleOptionSlider *slider = qstyleoption_cast(option)) { const qreal dpr = painter->device()->devicePixelRatio(); - const QColor buttonColor = getButtonColor(option->palette); + const QColor buttonColor = this->buttonColor(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 = highlight(option->palette); + QColor activeHighlight = this->highlight(option->palette); QPixmap cache; QBrush oldBrush = painter->brush(); QPen oldPen = painter->pen(); @@ -117,7 +183,7 @@ public: shadowAlpha.setAlpha(10); QColor outline; if (option->state & State_HasFocus && option->state & State_KeyboardFocusChange) - outline = highlightedOutline(option->palette); + outline = this->highlightedOutline(option->palette); if ((option->subControls & SC_SliderGroove) && groove.isValid()) { QColor grooveColor; @@ -129,7 +195,7 @@ public: // draw background groove if (!QPixmapCache::find(groovePixmapName, &cache)) { - cache = styleCachePixmap(pixmapRect.size(), dpr); + cache = this->styleCachePixmap(pixmapRect.size(), dpr); QPainter groovePainter(&cache); groovePainter.setRenderHint(QPainter::Antialiasing, true); groovePainter.translate(0.5, 0.5); @@ -157,7 +223,6 @@ public: if (widgetCast) { QRect clipRect; //if (!groovePixmapName.isEmpty()) groovePixmapName += QLatin1String("_unattenuated"); - //groovePixmapName += "_unattenuated"_L1; //lf (!QPixmapCache::find(groovePixmapName, &cache)) { cache = styleCachePixmap(pixmapRect.size(), dpr); QPainter groovePainter(&cache); @@ -187,7 +252,7 @@ public: 1, 1, -pixmapRect.width() + (pixmapRect.width() * peakValue), -2), 1, 1); - groovePainter.setPen(innerContrastLine()); + groovePainter.setPen(this->innerContrastLine()); groovePainter.setBrush(Qt::green); double stepWidth = (double)widgetCast->width() * ((double)widgetCast->singleStep() / (widgetCast->maximum() - widgetCast->minimum())); groovePainter.drawRoundedRect(pixmapRect.adjusted( @@ -288,7 +353,7 @@ public: // gradient fill QRect r = pixmapRect.adjusted(1, 1, -2, -2); - QLinearGradient gradient = qt_fusion_gradient(gradRect, getButtonColor(option->palette),horizontal ? TopDown : FromLeft); + QLinearGradient gradient = qt_fusion_gradient(gradRect, this->buttonColor(option->palette),horizontal ? TopDown : FromLeft); handlePainter.setRenderHint(QPainter::Antialiasing, true); handlePainter.translate(0.5, 0.5); @@ -297,14 +362,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(getOutline(option->palette))); + handlePainter.setPen(QPen(this->outline(option->palette))); if (option->state & State_HasFocus && option->state & State_KeyboardFocusChange) - handlePainter.setPen(QPen(highlightedOutline(option->palette))); + handlePainter.setPen(QPen(this->highlightedOutline(option->palette))); handlePainter.setBrush(gradient); handlePainter.drawRoundedRect(r, 2, 2); handlePainter.setBrush(Qt::NoBrush); - handlePainter.setPen(innerContrastLine()); + handlePainter.setPen(this->innerContrastLine()); handlePainter.drawRoundedRect(r.adjusted(1, 1, -1, -1), 2, 2); QColor cornerAlpha = outline.darker(120); @@ -341,7 +406,57 @@ 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 6c435c3..f37e337 100644 --- a/src/qtestmain.cpp +++ b/src/qtestmain.cpp @@ -1,9 +1,17 @@ +#include +#include + +#include +#include +#include +#include +#include +#include +#include //#include "contclasses.h" #define INIT_FILELOG -#include "qtcommon.h" #include "qtclasses.h" -#include "qtvisuals.h" -//#include "global.h" +#include "global.h" OverseerHandler *osh = nullptr;