ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvCustomViewpointsToolbar.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
9 
10 // LOCAL
11 #include "ecvCameraParamEditDlg.h"
13 #include "ecvSettingManager.h"
14 
15 // CV_DB_LIB
16 #include <ecvDisplayTools.h>
17 
18 #ifdef USE_PCL_BACKEND
20 #endif
21 
22 // QT
23 #include <QApplication>
24 #include <QPainter>
25 
26 //-----------------------------------------------------------------------------
27 void ecvCustomViewpointsToolbar::constructor() {
28  // Create base pixmap
29  this->BasePixmap.fill(QColor(0, 0, 0, 0));
30  QPainter pixPaint(&this->BasePixmap);
31  pixPaint.drawPixmap(0, 0, 48, 48,
32  QPixmap(":/Resources/images/svg/pqCamera.png"));
33 
34  // Create plus pixmap
35  this->PlusPixmap = this->BasePixmap.copy();
36  QPainter pixWithPlusPaint(&this->PlusPixmap);
37  pixWithPlusPaint.drawPixmap(32, 32, 32, 32,
38  QPixmap(":/Resources/images/svg/pqPlus.png"));
39  this->ConfigPixmap = this->BasePixmap.copy();
40  QPainter pixWithConfigPaint(&this->ConfigPixmap);
41  pixWithConfigPaint.drawPixmap(
42  32, 32, 32, 32, QPixmap(":/Resources/images/svg/pqWrench.png"));
43 
44  this->PlusAction = this->ConfigAction = nullptr;
45 
46  this->setWindowTitle(tr("Custom Viewpoints Toolbar"));
48  this->connect(ecvDisplayTools::TheInstance(), SIGNAL(cameraParamChanged()),
49  SLOT(updateEnabledState()));
51  this->connect(settings, SIGNAL(modified()),
53 }
54 
55 //-----------------------------------------------------------------------------
57  this->setEnabled(ecvDisplayTools::GetCurrentScreen() != nullptr);
58  auto actions = this->actions();
59  actions[actions.size() - 2]->setEnabled(
60  actions.size() <
62 }
63 
64 //-----------------------------------------------------------------------------
66  // Recover tooltips from settings
67  QStringList tooltips = ecvCameraParamEditDlg::CustomViewpointToolTips();
68 
69  if (!this->ConfigAction) {
70  this->ConfigAction = this->addAction(
71  QIcon(this->ConfigPixmap), tr("Configure custom viewpoints"),
72  this, SLOT(ConfigureCustomViewpoints()));
73  this->ConfigAction->setObjectName("ConfigAction");
74  }
75 
76  if (!this->PlusAction) {
77  this->PlusAction = this->addAction(
78  QIcon(this->PlusPixmap),
79  tr("Add current viewpoint as custom viewpoint"), this,
81  this->PlusAction->setObjectName("PlusAction");
82  }
83 
84  // Remove unused actions
85  for (int cc = this->ViewpointActions.size(); cc > tooltips.size(); cc--) {
86  this->removeAction(this->ViewpointActions[cc - 1]);
87  }
88  if (this->ViewpointActions.size() > tooltips.size()) {
89  this->ViewpointActions.resize(tooltips.size());
90  }
91 
92  // add / change actions for custom views.
93  for (int cc = 0; cc < tooltips.size(); cc++) {
94  QPixmap pixmap;
95  if (this->ViewpointActions.size() > cc) {
96  this->ViewpointActions[cc]->setToolTip(tooltips[cc]);
97  } else {
98  // action does not exist yet, create it
99  pixmap = this->BasePixmap.copy();
100  QPainter pixWithNumberPaint(&pixmap);
101  QFont font = pixWithNumberPaint.font();
102  font.setPixelSize(24);
103  pixWithNumberPaint.setFont(font);
104  pixWithNumberPaint.setPen(
105  QApplication::palette().windowText().color());
106  pixWithNumberPaint.drawText(pixmap.rect(),
107  Qt::AlignRight | Qt::AlignBottom,
108  QString::number(cc + 1));
109 
110  QAction* action = this->addAction(QIcon(pixmap), "", this,
111  SLOT(ApplyCustomViewpoint()));
112  action->setObjectName(QString("ViewpointAction%1").arg(cc));
113  action->setToolTip(tooltips[cc]);
114  action->setData(cc);
115  this->ViewpointActions.push_back(action);
116  }
117  }
118 
119  this->updateEnabledState();
120 }
121 
122 //-----------------------------------------------------------------------------
124  ecvCameraParamEditDlg::ConfigureCustomViewpoints(this);
125 }
126 
127 //-----------------------------------------------------------------------------
130  int customViewpointIndex;
131  QAction* action = qobject_cast<QAction*>(this->sender());
132  if (!action) {
133  return;
134  }
135 
136  customViewpointIndex = action->data().toInt();
138  customViewpointIndex)) {
140  }
141  }
142 }
143 
144 //-----------------------------------------------------------------------------
147  int customViewpointIndex;
148  QAction* action = qobject_cast<QAction*>(this->sender());
149  if (!action) {
150  return;
151  }
152 
153  customViewpointIndex = action->data().toInt();
155  customViewpointIndex)) {
157  }
158  }
159 }
160 
161 //-----------------------------------------------------------------------------
163 #ifdef USE_PCL_BACKEND // update camera parameters in case
165 #endif
166 
168 }
169 
170 //-----------------------------------------------------------------------------
172 #ifdef USE_PCL_BACKEND
174  int customViewpointIndex;
175  QAction* action = qobject_cast<QAction*>(this->sender());
176  if (!action) {
177  return;
178  }
179 
180  customViewpointIndex = action->data().toInt();
181  if (ecvCameraParamEditDlg::ApplyCustomViewpoint(customViewpointIndex)) {
183  }
184  }
185 #else
187  "[ecvCustomViewpointsToolbar::ApplyCustomViewpoint] please use pcl "
188  "as backend and then try again!");
189 #endif
190 }
math::float4 color
static bool Warning(const char *format,...)
Prints out a formatted warning message in console.
Definition: CVLog.cpp:133
static void UpdateCamera()
static void UpdateCameraInfo()
static bool SetToCurrentViewpoint(int CustomViewpointIndex)
static bool AddCurrentViewpointToCustomViewpoints()
static QStringList CustomViewpointToolTips()
static bool DeleteCustomViewpoint(int CustomViewpointIndex)
static ecvDisplayTools * TheInstance()
static QWidget * GetCurrentScreen()
static void UpdateScreen()
static ecvSettingManager * TheInstance(bool autoInit=true)
Returns the (unique) static instance.