Device view resizes width to fit window size, UI updates on SDKcontroller update
This commit is contained in:
parent
17f1390f36
commit
d3993547c3
6 changed files with 56 additions and 39 deletions
|
|
@ -1328,9 +1328,31 @@ void RGBController::SetMode(int mode)
|
|||
UpdateMode();
|
||||
}
|
||||
|
||||
void RGBController::RegisterUpdateCallback(RGBControllerCallback new_callback, void * new_callback_arg)
|
||||
{
|
||||
UpdateCallbacks.push_back(new_callback);
|
||||
UpdateCallbackArgs.push_back(new_callback_arg);
|
||||
}
|
||||
|
||||
void RGBController::SignalUpdate()
|
||||
{
|
||||
UpdateMutex.lock();
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Client info has changed, call the callbacks |
|
||||
\*-------------------------------------------------*/
|
||||
for(unsigned int callback_idx = 0; callback_idx < UpdateCallbacks.size(); callback_idx++)
|
||||
{
|
||||
UpdateCallbacks[callback_idx](UpdateCallbackArgs[callback_idx]);
|
||||
}
|
||||
|
||||
UpdateMutex.unlock();
|
||||
}
|
||||
void RGBController::UpdateLEDs()
|
||||
{
|
||||
CallFlag_UpdateLEDs = true;
|
||||
|
||||
SignalUpdate();
|
||||
}
|
||||
|
||||
void RGBController::UpdateMode()
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
#include <string>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <mutex>
|
||||
|
||||
typedef unsigned int RGBColor;
|
||||
|
||||
|
|
@ -139,6 +140,8 @@ typedef struct
|
|||
matrix_map_type * matrix_map; /* Matrix map pointer */
|
||||
} zone;
|
||||
|
||||
typedef void (*RGBControllerCallback)(void *);
|
||||
|
||||
class RGBController
|
||||
{
|
||||
public:
|
||||
|
|
@ -188,6 +191,9 @@ public:
|
|||
unsigned char * GetSingleLEDColorDescription(int led);
|
||||
void SetSingleLEDColorDescription(unsigned char* data_buf);
|
||||
|
||||
void RegisterUpdateCallback(RGBControllerCallback new_callback, void * new_callback_arg);
|
||||
void SignalUpdate();
|
||||
|
||||
void UpdateLEDs();
|
||||
//void UpdateZoneLEDs(int zone);
|
||||
//void UpdateSingleLED(int led);
|
||||
|
|
@ -219,4 +225,8 @@ private:
|
|||
//bool CallFlag_UpdateZoneLEDs = false;
|
||||
//bool CallFlag_UpdateSingleLED = false;
|
||||
//bool CallFlag_UpdateMode = false;
|
||||
|
||||
std::mutex UpdateMutex;
|
||||
std::vector<RGBControllerCallback> UpdateCallbacks;
|
||||
std::vector<void *> UpdateCallbackArgs;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
|
|
|
|||
|
|
@ -60,6 +60,8 @@ private slots:
|
|||
|
||||
void on_ColorWheelBox_colorChanged(const QColor color);
|
||||
|
||||
void UpdateInterface();
|
||||
|
||||
private:
|
||||
Ui::OpenRGBDevicePageUi *ui;
|
||||
RGBController *device;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue