tab_widget.h
Go to the documentation of this file.
1 #ifndef TAB_BAR_H
2 #define TAB_BAR_H
3 
4 #include <QTabBar>
5 #include <QLabel>
6 #include <QPixmap>
7 #include <QDebug>
8 #include <QTabWidget>
9 #include <QMimeData>
10 #include <QDragEnterEvent>
11 #include <QDragLeaveEvent>
12 #include <QApplication>
13 
14 class TabWidget : public QTabWidget
15 {
16  Q_OBJECT
17 public:
18  TabWidget(QWidget* parent)
19  : QTabWidget(parent)
20  {
21  this->tabBar()->setFixedHeight(40);
22  setAcceptDrops(true);
23  }
24 
25  void dragEnterEvent(QDragEnterEvent *ev) override
26  {
27  if( ev->pos().y() > 43 )
28  {
29  ev->ignore();
30  return;
31  }
32  const QMimeData *mimeData = ev->mimeData();
33  QStringList mimeFormats = mimeData->formats();
34  for(const QString& format: mimeFormats)
35  {
36  QByteArray encoded = mimeData->data( format );
37  QDataStream stream(&encoded, QIODevice::ReadOnly);
38 
39  QStringList curves;
40 
41  while (!stream.atEnd())
42  {
43  QString curve_name;
44  stream >> curve_name;
45  if(!curve_name.isEmpty()) {
46  curves.push_back(curve_name);
47  }
48  }
49 
50  if( format.contains( "plot_area") && curves.size() == 1 )
51  {
52  QApplication::setOverrideCursor(QCursor(Qt::DragMoveCursor));
53  ev->accept();
54  _plot_to_move = curves.front();
55  return;
56  }
57  }
58  ev->ignore();
59  }
60 
61  void dragMoveEvent(QDragMoveEvent *ev) override
62  {
63  if( ev->pos().y() > 43 )
64  {
65  ev->ignore();
66  return;
67  }
68  ev->accept();
69  }
70 
71  void dragLeaveEvent(QDragLeaveEvent *ev) override
72  {
73  _plot_to_move = "";
74  QApplication::restoreOverrideCursor();
75  }
76 
77  void dropEvent(QDropEvent *ev) override
78  {
80  _plot_to_move = "";
81  QApplication::restoreOverrideCursor();
82  }
83 
84 private:
85  QString _plot_to_move;
86 
87 signals:
88 
89  void movingPlotWidgetToTab(QString plot_name);
90 };
91 
92 #endif // TAB_BAR_H
TabWidget(QWidget *parent)
Definition: tab_widget.h:18
void dragLeaveEvent(QDragLeaveEvent *ev) override
Definition: tab_widget.h:71
QString _plot_to_move
Definition: tab_widget.h:85
void movingPlotWidgetToTab(QString plot_name)
std::string format(const std::string &, const time_point< seconds > &, const femtoseconds &, const time_zone &)
void dragEnterEvent(QDragEnterEvent *ev) override
Definition: tab_widget.h:25
void dragMoveEvent(QDragMoveEvent *ev) override
Definition: tab_widget.h:61
void dropEvent(QDropEvent *ev) override
Definition: tab_widget.h:77


plotjuggler
Author(s): Davide Faconti
autogenerated on Sat Jul 6 2019 03:44:18