| | |
| | | // Copyright (C) 2023-2024 Stdware Collections (https://www.github.com/stdware) |
| | | // Copyright (C) 2021-2023 wangwenx190 (Yuhang Zhao) |
| | | // 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 { |
| | | |
| | |
| | | if (!minSize.isEmpty() && !maxSize.isEmpty() && (minSize == maxSize)) { |
| | | return true; |
| | | } |
| | | // Usually set by the user. |
| | | const QSizePolicy sizePolicy = widget->sizePolicy(); |
| | | if ((sizePolicy.horizontalPolicy() == QSizePolicy::Fixed) |
| | | && (sizePolicy.verticalPolicy() == QSizePolicy::Fixed)) { |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | |
| | | return static_cast<const QWidget *>(host)->isActiveWindow(); |
| | | } |
| | | |
| | | void WidgetItemDelegate::resetQtGrabbedControl() const { |
| | | 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()); |
| | | QApplication::postEvent(qt_button_down, event); |
| | | 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(); |
| | | } |
| | | |
| | | QRect WidgetItemDelegate::getGeometry(const QObject *host) const { |
| | | return static_cast<const QWidget *>(host)->geometry(); |
| | | } |
| | | |
| | | 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::setGeometry(QObject *host, const QRect &rect) { |
| | | static_cast<QWidget *>(host)->setGeometry(rect); |
| | | } |
| | | |
| | | void WidgetItemDelegate::bringWindowToTop(QObject *host) const { |
| | | static_cast<QWidget *>(host)->raise(); |
| | | } |
| | | |
| | | } |