Skip to content

Commit

Permalink
Merge pull request #80 from dgelessus/mipmap_preview_tabs
Browse files Browse the repository at this point in the history
Display mipmap preview levels as tabs instead of using a spinner
  • Loading branch information
zrax authored Mar 7, 2024
2 parents 26de95a + 95cbffd commit 933c21f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
37 changes: 20 additions & 17 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 <QTabBar>
#include <QFileDialog>
#include <QMessageBox>
#include <QRegularExpression>
Expand Down Expand Up @@ -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<int>::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)
Expand Down
1 change: 0 additions & 1 deletion 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 Down

0 comments on commit 933c21f

Please sign in to comment.