tab_widget.h
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 #ifndef TAB_BAR_H
8 #define TAB_BAR_H
9 
10 #include <QTabBar>
11 #include <QLabel>
12 #include <QPixmap>
13 #include <QDebug>
14 #include <QTabWidget>
15 #include <QMimeData>
16 #include <QDragEnterEvent>
17 #include <QDragLeaveEvent>
18 #include <QApplication>
19 
20 class TabWidget : public QTabWidget
21 {
22  Q_OBJECT
23 public:
24  TabWidget(QWidget* parent) : QTabWidget(parent)
25  {
26  this->tabBar()->setFixedHeight(40);
27  setAcceptDrops(true);
28  }
29 
30  void dragEnterEvent(QDragEnterEvent* ev) override
31  {
32  if (ev->pos().y() > 43)
33  {
34  ev->ignore();
35  return;
36  }
37  const QMimeData* mimeData = ev->mimeData();
38  QStringList mimeFormats = mimeData->formats();
39  for (const QString& format : mimeFormats)
40  {
41  QByteArray encoded = mimeData->data(format);
42  QDataStream stream(&encoded, QIODevice::ReadOnly);
43 
44  QStringList curves;
45 
46  while (!stream.atEnd())
47  {
48  QString curve_name;
49  stream >> curve_name;
50  if (!curve_name.isEmpty())
51  {
52  curves.push_back(curve_name);
53  }
54  }
55  }
56  ev->ignore();
57  }
58 
59  void dragMoveEvent(QDragMoveEvent* ev) override
60  {
61  if (ev->pos().y() > 43)
62  {
63  ev->ignore();
64  return;
65  }
66  ev->accept();
67  }
68 
69  void dragLeaveEvent(QDragLeaveEvent* ev) override
70  {
71  _plot_to_move = "";
72  QApplication::restoreOverrideCursor();
73  }
74 
75  void dropEvent(QDropEvent* ev) override
76  {
78  _plot_to_move = "";
79  QApplication::restoreOverrideCursor();
80  }
81 
82 private:
83  QString _plot_to_move;
84 
85 signals:
86 
87  void movingPlotWidgetToTab(QString plot_name);
88 };
89 
90 #endif // TAB_BAR_H
TabWidget::TabWidget
TabWidget(QWidget *parent)
Definition: tab_widget.h:24
TabWidget::movingPlotWidgetToTab
void movingPlotWidgetToTab(QString plot_name)
TabWidget
Definition: tab_widget.h:20
TabWidget::dragMoveEvent
void dragMoveEvent(QDragMoveEvent *ev) override
Definition: tab_widget.h:59
TabWidget::dragLeaveEvent
void dragLeaveEvent(QDragLeaveEvent *ev) override
Definition: tab_widget.h:69
format
auto format(const text_style &ts, const S &format_str, const Args &... args) -> std::basic_string< Char >
Definition: color.h:543
TabWidget::_plot_to_move
QString _plot_to_move
Definition: tab_widget.h:83
TabWidget::dragEnterEvent
void dragEnterEvent(QDragEnterEvent *ev) override
Definition: tab_widget.h:30
TabWidget::dropEvent
void dropEvent(QDropEvent *ev) override
Definition: tab_widget.h:75


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