panel_dock_widget.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <QChildEvent>
31 #include <QHBoxLayout>
32 #include <QLabel>
33 #include <QToolButton>
34 #include <QCloseEvent>
35 
36 #include "rviz/panel_dock_widget.h"
37 
38 namespace rviz
39 {
40 
41 PanelDockWidget::PanelDockWidget( const QString& name )
42  : QDockWidget( name )
43  , collapsed_(false)
44  , forced_hidden_(false)
45 {
46  QWidget *title_bar = new QWidget(this);
47 
48  QPalette pal(palette());
49  pal.setColor(QPalette::Background, QColor( 200,200,200 ) );
50  title_bar->setAutoFillBackground(true);
51  title_bar->setPalette(pal);
52  title_bar->setContentsMargins(0,0,0,0);
53 
54  QToolButton *close_button = new QToolButton();
55  close_button->setIcon(QIcon::fromTheme("window-close"));
56  close_button->setIconSize( QSize(10,10) );
57 
58  connect( close_button, SIGNAL( clicked() ), this, SLOT(close()) );
59 
60  title_label_ = new QLabel( name, this );
61 
62  icon_label_ = new QLabel( this );
63  icon_label_->setContentsMargins(2,2,0,0);
64  setIcon( QIcon() );
65 
66  QHBoxLayout *title_layout = new QHBoxLayout();
67  title_layout->setContentsMargins(2,2,2,2);
68  title_layout->addWidget( icon_label_, 0 );
69  title_layout->addWidget( title_label_, 1 );
70  title_layout->addWidget( close_button, 0 );
71  title_bar->setLayout(title_layout);
72  setTitleBarWidget( title_bar );
73 }
74 
75 void PanelDockWidget::setWindowTitle( QString title )
76 {
77  QDockWidget::setWindowTitle( title );
78  title_label_->setText( title );
79 }
80 
81 
82 void PanelDockWidget::setIcon( QIcon icon )
83 {
84  if ( icon.isNull() )
85  {
86  icon_label_->setVisible( false );
87  }
88  else
89  {
90  icon_label_->setVisible( true );
91  icon_label_->setPixmap( icon.pixmap(16,16) );
92  }
93 }
94 
95 void PanelDockWidget::setCollapsed( bool collapse )
96 {
97  if ( collapsed_ == collapse || isFloating() ) return;
98 
99 
100  if ( collapse )
101  {
102  if ( isVisible() )
103  {
105  collapsed_ = collapse;
106  }
107  }
108  else
109  {
111  collapsed_ = collapse;
112  }
113 }
114 
115 void PanelDockWidget::setContentWidget( QWidget* child )
116 {
117  if( widget() )
118  {
119  disconnect( widget(), SIGNAL( destroyed( QObject* )), this, SLOT( onChildDestroyed( QObject* )));
120  }
121  setWidget( child );
122  if( child )
123  {
124  connect( child, SIGNAL( destroyed( QObject* )), this, SLOT( onChildDestroyed( QObject* )));
125  }
126 }
127 
128 void PanelDockWidget::closeEvent ( QCloseEvent * event )
129 {
130  Q_EMIT closed();
131 }
132 
134 {
135  deleteLater();
136 }
137 
139 {
140  config.mapSetValue( "collapsed", collapsed_ );
141 }
142 
144 {
145  config.mapGetBool( "collapsed", &collapsed_ );
146 }
147 
148 void PanelDockWidget::setVisible( bool visible )
149 {
150  requested_visibility_ = visible;
151  QDockWidget::setVisible(requested_visibility_ && !forced_hidden_);
152 }
153 
155 {
156  forced_hidden_ = hidden;
158 }
159 
160 } // end namespace rviz
void setContentWidget(QWidget *child)
void setIcon(QIcon icon)
virtual void load(Config config)
PanelDockWidget(const QString &name)
void setCollapsed(bool collapsed)
void setWindowTitle(QString title)
void mapSetValue(const QString &key, QVariant value)
Set a named child to the given value.
Definition: config.cpp:185
Configuration data storage class.
Definition: config.h:125
bool mapGetBool(const QString &key, bool *value_out) const
Convenience function for looking up a named boolean.
Definition: config.cpp:270
virtual void closeEvent(QCloseEvent *event)
virtual void save(Config config)
void onChildDestroyed(QObject *)
virtual void setVisible(bool visible)
Override setVisible to respect the visibility override,.
virtual void overrideVisibility(bool hide)


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Sat Apr 27 2019 02:33:41