changeset 867:99373ca20caf alignment_view

First sketch at alignment view (between panes in stack)
author Chris Cannam
date Fri, 17 Oct 2014 14:58:51 +0100
parents d854c72dcaa1
children 99299949f965
files svgui.pro view/AlignmentView.cpp view/AlignmentView.h view/PaneStack.cpp view/PaneStack.h view/View.h
diffstat 6 files changed, 254 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/svgui.pro	Fri Oct 03 15:27:02 2014 +0100
+++ b/svgui.pro	Fri Oct 17 14:58:51 2014 +0100
@@ -89,12 +89,14 @@
            layer/TimeValueLayer.cpp \
            layer/WaveformLayer.cpp
 
-HEADERS += view/Overview.h \
+HEADERS += view/AlignmentView.h \
+           view/Overview.h \
            view/Pane.h \
            view/PaneStack.h \
            view/View.h \
            view/ViewManager.h
-SOURCES += view/Overview.cpp \
+SOURCES += view/AlignmentView.cpp \
+           view/Overview.cpp \
            view/Pane.cpp \
            view/PaneStack.cpp \
            view/View.cpp \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/view/AlignmentView.cpp	Fri Oct 17 14:58:51 2014 +0100
@@ -0,0 +1,140 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+    Sonic Visualiser
+    An audio file viewer and annotation editor.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2006-2014 Chris Cannam and QMUL.
+    
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.  See the file
+    COPYING included with this distribution for more information.
+*/
+
+#include "AlignmentView.h"
+
+#include <QPainter>
+
+using std::vector;
+
+AlignmentView::AlignmentView(QWidget *w) :
+    View(w, false),
+    m_above(0),
+    m_below(0)
+{
+    setObjectName(tr("AlignmentView"));
+}
+
+void
+AlignmentView::globalCentreFrameChanged(int f)
+{
+    View::globalCentreFrameChanged(f);
+    update();
+}
+
+void
+AlignmentView::viewCentreFrameChanged(View *v, int f)
+{
+    View::viewCentreFrameChanged(v, f);
+    if (v == m_above) {
+	m_centreFrame = f;
+	update();
+    } else if (v == m_below) {
+	update();
+    }
+}
+
+void
+AlignmentView::viewManagerPlaybackFrameChanged(int)
+{
+    update();
+}
+
+void
+AlignmentView::viewAboveZoomLevelChanged(int level, bool)
+{
+    m_zoomLevel = level;
+    update();
+}
+
+void
+AlignmentView::viewBelowZoomLevelChanged(int, bool)
+{
+    update();
+}
+
+void
+AlignmentView::setViewAbove(View *v)
+{
+    if (m_above) {
+	disconnect(m_above, 0, this, 0);
+    }
+
+    m_above = v;
+
+    if (m_above) {
+	connect(m_above,
+		SIGNAL(zoomLevelChanged(int, bool)),
+		this, 
+		SLOT(viewAboveZoomLevelChanged(int, bool)));
+    }
+}
+
+void
+AlignmentView::setViewBelow(View *v)
+{
+    if (m_below) {
+	disconnect(m_below, 0, this, 0);
+    }
+
+    m_below = v;
+
+    if (m_below) {
+	connect(m_below,
+		SIGNAL(zoomLevelChanged(int, bool)),
+		this, 
+		SLOT(viewBelowZoomLevelChanged(int, bool)));
+    }
+}
+
+void
+AlignmentView::paintEvent(QPaintEvent *)
+{
+    if (m_above == 0 || m_below == 0 || !m_manager) return;
+
+    int rate = m_manager->getMainModelSampleRate();
+    if (rate == 0) return;
+
+    bool darkPalette = false;
+    if (m_manager) darkPalette = m_manager->getGlobalDarkBackground();
+
+    QColor fg = Qt::black, bg = Qt::white;
+    if (darkPalette) std::swap(fg, bg);
+
+    QPainter paint(this);
+    paint.setPen(QPen(fg, 2));
+    paint.setBrush(Qt::NoBrush);
+    paint.setRenderHint(QPainter::Antialiasing, true);
+
+    paint.fillRect(rect(), bg);
+
+    vector<int> keyFrames;
+    for (int f = m_above->getModelsStartFrame(); 
+	 f <= m_above->getModelsEndFrame(); 
+	 f += rate * 5) {
+	keyFrames.push_back(f);
+    }
+
+    foreach (int f, keyFrames) {
+	int af = m_above->alignFromReference(f);
+	int ax = m_above->getXForFrame(af);
+	int bf = m_below->alignFromReference(f);
+	int bx = m_below->getXForFrame(bf);
+	paint.drawLine(ax, 0, bx, height());
+    }
+
+    paint.end();
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/view/AlignmentView.h	Fri Oct 17 14:58:51 2014 +0100
@@ -0,0 +1,47 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+    Sonic Visualiser
+    An audio file viewer and annotation editor.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2006-2014 Chris Cannam and QMUL.
+    
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.  See the file
+    COPYING included with this distribution for more information.
+*/
+
+#ifndef ALIGNMENT_VIEW_H
+#define ALIGNMENT_VIEW_H
+
+#include "View.h"
+
+class AlignmentView : public View
+{
+    Q_OBJECT
+
+public:
+    AlignmentView(QWidget *parent = 0);
+    virtual QString getPropertyContainerIconName() const { return "alignment"; }
+    
+    void setViewAbove(View *view);
+    void setViewBelow(View *view);
+
+public slots:
+    virtual void globalCentreFrameChanged(int);
+    virtual void viewCentreFrameChanged(View *, int);
+    virtual void viewAboveZoomLevelChanged(int, bool);
+    virtual void viewBelowZoomLevelChanged(int, bool);
+    virtual void viewManagerPlaybackFrameChanged(int);
+
+protected:
+    virtual void paintEvent(QPaintEvent *e);
+    virtual bool shouldLabelSelections() const { return false; }
+
+    View *m_above;
+    View *m_below;
+};
+
+#endif
--- a/view/PaneStack.cpp	Fri Oct 03 15:27:02 2014 +0100
+++ b/view/PaneStack.cpp	Fri Oct 17 14:58:51 2014 +0100
@@ -21,6 +21,7 @@
 #include "widgets/ClickableLabel.h"
 #include "layer/Layer.h"
 #include "ViewManager.h"
+#include "AlignmentView.h"
 
 #include <QApplication>
 #include <QHBoxLayout>
@@ -40,6 +41,7 @@
     QFrame(parent),
     m_currentPane(0),
     m_showAccessories(true),
+    m_showAlignmentViews(false),
     m_splitter(new QSplitter),
     m_propertyStackStack(new QStackedWidget),
     m_viewManager(viewManager),
@@ -67,6 +69,15 @@
     m_showAccessories = show;
 }
 
