Skip to content

Commit

Permalink
Restyle wizard
Browse files Browse the repository at this point in the history
Signed-off-by: Felix Weilbach <[email protected]>
  • Loading branch information
Felix Weilbach committed Feb 22, 2021
1 parent 66fd5f9 commit a13dfe6
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 13 deletions.
3 changes: 0 additions & 3 deletions src/gui/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,6 @@ Application::Application(int &argc, char **argv)
FolderMan::instance()->setupFolders();
_proxy.setupQtProxyFromConfig(); // folders have to be defined first, than we set up the Qt proxy.

// Enable word wrapping of QInputDialog (#4197)
setStyleSheet("QInputDialog QLabel { qproperty-wordWrap:1; }");

connect(AccountManager::instance(), &AccountManager::accountAdded,
this, &Application::slotAccountStateAdded);
connect(AccountManager::instance(), &AccountManager::accountRemoved,
Expand Down
91 changes: 81 additions & 10 deletions src/gui/wizard/owncloudwizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ Q_LOGGING_CATEGORY(lcWizard, "nextcloud.gui.wizard", QtInfoMsg)
OwncloudWizard::OwncloudWizard(QWidget *parent)
: QWizard(parent)
, _account(nullptr)
#ifdef WITH_PROVIDERS
, _welcomePage(new WelcomePage(this))
#endif // WITH_PROVIDERS
, _setupPage(new OwncloudSetupPage(this))
, _httpCredsPage(new OwncloudHttpCredsPage(this))
, _browserCredsPage(new OwncloudOAuthCredsPage)
Expand All @@ -61,9 +59,7 @@ OwncloudWizard::OwncloudWizard(QWidget *parent)
setObjectName("owncloudWizard");

setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
#ifdef WITH_PROVIDERS
setPage(WizardCommon::Page_Welcome, _welcomePage);
#endif // WITH_PROVIDERS
setPage(WizardCommon::Page_ServerSetup, _setupPage);
setPage(WizardCommon::Page_HttpCreds, _httpCredsPage);
setPage(WizardCommon::Page_OAuthCreds, _browserCredsPage);
Expand All @@ -76,7 +72,6 @@ OwncloudWizard::OwncloudWizard(QWidget *parent)

// note: start Id is set by the calling class depending on if the
// welcome text is to be shown or not.
setWizardStyle(QWizard::ModernStyle);

connect(this, &QWizard::currentIdChanged, this, &OwncloudWizard::slotCurrentPageChanged);
connect(_setupPage, &OwncloudSetupPage::determineAuthType, this, &OwncloudWizard::determineAuthType);
Expand All @@ -90,15 +85,11 @@ OwncloudWizard::OwncloudWizard(QWidget *parent)


Theme *theme = Theme::instance();
setWindowTitle(tr("%1 Connection Wizard").arg(theme->appNameGUI()));
setWindowTitle(tr("Add %1 account").arg(theme->appNameGUI()));
setWizardStyle(QWizard::ModernStyle);
setPixmap(QWizard::BannerPixmap, theme->wizardHeaderBanner());
setPixmap(QWizard::LogoPixmap, theme->wizardHeaderLogo());
setOption(QWizard::NoBackButtonOnStartPage);
setOption(QWizard::NoBackButtonOnLastPage);
setOption(QWizard::NoCancelButton);
setTitleFormat(Qt::RichText);
setSubTitleFormat(Qt::RichText);
setButtonText(QWizard::CustomButton1, tr("Skip folders configuration"));

// Change the next buttons size policy since we hide it on the
Expand All @@ -117,6 +108,55 @@ OwncloudWizard::OwncloudWizard(QWidget *parent)

// allow Flow2 page to poll on window activation
connect(this, &OwncloudWizard::onActivate, _flow2CredsPage, &Flow2AuthCredsPage::slotPollNow);

adjustWizardSize();
}

