Introduce View::handle() and View::equals()
So we can compare two windows without calling asQWidget().
This commit is contained in:
10
src/View.cpp
10
src/View.cpp
@@ -183,3 +183,13 @@ Controllers::FloatingWindow *View::asFloatingWindowController() const
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool View::equals(const View *other) const
|
||||
{
|
||||
return other && handle() == other->handle();
|
||||
}
|
||||
|
||||
bool View::equals(const std::unique_ptr<ViewWrapper> &other) const
|
||||
{
|
||||
return other && handle() == other->handle();
|
||||
}
|
||||
|
||||
12
src/View.h
12
src/View.h
@@ -38,6 +38,8 @@ namespace Controllers {
|
||||
class FloatingWindow;
|
||||
}
|
||||
|
||||
using HANDLE = const void *;
|
||||
|
||||
class DOCKS_EXPORT View
|
||||
{
|
||||
public:
|
||||
@@ -71,6 +73,16 @@ public:
|
||||
/// as the implementation of free() is free to delay it (with deleteLater() for example)
|
||||
bool inDtor() const;
|
||||
|
||||
/// @brief Returns whether this view represents the same GUI element as the other
|
||||
bool equals(const View *other) const;
|
||||
bool equals(const std::unique_ptr<ViewWrapper> &) const;
|
||||
|
||||
/// @brief Returns a handle for the GUI element
|
||||
/// This value only makes sense to the frontend. For example, for QtQuick it might be a
|
||||
/// QtQuickItem, while for QtWidgets it's a QWidget *. Can be whatever the frontend developer wants,
|
||||
/// as long as it uniquely identifies the GUI element. KDDW backend only uses it for comparison purposes
|
||||
virtual HANDLE handle() const = 0;
|
||||
|
||||
/// @brief Called by the layouting engine
|
||||
/// Override it in case your widget needs to know where it is in the layout. Usually only needed by Frame.s
|
||||
virtual void setLayoutItem(Layouting::Item *) {};
|
||||
|
||||
@@ -566,7 +566,7 @@ FloatingWindow *Frame::floatingWindow() const
|
||||
if (auto fw = p->asFloatingWindowController())
|
||||
return fw;
|
||||
|
||||
if (p->asQWidget() == view()->window()->asQWidget()) {
|
||||
if (p->equals(view()->window())) {
|
||||
// We stop at the window. (top-levels can have parent, but we're not interested)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -213,3 +213,8 @@ std::unique_ptr<ViewWrapper> ViewWrapper_qtwidgets::parentView() const
|
||||
{
|
||||
return std::unique_ptr<ViewWrapper>(new ViewWrapper_qtwidgets(m_widget->parentWidget()));
|
||||
}
|
||||
|
||||
HANDLE ViewWrapper_qtwidgets::handle() const
|
||||
{
|
||||
return reinterpret_cast<HANDLE>(m_widget);
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ public:
|
||||
bool is(Type) const override;
|
||||
std::unique_ptr<ViewWrapper> window() const override;
|
||||
std::unique_ptr<ViewWrapper> parentView() const override;
|
||||
HANDLE handle() const override;
|
||||
|
||||
private:
|
||||
QWidget *const m_widget;
|
||||
|
||||
@@ -311,6 +311,11 @@ public:
|
||||
return QWidget::windowHandle();
|
||||
}
|
||||
|
||||
HANDLE handle() const override
|
||||
{
|
||||
return reinterpret_cast<HANDLE>(this);
|
||||
}
|
||||
|
||||
std::unique_ptr<ViewWrapper> window() const override
|
||||
{
|
||||
ViewWrapper *wrapper = new ViewWrapper_qtwidgets(QWidget::window());
|
||||
|
||||
Reference in New Issue
Block a user