Add widget that displays the current color of all LEDs on a controller
This commit is contained in:
parent
38f8808bea
commit
17f1390f36
5 changed files with 187 additions and 2 deletions
|
|
@ -108,6 +108,7 @@ HEADERS += \
|
||||||
i2c_smbus/i2c_smbus.h \
|
i2c_smbus/i2c_smbus.h \
|
||||||
i2c_tools/i2c_tools.h \
|
i2c_tools/i2c_tools.h \
|
||||||
net_port/net_port.h \
|
net_port/net_port.h \
|
||||||
|
qt/DeviceView.h \
|
||||||
qt/OpenRGBDialog2.h \
|
qt/OpenRGBDialog2.h \
|
||||||
qt/OpenRGBProfileSaveDialog.h \
|
qt/OpenRGBProfileSaveDialog.h \
|
||||||
qt/OpenRGBServerInfoPage.h \
|
qt/OpenRGBServerInfoPage.h \
|
||||||
|
|
@ -246,6 +247,7 @@ SOURCES += \
|
||||||
i2c_smbus/i2c_smbus.cpp \
|
i2c_smbus/i2c_smbus.cpp \
|
||||||
i2c_tools/i2c_tools.cpp \
|
i2c_tools/i2c_tools.cpp \
|
||||||
net_port/net_port.cpp \
|
net_port/net_port.cpp \
|
||||||
|
qt/DeviceView.cpp \
|
||||||
qt/OpenRGBDialog2.cpp \
|
qt/OpenRGBDialog2.cpp \
|
||||||
qt/OpenRGBProfileSaveDialog.cpp \
|
qt/OpenRGBProfileSaveDialog.cpp \
|
||||||
qt/OpenRGBServerInfoPage.cpp \
|
qt/OpenRGBServerInfoPage.cpp \
|
||||||
|
|
|
||||||
123
qt/DeviceView.cpp
Normal file
123
qt/DeviceView.cpp
Normal file
|
|
@ -0,0 +1,123 @@
|
||||||
|
/*-----------------------------------------------------*\
|
||||||
|
| DeviceView.cpp |
|
||||||
|
| |
|
||||||
|
| OpenRGB Device view widget for Qt |
|
||||||
|
| |
|
||||||
|
| Adam Honse (calcprogrammer1@gmail.com) |
|
||||||
|
\*-----------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "DeviceView.h"
|
||||||
|
#include "RGBController.h"
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QResizeEvent>
|
||||||
|
#include <QStyleOption>
|
||||||
|
#include <QtCore/qmath.h>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
DeviceView::DeviceView(QWidget *parent) :
|
||||||
|
QWidget(parent),
|
||||||
|
initSize(128,128),
|
||||||
|
mouseDown(false),
|
||||||
|
margin(0),
|
||||||
|
wheelWidth(10),
|
||||||
|
current(Qt::red),
|
||||||
|
inWheel(false),
|
||||||
|
inSquare(false)
|
||||||
|
{
|
||||||
|
controller = NULL;
|
||||||
|
current = current.toHsv();
|
||||||
|
}
|
||||||
|
|
||||||
|
QColor DeviceView::color()
|
||||||
|
{
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceView::setController(RGBController * controller_ptr)
|
||||||
|
{
|
||||||
|
controller = controller_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
QSize DeviceView::sizeHint () const
|
||||||
|
{
|
||||||
|
return QSize(height(),height());
|
||||||
|
}
|
||||||
|
|
||||||
|
QSize DeviceView::minimumSizeHint () const
|
||||||
|
{
|
||||||
|
return initSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceView::mousePressEvent(QMouseEvent *event)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
unsigned int size = 0;
|
||||||
|
|
||||||
|
if(event->size().width() < event->size().height())
|
||||||
|
{
|
||||||
|
size = event->size().width();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
size = event->size().height();
|
||||||
|
}
|
||||||
|
|
||||||
|
wheel = QPixmap(event->size());
|
||||||
|
wheel.fill(Qt::transparent);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceView::paintEvent(QPaintEvent *)
|
||||||
|
{
|
||||||
|
#define MAX_COLS 100
|
||||||
|
|
||||||
|
int row = 0;
|
||||||
|
int col = 0;
|
||||||
|
int box_size = 20;
|
||||||
|
int box_margin = 2;
|
||||||
|
|
||||||
|
QPainter painter(this);
|
||||||
|
QStyleOption opt;
|
||||||
|
opt.initFrom(this);
|
||||||
|
|
||||||
|
if(controller != NULL)
|
||||||
|
{
|
||||||
|
for(int zone_idx = 0; zone_idx < controller->zones.size(); zone_idx++)
|
||||||
|
{
|
||||||
|
for(int led_idx = 0; led_idx < controller->zones[zone_idx].leds_count; led_idx++)
|
||||||
|
{
|
||||||
|
painter.fillRect((col * (box_size + box_margin)), (row * (box_size + box_margin)), box_size, box_size, QColor::fromRgb(RGBGetRValue(controller->zones[zone_idx].colors[led_idx]), RGBGetGValue(controller->zones[zone_idx].colors[led_idx]), RGBGetBValue(controller->zones[zone_idx].colors[led_idx])));
|
||||||
|
painter.drawRect((col * (box_size + box_margin)), (row * (box_size + box_margin)), box_size, box_size);
|
||||||
|
col++;
|
||||||
|
|
||||||
|
if(col > MAX_COLS)
|
||||||
|
{
|
||||||
|
row++;
|
||||||
|
col = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
row += 2;
|
||||||
|
col = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
49
qt/DeviceView.h
Normal file
49
qt/DeviceView.h
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
#ifndef DEVICEVIEW_H
|
||||||
|
#define DEVICEVIEW_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
#include "RGBController.h"
|
||||||
|
|
||||||
|
class DeviceView : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit DeviceView(QWidget *parent = 0);
|
||||||
|
|
||||||
|
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);
|
||||||
|
void mouseMoveEvent(QMouseEvent *event);
|
||||||
|
void mouseReleaseEvent(QMouseEvent *);
|
||||||
|
void resizeEvent(QResizeEvent *event);
|
||||||
|
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;
|
||||||
|
|
||||||
|
QColor posColor(const QPoint &point);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DEVICEVIEW_H
|
||||||
|
|
@ -20,6 +20,8 @@ OpenRGBDevicePage::OpenRGBDevicePage(RGBController *dev, QWidget *parent) :
|
||||||
\*-----------------------------------------------------*/
|
\*-----------------------------------------------------*/
|
||||||
QPalette pal;
|
QPalette pal;
|
||||||
|
|
||||||
|
ui->widget->setController(device);
|
||||||
|
|
||||||
pal = ui->ButtonRed->palette();
|
pal = ui->ButtonRed->palette();
|
||||||
pal.setColor(QPalette::Button, QColor(255, 0, 0));
|
pal.setColor(QPalette::Button, QColor(255, 0, 0));
|
||||||
ui->ButtonRed->setAutoFillBackground(true);
|
ui->ButtonRed->setAutoFillBackground(true);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>556</width>
|
<width>687</width>
|
||||||
<height>300</height>
|
<height>300</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
|
@ -264,7 +264,7 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="6" rowspan="4" colspan="6">
|
<item row="0" column="9" rowspan="4" colspan="3">
|
||||||
<widget class="ColorWheel" name="ColorWheelBox" native="true">
|
<widget class="ColorWheel" name="ColorWheelBox" native="true">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||||
|
|
@ -274,6 +274,9 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="0" column="6" rowspan="4" colspan="3">
|
||||||
|
<widget class="DeviceView" name="widget" native="true"/>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
|
|
@ -286,6 +289,12 @@
|
||||||
<signal>colorChanged(QColor)</signal>
|
<signal>colorChanged(QColor)</signal>
|
||||||
</slots>
|
</slots>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>DeviceView</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header location="global">DeviceView.h</header>
|
||||||
|
<container>1</container>
|
||||||
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<tabstops>
|
<tabstops>
|
||||||
<tabstop>ZoneBox</tabstop>
|
<tabstop>ZoneBox</tabstop>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue