From 28909f376ee4eb2e58af110e6618baecdcfa744f Mon Sep 17 00:00:00 2001 From: Apex Liu Date: Fri, 20 Sep 2019 00:42:37 +0800 Subject: [PATCH] =?UTF-8?q?=E9=83=A8=E5=88=86=E8=A7=A3=E5=86=B3win?= =?UTF-8?q?=E4=B8=8B=E6=92=AD=E6=94=BE=E5=99=A8=E4=B8=AD=E6=96=87=E4=B9=B1?= =?UTF-8?q?=E7=A0=81=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/tp-player/dlgmessage.cpp | 21 ----------- client/tp-player/dlgmessage.h | 24 ------------ client/tp-player/dlgmessage.ui | 32 ---------------- client/tp-player/main.cpp | 6 +++ client/tp-player/mainwindow.cpp | 37 +++++++++---------- client/tp-player/mainwindow.h | 5 +-- client/tp-player/mainwindow.ui | 5 +++ client/tp-player/thr_play.cpp | 5 ++- client/tp-player/tp-player.pro | 65 ++++++++++++++++----------------- 9 files changed, 65 insertions(+), 135 deletions(-) delete mode 100644 client/tp-player/dlgmessage.cpp delete mode 100644 client/tp-player/dlgmessage.h delete mode 100644 client/tp-player/dlgmessage.ui diff --git a/client/tp-player/dlgmessage.cpp b/client/tp-player/dlgmessage.cpp deleted file mode 100644 index 5df1bb5..0000000 --- a/client/tp-player/dlgmessage.cpp +++ /dev/null @@ -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); -} diff --git a/client/tp-player/dlgmessage.h b/client/tp-player/dlgmessage.h deleted file mode 100644 index 8dbbe7d..0000000 --- a/client/tp-player/dlgmessage.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef DLGMESSAGE_H -#define DLGMESSAGE_H - -#include - -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 diff --git a/client/tp-player/dlgmessage.ui b/client/tp-player/dlgmessage.ui deleted file mode 100644 index 71a5631..0000000 --- a/client/tp-player/dlgmessage.ui +++ /dev/null @@ -1,32 +0,0 @@ - - - DlgMessage - - - - 0 - 0 - 400 - 120 - - - - - - - - - 10 - 10 - 59 - 16 - - - - - - - - - - diff --git a/client/tp-player/main.cpp b/client/tp-player/main.cpp index bbf4c1a..2131644 100644 --- a/client/tp-player/main.cpp +++ b/client/tp-player/main.cpp @@ -3,6 +3,7 @@ #include #include #include +#include // 编译出来的可执行程序复制到单独目录,然后执行 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(); diff --git a/client/tp-player/mainwindow.cpp b/client/tp-player/mainwindow.cpp index f4acfbb..9c56f4f 100644 --- a/client/tp-player/mainwindow.cpp +++ b/client/tp-player/mainwindow.cpp @@ -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 + ); + diff --git a/client/tp-player/mainwindow.h b/client/tp-player/mainwindow.h index dbcdb09..ca7fe78 100644 --- a/client/tp-player/mainwindow.h +++ b/client/tp-player/mainwindow.h @@ -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 diff --git a/client/tp-player/mainwindow.ui b/client/tp-player/mainwindow.ui index ecdf9ac..b296c52 100644 --- a/client/tp-player/mainwindow.ui +++ b/client/tp-player/mainwindow.ui @@ -10,6 +10,11 @@ 360 + + + 微软雅黑 Light + + Teleport Replayer diff --git a/client/tp-player/thr_play.cpp b/client/tp-player/thr_play.cpp index 9d133d0..1000653 100644 --- a/client/tp-player/thr_play.cpp +++ b/client/tp-player/thr_play.cpp @@ -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); diff --git a/client/tp-player/tp-player.pro b/client/tp-player/tp-player.pro index a7ca8e7..cffb1d5 100644 --- a/client/tp-player/tp-player.pro +++ b/client/tp-player/tp-player.pro @@ -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