QGIS API Documentation  3.2.0-Bonn (bc43194)
qgsdockwidget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsdockwidget.cpp
3  -----------------
4  begin : June 2016
5  copyright : (C) 2016 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 
19 #include "qgsdockwidget.h"
20 
21 
22 QgsDockWidget::QgsDockWidget( QWidget *parent, Qt::WindowFlags flags )
23  : QDockWidget( parent, flags )
24 {
25  connect( this, &QDockWidget::visibilityChanged, this, &QgsDockWidget::handleVisibilityChanged );
26 }
27 
28 QgsDockWidget::QgsDockWidget( const QString &title, QWidget *parent, Qt::WindowFlags flags )
29  : QDockWidget( title, parent, flags )
30 {
31  connect( this, &QDockWidget::visibilityChanged, this, &QgsDockWidget::handleVisibilityChanged );
32 }
33 
34 void QgsDockWidget::setUserVisible( bool visible )
35 {
36  if ( visible )
37  {
38  show();
39  raise();
40  }
41  else
42  {
43  if ( !mVisibleAndActive )
44  return;
45 
46  hide();
47  }
48 }
49 
51 {
53 }
54 
56 {
57  return mVisibleAndActive;
58 }
59 
60 void QgsDockWidget::closeEvent( QCloseEvent *e )
61 {
62  emit closed();
63  emit closedStateChanged( true );
64  emit openedStateChanged( false );
65  QDockWidget::closeEvent( e );
66 }
67 
68 void QgsDockWidget::showEvent( QShowEvent *e )
69 {
70  emit opened();
71  emit closedStateChanged( false );
72  emit openedStateChanged( true );
73  QDockWidget::showEvent( e );
74 }
75 
76 void QgsDockWidget::handleVisibilityChanged( bool visible )
77 {
78  mVisibleAndActive = visible;
79 }
80 
void closedStateChanged(bool wasClosed)
Emitted when dock widget is closed (or opened).
void closeEvent(QCloseEvent *) override
void toggleUserVisible()
Toggles whether the dock is user visible.
void setUserVisible(bool visible)
Sets the dock widget as visible to a user, ie both shown and raised to the front. ...
bool isUserVisible() const
Returns true if the dock is both opened and raised to the front (ie not hidden by any other tabs...
void showEvent(QShowEvent *event) override
void openedStateChanged(bool wasOpened)
Emitted when dock widget is opened (or closed).
void closed()
Emitted when dock widget is closed.
QgsDockWidget(QWidget *parent=nullptr, Qt::WindowFlags flags=nullptr)
Constructor for QgsDockWidget.
void opened()
Emitted when dock widget is opened.