Qt: Optimize palette view drawing

This commit is contained in:
Jeffrey Pfau 2015-04-27 23:13:25 -07:00
parent 57999df85e
commit 8b19ad7809
4 changed files with 31 additions and 43 deletions

View File

@ -41,6 +41,8 @@ void PaletteView::updatePalette() {
m_ui.bgGrid->setColor(i, palette[i]);
m_ui.objGrid->setColor(i, palette[i + 256]);
}
m_ui.bgGrid->update();
m_ui.objGrid->update();
}
void PaletteView::selectIndex(int index) {

View File

@ -31,6 +31,12 @@
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Background</string>
</property>
@ -48,22 +54,13 @@
<number>0</number>
</property>
<item>
<widget class="QGBA::Swatch" name="bgGrid">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<widget class="QGBA::Swatch" name="bgGrid" native="true">
<property name="minimumSize">
<size>
<width>175</width>
<height>175</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
@ -101,22 +98,13 @@
<number>0</number>
</property>
<item>
<widget class="QGBA::Swatch" name="objGrid">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<widget class="QGBA::Swatch" name="objGrid" native="true">
<property name="minimumSize">
<size>
<width>175</width>
<height>175</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
@ -155,9 +143,9 @@
<property name="title">
<string>Selection</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QGBA::Swatch" name="selected">
<widget class="QGBA::Swatch" name="selected" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -170,36 +158,33 @@
<height>64</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line">
<widget class="Line" name="line_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_5">
<layout class="QVBoxLayout" name="verticalLayout_9">
<item>
<widget class="QLabel" name="label_3">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Red</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Green</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Blue</string>
</property>
@ -208,7 +193,7 @@
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_7">
<layout class="QVBoxLayout" name="verticalLayout_10">
<property name="leftMargin">
<number>8</number>
</property>
@ -236,30 +221,30 @@
</layout>
</item>
<item>
<widget class="Line" name="line_2">
<widget class="Line" name="line_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_8">
<layout class="QVBoxLayout" name="verticalLayout_11">
<item>
<widget class="QLabel" name="label_11">
<widget class="QLabel" name="label_14">
<property name="text">
<string>16-bit value</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_12">
<widget class="QLabel" name="label_15">
<property name="text">
<string>Hex code</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_13">
<widget class="QLabel" name="label_16">
<property name="text">
<string>Palette index</string>
</property>
@ -268,7 +253,7 @@
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_6">
<layout class="QVBoxLayout" name="verticalLayout_12">
<property name="leftMargin">
<number>8</number>
</property>
@ -312,8 +297,9 @@
<customwidgets>
<customwidget>
<class>QGBA::Swatch</class>
<extends>QLabel</extends>
<extends>QWidget</extends>
<header>Swatch.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>

View File

@ -11,7 +11,7 @@
using namespace QGBA;
Swatch::Swatch(QWidget* parent)
: QLabel(parent)
: QWidget(parent)
{
m_size = 10;
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
@ -42,8 +42,8 @@ void Swatch::setColor(int index, uint16_t color) {
}
void Swatch::paintEvent(QPaintEvent* event) {
setPixmap(m_backing);
QLabel::paintEvent(event);
QPainter painter(this);
painter.drawPixmap(QPoint(), m_backing);
}
void Swatch::mousePressEvent(QMouseEvent* event) {

View File

@ -7,12 +7,12 @@
#define QGBA_SWATCH
#include <QColor>
#include <QLabel>
#include <QWidget>
#include <QVector>
namespace QGBA {
class Swatch : public QLabel {
class Swatch : public QWidget {
Q_OBJECT
public: