部分解决win下播放器中文乱码问题。

pull/175/head^2
Apex Liu 2019-09-20 00:42:37 +08:00
parent 6aa5c046df
commit 28909f376e
9 changed files with 65 additions and 135 deletions

View File

@ -1,21 +0,0 @@
#include "dlgmessage.h"
#include "ui_dlgmessage.h"
DlgMessage::DlgMessage(QWidget *parent) :
QDialog(parent),
ui(new Ui::DlgMessage)
{
ui->setupUi(this);
}
DlgMessage::~DlgMessage()
{
delete ui;
}
void DlgMessage::set_text(const QString& text) {
// TODO: 根据文字长度,父窗口宽度,调节对话框宽度,最大不超过父窗口宽度的 2/3。
// 调节label的宽度和高度并调节对话框高度最后将对话框调整到父窗口居中的位置。
ui->label->setText(text);
}

View File

@ -1,24 +0,0 @@
#ifndef DLGMESSAGE_H
#define DLGMESSAGE_H
#include <QDialog>
namespace Ui {
class DlgMessage;
}
class DlgMessage : public QDialog
{
Q_OBJECT
public:
explicit DlgMessage(QWidget *parent = nullptr);
~DlgMessage();
void set_text(const QString& text);
private:
Ui::DlgMessage *ui;
};
#endif // DLGMESSAGE_H

View File

@ -1,32 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DlgMessage</class>
<widget class="QDialog" name="DlgMessage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>120</height>
</rect>
</property>
<property name="windowTitle">
<string/>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>59</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string/>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -3,6 +3,7 @@
#include <QCommandLineParser>
#include <QDebug>
#include <QMessageBox>
#include <QTextCodec>
// 编译出来的可执行程序复制到单独目录,然后执行 windeployqt 应用程序文件名
// 即可自动将依赖的动态库等复制到此目录中。有些文件是多余的,可以酌情删除。
@ -47,6 +48,11 @@ int main(int argc, char *argv[])
QString resource = args.at(0);
qDebug() << resource;
// QTextCodec::setCodecForTr(QTextCodec::codecForName("GB2312"));
// QTextCodec::setCodecForLocale(QTextCodec::codecForName("GBK"));
// QTextCodec::setCodecForCStrings(QTextCodec::codecForName("GB2312"));
MainWindow w;
w.set_resource(resource);
w.show();

View File

