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 25, 2021
1 parent e192d8f commit 3e27044
Show file tree
Hide file tree
Showing 3 changed files with 92 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
98 changes: 88 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,62 @@ OwncloudWizard::OwncloudWizard(QWidget *parent)

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

adjustWizardSize();
centerWindow();
}

void OwncloudWizard::centerWindow()
{
const auto wizardWindow = window();
const auto screenGeometry = QGuiApplication::screenAt(wizardWindow->pos())->geometry();
const auto windowGeometry = wizardWindow->geometry();
const auto newWindowPosition = screenGeometry.center() - QPoint(windowGeometry.width() / 2, windowGeometry.height() / 2);
wizardWindow->move(newWindowPosition);
}


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(),
calculateLongestSide(pageSizes.first()),
[&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 +384,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();

// Set background colors
const auto colorAlphaDisabled = 128;
const auto backgroundColor = theme->wizardHeaderBackgroundColor();
const auto backgroundColorDisabled = QColor(backgroundColor.red(), backgroundColor.green(), backgroundColor.blue(), colorAlphaDisabled);

wizardPalette.setColor(QPalette::Window, backgroundColor);

wizardPalette.setColor(QPalette::Base, backgroundColor);
wizardPalette.setColor(QPalette::Disabled, QPalette::Base, backgroundColorDisabled);

// Set separator color
wizardPalette.setColor(QPalette::Mid, backgroundColor);

// Set foreground colors
const auto foregroundColor = theme->wizardHeaderTitleColor();
const auto foregroundColorDisabled = QColor(foregroundColor.red(), foregroundColor.green(), foregroundColor.blue(), colorAlphaDisabled);

wizardPalette.setColor(QPalette::WindowText, foregroundColor);
wizardPalette.setColor(QPalette::Disabled, QPalette::WindowText, foregroundColorDisabled);

wizardPalette.setColor(QPalette::Text, foregroundColor);
wizardPalette.setColor(QPalette::Disabled, QPalette::Text, foregroundColorDisabled);

setPalette(wizardPalette);

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

void OwncloudWizard::bringToTop()
Expand Down
4 changes: 4 additions & 0 deletions src/gui/wizard/owncloudwizard.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class OwncloudWizard : public QWizard
AbstractCredentials *getCredentials() const;

void bringToTop();
void centerWindow();

/**
* Shows a dialog explaining the virtual files mode and warning about it
Expand Down Expand Up @@ -114,6 +115,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 3e27044

Please sign in to comment.