+void
+PaneStack::setShowAlignmentViews(bool show)
+{
+    m_showAlignmentViews = show;
+    foreach (const PaneRec &r, m_panes) {
+        r.alignmentView->setVisible(m_showAlignmentViews);
+    }
+}
+
 Pane *
 PaneStack::addPane(bool suppressPropertyBox)
 {
@@ -112,6 +123,12 @@
     layout->addWidget(pane, 0, 1, 2, 1);
     layout->setColumnStretch(1, 20);
 
+    AlignmentView *av = new AlignmentView(frame);
+    av->setFixedHeight(40);//!!!
+    av->setVisible(m_showAlignmentViews);
+    av->setViewManager(m_viewManager);
+    layout->addWidget(av, 2, 1);
+
     QWidget *properties = 0;
     if (suppressPropertyBox) {
 	properties = new QFrame();
@@ -139,6 +156,7 @@
     rec.currentIndicator = currentIndicator;
     rec.frame = frame;
     rec.layout = layout;
+    rec.alignmentView = av;
     m_panes.push_back(rec);
 
     frame->setLayout(layout);
@@ -167,11 +185,34 @@
     }
 
     showOrHidePaneAccessories();
+    relinkAlignmentViews();
 
     return pane;
 }
 
 void
+PaneStack::relinkAlignmentViews()
+{
+    for (int i = 0; i < (int)m_panes.size(); ++i) {
+        m_panes[i].alignmentView->setViewAbove(m_panes[i].pane);
+        if (i + 1 < (int)m_panes.size()) {
+            m_panes[i].alignmentView->setViewBelow(m_panes[i+1].pane);
+        } else {
+            m_panes[i].alignmentView->setViewBelow(0);
+        }
+    }
+}
+
+void
+PaneStack::unlinkAlignmentViews()
+{
+    for (int i = 0; i < (int)m_panes.size(); ++i) {
+        m_panes[i].alignmentView->setViewAbove(0);
+        m_panes[i].alignmentView->setViewBelow(0);
+    }
+}
+
+void
 PaneStack::setPropertyStackMinWidth(int mw)
 {
     for (std::vector<PaneRec>::iterator i = m_panes.begin();
@@ -279,6 +320,7 @@
     }
 
     emit paneAboutToBeDeleted(pane);
+    unlinkAlignmentViews();
 
     cerr << "PaneStack::deletePane: about to delete parent " << pane->parent() << " of pane " << pane << endl;
 
@@ -303,6 +345,7 @@
     }
 
     showOrHidePaneAccessories();
