plot_docker_toolbar.cpp
Go to the documentation of this file.
1 /*
2  * This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at https://mozilla.org/MPL/2.0/.
5  */
6 
7 #include "plot_docker_toolbar.h"
8 #include "PlotJuggler/svg_util.h"
9 
11  : QWidget(parent)
12  , _parent(parent)
13  , ui(new Ui::DraggableToolbar)
14  , _fullscreen_mode(false)
15 {
16  ui->setupUi(this);
17 
18  QSettings settings;
19  QString theme = settings.value("StyleSheet::theme", "light").toString();
20  on_stylesheetChanged(theme);
21 
22  ui->buttonFullscreen->setVisible(false);
23  ui->buttonSplitHorizontal->setVisible(false);
24  ui->buttonSplitVertical->setVisible(false);
25  ui->buttonBackground->setVisible(false);
26 
27  setMouseTracking(true);
28  ui->widgetButtons->setMouseTracking(true);
29 
30  ui->label->installEventFilter(this);
31 
32  setAcceptDrops(true);
33 }
34 
36 {
37  delete ui;
38 }
39 
40 static void setButtonIcon(QPushButton* button, QIcon icon)
41 {
42  button->setIcon(icon);
43  button->setText("");
44 }
45 
47 {
49 
51 
52  ui->buttonClose->setHidden(_fullscreen_mode);
53  if (_fullscreen_mode)
54  {
55  ui->buttonSplitHorizontal->setVisible(false);
56  ui->buttonSplitVertical->setVisible(false);
57  }
58 }
59 
60 void DockToolbar::mousePressEvent(QMouseEvent* ev)
61 {
63 }
64 
65 void DockToolbar::mouseReleaseEvent(QMouseEvent* ev)
66 {
68 }
69 
70 void DockToolbar::mouseMoveEvent(QMouseEvent* ev)
71 {
72  ui->buttonFullscreen->setVisible(true);
73  ui->buttonBackground->setVisible(true);
74  ui->buttonSplitHorizontal->setVisible(!_fullscreen_mode);
75  ui->buttonSplitVertical->setVisible(!_fullscreen_mode);
77 
78  ev->accept();
79  QWidget::mouseMoveEvent(ev);
80 }
81 
82 void DockToolbar::enterEvent(QEvent* ev)
83 {
84  ui->buttonFullscreen->setVisible(true);
85  ui->buttonBackground->setVisible(true);
86  ui->buttonSplitHorizontal->setVisible(!_fullscreen_mode);
87  ui->buttonSplitVertical->setVisible(!_fullscreen_mode);
88 
89  ev->accept();
90  QWidget::enterEvent(ev);
91 }
92 
93 bool DockToolbar::eventFilter(QObject* object, QEvent* event)
94 {
95  if (event->type() == QEvent::MouseButtonDblClick)
96  {
97  bool ok = true;
98  QString newName =
99  QInputDialog::getText(this, tr("Change name of the Area"), tr("New name:"),
100  QLineEdit::Normal, ui->label->text(), &ok);
101  if (ok)
102  {
103  ui->label->setText(newName);
104  emit titleChanged(newName);
105  }
106  return true;
107  }
108  else
109  {
110  return QObject::eventFilter(object, event);
111  }
112 }
113 
115 {
116  _expand_icon = LoadSvg(":/resources/svg/expand.svg", theme);
117  _collapse_icon = LoadSvg(":/resources/svg/collapse.svg", theme);
119  setButtonIcon(ui->buttonClose, LoadSvg(":/resources/svg/close-button.svg", theme));
120  setButtonIcon(ui->buttonSplitHorizontal,
121  LoadSvg(":/resources/svg/add_column.svg", theme));
122  setButtonIcon(ui->buttonSplitVertical, LoadSvg(":/resources/svg/add_row.svg", theme));
123 }
124 
125 void DockToolbar::dragEnterEvent(QDragEnterEvent* event)
126 {
127  const QMimeData* mimeData = event->mimeData();
128  QStringList mimeFormats = mimeData->formats();
129 
130  bool has_curve = false;
131  for (const QString& format : mimeFormats)
132  {
133  QByteArray encoded = mimeData->data(format);
134  QDataStream stream(&encoded, QIODevice::ReadOnly);
135 
136  if (format == "curveslist/add_curve")
137  {
138  while (!stream.atEnd())
139  {
140  QString curve_name;
141  stream >> curve_name;
142  if (!curve_name.isEmpty())
143  {
144  if (!has_curve)
145  {
146  has_curve = true;
147  _dragging_curve = curve_name;
148  }
149  else
150  {
151  // multiple curves, discard
152  _dragging_curve.clear();
153  return;
154  }
155  }
156  }
157  }
158  }
159  if (has_curve)
160  {
161  event->accept();
162  ui->buttonFullscreen->setVisible(true);
163  ui->buttonBackground->setVisible(true);
164  ui->buttonSplitHorizontal->setVisible(!_fullscreen_mode);
165  ui->buttonSplitVertical->setVisible(!_fullscreen_mode);
166  }
167 }
168 
169 void DockToolbar::dragLeaveEvent(QDragLeaveEvent*)
170 {
171  ui->buttonFullscreen->setVisible(false);
172  ui->buttonBackground->setVisible(ui->buttonBackground->isChecked());
173  ui->buttonSplitHorizontal->setVisible(false);
174  ui->buttonSplitVertical->setVisible(false);
175 }
176 
177 void DockToolbar::dropEvent(QDropEvent* event)
178 {
179  auto global_pos = mapToGlobal(event->pos());
180  auto pos = ui->buttonBackground->mapFromGlobal(global_pos);
181  bool on_label = ui->buttonBackground->rect().contains(pos);
182  if (on_label)
183  {
185  _dragging_curve.clear();
186  }
187 }
188 
189 void DockToolbar::leaveEvent(QEvent* ev)
190 {
191  ui->buttonFullscreen->setVisible(_fullscreen_mode);
192  ui->buttonSplitHorizontal->setVisible(false);
193  ui->buttonSplitVertical->setVisible(false);
194  ui->buttonBackground->setVisible(ui->buttonBackground->isChecked());
195  QWidget::leaveEvent(ev);
196 }
197 
199 {
200  emit backgroundColorRequest({});
201 }
DockToolbar::on_buttonBackground_clicked
void on_buttonBackground_clicked()
Definition: plot_docker_toolbar.cpp:198
DockToolbar::titleChanged
void titleChanged(QString title)
DockToolbar::leaveEvent
void leaveEvent(QEvent *) override
Definition: plot_docker_toolbar.cpp:189
ads::CDockAreaWidget::titleBar
CDockAreaTitleBar * titleBar() const
Definition: DockAreaWidget.cpp:956
ads::CDockWidget::dockAreaWidget
CDockAreaWidget * dockAreaWidget() const
Definition: DockWidget.cpp:394
LoadSvg
const QPixmap & LoadSvg(QString filename, QString style_name="light")
Definition: svg_util.h:26
DockToolbar::DockToolbar
DockToolbar(ads::CDockWidget *parent)
Definition: plot_docker_toolbar.cpp:10
DockToolbar::eventFilter
bool eventFilter(QObject *object, QEvent *event) override
Definition: plot_docker_toolbar.cpp:93
DockToolbar::enterEvent
void enterEvent(QEvent *) override
Definition: plot_docker_toolbar.cpp:82
DockToolbar::_dragging_curve
QString _dragging_curve
Definition: plot_docker_toolbar.h:77
setButtonIcon
static void setButtonIcon(QPushButton *button, QIcon icon)
Definition: plot_docker_toolbar.cpp:40
DockToolbar::_fullscreen_mode
bool _fullscreen_mode
Definition: plot_docker_toolbar.h:73
DockToolbar::dragEnterEvent
void dragEnterEvent(QDragEnterEvent *event) override
Definition: plot_docker_toolbar.cpp:125
ok
ROSCPP_DECL bool ok()
DockToolbar::~DockToolbar
~DockToolbar() override
Definition: plot_docker_toolbar.cpp:35
DockToolbar::_parent
ads::CDockWidget * _parent
Definition: plot_docker_toolbar.h:71
DockToolbar::backgroundColorRequest
void backgroundColorRequest(QString name)
DockToolbar::_collapse_icon
QIcon _collapse_icon
Definition: plot_docker_toolbar.h:76
DockToolbar::mousePressEvent
void mousePressEvent(QMouseEvent *ev) override
Definition: plot_docker_toolbar.cpp:60
Ui
Definition: cheatsheet_dialog.h:6
DockToolbar::mouseMoveEvent
void mouseMoveEvent(QMouseEvent *ev) override
Definition: plot_docker_toolbar.cpp:70
ads::CDockWidget
Definition: DockWidget.h:54
DockToolbar::ui
Ui::DraggableToolbar * ui
Definition: plot_docker_toolbar.h:72
DockToolbar::dragLeaveEvent
void dragLeaveEvent(QDragLeaveEvent *event) override
Definition: plot_docker_toolbar.cpp:169
ads::CDockAreaTitleBar::mouseMoveEvent
virtual void mouseMoveEvent(QMouseEvent *ev) override
Definition: DockAreaTitleBar.cpp:504
format
auto format(const text_style &ts, const S &format_str, const Args &... args) -> std::basic_string< Char >
Definition: color.h:543
plot_docker_toolbar.h
DockToolbar::dropEvent
void dropEvent(QDropEvent *event) override
Definition: plot_docker_toolbar.cpp:177
ads::CDockAreaTitleBar::mousePressEvent
virtual void mousePressEvent(QMouseEvent *ev) override
Definition: DockAreaTitleBar.cpp:464
DockToolbar::toggleFullscreen
void toggleFullscreen()
Definition: plot_docker_toolbar.cpp:46
DockToolbar::_expand_icon
QIcon _expand_icon
Definition: plot_docker_toolbar.h:75
DockToolbar::mouseReleaseEvent
void mouseReleaseEvent(QMouseEvent *ev) override
Definition: plot_docker_toolbar.cpp:65
DockToolbar::on_stylesheetChanged
void on_stylesheetChanged(QString theme)
Definition: plot_docker_toolbar.cpp:114
svg_util.h
ads::CDockAreaTitleBar::mouseReleaseEvent
virtual void mouseReleaseEvent(QMouseEvent *ev) override
Definition: DockAreaTitleBar.cpp:483


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:45