##// END OF EJS Templates
Add code to ensure the corner widget to be always visible
perrinel -
r156:9b62d51e0971
parent child
Show More
@@ -1,74 +1,80
1 #include "Visualization/VisualizationWidget.h"
1 #include "Visualization/VisualizationWidget.h"
2 #include "Visualization/VisualizationTabWidget.h"
2 #include "Visualization/VisualizationTabWidget.h"
3 #include "Visualization/qcustomplot.h"
3 #include "Visualization/qcustomplot.h"
4
4
5 #include "ui_VisualizationWidget.h"
5 #include "ui_VisualizationWidget.h"
6
6
7 #include <QToolButton>
7 #include <QToolButton>
8
8
9 Q_LOGGING_CATEGORY(LOG_VisualizationWidget, "VisualizationWidget")
9 Q_LOGGING_CATEGORY(LOG_VisualizationWidget, "VisualizationWidget")
10
10
11 VisualizationWidget::VisualizationWidget(QWidget *parent)
11 VisualizationWidget::VisualizationWidget(QWidget *parent)
12 : QWidget{parent}, ui{new Ui::VisualizationWidget}
12 : QWidget{parent}, ui{new Ui::VisualizationWidget}
13 {
13 {
14 ui->setupUi(this);
14 ui->setupUi(this);
15
15
16 auto addTabViewButton = new QToolButton{ui->tabWidget};
16 auto addTabViewButton = new QToolButton{ui->tabWidget};
17 addTabViewButton->setText(tr("Add View"));
17 addTabViewButton->setText(tr("Add View"));
18 addTabViewButton->setCursor(Qt::ArrowCursor);
18 addTabViewButton->setCursor(Qt::ArrowCursor);
19 addTabViewButton->setAutoRaise(true);
19 addTabViewButton->setAutoRaise(true);
20 ui->tabWidget->setCornerWidget(addTabViewButton, Qt::TopRightCorner);
20 ui->tabWidget->setCornerWidget(addTabViewButton, Qt::TopRightCorner);
21 auto width = ui->tabWidget->cornerWidget()->width();
22 auto height = ui->tabWidget->cornerWidget()->height();
23 addTabViewButton->setMinimumHeight(height);
24 addTabViewButton->setMinimumWidth(width);
25 ui->tabWidget->setMinimumHeight(height);
26 ui->tabWidget->setMinimumWidth(width);
21
27
22 auto addTabView = [&]() {
28 auto addTabView = [&]() {
23 auto index = ui->tabWidget->addTab(new VisualizationTabWidget(ui->tabWidget),
29 auto index = ui->tabWidget->addTab(new VisualizationTabWidget(ui->tabWidget),
24 QString("View %1").arg(ui->tabWidget->count() + 1));
30 QString("View %1").arg(ui->tabWidget->count() + 1));
25 qCInfo(LOG_VisualizationWidget()) << tr("add the tab of index %1").arg(index);
31 qCInfo(LOG_VisualizationWidget()) << tr("add the tab of index %1").arg(index);
26 };
32 };
27
33
28 auto removeTabView = [&](int index) {
34 auto removeTabView = [&](int index) {
29 ui->tabWidget->removeTab(index);
35 ui->tabWidget->removeTab(index);
30 qCInfo(LOG_VisualizationWidget()) << tr("remove the tab of index %1").arg(index);
36 qCInfo(LOG_VisualizationWidget()) << tr("remove the tab of index %1").arg(index);
31 };
37 };
32
38
33 ui->tabWidget->setTabsClosable(true);
39 ui->tabWidget->setTabsClosable(true);
34
40
35 connect(addTabViewButton, &QToolButton::clicked, addTabView);
41 connect(addTabViewButton, &QToolButton::clicked, addTabView);
36 connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView);
42 connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView);
37 }
43 }
38
44
39 VisualizationWidget::~VisualizationWidget()
45 VisualizationWidget::~VisualizationWidget()
40 {
46 {
41 delete ui;
47 delete ui;
42 }
48 }
43
49
44 void VisualizationWidget::addTab(VisualizationTabWidget *tabWidget)
50 void VisualizationWidget::addTab(VisualizationTabWidget *tabWidget)
45 {
51 {
46 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
52 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
47 // lambda function (in the constructor)
53 // lambda function (in the constructor)
48 }
54 }
49
55
50 VisualizationTabWidget *VisualizationWidget::createTab()
56 VisualizationTabWidget *VisualizationWidget::createTab()
51 {
57 {
52 }
58 }
53
59
54 void VisualizationWidget::removeTab(VisualizationTabWidget *tab)
60 void VisualizationWidget::removeTab(VisualizationTabWidget *tab)
55 {
61 {
56 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
62 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
57 // lambda function (in the constructor)
63 // lambda function (in the constructor)
58 }
64 }
59
65
60 void VisualizationWidget::accept(IVisualizationWidget *visitor)
66 void VisualizationWidget::accept(IVisualizationWidget *visitor)
61 {
67 {
62 // TODO: manage the visitor
68 // TODO: manage the visitor
63 }
69 }
64
70
65 void VisualizationWidget::close()
71 void VisualizationWidget::close()
66 {
72 {
67 // The main view cannot be directly closed.
73 // The main view cannot be directly closed.
68 return;
74 return;
69 }
75 }
70
76
71 QString VisualizationWidget::name() const
77 QString VisualizationWidget::name() const
72 {
78 {
73 return QStringLiteral("MainView");
79 return QStringLiteral("MainView");
74 }
80 }
General Comments 0
You need to be logged in to leave comments. Login now