8 #include <QSignalMapper>
11 #include <QSvgGenerator>
12 #include <QInputDialog>
13 #include <QMouseEvent>
14 #include <QFileDialog>
15 #include <QApplication>
18 #include <QPushButton>
19 #include <QHBoxLayout>
30 : QWidget(parent), _mapped_data(mapped_data), _name(name), _main_window(mainwindow)
34 setContentsMargins(0, 0, 0, 0);
36 if (main_window == parent)
47 throw std::runtime_error(
"This is not supposed to happen");
54 QHBoxLayout* main_layout =
new QHBoxLayout(
this);
55 main_layout->setMargin(0);
61 connect(
_tabWidget->tabBar(), &QTabBar::tabBarDoubleClicked,
this,
66 connect(
_tabWidget, &QTabWidget::currentChanged,
this,
69 tabWidget()->tabBar()->installEventFilter(
this);
80 connect(
this, &TabbedPlotWidget::destroyed, main_window,
102 QWidget::paintEvent(event);
125 static int tab_suffix_count = 1;
134 if (tab_name.isEmpty())
136 tab_name = QString(
"tab%1").arg(tab_suffix_count++);
146 emit docker->plotWidgetAdded(docker->plotAt(0));
150 QWidget* button_widget =
new QWidget();
151 QHBoxLayout* layout =
new QHBoxLayout(button_widget);
152 layout->setSpacing(2);
153 layout->setMargin(0);
155 QPushButton* close_button =
new QPushButton();
158 QString theme = settings.value(
"StyleSheet::theme",
"light").toString();
159 close_button->setIcon(
LoadSvg(
":/resources/svg/close-button.svg", theme));
161 close_button->setFixedSize(QSize(16, 16));
162 close_button->setFlat(
true);
163 connect(close_button, &QPushButton::pressed,
this, [
this]() {
167 layout->addWidget(close_button);
168 tabWidget()->tabBar()->setTabButton(index, QTabBar::RightSide, button_widget);
179 QDomElement tabbed_area = doc.createElement(
"tabbed_widget");
181 tabbed_area.setAttribute(
"name",
_name);
184 for (
int i = 0; i <
tabWidget()->count(); i++)
189 element.setAttribute(
"tab_name",
tabWidget()->tabText(i));
190 tabbed_area.appendChild(element);
193 QDomElement current_plotmatrix = doc.createElement(
"currentTabIndex");
194 current_plotmatrix.setAttribute(
"index",
tabWidget()->currentIndex());
195 tabbed_area.appendChild(current_plotmatrix);
204 for (
auto docker_elem = tabbed_area.firstChildElement(
"Tab"); !docker_elem.isNull();
205 docker_elem = docker_elem.nextSiblingElement(
"Tab"))
207 QString tab_name = docker_elem.attribute(
"tab_name");
219 for (
int i = 0; i < prev_count; i++)
225 QDomElement current_tab = tabbed_area.firstChildElement(
"currentTabIndex");
226 int current_index = current_tab.attribute(
"index").toInt();
230 tabWidget()->setCurrentIndex(current_index);
247 int idx =
tabWidget()->tabBar()->currentIndex();
251 QInputDialog::getText(
this, tr(
"Change the tab name"), tr(
"New name:"),
252 QLineEdit::Normal,
tabWidget()->tabText(idx), &
ok);
281 this->parent()->deleteLater();
290 for (
int i = 0; i <
tabWidget()->count(); i++)
292 auto button =
_tabWidget->tabBar()->tabButton(i, QTabBar::RightSide);
295 button->setHidden(i != index);
313 for (
unsigned p = 0; p < docker->
plotCount(); p++)
319 docker->deleteLater();
329 for (
int i = 0; i <
tabWidget()->count(); i++)
341 int index =
tabWidget()->tabBar()->currentIndex();
343 const QString& tab_name = this->
tabWidget()->tabText(index);
345 destination_widget->
tabWidget()->addTab(tab_to_move, tab_name);
356 QTabBar* tab_bar =
tabWidget()->tabBar();
360 if (event->type() == QEvent::MouseButtonPress)
362 QMouseEvent* mouse_event =
static_cast<QMouseEvent*
>(event);
364 int index = tab_bar->tabAt(mouse_event->pos());
365 tab_bar->setCurrentIndex(index);
367 if (mouse_event->button() == Qt::RightButton)
413 return QObject::eventFilter(obj, event);