Removed the qtquick/qtwidgets ifdefs from ClassicIndicatorsWindow_*
They now each have their own implementation. qtquick one still not compiling, as it duplicates symbols.
This commit is contained in:
@@ -62,8 +62,6 @@ static QString iconName(DropLocation loc, bool active)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef KDDOCKWIDGETS_QTWIDGETS
|
||||
|
||||
#include <QPainter>
|
||||
|
||||
#define INDICATOR_WIDTH 40
|
||||
@@ -261,130 +259,3 @@ Indicator::Indicator(ClassicIndicators *classicIndicators, IndicatorWindow *pare
|
||||
setFixedSize(m_image.size());
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <QQmlContext>
|
||||
|
||||
IndicatorWindow::IndicatorWindow(KDDockWidgets::ClassicIndicators *classicIndicators)
|
||||
: QQuickView()
|
||||
, m_classicIndicators(classicIndicators)
|
||||
{
|
||||
setFlags(flags() | Qt::FramelessWindowHint | Qt::BypassWindowManagerHint | Qt::Tool);
|
||||
setColor(Qt::transparent);
|
||||
|
||||
rootContext()->setContextProperty(QStringLiteral("_window"), QVariant::fromValue<QObject *>(this));
|
||||
setSource(QUrl(QStringLiteral("qrc:/kddockwidgets/qtquick/views/qml/ClassicIndicatorsOverlay.qml")));
|
||||
|
||||
|
||||
// Two workarounds for two unrelated bugs:
|
||||
if (KDDockWidgets::isOffscreen()) {
|
||||
// 1. We need to create the window asap, otherwise, if a drag triggers the indicator window
|
||||
// to show, that creates a QOffscreenWindow, which flushes events in the ctor, triggering
|
||||
// more hover events which will trigger another QOffscreenWindow.
|
||||
// We then end up with a QWindow with two QPlatformWindow, and only one is deleted in
|
||||
// at shutdown, meaning some timers aren't unregistered, meaning we get a crash when
|
||||
// the timer event is sent to the destroyed QWindow.
|
||||
create();
|
||||
} else {
|
||||
// 2.
|
||||
// Small hack to avoid flickering when we drag over a window the first time
|
||||
// Not sure why a simply create() doesn't work instead
|
||||
// Not if offscreen though, as that QPA is flaky with window activation/focus
|
||||
resize(QSize(1, 1));
|
||||
show();
|
||||
hide();
|
||||
}
|
||||
}
|
||||
|
||||
DropLocation IndicatorWindow::hover(QPoint pt)
|
||||
{
|
||||
QQuickItem *item = indicatorForPos(pt);
|
||||
const DropLocation loc = item ? locationForIndicator(item)
|
||||
: DropLocation_None;
|
||||
classicIndicators()->setDropLocation(loc);
|
||||
return loc;
|
||||
}
|
||||
|
||||
QQuickItem *IndicatorWindow::indicatorForPos(QPoint pt) const
|
||||
{
|
||||
const QVector<QQuickItem *> indicators = indicatorItems();
|
||||
Q_ASSERT(indicators.size() == 9);
|
||||
|
||||
for (QQuickItem *item : indicators) {
|
||||
if (item->isVisible()) {
|
||||
QRect rect(0, 0, int(item->width()), int(item->height()));
|
||||
rect.moveTopLeft(item->mapToGlobal(QPointF(0, 0)).toPoint());
|
||||
if (rect.contains(pt)) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void IndicatorWindow::updatePositions()
|
||||
{
|
||||
// Not needed to implement, the Indicators use QML anchors
|
||||
}
|
||||
|
||||
QPoint IndicatorWindow::posForIndicator(KDDockWidgets::DropLocation loc) const
|
||||
{
|
||||
QQuickItem *indicator = IndicatorWindow::indicatorForLocation(loc);
|
||||
return indicator->mapToGlobal(indicator->boundingRect().center()).toPoint();
|
||||
}
|
||||
|
||||
QString IndicatorWindow::iconName(int loc, bool active) const
|
||||
{
|
||||
return KDDockWidgets::iconName(DropLocation(loc), active);
|
||||
}
|
||||
|
||||
ClassicIndicators *IndicatorWindow::classicIndicators() const
|
||||
{
|
||||
return m_classicIndicators;
|
||||
}
|
||||
|
||||
QQuickItem *IndicatorWindow::indicatorForLocation(DropLocation loc) const
|
||||
{
|
||||
const QVector<QQuickItem *> indicators = indicatorItems();
|
||||
Q_ASSERT(indicators.size() == 9);
|
||||
|
||||
for (QQuickItem *item : indicators) {
|
||||
if (locationForIndicator(item) == loc)
|
||||
return item;
|
||||
}
|
||||
|
||||
qWarning() << Q_FUNC_INFO << "Couldn't find indicator for location" << loc;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
DropLocation IndicatorWindow::locationForIndicator(const QQuickItem *item) const
|
||||
{
|
||||
return DropLocation(item->property("indicatorType").toInt());
|
||||
}
|
||||
|
||||
QVector<QQuickItem *> IndicatorWindow::indicatorItems() const
|
||||
{
|
||||
QVector<QQuickItem *> indicators;
|
||||
indicators.reserve(9);
|
||||
|
||||
QQuickItem *root = rootObject();
|
||||
const QList<QQuickItem *> items = root->childItems();
|
||||
for (QQuickItem *item : items) {
|
||||
if (QString::fromLatin1(item->metaObject()->className()).startsWith(QLatin1String("ClassicIndicator_QMLTYPE"))) {
|
||||
indicators.push_back(item);
|
||||
} else if (item->objectName() == QLatin1String("innerIndicators")) {
|
||||
const QList<QQuickItem *> innerIndicators = item->childItems();
|
||||
for (QQuickItem *innerItem : innerIndicators) {
|
||||
if (QString::fromLatin1(innerItem->metaObject()->className()).startsWith(QLatin1String("ClassicIndicator_QMLTYPE"))) {
|
||||
indicators.push_back(innerItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return indicators;
|
||||
}
|
||||
|
||||
#endif // QtQuick
|
||||
|
||||
@@ -9,14 +9,13 @@
|
||||
Contact KDAB at <info@kdab.com> for commercial licensing options.
|
||||
*/
|
||||
|
||||
#ifndef KD_INDICATORS_CLASSICINDICATORS_WINDOW_P_H
|
||||
#define KD_INDICATORS_CLASSICINDICATORS_WINDOW_P_H
|
||||
#ifndef KD_CLASSICINDICATORS_WINDOW_QTWIDGETS_H
|
||||
#define KD_CLASSICINDICATORS_WINDOW_QTWIDGETS_H
|
||||
#pragma once
|
||||
|
||||
#include "controllers/DropIndicatorOverlay.h"
|
||||
#include "controllers/indicators/ClassicIndicators.h"
|
||||
|
||||
#ifdef KDDOCKWIDGETS_QTWIDGETS
|
||||
|
||||
#include <QImage>
|
||||
#include <QWidget>
|
||||
#include <QResizeEvent>
|
||||
@@ -80,36 +79,7 @@ public:
|
||||
bool m_hovered = false;
|
||||
const DropLocation m_dropLocation;
|
||||
};
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <QQuickView>
|
||||
|
||||
namespace KDDockWidgets {
|
||||
class ClassicIndicators;
|
||||
|
||||
class IndicatorWindow : public QQuickView
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(KDDockWidgets::ClassicIndicators *classicIndicators READ classicIndicators CONSTANT)
|
||||
public:
|
||||
explicit IndicatorWindow(ClassicIndicators *);
|
||||
DropLocation hover(QPoint);
|
||||
void updatePositions();
|
||||
QPoint posForIndicator(DropLocation) const;
|
||||
Q_INVOKABLE QString iconName(int loc, bool active) const;
|
||||
KDDockWidgets::ClassicIndicators *classicIndicators() const;
|
||||
QQuickItem *indicatorForLocation(DropLocation loc) const;
|
||||
|
||||
private:
|
||||
DropLocation locationForIndicator(const QQuickItem *) const;
|
||||
QQuickItem *indicatorForPos(QPoint) const;
|
||||
QVector<QQuickItem *> indicatorItems() const;
|
||||
ClassicIndicators *const m_classicIndicators;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user