9 Window::Window(QWidget *parent) :
12 setWindowTitle("fstl");
14 QFile styleFile( ":/style.qss" );
15 styleFile.open( QFile::ReadOnly );
16 setStyleSheet(styleFile.readAll());
19 format.setVersion(2, 1);
20 format.setSampleBuffers(true);
22 canvas = new Canvas(format, this);
23 setCentralWidget(canvas);
25 open_action = new QAction("Open", this);
26 open_action->setShortcut(QKeySequence::Open);
27 QObject::connect(open_action, SIGNAL(triggered()),
28 this, SLOT(on_open()));
30 quit_action = new QAction("Quit", this);
31 quit_action->setShortcut(QKeySequence::Quit);
32 QObject::connect(quit_action, SIGNAL(triggered()),
35 about_action = new QAction("About", this);
36 QObject::connect(about_action, SIGNAL(triggered()),
37 this, SLOT(on_about()));
39 auto file_menu = menuBar()->addMenu("File");
40 file_menu->addAction(open_action);
41 file_menu->addAction(quit_action);
43 auto help_menu = menuBar()->addMenu("Help");
44 help_menu->addAction(about_action);
49 void Window::on_open()
51 QString filename = QFileDialog::getOpenFileName(
52 this, "Load .stl file", QString(), "*.stl");
53 if (not filename.isNull())
59 void Window::on_about()
61 QMessageBox::about(this, "",
62 "<p align=\"center\"><b>fstl</b></p>"
63 "<p>A fast viewer for <code>.stl</code> files.<br>"
64 "<a href=\"https://github.com/mkeeter/fstl\""
65 " style=\"color: #93a1a1;\">https://github.com/mkeeter/fstl</a></p>"
66 "<p>© 2014 Matthew Keeter<br>"
67 "<a href=\"mailto:matt.j.keeter@gmail.com\""
68 " style=\"color: #93a1a1;\">matt.j.keeter@gmail.com</a></p>");
72 void Window::enable_open_action()
74 open_action->setEnabled(true);
78 void Window::disable_open_action()
80 open_action->setEnabled(false);
84 void Window::load_stl(const QString &filename)
86 Loader* loader = new Loader(this, filename);
87 connect(loader, SIGNAL(started()),
88 this, SLOT(disable_open_action()));
89 connect(loader, SIGNAL(got_mesh(Mesh*)),
90 canvas, SLOT(load_mesh(Mesh*)));
91 connect(loader, SIGNAL(finished()),
92 loader, SLOT(deleteLater()));
93 connect(loader, SIGNAL(finished()),
94 this, SLOT(enable_open_action()));
95 connect(loader, SIGNAL(loaded_file(QString)),
96 this, SLOT(setWindowTitle(QString)));