Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve wizard ui #2895

Merged
merged 4 commits into from
Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion NEXTCLOUD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ option( WITH_PROVIDERS "Build with providers list" ON )


## Theming options
set( APPLICATION_WIZARD_HEADER_BACKGROUND_COLOR "#0082c9" CACHE STRING "Hex color of the wizard header background")
set(NEXTCLOUD_BACKGROUND_COLOR "#0082c9" CACHE STRING "Default Nextcloud background color")
FlexW marked this conversation as resolved.
Show resolved Hide resolved
set( APPLICATION_WIZARD_HEADER_BACKGROUND_COLOR ${NEXTCLOUD_BACKGROUND_COLOR} CACHE STRING "Hex color of the wizard header background")
set( APPLICATION_WIZARD_HEADER_TITLE_COLOR "#ffffff" CACHE STRING "Hex color of the text in the wizard header")
option( APPLICATION_WIZARD_USE_CUSTOM_LOGO "Use the logo from ':/client/theme/colored/wizard_logo.(png|svg)' else the default application icon is used" ON )

Expand Down
1 change: 1 addition & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#cmakedefine APPLICATION_SERVER_URL_ENFORCE "@APPLICATION_SERVER_URL_ENFORCE@"
#cmakedefine LINUX_APPLICATION_ID "@LINUX_APPLICATION_ID@"
#cmakedefine APPLICATION_WIZARD_HEADER_BACKGROUND_COLOR "@APPLICATION_WIZARD_HEADER_BACKGROUND_COLOR@"
#cmakedefine NEXTCLOUD_BACKGROUND_COLOR "@NEXTCLOUD_BACKGROUND_COLOR@"
#cmakedefine APPLICATION_WIZARD_HEADER_TITLE_COLOR "@APPLICATION_WIZARD_HEADER_TITLE_COLOR@"
#cmakedefine APPLICATION_WIZARD_USE_CUSTOM_LOGO "@APPLICATION_WIZARD_USE_CUSTOM_LOGO@"
#cmakedefine APPLICATION_VIRTUALFILE_SUFFIX "@APPLICATION_VIRTUALFILE_SUFFIX@"
Expand Down
3 changes: 3 additions & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ set(client_UI_SRCS
wizard/owncloudsetupnocredspage.ui
wizard/owncloudwizardresultpage.ui
wizard/webview.ui
wizard/welcomepage.ui
)

set(client_SRCS
Expand Down Expand Up @@ -134,6 +135,8 @@ set(client_SRCS
wizard/webviewpage.cpp
wizard/webview.cpp
wizard/slideshow.cpp
wizard/welcomepage.cpp
wizard/linklabel.cpp
)

IF(BUILD_UPDATER)
Expand Down
7 changes: 6 additions & 1 deletion src/gui/owncloudsetupwizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,12 @@ void OwncloudSetupWizard::startWizard()

_ocWizard->setRemoteFolder(_remoteFolder);

_ocWizard->setStartId(WizardCommon::Page_ServerSetup);
#ifdef WITH_PROVIDERS
const auto startPage = WizardCommon::Page_Welcome;
#else // WITH_PROVIDERS
const auto startPage = WizardCommon::Page_ServerSetup;
#endif // WITH_PROVIDERS
_ocWizard->setStartId(startPage);

_ocWizard->restart();

Expand Down
58 changes: 58 additions & 0 deletions src/gui/wizard/linklabel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (C) 2021 by Felix Weilbach <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/

#include "linklabel.h"
#include "guiutility.h"

namespace OCC {

LinkLabel::LinkLabel(QWidget *parent) : QLabel(parent)
{

}

void LinkLabel::setUrl(const QUrl &url)
{
this->url = url;
}

void LinkLabel::enterEvent(QEvent * /*event*/)
{
setFontUnderline(true);
setCursor(Qt::PointingHandCursor);
}

void LinkLabel::leaveEvent(QEvent * /*event*/)
{
setFontUnderline(false);
setCursor(Qt::ArrowCursor);
}

void LinkLabel::mouseReleaseEvent(QMouseEvent * /*event*/)
{
if (url.isValid()) {
Utility::openBrowser(url);
}

emit clicked();
}

void LinkLabel::setFontUnderline(bool value)
{
auto labelFont = font();
labelFont.setUnderline(value);
setFont(labelFont);
}

}
46 changes: 46 additions & 0 deletions src/gui/wizard/linklabel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (C) 2021 by Felix Weilbach <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/

#pragma once

#include <QLabel>
#include <QUrl>

namespace OCC {

class LinkLabel : public QLabel
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd argue you don't need that class at all, QLabel supports URLs just fine:
https://doc.qt.io/qt-5/qlabel.html#linkActivated

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created this class because of the hover event. I needed to underline the font on hover. I couldn't find an API in QLabel that allows me to underline the label just on hover. There is QLabel::linkHover() but with that, you get just the hover entry signal not the hover out signal. Please correct me if I'm wrong ;)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly I'd consider like it's overdoing it and I'd be fine to have the text underlined. I'd rather spare the extra class with debatable API just for that. :-)