+    relinkAlignmentViews();
 
     emit paneDeleted();
 }
@@ -362,6 +405,8 @@
 	++i;
     }
 
+    relinkAlignmentViews();
+
     cerr << "WARNING: PaneStack::hidePane(" << pane << "): Pane not found in visible panes" << endl;
 }
 
@@ -386,6 +431,8 @@
 	++i;
     }
 
+    relinkAlignmentViews();
+
     cerr << "WARNING: PaneStack::showPane(" << pane << "): Pane not found in hidden panes" << endl;
 }
 
--- a/view/PaneStack.h	Fri Oct 03 15:27:02 2014 +0100
+++ b/view/PaneStack.h	Fri Oct 17 14:58:51 2014 +0100
@@ -32,6 +32,7 @@
 class ViewManager;
 class PropertyContainer;
 class PropertyStack;
+class AlignmentView;
 
 class PaneStack : public QFrame
 {
@@ -71,6 +72,8 @@
     
     void setShowPaneAccessories(bool show); // current indicator, close button
 
+    void setShowAlignmentViews(bool show);
+
     void sizePanesEqually();
 
 signals:
@@ -112,18 +115,20 @@
 
     struct PaneRec
     {
-	Pane        *pane;
-	QWidget     *propertyStack;
-        QPushButton *xButton;
-	QLabel      *currentIndicator;
-        QFrame      *frame;
-        QGridLayout *layout;
+	Pane          *pane;
+	QWidget       *propertyStack;
+        QPushButton   *xButton;
+	QLabel        *currentIndicator;
+        QFrame        *frame;
+        QGridLayout   *layout;
+        AlignmentView *alignmentView;
     };
 
     std::vector<PaneRec> m_panes;
     std::vector<PaneRec> m_hiddenPanes;
 
     bool m_showAccessories;
+    bool m_showAlignmentViews;
 
     QSplitter *m_splitter;
     QStackedWidget *m_propertyStackStack;
@@ -134,6 +139,9 @@
 
     void showOrHidePaneAccessories();
 
+    void unlinkAlignmentViews();
+    void relinkAlignmentViews();
+
     LayoutStyle m_layoutStyle;
 };
 
--- a/view/View.h	Fri Oct 03 15:27:02 2014 +0100
+++ b/view/View.h	Fri Oct 17 14:58:51 2014 +0100
@@ -338,7 +338,7 @@
                             bool globalScroll,
                             PlaybackFollowMode followMode);
 
-    void zoomLevelChanged(int, bool);
+    void zoomLevelChanged(int level, bool locked);
 
     void contextHelpChanged(const QString &);
 
@@ -405,7 +405,7 @@
     void checkProgress(void *object);
     int getProgressBarWidth() const; // if visible
 
-    int              m_centreFrame;
+    int                 m_centreFrame;
     int                 m_zoomLevel;
     bool                m_followPan;
     bool                m_followZoom;