Skip to content

Commit

Permalink
Merge pull request FreeCAD#15772 from qewer33/master
Browse files Browse the repository at this point in the history
Make start page use QStackedWidget + other fixes
  • Loading branch information
chennes authored Aug 12, 2024
2 parents d7d256e + 000294e commit 38547bf
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 58 deletions.
12 changes: 3 additions & 9 deletions src/Mod/Start/Gui/FirstStartWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ FirstStartWidget::FirstStartWidget(QWidget* parent)
void FirstStartWidget::setupUi()
{
auto outerLayout = gsl::owner<QVBoxLayout*>(new QVBoxLayout(this));
outerLayout->addStretch();
QString application = QString::fromUtf8(App::Application::Config()["ExeName"].c_str());
_welcomeLabel = gsl::owner<QLabel*>(new QLabel);
outerLayout->addWidget(_welcomeLabel);
Expand All @@ -71,23 +72,16 @@ void FirstStartWidget::setupUi()
outerLayout->addWidget(_themeSelectorWidget);

_doneButton = gsl::owner<QPushButton*>(new QPushButton);
connect(_doneButton, &QPushButton::clicked, this, &FirstStartWidget::dismissed);
auto buttonBar = gsl::owner<QHBoxLayout*>(new QHBoxLayout);
buttonBar->addStretch();
buttonBar->addWidget(_doneButton);
outerLayout->addLayout(buttonBar);
outerLayout->addStretch();

connect(_doneButton, &QPushButton::clicked, this, &FirstStartWidget::doneClicked);
retranslateUi();
}

void FirstStartWidget::doneClicked()
{
auto hGrp = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/Mod/Start");
hGrp->SetBool("FirstStart2024", false);
this->hide();
}

