QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgsuserinputwidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsuserinputwidget.h
3 --------------------------------------
4 Date : 04.2015
5 Copyright : (C) 2015 Denis Rouzaud
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#include "qgsuserinputwidget.h"
17
18#include <QFrame>
19
20#include "moc_qgsuserinputwidget.cpp"
21
23 : QgsFloatingWidget( parent ? parent->window() : nullptr )
24{
25 //TODO add title tr( "User Input Panel" )
26
27 QFrame *f = new QFrame();
28 f->setObjectName( QStringLiteral( "mUserInputContainer" ) );
29
30 QPalette pal = palette();
31 pal.setBrush( backgroundRole(), pal.window() );
32 f->setPalette( pal );
33 f->setAutoFillBackground( true );
34 f->setFrameShape( QFrame::StyledPanel );
35 f->setFrameShadow( QFrame::Plain );
36
37 mLayout = new QBoxLayout( QBoxLayout::TopToBottom );
38 mLayout->setAlignment( Qt::AlignRight | Qt::AlignTop );
39 f->setLayout( mLayout );
40
41 QBoxLayout *topLayout = new QBoxLayout( QBoxLayout::TopToBottom );
42 topLayout->setContentsMargins( 0, 0, 0, 0 );
43 topLayout->addWidget( f );
44 setLayout( topLayout );
45
46 // this allows the widget to be resized on demand
47 topLayout->setSizeConstraint( QLayout::SetFixedSize );
48 mLayout->setSizeConstraint( QLayout::SetFixedSize );
49
50 setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding );
51 hide();
52}
53
55{
56 QFrame *line = nullptr;
57 if ( mWidgetList.count() > 0 )
58 {
59 line = new QFrame( this );
60 line->setFrameShadow( QFrame::Sunken );
61 line->setFrameShape( mLayoutHorizontal ? QFrame::VLine : QFrame::HLine );
62 mLayout->addWidget( line );
63 }
64 mLayout->addWidget( widget );
65
66 connect( widget, &QObject::destroyed, this, &QgsUserInputWidget::widgetDestroyed );
67
68 mWidgetList.insert( widget, line );
69
70 show();
71 raise();
72 adjustSize();
73}
74
75void QgsUserInputWidget::widgetDestroyed( QObject *obj )
76{
77 if ( obj->isWidgetType() )
78 {
79 QWidget *w = qobject_cast<QWidget *>( obj );
80 const auto it = mWidgetList.find( w );
81 if ( it != mWidgetList.end() )
82 {
83 if ( QFrame *frame = it.value() )
84 {
85 frame->deleteLater();
86 }
87 mWidgetList.erase( it );
88 }
89 }
90 if ( mWidgetList.count() == 0 )
91 {
92 hide();
93 }
94}
95
96void QgsUserInputWidget::setLayoutDirection( QBoxLayout::Direction direction )
97{
98 mLayout->setDirection( direction );
99
100 const bool horizontal = direction == QBoxLayout::LeftToRight || direction == QBoxLayout::RightToLeft;
101 QMap<QWidget *, QFrame *>::const_iterator i = mWidgetList.constBegin();
102 while ( i != mWidgetList.constEnd() )
103 {
104 if ( auto *lValue = i.value() )
105 {
106 lValue->setFrameShape( horizontal ? QFrame::VLine : QFrame::HLine );
107 }
108 ++i;
109 }
110
111 adjustSize();
112}
113
114void QgsUserInputWidget::paintEvent( QPaintEvent *event )
115{
116 if ( mWidgetList.count() == 0 )
117 {
118 hide();
119 }
120 else
121 {
123 }
124}
QgsFloatingWidget(QWidget *parent=nullptr)
Constructor for QgsFloatingWidget.
void paintEvent(QPaintEvent *e) override
void paintEvent(QPaintEvent *event) override
QgsUserInputWidget(QWidget *parent=nullptr)
Constructor for QgsUserInputWidget.
void addUserInputWidget(QWidget *widget)
Add a widget to be displayed in the dock.