9 #include <QInputDialog> 19 title_bar->setVisible(
false);
26 ads::CDockManager(parent), _name(name), _datamap(datamap)
30 auto CreateFirstWidget = [&]()
64 QSplitter* splitter = qobject_cast<QSplitter*>(widget);
67 QDomElement splitter_elem = doc.createElement(
"DockSplitter");
68 splitter_elem.setAttribute(
"orientation", (splitter->orientation() == Qt::Horizontal) ?
"|" :
"-");
69 splitter_elem.setAttribute(
"count", QString::number(splitter->count()));
73 for(
int size : splitter->sizes() )
77 for(
int size : splitter->sizes() )
79 sizes_str += QString::number(
double(size)/
double(total_size) );
82 sizes_str.resize( sizes_str.size()-1 );
83 splitter_elem.setAttribute(
"sizes", sizes_str);
85 for (
int i = 0; i < splitter->count(); ++i)
88 splitter_elem.appendChild( child );
96 QDomElement area_elem = doc.createElement(
"DockArea");
103 area_elem.appendChild( plotwidget_elem );
104 area_elem.setAttribute(
"name", dock_widget->toolBar()->label()->text());
115 QDomElement containers_elem = doc.createElement(
"Tab");
121 QDomElement elem = doc.createElement(
"Container");
123 elem.appendChild(child);
124 containers_elem.appendChild(elem);
126 return containers_elem;
131 QString orientation_str = elem.attribute(
"orientation");
132 int splitter_count = elem.attribute(
"count").toInt();
135 if (!orientation_str.startsWith(
"|") && !orientation_str.startsWith(
"-"))
140 Qt::Orientation orientation = orientation_str.startsWith(
"|") ? Qt::Horizontal : Qt::Vertical;
142 std::vector<DockWidget*> widgets(splitter_count);
145 for (
int i=1; i<splitter_count; i++ )
147 widget = (orientation == Qt::Horizontal) ?
154 for (
int i=0; i<splitter_count; i++ )
156 tot_size += ( orientation == Qt::Horizontal ) ? widgets[i]->width() : widgets[i]->height();
159 auto sizes_str = elem.attribute(
"sizes").splitRef(
";", QString::SkipEmptyParts);
162 for (
int i=0; i<splitter_count; i++ )
164 sizes.push_back( static_cast<int>(sizes_str[i].toDouble() * tot_size) );
167 auto splitter = ads::internal::findParent<ads::CDockSplitter*>(widget);
168 splitter->setSizes(sizes);
172 QDomElement child_elem = elem.firstChildElement();
173 while (child_elem.isNull() ==
false)
175 if( child_elem.tagName() ==
"DockArea" )
177 auto plot_elem = child_elem.firstChildElement(
"plot");
178 widgets[index]->plotWidget()->xmlLoadState(plot_elem);
179 if( child_elem.hasAttribute(
"name") )
181 QString area_name = child_elem.attribute(
"name");
182 widgets[index]->toolBar()->label()->setText(area_name);
186 else if( child_elem.tagName() ==
"DockSplitter" )
194 child_elem = child_elem.nextSiblingElement();
205 for (
auto container_elem = tab_element.firstChildElement(
"Container");
206 !container_elem.isNull();
207 container_elem = container_elem.nextSiblingElement(
"Container"))
209 auto splitter_elem = container_elem.firstChildElement(
"DockSplitter");
210 if( !splitter_elem.isNull())
241 for (
int index = 0; index <
plotCount(); index++)
249 for (
int index = 0; index <
plotCount(); index++)
257 for (
int index = 0; index <
plotCount(); index++)
267 setFrameShape(QFrame::NoFrame);
269 static int plot_count = 0;
270 QString plot_name = QString(
"_plot_%1_").arg(plot_count++);
271 auto plot_widget =
new PlotWidget(datamap,
this);
278 qobject_cast<QBoxLayout*>(layout())->insertWidget(0,
_toolbar);
292 auto FullscreenAction = [=]() {
300 auto area = parent_docker->
dockArea(i);
317 this->layout()->setMargin(10);
371 button->setIcon(icon);
379 _fullscreen_mode(false)
384 QString theme = settings.value(
"StyleSheet::theme",
"light").toString();
387 ui->buttonFullscreen->setVisible(
false );
388 ui->buttonSplitHorizontal->setVisible(
false );
389 ui->buttonSplitVertical->setVisible(
false );
391 setMouseTracking(
true);
392 ui->widgetButtons->setMouseTracking(
true);
394 ui->label->installEventFilter(
this);
410 ui->buttonSplitHorizontal->setVisible(
false );
411 ui->buttonSplitVertical->setVisible(
false );
427 ui->buttonFullscreen->setVisible(
true );
433 QWidget::mouseMoveEvent(ev);
438 ui->buttonFullscreen->setVisible(
true );
443 QWidget::enterEvent(ev);
448 if(event->type() == QEvent::MouseButtonDblClick)
451 QString newName = QInputDialog::getText(
this, tr(
"Change name of the Area"), tr(
"New name:"),
452 QLineEdit::Normal,
ui->label->text(), &ok);
455 ui->label->setText(newName);
460 return QObject::eventFilter(
object,event);
477 ui->buttonSplitHorizontal->setVisible(
false );
478 ui->buttonSplitVertical->setVisible(
false );
479 QWidget::leaveEvent(ev);
PlotWidget * plotAt(int index)
void dockWidgetRemoved(ads::CDockWidget *DockWidget)
void plotWidgetAdded(PlotWidget *)
QIcon LoadSvgIcon(QString filename, QString style_name="light")
CDockAreaWidget * addDockWidget(DockWidgetArea area, CDockWidget *Dockwidget, CDockAreaWidget *DockAreaWidget=nullptr)
PlotDocker(QString name, PlotDataMapRef &datamap, QWidget *parent=nullptr)
friend class CDockContainerWidget
PlotDataMapRef & _datamap
void setName(QString name)
virtual void mouseReleaseEvent(QMouseEvent *ev) override
QDomElement saveChildNodesState(QDomDocument &doc, QWidget *widget)
virtual void mousePressEvent(QMouseEvent *ev) override
Declaration of CDockSplitter.
const QList< CDockContainerWidget * > dockContainers() const
ads::CDockAreaTitleBar * createDockAreaTitleBar(ads::CDockAreaWidget *dock_area) const override
void restoreSplitter(QDomElement elem, DockWidget *widget)
virtual void mouseMoveEvent(QMouseEvent *ev) override
bool xmlLoadState(QDomElement &tab_element)
static void setButtonIcon(QPushButton *button, QIcon icon)
QDomElement xmlSaveState(QDomDocument &doc) const
void on_stylesheetChanged(QString theme)
void setHorizontalLink(bool enabled)
static void setFactory(CDockComponentsFactory *Factory)