Add New and Quit menu items to menu bar
This commit is contained in:
parent
c1f9630634
commit
e0addbdea2
@ -16,7 +16,7 @@
|
|||||||
using namespace nostalgia::studio;
|
using namespace nostalgia::studio;
|
||||||
using namespace ox::clargs;
|
using namespace ox::clargs;
|
||||||
|
|
||||||
int main(int argc, char **args) {
|
int run(int argc, char **args) {
|
||||||
ClArgs clargs(argc, (const char**) args);
|
ClArgs clargs(argc, (const char**) args);
|
||||||
QString argProfilePath = clargs.getString("profile").c_str();
|
QString argProfilePath = clargs.getString("profile").c_str();
|
||||||
|
|
||||||
@ -38,3 +38,7 @@ int main(int argc, char **args) {
|
|||||||
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **args) {
|
||||||
|
return run(argc, args);
|
||||||
|
}
|
||||||
|
@ -6,13 +6,18 @@
|
|||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDesktopWidget>
|
#include <QDesktopWidget>
|
||||||
|
#include <QDialog>
|
||||||
|
#include <QMenuBar>
|
||||||
#include "mainwindow.hpp"
|
#include "mainwindow.hpp"
|
||||||
|
|
||||||
namespace nostalgia {
|
namespace nostalgia {
|
||||||
namespace studio {
|
namespace studio {
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
MainWindow::MainWindow(NostalgiaStudioProfile config, QWidget *parent) {
|
MainWindow::MainWindow(NostalgiaStudioProfile config, QWidget *parent) {
|
||||||
auto screenSize = QApplication::desktop()->screenGeometry();
|
auto screenSize = QApplication::desktop()->screenGeometry();
|
||||||
|
|
||||||
@ -23,9 +28,66 @@ MainWindow::MainWindow(NostalgiaStudioProfile config, QWidget *parent) {
|
|||||||
move(screenSize.width() * (1 - sizePct) / 2, screenSize.height() * (1 - sizePct) / 2);
|
move(screenSize.width() * (1 - sizePct) / 2, screenSize.height() * (1 - sizePct) / 2);
|
||||||
|
|
||||||
setWindowTitle(config.app_name);
|
setWindowTitle(config.app_name);
|
||||||
|
|
||||||
|
setupMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow() {
|
MainWindow::~MainWindow() {
|
||||||
|
for (auto f : m_cleanupTasks) {
|
||||||
|
f();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::setupMenu() {
|
||||||
|
auto menu = menuBar();
|
||||||
|
auto fileMenu = menu->addMenu(tr("&File"));
|
||||||
|
|
||||||
|
// New...
|
||||||
|
addAction(
|
||||||
|
fileMenu,
|
||||||
|
tr("&New..."),
|
||||||
|
tr(""),
|
||||||
|
QKeySequence::New,
|
||||||
|
this,
|
||||||
|
SLOT(showNewDialog())
|
||||||
|
);
|
||||||
|
|
||||||
|
// Exit
|
||||||
|
addAction(
|
||||||
|
fileMenu,
|
||||||
|
tr("E&xit"),
|
||||||
|
tr("Exit the application"),
|
||||||
|
QKeySequence::Quit,
|
||||||
|
QApplication::quit
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::addAction(QMenu *menu, QString text, QString toolTip,
|
||||||
|
QKeySequence::StandardKey key, const QObject *tgt, const char *cb) {
|
||||||
|
auto action = menu->addAction(text);
|
||||||
|
action->setShortcuts(key);
|
||||||
|
action->setStatusTip(toolTip);
|
||||||
|
auto conn = connect(action, SIGNAL(triggered()), tgt, cb);
|
||||||
|
m_cleanupTasks.push_back([this, conn]() {
|
||||||
|
QObject::disconnect(conn);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::addAction(QMenu *menu, QString text, QString toolTip,
|
||||||
|
QKeySequence::StandardKey key, void (*cb)()) {
|
||||||
|
auto action = menu->addAction(text);
|
||||||
|
action->setShortcuts(key);
|
||||||
|
action->setStatusTip(toolTip);
|
||||||
|
auto conn = connect(action, &QAction::triggered, cb);
|
||||||
|
m_cleanupTasks.push_back([this, conn]() {
|
||||||
|
QObject::disconnect(conn);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::showNewDialog() {
|
||||||
|
QDialog dialog;
|
||||||
|
dialog.show();
|
||||||
|
dialog.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <ox/std/types.hpp>
|
#include <ox/std/types.hpp>
|
||||||
@ -12,6 +13,8 @@
|
|||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QPoint>
|
#include <QPoint>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QVector>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
namespace nostalgia {
|
namespace nostalgia {
|
||||||
namespace studio {
|
namespace studio {
|
||||||
@ -36,6 +39,7 @@ class MainWindow: public QMainWindow {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_projectPath;
|
QString m_projectPath;
|
||||||
|
QVector<std::function<void()>> m_cleanupTasks;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MainWindow(NostalgiaStudioProfile config, QWidget *parent = 0);
|
MainWindow(NostalgiaStudioProfile config, QWidget *parent = 0);
|
||||||
@ -45,10 +49,21 @@ class MainWindow: public QMainWindow {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void setupDockWidgets();
|
void setupDockWidgets();
|
||||||
|
|
||||||
|
void setupMenu();
|
||||||
|
|
||||||
|
void addAction(QMenu *menu, QString text, QString toolTip,
|
||||||
|
QKeySequence::StandardKey key, const QObject *tgt, const char *cb);
|
||||||
|
|
||||||
|
void addAction(QMenu *menu, QString text, QString toolTip,
|
||||||
|
QKeySequence::StandardKey key, void (*cb)());
|
||||||
|
|
||||||
int readSettings(QString path);
|
int readSettings(QString path);
|
||||||
|
|
||||||
int writeSettings(QString path);
|
int writeSettings(QString path);
|
||||||
|
|
||||||
public slots:
|
private slots:
|
||||||
|
void showNewDialog();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user