@ -87,8 +87,6 @@ MainWindow::MainWindow(QWidget *parent) :
m_thr_play = nullptr;
m_play_state = PLAY_STATE_UNKNOWN;
m_msg_box = nullptr;
ui->setupUi(this);
ui->centralWidget->setMouseTracking(true);
@ -135,10 +133,6 @@ MainWindow::~MainWindow()
m_thr_play = nullptr;
}
if(m_msg_box) {
delete m_msg_box;
}
delete ui;
}
@ -190,7 +184,7 @@ void MainWindow::paintEvent(QPaintEvent *e)
{
QRect rc_draw = e->rect();
QRect rc(100, 100, m_img_message.width(), m_img_message.height());
QRect rc(m_rc_message);
//rc.moveTo(m_rc.left()+rc.left(), m_rc.top() + rc.top());
int from_x = max(rc_draw.left(), rc.left()) - rc.left();
@ -243,9 +237,6 @@ void MainWindow::_do_update_data(update_data* dat) {
UpdateDataHelper data_helper(dat);
if(dat->data_type() == TYPE_DATA) {
if(m_msg_box) {
m_msg_box->hide();
}
if(dat->data_len() <= sizeof(TS_RECORD_PKG)) {
qDebug() << "invalid record package(1).";
@ -303,20 +294,28 @@ void MainWindow::_do_update_data(update_data* dat) {
else if(dat->data_type() == TYPE_MESSAGE) {
QPainter pp(&m_canvas);
QFontMetrics fm = pp.fontMetrics();
QRect rcWin(0, 0, m_canvas.width(), m_canvas.height());
QRect rc = fm.boundingRect(rcWin, Qt::AlignLeft|Qt::TextWordWrap, dat->message());
qDebug("message, w=%d, h=%d", rc.width(), rc.height());
// int w = fm.width(dat->message());
// int h = fm.height();
// qDebug("message, w=%d, h=%d", w, h);
pp.drawText(rcWin, Qt::AlignLeft|Qt::TextDontPrint, dat->message(), &m_rc_message);
m_img_message = QPixmap(rc.width() + 30, rc.height() + 30);
qDebug("message, w=%d, h=%d", m_rc_message.width(), m_rc_message.height());
m_rc_message.setWidth(m_rc_message.width()+60);
m_rc_message.setHeight(m_rc_message.height()+60);
m_img_message = QPixmap(m_rc_message.width(), m_rc_message.height());
m_img_message.fill(Qt::transparent);
QPainter pm(&m_img_message);
pm.setPen(QColor(255,255,255,153));
pm.fillRect(rc, QColor(0,0,0,190));
pm.drawText(rc, Qt::AlignLeft|Qt::TextWordWrap, dat->message());
pm.fillRect(m_rc_message, QColor(0,0,0,190));
QRect rcText(m_rc_message);
rcText.setLeft(30);
rcText.setTop(30);
pm.drawText(rcText, Qt::AlignLeft, dat->message());
m_rc_message.moveTo(
(m_canvas.width() - m_rc_message.width())/2,
(m_canvas.height() - m_rc_message.height())/2
);

View File

@ -8,7 +8,6 @@
#include "thr_play.h"
#include "update_data.h"
#include "record_format.h"
#include "dlgmessage.h"
#define PLAY_STATE_UNKNOWN 0
#define PLAY_STATE_RUNNING 1
@ -76,10 +75,8 @@ private:
int m_play_state;
//QMessageBox* m_msg_box;
DlgMessage* m_msg_box;
QPixmap m_img_message;
QRect m_rc_message;
};
#endif // MAINWINDOW_H

View File

@ -10,6 +10,11 @@
<height>360</height>
</rect>
</property>
<property name="font">
<font>
<family>微软雅黑 Light</family>
</font>
</property>
<property name="windowTitle">
<string>Teleport Replayer</string>
</property>

View File

@ -75,6 +75,7 @@ void ThreadPlay::run() {
qDebug() << "DOWNLOAD";
m_need_download = true;
// "正在缓存录像数据,请稍候..."
_notify_message("正在缓存录像数据,请稍候...");
m_thr_download = new ThreadDownload(m_res);
@ -207,7 +208,9 @@ void ThreadPlay::run() {
tpd_filename.sprintf("%stp-rdp-%d.tpd", path_base.toStdString().c_str(), fidx+1);
// for test.
msg.sprintf("无法打开录像数据文件!\n\n%s", tpd_filename.toStdString().c_str());
msg = QString::fromLocal8Bit("无法打开录像数据文件!\n\n");
//msg.sprintf("无法打开录像数据文件!\n\n%s", tpd_filename.toStdString().c_str());
msg += tpd_filename.toStdString().c_str();
_notify_message(msg);
QFile f_dat(tpd_filename);

View File

@ -1,34 +1,31 @@
TEMPLATE = app
TARGET = tp-player
QT += core gui widgets
HEADERS += \
dlgmessage.h \
mainwindow.h \
bar.h \
thr_download.h \
thr_play.h \
update_data.h \
record_format.h \
rle.h
SOURCES += \
dlgmessage.cpp \
main.cpp \
mainwindow.cpp \
bar.cpp \
thr_download.cpp \
thr_play.cpp \
update_data.cpp \
rle.c
RESOURCES += \
tp-player.qrc
RC_FILE += \
tp-player.rc
FORMS += \
dlgmessage.ui \
mainwindow.ui
TEMPLATE = app
TARGET = tp-player
QT += core gui widgets
HEADERS += \
mainwindow.h \
bar.h \
thr_download.h \
thr_play.h \
update_data.h \
record_format.h \
rle.h
SOURCES += \
main.cpp \
mainwindow.cpp \
bar.cpp \
thr_download.cpp \
thr_play.cpp \
update_data.cpp \
rle.c
RESOURCES += \
tp-player.qrc
RC_FILE += \
tp-player.rc
FORMS += \
mainwindow.ui