Skip to content

Commit

Permalink
Merge pull request #23 from J5lx/MrStevns/compact-dock-layout
Browse files Browse the repository at this point in the history
Consolidate BaseDockWidget/Toolbox minimum size handling
  • Loading branch information
MrStevns authored Aug 4, 2024
2 parents ed25a46 + 80aedf8 commit f5601d5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 51 deletions.
25 changes: 0 additions & 25 deletions app/src/basedockwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,3 @@ BaseDockWidget::BaseDockWidget(QWidget* pParent)
BaseDockWidget::~BaseDockWidget()
{
}

void BaseDockWidget::resizeEvent(QResizeEvent *event)
{
QDockWidget::resizeEvent(event);

// Not sure where the -2 comes from, but the event width is always 2 more than what is passed to FlowLayout::setGeometry
int minHeight = getMinHeightForWidth(event->size().width() - 2);

if (minHeight < 0) return;

#ifdef __APPLE__
// For some reason the behavior of minimumSize and the margin changes on mac when floating, so we need to do this
#else
int top, bottom;
layout()->getContentsMargins(nullptr, &top, nullptr, &bottom);
minHeight += top + bottom;
#endif
setMinimumSize(QSize(layout()->minimumSize().width(), minHeight));
}

int BaseDockWidget::getMinHeightForWidth(int width)
{
Q_UNUSED(width)
return -1;
}
5 changes: 0 additions & 5 deletions app/src/basedockwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,13 @@ class BaseDockWidget : public QDockWidget
explicit BaseDockWidget(QWidget* pParent);
virtual ~BaseDockWidget();

void resizeEvent(QResizeEvent *event) override;

public:
virtual void initUI() = 0;
virtual void updateUI() = 0;

Editor* editor() const { return mEditor; }
void setEditor( Editor* e ) { mEditor = e; }

protected:
virtual int getMinHeightForWidth(int width);

private:
Editor* mEditor = nullptr;
};
Expand Down
27 changes: 9 additions & 18 deletions app/src/toolbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,13 @@ void ToolBoxWidget::initUI()
connect(editor()->layers(), &LayerManager::currentLayerChanged, this, &ToolBoxWidget::onLayerDidChange);

connect(this, &QDockWidget::dockLocationChanged, this, [=](Qt::DockWidgetArea area) {

mDockArea = area;
if (area == Qt::DockWidgetArea::TopDockWidgetArea || area == Qt::BottomDockWidgetArea) {
ui->scrollArea->setMinimumHeight(getMinHeightForWidth(width()));
const int minimumHeight = ui->scrollAreaWidgetContents_2->layout()->heightForWidth(width());
ui->scrollArea->setMinimumHeight(minimumHeight);
setMinimumHeight(minimumHeight);
} else {
ui->scrollArea->setMinimumHeight(1);
ui->scrollArea->setMinimumHeight(0); // Default value
// Don't set own minimum height and let Qt come up with a sensible value
}
});

Expand All @@ -165,8 +166,6 @@ void ToolBoxWidget::initUI()
ui->scrollAreaWidgetContents_2->setLayout(flowlayout);
ui->scrollAreaWidgetContents_2->setContentsMargins(0,0,0,0);

setMinimumHeight(1);

QSettings settings(PENCIL2D, PENCIL2D);
restoreGeometry(settings.value("ToolBoxGeom").toByteArray());
}
Expand All @@ -177,19 +176,11 @@ void ToolBoxWidget::updateUI()

void ToolBoxWidget::resizeEvent(QResizeEvent* event)
{
BaseDockWidget::resizeEvent(event);
QDockWidget::resizeEvent(event);

if (ui->scrollArea->minimumHeight() <= 0) { return; }

setMinimumSize(QSize(layout()->minimumSize().width(), ui->scrollArea->minimumHeight()));
}

int ToolBoxWidget::getMinHeightForWidth(int width)
{
if (mDockArea != Qt::LeftDockWidgetArea && mDockArea != Qt::RightDockWidgetArea) {
return ui->scrollAreaWidgetContents_2->layout()->heightForWidth(width);
}
return 1;
const int minimumHeight = ui->scrollArea->minimumHeight();
if (minimumHeight <= 0) { return; }
setMinimumHeight(minimumHeight);
}

void ToolBoxWidget::onToolSetActive(ToolType toolType)
Expand Down
3 changes: 0 additions & 3 deletions app/src/toolbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,13 @@ public slots:
void smudgeOn();

protected:
int getMinHeightForWidth(int width) override;
void resizeEvent(QResizeEvent* event) override;

private:
void deselectAllTools();
void toolOn(ToolType toolType, QToolButton* toolButton);

Ui::ToolBoxWidget* ui = nullptr;

Qt::DockWidgetArea mDockArea = Qt::DockWidgetArea::LeftDockWidgetArea;
};

#endif

0 comments on commit f5601d5

Please sign in to comment.