changeset 190:53835534a9d3

* Allow user to activate a pane by clicking on the tab for its currently active layer. Formerly nothing happened if you clicked on the tab that was already topmost in a given property stack, because the tab widget only emitted a signal if the current tab changed. We want this to switch focus back to the pane if another one has been active in the mean time. * Make the thumbwheels look a bit round.
author Chris Cannam
date Mon, 22 Jan 2007 15:42:00 +0000
parents 5b7472db612b
children 3ed71a9d578b
files view/PaneStack.cpp view/PaneStack.h widgets/AudioDial.cpp widgets/NotifyingTabBar.cpp widgets/NotifyingTabBar.h widgets/PropertyBox.cpp widgets/PropertyStack.cpp widgets/PropertyStack.h widgets/Thumbwheel.cpp widgets/widgets.pro
diffstat 10 files changed, 194 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/view/PaneStack.cpp	Fri Jan 19 13:13:14 2007 +0000
+++ b/view/PaneStack.cpp	Mon Jan 22 15:42:00 2007 +0000
@@ -80,6 +80,8 @@
 	properties = new PropertyStack(frame, pane);
 	connect(properties, SIGNAL(propertyContainerSelected(View *, PropertyContainer *)),
 		this, SLOT(propertyContainerSelected(View *, PropertyContainer *)));
+        connect(properties, SIGNAL(viewSelected(View  *)),
+                this, SLOT(viewSelected(View *)));
         connect(properties, SIGNAL(contextHelpChanged(const QString &)),
                 this, SIGNAL(contextHelpChanged(const QString &)));
     }
@@ -381,6 +383,13 @@
 }
 
 void