void OwncloudWizard::adjustWizardSize()
{
const auto pageSizes = calculateWizardPageSizes();
const auto longestSide = calculateLongestSideOfWizardPages(pageSizes);

resize(QSize(longestSide, longestSide));
}

QList<QSize> OwncloudWizard::calculateWizardPageSizes() const
{
QList<QSize> pageSizes;
const auto pIds = pageIds();

std::transform(pIds.begin(), pIds.end(), std::back_inserter(pageSizes), [this](int pageId) {
auto p = page(pageId);

p->adjustSize();

return p->sizeHint();
});

return pageSizes;
}

int OwncloudWizard::calculateLongestSideOfWizardPages(const QList<QSize> &pageSizes) const
{
const auto calculateLongestSide = [](const QSize &size) {
return size.height() < size.width() ? size.width() : size.height();
};

return std::accumulate(
std::next(pageSizes.begin()),
pageSizes.end(),
[&pageSizes, &calculateLongestSide]() {
const auto longestSideOfSize = calculateLongestSide(pageSizes.first());

return longestSideOfSize;
}(),
[&calculateLongestSide](int currentLongestSide, const QSize &size) {
const auto longestSideOfSize = calculateLongestSide(size);
if (longestSideOfSize > currentLongestSide) {
return longestSideOfSize;
}
return currentLongestSide;
});
}

void OwncloudWizard::setAccount(AccountPtr account)
Expand Down Expand Up @@ -337,6 +377,37 @@ void OwncloudWizard::changeEvent(QEvent *e)
void OwncloudWizard::customizeStyle()
{
// HINT: Customize wizard's own style here, if necessary in the future (Dark-/Light-Mode switching)
auto theme = Theme::instance();
auto wizardPalette = palette();

wizardPalette.setColor(QPalette::Window, theme->wizardHeaderBackgroundColor());
QColor colorWindowDisabled(wizardPalette.color(QPalette::Window));
colorWindowDisabled.setAlpha(128);
wizardPalette.setColor(QPalette::Disabled, QPalette::Window, colorWindowDisabled);

wizardPalette.setColor(QPalette::Base, theme->wizardHeaderBackgroundColor());
QColor colorBaseDisabled(wizardPalette.color(QPalette::Base));
colorBaseDisabled.setAlpha(128);
wizardPalette.setColor(QPalette::Disabled, QPalette::Base, colorBaseDisabled);

wizardPalette.setColor(QPalette::WindowText, theme->wizardHeaderTitleColor());
QColor colorWindowTextDisabled(wizardPalette.color(QPalette::WindowText));
colorWindowTextDisabled.setAlpha(128);
wizardPalette.setColor(QPalette::Disabled, QPalette::WindowText, colorWindowTextDisabled);

wizardPalette.setColor(QPalette::Text, theme->wizardHeaderTitleColor());
QColor colorTextDisabled(wizardPalette.color(QPalette::Text));
colorTextDisabled.setAlpha(128);
wizardPalette.setColor(QPalette::Disabled, QPalette::Text, colorWindowTextDisabled);

// Set separator color
wizardPalette.setColor(QPalette::Mid, theme->wizardHeaderBackgroundColor());

setPalette(wizardPalette);

WizardCommon::customizePrimaryButtonStyle(button(QWizard::NextButton));
WizardCommon::customizeSecondaryButtonStyle(button(QWizard::CustomButton1));
WizardCommon::customizeSecondaryButtonStyle(button(QWizard::BackButton));
}

void OwncloudWizard::bringToTop()
Expand Down
3 changes: 3 additions & 0 deletions src/gui/wizard/owncloudwizard.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ public slots:

private:
void customizeStyle();
void adjustWizardSize();
int calculateLongestSideOfWizardPages(const QList<QSize> &pageSizes) const;
QList<QSize> calculateWizardPageSizes() const;

AccountPtr _account;
WelcomePage *_welcomePage;
Expand Down

0 comments on commit a13dfe6

Please sign in to comment.