diff --git a/src/activities/server/CMakeLists.txt b/src/activities/server/CMakeLists.txt index bb8a54794..a7a1443ca 100644 --- a/src/activities/server/CMakeLists.txt +++ b/src/activities/server/CMakeLists.txt @@ -1 +1 @@ -GCOMPRIS_ADD_RCC(activities/server *.qml *.svg *.js resource/* views/* controllers/* models/* assets/*) +GCOMPRIS_ADD_RCC(activities/server *.qml *.svg *.js resource/* views/* controllers/* models/* components/*) diff --git a/src/activities/server/Server.qml b/src/activities/server/Server.qml index fa5f4e5ab..307c88133 100644 --- a/src/activities/server/Server.qml +++ b/src/activities/server/Server.qml @@ -1,221 +1,194 @@ /* GCompris - server.qml * * Copyright (C) 2018 YOUR NAME * * Authors: * (GTK+ version) * YOUR NAME (Qt Quick port) * * 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 3 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. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . */ /*import QtQuick 2.2 import QtQuick.Controls 2.2 import QtQuick.Dialogs 1.2 import QtQuick.Controls.Material 2.1*/ import QtQuick 2.0 import QtQuick.Controls 2.2 import QtQuick.Dialogs 1.2 import QtQuick.Controls.Material 2.1 import GCompris 1.0 import "../../core" import "server.js" as Activity +import "components" ActivityBase { id: activity onStart: focus = true onStop: {} pageComponent: Rectangle { id: background anchors.fill: parent color: "#ABCDEF" signal start signal stop Component.onCompleted: { activity.start.connect(start) activity.stop.connect(stop) contentFrame.replace("views/DashboardView.qml"); } // Add here the QML items you need to access in javascript QtObject { id: items property Item main: activity.main property alias background: background property alias bar: bar property alias bonus: bonus } onStart: { Activity.start(items) } onStop: { Activity.stop() } Connections { target: masterController.ui_navigationController onGoCreateClientView: contentFrame.replace("views/CreateClientView.qml") onGoDashboardView: contentFrame.replace("views/DashboardView.qml") onGoEditClientView: contentFrame.replace("views/EditClientView.qml", {selectedClient: client}) onGoFindClientView: contentFrame.replace("views/FindClientView.qml") onGoManagePupilsView: contentFrame.replace("views/ManagePupilsView.qml") onGoManageGroupsView: contentFrame.replace("views/ManageGroupsView.qml") } - Rectangle { - id: navigationBar - anchors { - top: parent.top - bottom: parent.bottom - left: parent.left - } - width: 100 - color: "#000000" - Column { - Button { - text: "Dashboard" - onClicked: masterController.ui_navigationController.goDashboardView() - } - Button { - text: "New Client" - onClicked: masterController.ui_navigationController.goCreateClientView() - } - Button { - text: "Find Client" - onClicked: masterController.ui_navigationController.goFindClientView() - } - Button { - text: "Manage Pupils" - onClicked: masterController.ui_navigationController.goManagePupilsView() - } - Button { - text: "Manage Groups" - onClicked: masterController.ui_navigationController.goManageGroupsView() - } - } + NavigationBar { + id: navigationBar } + StackView { id: contentFrame anchors { top: parent.top bottom: parent.bottom right: parent.right left: navigationBar.right } initialItem: "qrc:/gcompris/src/activities/server/views/SplashView.qml" clip: true } /* Drawer { id: drawer width: Math.min(background.width, background.height) / 3 * 2 height: background.height ListView { focus: true currentIndex: -1 anchors.fill: parent delegate: ItemDelegate { width: parent.width text: model.text highlighted: ListView.isCurrentItem onClicked: { drawer.close() //model.triggered() } } model: ListModel { ListElement { text: qsTr("Open...") // triggered: { fileOpenDialog.open(); } } ListElement { text: qsTr("About...") // triggered: function(){ console.log("f"); } } } ScrollIndicator.vertical: ScrollIndicator { } } } ToolBar { Material.background: Material.Orange anchors.top: parent.top anchors.left: parent.left ToolButton { id: menuButton anchors.left: parent.left anchors.verticalCenter: parent.verticalCenter icon.source: "resource/baseline-menu-24px.svg" onClicked: drawer.open() } Label { anchors.centerIn: parent text: "Image Viewer" font.pixelSize: 20 elide: Label.ElideRight } } FileDialog { id: fileOpenDialog title: "Select an image file" folder: shortcuts.documents nameFilters: [ "Image files (*.png *.jpeg *.jpg)", ] onAccepted: { image.source = fileOpenDialog.fileUrl } }*/ DialogHelp { id: dialogHelp onClose: home() } Bar { id: bar content: BarEnumContent { value: help | home | level } onHelpClicked: { displayDialog(dialogHelp) } onPreviousLevelClicked: Activity.previousLevel() onNextLevelClicked: Activity.nextLevel() onHomeClicked: activity.home() } Bonus { id: bonus Component.onCompleted: win.connect(Activity.nextLevel) } } } diff --git a/src/activities/server/components/NavigationBar.qml b/src/activities/server/components/NavigationBar.qml new file mode 100644 index 000000000..625e71a23 --- /dev/null +++ b/src/activities/server/components/NavigationBar.qml @@ -0,0 +1,47 @@ +import QtQuick 2.9 +import "../../../core" + +Item { + property bool isCollapsed: true + + anchors { + top: parent.top + bottom: parent.bottom + left: parent.left + } + width: isCollapsed ? Style.widthNavigationBarCollapsed : Style.heightNavigationBarExpanded + + Rectangle { + anchors.fill: parent + color: Style.colourNavigationBarBackground + + Column { + width: parent.width + + NavigationButton { + iconCharacter: "\uf0c9" + description: "" + hoverColour: "#993333" + onNavigationButtonClicked: isCollapsed = !isCollapsed + } + NavigationButton { + iconCharacter: "\uf015" + description: "Dashboard" + hoverColour: "#dc8a00" + onNavigationButtonClicked: masterController.ui_navigationController.goDashboardView(); + } + NavigationButton { + iconCharacter: "\uf234" + description: "New Client" + hoverColour: "#dccd00" + onNavigationButtonClicked: masterController.ui_navigationController.goCreateClientView(); + } + NavigationButton { + iconCharacter: "\uf002" + description: "Find Client" + hoverColour: "#8aef63" + onNavigationButtonClicked: masterController.ui_navigationController.goFindClientView(); + } + } + } +} diff --git a/src/activities/server/components/NavigationButton.qml b/src/activities/server/components/NavigationButton.qml new file mode 100644 index 000000000..90061d730 --- /dev/null +++ b/src/activities/server/components/NavigationButton.qml @@ -0,0 +1,63 @@ +import QtQuick 2.6 +import "../../../core" + +Item { + property alias iconCharacter: textIcon.text + property alias description: textDescription.text + property color hoverColour: Style.colourNavigationBarBackground + + signal navigationButtonClicked() + + width: parent.width + height: Style.heightNavigationButton + + Rectangle { + id: background + anchors.fill: parent + color: Style.colourNavigationBarBackground + + Row { + Text { + id: textIcon + width: Style.widthNavigationButtonIcon + height: Style.heightNavigationButtonIcon + font { + family: Style.fontAwesome + pixelSize: Style.pixelSizeNavigationBarIcon + } + color: Style.colourNavigationBarFont + text: "\uf11a" + verticalAlignment: Text.AlignVCenter + horizontalAlignment: Text.AlignHCenter + } + Text { + id: textDescription + width: Style.widthNavigationButtonDescription + height: Style.heightNavigationButtonDescription + color: Style.colourNavigationBarFont + text: "SET ME!!" + verticalAlignment: Text.AlignVCenter + font.pixelSize: Style.pixelSizeNavigationBarText + } + } + + MouseArea { + anchors.fill: parent + cursorShape: Qt.PointingHandCursor + hoverEnabled: true + onEntered: background.state = "hover" + onExited: background.state = "" + onClicked: navigationButtonClicked() + } + + states: [ + State { + name: "hover" + PropertyChanges { + target: background + color: hoverColour + } + } + ] + } +} diff --git a/src/activities/server/views/ManageGroupsView.qml b/src/activities/server/views/ManageGroupsView.qml index f1435b834..d9b01a2cc 100644 --- a/src/activities/server/views/ManageGroupsView.qml +++ b/src/activities/server/views/ManageGroupsView.qml @@ -1,15 +1,13 @@ import QtQuick 2.0 import "../../../core" -color: Style.colourBackground - Item { Rectangle { anchors.fill: parent - color: "#f4c842" + color: Style.colourBackground Text { anchors.centerIn: parent text: "Edit Client View" } } } diff --git a/src/core/serverMasterController/commands/command.cpp b/src/core/serverMasterController/commands/command.cpp new file mode 100644 index 000000000..ed7d90339 --- /dev/null +++ b/src/core/serverMasterController/commands/command.cpp @@ -0,0 +1,47 @@ +#include "command.h" + +namespace cm { +namespace framework { + +class Command::Implementation +{ +public: + Implementation(const QString& _iconCharacter, const QString& _description, std::function _canExecute) + : iconCharacter(_iconCharacter) + , description(_description) + , canExecute(_canExecute) + { + } + + QString iconCharacter; + QString description; + std::function canExecute; +}; + +Command::Command(QObject* parent, const QString& iconCharacter, const QString& description, std::function canExecute) + : QObject(parent) +{ + implementation.reset(new Implementation(iconCharacter, description, canExecute)); +} + +Command::~Command() +{ +} + +const QString& Command::iconCharacter() const +{ + return implementation->iconCharacter; +} + +const QString& Command::description() const +{ + return implementation->description; +} + +bool Command::canExecute() const +{ + return implementation->canExecute(); +} + +} +} diff --git a/src/core/serverMasterController/commands/command.h b/src/core/serverMasterController/commands/command.h new file mode 100644 index 000000000..fd031901c --- /dev/null +++ b/src/core/serverMasterController/commands/command.h @@ -0,0 +1,44 @@ +#ifndef COMMAND_H +#define COMMAND_H + +#include + +#include +#include +#include + +#include + +namespace cm { +namespace framework { + +class CMLIBSHARED_EXPORT Command : public QObject +{ + Q_OBJECT + Q_PROPERTY( QString ui_iconCharacter READ iconCharacter CONSTANT ) + Q_PROPERTY( QString ui_description READ description CONSTANT ) + Q_PROPERTY( bool ui_canExecute READ canExecute NOTIFY canExecuteChanged ) + +public: + explicit Command(QObject* parent = nullptr, + const QString& iconCharacter = "", + const QString& description = "", + std::function canExecute = [](){ return true; }); + ~Command(); + + const QString& iconCharacter() const; + const QString& description() const; + bool canExecute() const; + +signals: + void canExecuteChanged(); + void executed(); + +private: + class Implementation; + QScopedPointer implementation; +}; + +}} + +#endif diff --git a/src/core/serverMasterController/controllers/command-controller.cpp b/src/core/serverMasterController/controllers/command-controller.cpp new file mode 100644 index 000000000..40bb801ad --- /dev/null +++ b/src/core/serverMasterController/controllers/command-controller.cpp @@ -0,0 +1,47 @@ +#include "command-controller.h" + +#include +#include + +using namespace cm::framework; + +namespace cm { +namespace controllers { + +class CommandController::Implementation +{ +public: + Implementation(CommandController* _commandController) + : commandController(_commandController) + { + Command* createClientSaveCommand = new Command( commandController, QChar( 0xf0c7 ), "Save" ); + QObject::connect( createClientSaveCommand, &Command::executed, commandController, &CommandController::onCreateClientSaveExecuted ); + createClientViewContextCommands.append( createClientSaveCommand ); + } + + CommandController* commandController{nullptr}; + + QList createClientViewContextCommands{}; +}; + +CommandController::CommandController(QObject* parent) + : QObject(parent) +{ + implementation.reset(new Implementation(this)); +} + +CommandController::~CommandController() +{ +} + +QQmlListProperty CommandController::ui_createClientViewContextCommands() +{ + return QQmlListProperty(this, implementation->createClientViewContextCommands); +} + +void CommandController::onCreateClientSaveExecuted() +{ + qDebug() << "You executed the Save command!"; +} + +}} diff --git a/src/core/serverMasterController/controllers/command-controller.h b/src/core/serverMasterController/controllers/command-controller.h new file mode 100644 index 000000000..3574e202b --- /dev/null +++ b/src/core/serverMasterController/controllers/command-controller.h @@ -0,0 +1,33 @@ +#ifndef COMMANDCONTROLLER_H +#define COMMANDCONTROLLER_H + +#include +#include +#include +#include + +namespace cm { +namespace controllers { + +class CMLIBSHARED_EXPORT CommandController : public QObject +{ + Q_OBJECT + Q_PROPERTY(QQmlListProperty ui_createClientViewContextCommands READ ui_createClientViewContextCommands CONSTANT) + +public: + explicit CommandController(QObject* _parent = nullptr); + ~CommandController(); + + QQmlListProperty ui_createClientViewContextCommands(); + +public slots: + void onCreateClientSaveExecuted(); + +private: + class Implementation; + QScopedPointer implementation; +}; + +}} + +#endif