2 #include <QSignalMapper> 5 #include <QSvgGenerator> 6 #include <QInputDialog> 9 #include <QApplication> 12 #include <QPushButton> 13 #include <QHBoxLayout> 25 , _mapped_data(mapped_data)
27 , _main_window(mainwindow)
31 setContentsMargins(0,0,0,0);
33 if (main_window == parent)
44 throw std::runtime_error(
"This is not supposed to happen");
51 QHBoxLayout* main_layout =
new QHBoxLayout(
this);
52 main_layout->setMargin(0);
58 connect(
_tabWidget->tabBar(), &QTabBar::tabBarDoubleClicked,
63 connect(
_tabWidget, &QTabWidget::currentChanged,
66 tabWidget()->tabBar()->installEventFilter(
this);
86 _buttonAddTab->setFlat(
true);
87 _buttonAddTab->setFixedSize( QSize(32,32));
88 _buttonAddTab->setFocusPolicy(Qt::NoFocus);
95 QWidget::paintEvent(event);
97 auto size =
tabWidget()->tabBar()->size();
119 static int tab_suffix_count = 1;
128 if( tab_name.isEmpty() )
130 tab_name = QString(
"tab%1").arg(tab_suffix_count++);
140 emit docker->plotWidgetAdded( docker->plotAt(0) );
144 QWidget* button_widget =
new QWidget();
145 QHBoxLayout* layout =
new QHBoxLayout(button_widget);
146 layout->setSpacing(2);
147 layout->setMargin(0);
149 QPushButton* close_button =
new QPushButton();
152 QString theme = settings.value(
"StyleSheet::theme",
"light").toString();
153 close_button->setIcon(
LoadSvgIcon(
":/resources/svg/close-button.svg", theme));
155 close_button->setFixedSize( QSize(16,16));
156 close_button->setFlat(
true);
157 connect(close_button, &QPushButton::pressed,
160 layout->addWidget(close_button);
161 tabWidget()->tabBar()->setTabButton(index, QTabBar::RightSide, button_widget);
172 QDomElement tabbed_area = doc.createElement(
"tabbed_widget");
174 tabbed_area.setAttribute(
"name",
_name);
177 for (
int i = 0; i <
tabWidget()->count(); i++)
182 element.setAttribute(
"tab_name",
tabWidget()->tabText(i));
183 tabbed_area.appendChild(element);
186 QDomElement current_plotmatrix = doc.createElement(
"currentTabIndex");
187 current_plotmatrix.setAttribute(
"index",
tabWidget()->currentIndex());
188 tabbed_area.appendChild(current_plotmatrix);
197 for (
auto docker_elem = tabbed_area.firstChildElement(
"Tab");
198 !docker_elem.isNull();
199 docker_elem = docker_elem.nextSiblingElement(
"Tab"))
201 QString tab_name = docker_elem.attribute(
"tab_name");
213 for(
int i=0; i<prev_count; i++ )
218 QDomElement current_tab = tabbed_area.firstChildElement(
"currentTabIndex");
219 int current_index = current_tab.attribute(
"index").toInt();
223 tabWidget()->setCurrentIndex(current_index);
242 int idx =
tabWidget()->tabBar()->currentIndex();
245 QString newName = QInputDialog::getText(
this, tr(
"Change the tab name"), tr(
"New name:"),
246 QLineEdit::Normal,
tabWidget()->tabText(idx), &ok);
277 this->parent()->deleteLater();
286 for (
int i=0; i<
tabWidget()->count(); i++ )
288 auto button =
_tabWidget->tabBar()->tabButton(i, QTabBar::RightSide);
290 button->setHidden( i!=index );
308 for (
unsigned p = 0; p < docker->
plotCount(); p++)
314 docker->deleteLater();
325 for (
int i = 0; i <
tabWidget()->count(); i++)
337 int index =
tabWidget()->tabBar()->currentIndex();
339 const QString& tab_name = this->
tabWidget()->tabText(index);
341 destination_widget->
tabWidget()->addTab(tab_to_move, tab_name);
352 QTabBar* tab_bar =
tabWidget()->tabBar();
356 if (event->type() == QEvent::MouseButtonPress)
358 QMouseEvent* mouse_event =
static_cast<QMouseEvent*
>(event);
360 int index = tab_bar->tabAt(mouse_event->pos());
361 tab_bar->setCurrentIndex(index);
363 if (mouse_event->button() == Qt::RightButton)
407 return QObject::eventFilter(obj, event);
If the flag is set each dock area has a tabs menu button.
PlotWidget * plotAt(int index)
void onPlotTabAdded(PlotDocker *docker)
QIcon LoadSvgIcon(QString filename, QString style_name="light")
void setName(QString name)
If this option is enabled, the tab of a dock widget is always displayed - even if it is the only visi...
void on_tabbedAreaDestroyed(QObject *object)
See QSplitter::setOpaqueResize() documentation.
static void setConfigFlag(eConfigFlag Flag, bool On=true)
bool xmlLoadState(QDomElement &tab_element)
QDomElement xmlSaveState(QDomDocument &doc) const
If the flag is set each dock area has an undock button.
void setHorizontalLink(bool enabled)