# HG changeset patch # User Chris Cannam # Date 1402677898 -3600 # Node ID 6eb0b20c940fe3475c3a847b10225ae720c7e958 # Parent edada332c374cbb70f2ec94b6abc7b0a3257ae2f# Parent 7717751f44070920714ed7885b409332556944db Merge diff -r 7717751f4407 -r 6eb0b20c940f view/View.cpp --- a/view/View.cpp Fri Jun 13 16:50:17 2014 +0100 +++ b/view/View.cpp Fri Jun 13 17:44:58 2014 +0100 @@ -26,6 +26,8 @@ #include "data/model/PowerOfSqrtTwoZoomConstraint.h" #include "data/model/RangeSummarisableTimeValueModel.h" +#include "widgets/IconLoader.h" + #include #include #include @@ -34,6 +36,7 @@ #include #include #include +#include #include #include @@ -517,11 +520,6 @@ else return Qt::white; } -View::LayerProgressBar::LayerProgressBar(QWidget *parent) : - QProgressBar(parent) -{ -} - void View::addLayer(Layer *layer) { @@ -539,7 +537,14 @@ pb->setFixedWidth(80); pb->setTextVisible(false); + QPushButton *cancel = new QPushButton(this); + cancel->setIcon(IconLoader().load("fileclose")); + cancel->setFlat(true); + cancel->setFixedSize(QSize(20, 20)); + connect(cancel, SIGNAL(clicked()), this, SLOT(cancelClicked())); + ProgressBarRec pbr; + pbr.cancel = cancel; pbr.bar = pb; pbr.lastCheck = 0; pbr.checkTimer = new QTimer(); @@ -552,6 +557,8 @@ int fs = Preferences::getInstance()->getViewFontSize(); f.setPointSize(std::min(fs, int(ceil(fs * 0.85)))); + cancel->hide(); + pb->setFont(f); pb->hide(); @@ -594,6 +601,7 @@ m_layers.erase(i); if (m_progressBars.find(layer) != m_progressBars.end()) { delete m_progressBars[layer].bar; + delete m_progressBars[layer].cancel; delete m_progressBars[layer].checkTimer; m_progressBars.erase(layer); } @@ -1460,6 +1468,25 @@ } void +View::cancelClicked() +{ + QPushButton *cancel = qobject_cast(sender()); + if (!cancel) return; + + for (ProgressMap::iterator i = m_progressBars.begin(); + i != m_progressBars.end(); ++i) { + + if (i->second.cancel == cancel) { + + Layer *layer = i->first; + Model *model = layer->getModel(); + + if (model) model->abandon(); + } + } +} + +void View::checkProgress(void *object) { if (!m_showProgress) return; @@ -1470,6 +1497,7 @@ i != m_progressBars.end(); ++i) { QProgressBar *pb = i->second.bar; + QPushButton *cancel = i->second.cancel; if (i->first == object) { @@ -1516,6 +1544,7 @@ if (completion >= 100) { pb->hide(); + cancel->hide(); timer->stop(); } else { @@ -1528,8 +1557,11 @@ timer->start(); } + cancel->move(0, ph - pb->height()/2 - 10); + cancel->show(); + pb->setValue(completion); - pb->move(0, ph - pb->height()); + pb->move(20, ph - pb->height()); pb->show(); pb->update(); diff -r 7717751f4407 -r 6eb0b20c940f view/View.h --- a/view/View.h Fri Jun 13 16:50:17 2014 +0100 +++ b/view/View.h Fri Jun 13 17:44:58 2014 +0100 @@ -29,6 +29,8 @@ class Layer; class ViewPropertyContainer; +class QPushButton; + #include #include @@ -309,6 +311,8 @@ virtual void overlayModeChanged(); virtual void zoomWheelsEnabledChanged(); + virtual void cancelClicked(); + virtual void progressCheckStalledTimerElapsed(); protected: @@ -373,16 +377,8 @@ mutable LayerList m_lastScrollableBackLayers; mutable LayerList m_lastNonScrollableBackLayers; - class LayerProgressBar : public QProgressBar { - public: - LayerProgressBar(QWidget *parent); - virtual QString text() const { return m_text; } - virtual void setText(QString text) { m_text = text; } - protected: - QString m_text; - }; - struct ProgressBarRec { + QPushButton *cancel; QProgressBar *bar; int lastCheck; QTimer *checkTimer;