qml: Dropping a dragged window now works
This commit is contained in:
@@ -72,6 +72,11 @@ bool DropIndicatorOverlayInterface::isHovered() const
|
||||
return m_windowBeingDragged != nullptr;
|
||||
}
|
||||
|
||||
DropIndicatorOverlayInterface::DropLocation DropIndicatorOverlayInterface::currentDropLocation() const
|
||||
{
|
||||
return m_currentDropLocation;
|
||||
}
|
||||
|
||||
KDDockWidgets::Location DropIndicatorOverlayInterface::multisplitterLocationFor(DropIndicatorOverlayInterface::DropLocation dropLoc)
|
||||
{
|
||||
switch (dropLoc) {
|
||||
@@ -103,14 +108,20 @@ void DropIndicatorOverlayInterface::onFrameDestroyed()
|
||||
|
||||
void DropIndicatorOverlayInterface::onHoveredFrameChanged(Frame *)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DropIndicatorOverlayInterface::setCurrentDropLocation(DropIndicatorOverlayInterface::DropLocation location)
|
||||
{
|
||||
m_currentDropLocation = location;
|
||||
if (m_currentDropLocation != location) {
|
||||
m_currentDropLocation = location;
|
||||
Q_EMIT currentDropLocationChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void DropIndicatorOverlayInterface::hover(QPoint globalPos)
|
||||
{
|
||||
hover_impl(globalPos);
|
||||
}
|
||||
|
||||
void DropIndicatorOverlayInterface::setHoveredFrameRect(QRect rect)
|
||||
{
|
||||
@@ -118,5 +129,4 @@ void DropIndicatorOverlayInterface::setHoveredFrameRect(QRect rect)
|
||||
m_hoveredFrameRect = rect;
|
||||
Q_EMIT hoveredFrameRectChanged();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ class DOCKS_EXPORT_FOR_UNIT_TESTS DropIndicatorOverlayInterface : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QRect hoveredFrameRect READ hoveredFrameRect NOTIFY hoveredFrameRectChanged)
|
||||
Q_PROPERTY(KDDockWidgets::DropIndicatorOverlayInterface::DropLocation currentDropLocation READ currentDropLocation NOTIFY currentDropLocationChanged)
|
||||
public:
|
||||
enum Type {
|
||||
TypeNone = 0,
|
||||
@@ -53,12 +54,12 @@ public:
|
||||
void setWindowBeingDragged(const FloatingWindow *);
|
||||
QRect hoveredFrameRect() const;
|
||||
bool isHovered() const;
|
||||
DropLocation currentDropLocation() const { return m_currentDropLocation; }
|
||||
DropLocation currentDropLocation() const;
|
||||
Frame *hoveredFrame() const { return m_hoveredFrame; }
|
||||
void setCurrentDropLocation(DropIndicatorOverlayInterface::DropLocation location);
|
||||
|
||||
virtual Type indicatorType() const = 0;
|
||||
virtual void hover(QPoint globalPos) = 0;
|
||||
void hover(QPoint globalPos);
|
||||
|
||||
virtual QPoint posForIndicator(DropLocation) const = 0; // Used by unit-tests only
|
||||
|
||||
@@ -67,17 +68,20 @@ public:
|
||||
Q_SIGNALS:
|
||||
void hoveredFrameChanged(KDDockWidgets::Frame *);
|
||||
void hoveredFrameRectChanged();
|
||||
void currentDropLocationChanged();
|
||||
|
||||
private:
|
||||
void onFrameDestroyed();
|
||||
void setHoveredFrameRect(QRect);
|
||||
QRect m_hoveredFrameRect;
|
||||
DropLocation m_currentDropLocation = DropLocation_None;
|
||||
|
||||
protected:
|
||||
virtual void hover_impl(QPoint globalPos) = 0;
|
||||
virtual void onHoveredFrameChanged(Frame *);
|
||||
virtual void updateVisibility() = 0;
|
||||
|
||||
Frame *m_hoveredFrame = nullptr;
|
||||
DropLocation m_currentDropLocation = DropLocation_None;
|
||||
QPointer<const FloatingWindow> m_windowBeingDragged;
|
||||
DropArea *const m_dropArea;
|
||||
};
|
||||
|
||||
@@ -45,7 +45,7 @@ DropIndicatorOverlayInterface::Type ClassicIndicators::indicatorType() const
|
||||
return TypeClassic;
|
||||
}
|
||||
|
||||
void ClassicIndicators::hover(QPoint globalPos)
|
||||
void ClassicIndicators::hover_impl(QPoint globalPos)
|
||||
{
|
||||
m_indicatorWindow->hover(globalPos);
|
||||
}
|
||||
|
||||
@@ -247,22 +247,37 @@ IndicatorWindow::IndicatorWindow(KDDockWidgets::ClassicIndicators *classicIndica
|
||||
|
||||
void IndicatorWindow::hover(QPoint pt)
|
||||
{
|
||||
qDebug() << "Hover" << pt;
|
||||
QQuickItem *item = indicatorForPos(pt);
|
||||
if (item) {
|
||||
const auto loc = DropIndicatorOverlayInterface::DropLocation(item->property("indicatorType").toInt());
|
||||
classicIndicators()->setDropLocation(loc);
|
||||
} else {
|
||||
classicIndicators()->setDropLocation(DropIndicatorOverlayInterface::DropLocation_None);
|
||||
}
|
||||
}
|
||||
|
||||
QQuickItem *IndicatorWindow::indicatorForPos(QPoint pt) const
|
||||
{
|
||||
const QVector<QQuickItem *> indicators = indicatorItems();
|
||||
Q_ASSERT(indicators.size() == 9);
|
||||
|
||||
for (QQuickItem *item : indicators) {
|
||||
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()
|
||||
{
|
||||
qDebug() << "updatePositions";
|
||||
// Not needed to implement, the Indicators use QML anchors
|
||||
}
|
||||
|
||||
QPoint IndicatorWindow::posForIndicator(KDDockWidgets::DropIndicatorOverlayInterface::DropLocation) const
|
||||
{
|
||||
QQuickItem *root = rootObject();
|
||||
const QList<QQuickItem*> items = root->childItems();
|
||||
for (QQuickItem *item : items) {
|
||||
qDebug() << Q_FUNC_INFO << item;
|
||||
}
|
||||
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
return {};
|
||||
}
|
||||
@@ -277,4 +292,27 @@ ClassicIndicators *IndicatorWindow::classicIndicators() const
|
||||
return m_classicIndicators;
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@@ -97,6 +97,8 @@ public:
|
||||
Q_INVOKABLE QString iconName(int loc, bool active) const;
|
||||
KDDockWidgets::ClassicIndicators* classicIndicators() const;
|
||||
private:
|
||||
QQuickItem *indicatorForPos(QPoint) const;
|
||||
QVector<QQuickItem*> indicatorItems() const;
|
||||
ClassicIndicators *const m_classicIndicators;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public:
|
||||
explicit ClassicIndicators(DropArea *dropArea);
|
||||
~ClassicIndicators() override;
|
||||
Type indicatorType() const override;
|
||||
void hover(QPoint globalPos) override;
|
||||
void hover_impl(QPoint globalPos) override;
|
||||
QPoint posForIndicator(DropLocation) const override;
|
||||
|
||||
bool innerIndicatorsVisible() const;
|
||||
|
||||
@@ -5,8 +5,9 @@ Image {
|
||||
id: root
|
||||
|
||||
property int indicatorType: DropIndicatorOverlayInterface.DropLocation_None
|
||||
readonly property bool isHovered: _window.classicIndicators.currentDropLocation === indicatorType
|
||||
|
||||
source: "qrc:/img/classic_indicators/" + _window.iconName(indicatorType, true) + ".png";
|
||||
source: "qrc:/img/classic_indicators/" + _window.iconName(indicatorType, isHovered) + ".png";
|
||||
width: 64
|
||||
height: 64
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ Item {
|
||||
anchors.fill: parent
|
||||
readonly property int outterMargin: 10
|
||||
readonly property int innerMargin: 10
|
||||
readonly property QtObject innerIndicators: innerIndicators
|
||||
|
||||
ClassicIndicator {
|
||||
visible: _window.classicIndicators.outterIndicatorsVisible
|
||||
@@ -60,6 +61,7 @@ Item {
|
||||
|
||||
Item {
|
||||
id: innerIndicators
|
||||
objectName: "innerIndicators"
|
||||
|
||||
x: _window.classicIndicators.hoveredFrameRect.x + (_window.classicIndicators.hoveredFrameRect.width / 2)
|
||||
y: _window.classicIndicators.hoveredFrameRect.y + (_window.classicIndicators.hoveredFrameRect.height / 2)
|
||||
|
||||
Reference in New Issue
Block a user