Segments
This commit is contained in:
parent
ead55f4ea6
commit
447e936464
14 changed files with 443 additions and 23 deletions
|
|
@ -20,6 +20,7 @@
|
|||
#define PAD_LED 0.1
|
||||
#define PAD_TEXT 0.1
|
||||
#define PAD_ZONE 1.0
|
||||
#define PAD_SEGMENT 0.9
|
||||
#define SIZE_TEXT 0.5
|
||||
|
||||
DeviceView::DeviceView(QWidget *parent) :
|
||||
|
|
@ -226,6 +227,7 @@ void DeviceView::InitDeviceView()
|
|||
| Process position and size for zones |
|
||||
\*-----------------------------------------------------*/
|
||||
unsigned int maxWidth = 0;
|
||||
unsigned int segment_count = 0;
|
||||
float totalHeight = 0;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
|
|
@ -245,6 +247,17 @@ void DeviceView::InitDeviceView()
|
|||
| For all other zones, compute the height including |
|
||||
| wrap-around |
|
||||
\*-----------------------------------------------------*/
|
||||
else if(controller->zones[zone_idx].segments.size() > 0)
|
||||
{
|
||||
for(std::size_t segment_idx = 0; segment_idx < controller->zones[zone_idx].segments.size(); segment_idx++)
|
||||
{
|
||||
unsigned int count = controller->zones[zone_idx].segments[segment_idx].leds_count;
|
||||
zone_pos[zone_idx].matrix_w = std::min(count, (unsigned int)MAX_COLS);
|
||||
totalHeight += (count / MAX_COLS) + ((count % MAX_COLS) > 0);
|
||||
|
||||
segment_count++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned int count = controller->zones[zone_idx].leds_count;
|
||||
|
|
@ -261,13 +274,17 @@ void DeviceView::InitDeviceView()
|
|||
}
|
||||
}
|
||||
|
||||
segment_pos.resize(segment_count);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Add some space for zone names and padding |
|
||||
\*-----------------------------------------------------*/
|
||||
totalHeight += controller->zones.size() * PAD_ZONE;
|
||||
totalHeight += segment_count * PAD_SEGMENT;
|
||||
|
||||
float current_y = 0; // We will be descending, placing each zone one unit below the previous one
|
||||
matrix_h = totalHeight;
|
||||
segment_count = 0;
|
||||
|
||||
for(std::size_t zone_idx = 0; zone_idx < controller->zones.size(); zone_idx++)
|
||||
{
|
||||
|
|
@ -366,6 +383,43 @@ void DeviceView::InitDeviceView()
|
|||
|
||||
current_y += map->height;
|
||||
}
|
||||
else if(controller->zones[zone_idx].segments.size() > 0)
|
||||
{
|
||||
for(std::size_t segment_idx = 0; segment_idx < controller->zones[zone_idx].segments.size(); segment_idx++)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Calculate segment label position and size |
|
||||
\*-----------------------------------------------------*/
|
||||
segment_pos[segment_count].matrix_x = (maxWidth - zone_pos[zone_idx].matrix_w) / 2.0;
|
||||
segment_pos[segment_count].matrix_y = current_y + SIZE_TEXT;
|
||||
segment_pos[segment_count].matrix_w = zone_pos[zone_idx].matrix_w;
|
||||
segment_pos[segment_count].matrix_h = SIZE_TEXT - PAD_TEXT;
|
||||
current_y += PAD_SEGMENT;
|
||||
|
||||
segment_count++;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Calculate LED box positions for segmented zones |
|
||||
\*-----------------------------------------------------*/
|
||||
unsigned int leds_count = controller->zones[zone_idx].segments[segment_idx].leds_count;
|
||||
|
||||
for(unsigned int led_idx = 0; led_idx < leds_count; led_idx++)
|
||||
{
|
||||
unsigned int led_pos_idx = controller->zones[zone_idx].start_idx + controller->zones[zone_idx].segments[segment_idx].start_idx + led_idx;
|
||||
|
||||
led_pos[led_pos_idx].matrix_x = zone_pos[zone_idx].matrix_x + ((led_idx % MAX_COLS) + PAD_LED);
|
||||
led_pos[led_pos_idx].matrix_y = current_y + ((led_idx / MAX_COLS) + PAD_LED);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| LED is a 1x1 square, minus padding on all sides |
|
||||
\*-----------------------------------------------------*/
|
||||
led_pos[led_pos_idx].matrix_w = (1 - (2 * PAD_LED));
|
||||
led_pos[led_pos_idx].matrix_h = (1 - (2 * PAD_LED));
|
||||
}
|
||||
|
||||
current_y += (leds_count / MAX_COLS) + ((leds_count % MAX_COLS) > 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
|
|
@ -409,7 +463,7 @@ void DeviceView::InitDeviceView()
|
|||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Scale the zones and LEDs |
|
||||
| Scale the zones, segments, and LEDs |
|
||||
| |
|
||||
| Atom is the width of a single square; if the whole |
|
||||
| thing becomes too tall, we ignore it and let the view |
|
||||
|
|
@ -425,6 +479,14 @@ void DeviceView::InitDeviceView()
|
|||
zone_pos[zone_idx].matrix_h *= atom;
|
||||
}
|
||||
|
||||
for(std::size_t segment_idx = 0; segment_idx < segment_pos.size(); segment_idx++)
|
||||
{
|
||||
segment_pos[segment_idx].matrix_x *= atom;
|
||||
segment_pos[segment_idx].matrix_y *= atom;
|
||||
segment_pos[segment_idx].matrix_w *= atom;
|
||||
segment_pos[segment_idx].matrix_h *= atom;
|
||||
}
|
||||
|
||||
for(std::size_t led_idx = 0; led_idx < led_pos.size(); led_idx++)
|
||||
{
|
||||
led_pos[led_idx].matrix_x *= atom;
|
||||
|
|
@ -547,7 +609,7 @@ void DeviceView::mouseReleaseEvent(QMouseEvent* event)
|
|||
|
||||
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 posx = zone_pos[zone_idx].matrix_x * size + offset_x + 12;
|
||||
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;
|
||||
|
|
@ -656,8 +718,10 @@ void DeviceView::paintEvent(QPaintEvent* /* event */)
|
|||
painter.setFont(font);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zone names |
|
||||
| Zone and Segment names |
|
||||
\*-----------------------------------------------------*/
|
||||
unsigned int segment_count = 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;
|
||||
|
|
@ -676,6 +740,28 @@ void DeviceView::paintEvent(QPaintEvent* /* event */)
|
|||
painter.setPen(palette().windowText().color());
|
||||
}
|
||||
painter.drawText(posx, posy + posh, QString(controller->zones[zone_idx].name.c_str()));
|
||||
|
||||
for(std::size_t segment_idx = 0; segment_idx < controller->zones[zone_idx].segments.size(); segment_idx++)
|
||||
{
|
||||
posx = segment_pos[segment_count].matrix_x * size + offset_x;
|
||||
posy = segment_pos[segment_count].matrix_y * size;
|
||||
posw = segment_pos[segment_count].matrix_w * size;
|
||||
posh = segment_pos[segment_count].matrix_h * size;
|
||||
|
||||
segment_count++;
|
||||
|
||||
rect = {posx, posy, posw, posh};
|
||||
|
||||
if(rect.contains(lastMousePos) && (!mouseDown || !mouseMoved))
|
||||
{
|
||||
painter.setPen(palette().highlight().color());
|
||||
}
|
||||
else
|
||||
{
|
||||
painter.setPen(palette().windowText().color());
|
||||
}
|
||||
painter.drawText(posx, posy + posh, QString(controller->zones[zone_idx].segments[segment_idx].name.c_str()));
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ private:
|
|||
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;
|
||||
|
||||
|
|
|
|||
|
|
@ -1089,16 +1089,12 @@ void Ui::OpenRGBDevicePage::on_ResizeButton_clicked()
|
|||
|
||||
if(device->zones[selected_zone].type == ZONE_TYPE_LINEAR)
|
||||
{
|
||||
OpenRGBZoneResizeDialog dlg(device->zones[selected_zone].leds_min,
|
||||
device->zones[selected_zone].leds_max,
|
||||
device->zones[selected_zone].leds_count);
|
||||
OpenRGBZoneResizeDialog dlg(device, selected_zone);
|
||||
|
||||
int new_size = dlg.show();
|
||||
|
||||
if(new_size >= 0)
|
||||
{
|
||||
device->ResizeZone(selected_zone, new_size);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Update LED box |
|
||||
\*-----------------------------------------------------*/
|
||||
|
|
@ -1117,7 +1113,7 @@ void Ui::OpenRGBDevicePage::on_ResizeButton_clicked()
|
|||
}
|
||||
}
|
||||
break;
|
||||
|
||||
#if 0
|
||||
case MODE_COLORS_MODE_SPECIFIC:
|
||||
{
|
||||
OpenRGBZoneResizeDialog dlg(device->modes[device->active_mode].colors_min,
|
||||
|
|
@ -1135,6 +1131,7 @@ void Ui::OpenRGBDevicePage::on_ResizeButton_clicked()
|
|||
UpdateMode();
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -276,7 +276,7 @@
|
|||
<item row="0" column="3">
|
||||
<widget class="QPushButton" name="ResizeButton">
|
||||
<property name="text">
|
||||
<string>Resize</string>
|
||||
<string>Edit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
|
|||
|
|
@ -1,11 +1,20 @@
|
|||
#include "OpenRGBZoneResizeDialog.h"
|
||||
|
||||
#include <QLineEdit>
|
||||
|
||||
using namespace Ui;
|
||||
|
||||
OpenRGBZoneResizeDialog::OpenRGBZoneResizeDialog(int size_min, int size_max, int size_current, QWidget *parent) :
|
||||
OpenRGBZoneResizeDialog::OpenRGBZoneResizeDialog(RGBController* edit_dev_ptr, unsigned int edit_zone_idx_val, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::OpenRGBZoneResizeDialogUi)
|
||||
{
|
||||
edit_dev = edit_dev_ptr;
|
||||
edit_zone_idx = edit_zone_idx_val;
|
||||
|
||||
unsigned int size_min = edit_dev->zones[edit_zone_idx].leds_min;
|
||||
unsigned int size_max = edit_dev->zones[edit_zone_idx].leds_max;
|
||||
unsigned int size_current = edit_dev->zones[edit_zone_idx].leds_count;
|
||||
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->ResizeSlider->setRange(size_min, size_max);
|
||||
|
|
@ -13,6 +22,23 @@ OpenRGBZoneResizeDialog::OpenRGBZoneResizeDialog(int size_min, int size_max, int
|
|||
|
||||
ui->ResizeSlider->setValue(size_current);
|
||||
ui->ResizeBox->setValue(size_current);
|
||||
|
||||
for(unsigned int segment_idx = 0; segment_idx < edit_dev->zones[edit_zone_idx].segments.size(); segment_idx++)
|
||||
{
|
||||
QTreeWidgetItem* new_item = new QTreeWidgetItem(ui->SegmentsTreeWidget);
|
||||
|
||||
QLineEdit* lineedit_name = new QLineEdit(ui->SegmentsTreeWidget);
|
||||
QLineEdit* lineedit_start = new QLineEdit(ui->SegmentsTreeWidget);
|
||||
QLineEdit* lineedit_length = new QLineEdit(ui->SegmentsTreeWidget);
|
||||
|
||||
lineedit_name->setText(QString::fromStdString(edit_dev->zones[edit_zone_idx].segments[segment_idx].name));
|
||||
lineedit_start->setText(QString::number(edit_dev->zones[edit_zone_idx].segments[segment_idx].start_idx));
|
||||
lineedit_length->setText(QString::number(edit_dev->zones[edit_zone_idx].segments[segment_idx].leds_count));
|
||||
|
||||
ui->SegmentsTreeWidget->setItemWidget(new_item, 0, lineedit_name);
|
||||
ui->SegmentsTreeWidget->setItemWidget(new_item, 1, lineedit_start);
|
||||
ui->SegmentsTreeWidget->setItemWidget(new_item, 2, lineedit_length);
|
||||
}
|
||||
}
|
||||
|
||||
OpenRGBZoneResizeDialog::~OpenRGBZoneResizeDialog()
|
||||
|
|
@ -57,5 +83,43 @@ int Ui::OpenRGBZoneResizeDialog::show()
|
|||
ret_val = ui->ResizeBox->value();
|
||||
}
|
||||
|
||||
if(ret_val >= 0)
|
||||
{
|
||||
edit_dev->ResizeZone(edit_zone_idx, ret_val);
|
||||
|
||||
edit_dev->zones[edit_zone_idx].segments.clear();
|
||||
|
||||
for(unsigned int item_idx = 0; item_idx < ui->SegmentsTreeWidget->topLevelItemCount(); item_idx++)
|
||||
{
|
||||
segment new_segment;
|
||||
new_segment.type = ZONE_TYPE_LINEAR;
|
||||
new_segment.name = ((QLineEdit*)ui->SegmentsTreeWidget->itemWidget(ui->SegmentsTreeWidget->topLevelItem(item_idx), 0))->text().toStdString();
|
||||
new_segment.start_idx = ((QLineEdit*)ui->SegmentsTreeWidget->itemWidget(ui->SegmentsTreeWidget->topLevelItem(item_idx), 1))->text().toInt();
|
||||
new_segment.leds_count = ((QLineEdit*)ui->SegmentsTreeWidget->itemWidget(ui->SegmentsTreeWidget->topLevelItem(item_idx), 2))->text().toInt();
|
||||
|
||||
edit_dev->zones[edit_zone_idx].segments.push_back(new_segment);
|
||||
}
|
||||
}
|
||||
|
||||
return(ret_val);
|
||||
}
|
||||
|
||||
void Ui::OpenRGBZoneResizeDialog::on_AddSegmentButton_clicked()
|
||||
{
|
||||
QTreeWidgetItem* new_item = new QTreeWidgetItem(ui->SegmentsTreeWidget);
|
||||
|
||||
QLineEdit* lineedit_name = new QLineEdit(ui->SegmentsTreeWidget);
|
||||
QLineEdit* lineedit_start = new QLineEdit(ui->SegmentsTreeWidget);
|
||||
QLineEdit* lineedit_length = new QLineEdit(ui->SegmentsTreeWidget);
|
||||
|
||||
ui->SegmentsTreeWidget->setItemWidget(new_item, 0, lineedit_name);
|
||||
ui->SegmentsTreeWidget->setItemWidget(new_item, 1, lineedit_start);
|
||||
ui->SegmentsTreeWidget->setItemWidget(new_item, 2, lineedit_length);
|
||||
}
|
||||
|
||||
|
||||
void Ui::OpenRGBZoneResizeDialog::on_RemoveSegmentButton_clicked()
|
||||
{
|
||||
ui->SegmentsTreeWidget->takeTopLevelItem(ui->SegmentsTreeWidget->topLevelItemCount() - 1);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
#include <QDialog>
|
||||
#include "ui_OpenRGBZoneResizeDialog.h"
|
||||
|
||||
#include "RGBController.h"
|
||||
|
||||
namespace Ui {
|
||||
class OpenRGBZoneResizeDialog;
|
||||
}
|
||||
|
|
@ -13,7 +15,7 @@ class Ui::OpenRGBZoneResizeDialog : public QDialog
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit OpenRGBZoneResizeDialog(int size_min, int size_max, int size_current, QWidget *parent = nullptr);
|
||||
explicit OpenRGBZoneResizeDialog(RGBController* edit_dev_ptr, unsigned int edit_zone_idx_val, QWidget *parent = nullptr);
|
||||
~OpenRGBZoneResizeDialog();
|
||||
|
||||
int show();
|
||||
|
|
@ -24,8 +26,14 @@ private slots:
|
|||
|
||||
void on_ResizeBox_valueChanged(int arg1);
|
||||
|
||||
void on_AddSegmentButton_clicked();
|
||||
|
||||
void on_RemoveSegmentButton_clicked();
|
||||
|
||||
private:
|
||||
Ui::OpenRGBZoneResizeDialogUi *ui;
|
||||
RGBController* edit_dev;
|
||||
unsigned int edit_zone_idx;
|
||||
};
|
||||
|
||||
#endif // OPENRGBZONERESIZEDIALOG_H
|
||||
|
|
|
|||
|
|
@ -6,14 +6,32 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>233</width>
|
||||
<height>73</height>
|
||||
<width>340</width>
|
||||
<height>187</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Resize Zone</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout" columnstretch="1,0">
|
||||
<item row="3" column="0" colspan="2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="AddSegmentButton">
|
||||
<property name="text">
|
||||
<string>Add Segment</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="RemoveSegmentButton">
|
||||
<property name="text">
|
||||
<string>Remove Segment</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QTooltipedSlider" name="ResizeSlider">
|
||||
<property name="sizePolicy">
|
||||
|
|
@ -27,17 +45,29 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QSpinBox" name="ResizeBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QTreeWidget" name="SegmentsTreeWidget">
|
||||
<property name="columnCount">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string notr="true">Name</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Start</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Length</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<item row="4" column="0" colspan="2">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
|
|
@ -53,6 +83,16 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QSpinBox" name="ResizeBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue