Improve position for north/south overlays

This commit is contained in:
Sergio Martins
2020-09-20 16:56:57 +01:00
parent af5e11a265
commit b303af738c
4 changed files with 15 additions and 9 deletions

View File

@@ -81,7 +81,7 @@ MainWindow::MainWindow(const QString &name, MainWindowOptions options,
auto centralWidget = new MyCentralWidget(this);
auto layout = new QHBoxLayout(centralWidget); // 1 level of indirection so we can add some margins
layout->setSpacing(0);
layout->setContentsMargins(1, 5, 1, 1);
layout->setContentsMargins(centerWidgetMargins());
if (d->m_supportsAutoHide) {
layout->addWidget(sideBar(SideBarLocation::West));
@@ -122,3 +122,8 @@ void MainWindow::resizeEvent(QResizeEvent *ev)
MainWindowBase::resizeEvent(ev);
onResized(ev); // Also call our own handler, since QtQuick doesn't have resizeEvent()
}
QMargins MainWindow::centerWidgetMargins() const
{
return { 1, 5, 1, 1};
}

View File

@@ -52,7 +52,7 @@ public:
protected:
void resizeEvent(QResizeEvent *) override;
QMargins centerWidgetMargins() const override;
private:
using QMainWindow::setCentralWidget;
void setCentralWidget(QWidget *); // overridden just to make it private

View File

@@ -163,8 +163,8 @@ QRect MainWindowBase::Private::rectForOverlay(Frame *frame, SideBarLocation loca
if (!sb)
return {};
DropArea *da = q->dropArea();
const QPoint dropAreaPos = da->mapTo(q, QPoint(0,0));
const QWidget *centralWidget = q->centralWidget();
//const QPoint dropAreaPos = da->mapTo(q, QPoint(0,0));
QRect rect;
switch (location) {
@@ -173,11 +173,11 @@ QRect MainWindowBase::Private::rectForOverlay(Frame *frame, SideBarLocation loca
const int margin = 1;
rect.setHeight(qMax(200, frame->minSize().height()));
rect.setWidth(q->width() - margin * 2);
rect.moveLeft(margin * 2);
rect.moveLeft(margin);
if (location == SideBarLocation::South) {
rect.moveTop(q->height() - rect.height() - sb->height());
rect.moveTop(centralWidget->geometry().bottom() - q->centerWidgetMargins().bottom() - rect.height() - sb->height());
} else {
rect.moveTop(dropAreaPos.y() + sb->height());
rect.moveTop(centralWidget->y() + sb->height() + q->centerWidgetMargins().top());
}
break;
}
@@ -189,7 +189,7 @@ QRect MainWindowBase::Private::rectForOverlay(Frame *frame, SideBarLocation loca
if (location == SideBarLocation::South) {
rect.moveLeft(q->width() - rect.width() - sb->width());
} else {
rect.moveLeft(dropAreaPos.x() + sb->width());
rect.moveLeft(centralWidget->x() + sb->width());
}
break;
@@ -290,7 +290,6 @@ void MainWindowBase::overlayOnSideBar(DockWidgetBase *dw)
d->m_overlayedDockWidget = dw;
frame->addWidget(dw);
d->updateOverlayGeometry();
frame->QWidgetAdapter::setGeometry(d->rectForOverlay(frame, sb->location()));
frame->QWidgetAdapter::show();
Q_EMIT dw->isOverlayedChanged(true);

View File

@@ -26,6 +26,7 @@
#include "LayoutSaver_p.h"
#include <QVector>
#include <QMargins>
namespace KDDockWidgets {
@@ -165,6 +166,7 @@ public:
protected:
void setUniqueName(const QString &uniqueName);
void onResized(QResizeEvent *); // Because QtQuick doesn't have resizeEvent()
virtual QMargins centerWidgetMargins() const = 0;
virtual SideBar* sideBar(SideBarLocation) const = 0;