bool FirstStartWidget::eventFilter(QObject* object, QEvent* event)
{
if (object == this && event->type() == QEvent::LanguageChange) {
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Start/Gui/FirstStartWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ class FirstStartWidget: public QGroupBox
public:
explicit FirstStartWidget(QWidget* parent = nullptr);
bool eventFilter(QObject* object, QEvent* event) override;
Q_SIGNAL void dismissed();

private:
void retranslateUi();
void setupUi();
void doneClicked();

ThemeSelectorWidget* _themeSelectorWidget;
GeneralSettingsWidget* _generalSettingsWidget;
Expand Down
125 changes: 79 additions & 46 deletions src/Mod/Start/Gui/StartView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <QPushButton>
#include <QScrollArea>
#include <QWidget>
#include <QStackedWidget>
#endif

#include "StartView.h"
Expand Down Expand Up @@ -68,7 +69,7 @@ gsl::owner<QPushButton*> createNewButton(const NewButton& newButton)
{
auto hGrp = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/Mod/Start");
const auto cardSpacing = static_cast<int>(hGrp->GetInt("FileCardSpacing", 20)); // NOLINT
const auto cardSpacing = static_cast<int>(hGrp->GetInt("FileCardSpacing", 25)); // NOLINT
const auto newFileIconSize = static_cast<int>(hGrp->GetInt("NewFileIconSize", 48)); // NOLINT
const auto cardLabelWith = static_cast<int>(hGrp->GetInt("FileCardLabelWith", 180)); // NOLINT

Expand All @@ -82,7 +83,8 @@ gsl::owner<QPushButton*> createNewButton(const NewButton& newButton)

auto textLayout = gsl::owner<QVBoxLayout*>(new QVBoxLayout);
auto textLabelLine1 = gsl::owner<QLabel*>(new QLabel(button));
textLabelLine1->setText(QLatin1String("<b>") + newButton.heading + QLatin1String("</b>"));
textLabelLine1->setText(newButton.heading);
textLabelLine1->setStyleSheet(QLatin1String("font-weight: bold;"));
auto textLabelLine2 = gsl::owner<QLabel*>(new QLabel(button));
textLabelLine2->setText(newButton.description);
textLabelLine2->setWordWrap(true);
Expand All @@ -102,7 +104,7 @@ gsl::owner<QPushButton*> createNewButton(const NewButton& newButton)

StartView::StartView(QWidget* parent)
: Gui::MDIView(nullptr, parent)
, _contents(new QScrollArea(parent))
, _contents(new QStackedWidget(parent))
, _newFileLabel {nullptr}
, _examplesLabel {nullptr}
, _recentFilesLabel {nullptr}
Expand All @@ -111,73 +113,90 @@ StartView::StartView(QWidget* parent)
setObjectName(QLatin1String("StartView"));
auto hGrp = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/Mod/Start");
auto cardSpacing = hGrp->GetInt("FileCardSpacing", 30); // NOLINT

auto scrolledWidget = gsl::owner<QWidget*>(new QWidget(this));
_contents->setWidget(scrolledWidget);
_contents->setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAsNeeded);
_contents->setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAsNeeded);
_contents->setWidgetResizable(true);
auto layout = gsl::owner<QVBoxLayout*>(new QVBoxLayout(scrolledWidget));
layout->setSizeConstraint(QLayout::SizeConstraint::SetMinAndMaxSize);

auto firstStart = hGrp->GetBool("FirstStart2024", true); // NOLINT
if (firstStart) {
auto firstStartRegion = gsl::owner<QHBoxLayout*>(new QHBoxLayout);
firstStartRegion->addStretch();
auto firstStartWidget = gsl::owner<FirstStartWidget*>(new FirstStartWidget(this));
firstStartRegion->addWidget(firstStartWidget);
firstStartRegion->addStretch();
layout->addLayout(firstStartRegion);

// Try to further differentiate the checkbox below, when the First Start box is shown
auto line = new QFrame();
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
layout->addWidget(line);
}

// Launch start automatically?
_showOnStartupCheckBox = gsl::owner<QCheckBox*>(new QCheckBox());
bool showOnStartup = hGrp->GetBool("ShowOnStartup", true);
_showOnStartupCheckBox->setCheckState(showOnStartup ? Qt::CheckState::Unchecked
: Qt::CheckState::Checked);
connect(_showOnStartupCheckBox, &QCheckBox::toggled, this, &StartView::showOnStartupChanged);
layout->addWidget(_showOnStartupCheckBox);
auto cardSpacing = hGrp->GetInt("FileCardSpacing", 15); // NOLINT

// First start page
auto firstStartScrollArea = gsl::owner<QScrollArea*>(new QScrollArea());
auto firstStartRegion = gsl::owner<QHBoxLayout*>(new QHBoxLayout(firstStartScrollArea));
firstStartRegion->addStretch();
auto firstStartWidget = gsl::owner<FirstStartWidget*>(new FirstStartWidget(this));
connect(firstStartWidget,
&FirstStartWidget::dismissed,
this,
&StartView::firstStartWidgetDismissed);
firstStartRegion->addWidget(firstStartWidget);
firstStartRegion->addStretch();
_contents->addWidget(firstStartScrollArea);

// Documents page
auto documentsWidget = gsl::owner<QWidget*>(new QWidget());
_contents->addWidget(documentsWidget);
auto documentsMainLayout = gsl::owner<QVBoxLayout*>(new QVBoxLayout());
documentsWidget->setLayout(documentsMainLayout);
auto documentsScrollArea = gsl::owner<QScrollArea*>(new QScrollArea());
documentsScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAsNeeded);
documentsMainLayout->addWidget(documentsScrollArea);
auto documentsScrollWidget = gsl::owner<QWidget*>(new QWidget(documentsScrollArea));
documentsScrollArea->setWidget(documentsScrollWidget);
documentsScrollArea->setWidgetResizable(true);
auto documentsContentLayout = gsl::owner<QVBoxLayout*>(new QVBoxLayout(documentsScrollWidget));
documentsContentLayout->setSizeConstraint(QLayout::SizeConstraint::SetMinAndMaxSize);

_newFileLabel = gsl::owner<QLabel*>(new QLabel());
layout->addWidget(_newFileLabel);
documentsContentLayout->addWidget(_newFileLabel);

auto createNewRow = gsl::owner<QWidget*>(new QWidget);
auto flowLayout = gsl::owner<FlowLayout*>(new FlowLayout);

// reset margins of layout to provide consistent spacing
// Reset margins of layout to provide consistent spacing
flowLayout->setContentsMargins({});

// this allows new file widgets to be targeted via QSS
// This allows new file widgets to be targeted via QSS
createNewRow->setObjectName(QStringLiteral("CreateNewRow"));
createNewRow->setLayout(flowLayout);

layout->addWidget(createNewRow);
documentsContentLayout->addWidget(createNewRow);
configureNewFileButtons(flowLayout);

