12#include "ClassicIndicatorsWindow_p.h"
13#include "ClassicIndicators_p.h"
14#include "../Utils_p.h"
22 QString suffix = active ? QStringLiteral(
"_active")
28 name = QStringLiteral(
"center");
31 name = QStringLiteral(
"inner_left");
34 name = QStringLiteral(
"inner_right");
37 name = QStringLiteral(
"inner_bottom");
40 name = QStringLiteral(
"inner_top");
43 name = QStringLiteral(
"outter_left");
46 name = QStringLiteral(
"outter_bottom");
49 name = QStringLiteral(
"outter_right");
52 name = QStringLiteral(
"outter_top");
66#ifdef KDDOCKWIDGETS_QTWIDGETS
70#define INDICATOR_WIDTH 40
71#define OUTTER_INDICATOR_MARGIN 10
77 p.drawImage(rect(), m_imageActive, rect());
79 p.drawImage(rect(), m_image, rect());
82void Indicator::setHovered(
bool hovered)
84 if (hovered != m_hovered) {
88 q->setDropLocation(m_dropLocation);
89 }
else if (q->currentDropLocation() == m_dropLocation) {
95QString Indicator::iconName(
bool active)
const
100QString Indicator::iconFileName(
bool active)
const
103 return KDDockWidgets::windowManagerHasTranslucency() ? QStringLiteral(
":/img/classic_indicators/%1.png").arg(name)
104 : QStringLiteral(
":/img/classic_indicators/opaque/%1.png").arg(name);
107static QWidgetAdapter *parentForIndicatorWindow(ClassicIndicators *classicIndicators_)
111 return isWayland() ? classicIndicators_
121IndicatorWindow::IndicatorWindow(ClassicIndicators *classicIndicators_)
122 :
QWidget(parentForIndicatorWindow(classicIndicators_), flagsForIndicatorWindow())
123 , classicIndicators(classicIndicators_)
143 connect(classicIndicators, &ClassicIndicators::indicatorsVisibleChanged,
144 this, &IndicatorWindow::updateIndicatorVisibility);
145 connect(classicIndicators, &ClassicIndicators::indicatorsVisibleChanged,
146 this, &IndicatorWindow::updateIndicatorVisibility);
148 m_indicators << m_center << m_left << m_right << m_top << m_bottom
149 << m_outterBottom << m_outterTop << m_outterLeft << m_outterRight;
152Indicator *IndicatorWindow::indicatorForLocation(
DropLocation loc)
const
168 return m_outterBottom;
170 return m_outterRight;
184void IndicatorWindow::updateMask()
188 if (!KDDockWidgets::windowManagerHasTranslucency()) {
189 for (Indicator *indicator : qAsConst(m_indicators)) {
190 if (indicator->isVisible())
204void IndicatorWindow::updateIndicatorVisibility()
206 for (Indicator *indicator : { m_left, m_right, m_bottom, m_top,
207 m_outterTop, m_outterLeft, m_outterRight, m_outterBottom,
209 indicator->setVisible(classicIndicators->dropIndicatorVisible(indicator->m_dropLocation));
216 Indicator *indicator = indicatorForLocation(loc);
217 return indicator->mapToGlobal(indicator->rect().center());
224 for (Indicator *indicator : qAsConst(m_indicators)) {
225 if (indicator->isVisible()) {
226 const bool hovered = indicator->rect().contains(indicator->mapFromGlobal(globalPos));
227 indicator->setHovered(hovered);
229 loc = indicator->m_dropLocation;
236void IndicatorWindow::updatePositions()
239 const int indicatorWidth = m_outterBottom->width();
240 const int halfIndicatorWidth = m_outterBottom->width() / 2;
242 m_outterLeft->move(r.
x() + OUTTER_INDICATOR_MARGIN, r.
center().
y() - halfIndicatorWidth);
243 m_outterBottom->move(r.
center().
x() - halfIndicatorWidth, r.
y() + height() - indicatorWidth - OUTTER_INDICATOR_MARGIN);
244 m_outterTop->move(r.
center().
x() - halfIndicatorWidth, r.
y() + OUTTER_INDICATOR_MARGIN);
245 m_outterRight->move(r.
x() + width() - indicatorWidth - OUTTER_INDICATOR_MARGIN, r.
center().
y() - halfIndicatorWidth);
246 Frame *hoveredFrame = classicIndicators->m_hoveredFrame;
248 QRect hoveredRect = hoveredFrame->QWidget::geometry();
249 m_center->move(r.
topLeft() + hoveredRect.
center() -
QPoint(halfIndicatorWidth, halfIndicatorWidth));
250 m_top->move(m_center->pos() -
QPoint(0, indicatorWidth + OUTTER_INDICATOR_MARGIN));
251 m_right->move(m_center->pos() +
QPoint(indicatorWidth + OUTTER_INDICATOR_MARGIN, 0));
252 m_bottom->move(m_center->pos() +
QPoint(0, indicatorWidth + OUTTER_INDICATOR_MARGIN));
253 m_left->move(m_center->pos() -
QPoint(indicatorWidth + OUTTER_INDICATOR_MARGIN, 0));
257Indicator::Indicator(ClassicIndicators *classicIndicators, IndicatorWindow *parent,
DropLocation location)
259 , q(classicIndicators)
260 , m_dropLocation(location)
262 m_image =
QImage(iconFileName(
false)).
scaled(INDICATOR_WIDTH, INDICATOR_WIDTH);
263 m_imageActive =
QImage(iconFileName(
true)).
scaled(INDICATOR_WIDTH, INDICATOR_WIDTH);
264 setFixedSize(m_image.size());
270#include <QQmlContext>
272IndicatorWindow::IndicatorWindow(KDDockWidgets::ClassicIndicators *classicIndicators)
274 , m_classicIndicators(classicIndicators)
279 rootContext()->setContextProperty(QStringLiteral(
"_window"), QVariant::fromValue<QObject *>(
this));
280 setSource(
QUrl(QStringLiteral(
"qrc:/kddockwidgets/private/quick/qml/ClassicIndicatorsOverlay.qml")));
284 if (KDDockWidgets::isOffscreen()) {
305 QQuickItem *item = indicatorForPos(pt);
306 const DropLocation loc = item ? locationForIndicator(item)
308 classicIndicators()->setDropLocation(loc);
312QQuickItem *IndicatorWindow::indicatorForPos(
QPoint pt)
const
315 Q_ASSERT(indicators.
size() == 9);
317 for (QQuickItem *item : indicators) {
318 if (item->isVisible()) {
319 QRect rect(0, 0,
int(item->width()),
int(item->height()));
320 rect.moveTopLeft(item->mapToGlobal(
QPointF(0, 0)).toPoint());
321 if (rect.contains(pt)) {
330void IndicatorWindow::updatePositions()
337 QQuickItem *indicator = IndicatorWindow::indicatorForLocation(loc);
338 return indicator->mapToGlobal(indicator->boundingRect().center()).toPoint();
341QString IndicatorWindow::iconName(
int loc,
bool active)
const
346ClassicIndicators *IndicatorWindow::classicIndicators()
const
348 return m_classicIndicators;
351QQuickItem *IndicatorWindow::indicatorForLocation(
DropLocation loc)
const
354 Q_ASSERT(indicators.
size() == 9);
356 for (QQuickItem *item : indicators) {
357 if (locationForIndicator(item) == loc)
361 qWarning() << Q_FUNC_INFO <<
"Couldn't find indicator for location" << loc;
365DropLocation IndicatorWindow::locationForIndicator(
const QQuickItem *item)
const
367 return DropLocation(item->property(
"indicatorType").toInt());
375 QQuickItem *root = rootObject();
377 for (QQuickItem *item : items) {
380 }
else if (item->objectName() ==
QLatin1String(
"innerIndicators")) {
382 for (QQuickItem *innerItem : innerIndicators) {
QImage scaled(int width, int height, Qt::AspectRatioMode aspectRatioMode, Qt::TransformationMode transformMode) const const
QPoint center() const const
QPoint topLeft() const const
QRegion united(const QRegion &r) const const
QString fromLatin1(const char *str, int size)
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const const
void push_back(const T &value)