Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions plugins/dde-dock/common/commontextbutton.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "commontextbutton.h"

#include <DStyleOption>

Check warning on line 7 in plugins/dde-dock/common/commontextbutton.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DStyleOption> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QPainter>

Check warning on line 8 in plugins/dde-dock/common/commontextbutton.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QPainter> not found. Please note: Cppcheck does not need standard library headers to get proper results.

CommonTextButton::CommonTextButton(QWidget *parent, const QString &text)
: QAbstractButton(parent)
{
setCursor(Qt::PointingHandCursor);
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
Dtk::Widget::DFontSizeManager::instance()->bind(this, Dtk::Widget::DFontSizeManager::T8);
}

void CommonTextButton::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);

QPainter p(this);
p.setRenderHint(QPainter::Antialiasing);

QRectF rect = this->rect();

if (isDown()) {
p.setBrush(QColor(0,0,0,255 * 0.2));
} else if (underMouse()) {
p.setBrush(QColor(0, 0, 0, 255 * 0.15));
} else {
p.setBrush(QColor(0, 0, 0, 255 * 0.1));
}

p.setPen(Qt::NoPen);
p.drawRoundedRect(rect, 8, 8);

p.setPen(QColor(255, 255, 255, 255));
p.drawText(rect, Qt::AlignCenter, text());
}

QSize CommonTextButton::sizeHint() const
{
const QFontMetrics metrics(font());
return QSize(metrics.horizontalAdvance(text()) + 24, metrics.height() + 6);
}

QSize CommonTextButton::minimumSizeHint() const

Check warning on line 48 in plugins/dde-dock/common/commontextbutton.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'minimumSizeHint' is never used.
{
return sizeHint();
}
18 changes: 18 additions & 0 deletions plugins/dde-dock/common/commontextbutton.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#pragma once

#include <QAbstractButton>

Check warning on line 7 in plugins/dde-dock/common/commontextbutton.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QAbstractButton> not found. Please note: Cppcheck does not need standard library headers to get proper results.

class CommonTextButton : public QAbstractButton
{
public:
explicit CommonTextButton(QWidget *parent = nullptr, const QString &text = "");
QSize sizeHint() const override;
QSize minimumSizeHint() const override;

protected:
void paintEvent(QPaintEvent *event) override;
};
30 changes: 28 additions & 2 deletions plugins/dde-dock/common/pluginitemdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "pluginitemdelegate.h"
#include "commontextbutton.h"

#include <DStyleOption>

Check warning on line 8 in plugins/dde-dock/common/pluginitemdelegate.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DStyleOption> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <DPalette>

Check warning on line 9 in plugins/dde-dock/common/pluginitemdelegate.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DPalette> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <DToolTip>

#include <QDebug>
Expand Down Expand Up @@ -189,6 +190,8 @@
, m_iconBtn(nullptr)
, m_nameLabel(nullptr)
, m_connBtn(nullptr)
, m_disConnectBtn(nullptr)
, m_state(NoState)
, m_spinner(nullptr)
, m_rightIconSpacerItem(new QSpacerItem(0, 0))
{
Expand All @@ -213,11 +216,14 @@

m_connBtn = new CommonIconButton(this);
m_connBtn->setIcon(QIcon::fromTheme("plugin_item_select"));
m_connBtn->setHoverIcon(QIcon::fromTheme("plugin_item_disconnect"));
m_connBtn->setFixedSize(16, 16);
m_connBtn->setClickable(true);
m_connBtn->hide();

m_disConnectBtn = new CommonTextButton(this);
m_disConnectBtn->setText(tr("Disconnect"));
m_disConnectBtn->setVisible(false);

m_spinner = new DSpinner(this);
m_spinner->setFixedSize(16, 16);
m_spinner->hide();
Expand All @@ -231,6 +237,7 @@
m_mainLayout->addStretch();
m_mainLayout->addSpacerItem(m_rightIconSpacerItem);
m_mainLayout->addWidget(m_connBtn, 0, Qt::AlignRight | Qt::AlignVCenter);
m_mainLayout->addWidget(m_disConnectBtn, 0, Qt::AlignRight | Qt::AlignVCenter);
m_mainLayout->addWidget(m_spinner, 0, Qt::AlignRight | Qt::AlignVCenter);
updateState(item->state());

Expand All @@ -241,7 +248,7 @@
connect(m_item, &PluginStandardItem::nameChanged, this, &PluginItemWidget::updateName);
connect(m_item, &PluginStandardItem::stateChanged, this, &PluginItemWidget::updateState);

connect(m_connBtn, &CommonIconButton::clicked, m_item, &PluginStandardItem::connectBtnClicked);
connect(m_disConnectBtn, &CommonTextButton::clicked, m_item, &PluginStandardItem::connectBtnClicked);
}

PluginItemWidget::~PluginItemWidget()
Expand All @@ -261,6 +268,7 @@
void PluginItemWidget::updateState(const PluginItemState state)
{
m_rightIconSpacerItem->changeSize(10, 0);
m_state = state;
switch (state) {
case PluginItemState::NoState:
m_connBtn->setVisible(false);
Expand Down Expand Up @@ -315,3 +323,21 @@
}
return QWidget::event(e);
}

void PluginItemWidget::enterEvent(QEnterEvent *event)
{
if (m_state == PluginItemState::Connected) {
m_disConnectBtn->setVisible(true);
m_connBtn->setVisible(false);
}
QWidget::enterEvent(event);
}

void PluginItemWidget::leaveEvent(QEvent *event)
{
m_disConnectBtn->setVisible(false);
if (m_state == PluginItemState::Connected) {
m_connBtn->setVisible(true);
};
QWidget::leaveEvent(event);
}
7 changes: 6 additions & 1 deletion plugins/dde-dock/common/pluginitemdelegate.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// SPDX-FileCopyrightText: 2016 - 2023 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2016 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#pragma once

#include "commoniconbutton.h"
#include "commontextbutton.h"

#include <DLabel>

Check warning on line 10 in plugins/dde-dock/common/pluginitemdelegate.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DLabel> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <DSpinner>

Check warning on line 11 in plugins/dde-dock/common/pluginitemdelegate.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DSpinner> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <QObject>
#include <QStyledItemDelegate>
Expand Down Expand Up @@ -116,14 +117,18 @@

protected:
bool event(QEvent *e) override;
void enterEvent(QEnterEvent *event) override;
void leaveEvent(QEvent *event) override;

private:
PluginStandardItem *m_item;

QHBoxLayout *m_mainLayout;
CommonIconButton *m_iconBtn;
CommonTextButton *m_disConnectBtn;
DLabel *m_nameLabel;
CommonIconButton *m_connBtn;
DSpinner *m_spinner;
QSpacerItem *m_rightIconSpacerItem;
PluginItemState m_state;
};
66 changes: 7 additions & 59 deletions plugins/dde-dock/translations/dde-dock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,65 +193,6 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>DatetimeWidget</name>
<message>
<source>Monday</source>
<translation>Monday</translation>
</message>
<message>
<source>Tuesday</source>
<translation>Tuesday</translation>
</message>
<message>
<source>Wednesday</source>
<translation>Wednesday</translation>
</message>
<message>
<source>Thursday</source>
<translation>Thursday</translation>
</message>
<message>
<source>Friday</source>
<translation>Friday</translation>
</message>
<message>
<source>Saturday</source>
<translation>Saturday</translation>
</message>
<message>
<source>Sunday</source>
<translation>Sunday</translation>
</message>
<message>
<source>monday</source>
<translation>monday</translation>
</message>
<message>
<source>tuesday</source>
<translation>tuesday</translation>
</message>
<message>
<source>wednesday</source>
<translation>wednesday</translation>
</message>
<message>
<source>thursday</source>
<translation>thursday</translation>
</message>
<message>
<source>friday</source>
<translation>friday</translation>
</message>
<message>
<source>saturday</source>
<translation>saturday</translation>
</message>
<message>
<source>sunday</source>
<translation>sunday</translation>
</message>
</context>
<context>
<name>DeviceControlWidget</name>
<message>
Expand Down Expand Up @@ -444,6 +385,13 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PluginItemWidget</name>
<message>
<source>Disconnect</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PowerApplet</name>
<message>
Expand Down
74 changes: 15 additions & 59 deletions plugins/dde-dock/translations/dde-dock_ady.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,65 +193,6 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>DatetimeWidget</name>
<message>
<source>Monday</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Tuesday</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Wednesday</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Thursday</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Friday</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Saturday</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Sunday</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>monday</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>tuesday</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>wednesday</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>thursday</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>friday</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>saturday</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>sunday</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>DeviceControlWidget</name>
<message>
Expand Down Expand Up @@ -444,6 +385,13 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PluginItemWidget</name>
<message>
<source>Disconnect</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PowerApplet</name>
<message>
Expand Down Expand Up @@ -545,6 +493,14 @@
<source>Charging, %1 hr until full</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Capacity %1, charging protection active</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Charging protection active</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PowerStatusWidget</name>
Expand Down
Loading
Loading