From: Matt Keeter Date: Fri, 7 Mar 2014 17:17:09 +0000 (-0600) Subject: Adding Open command to menu X-Git-Tag: v0.9.0~38 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=8239cb87b70c0661a3f576f08c63183a6dcfeb3c;p=fstl Adding Open command to menu --- diff --git a/src/main.cpp b/src/main.cpp index 35a853a..8653dd0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,6 +11,5 @@ int main(int argc, char *argv[]) Window window; window.show(); - window.load_stl("../../splitter/cayman.stl"); return a.exec(); } diff --git a/src/window.cpp b/src/window.cpp index b4d7c99..eb4d9dc 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -1,3 +1,6 @@ +#include +#include + #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); diff --git a/src/window.h b/src/window.h index 809aeb7..be43084 100644 --- a/src/window.h +++ b/src/window.h @@ -12,6 +12,9 @@ public: explicit Window(QWidget* parent=0); void load_stl(const QString& filename); +public slots: + void on_open(); + private: Canvas* canvas; };