Qt: Tile viewer improvements, magnification
Jeffrey Pfau jeffrey@endrift.com
Tue, 23 Aug 2016 10:31:01 -0700
4 files changed,
82 insertions(+),
16 deletions(-)
M
src/platform/qt/TilePainter.cpp
→
src/platform/qt/TilePainter.cpp
@@ -13,10 +13,12 @@ using namespace QGBA;
TilePainter::TilePainter(QWidget* parent) : QWidget(parent) + , m_size(8) { m_backing = QPixmap(256, 768); m_backing.fill(Qt::transparent); resize(256, 768); + setTileCount(3072); } void TilePainter::paintEvent(QPaintEvent* event) {@@ -25,30 +27,37 @@ painter.drawPixmap(QPoint(), m_backing);
} void TilePainter::resizeEvent(QResizeEvent* event) { - if (width() / 8 != m_backing.width() / 8) { - m_backing = QPixmap(width(), (3072 * 8) / (width() / 8)); + int calculatedHeight = (m_tileCount * m_size) / (width() / m_size) + m_size / 2; + if (width() / m_size != m_backing.width() / m_size || m_backing.height() != calculatedHeight) { + m_backing = QPixmap(width(), calculatedHeight); m_backing.fill(Qt::transparent); } } void TilePainter::mousePressEvent(QMouseEvent* event) { - int x = event->x() / 8; - int y = event->y() / 8; - emit indexPressed(y * (width() / 8) + x); + int x = event->x() / m_size; + int y = event->y() / m_size; + emit indexPressed(y * (width() / m_size) + x); } void TilePainter::setTile(int index, const uint16_t* data) { QPainter painter(&m_backing); - int w = width() / 8; + int w = width() / m_size; int x = index % w; int y = index / w; - QRect r(x * 8, y * 8, 8, 8); + QRect r(x * m_size, y * m_size, m_size, m_size); QImage tile(reinterpret_cast<const uchar*>(data), 8, 8, QImage::Format_RGB555); - painter.fillRect(r, tile.rgbSwapped()); + painter.drawImage(r, tile.rgbSwapped()); update(r); } void TilePainter::setTileCount(int tiles) { - setMinimumSize(16, (tiles * 8) / (width() / 8)); + m_tileCount = tiles; + setMinimumSize(16, (tiles * m_size) / (width() / m_size)); resizeEvent(nullptr); } + +void TilePainter::setTileMagnification(int mag) { + m_size = mag * 8; + setTileCount(m_tileCount); +}
M
src/platform/qt/TilePainter.h
→
src/platform/qt/TilePainter.h
@@ -21,6 +21,7 @@
public slots: void setTile(int index, const uint16_t*); void setTileCount(int tiles); + void setTileMagnification(int mag); signals: void indexPressed(int index);@@ -32,6 +33,8 @@ void resizeEvent(QResizeEvent*) override;
private: QPixmap m_backing; + int m_size; + int m_tileCount; }; }
M
src/platform/qt/TileView.cpp
→
src/platform/qt/TileView.cpp
@@ -26,7 +26,7 @@ GBAVideoTileCacheInit(&m_tileCache);
m_ui.preview->setDimensions(QSize(8, 8)); m_updateTimer.setSingleShot(true); - m_updateTimer.setInterval(10); + m_updateTimer.setInterval(1); connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateTiles())); const QFont font = QFontDatabase::systemFont(QFontDatabase::FixedFont);@@ -38,7 +38,12 @@ connect(m_controller, SIGNAL(frameAvailable(const uint32_t*)), &m_updateTimer, SLOT(start()));
connect(m_controller, SIGNAL(gameStopped(mCoreThread*)), this, SLOT(close())); connect(m_ui.tiles, SIGNAL(indexPressed(int)), this, SLOT(selectIndex(int))); connect(m_ui.paletteId, SIGNAL(valueChanged(int)), this, SLOT(updatePalette(int))); - connect(m_ui.palette256, SIGNAL(toggled(bool)), this, SLOT(updateTiles())); + connect(m_ui.palette256, &QAbstractButton::toggled, [this]() { + updateTiles(true); + }); + connect(m_ui.magnification, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), [this]() { + updateTiles(true); + }); } TileView::~TileView() {@@ -131,5 +136,5 @@ updateTiles(true);
} void TileView::showEvent(QShowEvent*) { - m_updateTimer.start(); + updateTiles(true); }
M
src/platform/qt/TileView.ui
→
src/platform/qt/TileView.ui
@@ -21,7 +21,7 @@ <string>256 colors</string>
</property> </widget> </item> - <item row="2" column="0"> + <item row="3" column="0"> <widget class="QGroupBox" name="groupBox"> <property name="sizePolicy"> <sizepolicy hsizetype="Fixed" vsizetype="Preferred">@@ -116,7 +116,7 @@ <enum>QSlider::TicksBelow</enum>
</property> </widget> </item> - <item row="3" column="0"> + <item row="4" column="0"> <spacer name="verticalSpacer"> <property name="orientation"> <enum>Qt::Vertical</enum>@@ -129,7 +129,7 @@ </size>
</property> </spacer> </item> - <item row="0" column="1" rowspan="4"> + <item row="0" column="1" rowspan="5"> <widget class="QScrollArea" name="scrollArea"> <property name="sizePolicy"> <sizepolicy hsizetype="Minimum" vsizetype="Expanding">@@ -145,7 +145,7 @@ <property name="geometry">
<rect> <x>0</x> <y>0</y> - <width>271</width> + <width>290</width> <height>768</height> </rect> </property>@@ -185,6 +185,36 @@ </layout>
</widget> </widget> </item> + <item row="2" column="0"> + <layout class="QHBoxLayout" name="horizontalLayout_4"> + <item> + <widget class="QSpinBox" name="magnification"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="suffix"> + <string>×</string> + </property> + <property name="minimum"> + <number>1</number> + </property> + <property name="maximum"> + <number>4</number> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Magnification</string> + </property> + </widget> + </item> + </layout> + </item> </layout> </widget> <customwidgets>@@ -193,6 +223,9 @@ <class>QGBA::TilePainter</class>
<extends>QWidget</extends> <header>TilePainter.h</header> <container>1</container> + <slots> + <slot>setTileMagnification(int)</slot> + </slots> </customwidget> <customwidget> <class>QGBA::Swatch</class>@@ -216,6 +249,22 @@ </hint>
<hint type="destinationlabel"> <x>96</x> <y>22</y> + </hint> + </hints> + </connection> + <connection> + <sender>magnification</sender> + <signal>valueChanged(int)</signal> + <receiver>tiles</receiver> + <slot>setTileMagnification(int)</slot> + <hints> + <hint type="sourcelabel"> + <x>36</x> + <y>83</y> + </hint> + <hint type="destinationlabel"> + <x>339</x> + <y>396</y> </hint> </hints> </connection>