Now if really... one thing which could be done is to use an event filter to catch the enter/leave events and force the style on the label. We're back at having an extra class though, it's just that it'd have a safer API in my views. Indeed it'd be more focused on "change some property of a widget when it is entered, restore it when it's left" so it's easier to have a focused API.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@er-vin
It was wished by the design team ;)

One problem I see with not making an extra class is how to embed the link into the label? I know I can use rich text for that but when rich text is used the font of the label stays not white anymore it uses a different color. Now I know I can work around this by setting the font in the rich text again but it gets then a lot more complicated than it is now. Another possibility would be to create another event filter or even use the HoverEventFilter and rename it to LinkLabelEventFilter but I'm unsure if this brings any benefit to what we have now. What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@er-vin
It was wished by the design team ;)

Not argument enough in my opinion if that leads to potentially harmful code piling up. ;-)

(not that this single occurrence is super harmful of course, but my experience is that unchallenged design decisions lead to a path of death by 1000 cuts, hence why the question should be at least asked, every single time)

One problem I see with not making an extra class is how to embed the link into the label? I know I can use rich text for that but when rich text is used the font of the label stays not white anymore it uses a different color. Now I know I can work around this by setting the font in the rich text again but it gets then a lot more complicated than it is now. Another possibility would be to create another event filter or even use the HoverEventFilter and rename it to LinkLabelEventFilter but I'm unsure if this brings any benefit to what we have now. What do you think?

Alright, I prefer the event filter but I see you'll be struggling with that one. Let's scrap that...

Well the main problem really is the QLabel inheritance. I'd be fine even with inheriting from QWidget and have a single QLabel as child (and in a private member). Design wise the problem is that this is still a QLabel with all its API being exposed to the users of LinkLabel. Delegation is way better than inheritance in most cases, here included.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK... too bad this went in unsolved. Is there any PR I should look forward to regarding this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@er-vin No not at the moment but I like to do better here. I will create one and let you know then.

{
Q_OBJECT
public:
explicit LinkLabel(QWidget *parent = nullptr);

void setUrl(const QUrl &url);

signals:
void clicked();

protected:
void enterEvent(QEvent *event) override;

void leaveEvent(QEvent *event) override;

void mouseReleaseEvent(QMouseEvent *event) override;

private:
void setFontUnderline(bool value);

QUrl url;
};

}
37 changes: 36 additions & 1 deletion src/gui/wizard/owncloudwizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "owncloudgui.h"

#include "wizard/owncloudwizard.h"
#include "wizard/welcomepage.h"
#include "wizard/owncloudsetuppage.h"
#include "wizard/owncloudhttpcredspage.h"
#include "wizard/owncloudoauthcredspage.h"
Expand All @@ -46,6 +47,9 @@ Q_LOGGING_CATEGORY(lcWizard, "nextcloud.gui.wizard", QtInfoMsg)
OwncloudWizard::OwncloudWizard(QWidget *parent)
: QWizard(parent)
, _account(nullptr)
#ifdef WITH_PROVIDERS
FlexW marked this conversation as resolved.
Show resolved Hide resolved
, _welcomePage(new WelcomePage(this))
#endif // WITH_PROVIDERS
, _setupPage(new OwncloudSetupPage(this))
, _httpCredsPage(new OwncloudHttpCredsPage(this))
, _browserCredsPage(new OwncloudOAuthCredsPage)
Expand All @@ -57,6 +61,9 @@ 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 Down Expand Up @@ -94,6 +101,12 @@ OwncloudWizard::OwncloudWizard(QWidget *parent)
setSubTitleFormat(Qt::RichText);
setButtonText(QWizard::CustomButton1, tr("Skip folders configuration"));

