Skip to content

Info icon widget #2010

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions gui/include/gui/widgets/infoiconwidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2025 Analog Devices Inc.
*
* This file is part of Scopy
* (see https://www.github.com/analogdevicesinc/scopy).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/

#ifndef INFOICONWIDGET_H
#define INFOICONWIDGET_H

#include <QLabel>
#include <QVBoxLayout>
#include <QWidget>
#include <scopy-gui_export.h>

namespace scopy {
class SCOPY_GUI_EXPORT InfoIconWidget : public QWidget
{
Q_OBJECT
public:
explicit InfoIconWidget(QString infoMessage, QWidget *parent = nullptr);

void setInfoMessage(QString infoMessage);
QString getInfoMessage();

private:
QVBoxLayout *m_layout;
QLabel *m_infoIcon;
};
} // namespace scopy

#endif // INFOICONWIDGET_H
5 changes: 5 additions & 0 deletions gui/include/gui/widgets/menucombo.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#ifndef MENUCOMBO_H
#define MENUCOMBO_H

#include "infoiconwidget.h"

#include <QComboBox>
#include <QLabel>
#include <QPen>
Expand All @@ -45,9 +47,11 @@ class SCOPY_GUI_EXPORT MenuCombo : public QWidget

QString title() const;
void setTitle(const QString &newTitle);
void setInfoMessage(QString infoMessage);

private:
QLabel *m_label;
InfoIconWidget *m_infoIcon;
QComboBox *m_combo;
MouseWheelWidgetGuard *m_mouseWheelGuard;
};
Expand All @@ -64,6 +68,7 @@ class SCOPY_GUI_EXPORT MenuComboWidget : public QWidget

QString title() const;
void setTitle(const QString &newTitle);
void setInfoMessage(QString infoMessage);

private:
MenuCombo *m_combo;
Expand Down
3 changes: 3 additions & 0 deletions gui/include/gui/widgets/menuspinbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <QPushButton>
#include <QLabel>
#include <QBoxLayout>
#include <infoiconwidget.h>

