12 #include "ClassicIndicatorsWindow_p.h"
13 #include "ClassicIndicators_p.h"
14 #include "../Utils_p.h"
20 static QString iconName(DropIndicatorOverlayInterface::DropLocation loc,
bool active)
22 QString suffix = active ? QStringLiteral(
"_active")
27 case DropIndicatorOverlayInterface::DropLocation_Center:
28 name = QStringLiteral(
"center");
30 case DropIndicatorOverlayInterface::DropLocation_Left:
31 name = QStringLiteral(
"inner_left");
33 case DropIndicatorOverlayInterface::DropLocation_Right:
34 name = QStringLiteral(
"inner_right");
36 case DropIndicatorOverlayInterface::DropLocation_Bottom:
37 name = QStringLiteral(
"inner_bottom");
39 case DropIndicatorOverlayInterface::DropLocation_Top:
40 name = QStringLiteral(
"inner_top");
42 case DropIndicatorOverlayInterface::DropLocation_OutterLeft:
43 name = QStringLiteral(
"outter_left");
45 case DropIndicatorOverlayInterface::DropLocation_OutterBottom:
46 name = QStringLiteral(
"outter_bottom");
48 case DropIndicatorOverlayInterface::DropLocation_OutterRight:
49 name = QStringLiteral(
"outter_right");
51 case DropIndicatorOverlayInterface::DropLocation_OutterTop:
52 name = QStringLiteral(
"outter_top");
54 case DropIndicatorOverlayInterface::DropLocation_None:
62 #ifdef KDDOCKWIDGETS_QTWIDGETS
66 #define INDICATOR_WIDTH 40
67 #define OUTTER_INDICATOR_MARGIN 10
73 p.drawImage(rect(), m_imageActive, rect());
75 p.drawImage(rect(), m_image, rect());
78 void Indicator::setHovered(
bool hovered)
80 if (hovered != m_hovered) {
84 q->setDropLocation(m_dropLocation);
85 }
else if (q->currentDropLocation() == m_dropLocation) {
86 q->setDropLocation(DropIndicatorOverlayInterface::DropLocation_None);
96 QString Indicator::iconFileName(
bool active)
const
99 return KDDockWidgets::windowManagerHasTranslucency() ? QStringLiteral(
":/img/classic_indicators/%1.png").arg(name)
100 : QStringLiteral(
":/img/classic_indicators/opaque/%1.png").arg(name);
103 static QWidgetAdapter *parentForIndicatorWindow(ClassicIndicators *classicIndicators_)
107 return isWayland() ? classicIndicators_
117 IndicatorWindow::IndicatorWindow(ClassicIndicators *classicIndicators_)
118 :
QWidget(parentForIndicatorWindow(classicIndicators_), flagsForIndicatorWindow())
119 , classicIndicators(classicIndicators_)
120 , m_center(new Indicator(classicIndicators, this, DropIndicatorOverlayInterface::DropLocation_Center))
121 , m_left(new Indicator(classicIndicators, this, DropIndicatorOverlayInterface::DropLocation_Left))
122 , m_right(new Indicator(classicIndicators, this, DropIndicatorOverlayInterface::DropLocation_Right))
123 , m_bottom(new Indicator(classicIndicators, this, DropIndicatorOverlayInterface::DropLocation_Bottom))
124 , m_top(new Indicator(classicIndicators, this, DropIndicatorOverlayInterface::DropLocation_Top))
125 , m_outterLeft(new Indicator(classicIndicators, this, DropIndicatorOverlayInterface::DropLocation_OutterLeft))
126 , m_outterRight(new Indicator(classicIndicators, this, DropIndicatorOverlayInterface::DropLocation_OutterRight))
127 , m_outterBottom(new Indicator(classicIndicators, this, DropIndicatorOverlayInterface::DropLocation_OutterBottom))
128 , m_outterTop(new Indicator(classicIndicators, this, DropIndicatorOverlayInterface::DropLocation_OutterTop))
139 connect(classicIndicators, &ClassicIndicators::innerIndicatorsVisibleChanged,
140 this, &IndicatorWindow::updateIndicatorVisibility);
141 connect(classicIndicators, &ClassicIndicators::outterIndicatorsVisibleChanged,
142 this, &IndicatorWindow::updateIndicatorVisibility);
144 m_indicators << m_center << m_left << m_right << m_top << m_bottom
145 << m_outterBottom << m_outterTop << m_outterLeft << m_outterRight;
148 Indicator *IndicatorWindow::indicatorForLocation(DropIndicatorOverlayInterface::DropLocation loc)
const
151 case DropIndicatorOverlayInterface::DropLocation_Center:
153 case DropIndicatorOverlayInterface::DropLocation_Left:
155 case DropIndicatorOverlayInterface::DropLocation_Right:
157 case DropIndicatorOverlayInterface::DropLocation_Bottom:
159 case DropIndicatorOverlayInterface::DropLocation_Top:
161 case DropIndicatorOverlayInterface::DropLocation_OutterLeft:
163 case DropIndicatorOverlayInterface::DropLocation_OutterBottom:
164 return m_outterBottom;
165 case DropIndicatorOverlayInterface::DropLocation_OutterRight:
166 return m_outterRight;
167 case DropIndicatorOverlayInterface::DropLocation_OutterTop:
169 case DropIndicatorOverlayInterface::DropLocation_None:
176 void IndicatorWindow::updateMask()
180 if (!KDDockWidgets::windowManagerHasTranslucency()) {
181 for (Indicator *indicator : qAsConst(m_indicators)) {
182 if (indicator->isVisible())
196 void IndicatorWindow::updateIndicatorVisibility()
198 for (Indicator *indicator : { m_left, m_right, m_bottom, m_top })
199 indicator->setVisible(classicIndicators->innerIndicatorsVisible());
201 for (Indicator *indicator : { m_outterTop, m_outterLeft, m_outterRight, m_outterBottom })
202 indicator->setVisible(classicIndicators->outterIndicatorsVisible());
204 m_center->setVisible(classicIndicators->tabIndicatorVisible());
209 QPoint IndicatorWindow::posForIndicator(DropIndicatorOverlayInterface::DropLocation loc)
const
211 Indicator *indicator = indicatorForLocation(loc);
212 return indicator->mapToGlobal(indicator->rect().center());
215 DropIndicatorOverlayInterface::DropLocation IndicatorWindow::hover(
QPoint globalPos)
217 DropIndicatorOverlayInterface::DropLocation loc = DropIndicatorOverlayInterface::DropLocation_None;
219 for (Indicator *indicator : qAsConst(m_indicators)) {
220 if (indicator->isVisible()) {
221 const bool hovered = indicator->rect().contains(indicator->mapFromGlobal(globalPos));
222 indicator->setHovered(hovered);
224 loc = indicator->m_dropLocation;
231 void IndicatorWindow::updatePositions()
234 const int indicatorWidth = m_outterBottom->width();
235 const int halfIndicatorWidth = m_outterBottom->width() / 2;
237 m_outterLeft->move(r.
x() + OUTTER_INDICATOR_MARGIN, r.
center().
y() - halfIndicatorWidth);
238 m_outterBottom->move(r.
center().
x() - halfIndicatorWidth, r.
y() + height() - indicatorWidth - OUTTER_INDICATOR_MARGIN);
239 m_outterTop->move(r.
center().
x() - halfIndicatorWidth, r.
y() + OUTTER_INDICATOR_MARGIN);
240 m_outterRight->move(r.
x() + width() - indicatorWidth - OUTTER_INDICATOR_MARGIN, r.
center().
y() - halfIndicatorWidth);
241 Frame *hoveredFrame = classicIndicators->m_hoveredFrame;
243 QRect hoveredRect = hoveredFrame->QWidget::geometry();
244 m_center->move(r.
topLeft() + hoveredRect.
center() -
QPoint(halfIndicatorWidth, halfIndicatorWidth));
245 m_top->move(m_center->pos() -
QPoint(0, indicatorWidth + OUTTER_INDICATOR_MARGIN));
246 m_right->move(m_center->pos() +
QPoint(indicatorWidth + OUTTER_INDICATOR_MARGIN, 0));
247 m_bottom->move(m_center->pos() +
QPoint(0, indicatorWidth + OUTTER_INDICATOR_MARGIN));
248 m_left->move(m_center->pos() -
QPoint(indicatorWidth + OUTTER_INDICATOR_MARGIN, 0));
252 Indicator::Indicator(ClassicIndicators *classicIndicators, IndicatorWindow *parent, ClassicIndicators::DropLocation location)
254 , q(classicIndicators)
255 , m_dropLocation(location)
257 m_image =
QImage(iconFileName(
false)).
scaled(INDICATOR_WIDTH, INDICATOR_WIDTH);
258 m_imageActive =
QImage(iconFileName(
true)).
scaled(INDICATOR_WIDTH, INDICATOR_WIDTH);
259 setFixedSize(m_image.size());
265 #include <QQmlContext>
267 IndicatorWindow::IndicatorWindow(KDDockWidgets::ClassicIndicators *classicIndicators)
269 , m_classicIndicators(classicIndicators)
274 rootContext()->setContextProperty(QStringLiteral(
"_window"), QVariant::fromValue<QObject *>(
this));
275 setSource(
QUrl(QStringLiteral(
"qrc:/kddockwidgets/private/quick/qml/ClassicIndicatorsOverlay.qml")));
279 if (KDDockWidgets::isOffscreen()) {
298 DropIndicatorOverlayInterface::DropLocation IndicatorWindow::hover(
QPoint pt)
300 QQuickItem *item = indicatorForPos(pt);
301 const DropIndicatorOverlayInterface::DropLocation loc = item ? locationForIndicator(item)
302 : DropIndicatorOverlayInterface::DropLocation_None;
303 classicIndicators()->setDropLocation(loc);
307 QQuickItem *IndicatorWindow::indicatorForPos(
QPoint pt)
const
310 Q_ASSERT(indicators.
size() == 9);
312 for (QQuickItem *item : indicators) {
313 if (item->isVisible()) {
314 QRect rect(0, 0,
int(item->width()),
int(item->height()));
315 rect.moveTopLeft(item->mapToGlobal(
QPointF(0, 0)).toPoint());
316 if (rect.contains(pt)) {
325 void IndicatorWindow::updatePositions()
330 QPoint IndicatorWindow::posForIndicator(KDDockWidgets::DropIndicatorOverlayInterface::DropLocation loc)
const
332 QQuickItem *indicator = IndicatorWindow::indicatorForLocation(loc);
333 return indicator->mapToGlobal(indicator->boundingRect().center()).toPoint();
341 ClassicIndicators *IndicatorWindow::classicIndicators()
const
343 return m_classicIndicators;
346 QQuickItem *IndicatorWindow::indicatorForLocation(DropIndicatorOverlayInterface::DropLocation loc)
const
349 Q_ASSERT(indicators.
size() == 9);
351 for (QQuickItem *item : indicators) {
352 if (locationForIndicator(item) == loc)
356 qWarning() << Q_FUNC_INFO <<
"Couldn't find indicator for location" << loc;
360 DropIndicatorOverlayInterface::DropLocation IndicatorWindow::locationForIndicator(
const QQuickItem *item)
const
362 return DropIndicatorOverlayInterface::DropLocation(item->property(
"indicatorType").toInt());
370 QQuickItem *root = rootObject();
372 for (QQuickItem *item : items) {
375 }
else if (item->objectName() ==
QLatin1String(
"innerIndicators")) {
377 for (QQuickItem *innerItem : innerIndicators) {