From d08030ea8f04f056aed88a4ad96dc9233d069787 Mon Sep 17 00:00:00 2001 From: Sine Striker <trueful@163.com> Date: 周一, 01 1月 2024 19:18:10 +0800 Subject: [PATCH] Add license --- src/widgets/widgetitemdelegate.cpp | 94 ++++++++++++++++++++++++++++++++++++----------- 1 files changed, 72 insertions(+), 22 deletions(-) diff --git a/src/widgets/widgetitemdelegate.cpp b/src/widgets/widgetitemdelegate.cpp index 9d338c1..ddbd953 100644 --- a/src/widgets/widgetitemdelegate.cpp +++ b/src/widgets/widgetitemdelegate.cpp @@ -1,10 +1,13 @@ +// Copyright (C) 2023-2024 Stdware Collections +// SPDX-License-Identifier: Apache-2.0 + #include "widgetitemdelegate_p.h" #include <QtGui/QMouseEvent> #include <QtWidgets/QWidget> #include <QtWidgets/QApplication> -extern Q_WIDGETS_EXPORT QWidget *qt_button_down; +extern Q_DECL_IMPORT QWidget *qt_button_down; namespace QWK { @@ -12,16 +15,16 @@ WidgetItemDelegate::~WidgetItemDelegate() = default; - QWindow *WidgetItemDelegate::window(QObject *obj) const { - return static_cast<QWidget *>(obj)->windowHandle(); + QWindow *WidgetItemDelegate::window(const QObject *obj) const { + return static_cast<const QWidget *>(obj)->windowHandle(); } - bool WidgetItemDelegate::isEnabled(QObject *obj) const { - return static_cast<QWidget *>(obj)->isEnabled(); + bool WidgetItemDelegate::isEnabled(const QObject *obj) const { + return static_cast<const QWidget *>(obj)->isEnabled(); } - bool WidgetItemDelegate::isVisible(QObject *obj) const { - return static_cast<QWidget *>(obj)->isVisible(); + bool WidgetItemDelegate::isVisible(const QObject *obj) const { + return static_cast<const QWidget *>(obj)->isVisible(); } QRect WidgetItemDelegate::mapGeometryToScene(const QObject *obj) const { @@ -31,26 +34,73 @@ return {originPoint, size}; } - QWindow *WidgetItemDelegate::hostWindow(QObject *host) const { - return static_cast<QWidget *>(host)->windowHandle(); + QWindow *WidgetItemDelegate::hostWindow(const QObject *host) const { + return static_cast<const QWidget *>(host)->windowHandle(); } - bool WidgetItemDelegate::isHostSizeFixed(QObject *host) const { - return false; - } - - bool WidgetItemDelegate::resetQtGrabbedControl() const { - if (qt_button_down) { - static constexpr const auto invalidPos = QPoint{-99999, -99999}; - const auto event = - new QMouseEvent(QEvent::MouseButtonRelease, invalidPos, invalidPos, invalidPos, - Qt::LeftButton, QGuiApplication::mouseButtons() ^ Qt::LeftButton, - QGuiApplication::keyboardModifiers()); - QApplication::postEvent(qt_button_down, event); - qt_button_down = nullptr; + bool WidgetItemDelegate::isHostSizeFixed(const QObject *host) const { + const auto widget = static_cast<const QWidget *>(host); + // "Qt::MSWindowsFixedSizeDialogHint" is used cross-platform actually. + if (widget->windowFlags() & Qt::MSWindowsFixedSizeDialogHint) { + return true; + } + // Caused by setFixedWidth/Height/Size(). + const QSize minSize = widget->minimumSize(); + const QSize maxSize = widget->maximumSize(); + if (!minSize.isEmpty() && !maxSize.isEmpty() && (minSize == maxSize)) { return true; } return false; } + bool WidgetItemDelegate::isWindowActive(const QObject *host) const { + return static_cast<const QWidget *>(host)->isActiveWindow(); + } + + void WidgetItemDelegate::resetQtGrabbedControl(QObject *host) const { + Q_UNUSED(host); + if (!qt_button_down) { + return; + } + static constexpr const auto invalidPos = + QPoint{std::numeric_limits<int>::lowest(), std::numeric_limits<int>::lowest()}; + const auto event = new QMouseEvent( + QEvent::MouseButtonRelease, invalidPos, invalidPos, invalidPos, Qt::LeftButton, + QGuiApplication::mouseButtons() ^ Qt::LeftButton, QGuiApplication::keyboardModifiers()); + QCoreApplication::postEvent(qt_button_down, event); + qt_button_down = nullptr; + } + + Qt::WindowStates WidgetItemDelegate::getWindowState(const QObject *host) const { + return static_cast<const QWidget *>(host)->windowState(); + } + + void WidgetItemDelegate::setWindowState(QObject *host, Qt::WindowStates state) const { + static_cast<QWidget *>(host)->setWindowState(state); + } + + void WidgetItemDelegate::setCursorShape(QObject *host, Qt::CursorShape shape) const { + static_cast<QWidget *>(host)->setCursor(QCursor(shape)); + } + + void WidgetItemDelegate::restoreCursorShape(QObject *host) const { + static_cast<QWidget *>(host)->unsetCursor(); + } + + Qt::WindowFlags WidgetItemDelegate::getWindowFlags(const QObject *host) const { + return static_cast<const QWidget *>(host)->windowFlags(); + } + + void WidgetItemDelegate::setWindowFlags(QObject *host, Qt::WindowFlags flags) const { + static_cast<QWidget *>(host)->setWindowFlags(flags); + } + + void WidgetItemDelegate::setWindowVisible(QObject *host, bool visible) const { + static_cast<QWidget *>(host)->setVisible(visible); + } + + void WidgetItemDelegate::bringWindowToTop(QObject *host) const { + static_cast<QWidget *>(host)->raise(); + } + } \ No newline at end of file -- Gitblit v1.9.1