![]() |
Mixxx
|
00001 /*************************************************************************** 00002 wwidget.cpp - description 00003 ------------------- 00004 begin : Wed Jun 18 2003 00005 copyright : (C) 2003 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 00019 #include <QtGui> 00020 #include <QtDebug> 00021 00022 #include "wwidget.h" 00023 #include "controlobject.h" 00024 #include "controlobjectthreadwidget.h" 00025 00026 00027 // Static member variable definition 00028 QString WWidget::m_qPath; 00029 00030 WWidget::WWidget(QWidget * parent, Qt::WFlags flags) : QWidget(parent, flags) 00031 { 00032 00033 m_fValue = 0.; 00034 m_bOff = false; 00035 connect(this, SIGNAL(valueChangedLeftDown(double)), this, SLOT(slotReEmitValueDown(double))); 00036 connect(this, SIGNAL(valueChangedRightDown(double)), this, SLOT(slotReEmitValueDown(double))); 00037 connect(this, SIGNAL(valueChangedLeftUp(double)), this, SLOT(slotReEmitValueUp(double))); 00038 connect(this, SIGNAL(valueChangedRightUp(double)), this, SLOT(slotReEmitValueUp(double))); 00039 00040 setAttribute(Qt::WA_StaticContents); 00041 setFocusPolicy(Qt::ClickFocus); 00042 //setBackgroundMode(Qt::NoBackground); //this is deprecated, and commenting it out doesn't seem to change anything -kousu 2009/03 00043 } 00044 00045 WWidget::~WWidget() 00046 { 00047 } 00048 00049 void WWidget::setValue(double fValue) 00050 { 00051 m_fValue = fValue; 00052 update(); 00053 } 00054 00055 void WWidget::setOnOff(double d) 00056 { 00057 if (d==0.) 00058 m_bOff = false; 00059 else 00060 m_bOff = true; 00061 00062 repaint(); 00063 } 00064 00065 void WWidget::slotReEmitValueDown(double fValue) 00066 { 00067 emit(valueChangedDown(fValue)); 00068 } 00069 00070 void WWidget::slotReEmitValueUp(double fValue) 00071 { 00072 emit(valueChangedUp(fValue)); 00073 } 00074 00075 int WWidget::selectNodeInt(const QDomNode &nodeHeader, const QString sNode) 00076 { 00077 QString text = selectNode(nodeHeader, sNode).toElement().text(); 00078 bool ok; 00079 int conv = text.toInt(&ok, 0); 00080 if (ok) { 00081 return conv; 00082 } else { 00083 return 0; 00084 } 00085 } 00086 00087 float WWidget::selectNodeFloat(const QDomNode &nodeHeader, const QString sNode) 00088 { 00089 return selectNode(nodeHeader, sNode).toElement().text().toFloat(); 00090 } 00091 00092 QString WWidget::selectNodeQString(const QDomNode &nodeHeader, const QString sNode) 00093 { 00094 QString ret; 00095 QDomNode node = selectNode(nodeHeader, sNode); 00096 if (!node.isNull()) 00097 ret = node.toElement().text(); 00098 else 00099 ret = ""; 00100 return ret; 00101 } 00102 00103 QDomNode WWidget::selectNode(const QDomNode &nodeHeader, const QString sNode) 00104 { 00105 QDomNode node = nodeHeader.firstChild(); 00106 while (!node.isNull()) 00107 { 00108 if (node.nodeName() == sNode) 00109 return node; 00110 node = node.nextSibling(); 00111 } 00112 return node; 00113 } 00114 00115 const QString WWidget::getPath(QString location) 00116 { 00117 QString l(location); 00118 return l.prepend(m_qPath); 00119 } 00120 00121 void WWidget::setPixmapPath(QString qPath) 00122 { 00123 m_qPath = qPath; 00124 } 00125 00126 QDomElement WWidget::openXMLFile(QString path, QString name) 00127 { 00128 QDomDocument doc(name); 00129 QFile file(path); 00130 if (!file.open(QIODevice::ReadOnly)) 00131 { 00132 qDebug() << "Could not open xml file:" << file.fileName(); 00133 return QDomElement(); 00134 } 00135 if (!doc.setContent(&file)) 00136 { 00137 qWarning() << "Error parsing xml file:" << file.fileName(); 00138 file.close(); 00139 return QDomElement(); 00140 } 00141 00142 file.close(); 00143 return doc.documentElement(); 00144 } 00145 00146 double WWidget::getValue() { 00147 return m_fValue; 00148 } 00149 00150 void WWidget::updateValue(double fValue) 00151 { 00152 setValue(fValue); 00153 emit(valueChangedUp(fValue)); 00154 emit(valueChangedDown(fValue)); 00155 }