namespace scopy {
namespace gui {
Expand Down Expand Up @@ -161,6 +162,7 @@ class SCOPY_GUI_EXPORT MenuSpinbox : public QWidget

public Q_SLOTS:
void setName(const QString &newName);
void setInfoMessage(QString infoMessage);
void setUnit(const QString &newUnit);
void setMinValue(double);
void setMaxValue(double);
Expand All @@ -186,6 +188,7 @@ private Q_SLOTS:
double clamp(double val, double min, double max);

QLabel *m_label;
InfoIconWidget *m_infoIcon;
QLineEdit *m_edit;
QComboBox *m_scaleCb;
QPushButton *m_plus;
Expand Down
5 changes: 5 additions & 0 deletions gui/res/icons/info.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions gui/res/resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
<file>icons/circle_led.svg</file>
<file>icons/device-shapes/square.svg</file>
<file>icons/device-shapes/rounded_square.svg</file>
<file>icons/info.svg</file>
</qresource>
<qresource prefix="/">
<file>icons/scopy-default/icons/search.svg</file>
Expand Down
56 changes: 56 additions & 0 deletions gui/src/widgets/infoiconwidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2025 Analog Devices Inc.
*
* This file is part of Scopy
* (see https://www.github.com/analogdevicesinc/scopy).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/

#include "infoiconwidget.h"

using namespace scopy;

InfoIconWidget::InfoIconWidget(QString infoMessage, QWidget *parent)
: QWidget{parent}
{
m_layout = new QVBoxLayout(this);
m_layout->setMargin(0);
m_layout->setSpacing(0);
this->setLayout(m_layout);

m_infoIcon = new QLabel(this);
QPixmap pixmap(":/gui/icons/info.svg");
m_infoIcon->setPixmap(pixmap);
m_layout->addWidget(m_infoIcon);

m_infoIcon->setVisible(false);

setInfoMessage(infoMessage);
}

void InfoIconWidget::setInfoMessage(QString infoMessage)
{
if(!infoMessage.isEmpty()) {
m_infoIcon->setVisible(true);
m_infoIcon->setToolTip(infoMessage);
} else {
m_infoIcon->setVisible(false);
}
}

QString InfoIconWidget::getInfoMessage() { return m_infoIcon->toolTip(); }

#include "moc_infoiconwidget.cpp"
16 changes: 15 additions & 1 deletion gui/src/widgets/menucombo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ QString MenuComboWidget::title() const { return m_combo->title(); }

void MenuComboWidget::setTitle(const QString &newTitle) { m_combo->setTitle(newTitle); }

void MenuComboWidget::setInfoMessage(QString infoMessage) { m_combo->setInfoMessage(infoMessage); }

MenuCombo::MenuCombo(QString title, QWidget *parent)
: QWidget(parent)
{
Expand All @@ -63,9 +65,19 @@ MenuCombo::MenuCombo(QString title, QWidget *parent)
m_label = new QLabel(title, this);
Style::setStyle(m_label, style::properties::label::subtle);

m_infoIcon = new InfoIconWidget("", parent);

m_combo = new QComboBox(this);

lay->addWidget(m_label);
QHBoxLayout *labelLayout = new QHBoxLayout();
labelLayout->setContentsMargins(0, 0, 0, 0);
labelLayout->setSpacing(5);

labelLayout->addWidget(m_label);
labelLayout->addWidget(m_infoIcon);
labelLayout->addItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Preferred));

lay->addLayout(labelLayout);
lay->addWidget(m_combo);
m_mouseWheelGuard->installEventRecursively(this);
}
Expand All @@ -77,4 +89,6 @@ QString MenuCombo::title() const { return m_label->text(); }

void MenuCombo::setTitle(const QString &newTitle) { m_label->setText(newTitle); }

void MenuCombo::setInfoMessage(QString infoMessage) { m_infoIcon->setInfoMessage(infoMessage); }

#include "moc_menucombo.cpp"
14 changes: 13 additions & 1 deletion gui/src/widgets/menuspinbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ MenuSpinbox::MenuSpinbox(QString name, double val, QString unit, double min, dou
m_label = new QLabel(name, parent);
Style::setStyle(m_label, style::properties::label::subtle);

m_infoIcon = new InfoIconWidget("", parent);

m_edit = new QLineEdit("0", parent);
m_scaleCb = new QComboBox(parent);
m_plus = new QPushButton("", parent);
Expand Down Expand Up @@ -110,7 +112,14 @@ void MenuSpinbox::layoutVertically(bool left)
btnLay->addWidget(m_plus);
btnLay->addWidget(m_minus);

editLay->addWidget(m_label);
QHBoxLayout *labelLayout = new QHBoxLayout();
labelLayout->setContentsMargins(0, 0, 0, 0);
labelLayout->setSpacing(2);
labelLayout->addWidget(m_label);
labelLayout->addWidget(m_infoIcon);
labelLayout->addItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Preferred));

editLay->addItem(labelLayout);
editLay->addWidget(m_edit);

editLay->addWidget(m_scaleCb);
Expand Down Expand Up @@ -170,6 +179,7 @@ void MenuSpinbox::layoutHorizontally(bool left)
btnLay->addWidget(m_plus);

editLay->addWidget(m_label);
editLay->addWidget(m_infoIcon);
editLay->addWidget(m_edit);

editLay->addWidget(m_scaleCb);
Expand Down Expand Up @@ -376,6 +386,8 @@ void MenuSpinbox::setName(const QString &newName)
Q_EMIT nameChanged(newName);
}

void MenuSpinbox::setInfoMessage(QString infoMessage) { m_infoIcon->setInfoMessage(infoMessage); }

double MenuSpinbox::getScaleForPrefix(QString prefix, Qt::CaseSensitivity s)
{
for(int i = 0; i < m_scales.count(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class SCOPY_IIO_WIDGETS_EXPORT CheckBoxAttrUi : public QObject, public GuiStrate
bool isValid() final;

void setCustomTitle(QString title) override;
void setInfoMessage(QString infoMessage) { m_infoIcon->setInfoMessage(infoMessage); }

public Q_SLOTS:
void receiveData(QString currentData, QString optionalData) override;
Expand All @@ -62,6 +63,7 @@ public Q_SLOTS:
MenuOnOffSwitch *m_menuOnOffSwitch;
bool m_isCompact;
QLabel *m_title;
InfoIconWidget *m_infoIcon;
};
} // namespace scopy

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <QWidget>
#include <iio.h>
#include <infoiconwidget.h>
#include <gui/widgets/menucombo.h>
#include "guistrategy/guistrategyinterface.h"
#include "iiowidgetdata.h"
Expand All @@ -48,6 +49,7 @@ class SCOPY_IIO_WIDGETS_EXPORT ComboAttrUi : public QObject, public GuiStrategyI
bool isValid() final;

void setCustomTitle(QString title) override;
void setInfoMessage(QString infoMessage);

public Q_SLOTS:
void receiveData(QString currentData, QString optionalData) override;
Expand All @@ -62,6 +64,7 @@ public Q_SLOTS:
QComboBox *m_comboWidget;
bool m_isCompact;
QLabel *m_title;
InfoIconWidget *m_infoIcon;
MenuCombo *m_comboMenuWidget;
};
} // namespace scopy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <QWidget>
#include <iio.h>
#include <infoiconwidget.h>
#include "guistrategy/guistrategyinterface.h"
#include <gui/widgets/menulineedit.h>
#include "iiowidgetdata.h"
Expand All @@ -49,6 +50,7 @@ class SCOPY_IIO_WIDGETS_EXPORT EditableGuiStrategy : public QObject, public GuiS
bool isValid() override;

