Device view resizes width to fit window size, UI updates on SDKcontroller update

This commit is contained in:
Adam Honse 2020-07-13 14:24:19 -05:00
parent 17f1390f36
commit d3993547c3
6 changed files with 56 additions and 39 deletions

View file

@ -17,20 +17,9 @@
DeviceView::DeviceView(QWidget *parent) :
QWidget(parent),
initSize(128,128),
mouseDown(false),
margin(0),
wheelWidth(10),
current(Qt::red),
inWheel(false),
inSquare(false)
mouseDown(false)
{
controller = NULL;
current = current.toHsv();
}
QColor DeviceView::color()
{
return current;
}
void DeviceView::setController(RGBController * controller_ptr)
@ -60,12 +49,7 @@ void DeviceView::mouseMoveEvent(QMouseEvent *event)
void DeviceView::mouseReleaseEvent(QMouseEvent *)
{
/*-----------------------------------------------------*\
| Clear mouse down and in-region flags |
\*-----------------------------------------------------*/
mouseDown = false;
inWheel = false;
inSquare = false;
}
void DeviceView::resizeEvent(QResizeEvent *event)
@ -81,19 +65,18 @@ void DeviceView::resizeEvent(QResizeEvent *event)
size = event->size().height();
}
wheel = QPixmap(event->size());
wheel.fill(Qt::transparent);
update();
}
void DeviceView::paintEvent(QPaintEvent *)
void DeviceView::paintEvent(QPaintEvent *event)
{
#define MAX_COLS 100
int width = event->rect().width();
int height = event->rect().height();
int row = 0;
int col = 0;
int box_size = 20;
int box_margin = 2;
int max_cols = ( width / (box_size + box_margin) ) - 1;
QPainter painter(this);
QStyleOption opt;
@ -109,7 +92,7 @@ void DeviceView::paintEvent(QPaintEvent *)
painter.drawRect((col * (box_size + box_margin)), (row * (box_size + box_margin)), box_size, box_size);
col++;
if(col > MAX_COLS)
if(col > max_cols)
{
row++;
col = 0;

View file

@ -12,11 +12,8 @@ public:
virtual QSize sizeHint () const;
virtual QSize minimumSizeHint () const;
QColor color();
void setController(RGBController * controller_ptr);
signals:
void colorChanged(const QColor color);
protected:
void mousePressEvent(QMouseEvent *event);
@ -26,20 +23,8 @@ protected:
void paintEvent(QPaintEvent *);
private:
QSize initSize;
QImage wheelImage;
QImage squareImage;
QPixmap wheel;
bool mouseDown;
QPoint lastPos;
int margin;
int wheelWidth;
QRegion wheelRegion;
QRegion squareRegion;
QColor current;
bool inWheel;
bool inSquare;
int x_offset;
int y_offset;
RGBController* controller;

View file

@ -4,6 +4,13 @@
using namespace Ui;
static void UpdateCallback(void * this_ptr)
{
OpenRGBDevicePage * this_obj = (OpenRGBDevicePage *)this_ptr;
QMetaObject::invokeMethod(this_obj, "UpdateInterface", Qt::QueuedConnection);
}
OpenRGBDevicePage::OpenRGBDevicePage(RGBController *dev, QWidget *parent) :
QFrame(parent),
ui(new Ui::OpenRGBDevicePageUi)
@ -22,6 +29,8 @@ OpenRGBDevicePage::OpenRGBDevicePage(RGBController *dev, QWidget *parent) :
ui->widget->setController(device);
device->RegisterUpdateCallback(UpdateCallback, this);
pal = ui->ButtonRed->palette();
pal.setColor(QPalette::Button, QColor(255, 0, 0));
ui->ButtonRed->setAutoFillBackground(true);
@ -270,6 +279,12 @@ void Ui::OpenRGBDevicePage::on_DirectionBox_currentIndexChanged(int /*index*/)
UpdateMode();
}
void Ui::OpenRGBDevicePage::UpdateInterface()
{
UpdateModeUi();
ui->widget->repaint();
}
void Ui::OpenRGBDevicePage::UpdateModeUi()
{
/*-----------------------------------------------------*\

View file

@ -60,6 +60,8 @@ private slots:
void on_ColorWheelBox_colorChanged(const QColor color);
void UpdateInterface();
private:
Ui::OpenRGBDevicePageUi *ui;
RGBController *device;