mirror of
https://github.com/CalcProgrammer1/OpenRGB.git
synced 2026-04-03 22:01:20 -04:00
DeviceView code cleanup, formatting, commenting
This commit is contained in:
1509
qt/DeviceView.cpp
1509
qt/DeviceView.cpp
File diff suppressed because it is too large
Load Diff
118
qt/DeviceView.h
118
qt/DeviceView.h
@@ -16,10 +16,10 @@
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float matrix_x;
|
||||
float matrix_y;
|
||||
float matrix_w;
|
||||
float matrix_h;
|
||||
float matrix_x;
|
||||
float matrix_y;
|
||||
float matrix_w;
|
||||
float matrix_h;
|
||||
} matrix_pos_size_type;
|
||||
|
||||
class DeviceView : public QWidget
|
||||
@@ -29,15 +29,34 @@ public:
|
||||
explicit DeviceView(QWidget *parent = 0);
|
||||
~DeviceView();
|
||||
|
||||
virtual QSize sizeHint () const;
|
||||
virtual QSize minimumSizeHint () const;
|
||||
/*-----------------------------------------------------*\
|
||||
| Qt size hints |
|
||||
\*-----------------------------------------------------*/
|
||||
virtual QSize minimumSizeHint() const;
|
||||
virtual QSize sizeHint() const;
|
||||
|
||||
void setChanged();
|
||||
void setController(RGBController * controller_ptr);
|
||||
void setNumericalLabels(bool enable);
|
||||
void setPerLED(bool per_led_mode);
|
||||
/*-----------------------------------------------------*\
|
||||
| Selection functions |
|
||||
\*-----------------------------------------------------*/
|
||||
bool SelectLED(std::size_t led_idx);
|
||||
bool SelectLEDs(std::vector<std::size_t> leds);
|
||||
bool SelectSegment(std::size_t zone_idx, std::size_t segment_idx, bool add = false);
|
||||
bool SelectZone(std::size_t zone_idx, bool add = false);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Setter functions |
|
||||
\*-----------------------------------------------------*/
|
||||
void ClearSelection();
|
||||
void SetChanged();
|
||||
void SetController(RGBController * controller_ptr);
|
||||
void SetNumericalLabels(bool enable);
|
||||
void SetPerLED(bool per_led_mode);
|
||||
void SetSelectionColor(RGBColor);
|
||||
|
||||
protected:
|
||||
/*-----------------------------------------------------*\
|
||||
| Qt events |
|
||||
\*-----------------------------------------------------*/
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
void mouseMoveEvent(QMouseEvent *event);
|
||||
void mouseReleaseEvent(QMouseEvent *);
|
||||
@@ -45,44 +64,57 @@ protected:
|
||||
void paintEvent(QPaintEvent *);
|
||||
|
||||
private:
|
||||
QSize initSize;
|
||||
bool mouseDown;
|
||||
bool ctrlDown;
|
||||
bool mouseMoved;
|
||||
bool changed;
|
||||
int size;
|
||||
int offset_x;
|
||||
QRect selectionRect;
|
||||
QPoint lastMousePos;
|
||||
QVector<int> previousSelection;
|
||||
QVector<int> selectedLeds;
|
||||
QVector<bool> selectionFlags;
|
||||
QVector<bool> previousFlags;
|
||||
bool per_led;
|
||||
|
||||
std::vector<matrix_pos_size_type> zone_pos;
|
||||
std::vector<matrix_pos_size_type> segment_pos;
|
||||
std::vector<matrix_pos_size_type> led_pos;
|
||||
std::vector<QString> led_labels;
|
||||
|
||||
float matrix_h;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| State tracking variables |
|
||||
\*-----------------------------------------------------*/
|
||||
bool changed;
|
||||
bool ctrl_down;
|
||||
QPoint last_mouse_point;
|
||||
bool mouse_down;
|
||||
bool mouse_moved;
|
||||
bool numerical_labels;
|
||||
bool per_led;
|
||||
|
||||
RGBController* controller;
|
||||
/*-----------------------------------------------------*\
|
||||
| Size tracking variables |
|
||||
\*-----------------------------------------------------*/
|
||||
QSize init_size;
|
||||
float matrix_h;
|
||||
int offset_x;
|
||||
int size;
|
||||
|
||||
QColor posColor(const QPoint &point);
|
||||
/*-----------------------------------------------------*\
|
||||
| Selection tracking variables |
|
||||
\*-----------------------------------------------------*/
|
||||
std::vector<std::size_t> previous_selection;
|
||||
std::vector<std::size_t> selected_leds;
|
||||
QRect selection_rect;
|
||||
std::vector<bool> selection_flags;
|
||||
std::vector<bool> previous_flags;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| UI element tracking variables |
|
||||
\*-----------------------------------------------------*/
|
||||
std::vector<QString> led_labels;
|
||||
std::vector<matrix_pos_size_type> led_pos;
|
||||
std::vector<matrix_pos_size_type> segment_pos;
|
||||
std::vector<matrix_pos_size_type> zone_pos;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Pointer to attached RGBController |
|
||||
\*-----------------------------------------------------*/
|
||||
RGBController* controller;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Private functions |
|
||||
\*-----------------------------------------------------*/
|
||||
void InitDeviceView();
|
||||
void updateSelection();
|
||||
void UpdateSelection();
|
||||
|
||||
signals:
|
||||
void selectionChanged(int selected_zone, int selected_segment, QVector<int>);
|
||||
/*-----------------------------------------------------*\
|
||||
| Signals |
|
||||
\*-----------------------------------------------------*/
|
||||
void selectionChanged(int selected_zone, int selected_segment, std::vector<std::size_t>);
|
||||
|
||||
public slots:
|
||||
bool selectLed(int);
|
||||
bool selectLeds(QVector<int>);
|
||||
bool selectSegment(int zone, int segment, bool add = false);
|
||||
bool selectZone(int zone, bool add = false);
|
||||
void clearSelection(); // Same as selecting the entire device
|
||||
void setSelectionColor(RGBColor);
|
||||
};
|
||||
|
||||
@@ -56,7 +56,7 @@ OpenRGBDevicePage::OpenRGBDevicePage(RGBController *dev, QWidget *parent) :
|
||||
{
|
||||
bool numerical_labels = ui_settings["numerical_labels"];
|
||||
|
||||
ui->DeviceViewBox->setNumericalLabels(numerical_labels);
|
||||
ui->DeviceViewBox->SetNumericalLabels(numerical_labels);
|
||||
}
|
||||
|
||||
if(ui_settings.contains("hex_format"))
|
||||
@@ -74,7 +74,7 @@ OpenRGBDevicePage::OpenRGBDevicePage(RGBController *dev, QWidget *parent) :
|
||||
/*-----------------------------------------------------*\
|
||||
| Initialize Device View |
|
||||
\*-----------------------------------------------------*/
|
||||
ui->DeviceViewBox->setController(device);
|
||||
ui->DeviceViewBox->SetController(device);
|
||||
ui->DeviceViewBoxFrame->hide();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
@@ -293,7 +293,7 @@ void OpenRGBDevicePage::UpdateColor()
|
||||
switch(color_mode)
|
||||
{
|
||||
case MODE_COLORS_PER_LED:
|
||||
ui->DeviceViewBox->setSelectionColor(rgb_color);
|
||||
ui->DeviceViewBox->SetSelectionColor(rgb_color);
|
||||
break;
|
||||
|
||||
case MODE_COLORS_MODE_SPECIFIC:
|
||||
@@ -529,7 +529,7 @@ void OpenRGBDevicePage::UpdateLEDList()
|
||||
if(!ui->ZoneBox->signalsBlocked())
|
||||
{
|
||||
ui->DeviceViewBox->blockSignals(true);
|
||||
ui->DeviceViewBox->clearSelection();
|
||||
ui->DeviceViewBox->ClearSelection();
|
||||
ui->DeviceViewBox->blockSignals(false);
|
||||
}
|
||||
}
|
||||
@@ -586,7 +586,7 @@ void OpenRGBDevicePage::UpdateLEDList()
|
||||
if(!ui->ZoneBox->signalsBlocked())
|
||||
{
|
||||
ui->DeviceViewBox->blockSignals(true);
|
||||
ui->DeviceViewBox->selectZone(selected_zone);
|
||||
ui->DeviceViewBox->SelectZone(selected_zone);
|
||||
ui->DeviceViewBox->blockSignals(false);
|
||||
}
|
||||
}
|
||||
@@ -630,7 +630,7 @@ void OpenRGBDevicePage::UpdateLEDList()
|
||||
if(!ui->ZoneBox->signalsBlocked())
|
||||
{
|
||||
ui->DeviceViewBox->blockSignals(true);
|
||||
ui->DeviceViewBox->selectSegment(selected_zone, selected_segment);
|
||||
ui->DeviceViewBox->SelectSegment(selected_zone, selected_segment);
|
||||
ui->DeviceViewBox->blockSignals(false);
|
||||
}
|
||||
}
|
||||
@@ -832,7 +832,7 @@ void OpenRGBDevicePage::UpdateLEDUi()
|
||||
if(!ui->LEDBox->signalsBlocked())
|
||||
{
|
||||
ui->DeviceViewBox->blockSignals(true);
|
||||
ui->DeviceViewBox->clearSelection();
|
||||
ui->DeviceViewBox->ClearSelection();
|
||||
ui->DeviceViewBox->blockSignals(false);
|
||||
}
|
||||
}
|
||||
@@ -858,7 +858,7 @@ void OpenRGBDevicePage::UpdateLEDUi()
|
||||
if(!ui->LEDBox->signalsBlocked())
|
||||
{
|
||||
ui->DeviceViewBox->blockSignals(true);
|
||||
ui->DeviceViewBox->selectLed(selected_led);
|
||||
ui->DeviceViewBox->SelectLED(selected_led);
|
||||
ui->DeviceViewBox->blockSignals(false);
|
||||
}
|
||||
}
|
||||
@@ -876,7 +876,7 @@ void OpenRGBDevicePage::UpdateLEDUi()
|
||||
if(!ui->LEDBox->signalsBlocked())
|
||||
{
|
||||
ui->DeviceViewBox->blockSignals(true);
|
||||
ui->DeviceViewBox->selectZone(selected_zone);
|
||||
ui->DeviceViewBox->SelectZone(selected_zone);
|
||||
ui->DeviceViewBox->blockSignals(false);
|
||||
}
|
||||
}
|
||||
@@ -910,7 +910,7 @@ void OpenRGBDevicePage::UpdateLEDUi()
|
||||
if(!ui->LEDBox->signalsBlocked())
|
||||
{
|
||||
ui->DeviceViewBox->blockSignals(true);
|
||||
ui->DeviceViewBox->selectLed(globalIndex);
|
||||
ui->DeviceViewBox->SelectLED(globalIndex);
|
||||
ui->DeviceViewBox->blockSignals(false);
|
||||
}
|
||||
}
|
||||
@@ -929,7 +929,7 @@ void OpenRGBDevicePage::UpdateLEDUi()
|
||||
if(!ui->LEDBox->signalsBlocked())
|
||||
{
|
||||
ui->DeviceViewBox->blockSignals(true);
|
||||
ui->DeviceViewBox->selectSegment(selected_zone, selected_segment);
|
||||
ui->DeviceViewBox->SelectSegment(selected_zone, selected_segment);
|
||||
ui->DeviceViewBox->blockSignals(false);
|
||||
}
|
||||
}
|
||||
@@ -963,7 +963,7 @@ void OpenRGBDevicePage::UpdateLEDUi()
|
||||
if(!ui->LEDBox->signalsBlocked())
|
||||
{
|
||||
ui->DeviceViewBox->blockSignals(true);
|
||||
ui->DeviceViewBox->selectLed(globalIndex);
|
||||
ui->DeviceViewBox->SelectLED(globalIndex);
|
||||
ui->DeviceViewBox->blockSignals(false);
|
||||
}
|
||||
}
|
||||
@@ -2041,7 +2041,7 @@ void OpenRGBDevicePage::UpdateInterface(unsigned int update_reason)
|
||||
case RGBCONTROLLER_UPDATE_REASON_CLEARSEGMENTS:
|
||||
case RGBCONTROLLER_UPDATE_REASON_RESIZEZONE:
|
||||
UpdateModeUi();
|
||||
ui->DeviceViewBox->setChanged();
|
||||
ui->DeviceViewBox->SetChanged();
|
||||
ui->DeviceViewBox->repaint();
|
||||
break;
|
||||
}
|
||||
@@ -2119,7 +2119,7 @@ void OpenRGBDevicePage::on_DeviceSaveButton_clicked()
|
||||
}
|
||||
}
|
||||
|
||||
void OpenRGBDevicePage::on_DeviceViewBox_selectionChanged(int selected_zone, int selected_segment, QVector<int> indices)
|
||||
void OpenRGBDevicePage::on_DeviceViewBox_selectionChanged(int selected_zone, int selected_segment, std::vector<std::size_t> indices)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Device View only supports per-LED modes |
|
||||
@@ -2131,11 +2131,12 @@ void OpenRGBDevicePage::on_DeviceViewBox_selectionChanged(int selected_zone, int
|
||||
\*-------------------------------------------------*/
|
||||
if((selected_zone < 0) && (indices.size() == 0))
|
||||
{
|
||||
if(MultipleSelected)
|
||||
{
|
||||
ui->LEDBox->removeItem(ui->LEDBox->count() -1);
|
||||
}
|
||||
if(MultipleSelected)
|
||||
{
|
||||
ui->LEDBox->removeItem(ui->LEDBox->count() -1);
|
||||
}
|
||||
MultipleSelected = false;
|
||||
|
||||
SetSelectedZone(true, -1, -1);
|
||||
}
|
||||
/*-------------------------------------------------*\
|
||||
@@ -2143,11 +2144,12 @@ void OpenRGBDevicePage::on_DeviceViewBox_selectionChanged(int selected_zone, int
|
||||
\*-------------------------------------------------*/
|
||||
else if(selected_zone >= 0)
|
||||
{
|
||||
if(MultipleSelected)
|
||||
{
|
||||
ui->LEDBox->removeItem(ui->LEDBox->count() -1);
|
||||
}
|
||||
if(MultipleSelected)
|
||||
{
|
||||
ui->LEDBox->removeItem(ui->LEDBox->count() -1);
|
||||
}
|
||||
MultipleSelected = false;
|
||||
|
||||
SetSelectedZone(false, selected_zone, selected_segment);
|
||||
}
|
||||
/*-------------------------------------------------*\
|
||||
@@ -2155,11 +2157,12 @@ void OpenRGBDevicePage::on_DeviceViewBox_selectionChanged(int selected_zone, int
|
||||
\*-------------------------------------------------*/
|
||||
else if(indices.size() == 1)
|
||||
{
|
||||
if(MultipleSelected)
|
||||
{
|
||||
ui->LEDBox->removeItem(ui->LEDBox->count() -1);
|
||||
}
|
||||
if(MultipleSelected)
|
||||
{
|
||||
ui->LEDBox->removeItem(ui->LEDBox->count() -1);
|
||||
}
|
||||
MultipleSelected = false;
|
||||
|
||||
ui->ZoneBox->setCurrentIndex(0);
|
||||
ui->LEDBox->setCurrentIndex(indices[0] + 1);
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ private slots:
|
||||
void on_BrightnessSlider_valueChanged(int value);
|
||||
void on_ColorWheelBox_colorChanged(const QColor color);
|
||||
void on_DeviceSaveButton_clicked();
|
||||
void on_DeviceViewBox_selectionChanged(int selected_zone, int selected_segment, QVector<int>);
|
||||
void on_DeviceViewBox_selectionChanged(int selected_zone, int selected_segment, std::vector<std::size_t>);
|
||||
void on_DirectionBox_currentIndexChanged(int index);
|
||||
void on_EditZoneButton_clicked();
|
||||
void on_GreenSpinBox_valueChanged(int green);
|
||||
|
||||
Reference in New Issue
Block a user