Add Platform_qt, a baseclass for both Qt frontends
So we can share some code between QtQuick and QtWidgets
This commit is contained in:
@@ -106,6 +106,8 @@ set(DOCKSLIBS_SRCS
|
||||
Controller.h
|
||||
Platform.cpp
|
||||
Platform.h
|
||||
qtcommon/Platform_qt.cpp
|
||||
qtcommon/Platform_qt.h
|
||||
qtwidgets/Platform_qtwidgets.cpp
|
||||
qtwidgets/Platform_qtwidgets.h
|
||||
qtwidgets/views/View_qtwidgets.cpp
|
||||
|
||||
30
src/qtcommon/Platform_qt.cpp
Normal file
30
src/qtcommon/Platform_qt.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
This file is part of KDDockWidgets.
|
||||
|
||||
SPDX-FileCopyrightText: 2019-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 "Platform_qt.h"
|
||||
|
||||
#include <QGuiApplication>
|
||||
|
||||
using namespace KDDockWidgets;
|
||||
|
||||
|
||||
Platform_qt::Platform_qt()
|
||||
{
|
||||
}
|
||||
|
||||
Platform_qt::~Platform_qt()
|
||||
{
|
||||
}
|
||||
|
||||
std::shared_ptr<ViewWrapper> Platform_qt::focusedView() const
|
||||
{
|
||||
return qobjectAsView(qApp->focusObject());
|
||||
}
|
||||
30
src/qtcommon/Platform_qt.h
Normal file
30
src/qtcommon/Platform_qt.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
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 "docks_export.h"
|
||||
#include "Platform.h"
|
||||
|
||||
namespace KDDockWidgets {
|
||||
|
||||
/// @brief Baseclass platform for Qt based platform
|
||||
/// Useful since QtWidgets and QtQuick share some similarities
|
||||
class DOCKS_EXPORT Platform_qt : public Platform
|
||||
{
|
||||
public:
|
||||
Platform_qt();
|
||||
~Platform_qt() override;
|
||||
|
||||
std::shared_ptr<ViewWrapper> focusedView() const override;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -52,11 +52,6 @@ const char *Platform_qtquick::name() const
|
||||
return "qtquick";
|
||||
}
|
||||
|
||||
std::shared_ptr<ViewWrapper> Platform_qtquick::focusedView() const
|
||||
{
|
||||
return qobjectAsView(qApp->focusObject());
|
||||
}
|
||||
|
||||
std::shared_ptr<ViewWrapper> Platform_qtquick::qobjectAsView(QObject *obj) const
|
||||
{
|
||||
if (auto w = qobject_cast<QQuickItem *>(obj)) {
|
||||
|
||||
@@ -11,19 +11,18 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Platform.h"
|
||||
#include "qtcommon/Platform_qt.h"
|
||||
|
||||
namespace KDDockWidgets {
|
||||
|
||||
/// @brief implements functions specific to a particular platform
|
||||
/// A platform can be for example qtwidgets, qtquick, etc.
|
||||
class DOCKS_EXPORT Platform_qtquick : public Platform
|
||||
class DOCKS_EXPORT Platform_qtquick : public Platform_qt
|
||||
{
|
||||
public:
|
||||
Platform_qtquick();
|
||||
~Platform_qtquick() override;
|
||||
const char *name() const override;
|
||||
std::shared_ptr<ViewWrapper> focusedView() const override;
|
||||
std::shared_ptr<ViewWrapper> qobjectAsView(QObject *) const override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -61,11 +61,6 @@ bool Platform_qtwidgets::hasActivePopup() const
|
||||
return qApp->activePopupWidget() != nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<ViewWrapper> Platform_qtwidgets::focusedView() const
|
||||
{
|
||||
return qobjectAsView(qApp->focusObject());
|
||||
}
|
||||
|
||||
std::shared_ptr<ViewWrapper> Platform_qtwidgets::qobjectAsView(QObject *obj) const
|
||||
{
|
||||
if (auto w = qobject_cast<QWidget *>(obj)) {
|
||||
|
||||
@@ -11,21 +11,20 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Platform.h"
|
||||
#include "qtcommon/Platform_qt.h"
|
||||
#include "qtwidgets/DebugWindow_p.h"
|
||||
|
||||
namespace KDDockWidgets {
|
||||
|
||||
/// @brief implements functions specific to a particular platform
|
||||
/// A platform can be for example qtwidgets, qtquick, etc.
|
||||
class DOCKS_EXPORT Platform_qtwidgets : public Platform
|
||||
class DOCKS_EXPORT Platform_qtwidgets : public Platform_qt
|
||||
{
|
||||
public:
|
||||
Platform_qtwidgets();
|
||||
~Platform_qtwidgets() override;
|
||||
const char *name() const override;
|
||||
bool hasActivePopup() const override;
|
||||
std::shared_ptr<ViewWrapper> focusedView() const override;
|
||||
std::shared_ptr<ViewWrapper> qobjectAsView(QObject *) const override;
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user