fix examples for Core API 2.0
This commit is contained in:
parent
af797125f8
commit
d680ad87b1
|
@ -7,7 +7,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>518</width>
|
||||
<height>368</height>
|
||||
<height>383</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -20,9 +20,16 @@
|
|||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_3">
|
||||
<widget class="QPushButton" name="uninstallBtn">
|
||||
<property name="text">
|
||||
<string>PushButton</string>
|
||||
<string>Uninstall Frameless Window</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="installBtn">
|
||||
<property name="text">
|
||||
<string>Install Frameless Window</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -122,6 +129,15 @@
|
|||
<height>25</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="mouseTracking">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::NoFocus</enum>
|
||||
</property>
|
||||
<property name="nativeMenuBar">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuItem_1">
|
||||
<property name="title">
|
||||
<string>Menu 1</string>
|
||||
|
|
|
@ -38,14 +38,14 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(par
|
|||
appMainWindow = new Ui::MainWindow;
|
||||
appMainWindow->setupUi(this);
|
||||
|
||||
const auto widget = new QWidget(this);
|
||||
m_titleBar = new QWidget(this);
|
||||
titleBarWidget = new Ui::TitleBar;
|
||||
titleBarWidget->setupUi(widget);
|
||||
titleBarWidget->setupUi(m_titleBar);
|
||||
|
||||
QMenuBar *mb = menuBar();
|
||||
titleBarWidget->horizontalLayout->insertWidget(1, mb);
|
||||
|
||||
setMenuWidget(widget);
|
||||
setMenuWidget(m_titleBar);
|
||||
|
||||
connect(this, &MainWindow::windowIconChanged, titleBarWidget->iconButton, &QPushButton::setIcon);
|
||||
connect(this, &MainWindow::windowTitleChanged, titleBarWidget->titleLabel, &QLabel::setText);
|
||||
|
@ -63,6 +63,13 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(par
|
|||
titleBarWidget->maximizeButton->setToolTip(isMaximized() ? tr("Restore") : tr("Maximize"));
|
||||
});
|
||||
|
||||
connect(appMainWindow->uninstallBtn, &QPushButton::clicked, [this]() {
|
||||
this->m_helper->uninstall();
|
||||
});
|
||||
connect(appMainWindow->installBtn, &QPushButton::clicked, [this]() {
|
||||
this->m_helper->install();
|
||||
});
|
||||
|
||||
setWindowTitle(tr("Hello, World!"));
|
||||
}
|
||||
|
||||
|
@ -85,12 +92,15 @@ void MainWindow::showEvent(QShowEvent *event)
|
|||
if (!inited) {
|
||||
const auto win = windowHandle();
|
||||
if (win) {
|
||||
FramelessWindowsManager::addWindow(win);
|
||||
FramelessWindowsManager::setHitTestVisibleInChrome(win, titleBarWidget->iconButton, true);
|
||||
FramelessWindowsManager::setHitTestVisibleInChrome(win, titleBarWidget->minimizeButton, true);
|
||||
FramelessWindowsManager::setHitTestVisibleInChrome(win, titleBarWidget->maximizeButton, true);
|
||||
FramelessWindowsManager::setHitTestVisibleInChrome(win, titleBarWidget->closeButton, true);
|
||||
FramelessWindowsManager::setHitTestVisibleInChrome(win, appMainWindow->menubar, true);
|
||||
m_helper = new FramelessHelper(win);
|
||||
m_helper->setHitTestVisible(titleBarWidget->iconButton);
|
||||
m_helper->setHitTestVisible(titleBarWidget->minimizeButton);
|
||||
m_helper->setHitTestVisible(titleBarWidget->maximizeButton);
|
||||
m_helper->setHitTestVisible(titleBarWidget->closeButton);
|
||||
m_helper->setHitTestVisible(appMainWindow->menubar);
|
||||
m_helper->setTitleBarHeight(m_titleBar->height());
|
||||
m_helper->setResizeBorderThickness(4);
|
||||
m_helper->install();
|
||||
setContentsMargins(1, 1, 1, 1);
|
||||
inited = true;
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include <QtWidgets/qmainwindow.h>
|
||||
#include "ui_MainWindow.h"
|
||||
#include "ui_TitleBar.h"
|
||||
#include "../../framelesshelper.h"
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
|
@ -45,6 +46,8 @@ Q_SIGNALS:
|
|||
void windowStateChanged();
|
||||
|
||||
private:
|
||||
__flh_ns::FramelessHelper *m_helper = nullptr;
|
||||
QWidget *m_titleBar = nullptr;
|
||||
Ui::TitleBar *titleBarWidget = nullptr;
|
||||
Ui::MainWindow *appMainWindow = nullptr;
|
||||
};
|
||||
|
|
|
@ -23,14 +23,14 @@ FLWindow::~FLWindow()
|
|||
|
||||
void FLWindow::initFramelessWindow()
|
||||
{
|
||||
m_flsHelper = new FramelessHelper(windowHandle());
|
||||
m_flsHelper->setResizeBorderThickness(4);
|
||||
m_flsHelper->setTitleBarHeight(m_titleBarWidget->height());
|
||||
m_flsHelper->setResizable(true);
|
||||
m_flsHelper->setHitTestVisible(m_minimizeButton);
|
||||
m_flsHelper->setHitTestVisible(m_maximizeButton);
|
||||
m_flsHelper->setHitTestVisible(m_closeButton);
|
||||
m_flsHelper->install();
|
||||
m_helper = new FramelessHelper(windowHandle());
|
||||
m_helper->setResizeBorderThickness(4);
|
||||
m_helper->setTitleBarHeight(m_titleBarWidget->height());
|
||||
m_helper->setResizable(true);
|
||||
m_helper->setHitTestVisible(m_minimizeButton);
|
||||
m_helper->setHitTestVisible(m_maximizeButton);
|
||||
m_helper->setHitTestVisible(m_closeButton);
|
||||
m_helper->install();
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
m_minimizeButton->hide();
|
||||
|
@ -54,10 +54,10 @@ void FLWindow::showEvent(QShowEvent *event)
|
|||
#ifdef Q_OS_WIN
|
||||
bool FLWindow::nativeEvent(const QByteArray &eventType, void *message, long *result)
|
||||
{
|
||||
if (!m_flsHelper)
|
||||
if (!m_helper)
|
||||
return QWidget::nativeEvent(eventType, message, result);
|
||||
|
||||
if (m_flsHelper->handleNativeEvent(this->windowHandle(), eventType, message, result))
|
||||
if (m_helper->handleNativeEvent(this->windowHandle(), eventType, message, result))
|
||||
return true;
|
||||
else
|
||||
return QWidget::nativeEvent(eventType, message, result);
|
||||
|
|
|
@ -23,7 +23,7 @@ private:
|
|||
void setupUi();
|
||||
|
||||
private:
|
||||
__flh_ns::FramelessHelper *m_flsHelper = nullptr;
|
||||
__flh_ns::FramelessHelper *m_helper = nullptr;
|
||||
QWidget *m_titleBarWidget = nullptr;
|
||||
QPushButton *m_minimizeButton = nullptr;
|
||||
QPushButton *m_maximizeButton = nullptr;
|
||||
|
|
|
@ -99,10 +99,15 @@ void Widget::showEvent(QShowEvent *event)
|
|||
qFatal("Failed to retrieve the window handle.");
|
||||
return;
|
||||
}
|
||||
FramelessWindowsManager::addWindow(win);
|
||||
FramelessWindowsManager::setHitTestVisibleInChrome(win, m_minimizeButton, true);
|
||||
FramelessWindowsManager::setHitTestVisibleInChrome(win, m_maximizeButton, true);
|
||||
FramelessWindowsManager::setHitTestVisibleInChrome(win, m_closeButton, true);
|
||||
|
||||
m_helper = new FramelessHelper(win);
|
||||
m_helper->setHitTestVisible(m_minimizeButton);
|
||||
m_helper->setHitTestVisible(m_maximizeButton);
|
||||
m_helper->setHitTestVisible(m_closeButton);
|
||||
m_helper->setResizeBorderThickness(4);
|
||||
m_helper->setTitleBarHeight(m_titleBarWidget->height());
|
||||
m_helper->install();
|
||||
|
||||
const int margin = Utilities::getWindowVisibleFrameBorderThickness(winId());
|
||||
setContentsMargins(margin, margin, margin, margin);
|
||||
}
|
||||
|
@ -124,7 +129,6 @@ void Widget::changeEvent(QEvent *event)
|
|||
const int margin = ((isMaximized() || isFullScreen()) ? 0 : Utilities::getWindowVisibleFrameBorderThickness(winId()));
|
||||
setContentsMargins(margin, margin, margin, margin);
|
||||
updateSystemButtonIcons();
|
||||
updateTitleBarSize();
|
||||
shouldUpdate = true;
|
||||
} else if (event->type() == QEvent::ActivationChange) {
|
||||
shouldUpdate = true;
|
||||
|
@ -156,7 +160,7 @@ void Widget::paintEvent(QPaintEvent *event)
|
|||
};
|
||||
const ColorizationArea area = Utilities::getColorizationArea();
|
||||
const bool colorizedBorder = ((area == ColorizationArea::TitleBar_WindowBorder)
|
||||
|| (area == ColorizationArea::All));
|
||||
|| (area == ColorizationArea::AllArea));
|
||||
const QColor borderColor = (isActiveWindow() ? (colorizedBorder ? Utilities::getColorizationColor() : Qt::black) : Qt::darkGray);
|
||||
const auto borderThickness = static_cast<qreal>(Utilities::getWindowVisibleFrameBorderThickness(winId()));
|
||||
painter.setPen({borderColor, qMax(borderThickness, devicePixelRatioF())});
|
||||
|
@ -170,9 +174,13 @@ void Widget::setupUi()
|
|||
setObjectName(QStringLiteral("MainWidget"));
|
||||
setWindowTitle(tr("Hello, World!"));
|
||||
resize(800, 600);
|
||||
|
||||
m_titleBarWidget = new QWidget(this);
|
||||
m_titleBarWidget->setObjectName(QStringLiteral("TitleBarWidget"));
|
||||
m_titleBarWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
m_titleBarWidget->setFixedHeight(28);
|
||||
const QSize systemButtonSize = {45, 30};
|
||||
|
||||
m_windowTitleLabel = new QLabel(m_titleBarWidget);
|
||||
m_windowTitleLabel->setObjectName(QStringLiteral("WindowTitleLabel"));
|
||||
m_windowTitleLabel->setFrameShape(QFrame::NoFrame);
|
||||
|
@ -181,11 +189,17 @@ void Widget::setupUi()
|
|||
m_windowTitleLabel->setFont(titleFont);
|
||||
m_windowTitleLabel->setText(windowTitle());
|
||||
connect(this, &Widget::windowTitleChanged, m_windowTitleLabel, &QLabel::setText);
|
||||
|
||||
m_minimizeButton = new QPushButton(m_titleBarWidget);
|
||||
m_minimizeButton->setObjectName(QStringLiteral("MinimizeButton"));
|
||||
m_minimizeButton->setFixedSize(systemButtonSize);
|
||||
m_minimizeButton->setIconSize(systemButtonSize);
|
||||
connect(m_minimizeButton, &QPushButton::clicked, this, &Widget::showMinimized);
|
||||
|
||||
m_maximizeButton = new QPushButton(m_titleBarWidget);
|
||||
m_maximizeButton->setObjectName(QStringLiteral("MaximizeButton"));
|
||||
m_maximizeButton->setFixedSize(systemButtonSize);
|
||||
m_maximizeButton->setIconSize(systemButtonSize);
|
||||
connect(m_maximizeButton, &QPushButton::clicked, this, [this](){
|
||||
if (isMaximized() || isFullScreen()) {
|
||||
showNormal();
|
||||
|
@ -194,11 +208,15 @@ void Widget::setupUi()
|
|||
}
|
||||
updateSystemButtonIcons();
|
||||
});
|
||||
|
||||
m_closeButton = new QPushButton(m_titleBarWidget);
|
||||
m_closeButton->setObjectName(QStringLiteral("CloseButton"));
|
||||
m_closeButton->setFixedSize(systemButtonSize);
|
||||
m_closeButton->setIconSize(systemButtonSize);
|
||||
connect(m_closeButton, &QPushButton::clicked, this, &Widget::close);
|
||||
|
||||
updateSystemButtonIcons();
|
||||
updateTitleBarSize();
|
||||
|
||||
const auto titleBarLayout = new QHBoxLayout(m_titleBarWidget);
|
||||
titleBarLayout->setContentsMargins(0, 0, 0, 0);
|
||||
titleBarLayout->setSpacing(0);
|
||||
|
@ -209,6 +227,7 @@ void Widget::setupUi()
|
|||
titleBarLayout->addWidget(m_maximizeButton);
|
||||
titleBarLayout->addWidget(m_closeButton);
|
||||
m_titleBarWidget->setLayout(titleBarLayout);
|
||||
|
||||
m_clockLabel = new QLabel(this);
|
||||
m_clockLabel->setObjectName(QStringLiteral("ClockLabel"));
|
||||
m_clockLabel->setFrameShape(QFrame::NoFrame);
|
||||
|
@ -216,12 +235,14 @@ void Widget::setupUi()
|
|||
clockFont.setBold(true);
|
||||
clockFont.setPointSize(70);
|
||||
m_clockLabel->setFont(clockFont);
|
||||
|
||||
const auto contentLayout = new QHBoxLayout;
|
||||
contentLayout->setContentsMargins(0, 0, 0, 0);
|
||||
contentLayout->setSpacing(0);
|
||||
contentLayout->addStretch();
|
||||
contentLayout->addWidget(m_clockLabel);
|
||||
contentLayout->addStretch();
|
||||
|
||||
const auto mainLayout = new QVBoxLayout(this);
|
||||
mainLayout->setContentsMargins(0, 0, 0, 0);
|
||||
mainLayout->setSpacing(0);
|
||||
|
@ -239,7 +260,7 @@ void Widget::updateStyleSheet()
|
|||
const bool dark = Utilities::shouldAppsUseDarkMode();
|
||||
const ColorizationArea area = Utilities::getColorizationArea();
|
||||
const bool colorizedTitleBar = ((area == ColorizationArea::TitleBar_WindowBorder)
|
||||
|| (area == ColorizationArea::All));
|
||||
|| (area == ColorizationArea::AllArea));
|
||||
const QColor colorizationColor = Utilities::getColorizationColor();
|
||||
const QColor mainWidgetBackgroundColor = (dark ? systemDarkColor : systemLightColor);
|
||||
const QColor titleBarWidgetBackgroundColor = [active, colorizedTitleBar, &colorizationColor, dark]{
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <QtWidgets/qwidget.h>
|
||||
#include "../../framelesshelper.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
QT_FORWARD_DECLARE_CLASS(QLabel)
|
||||
|
@ -57,6 +58,7 @@ private:
|
|||
void updateSystemButtonIcons();
|
||||
|
||||
private:
|
||||
__flh_ns::FramelessHelper *m_helper = nullptr;
|
||||
QWidget *m_titleBarWidget = nullptr;
|
||||
QLabel *m_windowTitleLabel = nullptr;
|
||||
QPushButton *m_minimizeButton = nullptr;
|
||||
|
|
|
@ -113,10 +113,10 @@ Q_ENUM_NS(SystemMetric)
|
|||
|
||||
enum class ColorizationArea : int
|
||||
{
|
||||
None = 0,
|
||||
NoArea = 0, // ‘None’ has been defined as a macro in X11 headers.
|
||||
StartMenu_TaskBar_ActionCenter,
|
||||
TitleBar_WindowBorder,
|
||||
All
|
||||
AllArea
|
||||
};
|
||||
Q_ENUM_NS(ColorizationArea)
|
||||
|
||||
|
|
|
@ -109,8 +109,7 @@ bool Utilities::shouldAppsUseDarkMode()
|
|||
ColorizationArea Utilities::getColorizationArea()
|
||||
{
|
||||
// ### TO BE IMPLEMENTED
|
||||
//return ColorizationArea::None; // ‘None’ has been defined as a macro in X11 headers.
|
||||
return ColorizationArea::All;
|
||||
return ColorizationArea::NoArea;
|
||||
}
|
||||
|
||||
bool Utilities::isThemeChanged(const void *data)
|
||||
|
|
|
@ -358,7 +358,7 @@ bool Utilities::shouldAppsUseDarkMode()
|
|||
ColorizationArea Utilities::getColorizationArea()
|
||||
{
|
||||
if (!isWin10OrGreater()) {
|
||||
return ColorizationArea::None;
|
||||
return ColorizationArea::NoArea;
|
||||
}
|
||||
const QString keyName = QStringLiteral("ColorPrevalence");
|
||||
const QSettings themeRegistry(QString::fromUtf8(kPersonalizeRegistryKey), QSettings::NativeFormat);
|
||||
|
@ -368,13 +368,13 @@ ColorizationArea Utilities::getColorizationArea()
|
|||
const bool theme = (themeValue != 0);
|
||||
const bool dwm = (dwmValue != 0);
|
||||
if (theme && dwm) {
|
||||
return ColorizationArea::All;
|
||||
return ColorizationArea::AllArea;
|
||||
} else if (theme) {
|
||||
return ColorizationArea::StartMenu_TaskBar_ActionCenter;
|
||||
} else if (dwm) {
|
||||
return ColorizationArea::TitleBar_WindowBorder;
|
||||
}
|
||||
return ColorizationArea::None;
|
||||
return ColorizationArea::NoArea;
|
||||
}
|
||||
|
||||
bool Utilities::isThemeChanged(const void *data)
|
||||
|
|
Loading…
Reference in New Issue