KDDockWidgets API Documentation 2.1
Loading...
Searching...
No Matches
Draggable.cpp
Go to the documentation of this file.
1/*
2 This file is part of KDDockWidgets.
3
4 SPDX-FileCopyrightText: 2019 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
5 Author: SĂ©rgio Martins <sergio.martins@kdab.com>
6
7 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
8
9 Contact KDAB at <info@kdab.com> for commercial licensing options.
10*/
11
12#include "Draggable_p.h"
13#include "DragController_p.h"
14#include "WidgetResizeHandler_p.h"
15#include "Utils_p.h"
16
17#include "kddockwidgets/core/Platform.h"
18#include "kddockwidgets/core/FloatingWindow.h"
19
20using namespace KDDockWidgets;
21using namespace KDDockWidgets::Core;
22
23class Draggable::Private
24{
25public:
26 explicit Private(View *_thisView, bool _enabled)
27 : thisView(_thisView)
28 , enabled(_enabled)
29 {
30 assert(thisView);
31 }
32
33 ObjectGuard<WidgetResizeHandler> widgetResizeHandler;
34 View *const thisView;
35 const bool enabled;
36};
37
38Draggable::Draggable(View *thisView, bool enabled)
39 : d(new Private(thisView, enabled))
40{
41 if (thisView && d->enabled)
42 DragController::instance()->registerDraggable(this);
43}
44
45Draggable::~Draggable()
46{
47 if (d->thisView && d->enabled)
48 DragController::instance()->unregisterDraggable(this);
49
50 delete d->widgetResizeHandler;
51 delete d;
52}
53
54View *Draggable::asView() const
55{
56 return d->thisView;
57}
58
59Controller *Draggable::asController() const
60{
61 if (auto v = d->thisView)
62 return v->controller();
63
64 return nullptr;
65}
66
67bool Draggable::dragCanStart(Point pressPos, Point globalPos) const
68{
69 return (globalPos - pressPos).manhattanLength() > Core::Platform::instance()->startDragDistance();
70}
71
72void Draggable::setWidgetResizeHandler(WidgetResizeHandler *w)
73{
74 assert(!d->widgetResizeHandler);
75 assert(w);
76 d->widgetResizeHandler = w;
77}
78
79bool Draggable::isInProgrammaticDrag() const
80{
81 return DragController::instance()->isInProgrammaticDrag();
82}
static Platform * instance()
Returns the platform singleton.
int startDragDistance() const
Returns how many pixels the mouse must move for a drag to start This is usually 4 by default (QApplic...
Class to abstract QAction, so code still works with QtQuick and Flutter.

© Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
KDDockWidgets
Advanced Dock Widget Framework for Qt
https://www.kdab.com/development-resources/qt-tools/kddockwidgets/
Generated by doxygen 1.9.8