| | |
| | | int main(int argc, char *argv[]) { |
| | | qputenv("QT_WIN_DEBUG_CONSOLE", "attach"); |
| | | qputenv("QSG_INFO", "1"); |
| | | #if 0 |
| | | qputenv("QT_WIDGETS_RHI", "1"); |
| | | qputenv("QSG_RHI_BACKEND", "d3d12"); |
| | | qputenv("QSG_RHI_HDR", "scrgb"); |
| | | qputenv("QT_QPA_DISABLE_REDIRECTION_SURFACE", "1"); |
| | | //qputenv("QT_WIDGETS_HIGHDPI_DOWNSCALE", "1"); |
| | | //qputenv("QT_WIDGETS_RHI", "1"); |
| | | //qputenv("QSG_RHI_BACKEND", "d3d12"); |
| | | //qputenv("QSG_RHI_HDR", "scrgb"); |
| | | //qputenv("QT_QPA_DISABLE_REDIRECTION_SURFACE", "1"); |
| | | |
| | | #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) |
| | | QGuiApplication::setHighDpiScaleFactorRoundingPolicy( |
| | | Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); |
| | | #endif |
| | | |
| | | QGuiApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); |
| | | QCoreApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); |
| | | QApplication a(argc, argv); |
| | | |
| | | #if 0 && defined(Q_OS_WINDOWS) && QT_VERSION < QT_VERSION_CHECK(6, 0, 0) |
| | | QApplication::setFont([]() { |
| | | QFont f("Microsoft YaHei"); |
| | | f.setStyleStrategy(QFont::PreferAntialias); |
| | | f.setPixelSize(15); |
| | | return f; |
| | | }()); |
| | | #endif |
| | | |
| | | MainWindow w; |
| | | w.show(); |
| | | |
| | | #if 0 |
| | | QMainWindow w2; |
| | | w2.show(); |
| | | #endif |
| | | return a.exec(); |
| | | } |
| | |
| | | |
| | | protected: |
| | | void timerEvent(QTimerEvent *event) override { |
| | | QLabel::timerEvent(event); |
| | | setText(QTime::currentTime().toString(QStringLiteral("hh:mm:ss"))); |
| | | } |
| | | }; |
| | | |
| | | MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { |
| | | setAttribute(Qt::WA_DontCreateNativeAncestors); |
| | | |
| | | installWindowAgent(); |
| | | |
| | | #if 1 |
| | |
| | | return QMainWindow::event(event); |
| | | } |
| | | |
| | | |
| | | void MainWindow::closeEvent(QCloseEvent *event) { |
| | | // if (!(qApp->keyboardModifiers() & Qt::ControlModifier)) { |
| | | // QTimer::singleShot(1000, this, &QWidget::show); |
| | | // } |
| | | event->accept(); |
| | | } |
| | | |
| | | void MainWindow::installWindowAgent() { |
| | | // 1. Setup window agent |
| | | windowAgent = new QWK::WidgetWindowAgent(this); |
| | |
| | | }); |
| | | |
| | | #ifdef Q_OS_WIN |
| | | auto noneAction = new QAction(tr("None"), menuBar); |
| | | noneAction->setData(QStringLiteral("none")); |
| | | noneAction->setCheckable(true); |
| | | noneAction->setChecked(true); |
| | | |
| | | auto dwmBlurAction = new QAction(tr("Enable DWM blur"), menuBar); |
| | | dwmBlurAction->setData(QStringLiteral("dwm-blur")); |
| | | dwmBlurAction->setCheckable(true); |
| | |
| | | micaAltAction->setCheckable(true); |
| | | |
| | | auto winStyleGroup = new QActionGroup(menuBar); |
| | | // At most one action can be checked at any one time. The actions can also be all unchecked. |
| | | winStyleGroup->setExclusionPolicy(QActionGroup::ExclusionPolicy::ExclusiveOptional); |
| | | winStyleGroup->addAction(noneAction); |
| | | winStyleGroup->addAction(dwmBlurAction); |
| | | winStyleGroup->addAction(acrylicAction); |
| | | winStyleGroup->addAction(micaAction); |
| | | winStyleGroup->addAction(micaAltAction); |
| | | connect(winStyleGroup, &QActionGroup::triggered, this, [this, winStyleGroup](QAction *action) { |
| | | // Unset all custom style attributes first, otherwise the style will not display correctly |
| | | for (auto _act : winStyleGroup->actions()) { |
| | | windowAgent->setWindowAttribute(_act->data().toString(), false); |
| | | for (const QAction* _act : winStyleGroup->actions()) { |
| | | const QString data = _act->data().toString(); |
| | | if (data.isEmpty() || data == QStringLiteral("none")) { |
| | | continue; |
| | | } |
| | | windowAgent->setWindowAttribute(action->data().toString(), action->isChecked()); |
| | | setProperty("custom-style", action->isChecked()); |
| | | windowAgent->setWindowAttribute(data, false); |
| | | } |
| | | const QString data = action->data().toString(); |
| | | if (data == QStringLiteral("none")) { |
| | | setProperty("custom-style", false); |
| | | } else if (!data.isEmpty()) { |
| | | windowAgent->setWindowAttribute(data, true); |
| | | setProperty("custom-style", true); |
| | | } |
| | | style()->polish(this); |
| | | }); |
| | | |
| | |
| | | |
| | | #ifdef Q_OS_WIN |
| | | settings->addSeparator(); |
| | | settings->addAction(noneAction); |
| | | settings->addAction(dwmBlurAction); |
| | | settings->addAction(acrylicAction); |
| | | settings->addAction(micaAction); |
| | |
| | | protected: |
| | | bool event(QEvent *event) override; |
| | | |
| | | void closeEvent(QCloseEvent *event) override; |
| | | |
| | | private: |
| | | void installWindowAgent(); |
| | | void loadStyleSheet(Theme theme); |
| | |
| | | mipmap: true |
| | | width: 12 |
| | | height: 12 |
| | | fillMode: Image.PreserveAspectFit |
| | | } |
| | | } |
| | | background: Rectangle { |
| | |
| | | |
| | | #include <QtGui/QGuiApplication> |
| | | #include <QtQml/QQmlApplicationEngine> |
| | | #include <QtQml/QQmlContext> |
| | | #include <QtQuick/QQuickWindow> |
| | | |
| | | #include <QWKQuick/qwkquickglobal.h> |
| | | |
| | | #ifdef Q_OS_WIN |
| | | // Indicates to hybrid graphics systems to prefer the discrete part by default. |
| | | extern "C" { |
| | | Q_DECL_EXPORT unsigned long NvOptimusEnablement = 0x00000001; |
| | | Q_DECL_EXPORT int AmdPowerXpressRequestHighPerformance = 1; |
| | | } |
| | | #endif |
| | | |
| | | int main(int argc, char *argv[]) { |
| | | qputenv("QT_WIN_DEBUG_CONSOLE", "attach"); |
| | | qputenv("QT_WIN_DEBUG_CONSOLE", "attach"); // or "new": create a separate console window |
| | | qputenv("QSG_INFO", "1"); |
| | | qputenv("QSG_NO_VSYNC", "1"); |
| | | #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
| | | qputenv("QT_QUICK_CONTROLS_STYLE", "Basic"); |
| | | #else |
| | | qputenv("QT_QUICK_CONTROLS_STYLE", "Default"); |
| | | #endif |
| | | #if 0 |
| | | qputenv("QSG_RHI_BACKEND", "opengl"); |
| | | //qputenv("QSG_RHI_HDR", "scrgb"); |
| | | //qputenv("QSG_RHI_BACKEND", "opengl"); // other options: d3d11, d3d12, vulkan |
| | | //qputenv("QSG_RHI_HDR", "scrgb"); // other options: hdr10, p3 |
| | | //qputenv("QT_QPA_DISABLE_REDIRECTION_SURFACE", "1"); |
| | | #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) |
| | | QGuiApplication::setHighDpiScaleFactorRoundingPolicy( |
| | | Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); |
| | | #endif |
| | |
| | | // Make sure alpha channel is requested, our special effects on Windows depends on it. |
| | | QQuickWindow::setDefaultAlphaBuffer(true); |
| | | QQmlApplicationEngine engine; |
| | | #if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0) |
| | | const bool curveRenderingAvailable = true; |
| | | #else |
| | | const bool curveRenderingAvailable = false; |
| | | #endif |
| | | engine.rootContext()->setContextProperty(QStringLiteral("$curveRenderingAvailable"), QVariant(curveRenderingAvailable)); |
| | | QWK::registerTypes(&engine); |
| | | engine.load(QUrl(QStringLiteral("qrc:///main.qml"))); |
| | | return application.exec(); |
| | |
| | | title: qsTr("Hello, world!") |
| | | Component.onCompleted: { |
| | | windowAgent.setup(window) |
| | | windowAgent.setWindowAttribute("dark-mode", true) |
| | | window.visible = true |
| | | } |
| | | |
| | |
| | | id: windowAgent |
| | | } |
| | | |
| | | MouseArea { |
| | | anchors.fill: parent |
| | | TapHandler { |
| | | acceptedButtons: Qt.RightButton |
| | | onClicked: contextMenu.open() |
| | | onTapped: contextMenu.open() |
| | | } |
| | | |
| | | Rectangle { |
| | |
| | | height: 18 |
| | | mipmap: true |
| | | source: "qrc:///app/example.png" |
| | | fillMode: Image.PreserveAspectFit |
| | | Component.onCompleted: windowAgent.setSystemButton(WindowAgent.WindowIcon, iconButton) |
| | | } |
| | | |
| | |
| | | bold: true |
| | | } |
| | | color: "#FEFEFE" |
| | | Component.onCompleted: { |
| | | if ($curveRenderingAvailable) { |
| | | timeLabel.renderType = Text.CurveRendering |
| | | } |
| | | } |
| | | } |
| | | |
| | | Menu { |
| | |
| | | MenuItem { |
| | | text: qsTr("Dark") |
| | | checkable: true |
| | | checked: true |
| | | onTriggered: windowAgent.setWindowAttribute("dark-mode", true) |
| | | } |
| | | } |
| | |
| | | |
| | | MenuItem { |
| | | enabled: Qt.platform.os === "windows" |
| | | text: qsTr("None") |
| | | checkable: true |
| | | checked: true |
| | | onTriggered: { |
| | | window.color = darkStyle.windowBackgroundColor |
| | | windowAgent.setWindowAttribute("dwm-blur", false) |
| | | windowAgent.setWindowAttribute("acrylic-material", false) |
| | | windowAgent.setWindowAttribute("mica", false) |
| | | windowAgent.setWindowAttribute("mica-alt", false) |
| | | } |
| | | } |
| | | |
| | | MenuItem { |
| | | enabled: Qt.platform.os === "windows" |
| | | text: qsTr("DWM blur") |
| | | checkable: true |
| | | onTriggered: { |
| | | window.color = checked ? "transparent" : darkStyle.windowBackgroundColor |
| | | windowAgent.setWindowAttribute("dwm-blur", checked) |
| | | window.color = "transparent" |
| | | windowAgent.setWindowAttribute("acrylic-material", false) |
| | | windowAgent.setWindowAttribute("mica", false) |
| | | windowAgent.setWindowAttribute("mica-alt", false) |
| | | windowAgent.setWindowAttribute("dwm-blur", true) |
| | | } |
| | | } |
| | | |
| | |
| | | text: qsTr("Acrylic material") |
| | | checkable: true |
| | | onTriggered: { |
| | | window.color = checked ? "transparent" : darkStyle.windowBackgroundColor |
| | | windowAgent.setWindowAttribute("acrylic-material", checked) |
| | | window.color = "transparent" |
| | | windowAgent.setWindowAttribute("dwm-blur", false) |
| | | windowAgent.setWindowAttribute("mica", false) |
| | | windowAgent.setWindowAttribute("mica-alt", false) |
| | | windowAgent.setWindowAttribute("acrylic-material", true) |
| | | } |
| | | } |
| | | |
| | |
| | | text: qsTr("Mica") |
| | | checkable: true |
| | | onTriggered: { |
| | | window.color = checked ? "transparent" : darkStyle.windowBackgroundColor |
| | | windowAgent.setWindowAttribute("mica", checked) |
| | | window.color = "transparent" |
| | | windowAgent.setWindowAttribute("dwm-blur", false) |
| | | windowAgent.setWindowAttribute("acrylic-material", false) |
| | | windowAgent.setWindowAttribute("mica-alt", false) |
| | | windowAgent.setWindowAttribute("mica", true) |
| | | } |
| | | } |
| | | |
| | |
| | | text: qsTr("Mica Alt") |
| | | checkable: true |
| | | onTriggered: { |
| | | window.color = checked ? "transparent" : darkStyle.windowBackgroundColor |
| | | windowAgent.setWindowAttribute("mica-alt", checked) |
| | | window.color = "transparent" |
| | | windowAgent.setWindowAttribute("dwm-blur", false) |
| | | windowAgent.setWindowAttribute("acrylic-material", false) |
| | | windowAgent.setWindowAttribute("mica", false) |
| | | windowAgent.setWindowAttribute("mica-alt", true) |
| | | } |
| | | } |
| | | } |