From 8af748c5c5a4f0672cca7d9a7ee54414f087a0af Mon Sep 17 00:00:00 2001 From: RJ Ryan Date: Tue, 7 Jan 2014 18:43:48 -0500 Subject: Make WLabel inherit QLabel instead of WWidget. WLabel and its variants don't really need anything provided by WWidget. As far as I can tell no existing CSS styles use WWidget to style WLabel either, so this should be safe skin-wise. This also gets rid of WWidget::getComposedWidget since its sole purpose was for styling labels. --- src/skin/legacyskinparser.cpp | 40 ++++++++-------------------------------- src/widget/wkey.cpp | 4 ++-- src/widget/wlabel.cpp | 27 ++++++++++----------------- src/widget/wlabel.h | 4 +--- src/widget/wnumber.cpp | 2 +- src/widget/wnumberpos.cpp | 2 +- src/widget/wnumberrate.cpp | 4 ++-- src/widget/wtime.cpp | 4 ++-- src/widget/wtrackproperty.cpp | 4 ++-- src/widget/wtracktext.cpp | 4 ++-- src/widget/wwidget.h | 4 ---- 11 files changed, 31 insertions(+), 68 deletions(-) diff --git a/src/skin/legacyskinparser.cpp b/src/skin/legacyskinparser.cpp index 91425393f9..1a260d7981 100644 --- a/src/skin/legacyskinparser.cpp +++ b/src/skin/legacyskinparser.cpp @@ -759,16 +759,13 @@ QWidget* LegacySkinParser::parseText(QDomElement node) { return NULL; WTrackText* p = new WTrackText(m_pParent); - setupWidget(node, p); // NOTE(rryan): To support color schemes, the WWidget::setup() call must // come first. This is because WNumber/WLabel both change the palette based // on the node and setupWidget() will set the widget style. If the style is // set before the palette is set then the custom palette will not take // effect which breaks color scheme support. p->setup(node, *m_pContext); - if (p->getComposedWidget()) { - setupWidget(node, p->getComposedWidget(), false); - } + setupWidget(node, p); setupConnections(node, p); p->installEventFilter(m_pKeyboard); p->installEventFilter(m_pControllerManager->getControllerLearningEventFilter()); @@ -796,16 +793,13 @@ QWidget* LegacySkinParser::parseTrackProperty(QDomElement node) { return NULL; WTrackProperty* p = new WTrackProperty(m_pParent); - setupWidget(node, p); // NOTE(rryan): To support color schemes, the WWidget::setup() call must // come first. This is because WNumber/WLabel both change the palette based // on the node and setupWidget() will set the widget style. If the style is // set before the palette is set then the custom palette will not take // effect which breaks color scheme support. p->setup(node, *m_pContext); - if (p->getComposedWidget()) { - setupWidget(node, p->getComposedWidget(), false); - } + setupWidget(node, p); setupConnections(node, p); p->installEventFilter(m_pKeyboard); p->installEventFilter(m_pControllerManager->getControllerLearningEventFilter()); @@ -869,16 +863,13 @@ QWidget* LegacySkinParser::parseNumberRate(QDomElement node) { palette.setBrush(QPalette::Button, Qt::NoBrush); WNumberRate * p = new WNumberRate(pSafeChannelStr, m_pParent); - setupWidget(node, p); // NOTE(rryan): To support color schemes, the WWidget::setup() call must // come first. This is because WNumber/WLabel both change the palette based // on the node and setupWidget() will set the widget style. If the style is // set before the palette is set then the custom palette will not take // effect which breaks color scheme support. p->setup(node, *m_pContext); - if (p->getComposedWidget()) { - setupWidget(node, p->getComposedWidget(), false); - } + setupWidget(node, p); setupConnections(node, p); p->installEventFilter(m_pKeyboard); p->installEventFilter(m_pControllerManager->getControllerLearningEventFilter()); @@ -893,16 +884,13 @@ QWidget* LegacySkinParser::parseNumberPos(QDomElement node) { const char* pSafeChannelStr = safeChannelString(channelStr); WNumberPos* p = new WNumberPos(pSafeChannelStr, m_pParent); - setupWidget(node, p); // NOTE(rryan): To support color schemes, the WWidget::setup() call must // come first. This is because WNumber/WLabel both change the palette based // on the node and setupWidget() will set the widget style. If the style is // set before the palette is set then the custom palette will not take // effect which breaks color scheme support. p->setup(node, *m_pContext); - if (p->getComposedWidget()) { - setupWidget(node, p->getComposedWidget(), false); - } + setupWidget(node, p); setupConnections(node, p); p->installEventFilter(m_pKeyboard); p->installEventFilter(m_pControllerManager->getControllerLearningEventFilter()); @@ -911,16 +899,13 @@ QWidget* LegacySkinParser::parseNumberPos(QDomElement node) { QWidget* LegacySkinParser::parseNumber(QDomElement node) { WNumber* p = new WNumber(m_pParent); - setupWidget(node, p); // NOTE(rryan): To support color schemes, the WWidget::setup() call must // come first. This is because WNumber/WLabel both change the palette based // on the node and setupWidget() will set the widget style. If the style is // set before the palette is set then the custom palette will not take // effect which breaks color scheme support. p->setup(node, *m_pContext); - if (p->getComposedWidget()) { - setupWidget(node, p->getComposedWidget(), false); - } + setupWidget(node, p); setupConnections(node, p); p->installEventFilter(m_pKeyboard); p->installEventFilter(m_pControllerManager->getControllerLearningEventFilter()); @@ -929,16 +914,13 @@ QWidget* LegacySkinParser::parseNumber(QDomElement node) { QWidget* LegacySkinParser::parseLabel(QDomElement node) { WLabel * p = new WLabel(m_pParent); - setupWidget(node, p); // NOTE(rryan): To support color schemes, the WWidget::setup() call must // come first. This is because WNumber/WLabel both change the palette based // on the node and setupWidget() will set the widget style. If the style is // set before the palette is set then the custom palette will not take // effect which breaks color scheme support. p->setup(node, *m_pContext); - if (p->getComposedWidget()) { - setupWidget(node, p->getComposedWidget(), false); - } + setupWidget(node, p); setupConnections(node, p); p->installEventFilter(m_pKeyboard); p->installEventFilter(m_pControllerManager->getControllerLearningEventFilter()); @@ -947,16 +929,13 @@ QWidget* LegacySkinParser::parseLabel(QDomElement node) { QWidget* LegacySkinParser::parseTime(QDomElement node) { WTime *p = new WTime(m_pParent); - setupWidget(node, p); // NOTE(rryan): To support color schemes, the WWidget::setup() call must // come first. This is because WNumber/WLabel both change the palette based // on the node and setupWidget() will set the widget style. If the style is // set before the palette is set then the custom palette will not take // effect which breaks color scheme support. p->setup(node, *m_pContext); - if (p->getComposedWidget()) { - setupWidget(node, p->getComposedWidget(), false); - } + setupWidget(node, p); setupConnections(node, p); p->installEventFilter(m_pKeyboard); p->installEventFilter(m_pControllerManager->getControllerLearningEventFilter()); @@ -1228,16 +1207,13 @@ QString LegacySkinParser::getLibraryStyle(QDomNode node) { QWidget* LegacySkinParser::parseKey(QDomElement node) { WKey* p = new WKey(m_pParent); - setupWidget(node, p); // NOTE(rryan): To support color schemes, the WWidget::setup() call must // come first. This is because WNumber/WLabel both change the palette based // on the node and setupWidget() will set the widget style. If the style is // set before the palette is set then the custom palette will not take // effect which breaks color scheme support. p->setup(node, *m_pContext); - if (p->getComposedWidget()) { - setupWidget(node, p->getComposedWidget(), false); - } + setupWidget(node, p); setupConnections(node, p); p->installEventFilter(m_pKeyboard); p->installEventFilter(m_pControllerManager->getControllerLearningEventFilter()); diff --git a/src/widget/wkey.cpp b/src/widget/wkey.cpp index 5b35387746..84fc6ab99d 100644 --- a/src/widget/wkey.cpp +++ b/src/widget/wkey.cpp @@ -22,9 +22,9 @@ void WKey::setValue(double dValue) { if (key != mixxx::track::io::key::INVALID) { // Render this key with the user-provided notation. - m_pLabel->setText(KeyUtils::keyToString(key)); + setText(KeyUtils::keyToString(key)); } else { - m_pLabel->setText(""); + setText(""); } } diff --git a/src/widget/wlabel.cpp b/src/widget/wlabel.cpp index 69292795af..60a9861144 100644 --- a/src/widget/wlabel.cpp +++ b/src/widget/wlabel.cpp @@ -18,54 +18,47 @@ #include "widget/wlabel.h" #include -#include #include "widget/wskincolor.h" WLabel::WLabel(QWidget* pParent) - : WWidget(pParent), - m_pLabel(new QLabel(this)), + : QLabel(pParent), m_qsText("") { - QLayout* pLayout = new QVBoxLayout(this); - pLayout->setContentsMargins(0, 0, 0, 0); - pLayout->addWidget(m_pLabel); - setLayout(pLayout); } WLabel::~WLabel() { - delete m_pLabel; } void WLabel::setup(QDomNode node, const SkinContext& context) { // Colors - QPalette palette = m_pLabel->palette(); //we have to copy out the palette to edit it since it's const (probably for threadsafety) + QPalette pal = palette(); //we have to copy out the palette to edit it since it's const (probably for threadsafety) if (context.hasNode(node, "BgColor")) { m_qBgColor.setNamedColor(context.selectString(node, "BgColor")); - palette.setColor(this->backgroundRole(), WSkinColor::getCorrectColor(m_qBgColor)); - m_pLabel->setAutoFillBackground(true); + pal.setColor(this->backgroundRole(), WSkinColor::getCorrectColor(m_qBgColor)); + setAutoFillBackground(true); } m_qFgColor.setNamedColor(context.selectString(node, "FgColor")); - palette.setColor(this->foregroundRole(), WSkinColor::getCorrectColor(m_qFgColor)); - m_pLabel->setPalette(palette); + pal.setColor(this->foregroundRole(), WSkinColor::getCorrectColor(m_qFgColor)); + setPalette(pal); // Text if (context.hasNode(node, "Text")) m_qsText = context.selectString(node, "Text"); - m_pLabel->setText(m_qsText); + setText(m_qsText); // Font size if (context.hasNode(node, "FontSize")) { int fontsize = 9; fontsize = context.selectString(node, "FontSize").toInt(); - m_pLabel->setFont( QFont("Helvetica",fontsize,QFont::Normal) ); + setFont( QFont("Helvetica",fontsize,QFont::Normal) ); } // Alignment if (context.hasNode(node, "Alignment")) { if (context.selectString(node, "Alignment") == "right") { - m_pLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter); + setAlignment(Qt::AlignRight | Qt::AlignVCenter); } else if (context.selectString(node, "Alignment") == "center") { - m_pLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); + setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); } } } diff --git a/src/widget/wlabel.h b/src/widget/wlabel.h index f47c972ffd..557a151ade 100644 --- a/src/widget/wlabel.h +++ b/src/widget/wlabel.h @@ -23,17 +23,15 @@ #include "widget/wwidget.h" #include "skin/skincontext.h" -class WLabel : public WWidget { +class WLabel : public QLabel { Q_OBJECT public: WLabel(QWidget* pParent=NULL); virtual ~WLabel(); virtual void setup(QDomNode node, const SkinContext& context); - virtual QWidget* getComposedWidget() { return m_pLabel; } protected: - QLabel* m_pLabel; QString m_qsText; // Foreground and background colors. QColor m_qFgColor; diff --git a/src/widget/wnumber.cpp b/src/widget/wnumber.cpp index 30eb8f0aea..a3a862ab5b 100644 --- a/src/widget/wnumber.cpp +++ b/src/widget/wnumber.cpp @@ -52,7 +52,7 @@ void WNumber::setValue(double dValue) { int d1 = (int)floor((v-floor(v))*10.); int d2 = (int)floor((v-floor(v))*100.)%10; - m_pLabel->setText(QString(m_qsText).append("%1.%2%3").arg( + setText(QString(m_qsText).append("%1.%2%3").arg( QString("%1").arg(static_cast(v), 3, 10), QString("%1").arg(d1, 1, 10), QString("%1").arg(d2, 1, 10))); diff --git a/src/widget/wnumberpos.cpp b/src/widget/wnumberpos.cpp index bca8148ac4..b9c33f0c27 100644 --- a/src/widget/wnumberpos.cpp +++ b/src/widget/wnumberpos.cpp @@ -105,7 +105,7 @@ void WNumberPos::slotSetValue(double dValue) { // we care about. Slice it off. valueString = valueString.left(valueString.length() - 1); - m_pLabel->setText(QString("%1%2").arg(m_qsText, valueString)); + setText(QString("%1%2").arg(m_qsText, valueString)); } void WNumberPos::slotSetRemain(double remain) { diff --git a/src/widget/wnumberrate.cpp b/src/widget/wnumberrate.cpp index 7b0d08cebe..4f4ac2db14 100644 --- a/src/widget/wnumberrate.cpp +++ b/src/widget/wnumberrate.cpp @@ -48,6 +48,6 @@ void WNumberRate::setValue(double) { sign = '-'; } - m_pLabel->setText(QString(m_qsText).append(sign) - .append("%1").arg(fabs(vsign)*100., 0, 'f', 2)); + setText(QString(m_qsText).append(sign) + .append("%1").arg(fabs(vsign)*100., 0, 'f', 2)); } diff --git a/src/widget/wtime.cpp b/src/widget/wtime.cpp index d7814e8c1e..82ebc4ed5e 100644 --- a/src/widget/wtime.cpp +++ b/src/widget/wtime.cpp @@ -55,7 +55,7 @@ void WTime::setTimeFormat(QDomNode node, const SkinContext& context) { void WTime::refreshTime() { QTime time = QTime::currentTime(); QString timeString = time.toString(m_sTimeFormat); - if (m_pLabel->text() != timeString) { - m_pLabel->setText(timeString); + if (text() != timeString) { + setText(timeString); } } diff --git a/src/widget/wtrackproperty.cpp b/src/widget/wtrackproperty.cpp index 55326fd3a4..7ccab172d2 100644 --- a/src/widget/wtrackproperty.cpp +++ b/src/widget/wtrackproperty.cpp @@ -30,14 +30,14 @@ void WTrackProperty::slotTrackUnloaded(TrackPointer track) { disconnect(m_pCurrentTrack.data(), 0, this, 0); } m_pCurrentTrack.clear(); - m_pLabel->setText(""); + setText(""); } void WTrackProperty::updateLabel(TrackInfoObject*) { if (m_pCurrentTrack) { QVariant property = m_pCurrentTrack->property(m_property.toAscii().constData()); if (property.isValid() && qVariantCanConvert(property)) { - m_pLabel->setText(property.toString()); + setText(property.toString()); } } } diff --git a/src/widget/wtracktext.cpp b/src/widget/wtracktext.cpp index 6e029e35fd..8de2a1dd57 100644 --- a/src/widget/wtracktext.cpp +++ b/src/widget/wtracktext.cpp @@ -25,11 +25,11 @@ void WTrackText::slotTrackUnloaded(TrackPointer track) { disconnect(m_pCurrentTrack.data(), 0, this, 0); } m_pCurrentTrack.clear(); - m_pLabel->setText(""); + setText(""); } void WTrackText::updateLabel(TrackInfoObject*) { if (m_pCurrentTrack) { - m_pLabel->setText(m_pCurrentTrack->getInfo()); + setText(m_pCurrentTrack->getInfo()); } } diff --git a/src/widget/wwidget.h b/src/widget/wwidget.h index 492a8258c9..5ebede46fe 100644 --- a/src/widget/wwidget.h +++ b/src/widget/wwidget.h @@ -40,10 +40,6 @@ public: WWidget(QWidget *parent=0, Qt::WindowFlags flags=0); virtual ~WWidget(); - // Sometimes WWidget's compose a QWidget (like a label). This is used during - // skin parsing to style and size the composed widget. - virtual QWidget* getComposedWidget() { return NULL; } - Q_PROPERTY(bool disabled READ isDisabled); Q_PROPERTY(double value READ getValue); -- cgit v1.2.3