Skip to content

Commit

Permalink
regmap: add list of colors for values of the regmap
Browse files Browse the repository at this point in the history
Signed-off-by: IonutMuthi <[email protected]>
  • Loading branch information
IonutMuthi committed Dec 20, 2024
1 parent 72ef3a8 commit afe8227
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
18 changes: 17 additions & 1 deletion gui/style/json/global.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,21 @@
"ch7": "#c7c10a",
"white": "#FFFFFF",
"black": "#000000",
"run_button_color": "&interactive_primary_idle&"
"run_button_color": "&interactive_primary_idle&",
"regmap_value_color_0": "#FF0000",
"regmap_value_color_1": "#00FF00",
"regmap_value_color_2": "#E76423",
"regmap_value_color_3": "#B16EE0",
"regmap_value_color_4": "#2E9E6F",
"regmap_value_color_5": "#3A8EE9",
"regmap_value_color_6": "#F64C5A",
"regmap_value_color_7": "#1694CA",
"regmap_value_color_8": "#E84DB4",
"regmap_value_color_9": "#0000FF",
"regmap_value_color_10": "#FFFF00",
"regmap_value_color_11": "#00FFFF",
"regmap_value_color_12": "#FF00FF",
"regmap_value_color_13": "#8B4513",
"regmap_value_color_14": "#8A2BE2",
"regmap_value_color_15": "#DEB887"
}
30 changes: 30 additions & 0 deletions plugins/regmap/src/regmapplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,35 @@ bool RegmapPlugin::loadPreferencesPage()
"Register background and Bitfield text", "Register text and Bitfield background"},
generalSection));

QWidget *colorWidget = new QWidget(m_preferencesPage);
QVBoxLayout *colorWidgetLayout = new QVBoxLayout(colorWidget);
colorWidgetLayout->setContentsMargins(0, 0, 0, 0);

for(int i = 0; i < 16; i++) {
QString regmapValueColorString = "regmap_value_color_";
QColor color =
Style::getAttribute(QString(regmapValueColorString + QString::number(i)).toStdString().c_str());

QWidget *hContainer = new QWidget; // Horizontal container
QHBoxLayout *hLayout = new QHBoxLayout(hContainer);
hLayout->setContentsMargins(0, 0, 0, 0); // Remove margins for tight layout

// Create a color square
QFrame *colorSquare = new QFrame;
colorSquare->setFixedSize(40, 40); // Increased size of the square
colorSquare->setStyleSheet("background-color: " + color.name() + ";");

QLabel *label = new QLabel("Color for value : " + QString::number(i, 16));
label->setMargin(0); // Remove default margins for the label
hLayout->addWidget(colorSquare);
hLayout->addWidget(label);
hLayout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Fixed));

colorWidgetLayout->addWidget(hContainer); // Add the horizontal container to the main layout
}

lay->addWidget(colorWidget);

return true;
}

Expand Down Expand Up @@ -337,3 +366,4 @@ void RegmapPlugin::InitApi()
js->registerApi(api);
}
#include "moc_regmapplugin.cpp"
#include "regmapstylehelper.hpp"
14 changes: 13 additions & 1 deletion plugins/regmap/src/regmapstylehelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,5 +204,17 @@ void RegmapStyleHelper::smallBlueButton(QPushButton *button, QString objectName)
QString RegmapStyleHelper::getColorBasedOnValue(QString value)
{
uint32_t colorIndex = Utils::convertQStringToUint32(value) % 16;
return StyleHelper::getChannelColor(colorIndex);
return RegmapStyleHelper::getRegmapValueColor(colorIndex);
}

QString RegmapStyleHelper::getRegmapValueColor(int index)
{
if(index <= 15) {
QString regmapValueColorString = "regmap_value_color_";
QColor color = Style::getAttribute(
QString(regmapValueColorString + QString::number(index)).toStdString().c_str());
return color.name();
} else {
return "";
}
}
1 change: 1 addition & 0 deletions plugins/regmap/src/regmapstylehelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class RegmapStyleHelper
private:
QMap<QString, QString> colorMap;
static RegmapStyleHelper *pinstance_;
static QString getRegmapValueColor(int index);
};
} // namespace scopy::regmap
#endif // REGMAPSTYLEHELPER_HPP

0 comments on commit afe8227

Please sign in to comment.