第一阶段只差兼容性问题了

This commit is contained in:
Mike Solar
2023-08-01 23:51:40 +08:00
parent 9b53ef9764
commit 6a695e8a03
20 changed files with 167 additions and 54 deletions

View File

@ -9,6 +9,7 @@
#include "config.h"
#include <QTimer>
#include <QtSvg/QtSvg>
#include <QPixmap>
#include "mainwindowlayout.h"
#include "globalvariables.h"
#ifdef _DEBUG
@ -20,30 +21,50 @@ QString url_param;
NavBar::NavBar(ConfigResponse *configResponse, MainScreen *mainScreen,QWidget *parent) :
QWidget(parent), ui(new Ui::NavBar) {
ui->setupUi(this);
this->setAttribute(Qt::WA_DeleteOnClose);
//this->setAttribute(Qt::WA_DeleteOnClose);
buffer = new QByteArray;
/*QString style = "background-color:";
style += configResponse->basic.backgroud_color.toUpper();
style += ";";
setStyleSheet(style);*/
//setStyleSheet("margin:0");
setContentsMargins(0, 0, 0, 0);
if (configResponse->succeed&&configResponse->menus.empty()!=true) {
getLogoFromInternet(configResponse);
}
else {
getLogoFromLocal();
}
this->setLayout(nullptr);
int n = buttonStructs.length();
int x = (width() - height()*n) / 2;
layout2 = new QHBoxLayout;
layout_right = new QHBoxLayout;
layout_left = new QHBoxLayout;
logo_label = new QLabel(this);
//*logo = logo->scaled(this->width() / (5 / scale), this->height());
logo_label->setScaledContents(true);
logo_label->setPixmap(QPixmap::fromImage(*logo));
logo_label->setMaximumHeight(parent->height() / 8);
layout_left->addWidget(logo_label);
layout_left->setAlignment(Qt::AlignCenter);
for (auto buttonStruct : buttonStructs) {
MyButton *myButton = new MyButton(buttonStruct, height(), height(), &buttons,this);
myButton->setGeometry(x, 0, height(), height());
myButton->show();
myButton->setMaximumHeight(parent->height() / 8);
layout_right->addWidget(myButton);
//myButton->show();
connect(myButton, &MyButton::clicked1, mainWindowLayout, &MainWindowLayout::clickButton);
x += height();
buttons << myButton;
}
layout_right->setAlignment(Qt::AlignLeft);
if (!buttonStructs.empty()) {
connect(this, &NavBar::firstUrl, mainScreen, &MainScreen::firstUrl);
emit firstUrl(buttonStructs[0].url);
}
layout2->addLayout(layout_left, 1);
layout2->addLayout(layout_right, 4);
layout_right->setMargin(0);
layout2->setMargin(0);
//layout2->setAlignment(Qt::AlignJustify);
this->setLayout(layout2);
logo_label->show();
}
NavBar::~NavBar() {
@ -52,8 +73,15 @@ NavBar::~NavBar() {
delete buttonStruct.image_cover;
}
for(auto button : buttons){
layout_right->removeWidget(button);
delete button;
}
layout2->removeWidget(logo_label);
delete logo_label;
delete logo;
//delete layout_left;
delete layout_right;
delete layout2;
delete ui;
}
@ -66,20 +94,14 @@ void NavBar::paintEvent(QPaintEvent *event) {
QRectF rect(0, 0, this->width(), this->height());
painter.fillRect(rect, qColor);
QRectF rect2(0, 0, this->width()/5, this->height());
painter.drawImage(rect2, *logo);
}
void NavBar::resizeEvent(QResizeEvent *event) {
QWidget::resizeEvent(event);
int n = buttonStructs.length();
int x = (width() - height()*n) / 2;
for(auto button:buttons){
button->setSize(event->size().height(),event->size().height(),event->size().height(),event->size().height());
button->setGeometry(x, 0, event->size().height(), event->size().height());
x += event->size().height();
button->setMaximumSize(event->size().height(), event->size().height());
button->update();
}
logo_label->setMaximumSize(event->size().width() / 5, event->size().height());
}
void NavBar::getLogoFromInternet(ConfigResponse *configResponse) {
qColor.setNamedColor(configResponse->basic.backgroud_color);
@ -98,10 +120,8 @@ void NavBar::getLogoFromInternet(ConfigResponse *configResponse) {
delete request_logo;
if (downloadSuccess == true) {
*buffer = reply->readAll();
QSvgRenderer *render_logo = new QSvgRenderer(*buffer);
logo = new QImage(400, 200, QImage::Format_ARGB32);
QPainter painter_logo(logo);
render_logo->render(&painter_logo);
logo = new QImage();
logo->loadFromData(*buffer);
buffer->clear();
for (auto button : configResponse->menus) {
QUrl url_image(button.img);