Mercurial > hg > svgui
comparison view/View.cpp @ 797:edada332c374 tonioni
Add an experimental cancel button to view progress bars
author | Chris Cannam |
---|---|
date | Fri, 13 Jun 2014 17:39:01 +0100 |
parents | b076cefaf708 |
children | 102ffad481e6 |
comparison
equal
deleted
inserted
replaced
795:54efa0a4f728 | 797:edada332c374 |
---|---|
24 #include "layer/TimeRulerLayer.h" | 24 #include "layer/TimeRulerLayer.h" |
25 #include "layer/SingleColourLayer.h" | 25 #include "layer/SingleColourLayer.h" |
26 #include "data/model/PowerOfSqrtTwoZoomConstraint.h" | 26 #include "data/model/PowerOfSqrtTwoZoomConstraint.h" |
27 #include "data/model/RangeSummarisableTimeValueModel.h" | 27 #include "data/model/RangeSummarisableTimeValueModel.h" |
28 | 28 |
29 #include "widgets/IconLoader.h" | |
30 | |
29 #include <QPainter> | 31 #include <QPainter> |
30 #include <QPaintEvent> | 32 #include <QPaintEvent> |
31 #include <QRect> | 33 #include <QRect> |
32 #include <QApplication> | 34 #include <QApplication> |
33 #include <QProgressDialog> | 35 #include <QProgressDialog> |
34 #include <QTextStream> | 36 #include <QTextStream> |
35 #include <QFont> | 37 #include <QFont> |
36 #include <QMessageBox> | 38 #include <QMessageBox> |
39 #include <QPushButton> | |
37 | 40 |
38 #include <iostream> | 41 #include <iostream> |
39 #include <cassert> | 42 #include <cassert> |
40 #include <cmath> | 43 #include <cmath> |
41 | 44 |
515 if (widgetLight != light) return widgetfg; | 518 if (widgetLight != light) return widgetfg; |
516 else if (light) return Qt::black; | 519 else if (light) return Qt::black; |
517 else return Qt::white; | 520 else return Qt::white; |
518 } | 521 } |
519 | 522 |
520 View::LayerProgressBar::LayerProgressBar(QWidget *parent) : | |
521 QProgressBar(parent) | |
522 { | |
523 } | |
524 | |
525 void | 523 void |
526 View::addLayer(Layer *layer) | 524 View::addLayer(Layer *layer) |
527 { | 525 { |
528 delete m_cache; | 526 delete m_cache; |
529 m_cache = 0; | 527 m_cache = 0; |
537 pb->setMinimum(0); | 535 pb->setMinimum(0); |
538 pb->setMaximum(0); | 536 pb->setMaximum(0); |
539 pb->setFixedWidth(80); | 537 pb->setFixedWidth(80); |
540 pb->setTextVisible(false); | 538 pb->setTextVisible(false); |
541 | 539 |
540 QPushButton *cancel = new QPushButton(this); | |
541 cancel->setIcon(IconLoader().load("fileclose")); | |
542 cancel->setFlat(true); | |
543 cancel->setFixedSize(QSize(20, 20)); | |
544 connect(cancel, SIGNAL(clicked()), this, SLOT(cancelClicked())); | |
545 | |
542 ProgressBarRec pbr; | 546 ProgressBarRec pbr; |
547 pbr.cancel = cancel; | |
543 pbr.bar = pb; | 548 pbr.bar = pb; |
544 pbr.lastCheck = 0; | 549 pbr.lastCheck = 0; |
545 pbr.checkTimer = new QTimer(); | 550 pbr.checkTimer = new QTimer(); |
546 connect(pbr.checkTimer, SIGNAL(timeout()), this, | 551 connect(pbr.checkTimer, SIGNAL(timeout()), this, |
547 SLOT(progressCheckStalledTimerElapsed())); | 552 SLOT(progressCheckStalledTimerElapsed())); |
549 m_progressBars[layer] = pbr; | 554 m_progressBars[layer] = pbr; |
550 | 555 |
551 QFont f(pb->font()); | 556 QFont f(pb->font()); |
552 int fs = Preferences::getInstance()->getViewFontSize(); | 557 int fs = Preferences::getInstance()->getViewFontSize(); |
553 f.setPointSize(std::min(fs, int(ceil(fs * 0.85)))); | 558 f.setPointSize(std::min(fs, int(ceil(fs * 0.85)))); |
559 | |
560 cancel->hide(); | |
554 | 561 |
555 pb->setFont(f); | 562 pb->setFont(f); |
556 pb->hide(); | 563 pb->hide(); |
557 | 564 |
558 connect(layer, SIGNAL(layerParametersChanged()), | 565 connect(layer, SIGNAL(layerParametersChanged()), |
592 for (LayerList::iterator i = m_layers.begin(); i != m_layers.end(); ++i) { | 599 for (LayerList::iterator i = m_layers.begin(); i != m_layers.end(); ++i) { |
593 if (*i == layer) { | 600 if (*i == layer) { |
594 m_layers.erase(i); | 601 m_layers.erase(i); |
595 if (m_progressBars.find(layer) != m_progressBars.end()) { | 602 if (m_progressBars.find(layer) != m_progressBars.end()) { |
596 delete m_progressBars[layer].bar; | 603 delete m_progressBars[layer].bar; |
604 delete m_progressBars[layer].cancel; | |
597 delete m_progressBars[layer].checkTimer; | 605 delete m_progressBars[layer].checkTimer; |
598 m_progressBars.erase(layer); | 606 m_progressBars.erase(layer); |
599 } | 607 } |
600 break; | 608 break; |
601 } | 609 } |
1458 setCentreFrame(m_centreFrame - delta, e); | 1466 setCentreFrame(m_centreFrame - delta, e); |
1459 } | 1467 } |
1460 } | 1468 } |
1461 | 1469 |
1462 void | 1470 void |
1463 View::checkProgress(void *object) | 1471 View::cancelClicked() |
1464 { | 1472 { |
1465 if (!m_showProgress) return; | 1473 QPushButton *cancel = qobject_cast<QPushButton *>(sender()); |
1466 | 1474 if (!cancel) return; |
1467 int ph = height(); | |
1468 | 1475 |
1469 for (ProgressMap::iterator i = m_progressBars.begin(); | 1476 for (ProgressMap::iterator i = m_progressBars.begin(); |
1470 i != m_progressBars.end(); ++i) { | 1477 i != m_progressBars.end(); ++i) { |
1471 | 1478 |
1479 if (i->second.cancel == cancel) { | |
1480 | |
1481 Layer *layer = i->first; | |
1482 Model *model = layer->getModel(); | |
1483 | |
1484 if (model) model->abandon(); | |
1485 } | |
1486 } | |
1487 } | |
1488 | |
1489 void | |
1490 View::checkProgress(void *object) | |
1491 { | |
1492 if (!m_showProgress) return; | |
1493 | |
1494 int ph = height(); | |
1495 | |
1496 for (ProgressMap::iterator i = m_progressBars.begin(); | |
1497 i != m_progressBars.end(); ++i) { | |
1498 | |
1472 QProgressBar *pb = i->second.bar; | 1499 QProgressBar *pb = i->second.bar; |
1500 QPushButton *cancel = i->second.cancel; | |
1473 | 1501 |
1474 if (i->first == object) { | 1502 if (i->first == object) { |
1475 | 1503 |
1476 // The timer is used to test for stalls. If the progress | 1504 // The timer is used to test for stalls. If the progress |
1477 // bar does not get updated for some length of time, the | 1505 // bar does not get updated for some length of time, the |
1514 } | 1542 } |
1515 | 1543 |
1516 if (completion >= 100) { | 1544 if (completion >= 100) { |
1517 | 1545 |
1518 pb->hide(); | 1546 pb->hide(); |
1547 cancel->hide(); | |
1519 timer->stop(); | 1548 timer->stop(); |
1520 | 1549 |
1521 } else { | 1550 } else { |
1522 | 1551 |
1523 // cerr << "progress = " << completion << endl; | 1552 // cerr << "progress = " << completion << endl; |
1526 i->second.lastCheck = 0; | 1555 i->second.lastCheck = 0; |
1527 timer->setInterval(2000); | 1556 timer->setInterval(2000); |
1528 timer->start(); | 1557 timer->start(); |
1529 } | 1558 } |
1530 | 1559 |
1560 cancel->move(0, ph - pb->height()/2 - 10); | |
1561 cancel->show(); | |
1562 | |
1531 pb->setValue(completion); | 1563 pb->setValue(completion); |
1532 pb->move(0, ph - pb->height()); | 1564 pb->move(20, ph - pb->height()); |
1533 | 1565 |
1534 pb->show(); | 1566 pb->show(); |
1535 pb->update(); | 1567 pb->update(); |
1536 | 1568 |
1537 ph -= pb->height(); | 1569 ph -= pb->height(); |