Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update CrEchoView to use QT4 QFrame and use the paintEvent for painting

the canvas.
  • Loading branch information...
commit 2fe1d5c1fef3ec8cbd80b234519571c85f5ca5c9 1 parent 2691560
@laudrup authored
View
8 creox/effects_gui/crecho.cpp
@@ -99,10 +99,10 @@ CrEcho::CrEcho(QWidget *parent, const char *name )
(void)m_voiceArray->addSlider(i18n("Delay"), i18n("ms"), delayValid, &m_epar->parallelEcho[m_visibleVoice].delay, true, true);
(void)m_voiceArray->addSlider(i18n("Decay"), "%", mixValid, &m_epar->parallelEcho[m_visibleVoice].decay, true, true);
(void)m_voiceArray->addSlider(i18n("Feedback"), "%", mixValid, &m_epar->parallelEcho[m_visibleVoice].feedback);
- connect(m_voiceArray->getSliderEntry(0), SIGNAL(valueChanged(float)), m_echoTapsView, SLOT(slotUpdateSelectedTap()));
- connect(m_voiceArray->getSliderEntry(1), SIGNAL(valueChanged(float)), m_echoTapsView, SLOT(slotUpdateSelectedTap()));
- connect(m_finalEchoArray->getSliderEntry(0), SIGNAL(valueChanged(float)), m_echoTapsView, SLOT(slotUpdateFinalTap()));
- connect(m_finalEchoArray->getSliderEntry(1), SIGNAL(valueChanged(float)), m_echoTapsView, SLOT(slotUpdateFinalTap()));
+ connect(m_voiceArray->getSliderEntry(0), SIGNAL(valueChanged(float)), m_echoTapsView, SLOT(update()));
+ connect(m_voiceArray->getSliderEntry(1), SIGNAL(valueChanged(float)), m_echoTapsView, SLOT(update()));
+ connect(m_finalEchoArray->getSliderEntry(0), SIGNAL(valueChanged(float)), m_echoTapsView, SLOT(update()));
+ connect(m_finalEchoArray->getSliderEntry(1), SIGNAL(valueChanged(float)), m_echoTapsView, SLOT(update()));
updateVoicesListBox();
m_voicesListBox->setFixedWidth(m_voicesListBox->sizeHint().width());
View
226 creox/effects_gui/crechotapsview.cpp
@@ -16,90 +16,84 @@
* *
***************************************************************************/
-
-#include <cassert>
-#include <cstring>
-#include <iostream>
#include <QPainter>
#include <QPalette>
#include <QPen>
#include <QColor>
#include <QMatrix>
-#include <qfont.h>
+#include <QFont>
#include <QFontMetrics>
#include <QApplication>
-//Added by qt3to4:
-#include <Q3Frame>
+
+#include <cstring>
+
#include "crechotapsview.h"
+
#define WIDGET_HEIGHT (180)
CrEchoTapsView::CrEchoTapsView(const EchoParameters* epar, const int selectedEchoTap,
QWidget *parent, const char *name )
- : Q3Frame(parent,name), m_epar(epar), m_selectedEchoTap(selectedEchoTap)
+ : QFrame(parent,name), m_epar(epar), m_selectedEchoTap(selectedEchoTap)
{
(void)std::memcpy(&m_parallelEcho,
- reinterpret_cast<void*>(
- const_cast<EchoParameters::ParallelEcho(*)[10]>(&m_epar->parallelEcho)),
+ reinterpret_cast<void*>(const_cast<EchoParameters::ParallelEcho(*)[10]>
+ (&m_epar->parallelEcho)),
sizeof(EchoParameters::ParallelEcho) * 10);
m_finalFeedback = m_epar->finalFeedback;
m_finalDelay = m_epar->finalDelay;
setBackgroundColor(Qt::black);
- //setBackgroundMode(QWidget::FixedColor);
- setFrameStyle(Q3Frame::Box | Q3Frame::Raised);
+ setFrameStyle(QFrame::Box | QFrame::Raised);
setLineWidth(1);
setMidLineWidth(1);
- setMargin(0);
}
CrEchoTapsView::~CrEchoTapsView()
{
-#ifdef _DEBUG
- std::cerr << "CrEchoTapsView deleted...\n";
-#endif
}
-void CrEchoTapsView::drawContents(QPainter* painter)
+void CrEchoTapsView::paintEvent(QPaintEvent*)
{
//draw grid
- painter->save();
+ QPainter painter(this);
+ painter.save();
transformPainter(painter);
drawGrid(painter);
redrawAllTaps(painter);
- painter->restore();
+ painter.restore();
}
-void CrEchoTapsView::transformPainter(QPainter* painter)
+void CrEchoTapsView::transformPainter(QPainter& painter)
{
- painter->setWindow(-20, -10, 1040, 120);
+ painter.setWindow(-20, -10, 1040, 120);
const QMatrix matrix(1, 0, 0, -1, 0, 100);
- painter->setWorldMatrix(matrix);
+ painter.setWorldMatrix(matrix);
}
-void CrEchoTapsView::drawGrid(QPainter* painter)
+void CrEchoTapsView::drawGrid(QPainter& painter)
{
- painter->setPen(QPen(QColor(100, 100, 100), 0, Qt::SolidLine));
+ painter.setPen(QPen(QColor(100, 100, 100), 0, Qt::SolidLine));
for (int count = 10; count <= 100; count += 10)
{
- painter->drawLine(0, count, 1000, count);
+ painter.drawLine(0, count, 1000, count);
}
for (int count = 0; count <= 1000; count += 100)
{
- painter->drawLine(count, 0, count, 100);
+ painter.drawLine(count, 0, count, 100);
}
- painter->setPen(Qt::gray);
- painter->drawLine(0, 0, 1000, 0);
+ painter.setPen(Qt::gray);
+ painter.drawLine(0, 0, 1000, 0);
//draw circle
- const QPoint circlePos = painter->xForm(QPoint(0, 0));
- painter->save();
- painter->resetXForm();
- painter->setBrush(Qt::yellow);
- painter->drawRect(circlePos.x() - 3, circlePos.y() - 3, 6, 6);
- painter->restore();
+ const QPoint circlePos = painter.xForm(QPoint(0, 0));
+ painter.save();
+ painter.resetXForm();
+ painter.setBrush(Qt::yellow);
+ painter.drawRect(circlePos.x() - 3, circlePos.y() - 3, 6, 6);
+ painter.restore();
}
void CrEchoTapsView::drawEchoTap(const float delay, const float decay, const TapType type,
- QPainter* painter) const
+ QPainter& painter) const
{
QPen pen;
switch(type)
@@ -122,69 +116,63 @@ void CrEchoTapsView::drawEchoTap(const float delay, const float decay, const Tap
pen.setWidth(2);
break;
default:
- assert(0);
+ abort();
}
- painter->setPen(pen);
+ painter.setPen(pen);
const int delay_i = roundToInt(delay);
const int decay_i = roundToInt(decay);
- if (type != tap_final)
- {
- painter->drawLine(0, 0, 0, decay_i);
- }
- painter->drawLine(0, decay_i, delay_i, decay_i);
- painter->drawLine(delay_i, decay_i, delay_i, 0);
+ if (type != tap_final) {
+ painter.drawLine(0, 0, 0, decay_i);
+ }
+ painter.drawLine(0, decay_i, delay_i, decay_i);
+ painter.drawLine(delay_i, decay_i, delay_i, 0);
//draw text
- if (type == tap_selected || type == tap_deleted)
- {
- const QPoint delayPos = painter->xForm(QPoint(delay_i, 0));
- const QPoint decayPos = painter->xForm(QPoint(delay_i, decay_i));
- painter->save();
- painter->resetXForm();
- QFont sfont(font());
- //!! not good for all displays !!
- //sfont.setPixelSize(5);
- sfont.setPointSize(8);
- painter->setFont(sfont);
- painter->setClipRect(contentsRect());
- if (type == tap_deleted)
- {
- const QFontMetrics fm(sfont);
-
- const int msWidth = fm.width(QString("%1 ms").arg(delay, 0, 'f', 2));
- painter->fillRect(delayPos.x() - 17, delayPos.y() - fm.height() + 9,
- msWidth + 10, fm.height() + 4, Qt::black);
-
- const int percWidth = fm.width(QString("%1 %").arg(decay, 0, 'f', 2));
- painter->fillRect(decayPos.x() - 17, decayPos.y() - fm.height() - 3,
- percWidth + 10, fm.height() + 4, Qt::black);
- }
- else
- {
- painter->drawText(delayPos.x() - 12, delayPos.y() + 9,
- QString("%1 ms").arg(delay, 0, 'f', 2));
- painter->drawText(decayPos.x() - 12, decayPos.y() - 3,
- QString("%1 %").arg(decay, 0, 'f', 2));
- }
- painter->restore();
+ if (type == tap_selected || type == tap_deleted) {
+ const QPoint delayPos = painter.xForm(QPoint(delay_i, 0));
+ const QPoint decayPos = painter.xForm(QPoint(delay_i, decay_i));
+ painter.save();
+ painter.resetXForm();
+ QFont sfont(font());
+ //!! not good for all displays !!
+ //sfont.setPixelSize(5);
+ sfont.setPointSize(8);
+ painter.setFont(sfont);
+ painter.setClipRect(contentsRect());
+ if (type == tap_deleted) {
+ const QFontMetrics fm(sfont);
+
+ const int msWidth = fm.width(QString("%1 ms").arg(delay, 0, 'f', 2));
+ painter.fillRect(delayPos.x() - 17, delayPos.y() - fm.height() + 9,
+ msWidth + 10, fm.height() + 4, Qt::black);
+
+ const int percWidth = fm.width(QString("%1 %").arg(decay, 0, 'f', 2));
+ painter.fillRect(decayPos.x() - 17, decayPos.y() - fm.height() - 3,
+ percWidth + 10, fm.height() + 4, Qt::black);
+ } else {
+ painter.drawText(delayPos.x() - 12, delayPos.y() + 9,
+ QString("%1 ms").arg(delay, 0, 'f', 2));
+ painter.drawText(decayPos.x() - 12, decayPos.y() - 3,
+ QString("%1 %").arg(decay, 0, 'f', 2));
}
+ painter.restore();
+ }
//draw arrow
- const QPoint arrowPos = painter->xForm(QPoint(delay_i, 0));
- painter->save();
- painter->resetXForm();
- if (type == tap_final || type == tap_finalDeleted)
- {
- pen.setWidth(0);
- painter->setPen(pen);
- }
+ const QPoint arrowPos = painter.xForm(QPoint(delay_i, 0));
+ painter.save();
+ painter.resetXForm();
+ if (type == tap_final || type == tap_finalDeleted) {
+ pen.setWidth(0);
+ painter.setPen(pen);
+ }
QPainterPath path;
path.moveTo(arrowPos);
path.lineTo(arrowPos.x() - 2, arrowPos.y() - 2);
path.lineTo(arrowPos.x() + 2, arrowPos.y() - 2);
path.lineTo(arrowPos);
- painter->drawPath(path);
+ painter.drawPath(path);
- painter->restore();
+ painter.restore();
}
QSize CrEchoTapsView::sizeHint() const
@@ -192,71 +180,33 @@ QSize CrEchoTapsView::sizeHint() const
return QSize(300, WIDGET_HEIGHT);
}
-void CrEchoTapsView::redrawAllTaps(QPainter* painter)
+void CrEchoTapsView::redrawAllTaps(QPainter& painter)
{
m_finalFeedback = m_epar->finalFeedback;
m_finalDelay = m_epar->finalDelay;
- if (m_finalFeedback)
- {
- drawEchoTap(m_finalDelay, m_finalFeedback, tap_final, painter);
- }
+ if (m_finalFeedback) {
+ drawEchoTap(m_finalDelay, m_finalFeedback, tap_final, painter);
+ }
(void)std::memcpy(&m_parallelEcho,
reinterpret_cast<void*>(
const_cast<EchoParameters::ParallelEcho(*)[10]>(&m_epar->parallelEcho)),
sizeof(EchoParameters::ParallelEcho) * 10);
bool drawSelected = false;
- for (int count=0; count < m_epar->parallelEchoCount; count++)
- {
- if (count == m_selectedEchoTap)
- {
- drawSelected = true;
- continue;
- }
- drawEchoTap(m_parallelEcho[count].delay, m_parallelEcho[count].decay, tap_normal, painter);
- }
- if (drawSelected)
- {
- drawEchoTap(m_parallelEcho[m_selectedEchoTap].delay,
- m_parallelEcho[m_selectedEchoTap].decay, tap_selected, painter);
+ for (int count=0; count < m_epar->parallelEchoCount; count++) {
+ if (count == m_selectedEchoTap) {
+ drawSelected = true;
+ continue;
}
+ drawEchoTap(m_parallelEcho[count].delay, m_parallelEcho[count].decay, tap_normal, painter);
+ }
+ if (drawSelected) {
+ drawEchoTap(m_parallelEcho[m_selectedEchoTap].delay,
+ m_parallelEcho[m_selectedEchoTap].decay, tap_selected, painter);
+ }
}
void CrEchoTapsView::slotChangeSelectedTap(int echoTapNum)
{
- QPainter painter(this);
- transformPainter(&painter);
- if (m_selectedEchoTap != -1)
- {
- drawEchoTap(m_parallelEcho[m_selectedEchoTap].delay,
- m_parallelEcho[m_selectedEchoTap].decay, tap_deleted, &painter);
- drawGrid(&painter);
- }
m_selectedEchoTap = echoTapNum;
- redrawAllTaps(&painter);
-#if 0
- std::cerr << "CrEchoTapsView::slotChangeSelectedTap | tap: " << echoTapNum << "\n";
-#endif
-}
-
-void CrEchoTapsView::slotUpdateSelectedTap()
-{
- assert(m_selectedEchoTap != -1);
- QPainter painter(this);
- transformPainter(&painter);
- drawEchoTap(m_parallelEcho[m_selectedEchoTap].delay,
- m_parallelEcho[m_selectedEchoTap].decay, tap_deleted, &painter);
- drawGrid(&painter);
- redrawAllTaps(&painter);
-}
-
-void CrEchoTapsView::slotUpdateFinalTap()
-{
- QPainter painter(this);
- transformPainter(&painter);
- if (m_finalFeedback)
- {
- drawEchoTap(m_finalDelay, m_finalFeedback, tap_finalDeleted, &painter);
- }
- drawGrid(&painter);
- redrawAllTaps(&painter);
+ update();
}
View
30 creox/effects_gui/crechotapsview.h
@@ -19,8 +19,7 @@
#ifndef CRECHOTAPSVIEW_H
#define CRECHOTAPSVIEW_H
-#include <qwidget.h>
-#include <q3frame.h>
+#include <QFrame>
#include <QSizePolicy>
#include <QSize>
#include "echoprocessor.h"
@@ -30,11 +29,11 @@ class QPainter;
/**
* @author Jozef Kosoru
*/
-class CrEchoTapsView : public Q3Frame
+class CrEchoTapsView : public QFrame
{
Q_OBJECT
- public:
+ public:
CrEchoTapsView(const EchoParameters* epar, const int selectedEchoTap = -1, QWidget *parent = 0,
const char *name = 0);
@@ -47,15 +46,11 @@ class CrEchoTapsView : public Q3Frame
virtual QSize sizeHint() const;
- //void setSelectedEchoTap(const int echoTapNum, const bool repaint=true);
-
- public slots:
+ public slots:
void slotChangeSelectedTap(int echoTapNum);
- void slotUpdateSelectedTap();
- void slotUpdateFinalTap();
protected:
- virtual void drawContents(QPainter* painter);
+ virtual void paintEvent(QPaintEvent* event);
private:
enum TapType { tap_normal, tap_selected, tap_deleted, tap_final, tap_finalDeleted };
@@ -65,25 +60,24 @@ class CrEchoTapsView : public Q3Frame
float m_finalDelay;
int m_selectedEchoTap;
- void redrawAllTaps(QPainter* painter);
+ void redrawAllTaps(QPainter& painter);
- static void transformPainter(QPainter* painter);
- static void drawGrid(QPainter* painter);
+ static void transformPainter(QPainter& painter);
+ static void drawGrid(QPainter& painter);
void drawEchoTap(const float delay, const float decay, const TapType type,
- QPainter* painter) const;
+ QPainter& painter) const;
static inline int roundToInt(float f)
{
int sign=1;
- if(f<0.0f){
+ if(f<0.0f) {
f=-f;
sign=-1;
}
const int fi = static_cast<int>(f);
- if((f-static_cast<float>(fi))>=0.5f){
+ if((f-static_cast<float>(fi))>=0.5f) {
return (fi+1)*sign;
- }
- else{
+ } else {
return fi*sign;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.