9 Window::Window(QWidget *parent) :
12 setWindowTitle("fstl");
15 format.setVersion(2, 1);
16 format.setSampleBuffers(true);
18 canvas = new Canvas(format, this);
19 setCentralWidget(canvas);
21 open_action = new QAction("Open", this);
22 open_action->setShortcut(QKeySequence::Open);
23 QObject::connect(open_action, SIGNAL(triggered()),
24 this, SLOT(on_open()));
26 quit_action = new QAction("Quit", this);
27 quit_action->setShortcut(QKeySequence::Quit);
28 QObject::connect(quit_action, SIGNAL(triggered()),
31 about_action = new QAction("About", this);
32 QObject::connect(about_action, SIGNAL(triggered()),
33 this, SLOT(on_about()));
35 auto file_menu = menuBar()->addMenu("File");
36 file_menu->addAction(open_action);
37 file_menu->addAction(quit_action);
39 auto help_menu = menuBar()->addMenu("Help");
40 help_menu->addAction(about_action);
45 void Window::on_open()
47 QString filename = QFileDialog::getOpenFileName(
48 this, "Load .stl file", QString(), "*.stl");
49 if (not filename.isNull())
55 void Window::on_about()
57 QMessageBox::about(this, "About fstl", "<b>fstl</b><br><br>"
58 "A fast viewer for <code>.stl</code> files.<br>"
59 "<a href=\"https://github.com/mkeeter/fstl\">https://github.com/mkeeter/fstl</a><br><br>"
60 "© 2014 Matthew Keeter<br>"
61 "<a href=\"mailto:matt.j.keeter@gmail.com\">matt.j.keeter@gmail.com</a><br>");
65 void Window::enable_open_action()
67 open_action->setEnabled(true);
71 void Window::disable_open_action()
74 open_action->setEnabled(false);
78 void Window::load_stl(const QString &filename)
80 Loader* loader = new Loader(this, filename);
81 connect(loader, SIGNAL(started()),
82 this, SLOT(disable_open_action()));
83 connect(loader, SIGNAL(got_mesh(Mesh*)),
84 canvas, SLOT(load_mesh(Mesh*)));
85 connect(loader, SIGNAL(finished()),
86 loader, SLOT(deleteLater()));
87 connect(loader, SIGNAL(finished()),
88 this, SLOT(enable_open_action()));
89 connect(loader, SIGNAL(loaded_file(QString)),
90 this, SLOT(setWindowTitle(QString)));