Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
3nids committed May 6, 2015
1 parent b49b492 commit a7a29ca
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 28 deletions.
5 changes: 3 additions & 2 deletions src/app/qgisapp.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -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 );
Expand Down
60 changes: 37 additions & 23 deletions src/gui/qgsuserinputdockwidget.cpp
Expand Up @@ -20,16 +20,21 @@

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 );
mLayout->setAlignment( Qt::AlignLeft | Qt::AlignTop );
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();
}

Expand All @@ -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 );
Expand All @@ -53,8 +58,8 @@ void QgsUserInputDockWidget::addUserInputWidget( QWidget *widget )

mWidgetList.insert( widget, line );

adjustSize();
show();
adjustSize();
}

void QgsUserInputDockWidget::widgetDestroyed( QObject *obj )
Expand All @@ -73,48 +78,57 @@ void QgsUserInputDockWidget::widgetDestroyed( QObject *obj )
++i;
}
}
if ( mWidgetList.count() == 0 )
}

void QgsUserInputDockWidget::areaChanged( Qt::DockWidgetArea area )
{
bool newLayoutHorizontal = area & Qt::BottomDockWidgetArea || area & Qt::TopDockWidgetArea;
if ( mLayoutHorizontal == newLayoutHorizontal )
{
hide();
// no change
adjustSize();
return;
}
mLayoutHorizontal = newLayoutHorizontal;
updateLayoutDirection();
}

void QgsUserInputDockWidget::areaChanged( Qt::DockWidgetArea area )
void QgsUserInputDockWidget::floatingChanged( bool floating )
{
mDockArea = area;
if ( mLayoutHorizontal == floating )
{
adjustSize();
return;
}
mLayoutHorizontal = floating;
updateLayoutDirection();
}

mLayout->setDirection( isLayoutHorizontal() ? QBoxLayout::LeftToRight : QBoxLayout::TopToBottom );
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;
}

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 );
}
}
9 changes: 6 additions & 3 deletions src/gui/qgsuserinputdockwidget.h
Expand Up @@ -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:
Expand All @@ -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;
};

Expand Down

0 comments on commit a7a29ca

Please sign in to comment.