You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
VideoClient98/src/mainwindow.cpp

220 lines
7.4 KiB
C++

#include "mainwindow.h"
// #include <QWKWidgets/qwkwidgetsglobal.h>
#include <QWKWidgets/widgetwindowagent.h>
#include <widgetframe/windowbar.h>
#include <widgetframe/windowbutton.h>
#include <QList>
#include <QtGui/QPainter>
#include "ui_mainwindow.h"
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include <QtGui/QActionGroup>
#else
#include <QtWidgets/QActionGroup>
#endif
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow) {
ui->setupUi(this);
// this->setWindowTitle("载荷视频播放软件");
installWindowAgent();
loadStyleSheet(Dark);
// apply the qss
QFile qssfile(":/Qss/qss.qss");
if (qssfile.open(QFile::ReadOnly)) {
QString style = QLatin1String(qssfile.readAll());
qApp->setStyleSheet(style);
qssfile.close();
} else {
qDebug() << "Open file fail " << Qt::endl;
}
// QList<QString> list;
// list.append("rtmp://liteavapp.qcloud.com/live/liteavdemoplayerstreamid");
// list.append("rtsp://182.92.130.23/nmyj/video");
// list.append("rtmp://182.92.130.23/nmyj/video");
// list.append("rtmp://ns8.indexforce.com/home/mystream");
// // ui->videoWidget->udpPlay("172.10.1.199", 13001);
// ui->videoWidget->setVedioSaveFileDirPath("./video");
// ui->videoWidget->play(list.at(1));
// ui->videoWidget->pushStream("udp://172.10.1.199:8009");
QString urlFile = "networkSettingInfo.ini";
QFile file(urlFile);
if (!file.exists()) {
file.open(QIODevice::WriteOnly);
file.close();
}
g_networkSettingInfo =
new QSettings("networkSettingInfo.ini", QSettings::IniFormat);
initSignalConnection();
initNotifyManager();
initNotifyMessageConnection();
}
MainWindow::~MainWindow() {
delete ui;
}
bool MainWindow::nativeEvent(const QByteArray &eventType, void *message,
qintptr *result) {
#ifdef Q_OS_WIN
MSG *msg = (MSG *)message;
if (msg->message == WM_SYSCOMMAND) {
if (61587 == msg->wParam) { // 单击事件
return true;
}
if (61539 == msg->wParam) { // 双击事件
return true;
}
}
#endif
return QMainWindow::nativeEvent(eventType, message, result);
}
void MainWindow::initSignalConnection() {
connect(ui->commandWidget, &CommandWidget::startConnectionSignal,
ui->videoWidget, &VideoWidget::udpPlay, Qt::UniqueConnection);
connect(ui->commandWidget, &CommandWidget::stopConnectionSignal,
ui->videoWidget, &VideoWidget::stopPlay, Qt::UniqueConnection);
}
void MainWindow::initNotifyMessageConnection() {
connect(ui->videoWidget, &VideoWidget::sendErrorMessageSignal, this,
&MainWindow::showMessageSlots);
connect(ui->commandWidget, &CommandWidget::sendErrorMessage, this,
&MainWindow::showMessageSlots);
}
void MainWindow::initNotifyManager() {
m_notifyManager = new NotifyManager(this, this);
m_notifyManager->setMaxCount(5);
m_notifyManager->setDisplayTime(2000);
m_notifyManager->setNotifyWndSize(400, 60);
}
void MainWindow::showMessageSlots(QString message, int type) {
if (m_notifyManager) {
m_notifyManager->notify(message, "", type, 3000);
}
}
void MainWindow::installWindowAgent() {
// 1. Setup window agent
windowAgent = new QWK::WidgetWindowAgent(this);
windowAgent->setup(this);
auto titleLabel = new QLabel();
titleLabel->setAlignment(Qt::AlignCenter);
titleLabel->setObjectName(QStringLiteral("win-title-label"));
#ifndef Q_OS_MAC
auto iconButton = new QWK::WindowButton();
iconButton->setEnabled(false);
iconButton->setObjectName(QStringLiteral("icon-button"));
iconButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
auto pinButton = new QWK::WindowButton();
pinButton->setCheckable(true);
pinButton->setObjectName(QStringLiteral("pin-button"));
pinButton->setProperty("system-button", true);
pinButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
auto minButton = new QWK::WindowButton();
minButton->setObjectName(QStringLiteral("min-button"));
minButton->setProperty("system-button", true);
minButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
auto maxButton = new QWK::WindowButton();
maxButton->setCheckable(true);
maxButton->setObjectName(QStringLiteral("max-button"));
maxButton->setProperty("system-button", true);
maxButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
auto closeButton = new QWK::WindowButton();
closeButton->setObjectName(QStringLiteral("close-button"));
closeButton->setProperty("system-button", true);
closeButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
#endif
auto windowBar = new QWK::WindowBar();
#ifndef Q_OS_MAC
windowBar->setIconButton(iconButton);
windowBar->setPinButton(pinButton);
windowBar->setMinButton(minButton);
windowBar->setMaxButton(maxButton);
windowBar->setCloseButton(closeButton);
#endif
// windowBar->setMenuBar(menuBar);
windowBar->setTitleLabel(titleLabel);
windowBar->setHostWidget(this);
windowAgent->setTitleBar(windowBar);
#ifndef Q_OS_MAC
windowAgent->setHitTestVisible(pinButton, true);
windowAgent->setSystemButton(QWK::WindowAgentBase::WindowIcon, iconButton);
windowAgent->setSystemButton(QWK::WindowAgentBase::Minimize, minButton);
windowAgent->setSystemButton(QWK::WindowAgentBase::Maximize, maxButton);
windowAgent->setSystemButton(QWK::WindowAgentBase::Close, closeButton);
#endif
#ifdef Q_OS_MAC
windowAgent->setSystemButtonAreaCallback([](const QSize &size) {
static constexpr const int width = 75;
return QRect(QPoint(size.width() - width, 0),
QSize(width, size.height())); //
});
#endif
setMenuWidget(windowBar);
#ifndef Q_OS_MAC
connect(windowBar, &QWK::WindowBar::pinRequested, this,
[this, pinButton](bool pin) {
if (isHidden() || isMinimized() || isMaximized() ||
isFullScreen()) {
return;
}
setWindowFlag(Qt::WindowStaysOnTopHint, pin);
show();
pinButton->setChecked(pin);
});
connect(windowBar, &QWK::WindowBar::minimizeRequested, this,
&QWidget::showMinimized);
connect(windowBar, &QWK::WindowBar::maximizeRequested, this,
[this, maxButton](bool max) {
if (max) {
showMaximized();
} else {
showNormal();
}
// It's a Qt issue that if a QAbstractButton::clicked triggers a
// window's maximization, the button remains to be hovered until
// the mouse move. As a result, we need to manually send leave
// events to the button.
// emulateLeaveEvent(maxButton);
});
connect(windowBar, &QWK::WindowBar::closeRequested, this, &QWidget::close);
#endif
}
void MainWindow::loadStyleSheet(Theme theme) {
if (!styleSheet().isEmpty() && theme == currentTheme) return;
currentTheme = theme;
if (QFile qss(theme == Dark ? QStringLiteral(":/Qss/dark-style.qss")
: QStringLiteral(":/Qss/light-style.qss"));
qss.open(QIODevice::ReadOnly | QIODevice::Text)) {
setStyleSheet(QString::fromUtf8(qss.readAll()));
Q_EMIT themeChanged();
}
}