kylin-nm/plugins/component/AddBtn/addnetbtn.cpp

112 lines
3.5 KiB
C++
Raw Normal View History

2022-11-18 14:09:12 +08:00
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
2023-04-21 10:03:57 +08:00
* the Free Software Foundation; either version 3 of the License, or
2022-11-18 14:09:12 +08:00
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
2022-06-17 18:48:59 +08:00
#include "addnetbtn.h"
#include <QEvent>
#include <QHBoxLayout>
2023-04-06 14:09:59 +08:00
#include <QLabel>
2022-06-17 18:48:59 +08:00
#include <QVariant>
#include <QPainter>
#include <QPainterPath>
#define RADIUS 6.0
AddNetBtn::AddNetBtn(bool isWlan, QWidget *parent) : QPushButton(parent)
{
this->setObjectName("this");
this->setMinimumSize(QSize(580, 60));
this->setMaximumSize(QSize(16777215, 60));
this->setProperty("useButtonPalette", true);
this->setFlat(true);
2021-10-27 12:28:16 +08:00
2023-04-06 14:09:59 +08:00
QHBoxLayout *addLyt = new QHBoxLayout;
2022-06-17 18:48:59 +08:00
2022-11-18 14:09:12 +08:00
QLabel *iconLabel = new QLabel(this);
2023-04-10 17:38:17 +08:00
m_textLabel = new QLabel(this);
2022-06-17 18:48:59 +08:00
if (isWlan) {
2023-04-10 17:38:17 +08:00
m_textLabel->setText(tr("Add Others"));
2022-06-17 18:48:59 +08:00
addLyt->addSpacing(8);
2023-04-10 17:38:17 +08:00
addLyt->addWidget(m_textLabel);
2022-06-17 18:48:59 +08:00
} else {
2023-04-10 17:38:17 +08:00
m_textLabel->setText(tr("Add WiredNetork"));
2022-06-17 18:48:59 +08:00
QIcon mAddIcon = QIcon::fromTheme("list-add-symbolic");
2023-04-10 17:38:17 +08:00
iconLabel->setPixmap(mAddIcon.pixmap(mAddIcon.actualSize(QSize(16, 16))));
2023-04-06 14:09:59 +08:00
iconLabel->setProperty("useIconHighlightEffect", 0x2);
// iconLabel->setProperty("iconHighlightEffectMode", 1);
2022-06-17 18:48:59 +08:00
addLyt->addStretch();
addLyt->addWidget(iconLabel);
2023-04-10 17:38:17 +08:00
addLyt->addWidget(m_textLabel);
2022-06-17 18:48:59 +08:00
}
addLyt->addStretch();
this->setLayout(addLyt);
}
AddNetBtn::~AddNetBtn()
{
}
void AddNetBtn::enterEvent(QEvent *event){
Q_EMIT enterWidget();
QPushButton::enterEvent(event);
}
void AddNetBtn::leaveEvent(QEvent *event){
Q_EMIT leaveWidget();
QPushButton::leaveEvent(event);
}
void AddNetBtn::paintEvent(QPaintEvent *event)
{
2023-04-06 14:09:59 +08:00
QPalette pal = qApp->palette();
2022-06-17 18:48:59 +08:00
QPainter painter(this);
painter.setRenderHint(QPainter:: Antialiasing, true); //设置渲染,启动反锯齿
painter.setPen(Qt::NoPen);
2023-04-11 15:34:43 +08:00
2023-04-06 14:09:59 +08:00
painter.setBrush(this->palette().base().color());
QColor color = pal.color(QPalette::Button);
color.setAlphaF(0.5);
pal.setColor(QPalette::Button, color);
this->setPalette(pal);
2022-06-17 18:48:59 +08:00
QRect rect = this->rect();
QPainterPath path;
//设置起点
path.moveTo(rect.topLeft().x(), rect.topLeft().y());
path.lineTo(rect.bottomLeft().x(), rect.bottomLeft().y() - RADIUS);
//绘制圆角 圆弧以外切圆的270度位置为起点逆时针画圆弧运行90度结束
path.arcTo(QRect(QPoint(rect.bottomLeft().x(), rect.bottomLeft().y() - (RADIUS * 2)), QSize(RADIUS * 2, RADIUS * 2)), 180, 90);
path.lineTo(rect.bottomRight().x() - RADIUS, rect.bottomRight().y());
//画圆弧
path.arcTo(QRect(QPoint(rect.bottomRight().x() - (RADIUS * 2), rect.bottomRight().y() - (RADIUS * 2)), QSize(RADIUS * 2, RADIUS * 2)), 270, 90);
path.lineTo(rect.topRight());
path.lineTo(rect.topLeft());
painter.drawPath(path);
QPushButton::paintEvent(event);
}