Mercurial > hg > svgui
changeset 808:40c6c9344ff6 warnfix_no_size_t
Merge from branch tony_integration
author | Chris Cannam |
---|---|
date | Wed, 18 Jun 2014 08:40:46 +0100 |
parents | e4773943c9c1 (current diff) 5c4a405a70fc (diff) |
children | 51da09385b38 c4ef666721bf |
files | layer/FlexiNoteLayer.cpp layer/FlexiNoteLayer.h view/Overview.cpp view/Pane.cpp view/Pane.h view/View.cpp view/View.h view/ViewManager.cpp |
diffstat | 9 files changed, 257 insertions(+), 111 deletions(-) [+] |
line wrap: on
line diff
--- a/layer/FlexiNoteLayer.cpp Tue Jun 17 15:55:27 2014 +0100 +++ b/layer/FlexiNoteLayer.cpp Wed Jun 18 08:40:46 2014 +0100 @@ -818,12 +818,12 @@ QPoint localPos; FlexiNoteModel::Point illuminatePoint(0); -// bool shouldIlluminate = false; + bool shouldIlluminate = false; -// if (v->shouldIlluminateLocalFeatures(this, localPos)) { -// shouldIlluminate = getPointToDrag(v, localPos.x(), localPos.y(), -// illuminatePoint); -// } + if (v->shouldIlluminateLocalFeatures(this, localPos)) { + shouldIlluminate = getPointToDrag(v, localPos.x(), localPos.y(), + illuminatePoint); + } paint.save(); paint.setRenderHint(QPainter::Antialiasing, false); @@ -847,28 +847,42 @@ paint.setPen(getBaseQColor()); paint.setBrush(brushColour); - // if (shouldIlluminate && - // // "illuminatePoint == p" - // !FlexiNoteModel::Point::Comparator()(illuminatePoint, p) && - // !FlexiNoteModel::Point::Comparator()(p, illuminatePoint)) { - // - // paint.setPen(v->getForeground()); - // paint.setBrush(v->getForeground()); - // - // QString vlabel = QString("%1%2").arg(p.value).arg(m_model->getScaleUnits()); - // v->drawVisibleText(paint, - // x - paint.fontMetrics().width(vlabel) - 2, - // y + paint.fontMetrics().height()/2 - // - paint.fontMetrics().descent(), - // vlabel, View::OutlinedText); - // - // QString hlabel = RealTime::frame2RealTime - // (p.frame, m_model->getSampleRate()).toText(true).c_str(); - // v->drawVisibleText(paint, - // x, - // y - h/2 - paint.fontMetrics().descent() - 2, - // hlabel, View::OutlinedText); - // } + if (shouldIlluminate && + // "illuminatePoint == p" + !FlexiNoteModel::Point::Comparator()(illuminatePoint, p) && + !FlexiNoteModel::Point::Comparator()(p, illuminatePoint)) { + + paint.drawLine(x, -1, x, v->height() + 1); + paint.drawLine(x+w, -1, x+w, v->height() + 1); + + paint.setPen(v->getForeground()); + // paint.setBrush(v->getForeground()); + + QString vlabel = QString("freq: %1%2").arg(p.value).arg(m_model->getScaleUnits()); + // v->drawVisibleText(paint, + // x - paint.fontMetrics().width(vlabel) - 2, + // y + paint.fontMetrics().height()/2 + // - paint.fontMetrics().descent(), + // vlabel, View::OutlinedText); + v->drawVisibleText(paint, + x, + y - h/2 - 2 - paint.fontMetrics().height() + - paint.fontMetrics().descent(), + vlabel, View::OutlinedText); + + QString hlabel = "dur: " + QString(RealTime::frame2RealTime + (p.duration, m_model->getSampleRate()).toText(true).c_str()); + v->drawVisibleText(paint, + x, + y - h/2 - paint.fontMetrics().descent() - 2, + hlabel, View::OutlinedText); + + QString llabel = QString("%1").arg(p.label); + v->drawVisibleText(paint, + x, + y + h + 2 + paint.fontMetrics().descent(), + llabel, View::OutlinedText); + } paint.drawRect(x, y - h/2, w, h); } @@ -1279,19 +1293,22 @@ int frame = v->getFrameForX(e->x()); float value = getValueForY(v, e->y()); + FlexiNoteModel::PointList noteList = m_model->getPoints(); + if (m_intelligentActions) { int smallestRightNeighbourFrame = 0; - for (FlexiNoteModel::PointList::const_iterator i = m_model->getPoints().begin(); - i != m_model->getPoints().end(); ++i) { + for (FlexiNoteModel::PointList::const_iterator i = noteList.begin(); + i != noteList.end(); ++i) { FlexiNote currentNote = *i; if (currentNote.frame > frame) { smallestRightNeighbourFrame = currentNote.frame; break; } } - - duration = std::min(smallestRightNeighbourFrame - frame + 1, duration); - duration = (duration > 0) ? duration : 0; + if (smallestRightNeighbourFrame > 0) { + duration = std::min(smallestRightNeighbourFrame - frame + 1, duration); + duration = (duration > 0) ? duration : 0; + } } if (!m_intelligentActions || @@ -1313,7 +1330,7 @@ for (int i = 0; i < v->getLayerCount(); ++i) { Layer *layer = v->getLayer(i); - if (layer && !layer->isLayerDormant(v) && + if (layer && layer->getLayerPresentationName() != "candidate") { cerr << "FlexiNoteLayer::getAssociatedPitchModel: looks like our layer is " << layer << endl; SparseTimeValueModel *model = qobject_cast<SparseTimeValueModel *> @@ -1474,7 +1491,7 @@ v->setCursor(Qt::ArrowCursor); - // std::cerr << "Mouse moved in edit mode over FlexiNoteLayer" << std::endl; + std::cerr << "Mouse moved in edit mode over FlexiNoteLayer" << std::endl; // v->setCursor(Qt::SizeHorCursor); } @@ -1638,6 +1655,31 @@ } void +FlexiNoteLayer::deleteSelectionInclusive(Selection s) +{ + if (!m_model) return; + + FlexiNoteModel::EditCommand *command = + new FlexiNoteModel::EditCommand(m_model, tr("Delete Selected Points")); + + FlexiNoteModel::PointList points = + m_model->getPoints(s.getStartFrame(), s.getEndFrame()); + + for (FlexiNoteModel::PointList::iterator i = points.begin(); + i != points.end(); ++i) { + bool overlap = !( + ((s.getStartFrame() <= i->frame) && (s.getEndFrame() <= i->frame)) || // selection is left of note + ((s.getStartFrame() >= (i->frame+i->duration)) && (s.getEndFrame() >= (i->frame+i->duration))) // selection is right of note + ); + if (overlap) { + command->deletePoint(*i); + } + } + + finish(command); +} + +void FlexiNoteLayer::copy(View *v, Selection s, Clipboard &to) { if (!m_model) return;
--- a/layer/FlexiNoteLayer.h Tue Jun 17 15:55:27 2014 +0100 +++ b/layer/FlexiNoteLayer.h Wed Jun 18 08:40:46 2014 +0100 @@ -73,6 +73,7 @@ virtual void moveSelection(Selection s, int newStartFrame); virtual void resizeSelection(Selection s, Selection newSize); virtual void deleteSelection(Selection s); + virtual void deleteSelectionInclusive(Selection s); virtual void copy(View *v, Selection s, Clipboard &to); virtual bool paste(View *v, const Clipboard &from, int frameOffset,
--- a/view/Pane.cpp Tue Jun 17 15:55:27 2014 +0100 +++ b/view/Pane.cpp Wed Jun 18 08:40:46 2014 +0100 @@ -41,6 +41,7 @@ #include <QCursor> #include <QTextStream> #include <QMimeData> +#include <QApplication> #include <iostream> #include <cmath> @@ -82,7 +83,9 @@ m_hthumb(0), m_vthumb(0), m_reset(0), - m_mouseInWidget(false) + m_mouseInWidget(false), + m_playbackFrameMoveScheduled(false), + m_playbackFrameMoveTo(0) { setObjectName("Pane"); setMouseTracking(true); @@ -1329,6 +1332,11 @@ m_dragStartMinValue = dmin; } + // Schedule a play-head move to the mouse frame location. This + // will happen only if nothing else of interest happens + // (double-click, drag) before the timeout. + schedulePlaybackFrameMove(getFrameForX(e->x())); + } else if (mode == ViewManager::SelectMode) { if (!hasTopLayerTimeXAxis()) return; @@ -1371,6 +1379,12 @@ } m_resizing = false; + + // Schedule a play-head move to the mouse frame + // location. This will happen only if nothing else of + // interest happens (double-click, drag) before the + // timeout. + schedulePlaybackFrameMove(mouseFrame); } update(); @@ -1414,6 +1428,24 @@ } void +Pane::schedulePlaybackFrameMove(int frame) +{ + m_playbackFrameMoveTo = frame; + m_playbackFrameMoveScheduled = true; + QTimer::singleShot(QApplication::doubleClickInterval() + 10, this, + SLOT(playbackScheduleTimerElapsed())); +} + +void +Pane::playbackScheduleTimerElapsed() +{ + if (m_playbackFrameMoveScheduled) { + m_manager->setPlaybackFrame(m_playbackFrameMoveTo); + m_playbackFrameMoveScheduled = false; + } +} + +void Pane::mouseReleaseEvent(QMouseEvent *e) { if (e->buttons() & Qt::RightButton) { @@ -1431,6 +1463,9 @@ mouseMoveEvent(e); } + int mouseFrame = e ? getFrameForX(e->x()) : 0; + if (mouseFrame < 0) mouseFrame = 0; + if (m_navigating || mode == ViewManager::NavigateMode) { m_navigating = false; @@ -1476,16 +1511,6 @@ m_manager->addSelection(selection); } } - else if (m_manager && !m_manager->haveInProgressSelection()) { - - //cerr << "JTEST: release without selection" << endl; - // Get frame location of mouse - int mouseFrame = getFrameForX(e->x()); - //cerr << "JTEST: frame location of click is " << mouseFrame << endl; - // Move play head to that frame location - int playbackFrame = fmax(0,mouseFrame); - m_manager->setPlaybackFrame(playbackFrame); - } update(); @@ -1588,7 +1613,8 @@ FlexiNoteLayer *layer = qobject_cast<FlexiNoteLayer *>(getTopFlexiNoteLayer()); if (layer) { layer->mouseMoveEvent(this, e); //!!! ew - return; + update(); + // return; } } @@ -1808,6 +1834,10 @@ update(); } + + if (m_dragMode != UnresolvedDrag) { + m_playbackFrameMoveScheduled = false; + } } void @@ -2078,6 +2108,10 @@ edgeScrollMaybe(e->x()); update(); + + if (min != max) { + m_playbackFrameMoveScheduled = false; + } } void @@ -2114,7 +2148,7 @@ return; } -// cerr << "mouseDoubleClickEvent" << endl; + cerr << "mouseDoubleClickEvent" << endl; m_clickPos = e->pos(); m_clickedInRange = true; @@ -2122,6 +2156,9 @@ m_ctrlPressed = (e->modifiers() & Qt::ControlModifier); m_altPressed = (e->modifiers() & Qt::AltModifier); + // cancel any pending move that came from a single click + m_playbackFrameMoveScheduled = false; + ViewManager::ToolMode mode = ViewManager::NavigateMode; if (m_manager) mode = m_manager->getToolModeFor(this);
--- a/view/Pane.h Tue Jun 17 15:55:27 2014 +0100 +++ b/view/Pane.h Wed Jun 18 08:40:46 2014 +0100 @@ -91,6 +91,9 @@ void mouseEnteredWidget(); void mouseLeftWidget(); +protected slots: + void playbackScheduleTimerElapsed(); + protected: virtual void paintEvent(QPaintEvent *e); virtual void mousePressEvent(QMouseEvent *e); @@ -139,6 +142,8 @@ Layer *getTopFlexiNoteLayer(); + void schedulePlaybackFrameMove(int frame); + bool m_identifyFeatures; QPoint m_identifyPoint; QPoint m_clickPos; @@ -184,6 +189,9 @@ bool m_mouseInWidget; + bool m_playbackFrameMoveScheduled; + int m_playbackFrameMoveTo; + static QCursor *m_measureCursor1; static QCursor *m_measureCursor2; };
--- a/view/View.cpp Tue Jun 17 15:55:27 2014 +0100 +++ b/view/View.cpp Wed Jun 18 08:40:46 2014 +0100 @@ -26,6 +26,8 @@ #include "data/model/PowerOfSqrtTwoZoomConstraint.h" #include "data/model/RangeSummarisableTimeValueModel.h" +#include "widgets/IconLoader.h" + #include <QPainter> #include <QPaintEvent> #include <QRect> @@ -34,6 +36,7 @@ #include <QTextStream> #include <QFont> #include <QMessageBox> +#include <QPushButton> #include <iostream> #include <cassert> @@ -53,6 +56,7 @@ m_followPan(true), m_followZoom(true), m_followPlay(PlaybackScrollPage), + m_followPlayIsDetached(false), m_playPointerFrame(0), m_showProgress(showProgress), m_cache(0), @@ -516,11 +520,6 @@ else return Qt::white; } -View::LayerProgressBar::LayerProgressBar(QWidget *parent) : - QProgressBar(parent) -{ -} - void View::addLayer(Layer *layer) { @@ -538,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(); @@ -551,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(); @@ -593,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); } @@ -992,6 +1001,12 @@ ((QApplication::mouseButtons() != Qt::NoButton) || (QApplication::keyboardModifiers() & Qt::AltModifier)); + bool pointerInVisibleArea = + long(m_playPointerFrame) >= getStartFrame() && + (m_playPointerFrame < getEndFrame() || + // include old pointer location so we know to refresh when moving out + oldPlayPointerFrame < getEndFrame()); + switch (m_followPlay) { case PlaybackScrollContinuous: @@ -1001,56 +1016,75 @@ break; case PlaybackScrollPage: - { - int xold = getXForFrame(oldPlayPointerFrame); - update(xold - 4, 0, 9, height()); - - int w = getEndFrame() - getStartFrame(); - w -= w/5; - int sf = (m_playPointerFrame / w) * w - w/8; - - if (m_manager && - m_manager->isPlaying() && - m_manager->getPlaySelectionMode()) { - MultiSelection::SelectionList selections = m_manager->getSelections(); - if (!selections.empty()) { - int selectionStart = selections.begin()->getStartFrame(); - if (sf < selectionStart - w / 10) { - sf = selectionStart - w / 10; - } - } - } + + if (!pointerInVisibleArea && somethingGoingOn) { + + m_followPlayIsDetached = true; + + } else if (!pointerInVisibleArea && m_followPlayIsDetached) { + + // do nothing; we aren't tracking until the pointer comes back in + + } else { + + int xold = getXForFrame(oldPlayPointerFrame); + update(xold - 4, 0, 9, height()); + + int w = getEndFrame() - getStartFrame(); + w -= w/5; + int sf = (m_playPointerFrame / w) * w - w/8; + + if (m_manager && + m_manager->isPlaying() && + m_manager->getPlaySelectionMode()) { + MultiSelection::SelectionList selections = m_manager->getSelections(); + if (!selections.empty()) { + int selectionStart = selections.begin()->getStartFrame(); + if (sf < selectionStart - w / 10) { + sf = selectionStart - w / 10; + } + } + } #ifdef DEBUG_VIEW_WIDGET_PAINT - cerr << "PlaybackScrollPage: f = " << m_playPointerFrame << ", sf = " << sf << ", start frame " - << getStartFrame() << endl; + cerr << "PlaybackScrollPage: f = " << m_playPointerFrame << ", sf = " << sf << ", start frame " + << getStartFrame() << endl; #endif - // We don't consider scrolling unless the pointer is outside - // the clearly visible range already - - int xnew = getXForFrame(m_playPointerFrame); + // We don't consider scrolling unless the pointer is outside + // the central visible range already + + int xnew = getXForFrame(m_playPointerFrame); #ifdef DEBUG_VIEW_WIDGET_PAINT - cerr << "xnew = " << xnew << ", width = " << width() << endl; + cerr << "xnew = " << xnew << ", width = " << width() << endl; #endif - if (xnew < width()/8 || xnew > (width()*7)/8) { - if (!somethingGoingOn) { - int offset = getFrameForX(width()/2) - getStartFrame(); - int newCentre = sf + offset; - bool changed = setCentreFrame(newCentre, false); - if (changed) { - xold = getXForFrame(oldPlayPointerFrame); - update(xold - 4, 0, 9, height()); - } - } - } - - update(xnew - 4, 0, 9, height()); - - break; - } + bool shouldScroll = (xnew > (width() * 7) / 8); + + if (!m_followPlayIsDetached && (xnew < width() / 8)) { + shouldScroll = true; + } + + if (xnew > width() / 8) { + m_followPlayIsDetached = false; + } else if (somethingGoingOn) { + m_followPlayIsDetached = true; + } + + if (!somethingGoingOn && shouldScroll) { + int offset = getFrameForX(width()/2) - getStartFrame(); + int newCentre = sf + offset; + bool changed = setCentreFrame(newCentre, false); + if (changed) { + xold = getXForFrame(oldPlayPointerFrame); + update(xold - 4, 0, 9, height()); + } + } + + update(xnew - 4, 0, 9, height()); + } + break; case PlaybackIgnore: if (m_playPointerFrame >= getStartFrame() && @@ -1434,6 +1468,25 @@ } void +View::cancelClicked() +{ + QPushButton *cancel = qobject_cast<QPushButton *>(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; @@ -1444,6 +1497,7 @@ i != m_progressBars.end(); ++i) { QProgressBar *pb = i->second.bar; + QPushButton *cancel = i->second.cancel; if (i->first == object) { @@ -1490,6 +1544,7 @@ if (completion >= 100) { pb->hide(); + cancel->hide(); timer->stop(); } else { @@ -1502,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(); @@ -1562,7 +1620,7 @@ View::paintEvent(QPaintEvent *e) { // Profiler prof("View::paintEvent", false); -// SVDEBUG << "View::paintEvent: centre frame is " << m_centreFrame << endl; +// cerr << "View::paintEvent: centre frame is " << m_centreFrame << endl; if (m_layers.empty()) { QFrame::paintEvent(e); @@ -1818,7 +1876,10 @@ showPlayPointer = false; } else if (m_manager && !m_manager->isPlaying()) { if (m_playPointerFrame == getCentreFrame() && + m_manager->shouldShowCentreLine() && m_followPlay != PlaybackIgnore) { + // Don't show the play pointer when it is redundant with + // the centre line showPlayPointer = false; } }
--- a/view/View.h Tue Jun 17 15:55:27 2014 +0100 +++ b/view/View.h Wed Jun 18 08:40:46 2014 +0100 @@ -29,6 +29,8 @@ class Layer; class ViewPropertyContainer; +class QPushButton; + #include <map> #include <set> @@ -309,6 +311,8 @@ virtual void overlayModeChanged(); virtual void zoomWheelsEnabledChanged(); + virtual void cancelClicked(); + virtual void progressCheckStalledTimerElapsed(); protected: @@ -352,7 +356,8 @@ bool m_followPan; bool m_followZoom; PlaybackFollowMode m_followPlay; - int m_playPointerFrame; + bool m_followPlayIsDetached; + int m_playPointerFrame; bool m_lightBackground; bool m_showProgress; @@ -372,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;
--- a/view/ViewManager.cpp Tue Jun 17 15:55:27 2014 +0100 +++ b/view/ViewManager.cpp Wed Jun 18 08:40:46 2014 +0100 @@ -554,7 +554,7 @@ if (v) emit viewCentreFrameChanged(v, f); } - if (!dynamic_cast<Overview *>(v) || (mode != PlaybackIgnore)) { + if (!dynamic_cast<Overview *>(v) || (mode == PlaybackScrollContinuous)) { if (m_mainModelSampleRate != 0) { emit activity(tr("Scroll to %1") .arg(RealTime::frame2RealTime @@ -562,7 +562,7 @@ } } - if (mode == PlaybackIgnore) { + if (mode != PlaybackScrollContinuous) { return; }
--- a/widgets/CommandHistory.cpp Tue Jun 17 15:55:27 2014 +0100 +++ b/widgets/CommandHistory.cpp Wed Jun 18 08:40:46 2014 +0100 @@ -37,7 +37,7 @@ #include <typeinfo> -#define DEBUG_COMMAND_HISTORY 1 +//#define DEBUG_COMMAND_HISTORY 1 CommandHistory *CommandHistory::m_instance = 0;
--- a/widgets/InteractiveFileFinder.cpp Tue Jun 17 15:55:27 2014 +0100 +++ b/widgets/InteractiveFileFinder.cpp Wed Jun 18 08:40:46 2014 +0100 @@ -217,7 +217,8 @@ } QString -InteractiveFileFinder::getSaveFileName(FileType type, QString fallbackLocation) +InteractiveFileFinder::getSaveFileName(FileType type, + QString fallbackLocation) { QString settingsKeyStub; QString lastPath = fallbackLocation; @@ -312,7 +313,6 @@ dialog.setNameFilters(filters); dialog.setWindowTitle(title); dialog.setDirectory(lastPath); - dialog.setAcceptMode(QFileDialog::AcceptSave); dialog.setFileMode(QFileDialog::AnyFile); dialog.setConfirmOverwrite(false); // we'll do that