Compare commits

...

3 Commits

Author SHA1 Message Date
Sergio Martins
def85228d0 Update overlay geometries when central widget changes size
We were only updating the overlays when the main window changed
size, but it can happen that only the central widget changes size,
for example when you remove or add a toolbar

Fixes #227
2021-08-22 22:24:10 +01:00
Sergio Martins
a1578c92ab Added signal MainWindowBase::centralWidgetResized() 2021-08-22 22:18:14 +01:00
Sergio Martins
8fe0bcf1b3 Minor refactoring, move some logic into a reusable function 2021-08-22 22:09:25 +01:00
4 changed files with 29 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
* v1.4.1 (unreleased)
-
- Fixed overlayed dock widgets being misplaced when removing a toolbar (#227)
* v1.4.0 (16 July 2021)
- No longer supports Qt versions less than 5.12

View File

@@ -39,6 +39,7 @@ using namespace KDDockWidgets;
namespace KDDockWidgets {
class MyCentralWidget : public QWidget
{
Q_OBJECT
public:
explicit MyCentralWidget(QWidget *parent = nullptr)
: QWidget(parent)
@@ -47,6 +48,14 @@ public:
}
~MyCentralWidget() override;
void resizeEvent(QResizeEvent *ev) override
{
QWidget::resizeEvent(ev);
Q_EMIT resized(ev->oldSize(), ev->size());
}
Q_SIGNALS:
void resized(QSize oldSize, QSize newSize);
};
}
@@ -114,6 +123,8 @@ MainWindow::MainWindow(const QString &name, MainWindowOptions options,
d->updateMargins(); // logical dpi might have changed
Q_EMIT DockRegistry::self()->windowChangedScreen(windowHandle());
});
connect(d->m_centralWidget, &MyCentralWidget::resized, this, &MainWindowBase::centralWidgetResized);
}
MainWindow::~MainWindow()
@@ -147,3 +158,5 @@ QRect MainWindow::centralAreaGeometry() const
{
return centralWidget()->geometry();
}
#include "MainWindow.moc"

View File

@@ -56,6 +56,13 @@ public:
return m_options & MainWindowOption_HasCentralFrame;
}
void updateOverlayedDockWidgetGeometries()
{
if (m_overlayedDockWidget)
updateOverlayGeometry(m_overlayedDockWidget->d->frame()->QWidgetAdapter::size());
}
CursorPositions allowedResizeSides(SideBarLocation loc) const;
QRect rectForOverlay(Frame *, SideBarLocation) const;
@@ -80,6 +87,10 @@ MainWindowBase::MainWindowBase(const QString &uniqueName, KDDockWidgets::MainWin
connect(d->m_layoutWidget, &LayoutWidget::visibleWidgetCountChanged, this,
&MainWindowBase::frameCountChanged);
connect(this, &MainWindowBase::centralWidgetResized, this, [this] {
d->updateOverlayedDockWidgetGeometries();
});
}
MainWindowBase::~MainWindowBase()
@@ -636,8 +647,7 @@ void MainWindowBase::setUniqueName(const QString &uniqueName)
void MainWindowBase::onResized(QResizeEvent *)
{
if (d->m_overlayedDockWidget)
d->updateOverlayGeometry(d->m_overlayedDockWidget->d->frame()->QWidgetAdapter::size());
d->updateOverlayedDockWidgetGeometries();
}
bool MainWindowBase::deserialize(const LayoutSaver::MainWindow &mw)

View File

@@ -225,6 +225,9 @@ Q_SIGNALS:
/// can be tabbed together, in which case this signal isn't emitted.
void frameCountChanged(int);
/// @brief emitted when the MainWindow::centralWidget() changes size
void centralWidgetResized(QSize oldSize, QSize newSize);
private:
class Private;
Private *const d;