kylin-nm/plugins/netconnect/deviceframe.cpp

74 lines
2.4 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 -*-
*
2024-01-26 11:07:17 +08:00
* Copyright (C) 2023, KylinSoft Co., Ltd.
2022-07-05 10:13:48 +08:00
*
* 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-07-05 10:13:48 +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.
*
*/
2021-10-27 12:28:16 +08:00
#include "deviceframe.h"
2023-04-07 14:20:19 +08:00
#include <QPainterPath>
2021-10-27 12:28:16 +08:00
2022-10-13 09:47:44 +08:00
#define LAYOUT_MARGINS 16,0,16,0
2021-10-27 12:28:16 +08:00
#define FRAME_HEIGHT 58
2021-12-01 11:07:21 +08:00
#define RADIUS 6.0
2021-10-27 12:28:16 +08:00
DeviceFrame::DeviceFrame(QString devName, QWidget *parent) : QFrame(parent)
{
this->setFrameShape(QFrame::Box);
this->setFixedHeight(FRAME_HEIGHT);
QHBoxLayout *deviceLayout = new QHBoxLayout(this);
deviceLayout->setContentsMargins(LAYOUT_MARGINS);
setLayout(deviceLayout);
deviceLabel = new QLabel(this);
dropDownLabel = new DrownLabel(devName, this);
2023-04-12 16:46:45 +08:00
// deviceSwitch = new KSwitchButton(this);
// deviceSwitch->installEventFilter(this);
2021-10-27 12:28:16 +08:00
deviceLayout->addWidget(deviceLabel);
deviceLayout->addStretch();
2023-04-12 16:46:45 +08:00
deviceLayout->addWidget(dropDownLabel);/*
deviceLayout->addWidget(deviceSwitch);*/
2021-10-27 12:28:16 +08:00
}
2022-08-23 13:42:29 +08:00
bool DeviceFrame::eventFilter(QObject *w,QEvent *e)
2021-10-27 12:28:16 +08:00
{
2023-04-12 16:46:45 +08:00
// if (w == deviceSwitch) {
// if (e->type() == QEvent::MouseButtonPress) {
// emit deviceSwitchClicked(!deviceSwitch->isChecked());
// return true;
// }
// }
2022-08-23 16:36:42 +08:00
return QFrame::eventFilter(w, e);
2021-10-27 12:28:16 +08:00
}
2021-12-01 11:07:21 +08:00
void DeviceFrame::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;
path.addRoundedRect (rect, RADIUS, RADIUS);
QRect temp_rect(rect.left(), rect.top() + rect.height()/2, rect.width(), rect.height()/2);
path.addRect(temp_rect);
painter.drawPath(path);
QFrame::paintEvent(event);
}