Skip to content

Commit

Permalink
WIP - implementing question mark based tooltip helper
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinGuillaume committed May 29, 2024
1 parent 5fd66b9 commit 9d904d3
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 1 deletion.
Binary file modified lib/tool/tools/mdprep/include/tools/mdprep/ui/advanced_form.hpp
Binary file not shown.
Binary file modified lib/tool/tools/mdprep/include/tools/mdprep/ui/basic_form.hpp
Binary file not shown.
Binary file modified lib/tool/tools/mdprep/include/tools/mdprep/ui/form_data.hpp
Binary file not shown.
Binary file modified lib/tool/tools/mdprep/src/ui/advanced_form.cpp
Binary file not shown.
Binary file modified lib/tool/tools/mdprep/src/ui/basic_form.cpp
Binary file not shown.
16 changes: 15 additions & 1 deletion lib/ui/include/ui/qt/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,21 @@ namespace VTX::UI::QT::Util
return QBitmap( QPixmap::fromImage( QImage( p_filepath ).createAlphaMask() ) );
}
QLabel * createLabelWithHelpTooltip( const char * p_label, const char * p_helpTooltip ) noexcept;
void addLabeledHLineSeparator( QBoxLayout * p_dest, const char * p_label ) noexcept;
class LabelWithHelper
{
public:
enum class E_QUESTIONMARK_POSITION
{
left,
right
};
LabelWithHelper( const char * p_label, const char * p_helper, const E_QUESTIONMARK_POSITION & p_postion );
QWidget * container = nullptr;
QLabel * label = nullptr;

private:
};
void addLabeledHLineSeparator( QBoxLayout * p_dest, const char * p_label ) noexcept;

// The idea is to create a lineEdit field with a validator that enforce the UInt64 size input
QLineEdit * addUInt64Field( QFormLayout * p_dest, const char * p_label, const char * p_tooltip ) noexcept;
Expand Down
93 changes: 93 additions & 0 deletions lib/ui/src/ui/qt/util.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "ui/qt/util.hpp"
#include "ui/qt/validator.hpp"
#include <QAction>
#include <qevent.h>
#include <qpushbutton.h>
#include <qtoolbutton.h>

namespace VTX::UI::QT::Util
{
Expand Down Expand Up @@ -35,6 +38,96 @@ namespace VTX::UI::QT::Util
p_menu.addAction( action );
}
}
class QHoverableQuestionMark : public QPushButton
{
int m_count = 0;
QWidget * popup = nullptr;

public:
QHoverableQuestionMark( const char * p_popupText ) : QPushButton()
{
setIcon( QIcon( ":/sprite/citations_icon_hovered.png" ) );
setAttribute( Qt::WA_Hover );

auto label = new QLabel( p_popupText );
label->setTextFormat( Qt::RichText );

popup = new QWidget;
popup->setWindowFlag( Qt::ToolTip );
auto layout = new QHBoxLayout( popup );
layout->addWidget( label );
}
void enterEvent( QEnterEvent * event ) { QWidget::enterEvent( event ); }

void leaveEvent( QEvent * event ) { QWidget::leaveEvent( event ); }
void hoverEnter( QHoverEvent * p_event )
{
auto p = p_event->globalPosition().toPoint();
if ( p.isNull() || ( p.x() == -1 && p.y() == -1 ) )
return;
popup->move( p_event->globalPosition().toPoint() );
setText( QString::asprintf( "{%d, %d}", p.x(), p.y() ) );
popup->show();
}

void hoverLeave( QHoverEvent * event )
{
popup->hide();
setText( "leaved" );
}

void hoverMove( QHoverEvent * p_event )
{
auto p = p_event->globalPosition().toPoint();
if ( p.isNull() || ( p.x() == -1 && p.y() == -1 ) )
return;
popup->move( p_event->globalPosition().toPoint() );
setText( QString::asprintf( "{%d, %d}", p.x(), p.y() ) );
}
bool event( QEvent * e )
{
switch ( e->type() )
{
case QEvent::HoverEnter:
hoverEnter( reinterpret_cast<QHoverEvent *>( e ) );
return true;
break;
case QEvent::HoverLeave:
hoverLeave( reinterpret_cast<QHoverEvent *>( e ) );
return true;
break;
case QEvent::HoverMove:
hoverMove( reinterpret_cast<QHoverEvent *>( e ) );
return true;
break;
default: break;
}
return QWidget::event( e );
}
};
LabelWithHelper::LabelWithHelper(
const char * p_label,
const char * p_helper,
const E_QUESTIONMARK_POSITION & p_postion
) :
container( new QWidget ),
label( new QLabel( p_label ) )
{
QHBoxLayout * layout = new QHBoxLayout( container );
QHoverableQuestionMark * questionMark = new QHoverableQuestionMark( p_helper );
layout->setContentsMargins( { 0, 0, 0, 0 } );

if ( p_postion == E_QUESTIONMARK_POSITION::left )
{
layout->addWidget( questionMark );
layout->addWidget( label );
}
else
{
layout->addWidget( label );
layout->addWidget( questionMark );
}
}

QLabel * createLabelWithHelpTooltip( const char * p_label, const char * p_helpTooltip ) noexcept
{
Expand Down

0 comments on commit 9d904d3

Please sign in to comment.