From 95cbffd047e456c07c01fa2b9308ae28357e9e36 Mon Sep 17 00:00:00 2001 From: dgelessus Date: Tue, 5 Mar 2024 22:39:19 +0100 Subject: [PATCH] Display mipmap preview levels as tabs instead of using a spinner --- src/PrpShop/PRP/Surface/QMipmap.cpp | 37 ++++++++++++++++------------- src/PrpShop/PRP/Surface/QMipmap.h | 1 - 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/PrpShop/PRP/Surface/QMipmap.cpp b/src/PrpShop/PRP/Surface/QMipmap.cpp index cd0bbaa..d7d75d8 100644 --- a/src/PrpShop/PRP/Surface/QMipmap.cpp +++ b/src/PrpShop/PRP/Surface/QMipmap.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -134,31 +135,33 @@ QMipmap_Preview::QMipmap_Preview(plCreatable* pCre, QWidget* parent) fTexture = new QTextureBox(scroll); scroll->setWidget(fTexture); - QWidget* levelWidget = new QWidget(this); - QGridLayout* levelLayout = new QGridLayout(levelWidget); - levelLayout->setContentsMargins(4, 4, 4, 4); - levelLayout->setHorizontalSpacing(8); - QSpinBox* levelSel = new QSpinBox(levelWidget); - if (tex->getCompressionType() == plBitmap::kJPEGCompression) - levelSel->setRange(0, 0); - else - levelSel->setRange(0, tex->getNumLevels() - 1); - connect(levelSel, QOverload::of(&QSpinBox::valueChanged), + QTabBar* levelSel = new QTabBar(this); + for (size_t level = 0; level < tex->getNumLevels(); level++) { + levelSel->insertTab(level, QString("%1x%2 (%3)") + .arg(tex->getLevelWidth(level)) + .arg(tex->getLevelHeight(level)) + .arg(level)); + } + connect(levelSel, &QTabBar::currentChanged, this, &QMipmap_Preview::setLevel); - levelLayout->addWidget(new QLabel(tr("Level:"), levelWidget), 0, 0); - levelLayout->addWidget(levelSel, 0, 1); - levelSel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum); - QLinkLabel* saveAsLink = new QLinkLabel(tr("Save As..."), levelWidget); - levelLayout->addWidget(saveAsLink, 1, 0, 1, 2); + + QWidget* saveAsWidget = new QWidget(this); + QGridLayout* saveAsLayout = new QGridLayout(saveAsWidget); + saveAsLayout->setContentsMargins(4, 4, 4, 4); + saveAsLayout->setHorizontalSpacing(8); + QLinkLabel* saveAsLink = new QLinkLabel(tr("Save As..."), saveAsWidget); + saveAsLayout->addWidget(saveAsLink, 0, 0); connect(fTexture, &QTextureBox::textureChanged, saveAsLink, &QWidget::setEnabled); connect(saveAsLink, &QLinkLabel::activated, fTexture, &QTextureBox::saveAs); + fTexture->setTexture(tex); QGridLayout* layout = new QGridLayout(this); layout->setContentsMargins(0, 0, 0, 0); layout->setVerticalSpacing(0); - layout->addWidget(levelWidget, 0, 0); - layout->addWidget(scroll, 1, 0); + layout->addWidget(levelSel, 0, 0); + layout->addWidget(saveAsWidget, 1, 0); + layout->addWidget(scroll, 2, 0); } void QMipmap_Preview::setLevel(int level) diff --git a/src/PrpShop/PRP/Surface/QMipmap.h b/src/PrpShop/PRP/Surface/QMipmap.h index 0858a26..b8fcf91 100644 --- a/src/PrpShop/PRP/Surface/QMipmap.h +++ b/src/PrpShop/PRP/Surface/QMipmap.h @@ -21,7 +21,6 @@ #include #include -#include #include "PRP/QObjLink.h" #include "QBitmaskCheckBox.h"