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

Add optional main menu bar.

Port to ApplicationWindow and use menuBar property that connects
to hand-crafted menu and enable all help menu actions.
parent d7c05b48
/*
* Copyright 2013 Andreas Cord-Landwehr <cordlandwehr@kde.org>
* Copyright 2013-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
......@@ -53,12 +53,7 @@ int main(int argc, char **argv)
Application app(argc, argv);
KAboutData::setApplicationData(aboutData);
// qmlRegisterType<MainWindow>("artikulate", 1, 0, "MainWindow");
MainWindow *mainWindow = new MainWindow();
QSize size(800, 600);
mainWindow->setMinimumSize(size);
mainWindow->show();
new MainWindow();
return app.exec();
}
......@@ -35,6 +35,7 @@
#include <KActionCollection>
#include <KConfigDialog>
#include <KDeclarative/KDeclarative>
#include <KHelpMenu>
#include <KLocalizedString>
#include <KMessageBox>
#include <KNS3/DownloadDialog>
......@@ -59,12 +60,11 @@ using namespace LearnerProfile;
MainWindow::MainWindow()
: m_actionCollection(new KActionCollection(this, "artikulate"))
, m_helpMenu(new KHelpMenu)
, m_resourceManager(new ResourceManager(this))
, m_trainingSession(new TrainingSession(this))
, m_profileManager(new LearnerProfile::ProfileManager(this))
{
setResizeMode(QQuickView::SizeRootObjectToView);
// load saved sound settings
OutputDeviceController::self().setVolume(Settings::audioOutputVolume());
......@@ -77,24 +77,21 @@ MainWindow::MainWindow()
m_resourceManager->registerLearningGoals(m_profileManager);
KDeclarative::KDeclarative kdeclarative;
kdeclarative.setDeclarativeEngine(engine());
kdeclarative.setDeclarativeEngine(this);
kdeclarative.setupBindings(); //TODO use result for determining touch/desktop version
// create menu
setupActions();
// set view
resize(QSize(800, 600));
rootContext()->setContextProperty("g_resourceManager", m_resourceManager);
rootContext()->setContextProperty("g_trainingSession", m_trainingSession);
rootContext()->setContextProperty("profileManager", m_profileManager);
rootContext()->setContextProperty("kcfg_UseContributorResources", Settings::useCourseRepository());
rootContext()->setContextProperty("kcfg_ShowMenuBar", Settings::showMenuBar());
// set starting screen
setSource(QUrl::fromLocalFile(QStandardPaths::locate(QStandardPaths::DataLocation, "qml/Main.qml")));
show();
load(QUrl::fromLocalFile(QStandardPaths::locate(QStandardPaths::DataLocation, "qml/Main.qml")));
// settings from kcfg values
// updateTrainingPhraseFont(); //FIXME deactivated while porting
......@@ -105,22 +102,20 @@ MainWindow::MainWindow()
}
// connect to QML signals
connect(rootObject(), SIGNAL(triggerDownloadCourses()),
connect(rootObjects().first(), SIGNAL(triggerDownloadCourses()),
this, SLOT(downloadNewStuff()));
connect(rootObject(), SIGNAL(triggerSettingsDialog()),
connect(rootObjects().first(), SIGNAL(triggerSettingsDialog()),
this, SLOT(showSettingsDialog()));
connect(rootObject(), SIGNAL(triggerAction(QString)),
connect(rootObjects().first(), SIGNAL(triggerAction(QString)),
this, SLOT(triggerAction(QString)));
connect(rootObject(), SIGNAL(switchMenuBarVisibility()),
connect(rootObjects().first(), SIGNAL(switchMenuBarVisibility()),
this, SLOT(switchMenuBarVisibility()));
// set font for the phrase in trainer to default from kcfg file
QObject *phraseText = rootObject()->findChild<QObject*>("phraseText");
QObject *phraseText = rootObjects().first()->findChild<QObject*>("phraseText");
if (phraseText) {
phraseText->setProperty("font", Settings::trainingPhraseFont());
}
// menuBar()->setVisible(Settings::showMenuBar());
}
MainWindow::~MainWindow()
......@@ -157,6 +152,11 @@ void MainWindow::setupActions()
actionCollection()->addAction("config_learner_profile", configLearnerProfileAction);
configLearnerProfileAction->setIcon(QIcon::fromTheme("user-identity"));
KStandardAction::helpContents(m_helpMenu, SLOT(appHelpActivated()), actionCollection());
KStandardAction::reportBug(m_helpMenu, SLOT(reportBug()), actionCollection());
KStandardAction::aboutKDE(m_helpMenu, SLOT(aboutKDE()), actionCollection());
KStandardAction::aboutApp(m_helpMenu, SLOT(aboutApplication()), actionCollection());
KStandardAction::quit(qApp, SLOT(quit()), actionCollection());
}
......@@ -194,7 +194,7 @@ void MainWindow::showSettingsDialog()
void MainWindow::updateTrainingPhraseFont()
{
QObject *phraseText = rootObject()->findChild<QObject*>("phraseText");
QObject *phraseText = rootObjects().first()->findChild<QObject*>("phraseText");
if (!phraseText) {
qDebug() << "no phraseText context object found, aborting";
return;
......@@ -263,7 +263,7 @@ void MainWindow::triggerAction(const QString &actionName)
void MainWindow::switchMenuBarVisibility()
{
Settings::setShowMenuBar(!Settings::showMenuBar());
// menuBar()->setVisible(Settings::showMenuBar());
rootContext()->setContextProperty("kcfg_ShowMenuBar", Settings::showMenuBar());
}
bool MainWindow::queryClose()
......
/*
* Copyright 2013 Andreas Cord-Landwehr <cordlandwehr@kde.org>
* Copyright 2013-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
......@@ -21,17 +21,18 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QQuickView>
#include <QQmlApplicationEngine>
#include <KActionCollection>
#include "core/resourcemanager.h"
class TrainingSession;
class KHelpMenu;
namespace LearnerProfile {
class ProfileManager;
}
class MainWindow : public QQuickView
class MainWindow : public QQmlApplicationEngine
{
Q_OBJECT
......@@ -50,9 +51,6 @@ public:
KActionCollection * actionCollection();
void setupActions();
virtual QSize sizeHint() const { return QSize(1000, 700); }
bool queryClose();
public Q_SLOTS:
......@@ -61,11 +59,12 @@ public Q_SLOTS:
void updateTrainingPhraseFont();
void updateKcfgUseContributorResources();
void configLearnerProfile();
void triggerAction(const QString &);
void switchMenuBarVisibility();
void triggerAction(const QString &);
private:
KActionCollection *m_actionCollection;
KHelpMenu *m_helpMenu;
ResourceManager *m_resourceManager;
TrainingSession *m_trainingSession;
LearnerProfile::ProfileManager *m_profileManager;
......
......@@ -34,6 +34,7 @@ set(artikulate_qml_files
CourseSwitcher.qml
LanguageSwitcher.qml
FlatButton.qml
MainMenuBar.qml
PhraseEditor.qml
PhraseEditorSoundComponent.qml
PhraseEditorTypeComponent.qml
......
......@@ -25,10 +25,11 @@ import QtQml.Models 2.2
import org.kde.kquickcontrolsaddons 2.0
import artikulate 1.0
Item {
ApplicationWindow {
id: root
width: 400 //parent.width
height: 600 //parent.height
visible: true
minimumWidth: 600
minimumHeight: 400
signal triggerDownloadCourses();
signal triggerSettingsDialog();
......@@ -60,6 +61,13 @@ Item {
id: availableCourseModel
resourceManager: g_resourceManager
}
// main menu bar
MainMenuBar {
id: topMenu
}
menuBar: { kcfg_ShowMenuBar ? topMenu : null }
ToolBar{
id: mainToolBar
RowLayout {
......@@ -128,11 +136,12 @@ Item {
onTriggered: triggerDownloadCourses()
}
MenuSeparator { }
MenuItem {
text: i18n("Configure Shortcuts...")
iconName: "configure-shortcuts"
onTriggered: triggerAction("options_configure_keybinding")
}
// TODO requires proper support of KKeySequenceWidget's settings
// MenuItem {
// text: i18n("Configure Shortcuts...")
// iconName: "configure-shortcuts"
// onTriggered: triggerAction("options_configure_keybinding")
// }
MenuItem {
text: i18n("Configure Artikulate...")
iconName: "settings-configure"
......@@ -197,6 +206,7 @@ Item {
rightMargin: theme.spacing
bottomMargin: theme.spacing
}
RowLayout {
id: mainRow
spacing: theme.spacing
......
/*
* 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.5
import QtQuick.Controls 1.2
MenuBar {
id: root
Menu {
title: i18n("File")
MenuItem {
text: i18n("Quit")
iconName: "application-exit"
shortcut: StandardKey.Quit
onTriggered: triggerAction("file_quit")
}
}
Menu {
title: i18n("Settings")
MenuItem {
text: i18n("Download Courses")
iconName: "get-hot-new-stuff"
onTriggered: triggerDownloadCourses()
}
MenuSeparator { }
// TODO requires proper support of KKeySequenceWidget's settings
// MenuItem {
// text: i18n("Configure Shortcuts...")
// iconName: "configure-shortcuts"
// onTriggered: triggerAction("options_configure_keybinding")
// }
MenuItem {
text: i18n("Configure Artikulate...")
iconName: "settings-configure"
onTriggered: triggerSettingsDialog()
}
MenuSeparator { }
MenuItem {
text: i18n("Show Menubar")
iconName: "show-menu"
checkable: true
checked: kcfg_ShowMenuBar
onTriggered: {
switchMenuBarVisibility()
}
}
}
Menu {
title: i18n("Help")
MenuItem {
text: i18n("Artikulate Handbook")
iconName: "help-contents"
shortcut: StandardKey.HelpContents
onTriggered: triggerAction("help_contents")
}
MenuSeparator { }
MenuItem {
text: i18n("Report Bug")
iconName: "tools-report-bug"
onTriggered: triggerAction("help_report_bug")
}
MenuSeparator { }
MenuItem {
text: i18n("About Artikulate")
iconName: "artikulate"
onTriggered: triggerAction("help_about_app")
}
MenuItem {
text: i18n("About KDE")
iconName: "help-about"
onTriggered: triggerAction("help_about_kde")
}
}
}
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