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

110 lines
3.5 KiB
C++
Raw Normal View History

2022-07-05 10:13:48 +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
* the Free Software Foundation; either version 2 of the License, or
* (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.
*
*/
2021-10-27 12:28:16 +08:00
#include "addnetbtn.h"
#include <QEvent>
#include <QHBoxLayout>
#include <QVariant>
2021-12-01 11:07:21 +08:00
#include <QPainter>
#include <QPainterPath>
#define RADIUS 6.0
2021-10-27 12:28:16 +08:00
AddNetBtn::AddNetBtn(bool isWlan, QWidget *parent) : QPushButton(parent)
2021-10-27 12:28:16 +08:00
{
this->setObjectName("this");
this->setMinimumSize(QSize(580, 60));
this->setMaximumSize(QSize(16777215, 60));
this->setProperty("useButtonPalette", true);
2022-06-01 17:13:25 +08:00
this->setFlat(true);
QPalette pal = this->palette();
QColor color = pal.color(QPalette::Button);
color.setAlphaF(0.5);
pal.setColor(QPalette::Button, color);
this->setPalette(pal);
2022-10-31 17:51:35 +08:00
QHBoxLayout *addLyt = new QHBoxLayout(this);
2021-10-27 12:28:16 +08:00
2022-10-31 17:51:35 +08:00
QLabel *iconLabel = new QLabel(this);
textLabel = new QLabel(this);
if (isWlan) {
textLabel->setText(tr("Add Others"));
addLyt->addSpacing(8);
addLyt->addWidget(textLabel);
} else {
textLabel->setText(tr("Add WiredNetork"));
QIcon mAddIcon = QIcon::fromTheme("list-add-symbolic");
iconLabel->setPixmap(mAddIcon.pixmap(mAddIcon.actualSize(QSize(24, 24))));
iconLabel->setProperty("useIconHighlightEffect", true);
iconLabel->setProperty("iconHighlightEffectMode", 1);
addLyt->addStretch();
addLyt->addWidget(iconLabel);
addLyt->addWidget(textLabel);
}
2021-10-27 12:28:16 +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);
}
2021-12-01 11:07:21 +08:00
void AddNetBtn::paintEvent(QPaintEvent *event)
{
QPalette pal = this->palette();
QPainter painter(this);
painter.setRenderHint(QPainter:: Antialiasing, true); //设置渲染,启动反锯齿
painter.setPen(Qt::NoPen);
painter.setBrush(pal.color(QPalette::Base));
QRect rect = this->rect();
QPainterPath path;
2022-06-01 17:13:25 +08:00
//设置起点
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());
2021-12-01 11:07:21 +08:00
painter.drawPath(path);
QPushButton::paintEvent(event);
}