X-Git-Url: https://git.sur5r.net/?p=fstl;a=blobdiff_plain;f=src%2Fwindow.cpp;h=0954b33eb92f46b2951f7330c50221dcfc8917fe;hp=3002ecc83daa6008dd3c42c420b933c24605008e;hb=5dd213695da2eb22219ac5143aa8b5cfe7c89559;hpb=967d178c4343c689c728571bb10d5c94ab8d9d13 diff --git a/src/window.cpp b/src/window.cpp index 3002ecc..0954b33 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -6,20 +6,26 @@ #include "canvas.h" #include "loader.h" +const QString Window::RECENT_FILE_KEY = "recentFiles"; + Window::Window(QWidget *parent) : QMainWindow(parent), open_action(new QAction("Open", this)), about_action(new QAction("About", this)), - quit_action(new QAction("Quit", this)) + quit_action(new QAction("Quit", this)), + perspective_action(new QAction("Perspective", this)), + orthogonal_action(new QAction("Orthographic", this)), + reload_action(new QAction("Reload", this)), + autoreload_action(new QAction("Autoreload", this)), + recent_files(new QMenu("Open recent", this)), + recent_files_group(new QActionGroup(this)), + recent_files_clear_action(new QAction("Clear recent files", this)), + watcher(new QFileSystemWatcher(this)) { setWindowTitle("fstl"); setAcceptDrops(true); - QFile styleFile(":/qt/style.qss"); - styleFile.open( QFile::ReadOnly ); - setStyleSheet(styleFile.readAll()); - QGLFormat format; format.setVersion(2, 1); format.setSampleBuffers(true); @@ -27,6 +33,9 @@ Window::Window(QWidget *parent) : canvas = new Canvas(format, this); setCentralWidget(canvas); + QObject::connect(watcher, &QFileSystemWatcher::fileChanged, + this, &Window::on_watched_change); + open_action->setShortcut(QKeySequence::Open); QObject::connect(open_action, &QAction::triggered, this, &Window::on_open); @@ -35,13 +44,50 @@ Window::Window(QWidget *parent) : QObject::connect(quit_action, &QAction::triggered, this, &Window::close); + autoreload_action->setCheckable(true); + autoreload_action->setChecked(true); + autoreload_action->setEnabled(false); + QObject::connect(autoreload_action, &QAction::triggered, + this, &Window::on_autoreload_triggered); + + reload_action->setShortcut(QKeySequence::Refresh); + reload_action->setEnabled(false); + QObject::connect(reload_action, &QAction::triggered, + this, &Window::on_reload); + QObject::connect(about_action, &QAction::triggered, this, &Window::on_about); + QObject::connect(recent_files_clear_action, &QAction::triggered, + this, &Window::on_clear_recent); + QObject::connect(recent_files_group, &QActionGroup::triggered, + this, &Window::on_load_recent); + + rebuild_recent_files(); + auto file_menu = menuBar()->addMenu("File"); file_menu->addAction(open_action); + file_menu->addMenu(recent_files); + file_menu->addSeparator(); + file_menu->addAction(reload_action); + file_menu->addAction(autoreload_action); file_menu->addAction(quit_action); + auto view_menu = menuBar()->addMenu("View"); + auto projection_menu = view_menu->addMenu("Projection"); + projection_menu->addAction(perspective_action); + projection_menu->addAction(orthogonal_action); + auto projections = new QActionGroup(projection_menu); + for (auto p : {perspective_action, orthogonal_action}) + { + projections->addAction(p); + p->setCheckable(true); + } + perspective_action->setChecked(true); + projections->setExclusive(true); + QObject::connect(projections, &QActionGroup::triggered, + this, &Window::on_projection); + auto help_menu = menuBar()->addMenu("Help"); help_menu->addAction(about_action); @@ -65,25 +111,39 @@ void Window::on_about() "
A fast viewer for .stl
files.
"
"https://github.com/mkeeter/fstl
© 2014 Matthew Keeter
"
+ "
© 2014-2017 Matthew Keeter
"
"matt.j.keeter@gmail.com
.stl
file.stl
and retry");
+ "This .stl
file is invalid or corrupted..stl
file is invalid or corrupted..stl
file begins with solid
but appears to be a binary file.fstl
loaded it, but other programs may be confused by this file.");
+}
+
+void Window::on_missing_file()
+{
+ QMessageBox::critical(this, "Error",
+ "Error: