KDDockWidgets API Documentation  1.5
Draggable.cpp
Go to the documentation of this file.
1 /*
2  This file is part of KDDockWidgets.
3 
4  SPDX-FileCopyrightText: 2019-2022 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 "FloatingWindow_p.h"
15 #include "WidgetResizeHandler_p.h"
16 #include "Utils_p.h"
17 
18 
19 using namespace KDDockWidgets;
20 
21 class Draggable::Private
22 {
23 public:
24  explicit Private(QWidgetOrQuick *_thisWidget, bool _enabled)
25  : thisWidget(_thisWidget)
26  , enabled(_enabled)
27  {
28  Q_ASSERT(thisWidget);
29  }
30 
31  QPointer<WidgetResizeHandler> widgetResizeHandler;
32  QWidgetOrQuick *const thisWidget;
33  const bool enabled;
34 };
35 
36 Draggable::Draggable(QWidgetOrQuick *thisWidget, bool enabled)
37  : d(new Private(thisWidget, enabled))
38 {
39  if (thisWidget && d->enabled)
40  DragController::instance()->registerDraggable(this);
41 }
42 
43 Draggable::~Draggable()
44 {
45  if (d->thisWidget && d->enabled)
46  DragController::instance()->unregisterDraggable(this);
47  delete d;
48 }
49 
50 QWidgetOrQuick *Draggable::asWidget() const
51 {
52  return d->thisWidget;
53 }
54 
55 bool Draggable::dragCanStart(QPoint pressPos, QPoint globalPos) const
56 {
57  return (globalPos - pressPos).manhattanLength() > KDDockWidgets::startDragDistance();
58 }
59 
60 void Draggable::setWidgetResizeHandler(WidgetResizeHandler *w)
61 {
62  Q_ASSERT(!d->widgetResizeHandler);
63  Q_ASSERT(w);
64  d->widgetResizeHandler = w;
65 }
QPointer< WidgetResizeHandler >
QWidget
KDDockWidgets
Definition: Config.cpp:36
QPoint

© 2019-2022 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 on Mon Mar 7 2022 02:01:20 for KDDockWidgets API Documentation by doxygen 1.8.20