KDDockWidgets API Documentation 2.0
Loading...
Searching...
No Matches
core/indicators/SegmentedDropIndicatorOverlay.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
13#include "core/DropArea.h"
14#include "Config.h"
15#include "core/ViewFactory.h"
16
17#include <algorithm>
18#include <cmath>
19
20using namespace KDDockWidgets;
21using namespace KDDockWidgets::Core;
22
28
30 : DropIndicatorOverlay(dropArea, Config::self().viewFactory()->createSegmentedDropIndicatorOverlayView(this, dropArea->view()))
31{
32 // If the app didn't choose opacity then we choose a suitable default value.
33 // ClassicIndicators works fine with an opaque dragged window because the indicators have higher
34 // Z, However for SegmentedIndicators the indicators are in the main window, so lower Z. Make
35 // the dragged window translucent a bit, so we can see the indicators
36 const bool userChoseOpacity = !std::isnan(Config::self().draggedWindowOpacity());
37 if (!userChoseOpacity)
39}
40
42
44{
45 m_hoveredPt = view()->mapFromGlobal(pt);
46 updateSegments();
48
49 return currentDropLocation();
50}
51
53{
54 for (const auto &m_segment : m_segments) {
55 if (m_segment.second.containsPoint(pos, Qt::OddEvenFill)) {
56 return m_segment.first;
57 }
58 }
59
60 return DropLocation_None;
61}
62
63std::unordered_map<DropLocation, Polygon> SegmentedDropIndicatorOverlay::segmentsForRect(Rect r, bool inner,
64 bool useOffset) const
65{
66 const int halfPenWidth = s_segmentPenWidth / 2;
67
68 const int l = s_segmentGirth;
69 const int top = (r.y() == 0 && useOffset) ? l : r.y();
70 const int left = (r.x() == 0 && useOffset) ? l : r.x();
71 const int right = (rect().right() == r.right() && useOffset) ? r.right() - l : r.right();
72 const int bottom = (rect().bottom() == r.bottom() && useOffset) ? r.bottom() - l : r.bottom();
73 const Point topLeft = { left + halfPenWidth, top + halfPenWidth };
74 const Point topRight = { right, top + halfPenWidth };
75 const Point bottomLeft = { left + halfPenWidth, bottom };
76 const Point bottomRight = { right, bottom };
77
78 const Vector<Point> leftPoints = { topLeft, bottomLeft, Point(left, bottom) + Point(l, -l),
79 topLeft + Point(l, l), topLeft };
80
81 const Vector<Point> rightPoints = { topRight, bottomRight, bottomRight + Point(-l, -l),
82 topRight + Point(-l, l) };
83
84 const Vector<Point> topPoints = { topLeft, topRight, topRight + Point(-l, l),
85 topLeft + Point(l, l) };
86
87 const Vector<Point> bottomPoints = { bottomLeft, bottomRight, bottomRight + Point(-l, -l),
88 bottomLeft + Point(l, -l) };
89
90 if (inner) {
91 Polygon bounds =
92 Vector<Point> { topLeft + Point(l, l), topRight + Point(-l, l),
93 bottomRight + Point(-l, -l), bottomLeft + Point(l, -l) };
94 const int maxWidth = bounds.boundingRect().width();
95 const Point centerPos = bounds.boundingRect().center();
96
97 // Build the center
98 const int indicatorWidth = std::min(s_centralIndicatorMaxWidth, maxWidth - 100);
99 const int indicatorHeight = std::min(s_centralIndicatorMaxHeight, int(indicatorWidth * 0.60));
100 const int tabWidth = int(indicatorWidth * 0.267);
101 const int tabHeight = int(indicatorHeight * 0.187);
102 const int centerRectLeft = centerPos.x() - indicatorWidth / 2;
103 const int centerRectRight = centerPos.x() + indicatorWidth / 2;
104 const int centerRectBottom = centerPos.y() + indicatorHeight / 2;
105 const int centerRectTop = centerPos.y() - indicatorHeight / 2;
106
107
108 const auto center = Vector<Point> {
109 { centerRectLeft, centerRectTop },
110 { centerRectLeft + tabWidth, centerRectTop },
111 { centerRectLeft + tabWidth, centerRectTop + tabHeight },
112 { centerRectRight, centerRectTop + tabHeight },
113 { centerRectRight, centerRectBottom },
114 { centerRectLeft, centerRectBottom },
115 };
116
117 return { { DropLocation_Left, leftPoints },
118 { DropLocation_Top, topPoints },
119 { DropLocation_Right, rightPoints },
120 { DropLocation_Bottom, bottomPoints },
122 }
123
124 return { { DropLocation_OutterLeft, leftPoints },
125 { DropLocation_OutterTop, topPoints },
126 { DropLocation_OutterRight, rightPoints },
127 { DropLocation_OutterBottom, bottomPoints } };
128}
129
130void SegmentedDropIndicatorOverlay::updateSegments()
131{
132 m_segments.clear();
133
134 const auto outterSegments = segmentsForRect(rect(), /*inner=*/false);
135
136 for (auto indicator : { DropLocation_OutterLeft, DropLocation_OutterRight,
138 if (dropIndicatorVisible(indicator)) {
139 auto it = outterSegments.find(indicator);
140 const Polygon segment = it == outterSegments.cend() ? Polygon() : it->second;
141 m_segments[indicator] = segment;
142 }
143 }
144
145 const bool hasOutter = !m_segments.empty();
146 const bool useOffset = hasOutter;
147 const auto innerSegments = segmentsForRect(hoveredGroupRect(), /*inner=*/true, useOffset);
148
149 for (auto indicator : { DropLocation_Left, DropLocation_Top, DropLocation_Right,
151 if (dropIndicatorVisible(indicator)) {
152 auto it = innerSegments.find(indicator);
153 const Polygon segment = it == innerSegments.cend() ? Polygon() : it->second;
154 m_segments[indicator] = segment;
155 }
156 }
157
158 view()->update();
159}
160
166
168{
169 return m_hoveredPt;
170}
171
172const std::unordered_map<DropLocation, Polygon> &SegmentedDropIndicatorOverlay::segments() const
173{
174 return m_segments;
175}
Application-wide config to tune certain behaviours of the framework.
Singleton to allow to choose certain behaviours of the framework.
Definition Config.h:64
void setDraggedWindowOpacity(double opacity)
sets the dragged window opacity 1.0 is fully opaque while 0.0 is fully transparent
Definition Config.cpp:230
static Config & self()
returns the singleton Config instance
Definition Config.cpp:88
View * view() const
Returns the view associated with this controller, if any.
virtual bool dropIndicatorVisible(DropLocation) const
Returns whether the specified drop indicator should be visible.
Point posForIndicator(DropLocation) const override
returns the position of the specified drop location The return is in global coordinates
const std::unordered_map< DropLocation, Polygon > & segments() const
virtual void update()=0
virtual Point mapFromGlobal(Point) const =0
A MultiSplitter with support for drop indicators when hovering over.
Class to abstract QAction, so code still works with QtQuick and Flutter.
DropLocation
Enum describing the different drop indicator types.
OddEvenFill
QTextStream & center(QTextStream &stream)
QTextStream & right(QTextStream &stream)

© 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