##// END OF EJS Templates
Visual display when dropping on top of a existing graph
trabillard -
r857:8c8decf98df7
parent child
Show More
@@ -53,6 +53,8 public:
53 53
54 54 QUrl imageTemporaryUrl(const QImage &image) const;
55 55
56 void setHightlightedDragWidget(VisualizationDragWidget *dragWidget);
57
56 58 private:
57 59 class DragDropHelperPrivate;
58 60 spimpl::unique_impl_ptr<DragDropHelperPrivate> impl;
@@ -13,6 +13,7 public:
13 13
14 14 virtual QMimeData *mimeData() const = 0;
15 15 virtual bool isDragAllowed() const = 0;
16 virtual void highlightForMerge(bool highlighted) { Q_UNUSED(highlighted); };
16 17
17 18 protected:
18 19 virtual void mousePressEvent(QMouseEvent *event) override;
@@ -59,6 +59,7 public:
59 59 // VisualisationDragWidget
60 60 QMimeData *mimeData() const override;
61 61 bool isDragAllowed() const override;
62 void highlightForMerge(bool highlighted) override;
62 63
63 64 signals:
64 65 void synchronize(const SqpRange &range, const SqpRange &oldRange);
@@ -29,7 +29,6 struct DragDropScroller::DragDropScrollerPrivate {
29 29 QScrollArea *m_CurrentScrollArea = nullptr;
30 30 std::unique_ptr<QTimer> m_Timer = nullptr;
31 31
32
33 32 enum class ScrollDirection { up, down, unknown };
34 33 ScrollDirection m_Direction = ScrollDirection::unknown;
35 34
@@ -148,6 +147,8 struct DragDropHelper::DragDropHelperPrivate {
148 147 QString m_ImageTempUrl; // Temporary file for image url generated by the drag & drop. Not using
149 148 // QTemporaryFile to have a name which is not generated.
150 149
150 VisualizationDragWidget *m_HighlightedDragWidget = nullptr;
151
151 152 explicit DragDropHelperPrivate()
152 153 : m_PlaceHolder{std::make_unique<QWidget>()},
153 154 m_DragDropScroller{std::make_unique<DragDropScroller>()}
@@ -176,9 +177,7 struct DragDropHelper::DragDropHelperPrivate {
176 177 };
177 178
178 179
179 DragDropHelper::DragDropHelper() : impl{spimpl::make_unique_impl<DragDropHelperPrivate>()}
180 {
181 }
180 DragDropHelper::DragDropHelper() : impl{spimpl::make_unique_impl<DragDropHelperPrivate>()} {}
182 181
183 182 DragDropHelper::~DragDropHelper()
184 183 {
@@ -188,6 +187,7 DragDropHelper::~DragDropHelper()
188 187 void DragDropHelper::resetDragAndDrop()
189 188 {
190 189 setCurrentDragWidget(nullptr);
190 impl->m_HighlightedDragWidget = nullptr;
191 191 }
192 192
193 193 void DragDropHelper::setCurrentDragWidget(VisualizationDragWidget *dragWidget)
@@ -245,6 +245,18 QUrl DragDropHelper::imageTemporaryUrl(const QImage &image) const
245 245 return QUrl::fromLocalFile(impl->m_ImageTempUrl);
246 246 }
247 247
248 void DragDropHelper::setHightlightedDragWidget(VisualizationDragWidget *dragWidget)
249 {
250 if (impl->m_HighlightedDragWidget) {
251 impl->m_HighlightedDragWidget->highlightForMerge(false);
252 }
253
254 if (dragWidget) {
255 impl->m_HighlightedDragWidget = dragWidget;
256 impl->m_HighlightedDragWidget->highlightForMerge(true);
257 }
258 }
259
248 260 bool DragDropHelper::checkMimeDataForVisualization(const QMimeData *mimeData,
249 261 VisualizationDragDropContainer *dropContainer)
250 262 {
@@ -294,12 +294,16 void VisualizationDragDropContainer::dragMoveEvent(QDragMoveEvent *event)
294 294 if (dropIndex != placeHolderIndex) {
295 295 helper.insertPlaceHolder(impl->m_Layout, dropIndex);
296 296 }
297
298 helper.setHightlightedDragWidget(nullptr);
297 299 }
298 300 else if (canMerge) {
299 301 // drop on the middle -> merge
300 302 if (impl->hasPlaceHolder()) {
301 303 helper.removePlaceHolder();
302 304 }
305
306 helper.setHightlightedDragWidget(dragWidgetHovered);
303 307 }
304 308 }
305 309 else {
@@ -344,6 +348,7 void VisualizationDragDropContainer::dropEvent(QDropEvent *event)
344 348 event->acceptProposedAction();
345 349
346 350 helper.removePlaceHolder();
351 helper.setHightlightedDragWidget(nullptr);
347 352
348 353 emit dropOccured(droppedIndex, event->mimeData());
349 354 }
@@ -351,7 +356,8 void VisualizationDragDropContainer::dropEvent(QDropEvent *event)
351 356 qCWarning(LOG_VisualizationDragDropContainer())
352 357 << tr("VisualizationDragDropContainer::dropEvent, couldn't drop because the "
353 358 "placeHolder is not found.");
354 Q_ASSERT(false);
359 sqpApp->dragDropHelper().setHightlightedDragWidget(nullptr);
360 // Q_ASSERT(false);
355 361 }
356 362 }
357 363 else {
@@ -73,8 +73,9 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget
73 73 &VisualizationGraphWidget::onMouseRelease);
74 74 connect(ui->widget, &QCustomPlot::mouseMove, this, &VisualizationGraphWidget::onMouseMove);
75 75 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
76 connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>(
77 &QCPAxis::rangeChanged),
76 connect(
77 ui->widget->xAxis,
78 static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>(&QCPAxis::rangeChanged),
78 79 this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection);
79 80
80 81 // Activates menu when right clicking on the graph
@@ -243,6 +244,16 bool VisualizationGraphWidget::isDragAllowed() const
243 244 return true;
244 245 }
245 246
247 void VisualizationGraphWidget::highlightForMerge(bool highlighted)
248 {
249 if (highlighted) {
250 plot().setBackground(QBrush(QColor("#BBD5EE")));
251 }
252 else {
253 plot().setBackground(QBrush(Qt::white));
254 }
255 }
256
246 257 void VisualizationGraphWidget::closeEvent(QCloseEvent *event)
247 258 {
248 259 Q_UNUSED(event);
@@ -290,9 +301,9 void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept
290 301
291 302 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2)
292 303 {
293 qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: VisualizationGraphWidget::onRangeChanged")
294 << QThread::currentThread()->objectName() << "DoAcqui"
295 << impl->m_DoAcquisition;
304 qCDebug(LOG_VisualizationGraphWidget())
305 << tr("TORM: VisualizationGraphWidget::onRangeChanged")
306 << QThread::currentThread()->objectName() << "DoAcqui" << impl->m_DoAcquisition;
296 307
297 308 auto graphRange = SqpRange{t1.lower, t1.upper};
298 309 auto oldGraphRange = SqpRange{t2.lower, t2.upper};
General Comments 0
You need to be logged in to leave comments. Login now