12 #include "SegmentedIndicators_p.h"
13 #include "../DropArea_p.h"
17 #include <QPainterPath>
21 int SegmentedIndicators::s_segmentGirth = 50;
22 int SegmentedIndicators::s_segmentPenWidth = 4;
23 qreal SegmentedIndicators::s_draggedWindowOpacity = 0.7;
25 QColor SegmentedIndicators::s_segmentBrushColor =
QColor(0xbb, 0xd5, 0xee, 200);
26 QColor SegmentedIndicators::s_hoveredSegmentBrushColor =
QColor(0x3574c5);
29 SegmentedIndicators::SegmentedIndicators(DropArea *dropArea)
30 : DropIndicatorOverlayInterface(dropArea)
36 const bool userChoseOpacity = !qIsNaN(
Config::self().draggedWindowOpacity());
37 if (!userChoseOpacity)
41 SegmentedIndicators::~SegmentedIndicators()
45 DropIndicatorOverlayInterface::DropLocation SegmentedIndicators::hover_impl(
QPoint pt)
47 m_hoveredPt = mapFromGlobal(pt);
49 setCurrentDropLocation(dropLocationForPos(m_hoveredPt));
51 return currentDropLocation();
54 DropIndicatorOverlayInterface::DropLocation SegmentedIndicators::dropLocationForPos(
QPoint pos)
const
56 for (
auto it = m_segments.cbegin(), end = m_segments.cend(); it != end; ++it) {
62 return DropLocation_None;
74 const int halfPenWidth = s_segmentPenWidth / 2;
76 const int l = s_segmentGirth;
77 const int top = (r.
y() == 0 && useOffset) ? l : r.
y();
78 const int left = (r.
x() == 0 && useOffset) ? l : r.
x();
80 const int bottom = (rect().bottom() == r.
bottom() && useOffset) ? r.
bottom() - l : r.
bottom();
81 const QPoint topLeft = {
left + halfPenWidth, top + halfPenWidth };
82 const QPoint topRight = {
right, top + halfPenWidth };
83 const QPoint bottomLeft = {
left + halfPenWidth, bottom };
88 topLeft +
QPoint(l, l), topLeft };
91 bottomRight +
QPoint(-l, -l),
92 topRight +
QPoint(-l, l) };
99 bottomRight +
QPoint(-l, -l),
100 bottomLeft +
QPoint(l, -l) };
106 bottomRight +
QPoint(-l, -l),
107 bottomLeft +
QPoint(l, -l) };
112 const int indicatorWidth = qMin(300, maxWidth - 100);
113 const int indicatorHeight = qMin(160,
int(indicatorWidth * 0.60));
114 const int tabWidth = int(indicatorWidth * 0.267);
115 const int tabHeight = int(indicatorHeight * 0.187);
116 const int centerRectLeft = centerPos.
x() - indicatorWidth / 2;
117 const int centerRectRight = centerPos.
x() + indicatorWidth / 2;
118 const int centerRectBottom = centerPos.
y() + indicatorHeight / 2;
119 const int centerRectTop = centerPos.
y() - indicatorHeight / 2;
123 { centerRectLeft, centerRectTop },
124 { centerRectLeft + tabWidth, centerRectTop },
125 { centerRectLeft + tabWidth, centerRectTop + tabHeight },
126 { centerRectRight, centerRectTop + tabHeight },
127 { centerRectRight, centerRectBottom },
128 { centerRectLeft, centerRectBottom },
132 return { leftPoints, topPoints, rightPoints, bottomPoints };
135 void SegmentedIndicators::updateSegments()
139 const bool hasMultipleFrames = m_dropArea->visibleCount() > 1;
140 const bool needsOutterIndicators =
true;
141 const bool needsInnerIndicators = needsOutterIndicators && hasMultipleFrames && hoveredFrameRect().isValid();
145 if (needsInnerIndicators) {
146 const bool useOffset = needsOutterIndicators;
147 auto segments = segmentsForRect(hoveredFrameRect(), center, useOffset);
148 for (
int i = 0; i < 4; ++i)
149 m_segments.insert(DropLocation(DropLocation_Left + i), segments[i]);
151 m_segments.insert(DropLocation_Center, center);
154 if (needsOutterIndicators) {
155 auto segments = segmentsForRect(rect(), center);
156 for (
int i = 0; i < 4; ++i)
157 m_segments.insert(DropLocation(DropLocation_OutterLeft + i), segments[i]);
163 void SegmentedIndicators::drawSegments(
QPainter *p)
165 for (
int i = DropLocation_First; i <= DropLocation_Last; ++i)
166 drawSegment(p, m_segments.value(DropLocation(i)));
174 QPen pen(s_segmentPenColor);
175 pen.setWidth(s_segmentPenWidth);
177 QColor brush(s_segmentBrushColor);
180 brush = s_hoveredSegmentBrushColor;
186 QPoint KDDockWidgets::SegmentedIndicators::posForIndicator(DropIndicatorOverlayInterface::DropLocation)
const