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 <QApplication>
31 #include <QChildEvent>
32 #include <QHBoxLayout>
33 #include <QLabel>
34 #include <QToolButton>
35 #include <QCloseEvent>
36 
37 #include "rviz/panel_dock_widget.h"
38 
39 namespace rviz
40 {
42  : QDockWidget(name), collapsed_(false), forced_hidden_(false)
43 {
44  QWidget* title_bar = new QWidget(this);
45 
46  QPalette pal(palette());
47  pal.setColor(QPalette::Background, QApplication::palette().color(QPalette::Mid));
48  title_bar->setAutoFillBackground(true);
49  title_bar->setPalette(pal);
50  title_bar->setContentsMargins(0, 0, 0, 0);
51 
52  QToolButton* close_button = new QToolButton();
53  close_button->setIcon(QIcon::fromTheme("window-close"));
54  close_button->setIconSize(QSize(10, 10));
55 
56  connect(close_button, SIGNAL(clicked()), this, SLOT(close()));
57 
58  title_label_ = new QLabel(name, this);
59 
60  icon_label_ = new QLabel(this);
61  icon_label_->setContentsMargins(2, 2, 0, 0);
62  setIcon(QIcon());
63 
64  QHBoxLayout* title_layout = new QHBoxLayout();
65  title_layout->setContentsMargins(2, 2, 2, 2);
66  title_layout->addWidget(icon_label_, 0);
67  title_layout->addWidget(title_label_, 1);
68  title_layout->addWidget(close_button, 0);
69  title_bar->setLayout(title_layout);
70  setTitleBarWidget(title_bar);
71 }
72 
74 {
75  QDockWidget::setWindowTitle(title);
76  title_label_->setText(title);
77 }
78 
79 
80 void PanelDockWidget::setIcon(QIcon icon)
81 {
82  if (icon.isNull())
83  {
84  icon_label_->setVisible(false);
85  }
86  else
87  {
88  icon_label_->setVisible(true);
89  icon_label_->setPixmap(icon.pixmap(16, 16));
90  }
91 }
92 
93 void PanelDockWidget::setCollapsed(bool collapse)
94 {
95  if (collapsed_ == collapse || isFloating())
96  return;
97 
98 
99  if (collapse)
100  {
101  if (isVisible())
102  {
104  collapsed_ = collapse;
105  }
106  }
107  else
108  {
110  collapsed_ = collapse;
111  }
112 }
113 
115 {
116  if (widget())
117  {
118  disconnect(widget(), SIGNAL(destroyed(QObject*)), this, SLOT(onChildDestroyed(QObject*)));
119  }
120  setWidget(child);
121  if (child)
122  {
123  connect(child, SIGNAL(destroyed(QObject*)), this, SLOT(onChildDestroyed(QObject*)));
124  }
125 }
126 
127 void PanelDockWidget::closeEvent(QCloseEvent* /*event*/)
128 {
129  Q_EMIT closed();
130 }
131 
132 void PanelDockWidget::onChildDestroyed(QObject* /*unused*/)
133 {
134  deleteLater();
135 }
136 
138 {
139  config.mapSetValue("collapsed", collapsed_);
140 }
141 
143 {
144  config.mapGetBool("collapsed", &collapsed_);
145 }
146 
147 void PanelDockWidget::setVisible(bool visible)
148 {
149  requested_visibility_ = visible;
151 }
152 
154 {
155  forced_hidden_ = hidden;
157 }
158 
159 } // end namespace rviz
void setContentWidget(QWidget *child)
void setIcon(QIcon icon)
void onChildDestroyed(QObject *unused)
void setVisible(bool visible) override
Override setVisible to respect the visibility override,.
virtual void load(Config config)
PanelDockWidget(const QString &name)
void setCollapsed(bool collapsed)
void setWindowTitle(QString title)
void setVisible(PanelDockWidget *widget, bool visible)
Definition: display.cpp:293
void mapSetValue(const QString &key, QVariant value)
Set a named child to the given value.
Definition: config.cpp:196
Configuration data storage class.
Definition: config.h:124
void closeEvent(QCloseEvent *event) override
virtual void save(Config config)
bool mapGetBool(const QString &key, bool *value_out) const
Convenience function for looking up a named boolean.
Definition: config.cpp:282
bool isVisible(PanelDockWidget *widget)
Definition: display.cpp:297
virtual void overrideVisibility(bool hide)


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Sat May 27 2023 02:06:24