viewer.cc
#include <thread>
#include <QtGui/QKeyEvent>
#include "viewer.hh"
Viewer::Viewer(QWidget *parent) : QGLViewer(parent) { }
void Viewer::init() {
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);
}
void Viewer::draw() {
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glBegin(GL_POLYGON);
glVertex3f(-0.5, -0.5, 0.0); glVertex3f( 0.5, -0.5, 0.0);
glVertex3f( 0.5, 0.5, 0.0); glVertex3f(-0.5, 0.5, 0.0);
glEnd();
}
QString Viewer::helpString() const {
return "<h2>Geometry Framework</h2> ...";
}
viewer.cc
(folytatás)void Viewer::keyPressEvent(QKeyEvent *e) {
using namespace std::literals::chrono_literals;
if (e->modifiers() == Qt::NoModifier)
switch (e->key()) {
case Qt::Key_P:
emit startComputation(tr("Testing progress bar..."));
for (size_t i = 1; i <= 10; ++i) {
std::this_thread::sleep_for(0.3s);
emit midComputation(i * 10);
}
emit endComputation();
break;
default:
QGLViewer::keyPressEvent(e);
} else
QGLViewer::keyPressEvent(e);
}
window.hh
#include "viewer.hh"
class Window : public QMainWindow {
private:
Viewer *viewer;
// ...
};
window.cc
Window::Window(QApplication *parent) : QMainWindow(), parent(parent) {
viewer = new Viewer(this);
connect(viewer, &Viewer::startComputation, this, &Window::startComputation);
connect(viewer, &Viewer::midComputation, this, &Window::midComputation);
connect(viewer, &Viewer::endComputation, this, &Window::endComputation);
setCentralWidget(viewer);
// ...
}