forked from github_mirror/framelesshelper
demo: add shortcut to switch between fullscreen state
Can also help use better debugging the old style window frame issue on Windows. Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
parent
1bce57445b
commit
6c060b3946
|
@ -28,6 +28,17 @@ import org.wangwenx190.FramelessHelper
|
||||||
import Demo
|
import Demo
|
||||||
|
|
||||||
FramelessWindow {
|
FramelessWindow {
|
||||||
|
property int __savedWindowState: Window.Windowed
|
||||||
|
|
||||||
|
function toggleFullScreen() {
|
||||||
|
if (window.visibility === Window.FullScreen) {
|
||||||
|
window.visibility = window.__savedWindowState;
|
||||||
|
} else {
|
||||||
|
window.__savedWindowState = window.visibility;
|
||||||
|
window.showFullScreen();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
id: window
|
id: window
|
||||||
visible: false // Hide the window before we sets up it's correct size and position.
|
visible: false // Hide the window before we sets up it's correct size and position.
|
||||||
width: 800
|
width: 800
|
||||||
|
@ -60,6 +71,22 @@ FramelessWindow {
|
||||||
window.visible = true;
|
window.visible = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Shortcut {
|
||||||
|
sequences: [ StandardKey.Cancel, StandardKey.Close, StandardKey.Quit ]
|
||||||
|
onActivated: {
|
||||||
|
if (window.visibility === Window.FullScreen) {
|
||||||
|
window.toggleFullScreen();
|
||||||
|
} else {
|
||||||
|
window.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Shortcut {
|
||||||
|
sequences: [ StandardKey.FullScreen, "ALT+RETURN" ]
|
||||||
|
onActivated: window.toggleFullScreen()
|
||||||
|
}
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
interval: 500
|
interval: 500
|
||||||
running: true
|
running: true
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include <QtCore/qcoreapplication.h>
|
#include <QtCore/qcoreapplication.h>
|
||||||
#include <QtCore/qfileinfo.h>
|
#include <QtCore/qfileinfo.h>
|
||||||
#include <QtCore/qdir.h>
|
#include <QtCore/qdir.h>
|
||||||
|
#include <QtGui/qshortcut.h>
|
||||||
#include <QtWidgets/qlabel.h>
|
#include <QtWidgets/qlabel.h>
|
||||||
#include <QtWidgets/qboxlayout.h>
|
#include <QtWidgets/qboxlayout.h>
|
||||||
#include <FramelessManager>
|
#include <FramelessManager>
|
||||||
|
@ -100,6 +101,26 @@ void Widget::initialize()
|
||||||
setLayout(mainLayout);
|
setLayout(mainLayout);
|
||||||
updateStyleSheet();
|
updateStyleSheet();
|
||||||
|
|
||||||
|
m_cancelShortcut.reset(new QShortcut(this));
|
||||||
|
m_cancelShortcut->setKey(FRAMELESSHELPER_STRING_LITERAL("ESC"));
|
||||||
|
connect(m_cancelShortcut.data(), &QShortcut::activated, this, [this](){
|
||||||
|
if (isFullScreen()) {
|
||||||
|
Q_EMIT m_fullScreenShortcut->activated();
|
||||||
|
} else {
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
m_fullScreenShortcut.reset(new QShortcut(this));
|
||||||
|
m_fullScreenShortcut->setKey(FRAMELESSHELPER_STRING_LITERAL("ALT+RETURN"));
|
||||||
|
connect(m_fullScreenShortcut.data(), &QShortcut::activated, this, [this](){
|
||||||
|
if (isFullScreen()) {
|
||||||
|
setWindowState(windowState() & ~Qt::WindowFullScreen);
|
||||||
|
} else {
|
||||||
|
showFullScreen();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
FramelessWidgetsHelper *helper = FramelessWidgetsHelper::get(this);
|
FramelessWidgetsHelper *helper = FramelessWidgetsHelper::get(this);
|
||||||
helper->setTitleBarWidget(m_titleBar.data());
|
helper->setTitleBarWidget(m_titleBar.data());
|
||||||
helper->setSystemButton(m_titleBar->minimizeButton(), SystemButtonType::Minimize);
|
helper->setSystemButton(m_titleBar->minimizeButton(), SystemButtonType::Minimize);
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QLabel;
|
class QLabel;
|
||||||
|
class QShortcut;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
FRAMELESSHELPER_BEGIN_NAMESPACE
|
FRAMELESSHELPER_BEGIN_NAMESPACE
|
||||||
|
@ -56,4 +57,6 @@ private Q_SLOTS:
|
||||||
private:
|
private:
|
||||||
QScopedPointer<QLabel> m_clockLabel;
|
QScopedPointer<QLabel> m_clockLabel;
|
||||||
QScopedPointer<FRAMELESSHELPER_PREPEND_NAMESPACE(StandardTitleBar)> m_titleBar;
|
QScopedPointer<FRAMELESSHELPER_PREPEND_NAMESPACE(StandardTitleBar)> m_titleBar;
|
||||||
|
QScopedPointer<QShortcut> m_fullScreenShortcut;
|
||||||
|
QScopedPointer<QShortcut> m_cancelShortcut;
|
||||||
};
|
};
|
||||||
|
|
|
@ -71,6 +71,9 @@ public:
|
||||||
Q_NODISCARD bool isBlurBehindWindowEnabled() const;
|
Q_NODISCARD bool isBlurBehindWindowEnabled() const;
|
||||||
void setBlurBehindWindowEnabled(const bool value, const QColor &color);
|
void setBlurBehindWindowEnabled(const bool value, const QColor &color);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Q_NODISCARD bool eventFilter(QObject *object, QEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_NODISCARD QRect mapItemGeometryToScene(const QQuickItem * const item) const;
|
Q_NODISCARD QRect mapItemGeometryToScene(const QQuickItem * const item) const;
|
||||||
Q_NODISCARD bool isInSystemButtons(const QPoint &pos, QuickGlobal::SystemButtonType *button) const;
|
Q_NODISCARD bool isInSystemButtons(const QPoint &pos, QuickGlobal::SystemButtonType *button) const;
|
||||||
|
|
|
@ -163,6 +163,8 @@ void FramelessQuickHelperPrivate::attachToWindow()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window->installEventFilter(this);
|
||||||
|
|
||||||
SystemParameters params = {};
|
SystemParameters params = {};
|
||||||
params.getWindowId = [window]() -> WId { return window->winId(); };
|
params.getWindowId = [window]() -> WId { return window->winId(); };
|
||||||
params.getWindowFlags = [window]() -> Qt::WindowFlags { return window->flags(); };
|
params.getWindowFlags = [window]() -> Qt::WindowFlags { return window->flags(); };
|
||||||
|
@ -335,7 +337,11 @@ void FramelessQuickHelperPrivate::bringWindowToFront()
|
||||||
window->show();
|
window->show();
|
||||||
}
|
}
|
||||||
if (window->visibility() == QQuickWindow::Minimized) {
|
if (window->visibility() == QQuickWindow::Minimized) {
|
||||||
window->showNormal(); // ### FIXME: we should not show normal, we should restore the previous state.
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
||||||
|
window->setWindowStates(window->windowStates() & ~Qt::WindowMinimized);
|
||||||
|
#else
|
||||||
|
window->showNormal();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
window->raise();
|
window->raise();
|
||||||
window->requestActivate();
|
window->requestActivate();
|
||||||
|
@ -448,6 +454,29 @@ void FramelessQuickHelperPrivate::setBlurBehindWindowEnabled(const bool value, c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FramelessQuickHelperPrivate::eventFilter(QObject *object, QEvent *event)
|
||||||
|
{
|
||||||
|
Q_ASSERT(object);
|
||||||
|
Q_ASSERT(event);
|
||||||
|
if (!object || !event) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#ifdef Q_OS_WINDOWS
|
||||||
|
if (!object->isWindowType()) {
|
||||||
|
return QObject::eventFilter(object, event);
|
||||||
|
}
|
||||||
|
if (event->type() != QEvent::WindowStateChange) {
|
||||||
|
return QObject::eventFilter(object, event);
|
||||||
|
}
|
||||||
|
const auto changeEvent = static_cast<QWindowStateChangeEvent *>(event);
|
||||||
|
if (Utils::windowStatesToWindowState(changeEvent->oldState()) == Qt::WindowFullScreen) {
|
||||||
|
const auto window = qobject_cast<QQuickWindow *>(object);
|
||||||
|
Utils::fixupQtInternals(window->winId());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return QObject::eventFilter(object, event);
|
||||||
|
}
|
||||||
|
|
||||||
QRect FramelessQuickHelperPrivate::mapItemGeometryToScene(const QQuickItem * const item) const
|
QRect FramelessQuickHelperPrivate::mapItemGeometryToScene(const QQuickItem * const item) const
|
||||||
{
|
{
|
||||||
Q_ASSERT(item);
|
Q_ASSERT(item);
|
||||||
|
|
|
@ -148,6 +148,12 @@ void WidgetsSharedHelper::changeEventHandler(QEvent *event)
|
||||||
QMetaObject::invokeMethod(m_targetWidget, "hiddenChanged");
|
QMetaObject::invokeMethod(m_targetWidget, "hiddenChanged");
|
||||||
QMetaObject::invokeMethod(m_targetWidget, "normalChanged");
|
QMetaObject::invokeMethod(m_targetWidget, "normalChanged");
|
||||||
QMetaObject::invokeMethod(m_targetWidget, "zoomedChanged");
|
QMetaObject::invokeMethod(m_targetWidget, "zoomedChanged");
|
||||||
|
#ifdef Q_OS_WINDOWS
|
||||||
|
const auto changeEvent = static_cast<QWindowStateChangeEvent *>(event);
|
||||||
|
if (Utils::windowStatesToWindowState(changeEvent->oldState()) == Qt::WindowFullScreen) {
|
||||||
|
Utils::fixupQtInternals(m_targetWidget->winId());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void WidgetsSharedHelper::paintEventHandler(QPaintEvent *event)
|
void WidgetsSharedHelper::paintEventHandler(QPaintEvent *event)
|
||||||
|
|
Loading…
Reference in New Issue