Skip to content

Commit

Permalink
Style: fix hardcoded icon theme folders
Browse files Browse the repository at this point in the history
- update readme

Signed-off-by: Andrei Popa <[email protected]>
  • Loading branch information
andrei47w committed Oct 23, 2024
1 parent 7d8e693 commit b690714
Show file tree
Hide file tree
Showing 23 changed files with 96 additions and 52 deletions.
3 changes: 2 additions & 1 deletion core/src/browsemenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ QWidget *BrowseMenu::createHeader(QWidget *parent)
Style::setStyle(btnCollapseMini, style::properties::widget::toolMenu);
Style::setStyle(btnCollapseMini, style::properties::button::toolButton);
btnCollapseMini->setCheckable(true);
btnCollapseMini->setFixedSize(Style::getDimension(json::global::unit_4), Style::getDimension(json::global::unit_4));
btnCollapseMini->setFixedSize(Style::getDimension(json::global::unit_4),
Style::getDimension(json::global::unit_4));
headerLay->addWidget(btnCollapseMini);

m_btnCollapse = new QPushButton(menuHeader);
Expand Down
3 changes: 2 additions & 1 deletion core/src/emuwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <style.h>

Q_LOGGING_CATEGORY(CAT_EMU_ADD_PAGE, "EmuAddPage")
using namespace scopy;
Expand All @@ -33,7 +34,7 @@ EmuWidget::EmuWidget(QWidget *parent)
QWidget *emuWidget = new QWidget(this);
QGridLayout *emuWidgetLay = new QGridLayout(emuWidget);
emuWidgetLay->setSpacing(10);
StyleHelper::RoundedCornersWidget(emuWidget, "emuWidgetTab");
Style::setStyle(emuWidget, style::properties::widget::basicComponent);

QLabel *demoLabel = new QLabel("Demo option", emuWidget);
StyleHelper::MenuSmallLabel(demoLabel);
Expand Down
3 changes: 2 additions & 1 deletion core/src/iiotabwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <QCheckBox>
#include <QLoggingCategory>
#include <style.h>
#include <stylehelper.h>

#include <iioutil/iioscantask.h>
Expand Down Expand Up @@ -380,7 +381,7 @@ QWidget *IioTabWidget::createUriWidget(QWidget *parent)
QWidget *w = new QWidget(parent);
QGridLayout *layout = new QGridLayout(w);
w->setLayout(layout);
StyleHelper::RoundedCornersWidget(w, "uriAddPage");
Style::setStyle(w, style::properties::widget::basicComponent);

