diff options
author | Samuel Rødal <sroedal@trolltech.com> | 2008-06-24 13:43:28 +0200 |
---|---|---|
committer | Samuel Rødal <sroedal@trolltech.com> | 2008-06-24 13:43:28 +0200 |
commit | 76be46027f110a00bc3f4b6c2d3a2af1b513ff3c (patch) | |
tree | e7a9352c8c5575e34ec620660e00e0c343ab72e5 | |
parent | a45e186faf0b6d4e261420cbacda941b8d2db264 (diff) |
Some more polish.
-rw-r--r-- | main.cpp | 11 | ||||
-rw-r--r-- | openglscene.cpp | 49 | ||||
-rw-r--r-- | openglscene.h | 2 |
3 files changed, 27 insertions, 35 deletions
@@ -1,9 +1,18 @@ #include "openglscene.h" -#include <QtOpenGL> +#include <QApplication> +#include <QGLWidget> +#include <QGraphicsView> +#include <QResizeEvent> class GraphicsView : public QGraphicsView { +public: + GraphicsView() + { + setWindowTitle(tr("OpenGL Scene")); + } + protected: void resizeEvent(QResizeEvent *event) { if (scene()) diff --git a/openglscene.cpp b/openglscene.cpp index adc442e..4e45cb1 100644 --- a/openglscene.cpp +++ b/openglscene.cpp @@ -13,7 +13,7 @@ #define GL_MULTISAMPLE 0x809D #endif -class Controls : public QGroupBox +class Controls : public QWidget { Q_OBJECT @@ -41,15 +41,15 @@ private: Controls::Controls(OpenGLScene *scene) : m_scene(scene) , m_models(new QComboBox) - , m_modelColor(qRgb(180, 100, 255)) - , m_backgroundColor(qRgb(0, 0, 0)) - , m_dir("models") + , m_modelColor(QColor::fromCmykF(0.40, 0.0, 1.0, 0.0).rgba()) + , m_backgroundColor(QColor::fromCmykF(0.39, 0.39, 0.0, 0.0).rgba()) + , m_dir(QLatin1String("models")) { QVBoxLayout *layout = new QVBoxLayout(this); - layout->addWidget(new QLabel("Model:")); + layout->addWidget(new QLabel(tr("Model:"))); - m_dir.setNameFilters(QStringList() << "*.obj"); + m_dir.setNameFilters(QStringList() << QLatin1String("*.obj")); m_models->addItems(m_dir.entryList()); connect(m_models, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(loadModel(const QString &))); #ifndef QT_NO_CONCURRENT @@ -60,22 +60,17 @@ Controls::Controls(OpenGLScene *scene) loadModel(m_models->currentText()); layout->addWidget(m_models); - QCheckBox *autoRotate = new QCheckBox("Auto-rotate"); - autoRotate->setChecked(true); - connect(autoRotate, SIGNAL(toggled(bool)), m_scene, SLOT(enableAutoRotate(bool))); - layout->addWidget(autoRotate); - - QCheckBox *wireframe = new QCheckBox("Render as wireframe"); + QCheckBox *wireframe = new QCheckBox(tr("Render as wireframe")); wireframe->setChecked(true); connect(wireframe, SIGNAL(toggled(bool)), m_scene, SLOT(enableWireframe(bool))); layout->addWidget(wireframe); - QCheckBox *normals = new QCheckBox("Display normals vectors"); + QCheckBox *normals = new QCheckBox(tr("Display normals vectors")); wireframe->setChecked(false); connect(normals, SIGNAL(toggled(bool)), m_scene, SLOT(enableNormals(bool))); layout->addWidget(normals); - layout->addWidget(new QLabel("Light position:")); + layout->addWidget(new QLabel(tr("Light position:"))); QSlider *lightPosition = new QSlider(Qt::Horizontal); lightPosition->setRange(-100, 100); connect(lightPosition, SIGNAL(valueChanged(int)), m_scene, SLOT(setLightPosition(int))); @@ -83,12 +78,12 @@ Controls::Controls(OpenGLScene *scene) m_scene->setLightPosition(lightPosition->value()); - QPushButton *colorButton = new QPushButton("Choose model color"); + QPushButton *colorButton = new QPushButton(tr("Choose model color")); connect(colorButton, SIGNAL(pressed()), this, SLOT(setModelColor())); layout->addWidget(colorButton); setModelColor(false); - QPushButton *backgroundButton = new QPushButton("Choose background color"); + QPushButton *backgroundButton = new QPushButton(tr("Choose background color")); connect(backgroundButton, SIGNAL(pressed()), this, SLOT(setBackgroundColor())); layout->addWidget(backgroundButton); setBackgroundColor(false); @@ -106,7 +101,7 @@ void Controls::loadModel(const QString &filename) #ifndef QT_NO_CONCURRENT m_modelLoader.setFuture(QtConcurrent::run(::loadModel, m_dir.filePath(filename))); #else - m_scene->setModel(::loadModel(filename)); + m_scene->setModel(::loadModel(m_dir.filePath(filename))); modelLoaded(); #endif } @@ -139,11 +134,10 @@ void Controls::setBackgroundColor(bool showDialog) OpenGLScene::OpenGLScene() : m_wireframeEnabled(true) , m_normalsEnabled(false) - , m_autoRotate(true) , m_rotating(false) , m_axis(0.0f, 1.0f, 0.0f) , m_angle(20.0f) - , m_distance(1.5f) + , m_distance(1.4f) , m_model(0) , m_lastTime(0) { @@ -179,7 +173,7 @@ void OpenGLScene::updateMatrix(qreal delta) void OpenGLScene::drawBackground(QPainter *painter, const QRectF &) { if (painter->paintEngine()->type() != QPaintEngine::OpenGL) { - qWarning() << "OpenGLScene: drawBackground needs a QGLWidget to be set as viewport on the graphics view"; + qWarning("OpenGLScene: drawBackground needs a QGLWidget to be set as viewport on the graphics view"); return; } @@ -202,7 +196,7 @@ void OpenGLScene::drawBackground(QPainter *painter, const QRectF &) unsigned int delta = current - m_lastTime; m_lastTime = current; - if (m_autoRotate && !m_rotating) + if (!m_rotating) updateMatrix(delta / 1000.0); glLoadIdentity(); @@ -219,11 +213,8 @@ void OpenGLScene::drawBackground(QPainter *painter, const QRectF &) glMatrixMode(GL_PROJECTION); glPopMatrix(); - if (m_autoRotate) + if (m_angle != 0) QTimer::singleShot(20, this, SLOT(update())); - - painter->paintEngine()->setDirty(QPaintEngine::AllDirty); - painter->paintEngine()->syncState(); } void OpenGLScene::setModel(Model *model) @@ -233,12 +224,6 @@ void OpenGLScene::setModel(Model *model) update(); } -void OpenGLScene::enableAutoRotate(bool enabled) -{ - m_autoRotate = enabled; - update(); -} - void OpenGLScene::enableWireframe(bool enabled) { m_wireframeEnabled = enabled; @@ -296,7 +281,7 @@ void OpenGLScene::updateRotation(const QPointF &last, const QPointF ¤t) if (length == 0) { m_angle = 0; } else { - m_angle = -10 * asin(sqrt(length)); + m_angle = -20 * asin(sqrt(length)); m_axis.x /= length; m_axis.y /= length; diff --git a/openglscene.h b/openglscene.h index 5be1c53..ef014d8 100644 --- a/openglscene.h +++ b/openglscene.h @@ -19,7 +19,6 @@ public: public slots: void setModel(Model *model); - void enableAutoRotate(bool enabled); void enableWireframe(bool enabled); void enableNormals(bool enabled); void setLightPosition(int pos); @@ -38,7 +37,6 @@ private: bool m_wireframeEnabled; bool m_normalsEnabled; - bool m_autoRotate; bool m_rotating; Point3d m_axis; |