_recentFilesLabel = gsl::owner<QLabel*>(new QLabel());
layout->addWidget(_recentFilesLabel);
documentsContentLayout->addWidget(_recentFilesLabel);
auto recentFilesListWidget = gsl::owner<FileCardView*>(new FileCardView(_contents));
connect(recentFilesListWidget, &QListView::clicked, this, &StartView::fileCardSelected);
layout->addWidget(recentFilesListWidget);
documentsContentLayout->addWidget(recentFilesListWidget);

_examplesLabel = gsl::owner<QLabel*>(new QLabel());
layout->addWidget(_examplesLabel);
documentsContentLayout->addWidget(_examplesLabel);
auto examplesListWidget = gsl::owner<FileCardView*>(new FileCardView(_contents));
connect(examplesListWidget, &QListView::clicked, this, &StartView::fileCardSelected);
layout->addWidget(examplesListWidget);
documentsContentLayout->addWidget(examplesListWidget);

documentsContentLayout->setSpacing(static_cast<int>(cardSpacing));
documentsContentLayout->addStretch();

// Documents page footer
auto footerLayout = gsl::owner<QHBoxLayout*>(new QHBoxLayout());
documentsMainLayout->addLayout(footerLayout);

layout->setSpacing(static_cast<int>(cardSpacing));
layout->addStretch();
_openFirstStart = gsl::owner<QPushButton*>(new QPushButton());
_openFirstStart->setIcon(QIcon(QLatin1String(":/icons/preferences-general.svg")));
connect(_openFirstStart, &QPushButton::clicked, this, &StartView::openFirstStartClicked);

_showOnStartupCheckBox = gsl::owner<QCheckBox*>(new QCheckBox());
bool showOnStartup = hGrp->GetBool("ShowOnStartup", true);
_showOnStartupCheckBox->setCheckState(showOnStartup ? Qt::CheckState::Unchecked
: Qt::CheckState::Checked);
connect(_showOnStartupCheckBox, &QCheckBox::toggled, this, &StartView::showOnStartupChanged);

footerLayout->addWidget(_openFirstStart);
footerLayout->addStretch();
footerLayout->addWidget(_showOnStartupCheckBox);

setCentralWidget(_contents);

// Set startup widget according to the first start parameter
auto firstStart = hGrp->GetBool("FirstStart2024", true); // NOLINT
_contents->setCurrentWidget(firstStart ? firstStartScrollArea : documentsWidget);

configureExamplesListWidget(examplesListWidget);
configureRecentFilesListWidget(recentFilesListWidget, _recentFilesLabel);

Expand Down Expand Up @@ -428,6 +447,19 @@ void StartView::showOnStartupChanged(bool checked)
// original sense, so is stored inverted.
}

void StartView::openFirstStartClicked()
{
_contents->setCurrentIndex(0);
}

void StartView::firstStartWidgetDismissed()
{
auto hGrp = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/Mod/Start");
hGrp->SetBool("FirstStart2024", false);
_contents->setCurrentIndex(1);
}

void StartView::changeEvent(QEvent* event)
{
if (event->type() == QEvent::LanguageChange) {
Expand All @@ -449,6 +481,7 @@ void StartView::retranslateUi()
_recentFilesLabel->setText(h1Start + tr("Recent Files") + h1End);

QString application = QString::fromUtf8(App::Application::Config()["ExeName"].c_str());
_openFirstStart->setText(tr("Open first start setup"));
_showOnStartupCheckBox->setText(
tr("Don't show this Start page again (start with blank screen)"));
}
9 changes: 7 additions & 2 deletions src/Mod/Start/Gui/StartView.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class QGridLayout;
class QLabel;
class QListView;
class QScrollArea;
class QStackedWidget;
class QPushButton;

namespace Gui
{
Expand Down Expand Up @@ -86,20 +88,23 @@ class StartGuiExport StartView: public Gui::MDIView
void postStart(PostStartBehavior behavior) const;

void fileCardSelected(const QModelIndex& index);

void showOnStartupChanged(bool checked);
void openFirstStartClicked();
void firstStartWidgetDismissed();

QString fileCardStyle() const;

private:
void retranslateUi();

QScrollArea* _contents = nullptr;
QStackedWidget* _contents = nullptr;
Start::RecentFilesModel _recentFilesModel;
Start::ExamplesModel _examplesModel;

QLabel* _newFileLabel;
QLabel* _examplesLabel;
QLabel* _recentFilesLabel;
QPushButton* _openFirstStart;
QCheckBox* _showOnStartupCheckBox;


Expand Down

0 comments on commit 38547bf

Please sign in to comment.