QLabel *uriLabel = new QLabel("URI", w);
StyleHelper::MenuSmallLabel(uriLabel);
Expand Down
2 changes: 1 addition & 1 deletion core/src/scopymainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ ScopyMainWindow::ScopyMainWindow(QWidget *parent)
connect(browseMenu, SIGNAL(requestSave()), this, SLOT(save()));
connect(browseMenu, &BrowseMenu::collapsed, this, [this](bool coll) {
if(coll) {
ui->animHolder->setAnimMin(40);
ui->animHolder->setAnimMin(Style::getDimension(json::global::unit_4));
} else {
ui->animHolder->setAnimMax(230);
}
Expand Down
3 changes: 2 additions & 1 deletion core/src/toolmenuitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ ToolMenuItem::ToolMenuItem(QString uuid, QString name, QString icon, QWidget *pa

m_toolBtn->setIcon(QIcon::fromTheme(m_icon));
m_toolBtn->setCheckable(true);
m_toolBtn->setIconSize(QSize(Style::getDimension(json::global::unit_2_5), Style::getDimension(json::global::unit_2_5)));
m_toolBtn->setIconSize(
QSize(Style::getDimension(json::global::unit_2_5), Style::getDimension(json::global::unit_2_5)));

m_toolRunBtn->setCheckable(true);
m_toolRunBtn->setText("");
Expand Down
3 changes: 2 additions & 1 deletion gui/src/widgets/connectionloadingbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ void ConnectionLoadingBar::setupUi()
m_progressBar->setMaximumHeight(10);
m_progressBar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
m_progressBar->setValue(0);
QString style = QString("QProgressBar::chunk {background-color: %1;}").arg(StyleHelper::getColor("interactive_primary_idle"));
QString style = QString("QProgressBar::chunk {background-color: %1;}")
.arg(StyleHelper::getColor("interactive_primary_idle"));
setStyleSheet(style);

layout()->addWidget(m_loadingLabel);
Expand Down
4 changes: 3 additions & 1 deletion gui/style/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

## Create new style property

Before creating a new style check if you can use an already existing or combine multiple existing styles. Only create a new one if necessary.

Navigate to style/qss/properties and pick/create a folder which matches the widget type you want to create a property for. Inside the folder create a .qss file.
- all style code must be surrounded by {} and have set a property "*[&&property&&=true]{ }". Do not replace the property name, keep it "&&property&&"
- property value can be changed from "true", but when using it in application you also need to specify the correct value
Expand All @@ -23,7 +25,7 @@ Add new .json file in style/json.
- properties can also be overwritten. example: "qss_properties_button_borderButton": "qss_properties_button_basicButton"

## Add plugin style
Create a style folder in your plugin and use the exact same file structure. Only the qss folder is relevant since the json files cannot be overwritten from other plugins.
Create a style folder in your plugin and use the exact same file structure. Only the qss folder is relevant since the json files cannot be overwritten from other plugins. You may add a folder in your style/qss/properties folder with the name of your plugin to avoid overwriting other core .qss style files with the same name.
In your plugin CMakeLists.txt file add the generate_style command.
arguments: **option, style_folder, header_folder** (option should always be "--plugin")

Expand Down
2 changes: 1 addition & 1 deletion gui/style/json/dark.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"background_primary": "#293038",
"background_secondary": "#4a4a4b",
"background_plot": "#0b1117",
"interactive_accent_pressed": "#00427A",
"interactive_accent_pressed": "#fc651c",
"content_success": "#83f81c",
"content_error": "#F44336",
"content_busy": "#F8E71C",
Expand Down
2 changes: 1 addition & 1 deletion gui/style/json/light.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"background_primary": "#FFFFFF",
"background_secondary": "#d4d6d9",
"background_plot": "#FFFFFF",
"interactive_accent_pressed": "#EDF3FC",
"interactive_accent_pressed": "#fc651c",
"content_success": "#83f81c",
"content_error": "#F44336",
"content_busy": "#F8E71C",
Expand Down
4 changes: 4 additions & 0 deletions gui/style/qss/properties/button/squareIconButton.qss
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ QPushButton[&&property&&=true]:checked {
QPushButton[&&property&&=true]:pressed {
background-color:&interactive_primary_idle&;
}

QPushButton[&&property&&=true]:hover {
background-color:&interactive_primary_hover&;
}
10 changes: 7 additions & 3 deletions plugins/adc/src/adcplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,9 @@ void ADCPlugin::newInstrument(ADCInstrumentType t, AcqTreeNode *root, GRTopBlock

if(t == TIME) {
m_toolList.append(SCOPY_NEW_TOOLMENUENTRY("time", "ADC - Time",
":/gui/icons/scopy-default/icons/tool_oscilloscope.svg"));
":/gui/icons/" +
Style::getAttribute(json::theme::icon_theme_folder) +
"/icons/tool_oscilloscope.svg"));
auto tme = m_toolList.last();
tme->setEnabled(true);
tme->setRunBtnVisible(true);
Expand Down Expand Up @@ -282,8 +284,10 @@ void ADCPlugin::newInstrument(ADCInstrumentType t, AcqTreeNode *root, GRTopBlock
m_ctrls.append(adc);
} else if(t == FREQUENCY) {

m_toolList.append(SCOPY_NEW_TOOLMENUENTRY(
"freq", "ADC - Frequency", ":/gui/icons/scopy-default/icons/tool_spectrum_analyzer.svg"));
m_toolList.append(SCOPY_NEW_TOOLMENUENTRY("freq", "ADC - Frequency",
":/gui/icons/" +
Style::getAttribute(json::theme::icon_theme_folder) +
"/icons/tool_spectrum_analyzer.svg"));
auto tme = m_toolList.last();
tme->setEnabled(true);
tme->setRunBtnVisible(true);
Expand Down
4 changes: 3 additions & 1 deletion plugins/adc/src/freq/fftplotcomponentsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QWidget>
#include <QLineEdit>
#include "fftplotcomponentchannel.h"
#include <style.h>

#include <gnuradio/fft/window.h>

Expand Down Expand Up @@ -149,7 +150,8 @@ FFTPlotComponentSettings::FFTPlotComponentSettings(FFTPlotComponent *plt, QWidge

m_settingsPlotHover = new QPushButton("", nullptr);
m_settingsPlotHover->setMaximumSize(16, 16);
m_settingsPlotHover->setIcon(QIcon(":/gui/icons/scopy-default/icons/preferences.svg"));
m_settingsPlotHover->setIcon(
QIcon(":/gui/icons/" + Style::getAttribute(json::theme::icon_theme_folder) + "/icons/preferences.svg"));

connect(m_settingsPlotHover, &QAbstractButton::clicked, this, [=]() { Q_EMIT requestSettings(); });

Expand Down
4 changes: 3 additions & 1 deletion plugins/adc/src/time/timeplotcomponentsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QWidget>
#include <QLineEdit>
#include <timeplotcomponentchannel.h>
#include <style.h>

using namespace scopy;
using namespace scopy::adc;
Expand Down Expand Up @@ -153,7 +154,8 @@ TimePlotComponentSettings::TimePlotComponentSettings(TimePlotComponent *plt, QWi

m_settingsPlotHover = new QPushButton("", nullptr);
m_settingsPlotHover->setMaximumSize(16, 16);
m_settingsPlotHover->setIcon(QIcon(":/gui/icons/scopy-default/icons/preferences.svg"));
m_settingsPlotHover->setIcon(
QIcon(":/gui/icons/" + Style::getAttribute(json::theme::icon_theme_folder) + "/icons/preferences.svg"));

connect(m_settingsPlotHover, &QAbstractButton::clicked, this, [=]() { Q_EMIT requestSettings(); });

Expand Down
9 changes: 6 additions & 3 deletions plugins/dac/src/dacplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "dacutils.h"

#include <QLabel>
#include <style.h>

#include <iioutil/connectionprovider.h>
#include <gui/deviceinfopage.h>
Expand Down Expand Up @@ -55,14 +56,16 @@ bool DACPlugin::loadPage()

bool DACPlugin::loadIcon()
{
SCOPY_PLUGIN_ICON(":/gui/icons/scopy-default/icons/tool_oscilloscope.svg");
SCOPY_PLUGIN_ICON(":/gui/icons/" + Style::getAttribute(json::theme::icon_theme_folder) +
"/icons/tool_oscilloscope.svg");
return true;
}

void DACPlugin::loadToolList()
{
m_toolList.append(
SCOPY_NEW_TOOLMENUENTRY("dac", "DAC", ":/gui/icons/scopy-default/icons/tool_signal_generator.svg"));
m_toolList.append(SCOPY_NEW_TOOLMENUENTRY("dac", "DAC",
":/gui/icons/" + Style::getAttribute(json::theme::icon_theme_folder) +
"/icons/tool_signal_generator.svg"));
}

void DACPlugin::unload()
Expand Down
3 changes: 2 additions & 1 deletion plugins/datalogger/include/datalogger/dataloggerplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public Q_SLOTS:
DataLogger_API *api;
bool isRunning = false;
int toolIndex = 0;
QString toolIcon = ":/gui/icons/" + Style::getAttribute(json::theme::icon_theme_folder) + "/icons/tool_datalogger.svg";
QString toolIcon =
":/gui/icons/" + Style::getAttribute(json::theme::icon_theme_folder) + "/icons/tool_datalogger.svg";
};
} // namespace scopy::datamonitor
#endif // DATALOGGERPLUGIN_H
3 changes: 2 additions & 1 deletion plugins/datalogger/src/dataloggerplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ bool DataLoggerPlugin::loadPage() { return false; }

bool DataLoggerPlugin::loadIcon()
{
SCOPY_PLUGIN_ICON(":/gui/icons/scopy-default/icons/datalogger.svg");
SCOPY_PLUGIN_ICON(":/gui/icons/" + Style::getAttribute(json::theme::icon_theme_folder) +
"/icons/datalogger.svg");
return true;
}

Expand Down
4 changes: 3 additions & 1 deletion plugins/m2k/m2k-gui/src/channel_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "gui/dynamicWidget.h"

#include <QHBoxLayout>
#include <style.h>

using namespace scopy;
using namespace scopy::m2kgui;
Expand Down Expand Up @@ -34,7 +35,8 @@ ChannelManager::ChannelManager(ChannelsPositionEnum position, QWidget *parent)
toolStatus = new QLabel("");
channelManagerToggled = false;

QStringList icons = QStringList() << ":/gui/icons/scopy-default/icons/menu.svg";
QStringList icons = QStringList()
<< ":/gui/icons/" + Style::getAttribute(json::theme::icon_theme_folder) + "/icons/menu.svg";

QIcon my_icon;
my_icon.addFile(icons[0], QSize(), QIcon::Normal);
Expand Down
5 changes: 4 additions & 1 deletion plugins/m2k/m2k-gui/src/channel_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <QButtonGroup>

#include <style.h>
#include <utils.h>

using namespace scopy;
Expand Down Expand Up @@ -54,7 +55,9 @@ ChannelWidget::ChannelWidget(int id, bool deletable, bool simplified, QColor col
nameButton()->installEventFilter(this);
m_channelWSpacer = new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Fixed);
setStyleSheet("scopy--ChannelWidget QPushButton#btn:hover:!pressed:!checked { border-image: "
"url(:/gui/icons/scopy-default/icons/setup_btn_hover.svg) }");
"url(:/gui/icons/" +
Style::getAttribute(json::theme::icon_theme_folder) +
"/icons/setup_btn_hover.svg) }");
}

ChannelWidget::~ChannelWidget()
Expand Down
3 changes: 2 additions & 1 deletion plugins/m2k/m2k-gui/src/linked_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ LinkedButton::LinkedButton(QWidget *parent)
{
setDynamicProperty(this, "info_button", true);

this->setIcon(Style::getPixmap(":/gui/icons/scopy-default/icons/info"));
this->setIcon(
Style::getPixmap(":/gui/icons/" + Style::getAttribute(json::theme::icon_theme_folder) + "/icons/info"));
this->setIconSize(QSize(32, 32));

this->setToolTip("See more info");
Expand Down
3 changes: 3 additions & 0 deletions plugins/m2k/src/m2kplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,13 @@ bool M2kPlugin::loadExtraButtons()
{

m_btnIdentify = new QPushButton("Identify");
Style::setStyle(m_btnIdentify, style::properties::button::grayButton);
m_extraButtons.append(m_btnIdentify);
m_btnCalibrate = new QPushButton("Calibrate");
Style::setStyle(m_btnCalibrate, style::properties::button::grayButton);
m_extraButtons.append(m_btnCalibrate);
m_btnRegister = new QPushButton("Register");
Style::setStyle(m_btnRegister, style::properties::button::grayButton);
m_extraButtons.append(m_btnRegister);

m_btnCalibrate->setDisabled(true);
Expand Down
Loading

0 comments on commit b690714

Please sign in to comment.