Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WScrollable: Add a scrollable widget type. #3890

Merged
merged 4 commits into from
Jun 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,7 @@ add_library(mixxx-lib STATIC EXCLUDE_FROM_ALL
src/widget/wpixmapstore.cpp
src/widget/wpushbutton.cpp
src/widget/wrecordingduration.cpp
src/widget/wscrollable.cpp
src/widget/wsearchlineedit.cpp
src/widget/wsingletoncontainer.cpp
src/widget/wsizeawarestack.cpp
Expand Down
34 changes: 34 additions & 0 deletions src/skin/legacy/legacyskinparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
#include "widget/wpushbutton.h"
#include "widget/wraterange.h"
#include "widget/wrecordingduration.h"
#include "widget/wscrollable.h"
#include "widget/wsearchlineedit.h"
#include "widget/wsingletoncontainer.h"
#include "widget/wsizeawarestack.h"
Expand Down Expand Up @@ -598,6 +599,8 @@ QList<QWidget*> LegacySkinParser::parseNode(const QDomElement& node) {
result = wrapWidget(parseBattery(node));
} else if (nodeName == "SetVariable") {
m_pContext->updateVariable(node);
} else if (nodeName == "Scrollable") {
result = wrapWidget(parseScrollable(node));
} else if (nodeName == "Template") {
result = parseTemplate(node);
} else if (nodeName == "SingletonDefinition") {
Expand Down Expand Up @@ -648,6 +651,37 @@ QWidget* LegacySkinParser::parseSplitter(const QDomElement& node) {
return pSplitter;
}

QWidget* LegacySkinParser::parseScrollable(const QDomElement& node) {
WScrollable* pScrollable = new WScrollable(m_pParent);
commonWidgetSetup(node, pScrollable);

QDomNode childrenNode = m_pContext->selectNode(node, "Children");
QWidget* pOldParent = m_pParent;
m_pParent = pScrollable;

if (!childrenNode.isNull()) {
QDomNodeList childNodes = childrenNode.childNodes();
if (childNodes.count() != 1) {
SKIN_WARNING(node, *m_pContext) << "Scrollables must have exactly one child";
}

QDomNode childnode = childNodes.at(0);
if (childnode.isElement()) {
QList<QWidget*> children = parseNode(childnode.toElement());
if (children.count() != 1) {
SKIN_WARNING(node, *m_pContext) << "Scrollables must have exactly one child";
} else if (children.at(0) != nullptr) {
pScrollable->setWidget(children.at(0));
}
}
}
pScrollable->setup(node, *m_pContext);
pScrollable->Init();

m_pParent = pOldParent;
return pScrollable;
}

void LegacySkinParser::parseChildren(
const QDomElement& node,
WWidgetGroup* pGroup) {
Expand Down
1 change: 1 addition & 0 deletions src/skin/legacy/legacyskinparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class LegacySkinParser : public QObject, public SkinParser {
QWidget* parseWidgetStack(const QDomElement& node);
QWidget* parseSizeAwareStack(const QDomElement& node);
QWidget* parseSplitter(const QDomElement& node);
QWidget* parseScrollable(const QDomElement& node);
void parseSingletonDefinition(const QDomElement& node);

// Visual widgets.
Expand Down
26 changes: 26 additions & 0 deletions src/widget/wscrollable.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "widget/wscrollable.h"

WScrollable::WScrollable(QWidget* pParent)
: QScrollArea(pParent),
WBaseWidget(this) {
}

void WScrollable::setup(const QDomNode& node, const SkinContext& context) {
QString horizontalPolicy;
// The QT default is "As Needed", so we don't need a selector for that.
if (context.hasNodeSelectString(node, "HorizontalScrollBarPolicy", &horizontalPolicy)) {
if (horizontalPolicy == "on") {
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
} else if (horizontalPolicy == "off") {
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}
}
QString verticalPolicy;
if (context.hasNodeSelectString(node, "VerticalScrollBarPolicy", &verticalPolicy)) {
if (verticalPolicy == "on") {
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
} else if (verticalPolicy == "off") {
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}
}
}
19 changes: 19 additions & 0 deletions src/widget/wscrollable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <QDomNode>
#include <QEvent>
#include <QScrollArea>

#include "preferences/usersettings.h"
#include "skin/legacy/skincontext.h"
#include "widget/wbasewidget.h"

/// Creates a QScrollArea. The QT default is to show scrollbars if needed.
class WScrollable : public QScrollArea, public WBaseWidget {
Q_OBJECT
public:
WScrollable(QWidget* pParent);

/// WScrollable supports the following attributes: HorizontalScrollBarPolicy, VerticalScrollBarPolicy
void setup(const QDomNode& node, const SkinContext& context);
};