-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Liking, disliking, and the reply view are not implemented. They also don't show in the Subscriptions tab yet, though I don't know if I will ever add that because I don't really care to.
- Loading branch information
1 parent
534ab9c
commit 7d2c18b
Showing
16 changed files
with
555 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule innertube-qt
updated
14 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/ui/widgets/renderers/backstage/backstagepollchoicerenderer.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#include "backstagepollchoicerenderer.h" | ||
#include "innertube.h" | ||
#include <QBoxLayout> | ||
#include <QLabel> | ||
#include <QMouseEvent> | ||
#include <QProgressBar> | ||
|
||
constexpr const char* notSelectedStylesheet = "QProgressBar::chunk { background-color: rgba(255, 255, 255, 0.2) }"; | ||
|
||
BackstagePollChoiceRenderer::BackstagePollChoiceRenderer(QWidget* parent) | ||
: m_choiceTextLabel(new QLabel(this)), | ||
m_percentageLabel(new QLabel(this)), | ||
m_progressBar(new QProgressBar(this)) | ||
{ | ||
m_choiceTextLabel->setMaximumWidth(width() - 100); | ||
|
||
m_progressBar->setFixedWidth(width()); | ||
m_progressBar->setMaximum(100); | ||
m_progressBar->setTextVisible(false); | ||
|
||
m_innerLayout = new QHBoxLayout(m_progressBar); | ||
m_innerLayout->addWidget(m_choiceTextLabel, 0, Qt::AlignLeft); | ||
m_innerLayout->addWidget(m_percentageLabel, 0, Qt::AlignRight); | ||
m_innerLayout->setContentsMargins(5, 0, 20, 0); | ||
} | ||
|
||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) | ||
void BackstagePollChoiceRenderer::enterEvent(QEnterEvent*) | ||
#else | ||
void BackstagePollChoiceRenderer::enterEvent(QEvent*) | ||
#endif | ||
{ | ||
setCursor(QCursor(Qt::PointingHandCursor)); | ||
} | ||
|
||
bool BackstagePollChoiceRenderer::hasStyle() const | ||
{ | ||
return !m_progressBar->styleSheet().isEmpty(); | ||
} | ||
|
||
void BackstagePollChoiceRenderer::leaveEvent(QEvent*) | ||
{ | ||
setCursor(QCursor()); | ||
} | ||
|
||
void BackstagePollChoiceRenderer::mousePressEvent(QMouseEvent* event) | ||
{ | ||
if (event->button() != Qt::LeftButton) | ||
return; | ||
|
||
QJsonValue endpoint = hasStyle() || value() == -1 ? m_data.selectServiceEndpoint : m_data.deselectServiceEndpoint; | ||
emit clicked(); | ||
InnerTube::instance()->get<InnertubeEndpoints::PerformCommentAction>(endpoint["performCommentActionEndpoint"]["action"].toString()); | ||
} | ||
|
||
void BackstagePollChoiceRenderer::reset() | ||
{ | ||
m_progressBar->reset(); | ||
m_progressBar->setStyleSheet(QString()); | ||
m_percentageLabel->clear(); | ||
} | ||
|
||
void BackstagePollChoiceRenderer::setData(const InnertubeObjects::PollChoice& pollChoice) | ||
{ | ||
m_data = pollChoice; | ||
m_choiceTextLabel->setText(pollChoice.text.text); | ||
} | ||
|
||
void BackstagePollChoiceRenderer::setValue(double value, bool selected) | ||
{ | ||
m_percentageLabel->setText(selected ? m_data.votePercentageIfSelected : m_data.votePercentageIfNotSelected); | ||
m_progressBar->setStyleSheet(selected ? QString() : notSelectedStylesheet); | ||
m_progressBar->setValue(value); | ||
} | ||
|
||
int BackstagePollChoiceRenderer::value() const | ||
{ | ||
return m_progressBar->value(); | ||
} |
42 changes: 42 additions & 0 deletions
42
src/ui/widgets/renderers/backstage/backstagepollchoicerenderer.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#ifndef BACKSTAGEPOLLCHOICERENDERER_H | ||
#define BACKSTAGEPOLLCHOICERENDERER_H | ||
#include "innertube/objects/backstage/poll/pollchoice.h" | ||
#include <QWidget> | ||
|
||
class QHBoxLayout; | ||
class QLabel; | ||
class QProgressBar; | ||
|
||
class BackstagePollChoiceRenderer : public QWidget | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit BackstagePollChoiceRenderer(QWidget* parent = nullptr); | ||
bool hasStyle() const; | ||
void reset(); | ||
void setData(const InnertubeObjects::PollChoice& pollChoice); | ||
|
||
void setValue(double value, bool selected); | ||
int value() const; | ||
|
||
double voteRatioIfNotSelected() const { return m_data.voteRatioIfNotSelected; } | ||
double voteRatioIfSelected() const { return m_data.voteRatioIfSelected; } | ||
protected: | ||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) | ||
void enterEvent(QEnterEvent*) override; | ||
#else | ||
void enterEvent(QEvent*) override; | ||
#endif | ||
void leaveEvent(QEvent*) override; | ||
void mousePressEvent(QMouseEvent* event) override; | ||
private: | ||
QLabel* m_choiceTextLabel; | ||
InnertubeObjects::PollChoice m_data; | ||
QHBoxLayout* m_innerLayout; | ||
QLabel* m_percentageLabel; | ||
QProgressBar* m_progressBar; | ||
signals: | ||
void clicked(); | ||
}; | ||
|
||
#endif // BACKSTAGEPOLLCHOICERENDERER_H |
80 changes: 80 additions & 0 deletions
80
src/ui/widgets/renderers/backstage/backstagepollrenderer.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#include "backstagepollrenderer.h" | ||
#include "backstagepollchoicerenderer.h" | ||
#include "innertube/objects/backstage/poll/poll.h" | ||
#include <QApplication> | ||
#include <QBoxLayout> | ||
#include <QLabel> | ||
#include <QProgressBar> | ||
|
||
BackstagePollRenderer::BackstagePollRenderer(QWidget* parent) | ||
: layout(new QVBoxLayout(this)), | ||
voteCount(new QLabel(this)) | ||
{ | ||
voteCount->setFont(QFont(qApp->font().toString(), qApp->font().pointSize() - 1)); | ||
layout->addWidget(voteCount); | ||
} | ||
|
||
QList<BackstagePollChoiceRenderer*> BackstagePollRenderer::choiceRenderers() const | ||
{ | ||
QList<BackstagePollChoiceRenderer*> list; | ||
list.reserve(layout->count()); | ||
|
||
for (int i = 0; i < layout->count(); ++i) | ||
if (auto choice = qobject_cast<BackstagePollChoiceRenderer*>(layout->itemAt(i)->widget())) | ||
list.append(choice); | ||
|
||
return list; | ||
} | ||
|
||
void BackstagePollRenderer::pollChoiceClicked() | ||
{ | ||
BackstagePollChoiceRenderer* senderChoice = qobject_cast<BackstagePollChoiceRenderer*>(sender()); | ||
if (senderChoice->hasStyle()) | ||
{ | ||
for (BackstagePollChoiceRenderer* pollChoiceRenderer : choiceRenderers()) | ||
{ | ||
if (!pollChoiceRenderer->hasStyle()) | ||
{ | ||
pollChoiceRenderer->setValue(pollChoiceRenderer->voteRatioIfNotSelected() * 100, false); | ||
} | ||
} | ||
} | ||
else if (senderChoice->value() != -1) | ||
{ | ||
for (BackstagePollChoiceRenderer* pollChoiceRenderer : choiceRenderers()) | ||
{ | ||
pollChoiceRenderer->reset(); | ||
} | ||
return; | ||
} | ||
else | ||
{ | ||
for (BackstagePollChoiceRenderer* pollChoiceRenderer : choiceRenderers()) | ||
{ | ||
pollChoiceRenderer->setValue(pollChoiceRenderer->voteRatioIfNotSelected() * 100, false); | ||
} | ||
} | ||
|
||
senderChoice->setValue(senderChoice->voteRatioIfSelected() * 100, true); | ||
} | ||
|
||
void BackstagePollRenderer::setData(const InnertubeObjects::Poll& poll) | ||
{ | ||
voteCount->setText(poll.totalVotes); | ||
bool hasSelected = std::ranges::any_of(poll.choices, [](const InnertubeObjects::PollChoice& choice) { | ||
return choice.selected; | ||
}); | ||
|
||
for (const InnertubeObjects::PollChoice& pollChoice : poll.choices) | ||
{ | ||
BackstagePollChoiceRenderer* pollChoiceRenderer = new BackstagePollChoiceRenderer(this); | ||
pollChoiceRenderer->setData(pollChoice); | ||
pollChoiceRenderer->setFixedHeight(36); | ||
|
||
if (hasSelected) | ||
pollChoiceRenderer->setValue(pollChoice.voteRatio * 100, pollChoice.selected); | ||
|
||
layout->addWidget(pollChoiceRenderer); | ||
connect(pollChoiceRenderer, &BackstagePollChoiceRenderer::clicked, this, &BackstagePollRenderer::pollChoiceClicked); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/ui/widgets/renderers/backstage/backstagepollrenderer.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef BACKSTAGEPOLLRENDERER_H | ||
#define BACKSTAGEPOLLRENDERER_H | ||
#include <QWidget> | ||
|
||
class BackstagePollChoiceRenderer; | ||
class QLabel; | ||
class QVBoxLayout; | ||
|
||
namespace InnertubeObjects { class Poll; } | ||
|
||
class BackstagePollRenderer : public QWidget | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit BackstagePollRenderer(QWidget* parent = nullptr); | ||
QList<BackstagePollChoiceRenderer*> choiceRenderers() const; | ||
void setData(const InnertubeObjects::Poll& poll); | ||
private: | ||
QVBoxLayout* layout; | ||
QLabel* voteCount; | ||
private slots: | ||
void pollChoiceClicked(); | ||
}; | ||
|
||
#endif // BACKSTAGEPOLLRENDERER_H |
Oops, something went wrong.