OfficeAssistant_Win10/OfficeAssistant_msvc/mainscreen.cpp

107 lines
3.3 KiB
C++
Raw Blame History

//
// Created by HW on 2023/07/27.
//
// You may need to build the project (run Qt uic code generator) to get "ui_MainScreen.h" resolved
#include "mainscreen.h"
#include "ui_MainScreen.h"
#include "netio.h"
#include <QPixmap>
#include <exception>
#include <QResizeEvent>
#include "globalvariables.h"
#include "settingsscreen.h"
#include "mythread.h"
MainScreen::MainScreen(QWidget *parent) :
QWidget(parent), ui(new Ui::MainScreen) {
ui->setupUi(this);
setContentsMargins(0, 0, 0, 0);
button = new QPushButton(this);
button->setHidden(true);
button->setStyleSheet("border-style:none;padding:10px;border-radius:5px;background-color:#FFFFFF");
//Plus Math icon by Icons8
QString dir = QApplication::applicationDirPath();
icon = new QIcon(dir + QString::fromLocal8Bit("/images/add.png"));
button->setIcon(*icon);
layout = new QHBoxLayout;
QSizePolicy sizePolicy(QSizePolicy::Policy::Expanding, QSizePolicy::QSizePolicy::Expanding);
button->setSizePolicy(sizePolicy);
miniblink = new QMiniBlink(this);
settingScreen = new SettingsScreen;
settingScreen->setHidden(true);
layout->addWidget(button, 1);
layout->addWidget(miniblink, 4);
layout->addWidget(settingScreen);
this->setLayout(layout);
layout->setMargin(0);
//miniblink->setAttribute(Qt::WA_DeleteOnClose);
miniblink->show();
//miniblink->setSizePolicy(sizePolicy);
//thread = new MyThread(this,&miniblink);
//thread->start();
//miniblink->moveToThread(thread);
connect(this, &MainScreen::ondestroy, miniblink, &QMiniBlink::ondestroy);
connect(button, &QPushButton::pressed, this, &MainScreen::startWeChat);
connect(this, &MainScreen::started, miniblink, &QMiniBlink::init);
//connect(miniblink, SIGNAL(finish()), miniblink, SLOT(deleteLater()));
//connect(miniblink, SIGNAL(destroyed()), thread, SLOT(quit()));
//connect(thread, &QThread::finished, thread, &QThread::deleteLater);
while(miniblink==nullptr){}
connect(this, &MainScreen::changeUrl, miniblink, &QMiniBlink::switchUrl);
emit started();
}
MainScreen::~MainScreen() {
emit ondestroy();
layout->removeWidget(miniblink);
layout->removeWidget(settingScreen);
layout->removeWidget(button);
button->setIcon(QIcon(nullptr));
delete miniblink;
delete settingScreen;
delete button;
delete icon;
delete layout;
delete ui;
}
void MainScreen::firstUrl(QString url)
{
emit changeUrl(url);
}
void MainScreen::clickButton1(QString text, QString url) {
if (text == QString::fromLocal8Bit("΢<EFBFBD>Ŷ࿪")) {
button->setHidden(false);
miniblink->setHidden(false);
settingScreen->setHidden(true);
emit changeUrl(url);
}
else if (text == QString::fromLocal8Bit("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")){
miniblink->setHidden(true);
button->setHidden(true);
settingScreen->setHidden(false);
}
else {
button->setHidden(true);
miniblink->setHidden(false);
settingScreen->setHidden(true);
emit changeUrl(url);
}
}
void MainScreen::startWeChat() {
QString path = QApplication::applicationDirPath();
QString exe = path + "/wxdk.exe";
ShellExecute(GetDesktopWindow(), L"open", exe.toStdWString().c_str(), L"79c86fb12b36dfa33d1a537c9af100b4c7928a9c", path.toStdWString().c_str(), SW_SHOW);
}
//void MainScreen::resizeEvent(QResizeEvent *event) {
// QWidget::resizeEvent(event);
// //broswer->resize(event->size().width() / 5 * 4, event->size().height());
// miniblink->resize(event->size().width() / 5 * 4, event->size().height());
// miniblink->update();
//}