Skip to content

Commit

Permalink
[gui] Control panel tooltip and layout.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlyr committed Apr 5, 2024
1 parent 4b74e6a commit 665430a
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/Gui/ParameterSetEditor/ParameterSetEditor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class RA_GUI_API VariableSetEditor : public Widgets::ControlPanel
VariableSetEditor& operator=( const VariableSetEditor& ) = delete;
VariableSetEditor( VariableSetEditor&& ) = delete;
VariableSetEditor&& operator=( VariableSetEditor&& ) = delete;
~VariableSetEditor() override = default;
~VariableSetEditor() = default;

Check warning on line 47 in src/Gui/ParameterSetEditor/ParameterSetEditor.hpp

View check run for this annotation

Codecov / codecov/patch

src/Gui/ParameterSetEditor/ParameterSetEditor.hpp#L47

Added line #L47 was not covered by tests

/** \brief Update the different UI element with the given renderParameter, using the given
* constraints.
Expand Down
68 changes: 40 additions & 28 deletions src/Gui/Widgets/ControlPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@ namespace Ra::Gui::Widgets {
ControlPanel::ControlPanel( const std::string& name, bool hline, QWidget* parent ) :
QFrame( parent ) {
setObjectName( name.c_str() );
m_mainLayout = new QVBoxLayout( this );
m_contentLayout = new QGridLayout( this );
m_mainLayout = new QVBoxLayout();
m_mainLayout->setObjectName( "main layout" );
m_contentLayout = new QGridLayout();
m_contentLayout->setObjectName( "first content layout" );

Check warning on line 26 in src/Gui/Widgets/ControlPanel.cpp

View check run for this annotation

Codecov / codecov/patch

src/Gui/Widgets/ControlPanel.cpp#L23-L26

Added lines #L23 - L26 were not covered by tests

if ( !name.empty() ) {
auto panelName = new QLabel( this );
auto panelName = new QLabel();
panelName->setText( name.c_str() );
m_mainLayout->addWidget( panelName );

Check warning on line 31 in src/Gui/Widgets/ControlPanel.cpp

View check run for this annotation

Codecov / codecov/patch

src/Gui/Widgets/ControlPanel.cpp#L28-L31

Added lines #L28 - L31 were not covered by tests
}
if ( hline ) {
QFrame* line;
line = new QFrame( this );
line = new QFrame();
line->setFrameShape( QFrame::HLine );
line->setFrameShadow( QFrame::Sunken );
m_mainLayout->addWidget( line );

Check warning on line 38 in src/Gui/Widgets/ControlPanel.cpp

View check run for this annotation

Codecov / codecov/patch

src/Gui/Widgets/ControlPanel.cpp#L35-L38

Added lines #L35 - L38 were not covered by tests
Expand All @@ -46,13 +48,15 @@ void ControlPanel::addOption( const std::string& name,
std::function<void( bool )> callback,
bool set,
const std::string& tooltip ) {
auto label = new QLabel( name.c_str(), this );
auto button = new QCheckBox( this );
auto label = new QLabel( name.c_str() );
auto button = new QCheckBox();

Check warning on line 52 in src/Gui/Widgets/ControlPanel.cpp

View check run for this annotation

Codecov / codecov/patch

src/Gui/Widgets/ControlPanel.cpp#L51-L52

Added lines #L51 - L52 were not covered by tests
button->setAutoExclusive( false );
button->setChecked( set );
if ( !tooltip.empty() ) {
button->setToolTip(
QString( "<qt>%1</qt>" ).arg( QString( tooltip.c_str() ).toHtmlEscaped() ) );
auto tooltipString =
QString( "<qt>%1</qt>" ).arg( QString( tooltip.c_str() ).toHtmlEscaped() );
label->setToolTip( tooltipString );
button->setToolTip( tooltipString );

Check warning on line 59 in src/Gui/Widgets/ControlPanel.cpp

View check run for this annotation

Codecov / codecov/patch

src/Gui/Widgets/ControlPanel.cpp#L57-L59

Added lines #L57 - L59 were not covered by tests
}
connect( button, &QCheckBox::stateChanged, std::move( callback ) );

Expand All @@ -62,7 +66,7 @@ void ControlPanel::addOption( const std::string& name,
}

void ControlPanel::addLabel( const std::string& text ) {
auto label = new QLabel( text.c_str(), this );
auto label = new QLabel( text.c_str() );
auto index = m_contentLayout->rowCount();
m_contentLayout->addWidget( label, index, 0, 1, -1 );

Check warning on line 71 in src/Gui/Widgets/ControlPanel.cpp

View check run for this annotation

Codecov / codecov/patch

src/Gui/Widgets/ControlPanel.cpp#L69-L71

Added lines #L69 - L71 were not covered by tests
}
Expand All @@ -88,14 +92,16 @@ void ControlPanel::addSliderInput( const std::string& name,
int min,
int max,
const std::string& tooltip ) {
auto inputLabel = new QLabel( tr( name.c_str() ), this );
auto inputLabel = new QLabel( tr( name.c_str() ) );

Check warning on line 95 in src/Gui/Widgets/ControlPanel.cpp

View check run for this annotation

Codecov / codecov/patch

src/Gui/Widgets/ControlPanel.cpp#L95

Added line #L95 was not covered by tests
auto sliderLayout = new QHBoxLayout();
auto inputField = new QSlider( Qt::Horizontal, this );
auto inputField = new QSlider( Qt::Horizontal );

Check warning on line 97 in src/Gui/Widgets/ControlPanel.cpp

View check run for this annotation

Codecov / codecov/patch

src/Gui/Widgets/ControlPanel.cpp#L97

Added line #L97 was not covered by tests
if ( !tooltip.empty() ) {
inputLabel->setToolTip(
QString( "<qt>%1</qt>" ).arg( QString( tooltip.c_str() ).toHtmlEscaped() ) );
auto tooltipString =
QString( "<qt>%1</qt>" ).arg( QString( tooltip.c_str() ).toHtmlEscaped() );
inputLabel->setToolTip( tooltipString );
inputField->setToolTip( tooltipString );

Check warning on line 102 in src/Gui/Widgets/ControlPanel.cpp

View check run for this annotation

Codecov / codecov/patch

src/Gui/Widgets/ControlPanel.cpp#L100-L102

Added lines #L100 - L102 were not covered by tests
}
auto spinbox = new QSpinBox( this );
auto spinbox = new QSpinBox();

Check warning on line 104 in src/Gui/Widgets/ControlPanel.cpp

View check run for this annotation

Codecov / codecov/patch

src/Gui/Widgets/ControlPanel.cpp#L104

Added line #L104 was not covered by tests
inputField->setRange( min, max );
inputField->setValue( initial );
inputField->setTickPosition( QSlider::TicksAbove );
Expand All @@ -122,11 +128,13 @@ void ControlPanel::addPowerSliderInput( const std::string& name,
double min,
double max,
const std::string& tooltip ) {
auto inputLabel = new QLabel( tr( name.c_str() ), this );
auto inputLabel = new QLabel( tr( name.c_str() ) );
auto inputField = new PowerSlider();

Check warning on line 132 in src/Gui/Widgets/ControlPanel.cpp

View check run for this annotation

Codecov / codecov/patch

src/Gui/Widgets/ControlPanel.cpp#L131-L132

Added lines #L131 - L132 were not covered by tests
if ( !tooltip.empty() ) {
inputLabel->setToolTip(
QString( "<qt>%1</qt>" ).arg( QString( tooltip.c_str() ).toHtmlEscaped() ) );
auto tooltipString =
QString( "<qt>%1</qt>" ).arg( QString( tooltip.c_str() ).toHtmlEscaped() );
inputLabel->setToolTip( tooltipString );
inputField->setToolTip( tooltipString );

Check warning on line 137 in src/Gui/Widgets/ControlPanel.cpp

View check run for this annotation

Codecov / codecov/patch

src/Gui/Widgets/ControlPanel.cpp#L135-L137

Added lines #L135 - L137 were not covered by tests
}
inputField->setObjectName( name.c_str() );
inputField->setRange( min, max );
Expand All @@ -145,12 +153,14 @@ void ControlPanel::addMatrixInput( const std::string& name,
int dec,
const std::string& tooltip ) {

auto inputLabel = new QLabel( tr( name.c_str() ), this );
auto inputField = new MatrixEditor( initial, dec, this );
auto inputLabel = new QLabel( tr( name.c_str() ) );
auto inputField = new MatrixEditor( initial, dec );

Check warning on line 157 in src/Gui/Widgets/ControlPanel.cpp

View check run for this annotation

Codecov / codecov/patch

src/Gui/Widgets/ControlPanel.cpp#L156-L157

Added lines #L156 - L157 were not covered by tests

if ( !tooltip.empty() ) {
inputLabel->setToolTip(
QString( "<qt>%1</qt>" ).arg( QString( tooltip.c_str() ).toHtmlEscaped() ) );
auto tooltipString =
QString( "<qt>%1</qt>" ).arg( QString( tooltip.c_str() ).toHtmlEscaped() );
inputLabel->setToolTip( tooltipString );
inputField->setToolTip( tooltipString );

Check warning on line 163 in src/Gui/Widgets/ControlPanel.cpp

View check run for this annotation

Codecov / codecov/patch

src/Gui/Widgets/ControlPanel.cpp#L161-L163

Added lines #L161 - L163 were not covered by tests
}
connect( inputField, &MatrixEditor::valueChanged, std::move( callback ) );

Expand All @@ -166,7 +176,7 @@ void ControlPanel::addColorInput(
bool withAlpha,
const std::string& tooltip ) {

auto button = new QPushButton( name.c_str(), this );
auto button = new QPushButton( name.c_str() );

Check warning on line 179 in src/Gui/Widgets/ControlPanel.cpp

View check run for this annotation

Codecov / codecov/patch

src/Gui/Widgets/ControlPanel.cpp#L179

Added line #L179 was not covered by tests
auto srgbColor = Ra::Core::Utils::Color::linearRGBTosRGB( color );
auto clrBttn = QColor::fromRgbF( srgbColor[0], srgbColor[1], srgbColor[2], srgbColor[3] );
auto clrDlg = [callback, clrBttn, withAlpha, button, name]() mutable {
Expand Down Expand Up @@ -268,8 +278,8 @@ void ControlPanel::addComboBox( const std::string& name,
int initial,
const std::vector<std::string>& items,
const std::string& tooltip ) {
auto inputLabel = new QLabel( tr( name.c_str() ), this );
auto inputField = new QComboBox( this );
auto inputLabel = new QLabel( tr( name.c_str() ) );
auto inputField = new QComboBox();

Check warning on line 282 in src/Gui/Widgets/ControlPanel.cpp

View check run for this annotation

Codecov / codecov/patch

src/Gui/Widgets/ControlPanel.cpp#L281-L282

Added lines #L281 - L282 were not covered by tests
for ( auto v : items ) {
inputField->addItem( QString::fromStdString( v ) );
}
Expand All @@ -291,8 +301,8 @@ void ControlPanel::addComboBox( const std::string& name,
const std::string& initial,
const std::vector<std::string>& items,
const std::string& tooltip ) {
auto inputLabel = new QLabel( tr( name.c_str() ), this );
auto inputField = new QComboBox( this );
auto inputLabel = new QLabel( tr( name.c_str() ) );
auto inputField = new QComboBox();

Check warning on line 305 in src/Gui/Widgets/ControlPanel.cpp

View check run for this annotation

Codecov / codecov/patch

src/Gui/Widgets/ControlPanel.cpp#L304-L305

Added lines #L304 - L305 were not covered by tests
for ( auto v : items ) {
inputField->addItem( QString::fromStdString( v ) );
}
Expand All @@ -312,13 +322,15 @@ void ControlPanel::addComboBox( const std::string& name,

void ControlPanel::addStretch( int stretch ) {
m_mainLayout->addStretch( stretch );
m_contentLayout = new QGridLayout( this );
m_contentLayout = new QGridLayout();
m_contentLayout->setObjectName( "stretch layout" );
m_mainLayout->addLayout( m_contentLayout );

Check warning on line 327 in src/Gui/Widgets/ControlPanel.cpp

View check run for this annotation

Codecov / codecov/patch

src/Gui/Widgets/ControlPanel.cpp#L324-L327

Added lines #L324 - L327 were not covered by tests
}

void ControlPanel::addWidget( QWidget* newWidget ) {
m_mainLayout->addWidget( newWidget );
m_contentLayout = new QGridLayout( this );
m_contentLayout = new QGridLayout();
m_contentLayout->setObjectName( "Widget content layout" );
m_mainLayout->addLayout( m_contentLayout );

Check warning on line 334 in src/Gui/Widgets/ControlPanel.cpp

View check run for this annotation

Codecov / codecov/patch

src/Gui/Widgets/ControlPanel.cpp#L331-L334

Added lines #L331 - L334 were not covered by tests
}

Expand Down
39 changes: 25 additions & 14 deletions src/Gui/Widgets/ControlPanel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <Gui/Widgets/ConstrainedNumericSpinBox.hpp>
#include <Gui/Widgets/VectorEditor.hpp>

#include <QBoxLayout>
#include <QFrame>
#include <QVBoxLayout>

Expand Down Expand Up @@ -235,7 +236,8 @@ class RA_GUI_API ControlPanel : public QFrame
void addStretch( int stretch );

void newLayout() {
m_contentLayout = new QGridLayout( this );
m_contentLayout = new QGridLayout();
m_contentLayout->setObjectName( "new layout" );
m_mainLayout->addLayout( m_contentLayout );
}

Expand All @@ -252,9 +254,9 @@ void ControlPanel::addConstrainedNumberInput( const std::string& name,
std::function<bool( T )> predicate,
const std::string& tooltip,
int dec ) {
auto inputLabel = new QLabel( tr( name.c_str() ), this );
auto inputLabel = new QLabel( tr( name.c_str() ) );

Check warning on line 257 in src/Gui/Widgets/ControlPanel.hpp

View check run for this annotation

Codecov / codecov/patch

src/Gui/Widgets/ControlPanel.hpp#L257

Added line #L257 was not covered by tests

auto inputField = new ConstrainedNumericSpinBox<T>( this );
auto inputField = new ConstrainedNumericSpinBox<T>();

Check warning on line 259 in src/Gui/Widgets/ControlPanel.hpp

View check run for this annotation

Codecov / codecov/patch

src/Gui/Widgets/ControlPanel.hpp#L259

Added line #L259 was not covered by tests
inputField->setValue( initial );
inputField->setMinimum( std::numeric_limits<T>::lowest() );
inputField->setMaximum( std::numeric_limits<T>::max() );
Expand All @@ -267,8 +269,10 @@ void ControlPanel::addConstrainedNumberInput( const std::string& name,
if constexpr ( std::is_floating_point_v<T> ) { inputField->setDecimals( dec ); }

if ( !tooltip.empty() ) {
inputLabel->setToolTip(
QString( "<qt>%1</qt>" ).arg( QString( tooltip.c_str() ).toHtmlEscaped() ) );
auto tooltipString =
QString( "<qt>%1</qt>" ).arg( QString( tooltip.c_str() ).toHtmlEscaped() );
inputLabel->setToolTip( tooltipString );
inputField->setToolTip( tooltipString );

Check warning on line 275 in src/Gui/Widgets/ControlPanel.hpp

View check run for this annotation

Codecov / codecov/patch

src/Gui/Widgets/ControlPanel.hpp#L272-L275

Added lines #L272 - L275 were not covered by tests
}
auto index = m_contentLayout->rowCount();
m_contentLayout->addWidget( inputLabel, index, 0 );
Expand All @@ -284,10 +288,13 @@ void ControlPanel::addNumberInput( const std::string& name,
const std::string& tooltip,
int dec ) {

auto inputLabel = new QLabel( tr( name.c_str() ), this );
auto inputLabel = new QLabel( tr( name.c_str() ) );

Check warning on line 291 in src/Gui/Widgets/ControlPanel.hpp

View check run for this annotation

Codecov / codecov/patch

src/Gui/Widgets/ControlPanel.hpp#L291

Added line #L291 was not covered by tests

using WidgetType = typename QtSpinBox::getType<T>::Type;
auto inputField = new WidgetType( this );
auto inputField = new WidgetType();
auto inputLayout = new QHBoxLayout();
inputLayout->addStretch();
inputLayout->addWidget( inputField );

Check warning on line 297 in src/Gui/Widgets/ControlPanel.hpp

View check run for this annotation

Codecov / codecov/patch

src/Gui/Widgets/ControlPanel.hpp#L294-L297

Added lines #L294 - L297 were not covered by tests
// to prevent overflow
inputField->setRange(
min,
Expand All @@ -300,12 +307,14 @@ void ControlPanel::addNumberInput( const std::string& name,
if constexpr ( std::is_floating_point_v<T> ) { inputField->setDecimals( dec ); }

if ( !tooltip.empty() ) {
inputLabel->setToolTip(
QString( "<qt>%1</qt>" ).arg( QString( tooltip.c_str() ).toHtmlEscaped() ) );
auto tooltipString =
QString( "<qt>%1</qt>" ).arg( QString( tooltip.c_str() ).toHtmlEscaped() );
inputLabel->setToolTip( tooltipString );
inputField->setToolTip( tooltipString );

Check warning on line 313 in src/Gui/Widgets/ControlPanel.hpp

View check run for this annotation

Codecov / codecov/patch

src/Gui/Widgets/ControlPanel.hpp#L310-L313

Added lines #L310 - L313 were not covered by tests
}
auto index = m_contentLayout->rowCount();
m_contentLayout->addWidget( inputLabel, index, 0 );
m_contentLayout->addWidget( inputField, index, 1 );
m_contentLayout->addLayout( inputLayout, index, 1 );

Check warning on line 317 in src/Gui/Widgets/ControlPanel.hpp

View check run for this annotation

Codecov / codecov/patch

src/Gui/Widgets/ControlPanel.hpp#L315-L317

Added lines #L315 - L317 were not covered by tests
}

template <typename T>
Expand All @@ -314,12 +323,14 @@ void ControlPanel::addVectorInput( const std::string& name,
const std::vector<T>& initial,
const std::string& tooltip ) {

auto inputLabel = new QLabel( tr( name.c_str() ), this );
auto inputField = new VectorEditor<T>( initial, this );
auto inputLabel = new QLabel( tr( name.c_str() ) );
auto inputField = new VectorEditor<T>( initial );

Check warning on line 327 in src/Gui/Widgets/ControlPanel.hpp

View check run for this annotation

Codecov / codecov/patch

src/Gui/Widgets/ControlPanel.hpp#L326-L327

Added lines #L326 - L327 were not covered by tests

if ( !tooltip.empty() ) {
inputLabel->setToolTip(
QString( "<qt>%1</qt>" ).arg( QString( tooltip.c_str() ).toHtmlEscaped() ) );
auto tooltipString =
QString( "<qt>%1</qt>" ).arg( QString( tooltip.c_str() ).toHtmlEscaped() );
inputLabel->setToolTip( tooltipString );
inputField->setToolTip( tooltipString );

Check warning on line 333 in src/Gui/Widgets/ControlPanel.hpp

View check run for this annotation

Codecov / codecov/patch

src/Gui/Widgets/ControlPanel.hpp#L330-L333

Added lines #L330 - L333 were not covered by tests
}
connect( inputField,
QOverload<const std::vector<T>&>::of( &VectorEditorSignals::valueChanged ),
Expand Down

0 comments on commit 665430a

Please sign in to comment.