Skip to content

Commit

Permalink
Display mipmap preview levels as tabs instead of using a spinner
Browse files Browse the repository at this point in the history
  • Loading branch information
dgelessus committed Mar 5, 2024
1 parent 228f0e5 commit 1ff4602
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 50 deletions.
75 changes: 33 additions & 42 deletions src/PrpShop/PRP/Surface/QMipmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <QGridLayout>
#include <QPainter>
#include <QSettings>
#include <QTabWidget>
#include <QFileDialog>
#include <QMessageBox>
#include <QRegularExpression>
Expand Down Expand Up @@ -54,7 +55,7 @@ QTextureBox::~QTextureBox()
delete[] fImageData;
}

void QTextureBox::setTexture(plMipmap* tex, int level)
void QTextureBox::setTexture(plMipmap* tex, size_t level)
{
delete fImage;
delete[] fImageData;
Expand All @@ -67,15 +68,8 @@ void QTextureBox::setTexture(plMipmap* tex, int level)
return;
}

if (level >= (int)tex->getNumLevels())
if (level >= tex->getNumLevels())
level = tex->getNumLevels() - 1;
if (level < 0) {
fImage = NULL;
fImageData = NULL;
update();
emit textureChanged(false);
return;
}

size_t size = tex->GetUncompressedSize(level);
fImageData = new unsigned char[size];
Expand Down Expand Up @@ -126,45 +120,42 @@ void QTextureBox::paintEvent(QPaintEvent* evt)

/* QMipmap_Preview */
QMipmap_Preview::QMipmap_Preview(plCreatable* pCre, QWidget* parent)
: QCreatable(pCre, kPreviewMipmap, parent), fLevel()
: QCreatable(pCre, kPreviewMipmap, parent)
{
plMipmap* tex = plMipmap::Convert(fCreatable);

QScrollArea* scroll = new QScrollArea(this);
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<int>::of(&QSpinBox::valueChanged),
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);
connect(fTexture, &QTextureBox::textureChanged, saveAsLink, &QWidget::setEnabled);
connect(saveAsLink, &QLinkLabel::activated, fTexture, &QTextureBox::saveAs);
fTexture->setTexture(tex);
auto levelTabs = new QTabWidget(this);
for (size_t level = 0; level < tex->getNumLevels(); level++) {
auto levelTab = new QWidget(levelTabs);
levelTabs->addTab(levelTab, QString("%1x%2 (%3)")
.arg(tex->getLevelWidth(level))
.arg(tex->getLevelHeight(level))
.arg(level));

QScrollArea* scroll = new QScrollArea(levelTab);
fTexture = new QTextureBox(scroll);
scroll->setWidget(fTexture);

QWidget* saveAsWidget = new QWidget(levelTab);
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, level);

QGridLayout* levelTabLayout = new QGridLayout(levelTab);
levelTabLayout->setContentsMargins(0, 0, 0, 0);
levelTabLayout->setVerticalSpacing(0);
levelTabLayout->addWidget(saveAsWidget, 0, 0);
levelTabLayout->addWidget(scroll, 1, 0);
}

QGridLayout* layout = new QGridLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setVerticalSpacing(0);
layout->addWidget(levelWidget, 0, 0);
layout->addWidget(scroll, 1, 0);
}

void QMipmap_Preview::setLevel(int level)
{
fLevel = level;
fTexture->setTexture(plMipmap::Convert(fCreatable), fLevel);
layout->addWidget(levelTabs, 0, 0);
}


Expand Down
9 changes: 1 addition & 8 deletions src/PrpShop/PRP/Surface/QMipmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

#include <PRP/Surface/plMipmap.h>
#include <QImage>
#include <QSpinBox>
#include "PRP/QObjLink.h"
#include "QBitmaskCheckBox.h"

Expand All @@ -38,7 +37,7 @@ class QTextureBox : public QWidget
: QWidget(parent), fImage(), fImageData() { }

~QTextureBox();
void setTexture(plMipmap* tex, int level = 0);
void setTexture(plMipmap* tex, size_t level = 0);

public slots:
void saveAs();
Expand All @@ -56,15 +55,9 @@ class QMipmap_Preview : public QCreatable

protected:
QTextureBox* fTexture;
int fLevel;

public:
QMipmap_Preview(plCreatable* pCre, QWidget* parent = NULL);

int level() const { return fLevel; }

public slots:
void setLevel(int level);
};

class QMipmap : public QCreatable
Expand Down

0 comments on commit 1ff4602

Please sign in to comment.