WIP: Multiple selection test
Rework of LED position data from RGBController into DeviceView, code style cleanup modified by Adam Honse <calcprogrammer1@gmail.com>
This commit is contained in:
parent
c6b10d9316
commit
a2a394492b
5 changed files with 644 additions and 114 deletions
|
|
@ -13,6 +13,7 @@
|
|||
#include <QStyleOption>
|
||||
#include <QtCore/qmath.h>
|
||||
#include <QDebug>
|
||||
#include <QMouseEvent>
|
||||
|
||||
DeviceView::DeviceView(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
|
|
@ -20,11 +21,106 @@ DeviceView::DeviceView(QWidget *parent) :
|
|||
mouseDown(false)
|
||||
{
|
||||
controller = NULL;
|
||||
setMouseTracking(1);
|
||||
}
|
||||
|
||||
void DeviceView::setController(RGBController * controller_ptr)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Store the controller pointer |
|
||||
\*-----------------------------------------------------*/
|
||||
controller = controller_ptr;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set the size of the selection flags vector |
|
||||
\*-----------------------------------------------------*/
|
||||
selectionFlags.resize(controller->leds.size());
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set the size of the zone and LED position vectors |
|
||||
\*-----------------------------------------------------*/
|
||||
zone_pos.resize(controller->zones.size());
|
||||
led_pos.resize(controller->leds.size());
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Process position and size for zones |
|
||||
\*-----------------------------------------------------*/
|
||||
unsigned int maxWidth = 0;
|
||||
unsigned int maxCols = 20;
|
||||
unsigned int totalHeight = 0;
|
||||
|
||||
for(std::size_t zone_idx = 0; zone_idx < controller->zones.size(); zone_idx++)
|
||||
{
|
||||
if((controller->zones[zone_idx].type == ZONE_TYPE_MATRIX) && (controller->zones[zone_idx].matrix_map))
|
||||
{
|
||||
totalHeight += controller->zones[zone_idx].matrix_map->height;
|
||||
zone_pos[zone_idx].matrix_w = controller->zones[zone_idx].matrix_map->width;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned int count = controller->zones[zone_idx].leds_count;
|
||||
zone_pos[zone_idx].matrix_w = std::min(count, maxCols);
|
||||
totalHeight += count / maxCols + !!(count % maxCols); // Equivalent to ceil(float(count) / maxCols);
|
||||
}
|
||||
|
||||
if(zone_pos[zone_idx].matrix_w > maxWidth)
|
||||
{
|
||||
maxWidth = zone_pos[zone_idx].matrix_w;
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Add some space for zone names and padding |
|
||||
\*-----------------------------------------------------*/
|
||||
totalHeight += controller->zones.size();
|
||||
|
||||
float atom = 1.0 / maxWidth; // Atom is the width of a single square; if the whole thing becomes too tall, we ignore it and let the view widget take care of it
|
||||
float current_y = 0; // We will be descending, placing each zone one atom below the previous one
|
||||
matrix_h = totalHeight * atom;
|
||||
|
||||
for(std::size_t zone_idx = 0; zone_idx < controller->zones.size(); zone_idx++)
|
||||
{
|
||||
zone_pos[zone_idx].matrix_x = (1.0 - (zone_pos[zone_idx].matrix_w * atom)) / 2;
|
||||
zone_pos[zone_idx].matrix_y = current_y + 0.5 * atom;
|
||||
zone_pos[zone_idx].matrix_w *= atom;
|
||||
zone_pos[zone_idx].matrix_h = 0.4 * atom;
|
||||
current_y += atom;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Now process the position and size for the LEDs |
|
||||
\*-----------------------------------------------------*/
|
||||
if((controller->zones[zone_idx].type == ZONE_TYPE_MATRIX) && (controller->zones[zone_idx].matrix_map))
|
||||
{
|
||||
matrix_map_type * map = controller->zones[zone_idx].matrix_map;
|
||||
|
||||
for(int led_x = 0; led_x < map->width; led_x++)
|
||||
{
|
||||
for(int led_y = 0; led_y < map->height; led_y++)
|
||||
{
|
||||
unsigned int map_idx = led_y * map->width + led_x;
|
||||
unsigned int color_idx = map->map[map_idx];
|
||||
|
||||
if(color_idx != 0xFFFFFFFF)
|
||||
{
|
||||
led_pos[color_idx].matrix_x = (zone_pos[zone_idx].matrix_x + led_x + 0.1) * atom;
|
||||
led_pos[color_idx].matrix_y = (current_y + led_y + 0.1) * atom;
|
||||
led_pos[color_idx].matrix_w = 0.8 * atom;
|
||||
led_pos[color_idx].matrix_h = 0.8 * atom;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int i = 0; i < controller->zones[zone_idx].leds_count; i++)
|
||||
{
|
||||
led_pos[i + controller->zones[zone_idx].start_idx].matrix_x = zone_pos[zone_idx].matrix_x + (i % maxCols + 0.1) * atom;
|
||||
led_pos[i + controller->zones[zone_idx].start_idx].matrix_y = current_y + (i / maxCols + 0.1) * atom;
|
||||
led_pos[i + controller->zones[zone_idx].start_idx].matrix_w = 0.8 * atom;
|
||||
led_pos[i + controller->zones[zone_idx].start_idx].matrix_h = 0.8 * atom;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QSize DeviceView::sizeHint () const
|
||||
|
|
@ -39,17 +135,88 @@ QSize DeviceView::minimumSizeHint () const
|
|||
|
||||
void DeviceView::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
ctrlDown = event->modifiers().testFlag(Qt::ControlModifier);
|
||||
mouseDown = true;
|
||||
mouseMoved = false;
|
||||
|
||||
if(ctrlDown)
|
||||
{
|
||||
previousFlags = selectionFlags;
|
||||
previousSelection = selectedLeds;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| It's okay if the size becomes negative |
|
||||
\*-----------------------------------------------------*/
|
||||
selectionRect.setLeft(event->x());
|
||||
selectionRect.setTop(event->y());
|
||||
selectionRect.setRight(event->x());
|
||||
selectionRect.setBottom(event->y());
|
||||
|
||||
updateSelection();
|
||||
update();
|
||||
}
|
||||
|
||||
void DeviceView::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
lastMousePos = event->pos();
|
||||
selectionRect.setRight(event->x());
|
||||
selectionRect.setBottom(event->y());
|
||||
|
||||
if(mouseDown)
|
||||
{
|
||||
mouseMoved = true;
|
||||
ctrlDown = event->modifiers().testFlag(Qt::ControlModifier);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Clear the previous selection in case ctrl is released |
|
||||
\*-----------------------------------------------------*/
|
||||
if(!ctrlDown)
|
||||
{
|
||||
previousSelection.clear();
|
||||
previousFlags.clear();
|
||||
previousFlags.resize(controller->leds.size());
|
||||
}
|
||||
updateSelection();
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
void DeviceView::mouseReleaseEvent(QMouseEvent *)
|
||||
void DeviceView::mouseReleaseEvent(QMouseEvent* event)
|
||||
{
|
||||
selectionRect = selectionRect.normalized();
|
||||
mouseDown = false;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Check if the user clicked a zone name & select it |
|
||||
\*-----------------------------------------------------*/
|
||||
if(!mouseMoved)
|
||||
{
|
||||
int size = width();
|
||||
int offset_x = 0;
|
||||
|
||||
if(height() < size * matrix_h)
|
||||
{
|
||||
size = height() / matrix_h;
|
||||
offset_x = (width() - size) / 2;
|
||||
}
|
||||
|
||||
for(int zone_idx = 0; zone_idx < controller->zones.size(); zone_idx++)
|
||||
{
|
||||
int posx = zone_pos[zone_idx].matrix_x * size + offset_x;
|
||||
int posy = zone_pos[zone_idx].matrix_y * size;
|
||||
int posw = zone_pos[zone_idx].matrix_w * size;
|
||||
int posh = zone_pos[zone_idx].matrix_h * size;
|
||||
|
||||
QRect rect = {posx, posy, posw, posh};
|
||||
|
||||
if(rect.contains(event->pos()))
|
||||
{
|
||||
selectZone(zone_idx, ctrlDown);
|
||||
}
|
||||
}
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
void DeviceView::resizeEvent(QResizeEvent *event)
|
||||
|
|
@ -70,78 +237,275 @@ void DeviceView::resizeEvent(QResizeEvent *event)
|
|||
|
||||
void DeviceView::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
int width = event->rect().width();
|
||||
int height = event->rect().height();
|
||||
int zone_width = 0;
|
||||
int zone_offset = 0;
|
||||
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;
|
||||
opt.initFrom(this);
|
||||
QFont font = painter.font();
|
||||
|
||||
if(controller != NULL)
|
||||
/*-----------------------------------------------------*\
|
||||
| Figure out the real width of the whole thing |
|
||||
\*-----------------------------------------------------*/
|
||||
int size = width();
|
||||
int offset_x = 0;
|
||||
|
||||
if(height() < size * matrix_h)
|
||||
{
|
||||
for(int zone_idx = 0; zone_idx < controller->zones.size(); zone_idx++)
|
||||
size = height() / matrix_h;
|
||||
offset_x = (width() - size) / 2;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| LED rectangles |
|
||||
\*-----------------------------------------------------*/
|
||||
for(int led_idx = 0; led_idx < controller->leds.size(); led_idx++)
|
||||
{
|
||||
int posx = led_pos[led_idx].matrix_x * size + offset_x;
|
||||
int posy = led_pos[led_idx].matrix_y * size;
|
||||
int posw = led_pos[led_idx].matrix_w * size;
|
||||
int posh = led_pos[led_idx].matrix_h * size;
|
||||
|
||||
QRect rect = {posx, posy, posw, posh};
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Fill color |
|
||||
\*-----------------------------------------------------*/
|
||||
QColor currentColor = QColor::fromRgb(
|
||||
RGBGetRValue(controller->colors[led_idx]),
|
||||
RGBGetGValue(controller->colors[led_idx]),
|
||||
RGBGetBValue(controller->colors[led_idx]));
|
||||
painter.setBrush(currentColor);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Border color |
|
||||
\*-----------------------------------------------------*/
|
||||
if(selectionFlags[led_idx])
|
||||
{
|
||||
if((controller->zones[zone_idx].type == ZONE_TYPE_MATRIX)
|
||||
&&(controller->zones[zone_idx].matrix_map != NULL))
|
||||
{
|
||||
unsigned int x_count = controller->zones[zone_idx].matrix_map->width;
|
||||
unsigned int y_count = controller->zones[zone_idx].matrix_map->height;
|
||||
painter.setPen(palette().highlight().color());
|
||||
}
|
||||
else
|
||||
{
|
||||
painter.setPen(palette().dark().color());
|
||||
}
|
||||
painter.drawRect(rect);
|
||||
|
||||
zone_width = x_count * (box_size + box_margin);
|
||||
zone_offset = (width - zone_width) / 2;
|
||||
/*-----------------------------------------------------*\
|
||||
| Label |
|
||||
| Set the font color so that the text is visible |
|
||||
\*-----------------------------------------------------*/
|
||||
font.setPixelSize(posh / 2);
|
||||
|
||||
for(int x = 0; x < x_count; x++)
|
||||
{
|
||||
for(int y = 0; y < y_count; y++)
|
||||
{
|
||||
unsigned int map_idx = (y * x_count) + x;
|
||||
unsigned int color_idx = controller->zones[zone_idx].matrix_map->map[map_idx];
|
||||
if(currentColor.value() > 127)
|
||||
{
|
||||
painter.setBrush(Qt::black);
|
||||
}
|
||||
else
|
||||
{
|
||||
painter.setBrush(Qt::white);
|
||||
}
|
||||
//painter.drawText(rect, Qt::AlignVCenter | Qt::AlignHCenter, QString(controller->leds[led_idx].label.c_str()));
|
||||
}
|
||||
|
||||
if( color_idx != 0xFFFFFFFF )
|
||||
{
|
||||
painter.fillRect((zone_offset + (x * (box_size + box_margin))), ((y + row) * (box_size + box_margin)), box_size, box_size, QColor::fromRgb(RGBGetRValue(controller->zones[zone_idx].colors[color_idx]), RGBGetGValue(controller->zones[zone_idx].colors[color_idx]), RGBGetBValue(controller->zones[zone_idx].colors[color_idx])));
|
||||
painter.drawRect((zone_offset + (x * (box_size + box_margin))), ((y + row) * (box_size + box_margin)), box_size, box_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
row += y_count;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned int x_count = controller->zones[zone_idx].leds_count;
|
||||
/*-----------------------------------------------------*\
|
||||
| Zone names |
|
||||
\*-----------------------------------------------------*/
|
||||
for(int zone_idx = 0; zone_idx < controller->zones.size(); zone_idx++)
|
||||
{
|
||||
int posx = zone_pos[zone_idx].matrix_x * size + offset_x;
|
||||
int posy = zone_pos[zone_idx].matrix_y * size;
|
||||
int posw = zone_pos[zone_idx].matrix_w * size;
|
||||
int posh = zone_pos[zone_idx].matrix_h * size;
|
||||
|
||||
zone_width = x_count * (box_size + box_margin);
|
||||
QRect rect = {posx, posy, posw, posh};
|
||||
|
||||
if(zone_width > width)
|
||||
{
|
||||
zone_width = width;
|
||||
}
|
||||
font.setPixelSize(posh / 2);
|
||||
if(rect.contains(lastMousePos))
|
||||
{
|
||||
painter.setPen(palette().highlight().color());
|
||||
}
|
||||
else
|
||||
{
|
||||
painter.setPen(palette().windowText().color());
|
||||
}
|
||||
painter.drawText(rect, Qt::AlignVCenter | Qt::AlignHCenter, QString(controller->zones[zone_idx].name.c_str()));
|
||||
}
|
||||
|
||||
zone_offset = (width - zone_width) / 2;
|
||||
/*-----------------------------------------------------*\
|
||||
| Selection area |
|
||||
\*-----------------------------------------------------*/
|
||||
if(mouseDown)
|
||||
{
|
||||
QRect rect = selectionRect.normalized();
|
||||
QColor color = palette().highlight().color();
|
||||
color.setAlpha(63);
|
||||
painter.fillRect(rect, color);
|
||||
color.setAlpha(127);
|
||||
painter.setBrush(color);
|
||||
painter.drawRect(rect);
|
||||
}
|
||||
}
|
||||
|
||||
for(int led_idx = 0; led_idx < x_count; led_idx++)
|
||||
{
|
||||
painter.fillRect((zone_offset + (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((zone_offset + (col * (box_size + box_margin))), (row * (box_size + box_margin)), box_size, box_size);
|
||||
col++;
|
||||
void DeviceView::updateSelection()
|
||||
{
|
||||
selectedLeds.clear();
|
||||
selectionFlags.resize(controller->leds.size()); // Could this change?
|
||||
|
||||
if(col > max_cols)
|
||||
{
|
||||
row++;
|
||||
col = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
QRect sel = selectionRect.normalized();
|
||||
std::vector<led>& leds = controller->leds;
|
||||
|
||||
row += 2;
|
||||
col = 0;
|
||||
int size = width();
|
||||
int offset_x = 0;
|
||||
|
||||
if(height() < size * matrix_h)
|
||||
{
|
||||
size = height() / matrix_h;
|
||||
offset_x = (width() - size) / 2;
|
||||
}
|
||||
|
||||
for(int led_idx = 0; led_idx < leds.size(); ++led_idx)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Check intersection |
|
||||
\*-----------------------------------------------------*/
|
||||
int posx = led_pos[led_idx].matrix_x * size + offset_x;
|
||||
int posy = led_pos[led_idx].matrix_y * size;
|
||||
int posw = led_pos[led_idx].matrix_w * size;
|
||||
int posh = led_pos[led_idx].matrix_h * size;
|
||||
|
||||
QRect rect = {posx, posy, posw, posh};
|
||||
|
||||
selectionFlags[led_idx] = 0;
|
||||
|
||||
if(sel.intersects(rect))
|
||||
{
|
||||
selectedLeds.push_back(led_idx);
|
||||
selectionFlags[led_idx] = 1;
|
||||
}
|
||||
if(ctrlDown)
|
||||
{
|
||||
selectionFlags[led_idx] ^= previousFlags[led_idx];
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send selection changed signal |
|
||||
\*-----------------------------------------------------*/
|
||||
emit selectionChanged(selectedLeds);
|
||||
}
|
||||
|
||||
bool DeviceView::selectLed(int target)
|
||||
{
|
||||
if(target < 0 || target >= controller->leds.size())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
selectedLeds.resize(1);
|
||||
selectedLeds[0] = target;
|
||||
selectionFlags.clear();
|
||||
selectionFlags.resize(controller->leds.size());
|
||||
selectionFlags[target] = 1;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send selection changed signal |
|
||||
\*-----------------------------------------------------*/
|
||||
emit selectionChanged(selectedLeds);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DeviceView::selectLeds(QVector<int> target)
|
||||
{
|
||||
for(int item: target)
|
||||
{
|
||||
if(item < 0 || item >= controller->leds.size())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
selectionFlags.clear();
|
||||
selectionFlags.resize(controller->leds.size());
|
||||
|
||||
for(int item: target)
|
||||
{
|
||||
selectionFlags[item] = 1;
|
||||
}
|
||||
|
||||
//selectedLeds = target;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Filter out duplicate items |
|
||||
\*-----------------------------------------------------*/
|
||||
selectedLeds.clear();
|
||||
|
||||
for(int i = 0; i < selectionFlags.size(); ++i)
|
||||
{
|
||||
if(selectionFlags[i])
|
||||
{
|
||||
selectedLeds.push_back(i);
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send selection changed signal |
|
||||
\*-----------------------------------------------------*/
|
||||
emit selectionChanged(selectedLeds);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DeviceView::selectZone(int zone, bool add)
|
||||
{
|
||||
if(zone < 0 || zone >= controller->zones.size())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!add)
|
||||
{
|
||||
selectedLeds.clear();
|
||||
selectionFlags.clear();
|
||||
selectionFlags.resize(controller->leds.size());
|
||||
}
|
||||
|
||||
int zoneStart = controller->zones[zone].start_idx;
|
||||
|
||||
for(int led_idx = 0; led_idx < controller->zones[zone].leds_count; ++led_idx)
|
||||
{
|
||||
if(!selectionFlags[zoneStart + led_idx])
|
||||
{
|
||||
selectedLeds.push_back(zoneStart + led_idx);
|
||||
selectionFlags[zoneStart + led_idx] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send selection changed signal |
|
||||
\*-----------------------------------------------------*/
|
||||
emit selectionChanged(selectedLeds);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void DeviceView::clearSelection()
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Same as selecting the entire device |
|
||||
\*-----------------------------------------------------*/
|
||||
selectedLeds.clear();
|
||||
selectionFlags.clear();
|
||||
selectionFlags.resize(controller->leds.size());
|
||||
}
|
||||
|
||||
void DeviceView::setSelectionColor(RGBColor color)
|
||||
{
|
||||
if(selectedLeds.isEmpty())
|
||||
{
|
||||
controller->SetAllLEDs(color);
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int led_idx: selectedLeds)
|
||||
{
|
||||
controller->SetLED(led_idx, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,14 @@
|
|||
#include <QWidget>
|
||||
#include "RGBController.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float matrix_x;
|
||||
float matrix_y;
|
||||
float matrix_w;
|
||||
float matrix_h;
|
||||
} matrix_pos_size_type;
|
||||
|
||||
class DeviceView : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
@ -12,7 +20,7 @@ public:
|
|||
|
||||
virtual QSize sizeHint () const;
|
||||
virtual QSize minimumSizeHint () const;
|
||||
|
||||
|
||||
void setController(RGBController * controller_ptr);
|
||||
|
||||
protected:
|
||||
|
|
@ -21,14 +29,38 @@ protected:
|
|||
void mouseReleaseEvent(QMouseEvent *);
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
void paintEvent(QPaintEvent *);
|
||||
|
||||
private:
|
||||
QSize initSize;
|
||||
bool mouseDown;
|
||||
QPoint lastPos;
|
||||
bool ctrlDown;
|
||||
bool mouseMoved;
|
||||
QRect selectionRect;
|
||||
QPoint lastMousePos;
|
||||
QVector<int> previousSelection;
|
||||
QVector<int> selectedLeds;
|
||||
QVector<bool> selectionFlags;
|
||||
QVector<bool> previousFlags;
|
||||
|
||||
std::vector<matrix_pos_size_type> zone_pos;
|
||||
std::vector<matrix_pos_size_type> led_pos;
|
||||
|
||||
float matrix_h;
|
||||
|
||||
RGBController* controller;
|
||||
|
||||
QColor posColor(const QPoint &point);
|
||||
QColor posColor(const QPoint &point);
|
||||
void updateSelection();
|
||||
|
||||
signals:
|
||||
void selectionChanged(QVector<int>);
|
||||
|
||||
public slots:
|
||||
bool selectLed(int);
|
||||
bool selectLeds(QVector<int>);
|
||||
bool selectZone(int zone, bool add = false);
|
||||
void clearSelection(); // Same as selecting the entire device
|
||||
void setSelectionColor(RGBColor);
|
||||
};
|
||||
|
||||
#endif // DEVICEVIEW_H
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ static void UpdateCallback(void * this_ptr)
|
|||
{
|
||||
OpenRGBDevicePage * this_obj = (OpenRGBDevicePage *)this_ptr;
|
||||
|
||||
QMetaObject::invokeMethod(this_obj, "UpdateInterface", Qt::QueuedConnection);
|
||||
//QMetaObject::invokeMethod(this_obj, "UpdateInterface", Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
OpenRGBDevicePage::OpenRGBDevicePage(RGBController *dev, QWidget *parent) :
|
||||
|
|
@ -27,7 +27,7 @@ OpenRGBDevicePage::OpenRGBDevicePage(RGBController *dev, QWidget *parent) :
|
|||
\*-----------------------------------------------------*/
|
||||
QPalette pal;
|
||||
|
||||
ui->widget->setController(device);
|
||||
ui->DeviceViewBox->setController(device);
|
||||
|
||||
device->RegisterUpdateCallback(UpdateCallback, this);
|
||||
|
||||
|
|
@ -109,24 +109,58 @@ void Ui::OpenRGBDevicePage::on_ZoneBox_currentIndexChanged(int /*index*/)
|
|||
{
|
||||
case MODE_COLORS_PER_LED:
|
||||
{
|
||||
unsigned int selected_zone = ui->ZoneBox->currentIndex();
|
||||
int selected_zone = ui->ZoneBox->currentIndex();
|
||||
|
||||
ui->LEDBox->blockSignals(true);
|
||||
ui->LEDBox->clear();
|
||||
|
||||
if(selected_zone == 0)
|
||||
if(device->zones.size() > 1)
|
||||
{
|
||||
for (std::size_t i = 0; i < device->leds.size(); i++)
|
||||
if(selected_zone == 0)
|
||||
{
|
||||
ui->LEDBox->addItem(device->leds[i].name.c_str());
|
||||
if(device->leds.size() > 1)
|
||||
{
|
||||
ui->LEDBox->addItem("Entire device");
|
||||
ui->LEDBox->setEnabled(1);
|
||||
ui->SetLEDButton->setEnabled(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->LEDBox->setDisabled(1);
|
||||
ui->SetLEDButton->setDisabled(1);
|
||||
}
|
||||
for (std::size_t i = 0; i < device->leds.size(); i++)
|
||||
{
|
||||
ui->LEDBox->addItem(device->leds[i].name.c_str());
|
||||
}
|
||||
|
||||
ui->ResizeButton->setEnabled(false);
|
||||
if(!signalsBlocked())
|
||||
{
|
||||
ui->DeviceViewBox->blockSignals(true);
|
||||
ui->DeviceViewBox->clearSelection();
|
||||
ui->DeviceViewBox->blockSignals(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
selected_zone = selected_zone - 1;
|
||||
}
|
||||
|
||||
ui->ResizeButton->setEnabled(false);
|
||||
}
|
||||
else
|
||||
if(device->zones.size() == 1 || selected_zone != -1)
|
||||
{
|
||||
selected_zone = selected_zone - 1;
|
||||
|
||||
// Disable led box if there's only one LED anyway
|
||||
if(device->zones[selected_zone].leds_count > 1)
|
||||
{
|
||||
ui->LEDBox->addItem("Entire zone");
|
||||
ui->LEDBox->setEnabled(1);
|
||||
ui->SetLEDButton->setEnabled(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->LEDBox->setDisabled(1);
|
||||
ui->SetLEDButton->setDisabled(1);
|
||||
}
|
||||
for (std::size_t led_idx = 0; led_idx < device->zones[selected_zone].leds_count; led_idx++)
|
||||
{
|
||||
ui->LEDBox->addItem(device->zones[selected_zone].leds[led_idx].name.c_str());
|
||||
|
|
@ -140,6 +174,12 @@ void Ui::OpenRGBDevicePage::on_ZoneBox_currentIndexChanged(int /*index*/)
|
|||
{
|
||||
ui->ResizeButton->setEnabled(true);
|
||||
}
|
||||
if(!signalsBlocked())
|
||||
{
|
||||
ui->DeviceViewBox->blockSignals(true);
|
||||
ui->DeviceViewBox->selectZone(selected_zone);
|
||||
ui->DeviceViewBox->blockSignals(false);
|
||||
}
|
||||
}
|
||||
|
||||
ui->LEDBox->setCurrentIndex(0);
|
||||
|
|
@ -164,31 +204,93 @@ void Ui::OpenRGBDevicePage::on_LEDBox_currentIndexChanged(int index)
|
|||
unsigned int selected_zone = ui->ZoneBox->currentIndex();
|
||||
|
||||
RGBColor color = 0x00000000;
|
||||
bool updateColor = 0;
|
||||
|
||||
if(selected_zone == 0)
|
||||
if(device->zones.size() > 1)
|
||||
{
|
||||
color = device->GetLED(index);
|
||||
}
|
||||
else
|
||||
{
|
||||
selected_zone = selected_zone - 1;
|
||||
|
||||
if((unsigned int)index < device->zones[selected_zone].leds_count)
|
||||
if(selected_zone == 0) // All zones
|
||||
{
|
||||
color = device->zones[selected_zone].colors[index];
|
||||
if(device->leds.size() > 1)
|
||||
{
|
||||
if(index == 0) // All LEDs on the entire device
|
||||
{
|
||||
if(!signalsBlocked())
|
||||
{
|
||||
ui->DeviceViewBox->blockSignals(true);
|
||||
ui->DeviceViewBox->clearSelection();
|
||||
ui->DeviceViewBox->blockSignals(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
index = index - 1;
|
||||
}
|
||||
}
|
||||
if(device->leds.size() == 1 || index != -1)
|
||||
{
|
||||
color = device->GetLED(index); // One LED, proceed
|
||||
updateColor = 1;
|
||||
if(!signalsBlocked())
|
||||
{
|
||||
ui->DeviceViewBox->blockSignals(true);
|
||||
ui->DeviceViewBox->selectLed(index);
|
||||
ui->DeviceViewBox->blockSignals(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
selected_zone = selected_zone - 1;
|
||||
}
|
||||
}
|
||||
if(device->zones.size() == 1 || selected_zone != -1) // A specific zone is selected
|
||||
{
|
||||
if(device->zones[selected_zone].leds_count > 1)
|
||||
{
|
||||
if(index == 0) // Entire zone
|
||||
{
|
||||
if(!signalsBlocked())
|
||||
{
|
||||
ui->DeviceViewBox->blockSignals(true);
|
||||
ui->DeviceViewBox->selectZone(selected_zone);
|
||||
ui->DeviceViewBox->blockSignals(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
index = index - 1;
|
||||
}
|
||||
}
|
||||
if(device->zones[selected_zone].leds_count == 1 || index != -1)
|
||||
{
|
||||
if((unsigned int)index < device->zones[selected_zone].leds_count)
|
||||
{
|
||||
color = device->zones[selected_zone].colors[index];
|
||||
updateColor = 1;
|
||||
int globalIndex = device->zones[selected_zone].leds - &(device->leds[0]) + index;
|
||||
if(!signalsBlocked())
|
||||
{
|
||||
ui->DeviceViewBox->blockSignals(true);
|
||||
ui->DeviceViewBox->selectLed(globalIndex);
|
||||
ui->DeviceViewBox->blockSignals(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Update color picker with color of selected LED |
|
||||
\*-----------------------------------------------------*/
|
||||
UpdatingColor = true;
|
||||
ui->RedSpinBox->setValue(RGBGetRValue(color));
|
||||
ui->GreenSpinBox->setValue(RGBGetGValue(color));
|
||||
ui->BlueSpinBox->setValue(RGBGetBValue(color));
|
||||
UpdatingColor = false;
|
||||
updateHSV();
|
||||
updateWheel();
|
||||
if(updateColor)
|
||||
{
|
||||
UpdatingColor = true;
|
||||
ui->RedSpinBox->setValue(RGBGetRValue(color));
|
||||
ui->GreenSpinBox->setValue(RGBGetGValue(color));
|
||||
ui->BlueSpinBox->setValue(RGBGetBValue(color));
|
||||
UpdatingColor = false;
|
||||
updateHSV();
|
||||
updateWheel();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -282,7 +384,7 @@ void Ui::OpenRGBDevicePage::on_DirectionBox_currentIndexChanged(int /*index*/)
|
|||
void Ui::OpenRGBDevicePage::UpdateInterface()
|
||||
{
|
||||
UpdateModeUi();
|
||||
ui->widget->repaint();
|
||||
ui->DeviceViewBox->repaint();
|
||||
}
|
||||
|
||||
void Ui::OpenRGBDevicePage::UpdateModeUi()
|
||||
|
|
@ -469,7 +571,17 @@ void Ui::OpenRGBDevicePage::UpdateModeUi()
|
|||
ui->ZoneBox->blockSignals(true);
|
||||
ui->ZoneBox->clear();
|
||||
|
||||
ui->ZoneBox->addItem("All Zones");
|
||||
if(device->zones.size() > 1)
|
||||
{
|
||||
ui->ZoneBox->setEnabled(1);
|
||||
ui->ZoneBox->addItem("All Zones");
|
||||
ui->SetZoneButton->setEnabled(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->ZoneBox->setDisabled(1);
|
||||
ui->SetZoneButton->setDisabled(1);
|
||||
}
|
||||
|
||||
for (std::size_t i = 0; i < device->zones.size(); i++)
|
||||
{
|
||||
|
|
@ -1054,6 +1166,34 @@ void Ui::OpenRGBDevicePage::on_ValSpinBox_valueChanged(int /*arg1*/)
|
|||
updateWheel();
|
||||
}
|
||||
|
||||
void Ui::OpenRGBDevicePage::on_DeviceViewBox_selectionChanged(QVector<int> indices)
|
||||
{
|
||||
ui->ZoneBox->blockSignals(true);
|
||||
ui->ZoneBox->setCurrentIndex(0);
|
||||
ui->ZoneBox->blockSignals(false);
|
||||
if(indices.size() != 0 && indices.size() != device->leds.size())
|
||||
{
|
||||
ui->LEDBox->blockSignals(true);
|
||||
if(indices.size() == 1)
|
||||
{
|
||||
if(device->leds.size() == 1)
|
||||
{
|
||||
ui->LEDBox->setCurrentIndex(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->LEDBox->setCurrentIndex(indices[0] + 1);
|
||||
// Set everything to it's color
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->LEDBox->setCurrentText("Multiple (" + QVariant(indices.size()).toString() + ")");
|
||||
}
|
||||
ui->LEDBox->blockSignals(false);
|
||||
}
|
||||
}
|
||||
|
||||
void Ui::OpenRGBDevicePage::on_SetAllButton_clicked()
|
||||
{
|
||||
unsigned char red = ui->RedSpinBox->value();
|
||||
|
|
|
|||
|
|
@ -25,43 +25,37 @@ public:
|
|||
void UpdateModeUi();
|
||||
|
||||
private slots:
|
||||
void on_ButtonRed_clicked();
|
||||
void on_ButtonYellow_clicked();
|
||||
void on_ButtonGreen_clicked();
|
||||
void on_ButtonCyan_clicked();
|
||||
void on_ButtonBlue_clicked();
|
||||
void on_ButtonMagenta_clicked();
|
||||
void UpdateInterface();
|
||||
|
||||
void on_ColorWheelBox_colorChanged(const QColor color);
|
||||
void on_DirectionBox_currentIndexChanged(int index);
|
||||
void on_ZoneBox_currentIndexChanged(int index);
|
||||
void on_LEDBox_currentIndexChanged(int index);
|
||||
void on_ModeBox_currentIndexChanged(int index);
|
||||
void on_SetDeviceButton_clicked();
|
||||
void on_SetZoneButton_clicked();
|
||||
void on_SetLEDButton_clicked();
|
||||
void on_SpeedSlider_valueChanged(int value);
|
||||
void on_RedSpinBox_valueChanged(int arg1);
|
||||
void on_HueSpinBox_valueChanged(int arg1);
|
||||
void on_GreenSpinBox_valueChanged(int arg1);
|
||||
void on_SatSpinBox_valueChanged(int arg1);
|
||||
void on_BlueSpinBox_valueChanged(int arg1);
|
||||
void on_ValSpinBox_valueChanged(int arg1);
|
||||
void on_DeviceViewBox_selectionChanged(QVector<int>);
|
||||
|
||||
void on_ButtonRed_clicked();
|
||||
void on_ButtonYellow_clicked();
|
||||
void on_ButtonGreen_clicked();
|
||||
void on_ButtonCyan_clicked();
|
||||
void on_ButtonBlue_clicked();
|
||||
void on_ButtonMagenta_clicked();
|
||||
void on_SetDeviceButton_clicked();
|
||||
void on_SetZoneButton_clicked();
|
||||
void on_SetLEDButton_clicked();
|
||||
void on_SetAllButton_clicked();
|
||||
|
||||
void on_RandomCheck_clicked();
|
||||
|
||||
void on_SpeedSlider_valueChanged(int value);
|
||||
|
||||
void on_DirectionBox_currentIndexChanged(int index);
|
||||
|
||||
void on_PerLEDCheck_clicked();
|
||||
|
||||
void on_ModeSpecificCheck_clicked();
|
||||
|
||||
void on_ResizeButton_clicked();
|
||||
|
||||
void on_ColorWheelBox_colorChanged(const QColor color);
|
||||
|
||||
void UpdateInterface();
|
||||
|
||||
private:
|
||||
Ui::OpenRGBDevicePageUi *ui;
|
||||
RGBController *device;
|
||||
|
|
|
|||
|
|
@ -275,7 +275,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="11">
|
||||
<widget class="DeviceView" name="widget" native="true">
|
||||
<widget class="DeviceView" name="DeviceViewBox" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
|
||||
<horstretch>0</horstretch>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue