summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRJ Ryan <rryan@mixxx.org>2013-12-24 12:22:33 -0500
committerRJ Ryan <rryan@mixxx.org>2013-12-24 12:22:33 -0500
commit8031720dbcdae5839e1c70d1e85df85539003c0f (patch)
treecbd95afff661c251537929a665916896bc456dee
parentcdbe4e0f1ff2ab7a017195264ce27ede4d6fdf87 (diff)
Refactor WNumber to inherit from WLabel since they had almost identical code.
-rw-r--r--src/widget/wlabel.cpp29
-rw-r--r--src/widget/wlabel.h14
-rw-r--r--src/widget/wnumber.cpp81
-rw-r--r--src/widget/wnumber.h23
4 files changed, 46 insertions, 101 deletions
diff --git a/src/widget/wlabel.cpp b/src/widget/wlabel.cpp
index 147b77e3cb..5926ac81c6 100644
--- a/src/widget/wlabel.cpp
+++ b/src/widget/wlabel.cpp
@@ -15,27 +15,28 @@
* *
***************************************************************************/
+#include "widget/wlabel.h"
+
+#include <QFont>
#include <QVBoxLayout>
-#include "widget/wlabel.h"
#include "widget/wskincolor.h"
-WLabel::WLabel(QWidget * parent) : WWidget(parent)
-{
- m_pLabel = new QLabel(this);
+WLabel::WLabel(QWidget* pParent)
+ : WWidget(pParent),
+ m_pLabel(new QLabel(this)),
+ m_qsText("") {
QLayout* pLayout = new QVBoxLayout(this);
pLayout->setContentsMargins(0, 0, 0, 0);
pLayout->addWidget(m_pLabel);
setLayout(pLayout);
- m_qsText = "";
}
WLabel::~WLabel() {
delete m_pLabel;
}
-void WLabel::setup(QDomNode node)
-{
+void WLabel::setup(QDomNode node) {
// Colors
QPalette palette = m_pLabel->palette(); //we have to copy out the palette to edit it since it's const (probably for threadsafety)
if (!WWidget::selectNode(node, "BgColor").isNull()) {
@@ -52,13 +53,19 @@ void WLabel::setup(QDomNode node)
m_qsText = selectNodeQString(node, "Text");
m_pLabel->setText(m_qsText);
+ // Font size
+ if (!selectNode(node, "FontSize").isNull()) {
+ int fontsize = 9;
+ fontsize = selectNodeQString(node, "FontSize").toInt();
+ m_pLabel->setFont( QFont("Helvetica",fontsize,QFont::Normal) );
+ }
+
// Alignment
if (!selectNode(node, "Alignment").isNull()) {
- if (selectNodeQString(node, "Alignment")=="right")
+ if (selectNodeQString(node, "Alignment")=="right") {
m_pLabel->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
- // FWI: Begin of font alignment patch
- else if (selectNodeQString(node, "Alignment")=="center")
+ } else if (selectNodeQString(node, "Alignment")=="center") {
m_pLabel->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
- // FWI: End of font alignment patch
+ }
}
}
diff --git a/src/widget/wlabel.h b/src/widget/wlabel.h
index d5459cc435..19fb9261c8 100644
--- a/src/widget/wlabel.h
+++ b/src/widget/wlabel.h
@@ -22,23 +22,21 @@
#include "widget/wwidget.h"
-/**
- *@author Tue Haste Andersen
- */
class WLabel : public WWidget {
Q_OBJECT
public:
- WLabel(QWidget *parent=0);
+ WLabel(QWidget* pParent=NULL);
virtual ~WLabel();
- void setup(QDomNode node);
+ virtual void setup(QDomNode node);
virtual QWidget* getComposedWidget() { return m_pLabel; }
protected:
- QLabel *m_pLabel;
+ QLabel* m_pLabel;
QString m_qsText;
- /** Foreground and background colors */
- QColor m_qFgColor, m_qBgColor;
+ // Foreground and background colors.
+ QColor m_qFgColor;
+ QColor m_qBgColor;
};
#endif
diff --git a/src/widget/wnumber.cpp b/src/widget/wnumber.cpp
index 2dd0d11d04..33304f9676 100644
--- a/src/widget/wnumber.cpp
+++ b/src/widget/wnumber.cpp
@@ -18,83 +18,37 @@
#include "widget/wnumber.h"
#include <math.h>
-#include <QFont>
-#include <QLabel>
#include <QVBoxLayout>
#include "widget/wskincolor.h"
-WNumber::WNumber(QWidget * parent) : WWidget(parent)
-{
- m_pLabel = new QLabel(this);
- QLayout* pLayout = new QVBoxLayout(this);
- pLayout->setContentsMargins(0, 0, 0, 0);
- pLayout->addWidget(m_pLabel);
- setLayout(pLayout);
- m_qsText = "";
- m_dConstFactor = 0.;
+WNumber::WNumber(QWidget* pParent)
+ : WLabel(pParent),
+ m_iNoDigits(-1),
+ m_dConstFactor(0.0) {
}
-WNumber::~WNumber()
-{
- delete m_pLabel;
+WNumber::~WNumber() {
}
-void WNumber::setup(QDomNode node)
-{
- // Number of digits
- setNumDigits(selectNodeInt(node, "NumberOfDigits"));
-
- // Colors
- QPalette palette = m_pLabel->palette(); //we have to copy out the palette to edit it since it's const (probably for threadsafety)
- if (!WWidget::selectNode(node, "BgColor").isNull()) {
- m_qBgColor.setNamedColor(WWidget::selectNodeQString(node, "BgColor"));
- palette.setColor(this->backgroundRole(), WSkinColor::getCorrectColor(m_qBgColor));
- m_pLabel->setAutoFillBackground(true);
- }
- m_qFgColor.setNamedColor(WWidget::selectNodeQString(node, "FgColor"));
- palette.setColor(this->foregroundRole(), WSkinColor::getCorrectColor(m_qFgColor));
- m_pLabel->setPalette(palette);
-
- // Text
- if (!selectNode(node, "Text").isNull())
- m_qsText = selectNodeQString(node, "Text");
-
- // FWI: Begin of font size patch
- if (!selectNode(node, "FontSize").isNull()) {
- int fontsize = 9;
- fontsize = selectNodeQString(node, "FontSize").toInt();
- m_pLabel->setFont( QFont("Helvetica",fontsize,QFont::Normal) );
- }
- // FWI: End of font size patch
+void WNumber::setup(QDomNode node) {
+ WLabel::setup(node);
- // Alignment
- if (!selectNode(node, "Alignment").isNull())
- {
- if (selectNodeQString(node, "Alignment")=="right")
- m_pLabel->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
- // FWI: Begin of font alignment patch
- else if (selectNodeQString(node, "Alignment")=="center")
- m_pLabel->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
- // FWI: End of font alignment patch
- }
+ // Number of digits
+ // TODO(rryan): This has been unused for a long time yet our skins specify
+ // this value all over the place.
+ m_iNoDigits = selectNodeInt(node, "NumberOfDigits");
// Constant factor
- if (!selectNode(node, "ConstFactor").isNull())
- {
+ if (!selectNode(node, "ConstFactor").isNull()) {
m_dConstFactor = selectNodeQString(node, "ConstFactor").toDouble();
- setValue(0.);
}
-}
-void WNumber::setNumDigits(int n)
-{
- m_iNoDigits = n;
+ setValue(0.);
}
-void WNumber::setValue(double dValue)
-{
- double v = dValue+m_dConstFactor;
+void WNumber::setValue(double dValue) {
+ double v = dValue + m_dConstFactor;
int d1 = (int)floor((v-floor(v))*10.);
int d2 = (int)floor((v-floor(v))*100.)%10;
@@ -103,8 +57,3 @@ void WNumber::setValue(double dValue)
QString("%1").arg(d1, 1, 10),
QString("%1").arg(d2, 1, 10)));
}
-
-void WNumber::setConstFactor(double c)
-{
- m_dConstFactor = c;
-}
diff --git a/src/widget/wnumber.h b/src/widget/wnumber.h
index 284e8884d3..d315a47ee5 100644
--- a/src/widget/wnumber.h
+++ b/src/widget/wnumber.h
@@ -20,33 +20,24 @@
#include <QLabel>
-#include "widget/wwidget.h"
+#include "widget/wlabel.h"
-/**
- *@author Tue & Ken Haste Andersen
- */
-
-class WNumber : public WWidget {
+class WNumber : public WLabel {
Q_OBJECT
public:
- WNumber(QWidget *parent=0);
+ WNumber(QWidget* pParent=NULL);
virtual ~WNumber();
- void setup(QDomNode node);
- void setNumDigits(int);
- void setConstFactor(double);
- virtual QWidget* getComposedWidget() { return m_pLabel; }
+ virtual void setup(QDomNode node);
public slots:
void setValue(double dValue);
protected:
- QLabel* m_pLabel;
- QString m_qsText;
+ // Number of digits to round to.
int m_iNoDigits;
- /** Foreground and background colors */
- QColor m_qFgColor, m_qBgColor;
- /** Constant factor added to value */
+
+ // Constant factor added to value.
double m_dConstFactor;
};