diff --git a/Changelog b/Changelog index 492d53e1..a3bd63a2 100644 --- a/Changelog +++ b/Changelog @@ -7,6 +7,7 @@ - Non-gui logic moved to controllers - Each controller has a gui counter part, implemented for each supported frontend - Uses nlohmann JSON library (MIT) instead of QJsonDocument, for saving/restoring layouts + - Added Config::setStartDragDistance() * v1.6.0 (unreleased) - Fixed restoring of normal geometry when closing a maximized window (#259) diff --git a/src/Config.cpp b/src/Config.cpp index a2a75c2c..b43d8a5d 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -56,6 +56,7 @@ public: CustomizableWidgets m_disabledPaintEvents = CustomizableWidget_None; qreal m_draggedWindowOpacity = Q_QNAN; int m_mdiPopupThreshold = 250; + int m_startDragDistance = -1; bool m_dropIndicatorsInhibited = false; }; @@ -309,4 +310,14 @@ bool Config::dropIndicatorsInhibited() const return d->m_dropIndicatorsInhibited; } +void Config::setStartDragDistance(int pixels) +{ + d->m_startDragDistance = pixels; +} + +int Config::startDragDistance() const +{ + return d->m_startDragDistance; +} + } diff --git a/src/Config.h b/src/Config.h index 7664b158..67e70157 100644 --- a/src/Config.h +++ b/src/Config.h @@ -86,7 +86,8 @@ public: ///@warning Only the default is supported on all platforms. Not all options work with all window managers, /// Qt does its best to abstract the differences however that's only a best effort. This is true specially /// for any option that changes window flags. - enum Flag { + enum Flag + { Flag_None = 0, ///< No option set Flag_NativeTitleBar = 1, ///< Enables the Native OS title bar on OSes that support it (Windows 10, macOS), ignored otherwise. Flag_AeroSnapWithClientDecos = 2, ///< Deprecated. This is now default and cannot be turned off. Moving a window on Windows 10 uses native moving, as that works well across screens with different HDPI settings. There's no reason to use manual client/Qt window moving. @@ -113,7 +114,8 @@ public: Q_DECLARE_FLAGS(Flags, Flag) ///@brief List of customizable widgets - enum CustomizableWidget { + enum CustomizableWidget + { CustomizableWidget_None = 0, ///< None CustomizableWidget_TitleBar, ///< The title bar CustomizableWidget_DockWidget, ///< The dock widget @@ -128,7 +130,8 @@ public: ///@internal /// Internal flags for additional tuning. ///@warning Not for public consumption, support will be limited. - enum InternalFlag { + enum InternalFlag + { InternalFlag_None = 0, ///< The default InternalFlag_NoAeroSnap = 1, ///< Only for development. Disables Aero-snap. InternalFlag_DontUseParentForFloatingWindows = 2, ///< FloatingWindows won't have a parent top-level. @@ -319,6 +322,16 @@ public: void setMDIPopupThreshold(int); int mdiPopupThreshold() const; + /// @brief Sets how many pixels the mouse needs to travel before a drag is actually started + /// Calling this is usually unneeded and just provided as a means to override Platform::startDragDistance() + /// , which already has a reasonable default 4 pixels + void setStartDragDistance(int); + + /// @brief Returns the value set by setStartDragDistance() + /// Returns -1 if setStartDragDistance() wasn't call, in which case the Platform::startDragDistance() + /// will be used + int startDragDistance() const; + private: Q_DISABLE_COPY(Config) Config(); diff --git a/src/Platform.cpp b/src/Platform.cpp index d92ee298..5b440dba 100644 --- a/src/Platform.cpp +++ b/src/Platform.cpp @@ -74,6 +74,16 @@ bool Platform::isQtQuick() const int Platform::startDragDistance() const { + const int userRequestedDistance = Config::self().startDragDistance(); + if (userRequestedDistance > -1) + return userRequestedDistance; + + return startDragDistance_impl(); +} + +int Platform::startDragDistance_impl() const +{ + // Override this method in derived classes for some different value if needed return 4; } diff --git a/src/Platform.h b/src/Platform.h index 64e07fcf..05654794 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -99,7 +99,10 @@ public: bool isQtQuick() const; /// @brief Returns how many pixels the mouse must move for a drag to start - virtual int startDragDistance() const; + /// This is usually 4 by default (QApplication::startDragDistance() for QtWidgets) + /// You can override by calling Config::setStartDragDistance(), so you don't need to create + /// a new Platform class. + int startDragDistance() const; /// @brief Return whether we use the global event filter based mouse grabber virtual bool usesFallbackMouseGrabber() const = 0; @@ -255,6 +258,7 @@ public: Private *const d; protected: + virtual int startDragDistance_impl() const; Platform(); }; diff --git a/src/qtwidgets/Platform_qtwidgets.cpp b/src/qtwidgets/Platform_qtwidgets.cpp index 2a16c566..40849773 100644 --- a/src/qtwidgets/Platform_qtwidgets.cpp +++ b/src/qtwidgets/Platform_qtwidgets.cpp @@ -162,7 +162,7 @@ QSize Platform_qtwidgets::screenSizeFor(View *view) const return {}; } -int Platform_qtwidgets::startDragDistance() const +int Platform_qtwidgets::startDragDistance_impl() const { return QApplication::startDragDistance(); } diff --git a/src/qtwidgets/Platform_qtwidgets.h b/src/qtwidgets/Platform_qtwidgets.h index fbaa8d36..ec0b1139 100644 --- a/src/qtwidgets/Platform_qtwidgets.h +++ b/src/qtwidgets/Platform_qtwidgets.h @@ -37,7 +37,7 @@ public: int screenNumberFor(View *) const override; QSize screenSizeFor(View *) const override; - int startDragDistance() const override; + int startDragDistance_impl() const override; View *createView(View *parent = nullptr) const override; bool inDisallowedDragView(QPoint globalPos) const override; bool usesFallbackMouseGrabber() const override; diff --git a/tests/tst_platform.cpp b/tests/tst_platform.cpp index 746e1d66..b615d832 100644 --- a/tests/tst_platform.cpp +++ b/tests/tst_platform.cpp @@ -12,6 +12,7 @@ #include "main.h" #include "private/View_p.h" #include "Platform.h" +#include "Config.h" #include @@ -32,4 +33,15 @@ TEST_CASE("Platform::createDefaultViewFactory") { auto plat = Platform::instance(); REQUIRE(plat->createDefaultViewFactory()); -} \ No newline at end of file +} + +TEST_CASE("Platform::startDragDistance") +{ + auto plat = Platform::instance(); + const int defaultDistance = plat->startDragDistance(); + CHECK_GE(defaultDistance, -1); + + const int newDistance = defaultDistance + 1; + Config::self().setStartDragDistance(newDistance); + CHECK_EQ(plat->startDragDistance(), newDistance); +}