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

Rewrite Wizard navigation #11862

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
11 changes: 7 additions & 4 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,19 @@ set( final_src
${3rdparty_SRC}
)

add_library(owncloudGui SHARED ${final_src})
set_target_properties(owncloudGui PROPERTIES AUTOUIC ON AUTORCC ON)

add_subdirectory(newwizard)
add_subdirectory(folderwizard)
add_subdirectory(loginrequireddialog)

add_library(owncloudGui SHARED ${final_src})
set_target_properties(owncloudGui PROPERTIES AUTOUIC ON AUTORCC ON)
# for the generated qml module
target_include_directories(owncloudGui PRIVATE models spaces)
target_include_directories(owncloudGui PRIVATE models spaces newwizard)
target_link_libraries(owncloudGui
PUBLIC
Qt::Widgets Qt::Network Qt::Xml Qt::Quick Qt::QuickWidgets Qt::QuickControls2
newwizard folderwizard loginrequireddialog
folderwizard loginrequireddialog
libsync
Qt6Keychain::Qt6Keychain
)
Expand All @@ -127,6 +128,8 @@ ecm_add_qml_module(owncloudGui

spaces/qml/SpaceDelegate.qml
spaces/qml/SpacesView.qml

newwizard/qml/Navigation.qml
)

generate_export_header(owncloudGui
Expand Down
14 changes: 14 additions & 0 deletions src/gui/accountmodalwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "accountmodalwidget.h"
#include "ui_accountmodalwidget.h"

#include "gui/qmlutils.h"

namespace OCC {

AccountModalWidget::AccountModalWidget(const QString &title, QWidget *widget, QWidget *parent)
Expand All @@ -29,6 +31,18 @@ AccountModalWidget::AccountModalWidget(const QString &title, QWidget *widget, QW
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &AccountModalWidget::reject);
}


AccountModalWidget::AccountModalWidget(const QString &title, const QUrl &qmlSource, QObject *qmlContext, QWidget *parent)
: AccountModalWidget(
title,
[&] {
auto *out = new QmlUtils::OCQuickWidget;
out->setOCContext(qmlSource, parent, qmlContext, QJSEngine::JavaScriptOwnership);
return out;
}(),
parent)
{
}
void AccountModalWidget::setStandardButtons(QDialogButtonBox::StandardButtons buttons)
{
ui->buttonBox->setStandardButtons(buttons);
Expand Down
3 changes: 3 additions & 0 deletions src/gui/accountmodalwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#pragma once

#include "gui/qmlutils.h"

#include <QDialogButtonBox>

namespace OCC {
Expand All @@ -27,6 +29,7 @@ class AccountModalWidget : public QWidget
Q_OBJECT
public:
AccountModalWidget(const QString &title, QWidget *widget, QWidget *parent);
AccountModalWidget(const QString &title, const QUrl &qmlSource, QObject *qmlContext, QWidget *parent);

enum class Result { Rejected, Accepted };
Q_ENUM(Result)
Expand Down
2 changes: 1 addition & 1 deletion src/gui/accountsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ AccountSettings::AccountSettings(const AccountStatePtr &accountState, QWidget *p
_sortModel = weightedModel;

ui->quickWidget->engine()->addImageProvider(QStringLiteral("space"), new Spaces::SpaceImageProvider(_accountState->account()));
QmlUtils::initQuickWidget(ui->quickWidget, QUrl(QStringLiteral("qrc:/qt/qml/org/ownCloud/gui/qml/FolderDelegate.qml")), this);
ui->quickWidget->setOCContext(QUrl(QStringLiteral("qrc:/qt/qml/org/ownCloud/gui/qml/FolderDelegate.qml")), this);

connect(FolderMan::instance(), &FolderMan::folderListChanged, _model, &FolderStatusModel::resetFolders);
if (accountsState()->supportsSpaces()) {
Expand Down
6 changes: 1 addition & 5 deletions src/gui/newwizard/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_library(newwizard STATIC
target_sources(owncloudGui PRIVATE
enums.cpp

pages/abstractsetupwizardpage.h
Expand Down Expand Up @@ -57,7 +57,3 @@ add_library(newwizard STATIC

setupwizardcontext.cpp
)
target_link_libraries(newwizard PUBLIC Qt::Widgets libsync owncloudResources)
set_target_properties(newwizard PROPERTIES AUTOUIC ON AUTORCC ON)
target_include_directories(newwizard PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
apply_common_target_settings(newwizard)
2 changes: 2 additions & 0 deletions src/gui/newwizard/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
#include "common/utility.h"

#include <QObject>
#include <QtQmlIntegration/QtQmlIntegration>

namespace OCC::Wizard {
Q_NAMESPACE
QML_ELEMENT

enum class SetupWizardState {
ServerUrlState,
Expand Down
71 changes: 17 additions & 54 deletions src/gui/newwizard/navigation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,77 +6,40 @@
namespace OCC::Wizard {

Navigation::Navigation(QWidget *parent)
: QWidget(parent)
: OCQuickWidget(parent)
{
// this class manages its own layout
setLayout(new QHBoxLayout(this));
setOCContext(QUrl(QStringLiteral("qrc:/qt/qml/org/ownCloud/gui/newwizard/qml/Navigation.qml")), this->parentWidget(), this, QJSEngine::CppOwnership);
}

void Navigation::setEntries(const QList<SetupWizardState> &newEntries)
void Navigation::setStates(const QList<SetupWizardState> &newEntries)
{
// TODO: more advanced implementation (reuse existing buttons within layout)
// current active page is also lost that way
removeAllItems();

for (const auto state : newEntries) {
const QString text = Utility::enumToDisplayName(state);

auto newButton = new QRadioButton(text, this);

_entries.insert(state, newButton);
layout()->addWidget(newButton);

connect(newButton, &QRadioButton::clicked, this, [this, state]() {
// clicks to the current state button should be ignored
// this used to be handled by disabling the button
if (state != _activeState) {
Q_EMIT paginationEntryClicked(state);
}
});
if (_states != newEntries) {
_states = newEntries;
Q_EMIT statesChanged();
}

enableOrDisableButtons();
}

// needed to clean up widgets we added to the layout
Navigation::~Navigation() noexcept
QList<SetupWizardState> Navigation::states() const
{
removeAllItems();
return _states;
}

void Navigation::removeAllItems()
void Navigation::setActiveState(SetupWizardState newState)
{
qDeleteAll(_entries);
if (_activeState != newState) {
_activeState = newState;
Q_EMIT activeStatesChanged();
}
}

void Navigation::enableOrDisableButtons()
SetupWizardState Navigation::activeState() const
{
for (const auto state : _entries.keys()) {
auto button = _entries.value(state);

const auto enabled = [&state, this]() {
if (_enabled) {
return state <= _activeState;
}

return false;
}();

// we just ignore clicks to the current page
button->setEnabled(enabled);
}
return _activeState;
}

void Navigation::setActiveState(SetupWizardState newState)
QString Navigation::stateDisplayName(SetupWizardState state) const
{
_activeState = newState;

for (const auto key : _entries.keys()) {
auto button = _entries.value(key);
button->setChecked(key == _activeState);
}

enableOrDisableButtons();
return Utility::enumToDisplayName(state);
}

}
38 changes: 22 additions & 16 deletions src/gui/newwizard/navigation.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#include "enums.h"

#include "gui/qmlutils.h"

#include <QHBoxLayout>
#include <QMap>
#include <QRadioButton>
Expand All @@ -27,42 +29,46 @@ namespace OCC::Wizard {
/**
* Provides a radio button based quick navigation on the wizard's bottom side.
*/
class Navigation : public QWidget
class Navigation : public QmlUtils::OCQuickWidget
{
Q_OBJECT
Q_PROPERTY(QList<SetupWizardState> states READ states NOTIFY statesChanged)
Q_PROPERTY(SetupWizardState activeState READ activeState WRITE setActiveState NOTIFY activeStatesChanged)
QML_ELEMENT
QML_UNCREATABLE("C++")

public:
explicit Navigation(QWidget *parent = nullptr);

~Navigation() noexcept override;

/**
* Set or replace entries in the navigation.
* This method creates the corresponding buttons.
* @param newEntries ordered list of wizard states to be rendered in the navigation
*/
void setEntries(const QList<SetupWizardState> &newEntries);
void setStates(const QList<SetupWizardState> &newEntries);
QList<SetupWizardState> states() const;

Q_SIGNALS:
/**
* Emitted when a pagination entry is clicked.
* This event is only emitted for previous states.
* @param clickedState state the user wants to switch to
* Change to another state. Applies changes to hosted UI elements (e.g., disables buttons, )
*/
void paginationEntryClicked(SetupWizardState clickedState);
void setActiveState(SetupWizardState activeState);
SetupWizardState activeState() const;

Q_INVOKABLE QString stateDisplayName(SetupWizardState state) const;

public Q_SLOTS:
Q_SIGNALS:
/**
* Change to another state. Applies changes to hosted UI elements (e.g., disables buttons, )
* @param newState state to activate
* Emitted when a state is clicked.
* This event is only emitted for previous states.
* @param clickedState state the user wants to switch to
*/
void setActiveState(SetupWizardState newState);
void stateClicked(SetupWizardState clickedState);
void statesChanged();
void activeStatesChanged();

private:
void removeAllItems();
void enableOrDisableButtons();

QMap<SetupWizardState, QRadioButton *> _entries;
QList<SetupWizardState> _states;
SetupWizardState _activeState = SetupWizardState::FirstState;
bool _enabled = true;
};
Expand Down
69 changes: 69 additions & 0 deletions src/gui/newwizard/qml/Navigation.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright (C) by Hannah von Reth <[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.
*/

import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import org.ownCloud.gui 1.0
import org.ownCloud.libsync 1.0
import org.ownCloud.resources 1.0

Pane {
id: navigationBar
readonly property Navigation navigation: ocContext

// Connections {
// target: ocParentWidget

// function onFocusFirst() {
// if (accountButtons.count === 0) {
// addAccountButton.forceActiveFocus(Qt.TabFocusReason);
// } else {
// accountButtons.itemAt(0).forceActiveFocus(Qt.TabFocusReason);
// }
// }

// function onFocusLast() {
// quitButton.forceActiveFocus(Qt.TabFocusReason);
// }
// }

RowLayout {
anchors.fill: parent

Item {
Layout.fillWidth: true
}

Repeater {
id: statesRepeater

model: navigation.states

delegate: RadioButton {
property int wizardState: modelData
Accessible.role: Accessible.PageTab
checked: navigation.currentState === wizardState
text: navigation.stateDisplayName(wizardState)
onClicked: {
// settingsDialog.currentAccount = accountState.account;
}
}
}
}

Item {
Layout.fillWidth: true
}
}
4 changes: 2 additions & 2 deletions src/gui/newwizard/setupwizardwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ SetupWizardWidget::SetupWizardWidget(SettingsDialog *parent)
Q_EMIT backButtonClicked();
});

connect(_ui->navigation, &Navigation::paginationEntryClicked, this, [this](SetupWizardState clickedState) {
connect(_ui->navigation, &Navigation::stateClicked, this, [this](SetupWizardState clickedState) {
slotStartTransition();
Q_EMIT navigationEntryClicked(clickedState);
});
Expand Down Expand Up @@ -178,7 +178,7 @@ void SetupWizardWidget::showErrorMessage(const QString &errorMessage)

void SetupWizardWidget::setNavigationEntries(const QList<SetupWizardState> &entries)
{
_ui->navigation->setEntries(entries);
_ui->navigation->setStates(entries);
}

void SetupWizardWidget::slotUpdateNextButton()
Expand Down
9 changes: 5 additions & 4 deletions src/gui/newwizard/setupwizardwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@

#pragma once

#include "gui/newwizard/navigation.h"
#include "gui/newwizard/pages/abstractsetupwizardpage.h"
#include "gui/newwizard/setupwizardaccountbuilder.h"
#include "gui/qmlutils.h"
#include "gui/settingsdialog.h"
#include "navigation.h"
#include "pages/abstractsetupwizardpage.h"
#include "setupwizardaccountbuilder.h"

namespace Ui {
class SetupWizardWidget;
Expand All @@ -31,7 +32,7 @@ namespace OCC::Wizard {
class SetupWizardWidget : public QWidget
{
Q_OBJECT

OC_DECLARE_WIDGET_FOCUS
public:
explicit SetupWizardWidget(SettingsDialog *parent);
~SetupWizardWidget() noexcept override;
Expand Down
Loading
Loading