toolbar: force minimum width

Improves usability on screens with less height
This commit is contained in:
itsmattkc
2021-08-24 10:00:51 -07:00
parent 2794730afa
commit 4d0d38aca2
2 changed files with 19 additions and 4 deletions
+17 -4
View File
@@ -20,10 +20,11 @@
#include "toolbar.h"
#include <QPushButton>
#include <QVariant>
#include <QButtonGroup>
#include <QEvent>
#include <QPushButton>
#include <QResizeEvent>
#include <QVariant>
#include "node/factory.h"
#include "ui/icons/icons.h"
@@ -31,8 +32,10 @@
namespace olive {
#define super QWidget
Toolbar::Toolbar(QWidget *parent) :
QWidget(parent)
super(parent)
{
layout_ = new FlowLayout(this);
layout_->setMargin(0);
@@ -88,7 +91,17 @@ void Toolbar::changeEvent(QEvent *e)
} else if (e->type() == QEvent::StyleChange) {
UpdateIcons();
}
QWidget::changeEvent(e);
super::changeEvent(e);
}
void Toolbar::resizeEvent(QResizeEvent *e)
{
super::resizeEvent(e);
int min_height = toolbar_btns_.size() * toolbar_btns_.first()->height() + (toolbar_btns_.size()-1) * layout_->verticalSpacing();
int new_height = e->size().height();
int columns_required = min_height / new_height + (min_height % new_height != 0);
setMinimumWidth(toolbar_btns_.first()->width() * columns_required + layout_->horizontalSpacing() * (columns_required-1) + 1);
}
void Toolbar::Retranslate()
+2
View File
@@ -89,6 +89,8 @@ protected:
*/
virtual void changeEvent(QEvent* e) override;
virtual void resizeEvent(QResizeEvent *e) override;
signals:
/**
* @brief Emitted whenever a tool is selected using this widget