]> git.sur5r.net Git - fstl/commitdiff
Adding Open command to menu
authorMatt Keeter <matt.j.keeter@gmail.com>
Fri, 7 Mar 2014 17:17:09 +0000 (11:17 -0600)
committerMatt Keeter <matt.j.keeter@gmail.com>
Fri, 7 Mar 2014 17:17:09 +0000 (11:17 -0600)
src/main.cpp
src/window.cpp
src/window.h

index 35a853a5c9a1407daf4fa8c2c66d6c45fdcd6e14..8653dd02dfab599b7bb06c1dca6aea2e1a62172a 100644 (file)
@@ -11,6 +11,5 @@ int main(int argc, char *argv[])
     Window window;
     window.show();
 
-    window.load_stl("../../splitter/cayman.stl");
     return a.exec();
 }
index b4d7c99e889005a9c4cf69d6276f88da18bb43dc..eb4d9dc862ca5c452065cbb3afe887f393653284 100644 (file)
@@ -1,3 +1,6 @@
+#include <QMenuBar>
+#include <QFileDialog>
+
 #include "window.h"
 #include "canvas.h"
 #include "loader.h"
@@ -14,9 +17,26 @@ Window::Window(QWidget *parent) :
     canvas = new Canvas(format, this);
     setCentralWidget(canvas);
 
+    QAction* open_action = new QAction("Open", this);
+    open_action->setShortcut(QKeySequence::Open);
+    QObject::connect(open_action, SIGNAL(triggered()),
+                     this, SLOT(on_open()));
+    auto file_menu = menuBar()->addMenu("File");
+    file_menu->addAction(open_action);
+
     resize(600, 400);
 }
 
+void Window::on_open()
+{
+    QString filename = QFileDialog::getOpenFileName(
+                this, "Load .stl file", QString(), "*.stl");
+    if (not filename.isNull())
+    {
+        load_stl(filename);
+    }
+}
+
 void Window::load_stl(const QString &filename)
 {
     Loader* loader = new Loader(this, filename);
index 809aeb74d3f37cf0b0d6cc78fd23b329eef3a009..be43084a00e4f5afbcc13c226c99ae47f378ee5a 100644 (file)
@@ -12,6 +12,9 @@ public:
     explicit Window(QWidget* parent=0);
     void load_stl(const QString& filename);
 
+public slots:
+    void on_open();
+
 private:
     Canvas* canvas;
 };