2020
2121QgsUserInputDockWidget::QgsUserInputDockWidget ( QWidget *parent )
2222 : QDockWidget( tr( " User input" ), parent )
23- , mDockArea( Qt::BottomDockWidgetArea )
23+ , mLayoutHorizontal( true )
2424{
2525 QWidget* w = new QWidget ( this );
2626 mLayout = new QBoxLayout ( QBoxLayout::LeftToRight, this );
2727 mLayout ->setAlignment ( Qt::AlignLeft | Qt::AlignTop );
2828 w->setLayout ( mLayout );
2929 setWidget ( w );
3030
31- connect ( this , SIGNAL ( dockLocationChanged ( Qt::DockWidgetArea ) ), this , SLOT ( areaChanged ( Qt::DockWidgetArea ) ) );
31+ QPalette pal = palette ();
32+ pal.setColor ( QPalette::Background, QColor ( 231 , 245 , 254 ) );
33+ setPalette ( pal );
34+ setAutoFillBackground ( true );
3235
36+ connect ( this , SIGNAL ( dockLocationChanged ( Qt::DockWidgetArea ) ), this , SLOT ( areaChanged ( Qt::DockWidgetArea ) ) );
37+ connect ( this , SIGNAL ( topLevelChanged ( bool ) ), this , SLOT ( floatingChanged ( bool ) ) );
3338 hide ();
3439}
3540
@@ -44,7 +49,7 @@ void QgsUserInputDockWidget::addUserInputWidget( QWidget *widget )
4449 {
4550 line = new QFrame ( this );
4651 line->setFrameShadow ( QFrame::Sunken );
47- line->setFrameShape ( isLayoutHorizontal () ? QFrame::VLine : QFrame::HLine );
52+ line->setFrameShape ( mLayoutHorizontal ? QFrame::VLine : QFrame::HLine );
4853 mLayout ->addWidget ( line );
4954 }
5055 mLayout ->addWidget ( widget );
@@ -53,8 +58,8 @@ void QgsUserInputDockWidget::addUserInputWidget( QWidget *widget )
5358
5459 mWidgetList .insert ( widget, line );
5560
56- adjustSize ();
5761 show ();
62+ adjustSize ();
5863}
5964
6065void QgsUserInputDockWidget::widgetDestroyed ( QObject *obj )
@@ -73,48 +78,57 @@ void QgsUserInputDockWidget::widgetDestroyed( QObject *obj )
7378 ++i;
7479 }
7580 }
76- if ( mWidgetList .count () == 0 )
81+ }
82+
83+ void QgsUserInputDockWidget::areaChanged ( Qt::DockWidgetArea area )
84+ {
85+ bool newLayoutHorizontal = area & Qt::BottomDockWidgetArea || area & Qt::TopDockWidgetArea;
86+ if ( mLayoutHorizontal == newLayoutHorizontal )
7787 {
78- hide ();
88+ // no change
89+ adjustSize ();
90+ return ;
7991 }
92+ mLayoutHorizontal = newLayoutHorizontal;
93+ updateLayoutDirection ();
8094}
8195
82- void QgsUserInputDockWidget::areaChanged ( Qt::DockWidgetArea area )
96+ void QgsUserInputDockWidget::floatingChanged ( bool floating )
8397{
84- mDockArea = area;
98+ if ( mLayoutHorizontal == floating )
99+ {
100+ adjustSize ();
101+ return ;
102+ }
103+ mLayoutHorizontal = floating;
104+ updateLayoutDirection ();
105+ }
85106
86- mLayout ->setDirection ( isLayoutHorizontal () ? QBoxLayout::LeftToRight : QBoxLayout::TopToBottom );
107+ void QgsUserInputDockWidget::updateLayoutDirection ()
108+ {
109+ mLayout ->setDirection ( mLayoutHorizontal ? QBoxLayout::LeftToRight : QBoxLayout::TopToBottom );
87110
88111 QMap<QWidget*, QFrame*>::iterator i = mWidgetList .begin ();
89112 while ( i != mWidgetList .end () )
90113 {
91114 if ( i.value () )
92115 {
93- i.value ()->setFrameShape ( isLayoutHorizontal () ? QFrame::VLine : QFrame::HLine );
116+ i.value ()->setFrameShape ( mLayoutHorizontal ? QFrame::VLine : QFrame::HLine );
94117 }
95118 ++i;
96119 }
97120
98121 adjustSize ();
99122}
100123
101- bool QgsUserInputDockWidget::isLayoutHorizontal ()
102- {
103- if ( mDockArea & Qt::BottomDockWidgetArea || mDockArea & Qt::TopDockWidgetArea || mDockArea & Qt::NoDockWidgetArea )
104- {
105- return true ;
106- }
107- else
108- {
109- return false ;
110- }
111- }
112-
113124void QgsUserInputDockWidget::paintEvent ( QPaintEvent * event )
114125{
115- QDockWidget::paintEvent ( event );
116126 if ( mWidgetList .count () == 0 )
117127 {
118128 hide ();
119129 }
130+ else
131+ {
132+ QDockWidget::paintEvent ( event );
133+ }
120134}
0 commit comments