summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--muse/awl/aslider.cpp9
-rw-r--r--muse/awl/aslider.h1
-rw-r--r--muse/awl/awlplugin.cpp8
-rw-r--r--muse/awl/awlplugin.h14
-rw-r--r--muse/awl/drawbar.cpp128
-rw-r--r--muse/awl/drawbar.h54
-rw-r--r--muse/awl/slider.cpp13
-rw-r--r--muse/awl/slider.h1
8 files changed, 219 insertions, 9 deletions
diff --git a/muse/awl/aslider.cpp b/muse/awl/aslider.cpp
index 478390e3..fe2880d6 100644
--- a/muse/awl/aslider.cpp
+++ b/muse/awl/aslider.cpp
@@ -108,7 +108,7 @@ void AbstractSlider::setScaleValueColor(const QColor& c)
void AbstractSlider::wheelEvent(QWheelEvent* ev)
{
- int div = 50;
+ double div = 50.0;
if (ev->modifiers() & Qt::ShiftModifier)
div = 15;
_value += (ev->delta() * lineStep()) / div;
@@ -117,6 +117,7 @@ void AbstractSlider::wheelEvent(QWheelEvent* ev)
else if (_value > _maxValue)
_value = _maxValue;
valueChange();
+ update();
}
//---------------------------------------------------------
@@ -133,7 +134,7 @@ void AbstractSlider::keyPressEvent(QKeyEvent* ev)
case Qt::Key_Up:
case Qt::Key_Left: _value += lineStep(); break;
case Qt::Key_Down:
- case Qt::Key_Right: _value -= lineStep(); break;
+ case Qt::Key_Right: _value -= lineStep(); break;
case Qt::Key_PageDown: _value -= pageStep(); break;
case Qt::Key_PageUp: _value += pageStep(); break;
default:
@@ -143,8 +144,10 @@ void AbstractSlider::keyPressEvent(QKeyEvent* ev)
_value = _minValue;
else if (_value > _maxValue)
_value = _maxValue;
- if (oval != _value)
+ if (oval != _value) {
valueChange();
+ update();
+ }
}
//---------------------------------------------------------
diff --git a/muse/awl/aslider.h b/muse/awl/aslider.h
index 79c4b8bd..adc462b4 100644
--- a/muse/awl/aslider.h
+++ b/muse/awl/aslider.h
@@ -35,6 +35,7 @@ namespace Awl {
//---------------------------------------------------------
class AbstractSlider : public QWidget {
+
Q_OBJECT
Q_PROPERTY(double value READ value WRITE setValue)
Q_PROPERTY(bool center READ center WRITE setCenter)
diff --git a/muse/awl/awlplugin.cpp b/muse/awl/awlplugin.cpp
index df0769ed..43435f5e 100644
--- a/muse/awl/awlplugin.cpp
+++ b/muse/awl/awlplugin.cpp
@@ -31,6 +31,7 @@
#include "floatentry.h"
#include "panknob.h"
#include "midipanknob.h"
+#include "drawbar.h"
#include <QtCore/QtPlugin>
#include <QtDesigner/QDesignerCustomWidgetInterface>
@@ -91,6 +92,10 @@ QWidget* MidiPanKnobPlugin::createWidget(QWidget* parent)
{
return new Awl::MidiPanKnob(parent);
}
+QWidget* DrawbarPlugin::createWidget(QWidget* parent)
+ {
+ return new Awl::Drawbar(parent);
+ }
//---------------------------------------------------------
// customWidgets
@@ -113,7 +118,8 @@ QList<QDesignerCustomWidgetInterface*> AwlPlugins::customWidgets() const
<< new TempoLabelPlugin
<< new CheckBoxPlugin
<< new ComboBoxPlugin
- << new FloatEntryPlugin;
+ << new FloatEntryPlugin
+ << new DrawbarPlugin;
return plugins;
}
diff --git a/muse/awl/awlplugin.h b/muse/awl/awlplugin.h
index 8dcfb08e..79b180fd 100644
--- a/muse/awl/awlplugin.h
+++ b/muse/awl/awlplugin.h
@@ -244,6 +244,20 @@ class MidiPanKnobPlugin : public QObject, public AwlPlugin {
};
//---------------------------------------------------------
+// DrawbarPlugin
+//---------------------------------------------------------
+
+class DrawbarPlugin : public QObject, public AwlPlugin {
+ Q_OBJECT
+
+ public:
+ DrawbarPlugin(QObject* parent = 0) : QObject(parent) {}
+ QString includeFile() const { return "awl/drawbar.h"; }
+ QString name() const { return "Awl::Drawbar"; }
+ QWidget* createWidget(QWidget* parent);
+ };
+
+//---------------------------------------------------------
// AwlPlugins
//---------------------------------------------------------
diff --git a/muse/awl/drawbar.cpp b/muse/awl/drawbar.cpp
new file mode 100644
index 00000000..c24efc4e
--- /dev/null
+++ b/muse/awl/drawbar.cpp
@@ -0,0 +1,128 @@
+//=============================================================================
+// Awl
+// Audio Widget Library
+// $Id:$
+//
+// Copyright (C) 2007 by Werner Schweer and others
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+//=============================================================================
+
+#include "drawbar.h"
+
+namespace Awl {
+
+#if 0
+ }
+#endif
+
+//---------------------------------------------------------
+// Drawbar
+//---------------------------------------------------------
+
+Drawbar::Drawbar(QWidget* parent)
+ : Slider(parent)
+ {
+ _sliderColor = Qt::darkGray;
+ setOrientation(Qt::Vertical);
+ setInvertedAppearance(true);
+ setRange(0.0, 8.0);
+ setLineStep(1.0);
+ }
+
+Drawbar::~Drawbar()
+ {
+ }
+
+//---------------------------------------------------------
+// setSliderColor
+//---------------------------------------------------------
+
+void Drawbar::setSliderColor(const QColor& c)
+ {
+ if (c != _sliderColor) {
+ _sliderColor = c;
+ update();
+ }
+ }
+
+//---------------------------------------------------------
+// paint
+//---------------------------------------------------------
+
+void Drawbar::paintEvent(QPaintEvent*)
+ {
+ int h = height();
+ int w = width();
+
+ int kh = w * 2;
+ int kw = w;
+ int pixel = h - kh;
+ int ppos = pixel - int(pixel * _value / 8.0);
+
+ QPainter p(this);
+
+ QColor sc(Qt::darkGray);
+ QColor svc(Qt::gray);
+
+ p.setBrush(svc);
+
+ //---------------------------------------------------
+ // draw scale
+ //---------------------------------------------------
+
+ int sx = (w + 9) / 10;
+ int sw = w - 2 * sx;
+ p.fillRect(sx, 0, sw, ppos, sc);
+ QPen pen(Qt::white);
+ int lw = 2;
+ pen.setWidth(lw);
+ p.setPen(pen);
+ int sx1 = sx + lw/2;
+ p.drawLine(sx1, 0, sx1, ppos);
+ int sx2 = sx + sw - lw/2;
+ p.drawLine(sx2, 0, sx2, ppos);
+
+ //---------------------------------------------------
+ // draw numbers
+ //---------------------------------------------------
+
+ p.save();
+ p.setClipRect(QRect(sx, 0, sw, ppos));
+ QFont f = p.font();
+ f.setPixelSize(8);
+
+ int ch = pixel / 8;
+ QString num("%1");
+ for (int i = 1; i < 9; ++i) {
+ p.drawText(0, ch * (i-1) - (pixel - ppos), w, ch, Qt::AlignCenter, num.arg(9-i));
+ }
+ p.restore();
+
+ //---------------------------------------------------
+ // draw slider
+ //---------------------------------------------------
+
+ p.fillRect(0, ppos, kw, kh, _sliderColor);
+
+ pen.setWidth(1);
+ pen.setColor(Qt::black);
+ p.setPen(pen);
+
+ int y1 = ppos + kh / 5 * 2;
+ int y2 = ppos + kh / 5 * 3;
+ p.drawLine(0, y1, kw, y1);
+ p.drawLine(0, y2, kw, y2);
+ }
+}
+
diff --git a/muse/awl/drawbar.h b/muse/awl/drawbar.h
new file mode 100644
index 00000000..4794b784
--- /dev/null
+++ b/muse/awl/drawbar.h
@@ -0,0 +1,54 @@
+//=============================================================================
+// Awl
+// Audio Widget Library
+// $Id:$
+//
+// Copyright (C) 2007 by Werner Schweer and others
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+//=============================================================================
+
+#ifndef __AWLDRAWBAR_H__
+#define __AWLDRAWBAR_H__
+
+#include "slider.h"
+
+namespace Awl {
+
+//---------------------------------------------------------
+// Drawbar
+//---------------------------------------------------------
+
+class Drawbar : public Slider {
+ Q_OBJECT
+
+ Q_PROPERTY(QColor sliderColor READ sliderColor WRITE setSliderColor)
+
+ virtual void paintEvent(QPaintEvent*);
+
+ protected:
+ QColor _sliderColor;
+
+ public:
+ Drawbar(QWidget* parent = 0);
+ ~Drawbar();
+
+ //! return current slider color
+ QColor sliderColor() const { return _sliderColor; }
+ void setSliderColor(const QColor&);
+ };
+
+}
+
+#endif
+
diff --git a/muse/awl/slider.cpp b/muse/awl/slider.cpp
index 2505349d..48328a7b 100644
--- a/muse/awl/slider.cpp
+++ b/muse/awl/slider.cpp
@@ -171,13 +171,16 @@ void Slider::mouseMoveEvent(QMouseEvent* ev)
{
if (!dragMode)
return;
- int ppos;
- if (orient == Qt::Vertical)
- ppos = dragppos + (startDrag.y() - ev->y());
- else
- ppos = dragppos + (ev->x() - startDrag.x());
+ int delta = startDrag.y() - ev->y();
+
+ if (_invert)
+ delta = -delta;
+ if (orient == Qt::Horizontal)
+ delta = -delta;
+ int ppos = dragppos + delta;
if (ppos < 0)
ppos = 0;
+
int pixel = (orient == Qt::Vertical) ? height() - _sliderSize.height() : width() - _sliderSize.width();
if (ppos > pixel)
ppos = pixel;
diff --git a/muse/awl/slider.h b/muse/awl/slider.h
index 8d84849d..e8e38ba2 100644
--- a/muse/awl/slider.h
+++ b/muse/awl/slider.h
@@ -39,6 +39,7 @@ class Slider : public AbstractSlider {
Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
Q_PROPERTY(QSize sliderSize READ sliderSize WRITE setSliderSize)
+
Qt::Orientation orient;
QSize _sliderSize;