Commit 76944895 authored by Stefan Pfeifer's avatar Stefan Pfeifer

Visual improvements to the layer legend

parent 1674e13d
Pipeline #40773578 passed with stage
in 11 minutes and 17 seconds
......@@ -12,64 +12,23 @@ QColor getLayerColor(const Layer& layer)
return QColor::fromHsvF(uni(rng), 0.8, 1.0);
}
/*
std::vector<QColor> getLayerColors(const Layers& layers)
{
double h_min = 0.0;
double h_max = 0.2;
double s_min = 0.5;
double s_max = 1.0;
auto cmp_rho = [](const Layer& lhs, const Layer& rhs){ return lhs.rho < rhs.rho; };
auto cmp_E = [](const Layer& lhs, const Layer& rhs){ return lhs.E < rhs.E; };
double rho_min = std::min_element(layers.begin(), layers.end(), cmp_rho)->rho;
double rho_max = std::max_element(layers.begin(), layers.end(), cmp_rho)->rho;
double E_min = std::min_element(layers.begin(), layers.end(), cmp_E)->E;
double E_max = std::max_element(layers.begin(), layers.end(), cmp_E)->E;
std::vector<QColor> colors;
for(auto& layer: layers)
{
double h = (E_min < E_max)
? h_min + (layer.E - E_min)/(E_max - E_min)*(h_max - h_min)
: 0.5*(h_min + h_max);
double s = (rho_min < rho_max)
? s_min + (layer.rho - rho_min)/(rho_max - rho_min)*(s_max - s_min)
: 0.5*(s_min + s_max);
qInfo() << "h = " << h;
qInfo() << "s = " << s;
colors.push_back(QColor::fromHsvF(h, s, 1.0));
}
return colors;
}
*/
QPixmap getLayerPixmap(const Layer& layer)
{
// https://stackoverflow.com/a/29196812/4692009
// https://stackoverflow.com/a/37213313/4692009
const double size = 48.0;
const QColor color = getLayerColor(layer);
const int size = 48;
const int line_width = 2;
const qreal rounding = 0.2;
QPixmap pixmap(size, size);
pixmap.fill(Qt::transparent);
QPainter painter(&pixmap);
painter.setRenderHint(QPainter::Antialiasing);
//painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
painter.fillRect(QRectF{0.0, 0.0, size, size}, color);
//QPainterPath path;
//path.addRoundedRect(QRectF(0, 0, size, size), 0.3*size, 0.3*size);
//painter.setPen(Qt::NoPen);
//painter.fillPath(path, color);
//painter.drawPath(path);
painter.setPen({Qt::black, line_width});
painter.setBrush(getLayerColor(layer));
QPainterPath path;
path.addRoundedRect({line_width/2, line_width/2, size - line_width, size - line_width},
rounding*size, rounding*size);
painter.drawPath(path);
return pixmap;
}
......@@ -4,20 +4,17 @@ LayerEntry::LayerEntry()
: symbol(new QLabel()),
label(new QLabel())
{
int size = symbol->sizeHint().height();
symbol->setFixedWidth(size);
symbol->setFixedHeight(size);
symbol->setFixedWidth(18); // Magic number
symbol->setFixedHeight(18); // Magic number
symbol->setScaledContents(true);
label->setAutoFillBackground(false);
label->setStyleSheet("background-color: rgba(0, 0, 0, 0)");
label->setStyleSheet("color: white; font: 18px; max-height: 18px; background-color: transparent;");
auto hbox = new QHBoxLayout();
hbox->setMargin(0);
hbox->setMargin(2); // Magic number
hbox->addWidget(symbol, 0);
hbox->addSpacing(10); // Magic number
hbox->addWidget(label, 1);
this->setLayout(hbox);
this->setStyleSheet("background-color: rgba(0, 0, 0, 0)");
}
void LayerEntry::setData(const Layer& layer)
......@@ -30,7 +27,6 @@ LayerLegend::LayerLegend()
: vbox(new QVBoxLayout())
{
this->setLayout(vbox);
this->setStyleSheet("background-color: rgba(0, 0, 0, 0)");
}
void LayerLegend::setData(const Layers& layers)
......
......@@ -53,7 +53,7 @@ LimbView::LimbView()
auto vbox = new QVBoxLayout();
this->setLayout(vbox);
vbox->setMargin(20);
vbox->setMargin(25);
vbox->addWidget(legend);
vbox->addStretch();
vbox->addLayout(hbox);
......
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