21#include "moc_qgsuserinputwidget.cpp"
23using namespace Qt::StringLiterals;
30 QFrame *f =
new QFrame();
31 f->setObjectName( u
"mUserInputContainer"_s );
33 QPalette
pal = palette();
34 pal.setBrush( backgroundRole(),
pal.window() );
36 f->setAutoFillBackground(
true );
37 f->setFrameShape( QFrame::StyledPanel );
38 f->setFrameShadow( QFrame::Plain );
40 mLayout =
new QBoxLayout( QBoxLayout::TopToBottom );
41 mLayout->setAlignment( Qt::AlignRight | Qt::AlignTop );
42 f->setLayout( mLayout );
44 QBoxLayout *topLayout =
new QBoxLayout( QBoxLayout::TopToBottom );
45 topLayout->setContentsMargins( 0, 0, 0, 0 );
46 topLayout->addWidget( f );
47 setLayout( topLayout );
50 topLayout->setSizeConstraint( QLayout::SetFixedSize );
51 mLayout->setSizeConstraint( QLayout::SetFixedSize );
53 setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding );
59 QFrame *line =
nullptr;
60 if ( mWidgetList.count() > 0 )
62 line =
new QFrame(
this );
63 line->setFrameShadow( QFrame::Sunken );
64 line->setFrameShape( mLayoutHorizontal ? QFrame::VLine : QFrame::HLine );
65 mLayout->addWidget( line );
67 mLayout->addWidget( widget );
69 connect( widget, &QObject::destroyed,
this, &QgsUserInputWidget::widgetDestroyed );
71 mWidgetList.insert( widget, line );
78void QgsUserInputWidget::widgetDestroyed( QObject *obj )
80 if ( obj->isWidgetType() )
82 QWidget *w = qobject_cast<QWidget *>( obj );
83 const auto it = mWidgetList.find( w );
84 if ( it != mWidgetList.end() )
86 if ( QFrame *frame = it.value() )
90 mWidgetList.erase( it );
93 if ( mWidgetList.count() == 0 )
99void QgsUserInputWidget::setLayoutDirection( QBoxLayout::Direction direction )
101 mLayout->setDirection( direction );
103 const bool horizontal = direction == QBoxLayout::LeftToRight || direction == QBoxLayout::RightToLeft;
104 QMap<QWidget *, QFrame *>::const_iterator i = mWidgetList.constBegin();
105 while ( i != mWidgetList.constEnd() )
107 if (
auto *lValue = i.value() )
109 lValue->setFrameShape( horizontal ? QFrame::VLine : QFrame::HLine );
119 if ( mWidgetList.count() == 0 )