178 lines
4.9 KiB
C++
178 lines
4.9 KiB
C++
#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 <QScrollbarStyleAnimation>
|
|
//#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 calculateDpi(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, calculateDpi(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;
|
|
}
|
|
|
|
static inline QColor backgroundColor(const QPalette &pal, const QWidget* widget)
|
|
{
|
|
#if QT_CONFIG(scrollarea)
|
|
if (qobject_cast<const QScrollBar *>(widget) && widget->parent() &&
|
|
qobject_cast<const QAbstractScrollArea *>(widget->parent()->parent()))
|
|
return widget->parentWidget()->parentWidget()->palette().color(QPalette::Base);
|
|
#else
|
|
Q_UNUSED(widget);
|
|
#endif
|
|
return pal.color(QPalette::Base);
|
|
}
|
|
|
|
}
|
|
|