From 7d7d3aaffcbeb6cf8e5895b6f903e867011cdb16 Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Fri, 20 Aug 2021 10:07:23 -0500 Subject: [PATCH] Don't draw the LED view or handle mouse events when the selected mode doesn't use per-LED colors --- qt/DeviceView.cpp | 136 ++++++++++++++++++++++----------------- qt/DeviceView.h | 2 + qt/OpenRGBDevicePage.cpp | 2 + 3 files changed, 80 insertions(+), 60 deletions(-) diff --git a/qt/DeviceView.cpp b/qt/DeviceView.cpp index ff8e597f..dbf771c0 100644 --- a/qt/DeviceView.cpp +++ b/qt/DeviceView.cpp @@ -22,6 +22,7 @@ DeviceView::DeviceView(QWidget *parent) : { controller = NULL; numerical_labels = false; + per_led = true; setMouseTracking(1); size = width(); @@ -342,6 +343,12 @@ void DeviceView::setNumericalLabels(bool enable) numerical_labels = enable; } +void DeviceView::setPerLED(bool per_led_mode) +{ + per_led = per_led_mode; + update(); +} + QSize DeviceView::sizeHint () const { return QSize(height() - 1, height() - 1); @@ -354,88 +361,97 @@ QSize DeviceView::minimumSizeHint () const void DeviceView::mousePressEvent(QMouseEvent *event) { - ctrlDown = event->modifiers().testFlag(Qt::ControlModifier); - mouseDown = true; - mouseMoved = false; - - if(ctrlDown) + if(per_led) { - previousFlags = selectionFlags; - previousSelection = selectedLeds; + 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(); } - - /*-----------------------------------------------------*\ - | 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) + if(per_led) { - mouseMoved = true; - ctrlDown = event->modifiers().testFlag(Qt::ControlModifier); + lastMousePos = event->pos(); + selectionRect.setRight(event->x()); + selectionRect.setBottom(event->y()); - /*-----------------------------------------------------*\ - | Clear the previous selection in case ctrl is released | - \*-----------------------------------------------------*/ - if(!ctrlDown) + if(mouseDown) { - previousSelection.clear(); - previousFlags.clear(); - previousFlags.resize(controller->leds.size()); + 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(); } - updateSelection(); + update(); } - update(); } void DeviceView::mouseReleaseEvent(QMouseEvent* event) { - selectionRect = selectionRect.normalized(); - mouseDown = false; - - /*-----------------------------------------------------*\ - | Check if the user clicked a zone name & select it | - \*-----------------------------------------------------*/ - if(!mouseMoved) + if(per_led) { - int size = width(); - int offset_x = 0; + selectionRect = selectionRect.normalized(); + mouseDown = false; - if(height() < size * matrix_h) + /*-----------------------------------------------------*\ + | Check if the user clicked a zone name & select it | + \*-----------------------------------------------------*/ + if(!mouseMoved) { - size = height() / matrix_h; - offset_x = (width() - size) / 2; - } + int size = width(); + int offset_x = 0; - for(std::size_t 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())) + if(height() < size * matrix_h) { - selectZone(zone_idx, ctrlDown); + size = height() / matrix_h; + offset_x = (width() - size) / 2; + } + + for(std::size_t 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(); } - update(); } void DeviceView::resizeEvent(QResizeEvent* /*event*/) @@ -459,7 +475,7 @@ void DeviceView::paintEvent(QPaintEvent* /* event */) /*-----------------------------------------------------*\ | If Device View is hidden, don't paint | \*-----------------------------------------------------*/ - if(isHidden()) + if(isHidden() || !per_led) { return; } diff --git a/qt/DeviceView.h b/qt/DeviceView.h index bddf27bf..c9c3cf1e 100644 --- a/qt/DeviceView.h +++ b/qt/DeviceView.h @@ -23,6 +23,7 @@ public: void setController(RGBController * controller_ptr); void setNumericalLabels(bool enable); + void setPerLED(bool per_led_mode); protected: void mousePressEvent(QMouseEvent *event); @@ -44,6 +45,7 @@ private: QVector selectedLeds; QVector selectionFlags; QVector previousFlags; + bool per_led; std::vector zone_pos; std::vector led_pos; diff --git a/qt/OpenRGBDevicePage.cpp b/qt/OpenRGBDevicePage.cpp index 72f7f1e0..4361a55a 100644 --- a/qt/OpenRGBDevicePage.cpp +++ b/qt/OpenRGBDevicePage.cpp @@ -600,6 +600,7 @@ void Ui::OpenRGBDevicePage::UpdateModeUi() { ui->PerLEDCheck->setEnabled(true); ui->PerLEDCheck->setChecked(per_led); + ui->DeviceViewBox->setPerLED(true); } else { @@ -607,6 +608,7 @@ void Ui::OpenRGBDevicePage::UpdateModeUi() ui->PerLEDCheck->setAutoExclusive(false); ui->PerLEDCheck->setChecked(false); ui->PerLEDCheck->setAutoExclusive(true); + ui->DeviceViewBox->setPerLED(false); } if(supports_mode_specific)