void setCustomTitle(QString title) override;
void setInfoMessage(QString infoMessage) { m_infoIcon->setInfoMessage(infoMessage); }

public Q_SLOTS:
void receiveData(QString currentData, QString optionalData) override;
Expand All @@ -63,6 +65,7 @@ public Q_SLOTS:
MenuLineEdit *m_lineEdit;
QString m_lastEmittedText;
QLabel *m_title;
InfoIconWidget *m_infoIcon;
};
} // namespace scopy

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ class SCOPY_IIO_WIDGETS_EXPORT GuiStrategyInterface
* */
virtual bool isValid() = 0;

/**
* @brief Allows user to set custom title
* @param title
* */
virtual void setCustomTitle(QString title) = 0;

public Q_SLOTS:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class SCOPY_IIO_WIDGETS_EXPORT RangeAttrUi : public QObject, public GuiStrategyI

void setCustomTitle(QString title) override;

void setInfoMessage(QString infoMessage);

public Q_SLOTS:
void receiveData(QString currentData, QString optionalData) override;

Expand Down
7 changes: 7 additions & 0 deletions iio-widgets/include/iio-widgets/iiowidgetbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ class SCOPY_IIO_WIDGETS_EXPORT IIOWidgetBuilder : public QObject
*/
IIOWidgetBuilder &title(QString title);

/**
* @brief Sets a info message for the IIOWidget
* @param infoMessage
*/
IIOWidgetBuilder &infoMessage(QString infoMessage);

private:
DataStrategyInterface *createDS();
GuiStrategyInterface *createUIS();
Expand All @@ -193,6 +199,7 @@ class SCOPY_IIO_WIDGETS_EXPORT IIOWidgetBuilder : public QObject
QString m_optionsAttribute;
QString m_optionsValues;
QString m_title;
QString m_infoMessage;
IIOWidgetBuilder::DS m_dataStrategy;
IIOWidgetBuilder::UIS m_uiStrategy;
QWidget *m_widgetParent;
Expand Down
1 change: 1 addition & 0 deletions iio-widgets/include/iio-widgets/iiowidgetdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ struct SCOPY_IIO_WIDGETS_EXPORT IIOWidgetFactoryRecipe
QString data = ""; // the name of the 'main' attribute that will be changed in the iio channel
QString iioDataOptions = ""; // the IIO attribute that describes what values can the attribute take
QString constDataOptions = ""; // the set of constant data that will populate an entry (e.g. combo box, range)
QString infoMessage = ""; // the message that will show when the "i" icon is hovered
};

#endif // SCOPY_IIOWIDGETDATA_H
4 changes: 3 additions & 1 deletion iio-widgets/src/guistrategy/checkboxguistrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ CheckBoxAttrUi::CheckBoxAttrUi(IIOWidgetFactoryRecipe recipe, bool isCompact, QW
if(!m_isCompact) {
m_title = new QLabel(recipe.data, m_ui);
m_title->setWordWrap(true);
m_title->setFixedWidth(m_menuOnOffSwitch->width());
Style::setStyle(m_title, style::properties::label::subtle);
m_ui->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
m_ui->layout()->addWidget(m_title);

m_infoIcon = new InfoIconWidget(recipe.infoMessage, m_ui);
m_ui->layout()->addWidget(m_infoIcon);
}
m_ui->layout()->addWidget(m_menuOnOffSwitch);

Expand Down
Loading
Loading