Commit fd690d3c authored by Andreas Cord-Landwehr's avatar Andreas Cord-Landwehr
Browse files

Add welcome screen if no courses are installed.

parent bc7d62b5
......@@ -229,6 +229,13 @@ void MainWindow::downloadNewStuff()
continue;
}
CourseResource *resource = new CourseResource(m_resourceManager, QUrl::fromLocalFile(path));
// set as active course if no training course is set
if (!m_trainingSession->course()) {
m_trainingSession->setCourse(resource->course());
m_trainingSession->setLanguage(resource->course()->language());
}
// update learning goals
//TODO will be gone after refactoring
foreach (LearningGoal *goal, m_profileManager->goals()) {
if (goal->category() == LearningGoal::Language
&& goal->identifier() == resource->language()
......
......@@ -113,6 +113,9 @@ QVariant PhraseModel::data(const QModelIndex &index, int role) const
}
if (!index.internalPointer()) {
if (!m_course || m_course->unitList().size() == 0) {
return QVariant();
}
Unit *unit = m_course->unitList().at(index.row());
switch(role)
{
......
......@@ -35,6 +35,7 @@ set(artikulate_qml_files
LanguageSwitcher.qml
FlatButton.qml
MainMenuBar.qml
NewUserWelcome.qml
PhraseEditor.qml
PhraseEditorSoundComponent.qml
PhraseEditorTypeComponent.qml
......
......@@ -49,14 +49,6 @@ ApplicationWindow {
property Learner learner: profileManager.activeProfile
property ResourceManager resourceManager: g_resourceManager
Component.onCompleted: {
var learner = profileManager.activeProfile;
if (learner == null) {
return;
}
g_trainingSession.language = g_resourceManager.language(learner.activeGoal(Learner.Language))
}
CourseModel {
id: availableCourseModel
resourceManager: g_resourceManager
......@@ -68,6 +60,84 @@ ApplicationWindow {
}
menuBar: { kcfg_ShowMenuBar ? topMenu : null }
Component {
id: welcomeScreen
NewUserWelcome { }
}
Component {
id: trainingScreen
RowLayout {
id: mainRow
Layout.fillHeight: true
spacing: theme.spacing
TreeView {
id: phraseTree
Layout.preferredWidth: Math.floor(main.width * 0.3)
Layout.fillHeight: true
TableViewColumn {
title: i18n("Categories")
role: "text"
}
model: PhraseModel {
id: phraseModel
course: g_trainingSession.course
}
selection: ItemSelectionModel {
model: phraseTree.model
}
itemDelegate: Item {
property bool isUnit: phraseModel.isUnit(styleData.index)
Component {
id: unitRowBackground
Rectangle {anchors.fill: parent; color: "steelblue"}
}
Loader {
anchors.fill: parent
sourceComponent: isUnit ? unitRowBackground : null
}
Text {
width: phraseTree.width - 100 //TODO check if this is really a reasonable value
anchors {
verticalCenter: parent.verticalCenter
topMargin: 5
bottomMargin: 5
}
color: {
if (isUnit) {
return "white";
}
return styleData.textColor
}
elide: Text.ElideRight
text: " " + styleData.value
font.bold: isUnit
}
}
onClicked: {
g_trainingSession.phrase = phraseModel.phrase(index)
}
Connections {
target: g_trainingSession
onPhraseChanged: {
phraseTree.expand(phraseModel.indexUnit(g_trainingSession.phrase.unit))
phraseTree.selection.setCurrentIndex(
phraseModel.indexPhrase(g_trainingSession.phrase),
ItemSelectionModel.ClearAndSelect)
}
}
}
TrainerSessionScreen {
id: trainerMain
Layout.alignment: Qt.AlignTop
Layout.preferredWidth: Math.floor(main.width * 0.7) - 30
Layout.fillHeight: true
}
}
}
ToolBar{
id: mainToolBar
RowLayout {
......@@ -218,75 +288,14 @@ ApplicationWindow {
bottomMargin: theme.spacing
}
RowLayout {
id: mainRow
spacing: theme.spacing
TreeView {
id: phraseTree
Layout.preferredWidth: Math.floor(main.width * 0.3)
Layout.fillHeight: true
TableViewColumn {
title: i18n("Categories")
role: "text"
}
model: PhraseModel {
id: phraseModel
course: g_trainingSession.course
}
selection: ItemSelectionModel {
model: phraseTree.model
}
itemDelegate: Item {
property bool isUnit: phraseModel.isUnit(styleData.index)
Component {
id: unitRowBackground
Rectangle {anchors.fill: parent; color: "steelblue"}
}
Loader {
anchors.fill: parent
sourceComponent: isUnit ? unitRowBackground : null
}
Text {
width: phraseTree.width - 100 //TODO check if this is really a reasonable value
anchors {
verticalCenter: parent.verticalCenter
topMargin: 5
bottomMargin: 5
}
color: {
if (isUnit) {
return "white";
}
return styleData.textColor
}
elide: Text.ElideRight
text: " " + styleData.value
font.bold: isUnit
}
}
onClicked: {
g_trainingSession.phrase = phraseModel.phrase(index)
}
Connections {
target: g_trainingSession
onPhraseChanged: {
phraseTree.expand(phraseModel.indexUnit(g_trainingSession.phrase.unit))
phraseTree.selection.setCurrentIndex(
phraseModel.indexPhrase(g_trainingSession.phrase),
ItemSelectionModel.ClearAndSelect)
}
}
}
TrainerSessionScreen {
id: trainerMain
Layout.alignment: Qt.AlignTop
Layout.preferredWidth: Math.floor(main.width * 0.7) - 30
Layout.fillHeight: true
Loader {
Layout.fillHeight: true
sourceComponent: {
g_trainingSession.language == null && courseFilterModel.filteredCount == 0
? welcomeScreen
: trainingScreen
}
}
}
//FIXME setup dialog deactivated for refactoring
......
/*
* Copyright 2015 Andreas Cord-Landwehr <cordlandwehr@kde.org>
*
* 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) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* 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 <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.1
import QtQuick.Controls 1.2
import QtQuick.Layouts 1.2
import artikulate 1.0
Item {
id: root
Layout.fillWidth: true
Layout.fillHeight: true
height: 50
ColumnLayout {
id: row
Text {
text: i18n("Welcome to Artikulate!")
font.pointSize: 24
}
Text {
text: i18n("There are no courses installed on this system.")
}
Text {
text: i18n("You can install them now from the Internet:")
}
Button {
text: i18n("Download Courses")
iconName: "get-hot-new-stuff"
onClicked: triggerDownloadCourses()
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment