mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 09:23:03 +00:00
fix: 调整已连接蓝牙的对勾位置
将对勾改成StateButton来实现,方便调整对勾位置,和UI设计图保持一致 Log: 优化蓝牙显示 Bug: https://pms.uniontech.com/zentao/bug-view-81641.html Change-Id: Ia8ff79b55ed7694cda78f02a07d53f97d89161e9
This commit is contained in:
parent
cacc83cbc1
commit
86ce60c15e
118
frame/util/statebutton.cpp
Normal file
118
frame/util/statebutton.cpp
Normal file
@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright (C) 2016 ~ 2018 Deepin Technology Co., Ltd.
|
||||
*
|
||||
* Author: chenwei <chenwei@uniontech.com>
|
||||
*
|
||||
* Maintainer: chenwei <chenwei@uniontech.com>
|
||||
*
|
||||
*
|
||||
* 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 3 of the License, or
|
||||
* 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "statebutton.h"
|
||||
|
||||
#include <QIcon>
|
||||
#include <QPainter>
|
||||
#include <QtMath>
|
||||
|
||||
StateButton::StateButton(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_type(Check)
|
||||
, m_switchFork(true)
|
||||
{
|
||||
setAttribute(Qt::WA_TranslucentBackground, true);
|
||||
}
|
||||
|
||||
void StateButton::setType(StateButton::Type type)
|
||||
{
|
||||
m_type = type;
|
||||
update();
|
||||
}
|
||||
|
||||
void StateButton::setSwitchFork(bool switchFork)
|
||||
{
|
||||
m_switchFork = switchFork;
|
||||
}
|
||||
|
||||
void StateButton::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QWidget::paintEvent(event);
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing, true);
|
||||
|
||||
int radius = qMin(width(), height());
|
||||
painter.setPen(QPen(Qt::NoPen));
|
||||
painter.setBrush(palette().color(QPalette::Highlight));
|
||||
painter.drawPie(rect(), 0, 360 * 16);
|
||||
|
||||
QPen pen(Qt::white, radius / 100.0 * 6.20, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin);
|
||||
switch (m_type) {
|
||||
case Check: drawCheck(painter, pen, radius); break;
|
||||
case Fork: drawFork(painter, pen, radius); break;
|
||||
}
|
||||
}
|
||||
|
||||
void StateButton::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
QWidget::mousePressEvent(event);
|
||||
if (m_switchFork)
|
||||
emit click();
|
||||
}
|
||||
|
||||
void StateButton::enterEvent(QEvent *event)
|
||||
{
|
||||
QWidget::enterEvent(event);
|
||||
if (m_switchFork)
|
||||
setType(Fork);
|
||||
}
|
||||
|
||||
void StateButton::leaveEvent(QEvent *event)
|
||||
{
|
||||
QWidget::leaveEvent(event);
|
||||
if (m_switchFork)
|
||||
setType(Check);
|
||||
}
|
||||
|
||||
void StateButton::drawCheck(QPainter &painter, QPen &pen, int radius)
|
||||
{
|
||||
painter.setPen(pen);
|
||||
|
||||
QPointF points[3] = {
|
||||
QPointF(radius / 100.0 * 32, radius / 100.0 * 57),
|
||||
QPointF(radius / 100.0 * 45, radius / 100.0 * 70),
|
||||
QPointF(radius / 100.0 * 75, radius / 100.0 * 35)
|
||||
};
|
||||
|
||||
painter.drawPolyline(points, 3);
|
||||
}
|
||||
|
||||
void StateButton::drawFork(QPainter &painter, QPen &pen, int radius)
|
||||
{
|
||||
pen.setCapStyle(Qt::RoundCap);
|
||||
painter.setPen(pen);
|
||||
|
||||
QPointF pointsl[2] = {
|
||||
QPointF(radius / 100.0 * 35, radius / 100.0 * 35),
|
||||
QPointF(radius / 100.0 * 65, radius / 100.0 * 65)
|
||||
};
|
||||
|
||||
painter.drawPolyline(pointsl, 2);
|
||||
|
||||
QPointF pointsr[2] = {
|
||||
QPointF(radius / 100.0 * 65, radius / 100.0 * 35),
|
||||
QPointF(radius / 100.0 * 35, radius / 100.0 * 65)
|
||||
};
|
||||
|
||||
painter.drawPolyline(pointsr, 2);
|
||||
}
|
61
frame/util/statebutton.h
Normal file
61
frame/util/statebutton.h
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (C) 2016 ~ 2018 Deepin Technology Co., Ltd.
|
||||
*
|
||||
* Author: chenwei <chenwei@uniontech.com>
|
||||
*
|
||||
* Maintainer: chenwei <chenwei@uniontech.com>
|
||||
*
|
||||
*
|
||||
* 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 3 of the License, or
|
||||
* 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef STATEBUTTON_H
|
||||
#define STATEBUTTON_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class StateButton : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum Type {
|
||||
Check,
|
||||
Fork
|
||||
};
|
||||
|
||||
public:
|
||||
explicit StateButton(QWidget *parent = nullptr);
|
||||
void setType(Type type);
|
||||
void setSwitchFork(bool switchFork);
|
||||
|
||||
signals:
|
||||
void click();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void enterEvent(QEvent *event) override;
|
||||
void leaveEvent(QEvent *event) override;
|
||||
|
||||
private:
|
||||
void drawCheck(QPainter &painter, QPen &pen, int radius);
|
||||
void drawFork(QPainter &painter, QPen &pen, int radius);
|
||||
|
||||
private:
|
||||
Type m_type;
|
||||
bool m_switchFork;
|
||||
};
|
||||
|
||||
#endif // STATEBUTTON_H
|
@ -25,6 +25,7 @@
|
||||
#include "bluetoothconstants.h"
|
||||
#include "refreshbutton.h"
|
||||
#include "horizontalseperator.h"
|
||||
#include "statebutton.h"
|
||||
|
||||
#include <DFontSizeManager>
|
||||
#include <DLabel>
|
||||
@ -42,7 +43,10 @@ BluetoothDeviceItem::BluetoothDeviceItem(QStyle *style, const Device *device, DL
|
||||
, m_standarditem(new DStandardItem())
|
||||
, m_labelAction(nullptr)
|
||||
, m_stateAction(nullptr)
|
||||
, m_connAction(nullptr)
|
||||
, m_loading(new DSpinner(parent))
|
||||
, m_iconWidget(new QWidget(parent->viewport()))
|
||||
, m_connButton(new StateButton(m_iconWidget))
|
||||
{
|
||||
initActionList();
|
||||
initConnect();
|
||||
@ -54,19 +58,35 @@ BluetoothDeviceItem::~BluetoothDeviceItem()
|
||||
delete m_loading;
|
||||
m_loading = nullptr;
|
||||
}
|
||||
if (m_iconWidget != nullptr) {
|
||||
delete m_iconWidget;
|
||||
m_iconWidget = nullptr;
|
||||
m_connButton = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void BluetoothDeviceItem::initActionList()
|
||||
{
|
||||
m_labelAction = new DViewItemAction(Qt::AlignLeft | Qt::AlignVCenter, QSize(), QSize(), false);
|
||||
m_stateAction = new DViewItemAction(Qt::AlignLeft | Qt::AlignVCenter, QSize(), QSize(), true);
|
||||
m_connAction = new DViewItemAction(Qt::AlignRight | Qt::AlignVCenter, QSize(16, 16), QSize(16, 16), false);
|
||||
|
||||
m_connButton->setType(StateButton::Check);
|
||||
m_connButton->setSwitchFork(false);
|
||||
m_connButton->setFixedSize(16, 16);
|
||||
m_iconWidget->setFixedSize(20, 16);
|
||||
QHBoxLayout *layout = new QHBoxLayout(m_iconWidget);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->addWidget(m_connButton);
|
||||
layout->addStretch();
|
||||
|
||||
m_loading->setFixedSize(QSize(24, 24));
|
||||
m_stateAction->setWidget(m_loading);
|
||||
m_connAction->setWidget(m_iconWidget);
|
||||
|
||||
m_standarditem->setAccessibleText(m_device->alias());
|
||||
m_standarditem->setActionList(Qt::RightEdge, {m_stateAction});
|
||||
m_standarditem->setActionList(Qt::LeftEdge, {m_labelAction});
|
||||
m_standarditem->setActionList(Qt::RightEdge, { m_stateAction, m_connAction });
|
||||
m_standarditem->setActionList(Qt::LeftEdge, { m_labelAction });
|
||||
|
||||
//蓝牙列表可用蓝牙设备信息文字显示高亮
|
||||
m_labelAction->setTextColorRole(DPalette::BrightText);
|
||||
@ -79,6 +99,7 @@ void BluetoothDeviceItem::initConnect()
|
||||
{
|
||||
connect(DApplicationHelper::instance(), &DApplicationHelper::themeTypeChanged, this, &BluetoothDeviceItem::updateIconTheme);
|
||||
connect(m_device, &Device::stateChanged, this, &BluetoothDeviceItem::updateDeviceState);
|
||||
connect(m_iconWidget, &QWidget::destroyed, [ this ] { this->m_iconWidget = nullptr; });
|
||||
}
|
||||
|
||||
void BluetoothDeviceItem::updateIconTheme(DGuiApplicationHelper::ColorType type)
|
||||
@ -105,16 +126,16 @@ void BluetoothDeviceItem::updateDeviceState(Device::State state)
|
||||
if (state == Device::StateAvailable) {
|
||||
m_loading->start();
|
||||
m_stateAction->setVisible(true);
|
||||
m_standarditem->setCheckState(Qt::Unchecked);
|
||||
m_connAction->setVisible(false);
|
||||
} else if (state == Device::StateConnected) {
|
||||
m_loading->stop();
|
||||
m_stateAction->setVisible(false);
|
||||
m_standarditem->setCheckState(Qt::Checked);
|
||||
m_connAction->setVisible(true);
|
||||
emit requestTopDeviceItem(m_standarditem);
|
||||
} else {
|
||||
m_loading->stop();
|
||||
m_stateAction->setVisible(false);
|
||||
m_standarditem->setCheckState(Qt::Unchecked);
|
||||
m_connAction->setVisible(false);
|
||||
}
|
||||
emit deviceStateChanged(m_device);
|
||||
}
|
||||
|
@ -50,6 +50,7 @@ class SettingLabel;
|
||||
class QStandardItemModel;
|
||||
class RefreshButton;
|
||||
class HorizontalSeperator;
|
||||
class StateButton;
|
||||
|
||||
const QString LightString = QString(":/light/buletooth_%1_light.svg");
|
||||
const QString DarkString = QString(":/dark/buletooth_%1_dark.svg");
|
||||
@ -85,7 +86,11 @@ private:
|
||||
DStandardItem *m_standarditem;
|
||||
DViewItemAction *m_labelAction;
|
||||
DViewItemAction *m_stateAction;
|
||||
DViewItemAction *m_connAction;
|
||||
DSpinner *m_loading;
|
||||
|
||||
QWidget *m_iconWidget;
|
||||
StateButton *m_connButton;
|
||||
};
|
||||
|
||||
class BluetoothAdapterItem : public QWidget
|
||||
|
Loading…
x
Reference in New Issue
Block a user