2023-08-18 19:09:55 +08:00
|
|
|
|
#include "minibutton.h"
|
2023-08-13 12:16:22 +08:00
|
|
|
|
#include <QPainter>
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#include "globalvariables.h"
|
|
|
|
|
|
|
|
|
|
MiniButton::MiniButton(QString orig_name, QString op, QWidget* parent)
|
|
|
|
|
{
|
|
|
|
|
this->orig_name = orig_name;
|
|
|
|
|
|
|
|
|
|
this->op = op;
|
|
|
|
|
connect(this, &MiniButton::click, this, &MiniButton::onclick2);
|
|
|
|
|
}
|
|
|
|
|
MiniButton::MiniButton(ButtonStruct button_struct, QWidget *parent)
|
|
|
|
|
: QPushButton(parent)
|
|
|
|
|
{
|
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
connect(this, &MiniButton::click, this, &MiniButton::onclick1);
|
|
|
|
|
this->button_struct = button_struct;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MiniButton::~MiniButton()
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
void MiniButton::paintEvent(QPaintEvent* event)
|
|
|
|
|
{
|
|
|
|
|
QPushButton::paintEvent(event);
|
|
|
|
|
setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
QRect rect(0, 0, this->width(), this->height());
|
|
|
|
|
QPainter painter(this);
|
2023-08-21 15:10:19 +08:00
|
|
|
|
q_color.setNamedColor(background_color);
|
|
|
|
|
|
2023-08-13 12:16:22 +08:00
|
|
|
|
painter.fillRect(rect, q_color);
|
|
|
|
|
int text_x = (width() - TEXT_SIZE * text().length() * scale * 3) / 2;
|
|
|
|
|
int text_y = (height()- TEXT_SIZE * scale * 3)/2;
|
|
|
|
|
QFont ft;
|
|
|
|
|
ft.setPixelSize(TEXT_SIZE);
|
|
|
|
|
QRectF text_rect(text_x, text_y, TEXT_SIZE * text().length() * scale * 3, TEXT_SIZE * scale * 3);
|
2023-08-21 15:10:19 +08:00
|
|
|
|
painter.setPen(text_color);
|
2023-08-13 12:16:22 +08:00
|
|
|
|
painter.drawText(text_rect, Qt::AlignCenter, text());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MiniButton::onclick1()
|
|
|
|
|
{
|
|
|
|
|
emit click1(button_struct.op, button_struct.func, button_struct.path, button_struct.url);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MiniButton::onclick2()
|
|
|
|
|
{
|
|
|
|
|
emit click2(this->orig_name,this->op);
|
|
|
|
|
}
|
|
|
|
|
|