Move common code info FrameViewInterface
So it's not duplicated between QtWidgets and QtQuick
This commit is contained in:
@@ -103,8 +103,10 @@ set(KDDW_BACKEND_SRCS
|
||||
views/MainWindowMDI.h
|
||||
views/MainWindowViewInterface.cpp
|
||||
views/MainWindowViewInterface.h
|
||||
views/FrameViewInterface.cpp
|
||||
views/DockWidgetViewInterface.cpp
|
||||
views/DockWidgetViewInterface.h
|
||||
views/FrameViewInterface.h
|
||||
qtcommon/Platform_qt.cpp
|
||||
qtcommon/Platform_qt.h
|
||||
qtcommon/Window_qt.cpp
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#include "kddockwidgets/KDDockWidgets.h"
|
||||
|
||||
#include "kddockwidgets/views/SideBarViewInterface.h"
|
||||
#include "kddockwidgets/views/FrameViewInterface.h"
|
||||
#include "kddockwidgets/views/TabBarViewInterface.h"
|
||||
#include "kddockwidgets/views/TitleBarViewInterface.h"
|
||||
#include "kddockwidgets/views/StackViewInterface.h"
|
||||
@@ -53,5 +52,4 @@ SideBarViewInterface::~SideBarViewInterface() = default;
|
||||
StackViewInterface::~StackViewInterface() = default;
|
||||
TabBarViewInterface::~TabBarViewInterface() = default;
|
||||
TitleBarViewInterface::~TitleBarViewInterface() = default;
|
||||
FrameViewInterface::~FrameViewInterface() = default;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ using namespace KDDockWidgets::Views;
|
||||
|
||||
Frame_qtquick::Frame_qtquick(Controllers::Frame *controller, QQuickItem *parent)
|
||||
: View_qtquick(controller, Type::Frame, parent)
|
||||
, m_controller(controller)
|
||||
, FrameViewInterface(controller)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ Frame_qtquick::~Frame_qtquick()
|
||||
|
||||
void Frame_qtquick::init()
|
||||
{
|
||||
connect(m_controller->tabWidget(), SIGNAL(countChanged()), /// clazy:exclude=old-style-connect
|
||||
connect(m_frame->tabWidget(), SIGNAL(countChanged()), /// clazy:exclude=old-style-connect
|
||||
this, SLOT(updateConstriants()));
|
||||
|
||||
connect(this, &View_qtquick::geometryUpdated, this, [this] {
|
||||
@@ -63,12 +63,12 @@ void Frame_qtquick::init()
|
||||
});
|
||||
|
||||
/// QML interface connect, since controllers won't be QObjects for much longer:
|
||||
connect(m_controller, &Controllers::Frame::isMDIChanged, this, &Frame_qtquick::isMDIChanged);
|
||||
connect(m_controller, &Controllers::Frame::currentDockWidgetChanged, this, &Frame_qtquick::currentDockWidgetChanged);
|
||||
connect(m_controller, &Controllers::Frame::actualTitleBarChanged, this, &Frame_qtquick::actualTitleBarChanged);
|
||||
connect(m_frame, &Controllers::Frame::isMDIChanged, this, &Frame_qtquick::isMDIChanged);
|
||||
connect(m_frame, &Controllers::Frame::currentDockWidgetChanged, this, &Frame_qtquick::currentDockWidgetChanged);
|
||||
connect(m_frame, &Controllers::Frame::actualTitleBarChanged, this, &Frame_qtquick::actualTitleBarChanged);
|
||||
|
||||
connect(this, &View_qtquick::itemGeometryChanged, this, [this] {
|
||||
for (auto dw : m_controller->dockWidgets()) {
|
||||
for (auto dw : m_frame->dockWidgets()) {
|
||||
auto dwView = static_cast<DockWidget_qtquick *>(asView_qtquick(dw->view()));
|
||||
dwView->frameGeometryChanged(geometry());
|
||||
}
|
||||
@@ -91,7 +91,7 @@ void Frame_qtquick::init()
|
||||
|
||||
void Frame_qtquick::updateConstriants()
|
||||
{
|
||||
m_controller->onDockWidgetCountChanged();
|
||||
m_frame->onDockWidgetCountChanged();
|
||||
|
||||
// QtQuick doesn't have layouts, so we need to do constraint propagation manually
|
||||
|
||||
@@ -119,12 +119,12 @@ int Frame_qtquick::currentIndex_impl() const
|
||||
|
||||
void Frame_qtquick::setCurrentTabIndex_impl(int index)
|
||||
{
|
||||
setCurrentDockWidget_impl(m_controller->dockWidgetAt(index));
|
||||
setCurrentDockWidget_impl(m_frame->dockWidgetAt(index));
|
||||
}
|
||||
|
||||
void Frame_qtquick::setCurrentDockWidget_impl(Controllers::DockWidget *dw)
|
||||
{
|
||||
m_controller->tabWidget()->setCurrentDockWidget(dw);
|
||||
m_frame->tabWidget()->setCurrentDockWidget(dw);
|
||||
}
|
||||
|
||||
void Frame_qtquick::insertDockWidget_impl(Controllers::DockWidget *dw, int index)
|
||||
@@ -189,7 +189,7 @@ void Frame_qtquick::setStackLayout(QQuickItem *stackLayout)
|
||||
|
||||
QSize Frame_qtquick::minSize() const
|
||||
{
|
||||
const QSize contentsSize = m_controller->dockWidgetsMinSize();
|
||||
const QSize contentsSize = m_frame->dockWidgetsMinSize();
|
||||
return contentsSize + QSize(0, nonContentsHeight());
|
||||
}
|
||||
|
||||
@@ -215,7 +215,7 @@ int Frame_qtquick::nonContentsHeight() const
|
||||
|
||||
Stack_qtquick *Frame_qtquick::stackView() const
|
||||
{
|
||||
if (auto stack = m_controller->tabWidget())
|
||||
if (auto stack = m_frame->tabWidget())
|
||||
return qobject_cast<Stack_qtquick *>(asQQuickItem(stack->view()));
|
||||
|
||||
return nullptr;
|
||||
@@ -227,14 +227,9 @@ QRect Frame_qtquick::dragRect() const
|
||||
return {};
|
||||
}
|
||||
|
||||
bool Frame_qtquick::isMDI() const
|
||||
{
|
||||
return m_controller->isMDI();
|
||||
}
|
||||
|
||||
KDDockWidgets::Views::TitleBar_qtquick *Frame_qtquick::titleBar() const
|
||||
{
|
||||
if (auto tb = m_controller->titleBar()) {
|
||||
if (auto tb = m_frame->titleBar()) {
|
||||
return dynamic_cast<KDDockWidgets::Views::TitleBar_qtquick *>(tb->view());
|
||||
}
|
||||
|
||||
@@ -243,7 +238,7 @@ KDDockWidgets::Views::TitleBar_qtquick *Frame_qtquick::titleBar() const
|
||||
|
||||
KDDockWidgets::Views::TitleBar_qtquick *Frame_qtquick::actualTitleBar() const
|
||||
{
|
||||
if (auto tb = m_controller->actualTitleBar()) {
|
||||
if (auto tb = m_frame->actualTitleBar()) {
|
||||
return dynamic_cast<KDDockWidgets::Views::TitleBar_qtquick *>(tb->view());
|
||||
}
|
||||
|
||||
@@ -265,7 +260,7 @@ bool Frame_qtquick::event(QEvent *e)
|
||||
|
||||
if (e->type() == QEvent::ParentChange) {
|
||||
auto p = parentView();
|
||||
m_controller->setLayout(p ? p->asLayout() : nullptr);
|
||||
m_frame->setLayout(p ? p->asLayout() : nullptr);
|
||||
}
|
||||
|
||||
return View_qtquick::event(e);
|
||||
|
||||
@@ -57,7 +57,6 @@ public:
|
||||
QRect dragRect() const override;
|
||||
|
||||
// QML interface:
|
||||
bool isMDI() const;
|
||||
KDDockWidgets::Views::TitleBar_qtquick *titleBar() const;
|
||||
KDDockWidgets::Views::TitleBar_qtquick *actualTitleBar() const;
|
||||
int userType() const;
|
||||
@@ -95,7 +94,6 @@ private:
|
||||
|
||||
QQuickItem *m_stackLayout = nullptr;
|
||||
QQuickItem *m_visualItem = nullptr;
|
||||
Controllers::Frame *const m_controller;
|
||||
QHash<Controllers::DockWidget *, QMetaObject::Connection> m_connections; // To make it easy to disconnect from lambdas
|
||||
};
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ VBoxLayout::~VBoxLayout() = default;
|
||||
|
||||
Frame_qtwidgets::Frame_qtwidgets(Controllers::Frame *controller, QWidget *parent)
|
||||
: View_qtwidgets<QWidget>(controller, Type::Frame, parent)
|
||||
, m_controller(controller)
|
||||
, FrameViewInterface(controller)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -62,13 +62,13 @@ void Frame_qtwidgets::init()
|
||||
auto vlayout = new VBoxLayout(this);
|
||||
vlayout->setContentsMargins(0, 0, 0, 0);
|
||||
vlayout->setSpacing(0);
|
||||
vlayout->addWidget(asQWidget(m_controller->titleBar()));
|
||||
auto tabWidget = m_controller->tabWidget();
|
||||
vlayout->addWidget(asQWidget(m_controller->tabWidget()));
|
||||
vlayout->addWidget(asQWidget(m_frame->titleBar()));
|
||||
auto tabWidget = m_frame->tabWidget();
|
||||
vlayout->addWidget(asQWidget(m_frame->tabWidget()));
|
||||
|
||||
tabWidget->setTabBarAutoHide(!m_controller->alwaysShowsTabs());
|
||||
tabWidget->setTabBarAutoHide(!m_frame->alwaysShowsTabs());
|
||||
|
||||
if (m_controller->isOverlayed())
|
||||
if (m_frame->isOverlayed())
|
||||
setAutoFillBackground(true);
|
||||
}
|
||||
|
||||
@@ -81,65 +81,60 @@ void Frame_qtwidgets::free_impl()
|
||||
|
||||
void Frame_qtwidgets::renameTab(int index, const QString &text)
|
||||
{
|
||||
m_controller->tabWidget()->renameTab(index, text);
|
||||
m_frame->tabWidget()->renameTab(index, text);
|
||||
}
|
||||
|
||||
void Frame_qtwidgets::changeTabIcon(int index, const QIcon &icon)
|
||||
{
|
||||
m_controller->tabWidget()->changeTabIcon(index, icon);
|
||||
m_frame->tabWidget()->changeTabIcon(index, icon);
|
||||
}
|
||||
|
||||
int Frame_qtwidgets::nonContentsHeight() const
|
||||
{
|
||||
Controllers::TitleBar *tb = m_controller->titleBar();
|
||||
QWidget *tabBar = asQWidget(m_controller->tabBar());
|
||||
Controllers::TitleBar *tb = m_frame->titleBar();
|
||||
QWidget *tabBar = asQWidget(m_frame->tabBar());
|
||||
|
||||
return (tb->isVisible() ? tb->height() : 0) + (tabBar->isVisible() ? tabBar->height() : 0);
|
||||
}
|
||||
|
||||
int Frame_qtwidgets::indexOfDockWidget_impl(const Controllers::DockWidget *dw)
|
||||
{
|
||||
return m_controller->tabWidget()->indexOfDockWidget(dw);
|
||||
return m_frame->tabWidget()->indexOfDockWidget(dw);
|
||||
}
|
||||
|
||||
void Frame_qtwidgets::setCurrentDockWidget_impl(Controllers::DockWidget *dw)
|
||||
{
|
||||
m_controller->tabWidget()->setCurrentDockWidget(dw);
|
||||
m_frame->tabWidget()->setCurrentDockWidget(dw);
|
||||
}
|
||||
|
||||
int Frame_qtwidgets::currentIndex_impl() const
|
||||
{
|
||||
return m_controller->tabWidget()->currentIndex();
|
||||
return m_frame->tabWidget()->currentIndex();
|
||||
}
|
||||
|
||||
void Frame_qtwidgets::insertDockWidget_impl(Controllers::DockWidget *dw, int index)
|
||||
{
|
||||
m_controller->tabWidget()->insertDockWidget(dw, index);
|
||||
m_frame->tabWidget()->insertDockWidget(dw, index);
|
||||
}
|
||||
|
||||
void Frame_qtwidgets::removeWidget_impl(Controllers::DockWidget *dw)
|
||||
{
|
||||
m_controller->tabWidget()->removeDockWidget(dw);
|
||||
m_frame->tabWidget()->removeDockWidget(dw);
|
||||
}
|
||||
|
||||
void Frame_qtwidgets::setCurrentTabIndex_impl(int index)
|
||||
{
|
||||
m_controller->tabWidget()->setCurrentDockWidget(index);
|
||||
m_frame->tabWidget()->setCurrentDockWidget(index);
|
||||
}
|
||||
|
||||
KDDockWidgets::Controllers::DockWidget *Frame_qtwidgets::currentDockWidget_impl() const
|
||||
{
|
||||
return m_controller->tabWidget()->dockwidgetAt(m_controller->tabWidget()->currentIndex());
|
||||
return m_frame->tabWidget()->dockwidgetAt(m_frame->tabWidget()->currentIndex());
|
||||
}
|
||||
|
||||
KDDockWidgets::Controllers::DockWidget *Frame_qtwidgets::dockWidgetAt_impl(int index) const
|
||||
{
|
||||
return m_controller->tabWidget()->dockwidgetAt(index);
|
||||
}
|
||||
|
||||
Controllers::Frame *Frame_qtwidgets::frame() const
|
||||
{
|
||||
return m_controller;
|
||||
return m_frame->tabWidget()->dockwidgetAt(index);
|
||||
}
|
||||
|
||||
bool Frame_qtwidgets::event(QEvent *e)
|
||||
@@ -149,7 +144,7 @@ bool Frame_qtwidgets::event(QEvent *e)
|
||||
|
||||
if (e->type() == QEvent::ParentChange) {
|
||||
auto p = parentView();
|
||||
m_controller->setLayout(p ? p->asLayout() : nullptr);
|
||||
m_frame->setLayout(p ? p->asLayout() : nullptr);
|
||||
}
|
||||
|
||||
return QWidget::event(e);
|
||||
@@ -160,7 +155,7 @@ void Frame_qtwidgets::paintEvent(QPaintEvent *)
|
||||
if (freed())
|
||||
return;
|
||||
|
||||
if (!m_controller->isFloating()) {
|
||||
if (!m_frame->isFloating()) {
|
||||
QPainter p(this);
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
@@ -168,7 +163,7 @@ void Frame_qtwidgets::paintEvent(QPaintEvent *)
|
||||
const qreal halfPenWidth = penWidth / 2;
|
||||
const QRectF rectf = QWidget::rect();
|
||||
|
||||
const bool isOverlayed = m_controller->isOverlayed();
|
||||
const bool isOverlayed = m_frame->isOverlayed();
|
||||
const QColor penColor = isOverlayed ? QColor(0x666666)
|
||||
: QColor(184, 184, 184, 184);
|
||||
QPen pen(penColor);
|
||||
@@ -190,18 +185,18 @@ QSize Frame_qtwidgets::maxSizeHint() const
|
||||
return {};
|
||||
|
||||
// waste due to QTabWidget margins, tabbar etc.
|
||||
const QSize waste = minSize() - m_controller->dockWidgetsMinSize();
|
||||
return waste + m_controller->biggestDockWidgetMaxSize();
|
||||
const QSize waste = minSize() - m_frame->dockWidgetsMinSize();
|
||||
return waste + m_frame->biggestDockWidgetMaxSize();
|
||||
}
|
||||
|
||||
QRect Frame_qtwidgets::dragRect() const
|
||||
{
|
||||
QRect rect = m_controller->dragRect();
|
||||
QRect rect = m_frame->dragRect();
|
||||
if (rect.isValid())
|
||||
return rect;
|
||||
|
||||
if (Config::self().flags() & Config::Flag_HideTitleBarWhenTabsVisible) {
|
||||
auto tabBar = qobject_cast<QTabBar *>(asQWidget(m_controller->tabBar()));
|
||||
auto tabBar = qobject_cast<QTabBar *>(asQWidget(m_frame->tabBar()));
|
||||
rect.setHeight(tabBar->height());
|
||||
rect.setWidth(QWidget::width() - tabBar->width());
|
||||
rect.moveTopLeft(QPoint(tabBar->width(), tabBar->y()));
|
||||
|
||||
@@ -39,7 +39,6 @@ public:
|
||||
Controllers::DockWidget *currentDockWidget_impl() const override;
|
||||
int nonContentsHeight() const override;
|
||||
QRect dragRect() const override;
|
||||
Controllers::Frame *frame() const;
|
||||
|
||||
protected:
|
||||
void free_impl() override;
|
||||
@@ -48,7 +47,6 @@ protected:
|
||||
|
||||
private:
|
||||
bool event(QEvent *) override;
|
||||
Controllers::Frame *const m_controller;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
36
src/views/FrameViewInterface.cpp
Normal file
36
src/views/FrameViewInterface.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
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 "FrameViewInterface.h"
|
||||
#include "controllers/Frame.h"
|
||||
|
||||
namespace KDDockWidgets {
|
||||
|
||||
namespace Views {
|
||||
FrameViewInterface::FrameViewInterface(Controllers::Frame *controller)
|
||||
: m_frame(controller)
|
||||
{
|
||||
}
|
||||
|
||||
FrameViewInterface::~FrameViewInterface() = default;
|
||||
|
||||
bool FrameViewInterface::isMDI() const
|
||||
{
|
||||
return m_frame->isMDI();
|
||||
}
|
||||
|
||||
Controllers::Frame *FrameViewInterface::frame() const
|
||||
{
|
||||
return m_frame;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
@@ -21,6 +21,7 @@ namespace KDDockWidgets {
|
||||
|
||||
namespace Controllers {
|
||||
class DockWidget;
|
||||
class Frame;
|
||||
}
|
||||
|
||||
namespace Views {
|
||||
@@ -29,6 +30,7 @@ namespace Views {
|
||||
class DOCKS_EXPORT FrameViewInterface
|
||||
{
|
||||
public:
|
||||
explicit FrameViewInterface(Controllers::Frame *);
|
||||
virtual ~FrameViewInterface();
|
||||
virtual void renameTab(int index, const QString &) = 0;
|
||||
virtual void changeTabIcon(int index, const QIcon &) = 0;
|
||||
@@ -42,6 +44,12 @@ public:
|
||||
virtual Controllers::DockWidget *currentDockWidget_impl() const = 0;
|
||||
virtual int nonContentsHeight() const = 0;
|
||||
virtual QRect dragRect() const = 0;
|
||||
|
||||
bool isMDI() const;
|
||||
Controllers::Frame *frame() const;
|
||||
|
||||
protected:
|
||||
Controllers::Frame *const m_frame;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user