Mixxx

/home/maxime/Projets/Mixxx/1.10/mixxx/src/widget/wnumber.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           wnumber.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 #include "wnumber.h"
00019 #include "wskincolor.h"
00020 #include <math.h>
00021 #include <qfont.h>
00022 //Added by qt3to4:
00023 #include <QLabel>
00024 
00025 WNumber::WNumber(QWidget * parent) : WWidget(parent)
00026 {
00027     m_pLabel = new QLabel(this);
00028     m_qsText = "";
00029     m_dConstFactor = 0.;
00030 }
00031 
00032 WNumber::~WNumber()
00033 {
00034     delete m_pLabel;
00035 }
00036 
00037 void WNumber::setup(QDomNode node)
00038 {
00039     // Number of digits
00040     setNumDigits(selectNodeInt(node, "NumberOfDigits"));
00041 
00042     // Colors
00043     QPalette palette = m_pLabel->palette(); //we have to copy out the palette to edit it since it's const (probably for threadsafety)
00044 
00045     if(!WWidget::selectNode(node, "BgColor").isNull()) {
00046         m_qBgColor.setNamedColor(WWidget::selectNodeQString(node, "BgColor"));
00047         //m_pLabel->setPaletteBackgroundColor(WSkinColor::getCorrectColor(m_qBgColor));
00048         palette.setColor(this->backgroundRole(), WSkinColor::getCorrectColor(m_qBgColor));
00049         m_pLabel->setAutoFillBackground(true);
00050     }
00051     m_qFgColor.setNamedColor(WWidget::selectNodeQString(node, "FgColor"));
00052     //m_pLabel->setPaletteForegroundColor(WSkinColor::getCorrectColor(m_qFgColor));
00053     palette.setColor(this->foregroundRole(), WSkinColor::getCorrectColor(m_qFgColor));
00054 
00055     m_pLabel->setPalette(palette);
00056 
00057     m_pLabel->setToolTip(toolTip());
00058 
00059     // Text
00060     if (!selectNode(node, "Text").isNull())
00061         m_qsText = selectNodeQString(node, "Text");
00062 
00063     QString size = selectNodeQString(node, "Size");
00064     int x = size.left(size.indexOf(",")).toInt();
00065     int y = size.mid(size.indexOf(",")+1).toInt();
00066     m_pLabel->setFixedSize(x,y);
00067 
00068     // FWI: Begin of font size patch
00069     if (!selectNode(node, "FontSize").isNull()) {
00070         int fontsize = 9;
00071         fontsize = selectNodeQString(node, "FontSize").toInt();
00072         m_pLabel->setFont( QFont("Helvetica",fontsize,QFont::Normal) );
00073     }
00074     // FWI: End of font size patch
00075 
00076     // Alignment
00077     if (!selectNode(node, "Alignment").isNull())
00078     {
00079         if (selectNodeQString(node, "Alignment")=="right")
00080             m_pLabel->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
00081         // FWI: Begin of font alignment patch
00082         else if (selectNodeQString(node, "Alignment")=="center")
00083             m_pLabel->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
00084         // FWI: End of font alignment patch
00085     }
00086 
00087     // Constant factor
00088     if (!selectNode(node, "ConstFactor").isNull())
00089     {
00090         m_dConstFactor = selectNodeQString(node, "ConstFactor").toDouble();
00091         setValue(0.);
00092     }
00093 }
00094 
00095 void WNumber::setNumDigits(int n)
00096 {
00097     m_iNoDigits = n;
00098 }
00099 
00100 void WNumber::setValue(double dValue)
00101 {
00102     double v = dValue+m_dConstFactor;
00103     int d1 = (int)floor((v-floor(v))*10.);
00104     int d2 = (int)floor((v-floor(v))*100.)%10;
00105 
00106     m_pLabel->setText(QString(m_qsText).append("%1.%2%3").arg((int)v,3,10).arg(d1,1,10).arg(d2,1,10));
00107 }
00108 
00109 void WNumber::setConstFactor(double c)
00110 {
00111     m_dConstFactor = c;
00112 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines