Skip to content

Commit

Permalink
update qss and fix unhandled heartbeat reply
Browse files Browse the repository at this point in the history
  • Loading branch information
Fidelxyz committed Apr 9, 2022
1 parent 450c30c commit f22f91e
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 35 deletions.
1 change: 1 addition & 0 deletions bilibili-live-danmuku.pro
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ LIBS += \
-L$$PWD/3rdparty/lib -lbrotlidec

RESOURCES += \
src/modules/danmu_display/stylesheet/stylesheet.qrc \
src/stylesheet/stylesheet.qrc

TRANSLATIONS += \
Expand Down
18 changes: 15 additions & 3 deletions src/danmuku.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "danmuku.h"

#include <QFile>
#include <QGraphicsDropShadowEffect>
#include <vector>

#include "module.h"
Expand All @@ -19,9 +21,19 @@ Danmuku::Danmuku(QWidget *parent)

layout_modules = new QVBoxLayout(ui->centralWidget); // deleted by QT

Module::danmuku = this;
loadModule(new LiveRoom()); // deleted in unloadModule
loadModule(new DanmuDisplay()); // deleted in unloadModule
loadModule(new LiveRoom(this)); // deleted in unloadModule
loadModule(new DanmuDisplay(this)); // deleted in unloadModule

// Qss
QFile qss(":/stylesheet/danmuku.qss");
if (qss.open(QFile::ReadOnly)) {
qDebug("QSS loaded.");
QString stylesheet = QLatin1String(qss.readAll());
setStyleSheet(stylesheet);
qss.close();
} else {
qWarning("Failed to load QSS stylesheet (danmuku.qss).");
}
}

Danmuku::~Danmuku() {
Expand Down
12 changes: 0 additions & 12 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include <QApplication>
#include <QFile>
#include <QLocale>
#include <QResource>
#include <QTranslator>

#include "danmuku.h"
Expand All @@ -20,16 +18,6 @@ int main(int argc, char *argv[]) {
}
}

QFile qss(":/stylesheet/display.qss");
if (qss.open(QFile::ReadOnly)) {
qDebug("QSS loaded.");
QString stylesheet = QLatin1String(qss.readAll());
a.setStyleSheet(stylesheet);
qss.close();
} else {
qWarning("Failed to load QSS stylesheet (display.qss).");
}

Danmuku w;
w.show();
return a.exec();
Expand Down
12 changes: 6 additions & 6 deletions src/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@

#include "danmuku.h"

Danmuku *Module::danmuku = nullptr;

Module::Module(const QString &name, const QList<QString> &dependencies)
: QObject(danmuku) {
Module::Module(const QString &name, const QList<QString> &dependencies,
Danmuku *parent)
: QObject(parent) {
qDebug() << "Loading module:" << name;
moduleMetadata.name = name;
moduleMetadata.dependencies = dependencies;

widget = new QWidget(danmuku); // deleted by QT
widget = new QWidget(parent); // deleted by QT
// TODO check dependencies
}

Module::~Module() { qDebug() << "Unloading module:" << moduleMetadata.name; }

QWidget *Module::getWidget() const { return widget; }

// for communication with other modules
Module *Module::getModule(const QString &name) {
return danmuku->getModule(name);
return ((Danmuku *)parent())->getModule(name);
}
8 changes: 5 additions & 3 deletions src/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@ class Module : public QObject {
Q_OBJECT

public:
Module(const QString &name, const QList<QString> &dependencies = {});
Module(const QString &name, const QList<QString> &dependencies,
Danmuku *parent);
~Module();
QWidget *getWidget() const;

protected:
Module *getModule(const QString &name);

public:
ModuleMetadata moduleMetadata;
static Danmuku *danmuku;

protected:
QWidget *widget;
static Module *getModule(const QString &name);
};

#define MODULE
Expand Down
2 changes: 1 addition & 1 deletion src/modules/danmu_display/danmu_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "ui_danmu_window.h"

DanmuDisplay::DanmuDisplay() : Module("danmu_display") {
DanmuDisplay::DanmuDisplay(Danmuku *parent) : Module("danmu_display", {}, parent) {
config = nullptr;
updateFollowersCountTimer = nullptr;

Expand Down
2 changes: 1 addition & 1 deletion src/modules/danmu_display/danmu_display.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class DanmuDisplay : public Module {
MODULE

public:
DanmuDisplay();
DanmuDisplay(Danmuku *parent);
~DanmuDisplay();

private:
Expand Down
14 changes: 14 additions & 0 deletions src/modules/danmu_display/danmu_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

#include <windows.h>

#include <QFile>
#include <QMouseEvent>

#include "ui_danmu_window.h"

#ifdef Q_CC_MSVC
#pragma comment(lib, "user32.lib")
#endif

DanmuWindow::DanmuWindow(QWidget *parent)
: QWidget(parent), ui(new Ui::DanmuWindow) { // deleted in ~DanmuWindow
Expand All @@ -27,6 +30,17 @@ DanmuWindow::DanmuWindow(QWidget *parent)
ui->list_danmu->setAttribute(Qt::WA_TransparentForMouseEvents);
ui->list_gift->setAttribute(Qt::WA_TransparentForMouseEvents);

// Qss
QFile qss(":/modules/danmu_display/stylesheet/danmu_window.qss");
if (qss.open(QFile::ReadOnly)) {
qDebug("QSS loaded.");
QString stylesheet = QLatin1String(qss.readAll());
setStyleSheet(stylesheet);
qss.close();
} else {
qWarning("Failed to load QSS stylesheet (danmu_window.qss).");
}

show();
}

Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions src/modules/danmu_display/stylesheet/stylesheet.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/modules/danmu_display/stylesheet">
<file>danmu_window.qss</file>
</qresource>
</RCC>
15 changes: 8 additions & 7 deletions src/modules/live_room/live_room.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

#include "utils/network.h"

LiveRoom::LiveRoom() : Module("live_room") {
LiveRoom::LiveRoom(Danmuku *parent) : Module("live_room", {}, parent) {
protocal = nullptr;

// Control UI
QHBoxLayout *layout = new QHBoxLayout(widget); // deleted by QT

input_roomID = new QLineEdit(widget); // deleted by QT
input_roomID->setPlaceholderText(tr("直播间号"));
#ifdef QT_DEBUG
input_roomID->setText("14003442"); // debug
#endif
Expand Down Expand Up @@ -76,9 +77,7 @@ void LiveRoom::stop() {
qDebug("Exit stop");
}

QObject *LiveRoom::getProtocal() {
return protocal;
}
QObject *LiveRoom::getProtocal() { return protocal; }

QJsonObject LiveRoom::requestDanmuInfo() {
QJsonObject response = requestJsonResponse(
Expand Down Expand Up @@ -113,7 +112,9 @@ void LiveRoom::updateFollowersCount() {
qWarning("Error occured in followersCountUpdated.");
return;
}
qDebug() << "followersCountUpdated:"
<< response["data"][(QString) "follower"].toInt();
emit followersCountUpdated(response["data"][(QString) "follower"].toInt());
qDebug()
<< "followersCountUpdated:"
<< response[QStringLiteral("data")][QStringLiteral("follower")].toInt();
emit followersCountUpdated(
response[QStringLiteral("data")][QStringLiteral("follower")].toInt());
}
2 changes: 1 addition & 1 deletion src/modules/live_room/live_room.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class LiveRoom : public Module {
MODULE

public:
LiveRoom();
LiveRoom(Danmuku* parent);
~LiveRoom();

private:
Expand Down
4 changes: 4 additions & 0 deletions src/modules/live_room/protocal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ void Protocal::recvData(const QByteArray& data) {
while (pack.length() != 0) {
qDebug() << "pack:" << pack;

if (pack == "[object Object]") { // heartbeat reply
break;
}

head = pack.left(WS_PACKAGE_HEADER_TOTAL_LENGTH);

int packLen = bytesToInt32(head.mid(WS_PACKAGE_OFFSET, 4));
Expand Down
7 changes: 7 additions & 0 deletions src/stylesheet/danmuku.qss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
QPushButton {
padding: 5px;
}

QLineEdit {
padding: 4px;
}
2 changes: 1 addition & 1 deletion src/stylesheet/stylesheet.qrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<RCC>
<qresource prefix="/stylesheet">
<file>display.qss</file>
<file>danmuku.qss</file>
</qresource>
</RCC>

0 comments on commit f22f91e

Please sign in to comment.