CustomFrame: Add a NativeFeatures enum

Replaces the htCaptionRect. As we don't want to pass many arguments,
instead just pass a struct which describes which native features
to enable
This commit is contained in:
Sergio Martins
2021-02-18 15:14:52 +00:00
parent b5043b2b87
commit 029ba1202e
2 changed files with 29 additions and 8 deletions

View File

@@ -318,7 +318,7 @@ bool WidgetResizeHandler::handleWindowsNativeEvent(FloatingWindow *fw, const QBy
bool WidgetResizeHandler::handleWindowsNativeEvent(QWindow *w, MSG *msg,
Qt5Qt6Compat::qintptr *result,
QRect htCaptionRect)
const NativeFeatures &features)
{
if (msg->message == WM_NCCALCSIZE) {
*result = 0;
@@ -354,9 +354,10 @@ bool WidgetResizeHandler::handleWindowsNativeEvent(QWindow *w, MSG *msg,
*result = HTBOTTOM;
} else if (!hasFixedWidth && xPos <= rect.right && xPos >= rect.right - borderWidth) {
*result = HTRIGHT;
} else if (!htCaptionRect.isNull()) {
} else if (!features.htCaptionRect.isNull()) {
const QPoint globalPosQt = QHighDpi::fromNativePixels(QPoint(xPos, yPos), w);
// htCaptionRect is the rect on which we allow for Windows to do a native drag
const QRect htCaptionRect = features.htCaptionRect;
if (globalPosQt.y() >= htCaptionRect.top() && globalPosQt.y() <= htCaptionRect.bottom() && globalPosQt.x() >= htCaptionRect.left() && globalPosQt.x() <= htCaptionRect.right()) {
if (!KDDockWidgets::inDisallowDragWidget(globalPosQt)) { // Just makes sure the mouse isn't over the close button, we don't allow drag in that case.
*result = HTCAPTION;
@@ -605,8 +606,8 @@ bool CustomFrameHelper::nativeEventFilter(const QByteArray &eventType, void *mes
if (!window)
return false;
const WidgetResizeHandler::Features features = m_shouldUseCustomFrameFunc(window);
if (!features) {
const WidgetResizeHandler::NativeFeatures features = m_shouldUseCustomFrameFunc(window);
if (!features.hasFeatures()) {
// No native support for is desired for this window
return false;
}
@@ -619,7 +620,7 @@ bool CustomFrameHelper::nativeEventFilter(const QByteArray &eventType, void *mes
window->setProperty(propertyName, true);
}
return WidgetResizeHandler::handleWindowsNativeEvent(window, msg, result);
return WidgetResizeHandler::handleWindowsNativeEvent(window, msg, result, features);
#else
Q_UNUSED(eventType);
Q_UNUSED(message);

View File

@@ -42,10 +42,30 @@ public:
Feature_NativeShadow = 1,
Feature_NativeResize = 2,
Feature_NativeDrag = 4,
Feature_NativeMaximize = 8
Feature_NativeMaximize = 8,
Feature_All = Feature_NativeShadow | Feature_NativeResize | Feature_NativeDrag
| Feature_NativeMaximize
};
Q_DECLARE_FLAGS(Features, Feature);
struct NativeFeatures {
NativeFeatures() = default;
NativeFeatures(QRect r)
: htCaptionRect(r) {
}
NativeFeatures(Features f)
: features(f) {
}
QRect htCaptionRect; // in global coordinates
Features features = Feature_All;
bool hasFeatures() const {
return features != Feature_None;
}
};
/**
* @brief CTOR
* @param isTopLevelResizer If true, then this resize handler is for top-level widgets (aka windows)
@@ -83,7 +103,7 @@ public:
static void setupWindow(QWindow *window);
#ifdef Q_OS_WIN
static bool handleWindowsNativeEvent(QWindow *w, MSG *msg, Qt5Qt6Compat::qintptr *result, QRect htCaptionRect = {});
static bool handleWindowsNativeEvent(QWindow *w, MSG *msg, Qt5Qt6Compat::qintptr *result, const NativeFeatures & = {});
static bool handleWindowsNativeEvent(FloatingWindow *w, const QByteArray &eventType,
void *message, Qt5Qt6Compat::qintptr *result);
#endif
@@ -140,7 +160,7 @@ class DOCKS_EXPORT CustomFrameHelper
{
Q_OBJECT
public:
typedef WidgetResizeHandler::Features (*ShouldUseCustomFrame)(QWindow *);
typedef WidgetResizeHandler::NativeFeatures (*ShouldUseCustomFrame)(QWindow *);
explicit CustomFrameHelper(ShouldUseCustomFrame shouldUseCustomFrameFunc,
QObject *parent = nullptr);
~CustomFrameHelper() override;