+PaneStack::viewSelected(View *v)
+{
+    Pane *p = dynamic_cast<Pane *>(v);
+    if (p) setCurrentPane(p);
+}
+
+void
 PaneStack::paneInteractedWith()
 {
     Pane *pane = dynamic_cast<Pane *>(sender());
--- a/view/PaneStack.h	Fri Jan 19 13:13:14 2007 +0000
+++ b/view/PaneStack.h	Mon Jan 22 15:42:00 2007 +0000
@@ -74,6 +74,7 @@
     void propertyContainerAdded(PropertyContainer *);
     void propertyContainerRemoved(PropertyContainer *);
     void propertyContainerSelected(View *client, PropertyContainer *);
+    void viewSelected(View *v);
     void paneInteractedWith();
     void rightButtonMenuRequested(QPoint);
 
--- a/widgets/AudioDial.cpp	Fri Jan 19 13:13:14 2007 +0000
+++ b/widgets/AudioDial.cpp	Mon Jan 22 15:42:00 2007 +0000
@@ -341,12 +341,13 @@
 {
     if (m_rangeMapper) {
         int newPosition = m_rangeMapper->getPositionForValue(mappedValue);
+        bool changed = (m_mappedValue != mappedValue);
         m_mappedValue = mappedValue;
         m_noMappedUpdate = true;
         std::cerr << "AudioDial::setMappedValue(" << mappedValue << "): new position is " << newPosition << std::endl;
         if (newPosition != value()) {
             setValue(newPosition);
-        } else {
+        } else if (changed) {
             emit valueChanged(newPosition);
         }
         m_noMappedUpdate = false;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/widgets/NotifyingTabBar.cpp	Mon Jan 22 15:42:00 2007 +0000
@@ -0,0 +1,52 @@
+/* -*- 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 2007 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 "NotifyingTabBar.h"
+
+#include <iostream>
+
+NotifyingTabBar::NotifyingTabBar(QWidget *parent) :
+    QTabBar(parent)
+{
+}
+
+NotifyingTabBar::~NotifyingTabBar()
+{
+}
+
+void
+NotifyingTabBar::mousePressEvent(QMouseEvent *e)
+{
+    int i = currentIndex();
+    QTabBar::mousePressEvent(e);
+    if (currentIndex() == i) {
+        emit activeTabClicked();
+    }
+}
+
+void
+NotifyingTabBar::enterEvent(QEvent *e)
+{
+    QTabBar::enterEvent(e);
+    emit mouseEntered();
+}
+
+void
+NotifyingTabBar::leaveEvent(QEvent *e)
+{
+    QTabBar::enterEvent(e);
+    emit mouseLeft();
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/widgets/NotifyingTabBar.h	Mon Jan 22 15:42:00 2007 +0000
@@ -0,0 +1,40 @@
+/* -*- 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 2007 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 _NOTIFYING_TAB_BAR_H_
+#define _NOTIFYING_TAB_BAR_H_
+
+#include <QTabBar>
+
+class NotifyingTabBar : public QTabBar
+{
+    Q_OBJECT
+
+public:
+    NotifyingTabBar(QWidget *parent = 0);
+    virtual ~NotifyingTabBar();
+    
+signals:
+    void mouseEntered();
+    void mouseLeft();
+    void activeTabClicked();
+
+protected:
+    virtual void mousePressEvent(QMouseEvent *);
+    virtual void enterEvent(QEvent *);
+    virtual void leaveEvent(QEvent *);
+};
+
+#endif
--- a/widgets/PropertyBox.cpp	Fri Jan 19 13:13:14 2007 +0000
+++ b/widgets/PropertyBox.cpp	Mon Jan 22 15:42:00 2007 +0000
@@ -612,22 +612,22 @@
     if (!w) return;
     
     if (!m_container) return;
-    QString cname = m_container->objectName();
+    QString cname = m_container->getPropertyContainerName();
     if (cname == "") return;
 
     QString wname = w->objectName();
 
     if (w == m_showButton) {
-        emit contextHelpChanged(tr("Toggle Visibility of %1 layer").arg(cname));
+        emit contextHelpChanged(tr("Toggle Visibility of %1").arg(cname));
     } else if (w == m_playButton) {
-        emit contextHelpChanged(tr("Toggle Playback of %1 layer").arg(cname));
+        emit contextHelpChanged(tr("Toggle Playback of %1").arg(cname));
     } else if (wname == "") {
         return;
     } else if (dynamic_cast<NotifyingCheckBox *>(w)) {
-        emit contextHelpChanged(tr("Toggle %1 property of %2 layer")
+        emit contextHelpChanged(tr("Toggle %1 property of %2")
                                 .arg(wname).arg(cname));
     } else {
-        emit contextHelpChanged(tr("Adjust %1 property of %2 layer")
+        emit contextHelpChanged(tr("Adjust %1 property of %2")
                                 .arg(wname).arg(cname));
     }
 }
--- a/widgets/PropertyStack.cpp	Fri Jan 19 13:13:14 2007 +0000
+++ b/widgets/PropertyStack.cpp	Mon Jan 22 15:42:00 2007 +0000
@@ -18,6 +18,7 @@
 #include "base/PropertyContainer.h"
 #include "view/View.h"
 #include "layer/Layer.h"
+#include "widgets/NotifyingTabBar.h"
 
 #include <QIcon>
 #include <QTabWidget>
@@ -30,6 +31,15 @@
     QTabWidget(parent),
     m_client(client)
 {
+    NotifyingTabBar *bar = new NotifyingTabBar();
+    bar->setDrawBase(false);
+
+    connect(bar, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredTabBar()));
+    connect(bar, SIGNAL(mouseLeft()), this, SLOT(mouseLeftTabBar()));
+    connect(bar, SIGNAL(activeTabClicked()), this, SLOT(activeTabClicked()));
+
+    setTabBar(bar);
+
     repopulate();
 
     connect(this, SIGNAL(currentChanged(int)),
@@ -176,6 +186,24 @@
     emit propertyContainerSelected(m_client, m_boxes[n]->getContainer());
 }
 
+void
+PropertyStack::mouseEnteredTabBar()
+{
+    emit contextHelpChanged(tr("Click to change the current active layer"));
+}
+
+void
+PropertyStack::mouseLeftTabBar()
+{
+    emit contextHelpChanged("");
+}
+
+void
+PropertyStack::activeTabClicked()
+{
+    emit viewSelected(m_client);
+}
+
 #ifdef INCLUDE_MOCFILES
 #include "PropertyStack.moc.cpp"
 #endif
--- a/widgets/PropertyStack.h	Fri Jan 19 13:13:14 2007 +0000
+++ b/widgets/PropertyStack.h	Mon Jan 22 15:42:00 2007 +0000
@@ -37,6 +37,7 @@
     int getContainerIndex(PropertyContainer *container) const;
 
 signals:
+    void viewSelected(View *client);
     void propertyContainerSelected(View *client, PropertyContainer *container);
     void contextHelpChanged(const QString &);
 
@@ -48,6 +49,10 @@
 
     void showLayer(bool);
 
+    void mouseEnteredTabBar();
+    void mouseLeftTabBar();
+    void activeTabClicked();
+
 protected slots:
     void selectedContainerChanged(int);
 
--- a/widgets/Thumbwheel.cpp	Fri Jan 19 13:13:14 2007 +0000
+++ b/widgets/Thumbwheel.cpp	Mon Jan 22 15:42:00 2007 +0000
@@ -16,12 +16,14 @@
 #include "Thumbwheel.h"
 
 #include "base/RangeMapper.h"
+#include "base/Profiler.h"
 
 #include <QMouseEvent>
 #include <QPaintEvent>
 #include <QWheelEvent>
 #include <QInputDialog>
 #include <QPainter>
+#include <QPainterPath>
 
 #include <cmath>
 #include <iostream>
@@ -136,17 +138,22 @@
 {
     if (m_rangeMapper) {
         int newValue = m_rangeMapper->getPositionForValue(mappedValue);
+        bool changed = (m_mappedValue != mappedValue);
         m_mappedValue = mappedValue;
         m_noMappedUpdate = true;
         std::cerr << "Thumbwheel::setMappedValue(" << mappedValue << "): new value is " << newValue << std::endl;
         if (newValue != getValue()) {
             setValue(newValue);
+            changed = true;
         }
-        emit valueChanged(newValue);
+        if (changed) emit valueChanged(newValue);
         m_noMappedUpdate = false;
     } else {
-        setValue(int(mappedValue));
-        emit valueChanged(int(mappedValue));
+        int v = int(mappedValue);
+        if (v != getValue()) {
+            setValue(v);
+            emit valueChanged(v);
+        }
     }
 }
 
@@ -414,26 +421,61 @@
 void
 Thumbwheel::paintEvent(QPaintEvent *)
 {
+    Profiler profiler("Thumbwheel::paintEvent", true);
+
     QPainter paint(this);
     paint.fillRect(rect(), palette().background().color());
-    paint.setRenderHint(QPainter::Antialiasing, false);
+
+    paint.setRenderHint(QPainter::Antialiasing, true);
 
     int bw = 3;
 
-    for (int i = 0; i < bw; ++i) {
+    float w  = width();
+    float w0 = 0.5;
+    float w1 = w - 0.5;
+
+    float h  = height();
+    float h0 = 0.5;
+    float h1 = h - 0.5;
+
+    for (int i = bw-1; i >= 0; --i) {
+//    for (int i = 0; i < 1; ++i) {
+
         int grey = (i + 1) * (256 / (bw + 1));
         QColor fc = QColor(grey, grey, grey);
         paint.setPen(fc);
-        paint.drawRect(i, i, width() - i*2 - 1, height() - i*2 - 1);
+
+        QPainterPath path;
+
+        if (m_orientation == Qt::Horizontal) {
+            path.moveTo(w0 + i, h0 + i + 2);
+            path.quadTo(w/2, i * 1.25, w1 - i, h0 + i + 2);
+            path.lineTo(w1 - i, h1 - i - 2);
+            path.quadTo(w/2, h - i * 1.25, w0 + i, h1 - i - 2);
+            path.closeSubpath();
+        } else {
+            path.moveTo(w0 + i + 2, h0 + i);
+            path.quadTo(i * 1.25, h/2, w0 + i + 2, h1 - i);
+            path.lineTo(w1 - i - 2, h1 - i);
+            path.quadTo(w - i * 1.25, h/2, w1 - i - 2, h0 + i);
+            path.closeSubpath();
+        }
+
+        paint.drawPath(path);
     }
 
-    paint.setClipRect(QRect(bw, bw, width() - bw*2, height() - bw*2));
+
+    if (m_orientation == Qt::Horizontal) {
+        paint.setClipRect(QRect(bw, bw+1, width() - bw*2, height() - bw*2 - 2));
+    } else {
+        paint.setClipRect(QRect(bw+1, bw, width() - bw*2 - 2, height() - bw*2));
+    }
 
     float radians = m_rotation * 1.5f * M_PI;
 
 //    std::cerr << "value = " << m_value << ", min = " << m_min << ", max = " << m_max << ", rotation = " << rotation << std::endl;
 
-    int w = (m_orientation == Qt::Horizontal ? width() : height()) - bw*2;
+    w = (m_orientation == Qt::Horizontal ? width() : height()) - bw*2;
 
     // total number of notches on the entire wheel
     int notches = 25;
@@ -441,8 +483,6 @@
     // radius of the wheel including invisible part
     int radius = w / 2 + 2;
 
-    paint.setRenderHint(QPainter::Antialiasing, true);
-
     for (int i = 0; i < notches; ++i) {
 
         float a0 = (2.f * M_PI * i) / notches + radians;
--- a/widgets/widgets.pro	Fri Jan 19 13:13:14 2007 +0000
+++ b/widgets/widgets.pro	Mon Jan 22 15:42:00 2007 +0000
@@ -23,6 +23,7 @@
            NotifyingCheckBox.h \
            NotifyingComboBox.h \
            NotifyingPushButton.h \
+           NotifyingTabBar.h \
            Panner.h \
            PluginParameterBox.h \
            PluginParameterDialog.h \
@@ -42,6 +43,7 @@
            NotifyingCheckBox.cpp \
            NotifyingComboBox.cpp \
            NotifyingPushButton.cpp \
+           NotifyingTabBar.cpp \
            Panner.cpp \
            PluginParameterBox.cpp \
            PluginParameterDialog.cpp \