Commit 96b7d6f7 authored by Anakin's avatar Anakin
Browse files

text in FileInfoWindow can be marked and copied,

code cleaning
parent 121f5c47
...@@ -47,6 +47,9 @@ Triangles: -</string> ...@@ -47,6 +47,9 @@ Triangles: -</string>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property> </property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
......
#pragma once #pragma once
#include <QWidget> #include <QWidget>
#include <QString>
#include "ui_FileInfoWindow.h" #include "ui_FileInfoWindow.h"
class FileInfoWindow : public QWidget class FileInfoWindow : public QWidget
...@@ -8,13 +7,21 @@ class FileInfoWindow : public QWidget ...@@ -8,13 +7,21 @@ class FileInfoWindow : public QWidget
Q_OBJECT Q_OBJECT
public: public:
FileInfoWindow(QWidget *parent = Q_NULLPTR); FileInfoWindow(QWidget *parent = Q_NULLPTR)
~FileInfoWindow(); : QWidget(parent)
, ui(new Ui::FileInfoWindow)
{
ui->setupUi(this);
setWindowFlags(Qt::Tool | Qt::NoDropShadowWindowHint);
ui->scrollArea->widget()->setStyleSheet("background-color: #ffffff");
};
~FileInfoWindow() { delete ui; };
private: private:
Ui::FileInfoWindow* ui; Ui::FileInfoWindow* ui;
public: public:
void setBasicText(QString text); void setBasicText(QString text) { ui->basic->setText(text); };
void setDetailText(QString text); void setDetailText(QString text) { ui->detail->setText(text); };
}; };
\ No newline at end of file
#pragma once #pragma once
#include <QObject>
#include <QOpenGlTexture>
#include <fstream> #include <fstream>
#include <QVector> #include <QVector>
#include <QVector2D> #include <QVector2D>
#include <QVector3D>
#include <QMatrix4x4> #include <QMatrix4x4>
#include <QQuaternion> #include <QQuaternion>
#include <QOpenGLFunctions>
#include <QOpenGlTexture>
#include <QObject>
#include <QOpenGLTexture>
#include <QRegExp> #include <QRegExp>
#include <..\Header\MainWindow.h> #include "MainWindow.h"
struct BoundingBox { struct BoundingBox {
QQuaternion rotation; QQuaternion rotation;
......
#pragma once #pragma once
#include "..\Header\FileInterface.h"
#include <QObject> #include <QObject>
#include <QOpenGLFunctions> #include <QOpenGLFunctions>
#include <QOpenGLShaderProgram> #include <QOpenGLShaderProgram>
#include <QOpenGLBuffer> #include <QOpenGLBuffer>
#include <QOpenGLTexture>
#include <QVector> #include <QVector>
#include "FileInterface.h"
struct DrawInformation { struct DrawInformation {
unsigned int offset; unsigned int offset;
...@@ -22,20 +22,28 @@ public: ...@@ -22,20 +22,28 @@ public:
GeometryEngine(QObject *parent = Q_NULLPTR); GeometryEngine(QObject *parent = Q_NULLPTR);
virtual ~GeometryEngine(); virtual ~GeometryEngine();
// attributes
private: private:
QOpenGLBuffer m_arrayBuf; QOpenGLBuffer m_arrayBuf;
QOpenGLBuffer m_indexBuf; QOpenGLBuffer m_indexBuf;
QVector<Material>* m_materials = Q_NULLPTR; QVector<Material>* m_materials = Q_NULLPTR;
QVector<DrawInformation> m_drawList;
BoundingBox m_boundings;
Material* m_defaultMaterial; Material* m_defaultMaterial;
BoundingBox m_boundings;
QVector<DrawInformation> m_drawList;
// functions
private:
void clearData(); void clearData();
public:
void drawGeometry(QOpenGLShaderProgram *program, bool wireframe);
// slots
public slots: public slots:
void loadFile(QString filePath); void loadFile(QString filePath);
void drawGeometry(QOpenGLShaderProgram *program, bool wireframe);
// signals
signals: signals:
void requestResetView(); void requestResetView();
void sendMessage(QString message, int severity); void sendMessage(QString message, int severity);
......
#pragma once #pragma once
#include <QtWidgets/QMainWindow> #include <QtWidgets/QMainWindow>
#include <qwidget.h> #include <QWidget>
#include "ui_MainWindow.h"
#include "FileInfoWindow.h"
#include <QByteArray> #include <QByteArray>
#include <QStringList>
#include <QLabel> #include <QLabel>
#include "ui_MainWindow.h"
#include "..\Header\FileInfoWindow.h"
struct Material; struct Material;
...@@ -18,27 +17,32 @@ public: ...@@ -18,27 +17,32 @@ public:
MainWindow(QWidget *parent = Q_NULLPTR); MainWindow(QWidget *parent = Q_NULLPTR);
~MainWindow(); ~MainWindow();
// attributes
private: private:
Ui::MainWindowClass* ui; Ui::MainWindowClass* ui;
int m_curSeverity;
void setupWidgets();
QByteArray m_fileInfo; QByteArray m_fileInfo;
QLabel* m_output; QLabel* m_output;
int m_curSeverity;
FileInfoWindow* m_infoWindow; FileInfoWindow* m_infoWindow;
// functions
private: private:
void setupWidgets();
void openFile(); void openFile();
void aboutFile();
void aboutTool();
void takeScreenShot(); void takeScreenShot();
void aboutTool();
protected: protected:
virtual void resizeEvent(QResizeEvent * e) Q_DECL_OVERRIDE; virtual void resizeEvent(QResizeEvent * e) Q_DECL_OVERRIDE;
// slots
public slots: public slots:
void printMessage(QString message, int severity); void printMessage(QString message, int severity);
void setFileInfo(QString name, QVector<Material>* materials, int vertices, int triangle); void setFileInfo(QString name, QVector<Material>* materials, int vertices, int triangle);
// signals
signals: signals:
void loadFile(QString); void loadFile(QString);
}; };
#pragma once #pragma once
#include "geometryengine.h"
#include "..\Header\SettingsWindow.h"
#include <QOpenGLWidget> #include <QOpenGLWidget>
#include <QOpenGLFunctions> #include <QOpenGLFunctions>
#include <QMatrix4x4>
#include <QQuaternion>
#include <QVector2D>
#include <QBasicTimer>
#include <QOpenGLShaderProgram> #include <QOpenGLShaderProgram>
#include <QMatrix4x4>
#include "GeometryEngine.h"
#include "SettingsWindow.h"
class GeometryEngine; class GeometryEngine;
...@@ -21,21 +17,16 @@ public: ...@@ -21,21 +17,16 @@ public:
explicit OglViewerWidget(QWidget *parent = 0); explicit OglViewerWidget(QWidget *parent = 0);
~OglViewerWidget(); ~OglViewerWidget();
signals: // attributes
void loadFile(QString);
private: private:
struct { QOpenGLShaderProgram m_program;
bool left = false; GeometryEngine *m_dataEngine;
bool right = false;
QVector2D position;
} m_mouse;
struct { QVector4D m_backgroundColorOn = { 0.02f, 0.02f, 0.02f, 1.0f };
bool x = true; QVector4D m_backgroundColorOff = { 0.5f, 0.8f, 1.0f, 1.0f };
bool y = true;
bool z = true; bool m_wireframe = false;
} m_rotDirections; bool m_lightOn = false;
struct { struct {
QVector4D position = { 1,1,1,0 }; QVector4D position = { 1,1,1,0 };
...@@ -46,44 +37,49 @@ private: ...@@ -46,44 +37,49 @@ private:
SettingsWindow* m_settings; SettingsWindow* m_settings;
QVector4D m_backgroundColorOn = {0.02f, 0.02f, 0.02f, 1.0f}; struct {
QVector4D m_backgroundColorOff = { 0.5f, 0.8f, 1.0f, 1.0f }; bool left = false;
bool right = false;
QVector2D position;
} m_mouse;
QOpenGLShaderProgram m_program; struct {
GeometryEngine *m_dataEngine; bool x = true;
bool y = true;
bool z = true;
} m_rotDirections;
QMatrix4x4 m_projection; QMatrix4x4 m_projection;
QVector3D m_translation; QVector3D m_translation;
QQuaternion m_rotation; QQuaternion m_rotation;
bool m_wireframe = false;
bool m_lightOn = false;
double m_zSpeed = 1.0; double m_zSpeed = 1.0;
// functions
private:
void initShaders();
void setConnections();
void resetView();
void updateLightPosition();
protected: protected:
void initializeGL() Q_DECL_OVERRIDE;
void resizeGL(int w, int h) Q_DECL_OVERRIDE;
void paintGL() Q_DECL_OVERRIDE;
void mousePressEvent(QMouseEvent *e) Q_DECL_OVERRIDE; void mousePressEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
void mouseReleaseEvent(QMouseEvent *e) Q_DECL_OVERRIDE; void mouseReleaseEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
void mouseMoveEvent(QMouseEvent *e) Q_DECL_OVERRIDE; void mouseMoveEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
void wheelEvent(QWheelEvent *e) Q_DECL_OVERRIDE; void wheelEvent(QWheelEvent *e) Q_DECL_OVERRIDE;
void dragEnterEvent(QDragEnterEvent *e) Q_DECL_OVERRIDE;
void dropEvent(QDropEvent * event) Q_DECL_OVERRIDE;
void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE; void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE;
void initializeGL() Q_DECL_OVERRIDE; void dragEnterEvent(QDragEnterEvent *e) Q_DECL_OVERRIDE;
void resizeGL(int w, int h) Q_DECL_OVERRIDE; void dropEvent(QDropEvent * event) Q_DECL_OVERRIDE;
void paintGL() Q_DECL_OVERRIDE;
private:
void initShaders();
void setConnections();
void updateLightPosition();
private slots:
void resetView();
// slots
public slots: public slots:
void changeDirection(int direction); void toggleAxis(int axis);
void toggleWireframe(); void toggleWireframe();
void toggleLight(); void toggleLight();
void showSettings(); void showSettings();
...@@ -93,7 +89,9 @@ public slots: ...@@ -93,7 +89,9 @@ public slots:
void setAttFac(double value); void setAttFac(double value);
void setAmbCoef(double value); void setAmbCoef(double value);
// signals
signals: signals:
void sendMessage(QString message, int severity); void sendMessage(QString message, int severity);
void loadFile(QString);
}; };
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "ui_SettingsWindow.h" #include "ui_SettingsWindow.h"
#include <QVector3D> #include <QVector3D>
class SettingsWindow : public QWidget class SettingsWindow : public QWidget
{ {
Q_OBJECT Q_OBJECT
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
#include <QImage> #include <QImage>
#include <QColor> #include <QColor>
#include <iostream>
QImage loadTga(QString filePath, bool &success) QImage loadTga(QString filePath, bool &success)
{ {
...@@ -67,7 +66,7 @@ QImage loadTga(QString filePath, bool &success) ...@@ -67,7 +66,7 @@ QImage loadTga(QString filePath, bool &success)
int valb = vui8Pixels.at(y * ui32Width * ui32BpP / 8 + x * ui32BpP / 8); int valb = vui8Pixels.at(y * ui32Width * ui32BpP / 8 + x * ui32BpP / 8);
QColor value(valr, valg, valb); QColor value(valr, valg, valb);
img.setPixelColor(x, ui32Width - 1 - y, value); img.setPixel(x, ui32Width - 1 - y, value.rgba());
} }
} }
} }
...@@ -97,7 +96,7 @@ QImage loadTga(QString filePath, bool &success) ...@@ -97,7 +96,7 @@ QImage loadTga(QString filePath, bool &success)
else else
color.setRgb(qRgb(tempData[2], tempData[1], tempData[0])); color.setRgb(qRgb(tempData[2], tempData[1], tempData[0]));
img.setPixelColor(tmp_pixelIndex % ui32Width, ui32Height - 1 - (tmp_pixelIndex / ui32Width), color); img.setPixel(tmp_pixelIndex % ui32Width, ui32Height - 1 - (tmp_pixelIndex / ui32Width), color.rgba());
tmp_pixelIndex++; tmp_pixelIndex++;
} }
} }
...@@ -117,7 +116,7 @@ QImage loadTga(QString filePath, bool &success) ...@@ -117,7 +116,7 @@ QImage loadTga(QString filePath, bool &success)
else else
color.setRgb(qRgb(tempData[2], tempData[1], tempData[0])); color.setRgb(qRgb(tempData[2], tempData[1], tempData[0]));
img.setPixelColor(tmp_pixelIndex % ui32Width, ui32Height - 1 - (tmp_pixelIndex / ui32Width), color); img.setPixel(tmp_pixelIndex % ui32Width, ui32Height - 1 - (tmp_pixelIndex / ui32Width), color.rgba());
tmp_pixelIndex++; tmp_pixelIndex++;
} }
} }
......
QLabel#output {
color : white;
min-width: 400px;
min-height: 50px;
}
QToolButton { QToolButton {
image: url(:/images/toolbar/placeholder.png); image: url(:/images/toolbar/placeholder.png);
border-style: none; border-style: none;
......
#include "..\Header\FileInfoWindow.h"
#include <QIcon>
FileInfoWindow::FileInfoWindow(QWidget *parent)
: QWidget(parent)
, ui(new Ui::FileInfoWindow)
{
ui->setupUi(this);
setWindowFlags(Qt::Tool | Qt::NoDropShadowWindowHint);
ui->scrollArea->widget()->setStyleSheet("background-color: #ffffff");
}
FileInfoWindow::~FileInfoWindow()
{
delete ui;
}
void FileInfoWindow::setBasicText(QString text)
{
ui->basic->setText(text);
}
void FileInfoWindow::setDetailText(QString text)
{
ui->detail->setText(text);
}
...@@ -2,20 +2,18 @@ ...@@ -2,20 +2,18 @@
#include "..\Header\MshFile.h" #include "..\Header\MshFile.h"
#include "..\Header\OglViewerWidget.h" #include "..\Header\OglViewerWidget.h"
#include "..\Header\MainWindow.h" #include "..\Header\MainWindow.h"
#include <cmath>
#include <QRegExp> #include <QRegExp>
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// public constructor/destructor // constructor/destructor
GeometryEngine::GeometryEngine(QObject *parent) GeometryEngine::GeometryEngine(QObject *parent)
: QObject(parent) : QObject(parent)
, m_indexBuf(QOpenGLBuffer::IndexBuffer) , m_indexBuf(QOpenGLBuffer::IndexBuffer)
, m_defaultMaterial(FileInterface::getDefaultMaterial())
{ {
initializeOpenGLFunctions(); initializeOpenGLFunctions();
m_defaultMaterial = FileInterface::getDefaultMaterial();
} }
GeometryEngine::~GeometryEngine() GeometryEngine::~GeometryEngine()
...@@ -27,7 +25,7 @@ GeometryEngine::~GeometryEngine() ...@@ -27,7 +25,7 @@ GeometryEngine::~GeometryEngine()
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// private functions // functions
void GeometryEngine::clearData() void GeometryEngine::clearData()
{ {
...@@ -52,94 +50,12 @@ void GeometryEngine::clearData() ...@@ -52,94 +50,12 @@ void GeometryEngine::clearData()
m_drawList.clear(); m_drawList.clear();
} }
/////////////////////////////////////////////////////////////////////////
// public slots
void GeometryEngine::loadFile(QString filePath)
{
// cleanup old stuff and recreate buffers
clearData();
m_arrayBuf.create();
m_indexBuf.create();
//reset view
emit requestResetView();
emit sendMessage("loading file..", 0);
try
{
QVector<Model*>* models;
QVector<VertexData> vertexData;
QVector<GLuint> indexData;
// open file and get the information
MshFile file(filePath, this);
models = file.getModels();
m_materials = file.getMaterials();
m_boundings = file.getBoundingBox();
// collect data
unsigned int indexOffset(0);
unsigned int vertexOffset(0);
for (auto& modelIterator : *models)
{
for (auto& segmentIterator : modelIterator->segmList)
{
// get draw information
DrawInformation new_info;
new_info.offset = indexOffset;
new_info.size = segmentIterator->indices.size();
new_info.textureIndex = segmentIterator->textureIndex;
new_info.modelMatrix = modelIterator->m4x4Translation;
new_info.modelMatrix.rotate(modelIterator->quadRotation);
// add offset to indices, no need to do it for the first one (maybe it's very big)
if (vertexOffset != 0)
for (auto& it : segmentIterator->indices)
it += vertexOffset;
// save data
vertexData += segmentIterator->vertices;
indexData += segmentIterator->indices;
if (segmentIterator->textureIndex < (unsigned) m_materials->size() && m_materials->at(segmentIterator->textureIndex).transparent)
m_drawList.push_back(new_info);
else
m_drawList.push_front(new_info);
// update offset
indexOffset += new_info.size;
vertexOffset += segmentIterator->vertices.size();
}
}
// Transfer vertex data to VBO 0
m_arrayBuf.bind();
m_arrayBuf.allocate(vertexData.data(), vertexData.size() * sizeof(VertexData));