diff options
author | RJ Ryan <rryan@mixxx.org> | 2013-06-19 00:46:54 -0400 |
---|---|---|
committer | RJ Ryan <rryan@mixxx.org> | 2013-06-19 00:46:54 -0400 |
commit | 25d57b59dff3947212909634864dd82365c9606b (patch) | |
tree | f0d0f8a048f8ed2f45c5ff015fc96891662f72f1 /src/widget/wdisplay.cpp | |
parent | e50f9f168fa08f2be6d0f13e8a225bbcc9de09bb (diff) |
Moving mixxx/* to the root. A new era begins!
Diffstat (limited to 'src/widget/wdisplay.cpp')
-rw-r--r-- | src/widget/wdisplay.cpp | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/src/widget/wdisplay.cpp b/src/widget/wdisplay.cpp new file mode 100644 index 0000000000..63cc194060 --- /dev/null +++ b/src/widget/wdisplay.cpp @@ -0,0 +1,91 @@ +/*************************************************************************** + wdisplay.cpp - description + ------------------- + begin : Fri Jun 21 2002 + copyright : (C) 2002 by Tue & Ken Haste Andersen + email : haste@diku.dk +***************************************************************************/ + +/*************************************************************************** +* * +* 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. * +* * +***************************************************************************/ + +#include "wdisplay.h" +#include "wpixmapstore.h" + +#include <QPainter> +#include <QPaintEvent> +#include <QtDebug> +#include <QPixmap> + +WDisplay::WDisplay(QWidget * parent) : WWidget(parent) { + m_pPixmaps = 0; + setPositions(0); +} + +WDisplay::~WDisplay() { + resetPositions(); +} + +void WDisplay::setup(QDomNode node) { + // Number of states + setPositions(selectNodeInt(node, "NumberStates")); + + // Load knob pixmaps + QString path = selectNodeQString(node, "Path"); + for (int i=0; i<m_iNoPos; ++i) { + setPixmap(i, getPath(path.arg(i))); + } +} + +void WDisplay::setPositions(int iNoPos) { + m_iNoPos = iNoPos; + m_iPos = 0; + + resetPositions(); + + if (m_iNoPos>0) { + m_pPixmaps = new QPixmap*[m_iNoPos]; + for (int i=0; i<m_iNoPos; i++) + m_pPixmaps[i] = 0; + } +} + +void WDisplay::resetPositions() { + if (m_pPixmaps) { + for (int i=0; i<m_iNoPos; i++) + if (m_pPixmaps[i]) + WPixmapStore::deletePixmap(m_pPixmaps[i]); + + //WPixmapStore::deletePixmap(m_pPixmaps); + m_pPixmaps = 0; + } +} + +void WDisplay::setPixmap(int iPos, const QString &filename) { + m_pPixmaps[iPos] = WPixmapStore::getPixmap(filename); + if (!m_pPixmaps[iPos]) + qDebug() << "WDisplay: Error loading pixmap" << filename; + else + setFixedSize(m_pPixmaps[iPos]->size()); +} + +void WDisplay::paintEvent(QPaintEvent *) { + if (m_pPixmaps) { + int idx = (int)(m_fValue*(float)(m_iNoPos)/128.); + // Range check + if (idx>(m_iNoPos-1)) + idx = m_iNoPos-1; + else if (idx<0) + idx = 0; + if (m_pPixmaps[idx]) { + QPainter p(this); + p.drawPixmap(0, 0, *m_pPixmaps[idx]); + } + } +} |