// Change the next buttons size policy since we hide it on the
// welcome page but want it to fill it's space that we don't get
// flickering when the page changes
auto nextButtonSizePolicy = button(QWizard::NextButton)->sizePolicy();
nextButtonSizePolicy.setRetainSizeWhenHidden(true);
button(QWizard::NextButton)->setSizePolicy(nextButtonSizePolicy);

// Connect styleChanged events to our widgets, so they can adapt (Dark-/Light-Mode switching)
connect(this, &OwncloudWizard::styleChanged, _setupPage, &OwncloudSetupPage::slotStyleChanged);
Expand Down Expand Up @@ -220,6 +233,29 @@ void OwncloudWizard::slotCurrentPageChanged(int id)
{
qCDebug(lcWizard) << "Current Wizard page changed to " << id;

const auto setNextButtonAsDefault = [this]() {
auto nextButton = qobject_cast<QPushButton *>(button(QWizard::NextButton));
if (nextButton) {
nextButton->setDefault(true);
nextButton->setFocus();
}
};

if (id == WizardCommon::Page_Welcome) {
// Set next button to just hidden so it retains it's layout
button(QWizard::NextButton)->setHidden(true);
// Need to set it from here, otherwise it has no effect
_welcomePage->setLoginButtonDefault();
} else if (id == WizardCommon::Page_WebView || id == WizardCommon::Page_Flow2AuthCreds) {
setButtonLayout({ QWizard::Stretch, QWizard::BackButton });
} else if (id == WizardCommon::Page_AdvancedSetup) {
setButtonLayout({ QWizard::Stretch, QWizard::CustomButton1, QWizard::BackButton, QWizard::NextButton });
setNextButtonAsDefault();
} else {
setButtonLayout({ QWizard::Stretch, QWizard::BackButton, QWizard::NextButton });
setNextButtonAsDefault();
}

if (id == WizardCommon::Page_ServerSetup) {
emit clearPendingRequests();
}
Expand All @@ -232,7 +268,6 @@ void OwncloudWizard::slotCurrentPageChanged(int id)
done(Accepted);
}

setOption(QWizard::HaveCustomButton1, id == WizardCommon::Page_AdvancedSetup);
if (id == WizardCommon::Page_AdvancedSetup && (_credentialsPage == _browserCredsPage || _credentialsPage == _flow2CredsPage)) {
// For OAuth, disable the back button in the Page_AdvancedSetup because we don't want
// to re-open the browser.
Expand Down
2 changes: 2 additions & 0 deletions src/gui/wizard/owncloudwizard.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace OCC {

Q_DECLARE_LOGGING_CATEGORY(lcWizard)

class WelcomePage;
class OwncloudSetupPage;
class OwncloudHttpCredsPage;
class OwncloudOAuthCredsPage;
Expand Down Expand Up @@ -115,6 +116,7 @@ public slots:
void customizeStyle();

AccountPtr _account;
WelcomePage *_welcomePage;
OwncloudSetupPage *_setupPage;
OwncloudHttpCredsPage *_httpCredsPage;
OwncloudOAuthCredsPage *_browserCredsPage;
Expand Down
13 changes: 13 additions & 0 deletions src/gui/wizard/owncloudwizardcommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#include <QLabel>
#include <QPixmap>
#include <QVariant>
#include <QRadioButton>
#include <QAbstractButton>
#include <QCheckBox>
#include <QSpinBox>

#include "wizard/owncloudwizardcommon.h"
#include "theme.h"
Expand Down Expand Up @@ -68,6 +72,15 @@ namespace WizardCommon {
errorLabel->setVisible(false);
}

void customizeHintLabel(QLabel *label)
{
auto palette = label->palette();
QColor textColor = palette.color(QPalette::Text);
textColor.setAlpha(128);
palette.setColor(QPalette::Text, textColor);
label->setPalette(palette);
}

} // ns WizardCommon

} // namespace OCC
6 changes: 6 additions & 0 deletions src/gui/wizard/owncloudwizardcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

class QVariant;
class QLabel;
class QRadioButton;
class QSpinBox;
class QCheckBox;
class QAbstractButton;

namespace OCC {

Expand All @@ -27,13 +31,15 @@ namespace WizardCommon {
QString titleTemplate();
QString subTitleTemplate();
void initErrorLabel(QLabel *errorLabel);
void customizeHintLabel(QLabel *label);

enum SyncMode {
SelectiveMode,
BoxMode
};

enum Pages {
Page_Welcome,
Page_ServerSetup,
Page_HttpCreds,
Page_ShibbolethCreds,
Expand Down
Loading