![]() |
Mixxx
|
00001 /*************************************************************************** 00002 wdisplay.cpp - description 00003 ------------------- 00004 begin : Fri Jun 21 2002 00005 copyright : (C) 2002 by Tue & Ken Haste Andersen 00006 email : haste@diku.dk 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #include "wdisplay.h" 00019 #include "wpixmapstore.h" 00020 00021 #include <QPainter> 00022 #include <QPaintEvent> 00023 #include <QtDebug> 00024 #include <QPixmap> 00025 00026 WDisplay::WDisplay(QWidget * parent) : WWidget(parent) 00027 { 00028 m_pPixmaps = 0; 00029 setPositions(0); 00030 } 00031 00032 WDisplay::~WDisplay() 00033 { 00034 resetPositions(); 00035 } 00036 00037 void WDisplay::setup(QDomNode node) 00038 { 00039 // Number of states 00040 setPositions(selectNodeInt(node, "NumberStates")); 00041 00042 // Load knob pixmaps 00043 QString path = selectNodeQString(node, "Path"); 00044 for (int i=0; i<m_iNoPos; ++i) 00045 { 00046 setPixmap(i, getPath(path.arg(i))); 00047 } 00048 } 00049 00050 void WDisplay::setPositions(int iNoPos) 00051 { 00052 m_iNoPos = iNoPos; 00053 m_iPos = 0; 00054 00055 resetPositions(); 00056 00057 if (m_iNoPos>0) 00058 { 00059 m_pPixmaps = new QPixmap*[m_iNoPos]; 00060 for (int i=0; i<m_iNoPos; i++) 00061 m_pPixmaps[i] = 0; 00062 } 00063 } 00064 00065 void WDisplay::resetPositions() 00066 { 00067 if (m_pPixmaps) 00068 { 00069 for (int i=0; i<m_iNoPos; i++) 00070 if (m_pPixmaps[i]) 00071 WPixmapStore::deletePixmap(m_pPixmaps[i]); 00072 00073 //WPixmapStore::deletePixmap(m_pPixmaps); 00074 m_pPixmaps = 0; 00075 } 00076 } 00077 00078 void WDisplay::setPixmap(int iPos, const QString &filename) 00079 { 00080 m_pPixmaps[iPos] = WPixmapStore::getPixmap(filename); 00081 if (!m_pPixmaps[iPos]) 00082 qDebug() << "WDisplay: Error loading pixmap" << filename; 00083 else 00084 setFixedSize(m_pPixmaps[iPos]->size()); 00085 } 00086 00087 void WDisplay::paintEvent(QPaintEvent *) 00088 { 00089 if (m_pPixmaps>0) 00090 { 00091 int idx = (int)(m_fValue*(float)(m_iNoPos)/128.); 00092 // Range check 00093 if (idx>(m_iNoPos-1)) 00094 idx = m_iNoPos-1; 00095 else if (idx<0) 00096 idx = 0; 00097 if (m_pPixmaps[idx]) { 00098 QPainter p(this); 00099 p.drawPixmap(0, 0, *m_pPixmaps[idx]); 00100 } 00101 } 00102 } 00103 00104 00105