Skip to content
Snippets Groups Projects
Commit 6dbd7256 authored by m.puchner's avatar m.puchner
Browse files

Merge branch 'WelcomeView2' into 'develop'

small UI refactor

See merge request !288
parents eef1d42c 91c050b1
No related branches found
No related tags found
1 merge request!288small UI refactor
Pipeline #43969 passed
...@@ -14,10 +14,9 @@ ...@@ -14,10 +14,9 @@
#include "GroupBoxCollapser.h" #include "GroupBoxCollapser.h"
#include <QBoxLayout> #include <QBoxLayout>
#include <QEvent>
#include <QGroupBox> #include <QGroupBox>
#include <QPropertyAnimation>
#include <QToolButton> #include <QToolButton>
#include <QVariant>
void GroupBoxCollapser::installIntoGroupBox(QGroupBox* groupBox, bool expanded) void GroupBoxCollapser::installIntoGroupBox(QGroupBox* groupBox, bool expanded)
{ {
...@@ -27,28 +26,11 @@ void GroupBoxCollapser::installIntoGroupBox(QGroupBox* groupBox, bool expanded) ...@@ -27,28 +26,11 @@ void GroupBoxCollapser::installIntoGroupBox(QGroupBox* groupBox, bool expanded)
QSignalBlocker b(p->m_toggleButton); QSignalBlocker b(p->m_toggleButton);
p->m_toggleButton->setChecked(false); p->m_toggleButton->setChecked(false);
p->m_toggleButton->setArrowType(Qt::ArrowType::RightArrow); p->m_toggleButton->setArrowType(Qt::ArrowType::RightArrow);
// this is necessary if contained widgets are resized while collapsed (tableView). It
// increases the layout, and therefore the title gets "compressed"
p->m_contentArea->hide(); p->m_contentArea->hide();
// groupBox->setFixedHeight(p->m_collapsedHeight);
} }
groupBox->installEventFilter(p);
}
bool GroupBoxCollapser::eventFilter(QObject* obj, QEvent* event)
{
if (event->type() == QEvent::StyleChange) {
initSizes();
initAnimation();
const bool isExpanded = m_toggleButton->isChecked();
m_groupBox->setFixedHeight(isExpanded ? m_expandedHeight : m_collapsedHeight);
}
return false;
} }
GroupBoxCollapser::GroupBoxCollapser(QGroupBox* groupBox) : QObject(groupBox), m_groupBox(groupBox) GroupBoxCollapser::GroupBoxCollapser(QGroupBox* groupBox) : QObject(groupBox)
{ {
QVBoxLayout* mainLayout = new QVBoxLayout; QVBoxLayout* mainLayout = new QVBoxLayout;
mainLayout->setSpacing(0); mainLayout->setSpacing(0);
...@@ -56,7 +38,6 @@ GroupBoxCollapser::GroupBoxCollapser(QGroupBox* groupBox) : QObject(groupBox), m ...@@ -56,7 +38,6 @@ GroupBoxCollapser::GroupBoxCollapser(QGroupBox* groupBox) : QObject(groupBox), m
m_contentArea = new QWidget(groupBox); m_contentArea = new QWidget(groupBox);
m_contentArea->setLayout(groupBox->layout()); m_contentArea->setLayout(groupBox->layout());
m_contentArea->layout()->setSizeConstraint(QLayout::SetMinimumSize);
mainLayout->addWidget(m_contentArea); mainLayout->addWidget(m_contentArea);
groupBox->setLayout(mainLayout); groupBox->setLayout(mainLayout);
...@@ -73,62 +54,17 @@ GroupBoxCollapser::GroupBoxCollapser(QGroupBox* groupBox) : QObject(groupBox), m ...@@ -73,62 +54,17 @@ GroupBoxCollapser::GroupBoxCollapser(QGroupBox* groupBox) : QObject(groupBox), m
groupBox->layout()->setMenuBar(m_toggleButton); groupBox->layout()->setMenuBar(m_toggleButton);
groupBox->setTitle(""); groupBox->setTitle("");
groupBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); groupBox->setProperty("collapsible", true); // helps to distinguish GroupBoxes in stylesheets
groupBox->setProperty("collapsible", true);
initSizes();
initAnimation();
connect(m_toggleButton, &QAbstractButton::clicked, this, &GroupBoxCollapser::toggle); connect(m_toggleButton, &QAbstractButton::clicked, this, &GroupBoxCollapser::toggle);
connect(&m_toggleAnimation, &QAbstractAnimation::finished, this,
&GroupBoxCollapser::onAnimationFinished);
} }
void GroupBoxCollapser::toggle(bool checked) void GroupBoxCollapser::toggle(bool checked)
{ {
m_toggleButton->setArrowType(checked ? Qt::ArrowType::DownArrow : Qt::ArrowType::RightArrow); m_toggleButton->setArrowType(checked ? Qt::ArrowType::DownArrow : Qt::ArrowType::RightArrow);
m_toggleAnimation.setDirection(checked ? QAbstractAnimation::Forward
: QAbstractAnimation::Backward);
if (m_toggleButton->isChecked()) if (m_toggleButton->isChecked())
m_contentArea->show(); m_contentArea->show();
else
m_toggleAnimation.start();
}
void GroupBoxCollapser::onAnimationFinished()
{
if (!m_toggleButton->isChecked())
m_contentArea->hide(); m_contentArea->hide();
} }
void GroupBoxCollapser::initAnimation()
{
m_toggleAnimation.clear();
// Add animations, to let the entire widget grow and shrink with its content
const auto addAnimation = [=](QObject* target, const QByteArray propertyName, int start,
int end) {
auto a = new QPropertyAnimation(target, propertyName);
a->setDuration(m_animationDuration);
a->setStartValue(start);
a->setEndValue(end);
m_toggleAnimation.addAnimation(a);
};
addAnimation(m_groupBox, "minimumHeight", m_collapsedHeight, m_expandedHeight);
addAnimation(m_groupBox, "maximumHeight", m_collapsedHeight, m_expandedHeight);
addAnimation(m_contentArea, "minimumHeight", 0, m_contentHeight);
addAnimation(m_contentArea, "maximumHeight", 0, m_contentHeight);
m_groupBox->setUpdatesEnabled(true);
}
void GroupBoxCollapser::initSizes()
{
m_contentHeight = m_contentArea->layout()->sizeHint().height();
m_collapsedHeight =
m_groupBox->sizeHint().height() - m_contentHeight
+ 1; // this is very likely necessary because of pressed state of toggle button?!
m_expandedHeight = m_collapsedHeight + m_contentHeight;
}
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#ifndef BORNAGAIN_GUI_VIEWS_COMMONWIDGETS_GROUPBOXCOLLAPSER_H #ifndef BORNAGAIN_GUI_VIEWS_COMMONWIDGETS_GROUPBOXCOLLAPSER_H
#define BORNAGAIN_GUI_VIEWS_COMMONWIDGETS_GROUPBOXCOLLAPSER_H #define BORNAGAIN_GUI_VIEWS_COMMONWIDGETS_GROUPBOXCOLLAPSER_H
#include <QParallelAnimationGroup> #include <QObject>
class QToolButton; class QToolButton;
class QGroupBox; class QGroupBox;
...@@ -25,24 +25,12 @@ class GroupBoxCollapser : public QObject { ...@@ -25,24 +25,12 @@ class GroupBoxCollapser : public QObject {
public: public:
static void installIntoGroupBox(QGroupBox* groupBox, bool expanded = true); static void installIntoGroupBox(QGroupBox* groupBox, bool expanded = true);
protected:
bool eventFilter(QObject* obj, QEvent* event) override;
private: private:
GroupBoxCollapser(QGroupBox* groupBox); GroupBoxCollapser(QGroupBox* groupBox);
void toggle(bool checked); void toggle(bool checked);
void onAnimationFinished();
void initAnimation();
void initSizes();
QToolButton* m_toggleButton; QToolButton* m_toggleButton;
QParallelAnimationGroup m_toggleAnimation;
QWidget* m_contentArea; QWidget* m_contentArea;
QGroupBox* m_groupBox;
int m_collapsedHeight;
int m_expandedHeight;
int m_contentHeight;
const int m_animationDuration{200};
}; };
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
// ************************************************************************************************ // ************************************************************************************************
#include "GUI/Views/WelcomeView.h" #include "GUI/Views/WelcomeView.h"
#include "GUI/Views/CommonWidgets/GroupBoxCollapser.h"
#include "GUI/Views/CommonWidgets/StyleUtils.h" #include "GUI/Views/CommonWidgets/StyleUtils.h"
#include "GUI/mainwindow/mainwindow.h" #include "GUI/mainwindow/mainwindow.h"
#include "GUI/mainwindow/projectdocument.h" #include "GUI/mainwindow/projectdocument.h"
...@@ -31,17 +32,16 @@ using namespace GUI::Utils; ...@@ -31,17 +32,16 @@ using namespace GUI::Utils;
WelcomeView::WelcomeView(MainWindow* parent) : m_mainWindow(parent), m_ui(new Ui::WelcomeView) WelcomeView::WelcomeView(MainWindow* parent) : m_mainWindow(parent), m_ui(new Ui::WelcomeView)
{ {
m_ui->setupUi(this); m_ui->setupUi(this);
m_ui->currentProjectLabel->setFont(Style::sectionFont(true));
m_ui->recentProjectsLabel->setFont(Style::sectionFont(true)); setAttribute(Qt::WA_StyledBackground, true);
GroupBoxCollapser::installIntoGroupBox(m_ui->groupBox_2);
GroupBoxCollapser::installIntoGroupBox(m_ui->groupBox);
QPalette palette = this->palette(); QPalette palette = this->palette();
palette.setColor(QPalette::Window, Qt::white); palette.setColor(QPalette::Window, Qt::white);
setPalette(palette); setPalette(palette);
palette = m_ui->currentProjectWidget->palette();
palette.setColor(QPalette::Window, QColor(243, 243, 243));
m_ui->currentProjectWidget->setPalette(palette);
connect(m_ui->newButton, &QPushButton::clicked, projectManager(), &ProjectManager::newProject); connect(m_ui->newButton, &QPushButton::clicked, projectManager(), &ProjectManager::newProject);
connect(m_ui->openButton, &QPushButton::clicked, [=]() { projectManager()->openProject(); }); connect(m_ui->openButton, &QPushButton::clicked, [=]() { projectManager()->openProject(); });
connect(m_ui->websiteButton, &QPushButton::clicked, connect(m_ui->websiteButton, &QPushButton::clicked,
......
...@@ -25,7 +25,7 @@ class WelcomeView; ...@@ -25,7 +25,7 @@ class WelcomeView;
} }
class WelcomeView : public QWidget { class WelcomeView : public QWidget {
Q_OBJECT
public: public:
WelcomeView(MainWindow* parent); WelcomeView(MainWindow* parent);
......
...@@ -21,30 +21,23 @@ ...@@ -21,30 +21,23 @@
<number>6</number> <number>6</number>
</property> </property>
<property name="leftMargin"> <property name="leftMargin">
<number>40</number> <number>9</number>
</property> </property>
<property name="topMargin"> <property name="topMargin">
<number>10</number> <number>9</number>
</property> </property>
<property name="rightMargin"> <property name="rightMargin">
<number>15</number> <number>9</number>
</property> </property>
<property name="bottomMargin"> <property name="bottomMargin">
<number>30</number> <number>9</number>
</property> </property>
<item> <item>
<widget class="QWidget" name="currentProjectWidget" native="true"> <widget class="QGroupBox" name="groupBox">
<property name="autoFillBackground"> <property name="title">
<bool>true</bool> <string>Current project</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_6"> <layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QLabel" name="currentProjectLabel">
<property name="text">
<string>Current project:</string>
</property>
</widget>
</item>
<item> <item>
<layout class="QFormLayout" name="formLayout"> <layout class="QFormLayout" name="formLayout">
<property name="labelAlignment"> <property name="labelAlignment">
...@@ -224,43 +217,54 @@ ...@@ -224,43 +217,54 @@
<number>7</number> <number>7</number>
</property> </property>
<item> <item>
<widget class="QLabel" name="recentProjectsLabel"> <widget class="QGroupBox" name="groupBox_2">
<property name="text"> <property name="title">
<string>Recent projects:</string> <string>Recent projects</string>
</property>
</widget>
</item>
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property> </property>
<property name="widgetResizable"> <layout class="QVBoxLayout" name="verticalLayout_6">
<bool>true</bool> <item>
</property> <widget class="QScrollArea" name="scrollArea">
<widget class="QWidget" name="scrollAreaWidgetContents"> <property name="frameShape">
<property name="geometry"> <enum>QFrame::NoFrame</enum>
<rect> </property>
<x>0</x> <property name="horizontalScrollBarPolicy">
<y>0</y> <enum>Qt::ScrollBarAlwaysOff</enum>
<width>800</width> </property>
<height>752</height> <property name="widgetResizable">
</rect> <bool>true</bool>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_3"> <widget class="QWidget" name="scrollAreaWidgetContents">
<property name="leftMargin"> <property name="geometry">
<number>0</number> <rect>
</property> <x>0</x>
<item> <y>0</y>
<widget class="QWidget" name="widget" native="true"> <width>817</width>
<layout class="QVBoxLayout" name="recentProjectsLayout"/> <height>765</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QWidget" name="widgetForRecentProjects" native="true">
<layout class="QVBoxLayout" name="recentProjectsLayout"/>
</widget>
</item>
</layout>
</widget> </widget>
</item> </widget>
</layout> </item>
</widget> </layout>
</widget> </widget>
</item> </item>
</layout> </layout>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment