Introduce ViewWrapper - a non-owning view
In many cases we need to access widgets that weren't created by KDDW, in that case we have no View. Since all our APIs want to deal in View and not in QWidget, we need a way to wrap stuff like QWidget::window() and windowHandle() All methods are unimplemented. Will only implement those that are required/used.
This commit is contained in:
@@ -98,6 +98,8 @@ set(DOCKSLIBS_SRCS
|
||||
controllers/TabBar.h
|
||||
View.cpp
|
||||
View.h
|
||||
ViewWrapper.cpp
|
||||
ViewWrapper.h
|
||||
Controller.cpp
|
||||
Controller.h
|
||||
|
||||
@@ -106,6 +108,8 @@ set(DOCKSLIBS_SRCS
|
||||
|
||||
views_qtwidgets/View_qtwidgets.cpp
|
||||
views_qtwidgets/View_qtwidgets.h
|
||||
views_qtwidgets/ViewWrapper_qtwidgets.cpp
|
||||
views_qtwidgets/ViewWrapper_qtwidgets.h
|
||||
views_qtwidgets/FloatingWindow_qtwidgets.cpp
|
||||
views_qtwidgets/FloatingWindow_qtwidgets.h
|
||||
views_qtwidgets/DockWidget_qtwidgets.cpp
|
||||
|
||||
10
src/View.h
10
src/View.h
@@ -31,6 +31,7 @@ class QWindow;
|
||||
|
||||
namespace KDDockWidgets {
|
||||
|
||||
class ViewWrapper;
|
||||
class Controller;
|
||||
|
||||
class DOCKS_EXPORT View
|
||||
@@ -48,7 +49,8 @@ public:
|
||||
Layout = 128,
|
||||
LayoutItem = 256,
|
||||
SideBar = 512,
|
||||
DropIndicatorOverlayInterface = 1024
|
||||
DropIndicatorOverlayInterface = 1024,
|
||||
ViewWrapper = 2048
|
||||
};
|
||||
|
||||
explicit View(Controller *controller, Type, QObject *thisObj);
|
||||
@@ -147,7 +149,7 @@ public:
|
||||
virtual void setFixedWidth(int) = 0;
|
||||
virtual void setFixedHeight(int) = 0;
|
||||
|
||||
// TODO: Check if these two should be in the controller or on view
|
||||
// TODOv2: Check if these two should be in the controller or on view
|
||||
virtual void onLayoutRequest()
|
||||
{
|
||||
}
|
||||
@@ -175,6 +177,10 @@ public:
|
||||
static QSize boundedMaxSize(QSize min, QSize max);
|
||||
|
||||
|
||||
/// @brief Returns the top-level gui element which this one is on
|
||||
/// Like QWidget::window()
|
||||
virtual std::unique_ptr<ViewWrapper> window() const = 0;
|
||||
|
||||
template<typename T>
|
||||
static QSize widgetMinSize(const T *w)
|
||||
{
|
||||
|
||||
277
src/ViewWrapper.cpp
Normal file
277
src/ViewWrapper.cpp
Normal file
@@ -0,0 +1,277 @@
|
||||
/*
|
||||
This file is part of KDDockWidgets.
|
||||
|
||||
SPDX-FileCopyrightText: 2020-2022 Klarälvdalens Datakonsult AB, a KDAB Group
|
||||
company <info@kdab.com> Author: Sérgio Martins <sergio.martins@kdab.com>
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
|
||||
|
||||
Contact KDAB at <info@kdab.com> for commercial licensing options.
|
||||
*/
|
||||
|
||||
#include "ViewWrapper.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
using namespace KDDockWidgets;
|
||||
|
||||
ViewWrapper::ViewWrapper()
|
||||
: View(nullptr, Type::ViewWrapper, nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
void ViewWrapper::setParent(View *)
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
}
|
||||
|
||||
QSize ViewWrapper::minSize() const
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
return {};
|
||||
}
|
||||
|
||||
QSize ViewWrapper::maxSizeHint() const
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
return {};
|
||||
}
|
||||
|
||||
QSize ViewWrapper::minimumSizeHint() const
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
return {};
|
||||
}
|
||||
|
||||
QSize ViewWrapper::maximumSize() const
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
return {};
|
||||
}
|
||||
|
||||
QRect ViewWrapper::geometry() const
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
return {};
|
||||
}
|
||||
|
||||
QRect ViewWrapper::normalGeometry() const
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
return {};
|
||||
}
|
||||
|
||||
void ViewWrapper::setGeometry(QRect)
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
}
|
||||
|
||||
bool ViewWrapper::isVisible() const
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
return {};
|
||||
}
|
||||
|
||||
void ViewWrapper::setVisible(bool)
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
}
|
||||
|
||||
void ViewWrapper::move(int, int)
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
}
|
||||
|
||||
void ViewWrapper::move(QPoint)
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
}
|
||||
|
||||
void ViewWrapper::setSize(int, int)
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
}
|
||||
|
||||
void ViewWrapper::setWidth(int)
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
}
|
||||
|
||||
void ViewWrapper::setHeight(int)
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
}
|
||||
|
||||
void ViewWrapper::show()
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
}
|
||||
|
||||
void ViewWrapper::hide()
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
}
|
||||
|
||||
void ViewWrapper::update()
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
}
|
||||
|
||||
void ViewWrapper::raiseAndActivate()
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
}
|
||||
|
||||
void ViewWrapper::raise()
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
}
|
||||
|
||||
void ViewWrapper::activateWindow()
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
}
|
||||
|
||||
bool ViewWrapper::isTopLevel() const
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
return {};
|
||||
}
|
||||
|
||||
QPoint ViewWrapper::mapToGlobal(QPoint) const
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
return {};
|
||||
}
|
||||
|
||||
QPoint ViewWrapper::mapFromGlobal(QPoint) const
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
return {};
|
||||
}
|
||||
|
||||
void ViewWrapper::setSizePolicy(QSizePolicy)
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
}
|
||||
|
||||
QSizePolicy ViewWrapper::sizePolicy() const
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
return {};
|
||||
}
|
||||
|
||||
void ViewWrapper::closeWindow()
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
}
|
||||
|
||||
QRect ViewWrapper::windowGeometry() const
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
return {};
|
||||
}
|
||||
|
||||
QSize ViewWrapper::parentSize() const
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
return {};
|
||||
}
|
||||
|
||||
bool ViewWrapper::close()
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
return {};
|
||||
}
|
||||
|
||||
void ViewWrapper::setFlag(Qt::WindowType, bool)
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
}
|
||||
|
||||
void ViewWrapper::setAttribute(Qt::WidgetAttribute, bool)
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
}
|
||||
|
||||
bool ViewWrapper::testAttribute(Qt::WidgetAttribute) const
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
return {};
|
||||
}
|
||||
|
||||
Qt::WindowFlags ViewWrapper::flags() const
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
return {};
|
||||
}
|
||||
|
||||
void ViewWrapper::setWindowTitle(const QString &)
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
}
|
||||
|
||||
void ViewWrapper::setWindowIcon(const QIcon &)
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
}
|
||||
|
||||
void ViewWrapper::showNormal()
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
}
|
||||
|
||||
void ViewWrapper::showMinimized()
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
}
|
||||
|
||||
void ViewWrapper::showMaximized()
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
}
|
||||
|
||||
bool ViewWrapper::isMinimized() const
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
return {};
|
||||
}
|
||||
|
||||
bool ViewWrapper::isMaximized() const
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
return {};
|
||||
}
|
||||
|
||||
void ViewWrapper::setMaximumSize(QSize)
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
}
|
||||
|
||||
bool ViewWrapper::isActiveWindow() const
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
return {};
|
||||
}
|
||||
|
||||
QWindow *ViewWrapper::windowHandle() const
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
return {};
|
||||
}
|
||||
|
||||
void ViewWrapper::setFixedWidth(int)
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
}
|
||||
|
||||
void ViewWrapper::setFixedHeight(int)
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
}
|
||||
|
||||
std::unique_ptr<ViewWrapper> ViewWrapper::window() const
|
||||
{
|
||||
qFatal("Not implemented");
|
||||
return {};
|
||||
}
|
||||
77
src/ViewWrapper.h
Normal file
77
src/ViewWrapper.h
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
This file is part of KDDockWidgets.
|
||||
|
||||
SPDX-FileCopyrightText: 2020-2022 Klarälvdalens Datakonsult AB, a KDAB Group
|
||||
company <info@kdab.com> Author: Sérgio Martins <sergio.martins@kdab.com>
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
|
||||
|
||||
Contact KDAB at <info@kdab.com> for commercial licensing options.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "View.h"
|
||||
|
||||
|
||||
namespace KDDockWidgets {
|
||||
|
||||
/// @brief The base class for view wrappers
|
||||
/// A view wrapper is a view that doesn't own the native GUI element(QWidget, QQuickItem etc.)
|
||||
/// It just adds View API to an existing GUI element
|
||||
/// Useful for GUI elements that are not created by KDDW.
|
||||
class ViewWrapper : public View
|
||||
{
|
||||
public:
|
||||
ViewWrapper();
|
||||
|
||||
void setParent(View *) override;
|
||||
QSize minSize() const override;
|
||||
QSize maxSizeHint() const override;
|
||||
QSize minimumSizeHint() const override;
|
||||
QSize maximumSize() const override;
|
||||
QRect geometry() const override;
|
||||
QRect normalGeometry() const override;
|
||||
void setGeometry(QRect) override;
|
||||
bool isVisible() const override;
|
||||
void setVisible(bool) override;
|
||||
void move(int x, int y) override;
|
||||
void move(QPoint) override;
|
||||
void setSize(int width, int height) override;
|
||||
void setWidth(int width) override;
|
||||
void setHeight(int height) override;
|
||||
void show() override;
|
||||
void hide() override;
|
||||
void update() override;
|
||||
void raiseAndActivate() override;
|
||||
void raise() override;
|
||||
void activateWindow() override;
|
||||
bool isTopLevel() const override;
|
||||
QPoint mapToGlobal(QPoint) const override;
|
||||
QPoint mapFromGlobal(QPoint) const override;
|
||||
void setSizePolicy(QSizePolicy) override;
|
||||
QSizePolicy sizePolicy() const override;
|
||||
void closeWindow() override;
|
||||
QRect windowGeometry() const override;
|
||||
QSize parentSize() const override;
|
||||
bool close() override;
|
||||
void setFlag(Qt::WindowType, bool = true) override;
|
||||
void setAttribute(Qt::WidgetAttribute, bool enable = true) override;
|
||||
bool testAttribute(Qt::WidgetAttribute) const override;
|
||||
Qt::WindowFlags flags() const override;
|
||||
void setWindowTitle(const QString &title) override;
|
||||
void setWindowIcon(const QIcon &) override;
|
||||
void showNormal() override;
|
||||
void showMinimized() override;
|
||||
void showMaximized() override;
|
||||
bool isMinimized() const override;
|
||||
bool isMaximized() const override;
|
||||
void setMaximumSize(QSize sz) override;
|
||||
bool isActiveWindow() const override;
|
||||
QWindow *windowHandle() const override;
|
||||
void setFixedWidth(int) override;
|
||||
void setFixedHeight(int) override;
|
||||
std::unique_ptr<ViewWrapper> window() const override;
|
||||
};
|
||||
|
||||
}
|
||||
22
src/views_qtwidgets/ViewWrapper_qtwidgets.cpp
Normal file
22
src/views_qtwidgets/ViewWrapper_qtwidgets.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
This file is part of KDDockWidgets.
|
||||
|
||||
SPDX-FileCopyrightText: 2020-2022 Klarälvdalens Datakonsult AB, a KDAB Group
|
||||
company <info@kdab.com> Author: Sérgio Martins <sergio.martins@kdab.com>
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
|
||||
|
||||
Contact KDAB at <info@kdab.com> for commercial licensing options.
|
||||
*/
|
||||
|
||||
#include "ViewWrapper_qtwidgets.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
using namespace KDDockWidgets::Views;
|
||||
|
||||
ViewWrapper_qtwidgets::ViewWrapper_qtwidgets(QWidget *widget)
|
||||
: ViewWrapper()
|
||||
, m_widget(widget)
|
||||
{
|
||||
}
|
||||
33
src/views_qtwidgets/ViewWrapper_qtwidgets.h
Normal file
33
src/views_qtwidgets/ViewWrapper_qtwidgets.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
This file is part of KDDockWidgets.
|
||||
|
||||
SPDX-FileCopyrightText: 2020-2022 Klarälvdalens Datakonsult AB, a KDAB Group
|
||||
company <info@kdab.com> Author: Sérgio Martins <sergio.martins@kdab.com>
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
|
||||
|
||||
Contact KDAB at <info@kdab.com> for commercial licensing options.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ViewWrapper.h"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace KDDockWidgets::Views {
|
||||
|
||||
|
||||
/// @brief A View that doesn't own its QWidget
|
||||
/// Implements a View API around an existing QWidget
|
||||
/// Useful for widgets that are not created by KDDW.
|
||||
class DOCKS_EXPORT ViewWrapper_qtwidgets : public ViewWrapper
|
||||
{
|
||||
public:
|
||||
explicit ViewWrapper_qtwidgets(QWidget *widget);
|
||||
|
||||
private:
|
||||
QWidget *const m_widget;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "private/Utils_p.h"
|
||||
#include "Controller.h"
|
||||
#include "View.h"
|
||||
#include "ViewWrapper_qtwidgets.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QEvent>
|
||||
@@ -309,6 +310,12 @@ public:
|
||||
return QWidget::windowHandle();
|
||||
}
|
||||
|
||||
std::unique_ptr<ViewWrapper> window() const
|
||||
{
|
||||
ViewWrapper *wrapper = new ViewWrapper_qtwidgets(QWidget::window());
|
||||
return std::unique_ptr<ViewWrapper>(wrapper);
|
||||
}
|
||||
|
||||
protected:
|
||||
bool event(QEvent *e) override
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user