Added Config::startDragDistance()
Allows the user to change the drag threshold without having to inherit from Platform
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
19
src/Config.h
19
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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
};
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "main.h"
|
||||
#include "private/View_p.h"
|
||||
#include "Platform.h"
|
||||
#include "Config.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -32,4 +33,15 @@ TEST_CASE("Platform::createDefaultViewFactory")
|
||||
{
|
||||
auto plat = Platform::instance();
|
||||
REQUIRE(plat->createDefaultViewFactory());
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user