1 /* 2 * Copyright (c) 2020-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef GRAPHIC_LITE_MAIN_WIDGET_H 17 #define GRAPHIC_LITE_MAIN_WIDGET_H 18 19 #include <QImage> 20 #include <QJsonDocument> 21 #include <QJsonObject> 22 #include <QLocalServer> 23 #include <QLocalSocket> 24 #include <QMessageBox> 25 #include <QMouseEvent> 26 #include <QPainter> 27 #include <QWidget> 28 29 #include "common/graphic_startup.h" 30 #include "gui_thread.h" 31 #include "key_input.h" 32 #include "monitor.h" 33 #include "mouse_input.h" 34 #include "mousewheel_input.h" 35 #include "scoket_thread.h" 36 #include "task_thread.h" 37 #include "ui_mainwidget.h" 38 39 QT_BEGIN_NAMESPACE 40 namespace Ui { 41 class MainWidget; 42 } 43 QT_END_NAMESPACE 44 45 namespace OHOS { 46 class MainWidget : public QWidget { 47 Q_OBJECT 48 49 public: 50 explicit MainWidget(QWidget* parent = nullptr); 51 ~MainWidget(); 52 void CreateGUIThread(); 53 void CreateTaskThread(); 54 void CreateSocketThread(); 55 56 protected: 57 void mouseMoveEvent(QMouseEvent* event) override; 58 void mousePressEvent(QMouseEvent* event) override; 59 void mouseReleaseEvent(QMouseEvent* event) override; 60 void wheelEvent(QWheelEvent* event) override; 61 void paintEvent(QPaintEvent* event) override; 62 void keyPressEvent(QKeyEvent* event) override; 63 void keyReleaseEvent(QKeyEvent* event) override; 64 65 private: 66 Ui::MainWidget* ui_; 67 QImage img_; 68 uint32_t width_; 69 uint32_t height_; 70 GUIThread* guiThread_; 71 TaskThread* taskThread_; 72 SocketThread* socketThread_; 73 74 public slots: UpdatePaintSlot(uint32_t * tftFb,uint32_t imgWidth,uint32_t imgHeight)75 void UpdatePaintSlot(uint32_t* tftFb, uint32_t imgWidth, uint32_t imgHeight) 76 { 77 img_ = QImage(imgWidth, imgHeight, QImage::Format_RGB32); 78 uint32_t* p = tftFb; 79 for (uint32_t i = 0; i < imgHeight; i++) { 80 for (uint32_t j = 0; j < imgWidth; j++) { 81 img_.setPixel(j, i, *p++); 82 } 83 } 84 update(); 85 }; 86 SendMsgSlot(size_t mainID)87 void SendMsgSlot(size_t mainID) 88 { 89 TcpScoketClient* tcpSocket = OHOS::TcpSocketClientManager::GetInstance()->GetTcpSocket(); 90 if (tcpSocket) { 91 QString str = QString::number(mainID); 92 printf("SendMsgSlot----------str=[%s] \n", str.toStdString().c_str()); 93 fflush(stdout); 94 tcpSocket->OnSendMessage(str); 95 } 96 } 97 }; 98 } // namespace OHOS 99 100 #endif // GRAPHIC_LITE_MAIN_WIDGET_H 101