Commit 1674e13d authored by Stefan Pfeifer's avatar Stefan Pfeifer

Implement widget-based layer legend for the limb view

parent 10852b77
Pipeline #40641402 passed with stage
in 10 minutes and 59 seconds
......@@ -151,6 +151,8 @@ add_library(
source/gui/input/editors/TreeEditor.cpp
source/gui/input/editors/TreeEditor.hpp
source/gui/input/editors/TreeItem.hpp
source/gui/input/views/LayerLegend.cpp
source/gui/input/views/LayerLegend.hpp
source/gui/input/views/LimbView.cpp
source/gui/input/views/LimbView.hpp
source/gui/input/views/LimbMesh.cpp
......
#include "LayerLegend.hpp"
LayerEntry::LayerEntry()
: symbol(new QLabel()),
label(new QLabel())
{
int size = symbol->sizeHint().height();
symbol->setFixedWidth(size);
symbol->setFixedHeight(size);
symbol->setScaledContents(true);
label->setAutoFillBackground(false);
label->setStyleSheet("background-color: rgba(0, 0, 0, 0)");
auto hbox = new QHBoxLayout();
hbox->setMargin(0);
hbox->addWidget(symbol, 0);
hbox->addWidget(label, 1);
this->setLayout(hbox);
this->setStyleSheet("background-color: rgba(0, 0, 0, 0)");
}
void LayerEntry::setData(const Layer& layer)
{
symbol->setPixmap(getLayerPixmap(layer));
label->setText(QString::fromStdString(layer.name));
}
LayerLegend::LayerLegend()
: vbox(new QVBoxLayout())
{
this->setLayout(vbox);
this->setStyleSheet("background-color: rgba(0, 0, 0, 0)");
}
void LayerLegend::setData(const Layers& layers)
{
while(vbox->count() < layers.size())
vbox->addWidget(new LayerEntry());
while(vbox->count() > layers.size())
{
QWidget* widget = vbox->takeAt(0)->widget();
widget->setParent(nullptr);
widget->deleteLater();
}
for(int i = 0; i < vbox->count(); ++i)
{
LayerEntry* layer = dynamic_cast<LayerEntry*>(vbox->itemAt(i)->widget());
layer->setData(layers[i]);
}
vbox->update();
}
#pragma once
#include "bow/input/Layers.hpp"
#include "LayerColors.hpp"
#include <QtWidgets>
class LayerEntry: public QWidget
{
public:
LayerEntry();
void setData(const Layer& layer);
private:
QLabel* symbol;
QLabel* label;
};
class LayerLegend: public QWidget
{
public:
LayerLegend();
void setData(const Layers& layers);
private:
QVBoxLayout* vbox;
};
......@@ -7,7 +7,8 @@
#include <math.h>
LimbView::LimbView()
: shader_program(nullptr)
: legend(new LayerLegend()),
shader_program(nullptr)
{
auto button0 = new QToolButton();
QObject::connect(button0, &QPushButton::clicked, this, &LimbView::viewProfile);
......@@ -42,7 +43,6 @@ LimbView::LimbView()
auto hbox = new QHBoxLayout();
hbox->setAlignment(Qt::AlignBottom);
hbox->setMargin(15);
hbox->addStretch();
hbox->addWidget(button0);
hbox->addWidget(button1);
......@@ -50,7 +50,13 @@ LimbView::LimbView()
hbox->addWidget(button3);
hbox->addSpacing(20);
hbox->addWidget(button4);
this->setLayout(hbox);
auto vbox = new QVBoxLayout();
this->setLayout(vbox);
vbox->setMargin(20);
vbox->addWidget(legend);
vbox->addStretch();
vbox->addLayout(hbox);
view3D();
}
......@@ -62,7 +68,9 @@ LimbView::~LimbView()
void LimbView::setData(const InputData& data)
{
legend->setData(data.layers);
limb_mesh.setData(data);
limb_mesh_vbo.create();
limb_mesh_vbo.bind();
limb_mesh_vbo.allocate(limb_mesh.vertexData().data(), limb_mesh.vertexData().size()*sizeof(GLfloat));
......@@ -241,9 +249,6 @@ void LimbView::mouseMoveEvent(QMouseEvent *event)
{
rot_x += ROT_SPEED*delta_y;
rot_y += ROT_SPEED*delta_x;
qInfo() << rot_x << ", " << rot_y;
update();
}
else if(event->buttons() & Qt::MiddleButton)
......
#pragma once
#include "bow/input/InputData.hpp"
#include "LimbMesh.hpp"
#include "LayerLegend.hpp"
#include <QtWidgets>
#include <QOpenGLWidget>
......@@ -15,11 +16,11 @@ QT_FORWARD_DECLARE_CLASS(QOpenGLShaderProgram)
class LimbView: public QOpenGLWidget, protected QOpenGLFunctions
{
private:
const float DEFAULT_ROT_X = 20.0f; // Magic number
const float DEFAULT_ROT_X = 20.0f; // Magic number
const float DEFAULT_ROT_Y = -30.0f; // Magic number
const float DEFAULT_ZOOM = 1.1f; // Magic number
const float ZOOM_SPEED = 0.2f; // Magic number
const float ROT_SPEED = 0.15f; // Magic number
const float DEFAULT_ZOOM = 1.1f; // Magic number
const float ZOOM_SPEED = 0.2f; // Magic number
const float ROT_SPEED = 0.15f; // Magic number
public:
LimbView();
......@@ -42,6 +43,8 @@ private:
void mouseMoveEvent(QMouseEvent *event) override;
void wheelEvent(QWheelEvent* event) override;
LayerLegend* legend;
LimbMesh limb_mesh;
QOpenGLBuffer limb_mesh_vbo;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment