user input fixes

* fix crash when entering value from widget in rotation map tool use
* initially display as floating
* use same background color as info bar
* fix auto adjust
This commit is contained in:
Denis Rouzaud 2015-05-06 09:56:31 +02:00
parent b49b49232a
commit a7a29ca9bd
3 changed files with 47 additions and 29 deletions

View File

@ -582,7 +582,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
// User Input Dock Widget
mUserInputDockWidget = new QgsUserInputDockWidget( this );
mUserInputDockWidget->setObjectName( "UserInputToolBar" );
mUserInputDockWidget->setObjectName( "UserInputDockWidget" );
//set the focus to the map canvas
mMapCanvas->setFocus();
@ -642,7 +642,8 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
addDockWidget( Qt::LeftDockWidgetArea, mAdvancedDigitizingDockWidget );
mAdvancedDigitizingDockWidget->hide();
addDockWidget( Qt::BottomDockWidgetArea, mUserInputDockWidget );
QMainWindow::addDockWidget( Qt::BottomDockWidgetArea, mUserInputDockWidget );
mUserInputDockWidget->setFloating( true );
// create the GPS tool on starting QGIS - this is like the browser
mpGpsWidget = new QgsGPSInformationWidget( mMapCanvas );

View File

@ -20,7 +20,7 @@
QgsUserInputDockWidget::QgsUserInputDockWidget( QWidget *parent )
: QDockWidget( tr( "User input" ), parent )
, mDockArea( Qt::BottomDockWidgetArea )
, mLayoutHorizontal( true )
{
QWidget* w = new QWidget( this );
mLayout = new QBoxLayout( QBoxLayout::LeftToRight, this );
@ -28,8 +28,13 @@ QgsUserInputDockWidget::QgsUserInputDockWidget( QWidget *parent )
w->setLayout( mLayout );
setWidget( w );
connect( this, SIGNAL( dockLocationChanged( Qt::DockWidgetArea ) ), this, SLOT( areaChanged( Qt::DockWidgetArea ) ) );
QPalette pal = palette();
pal.setColor( QPalette::Background, QColor( 231, 245, 254 ) );
setPalette( pal );
setAutoFillBackground( true );
connect( this, SIGNAL( dockLocationChanged( Qt::DockWidgetArea ) ), this, SLOT( areaChanged( Qt::DockWidgetArea ) ) );
connect( this, SIGNAL( topLevelChanged( bool ) ), this, SLOT( floatingChanged( bool ) ) );
hide();
}
@ -44,7 +49,7 @@ void QgsUserInputDockWidget::addUserInputWidget( QWidget *widget )
{
line = new QFrame( this );
line->setFrameShadow( QFrame::Sunken );
line->setFrameShape( isLayoutHorizontal() ? QFrame::VLine : QFrame::HLine );
line->setFrameShape( mLayoutHorizontal ? QFrame::VLine : QFrame::HLine );
mLayout->addWidget( line );
}
mLayout->addWidget( widget );
@ -53,8 +58,8 @@ void QgsUserInputDockWidget::addUserInputWidget( QWidget *widget )
mWidgetList.insert( widget, line );
adjustSize();
show();
adjustSize();
}
void QgsUserInputDockWidget::widgetDestroyed( QObject *obj )
@ -73,24 +78,42 @@ void QgsUserInputDockWidget::widgetDestroyed( QObject *obj )
++i;
}
}
if ( mWidgetList.count() == 0 )
{
hide();
}
}
void QgsUserInputDockWidget::areaChanged( Qt::DockWidgetArea area )
{
mDockArea = area;
bool newLayoutHorizontal = area & Qt::BottomDockWidgetArea || area & Qt::TopDockWidgetArea;
if ( mLayoutHorizontal == newLayoutHorizontal )
{
// no change
adjustSize();
return;
}
mLayoutHorizontal = newLayoutHorizontal;
updateLayoutDirection();
}
mLayout->setDirection( isLayoutHorizontal() ? QBoxLayout::LeftToRight : QBoxLayout::TopToBottom );
void QgsUserInputDockWidget::floatingChanged( bool floating )
{
if ( mLayoutHorizontal == floating )
{
adjustSize();
return;
}
mLayoutHorizontal = floating;
updateLayoutDirection();
}
void QgsUserInputDockWidget::updateLayoutDirection()
{
mLayout->setDirection( mLayoutHorizontal ? QBoxLayout::LeftToRight : QBoxLayout::TopToBottom );
QMap<QWidget*, QFrame*>::iterator i = mWidgetList.begin();
while ( i != mWidgetList.end() )
{
if ( i.value() )
{
i.value()->setFrameShape( isLayoutHorizontal() ? QFrame::VLine : QFrame::HLine );
i.value()->setFrameShape( mLayoutHorizontal ? QFrame::VLine : QFrame::HLine );
}
++i;
}
@ -98,23 +121,14 @@ void QgsUserInputDockWidget::areaChanged( Qt::DockWidgetArea area )
adjustSize();
}
bool QgsUserInputDockWidget::isLayoutHorizontal()
{
if ( mDockArea & Qt::BottomDockWidgetArea || mDockArea & Qt::TopDockWidgetArea || mDockArea & Qt::NoDockWidgetArea )
{
return true;
}
else
{
return false;
}
}
void QgsUserInputDockWidget::paintEvent( QPaintEvent * event )
{
QDockWidget::paintEvent( event );
if ( mWidgetList.count() == 0 )
{
hide();
}
else
{
QDockWidget::paintEvent( event );
}
}

View File

@ -31,6 +31,7 @@ class GUI_EXPORT QgsUserInputDockWidget : public QDockWidget
QgsUserInputDockWidget( QWidget* parent = 0 );
~QgsUserInputDockWidget();
//! add a widget to be displayed in the dock
void addUserInputWidget( QWidget* widget );
protected:
@ -39,17 +40,19 @@ class GUI_EXPORT QgsUserInputDockWidget : public QDockWidget
private slots:
void widgetDestroyed( QObject* obj );
//! when area change, update the layout according to the new dock location
void areaChanged( Qt::DockWidgetArea area );
void floatingChanged( bool floating );
private:
bool isLayoutHorizontal();
void createLayout();
void updateLayoutDirection();
// list of widget with their corresponding line separator
QMap<QWidget*, QFrame*> mWidgetList;
Qt::DockWidgetArea mDockArea;
bool mLayoutHorizontal;
QBoxLayout* mLayout;
};