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::Window, 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, &QToolButton::clicked, this, &PanelDockWidget::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 
73 void PanelDockWidget::setWindowTitle(const QString& title)
74 {
75  QDockWidget::setWindowTitle(title);
76  title_label_->setText(title);
77 }
78 
79 
80 void PanelDockWidget::setIcon(const 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(), &QObject::destroyed, this, &PanelDockWidget::onChildDestroyed);
119  }
120  setWidget(child);
121  if (child)
122  {
123  connect(child, &QObject::destroyed, this, &PanelDockWidget::onChildDestroyed);
124  }
125 }
126 
128 {
129  QToolButton* button = new QToolButton();
130  button->setIcon(QIcon::fromTheme("view-fullscreen"));
131  button->setIconSize(QSize(10, 10));
132  button->setToolTip("Toggle maximize");
133  connect(button, &QToolButton::clicked, this, &PanelDockWidget::toggleMaximized);
134  dynamic_cast<QHBoxLayout*>(titleBarWidget()->layout())->insertWidget(2, button);
135 }
136 
138 {
139  if (windowState() & Qt::WindowMaximized)
140  {
141  setFloating(false);
142  showNormal();
143  }
144  else
145  {
146  setFloating(true);
147  showMaximized();
148  }
149 }
150 
151 void PanelDockWidget::closeEvent(QCloseEvent* /*event*/)
152 {
153  Q_EMIT closed();
154 }
155 
156 void PanelDockWidget::onChildDestroyed(QObject* /*unused*/)
157 {
158  deleteLater();
159 }
160 
162 {
163  config.mapSetValue("collapsed", collapsed_);
164 }
165 
166 void PanelDockWidget::load(const Config& config)
167 {
168  config.mapGetBool("collapsed", &collapsed_);
169 }
170 
171 void PanelDockWidget::setVisible(bool visible)
172 {
173  requested_visibility_ = visible;
174  QDockWidget::setVisible(requested_visibility_ && !forced_hidden_);
175 }
176 
178 {
179  forced_hidden_ = hidden;
181 }
182 
183 } // end namespace rviz
rviz::PanelDockWidget::collapsed_
bool collapsed_
Definition: panel_dock_widget.h:85
panel_dock_widget.h
rviz::PanelDockWidget::toggleMaximized
void toggleMaximized()
Definition: panel_dock_widget.cpp:137
rviz::PanelDockWidget::requested_visibility_
bool requested_visibility_
Definition: panel_dock_widget.h:86
rviz::PanelDockWidget::setCollapsed
void setCollapsed(bool collapsed)
Definition: panel_dock_widget.cpp:93
rviz
Definition: add_display_dialog.cpp:54
rviz::PanelDockWidget::save
virtual void save(Config config)
Definition: panel_dock_widget.cpp:161
rviz::PanelDockWidget::closeEvent
void closeEvent(QCloseEvent *event) override
Definition: panel_dock_widget.cpp:151
rviz::PanelDockWidget::closed
void closed()
rviz::PanelDockWidget::onChildDestroyed
void onChildDestroyed(QObject *)
Definition: panel_dock_widget.cpp:156
rviz::PanelDockWidget::forced_hidden_
bool forced_hidden_
Definition: panel_dock_widget.h:87
rviz::PanelDockWidget::addMaximizeButton
void addMaximizeButton()
Definition: panel_dock_widget.cpp:127
rviz::PanelDockWidget::icon_label_
QLabel * icon_label_
Definition: panel_dock_widget.h:88
rviz::PanelDockWidget::load
virtual void load(const Config &config)
Definition: panel_dock_widget.cpp:166
rviz::PanelDockWidget::title_label_
QLabel * title_label_
Definition: panel_dock_widget.h:89
rviz::PanelDockWidget::overrideVisibility
virtual void overrideVisibility(bool hide)
Definition: panel_dock_widget.cpp:177
rviz::PanelDockWidget::setVisible
void setVisible(bool visible) override
Override setVisible to respect the visibility override,.
Definition: panel_dock_widget.cpp:171
rviz::PanelDockWidget::setIcon
void setIcon(const QIcon &icon)
Definition: panel_dock_widget.cpp:80
rviz::PanelDockWidget::setWindowTitle
void setWindowTitle(const QString &title)
Definition: panel_dock_widget.cpp:73
config
config
rviz::PanelDockWidget::PanelDockWidget
PanelDockWidget(const QString &name)
Definition: panel_dock_widget.cpp:41
rviz::Config
Configuration data storage class.
Definition: config.h:124
rviz::PanelDockWidget::setContentWidget
void setContentWidget(QWidget *child)
Definition: panel_dock_widget.cpp:114


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust, William Woodall
autogenerated on Fri Aug 2 2024 08:43:10