Skip to content
Merged
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
4 changes: 3 additions & 1 deletion deepin-devicemanager/src/Tool/commontools.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand All @@ -13,10 +13,12 @@
#include <QDBusReply>
#include <QFile>
#include <QDir>
#include <QProcess>

Check warning on line 16 in deepin-devicemanager/src/Tool/commontools.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 16 in deepin-devicemanager/src/Tool/commontools.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

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

Check warning on line 17 in deepin-devicemanager/src/Tool/commontools.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 17 in deepin-devicemanager/src/Tool/commontools.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

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

Check warning on line 18 in deepin-devicemanager/src/Tool/commontools.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 18 in deepin-devicemanager/src/Tool/commontools.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

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

Check warning on line 19 in deepin-devicemanager/src/Tool/commontools.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 19 in deepin-devicemanager/src/Tool/commontools.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

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

Check warning on line 20 in deepin-devicemanager/src/Tool/commontools.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 20 in deepin-devicemanager/src/Tool/commontools.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

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

Check warning on line 21 in deepin-devicemanager/src/Tool/commontools.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 21 in deepin-devicemanager/src/Tool/commontools.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

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

DWIDGET_USE_NAMESPACE
using namespace DDLog;
Expand Down
38 changes: 38 additions & 0 deletions deepin-devicemanager/src/Widget/headerinfotableDelegate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include <DApplication>

Check warning on line 5 in deepin-devicemanager/src/Widget/headerinfotableDelegate.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 5 in deepin-devicemanager/src/Widget/headerinfotableDelegate.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

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

Check warning on line 6 in deepin-devicemanager/src/Widget/headerinfotableDelegate.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 6 in deepin-devicemanager/src/Widget/headerinfotableDelegate.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

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

Check warning on line 7 in deepin-devicemanager/src/Widget/headerinfotableDelegate.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.

Check warning on line 7 in deepin-devicemanager/src/Widget/headerinfotableDelegate.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

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

#include "headerinfotableDelegate.h"

DWIDGET_USE_NAMESPACE

HeaderInfoDelegate::HeaderInfoDelegate(QObject *parent)
: QStyledItemDelegate(parent)
{
}

void HeaderInfoDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QStyleOptionViewItem opt(option);
initStyleOption(&opt, index);

QWidget *wnd = DApplication::activeWindow();

Check warning on line 23 in deepin-devicemanager/src/Widget/headerinfotableDelegate.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Variable 'wnd' can be declared as pointer to const

Check warning on line 23 in deepin-devicemanager/src/Widget/headerinfotableDelegate.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Variable 'wnd' can be declared as pointer to const
DPalette::ColorGroup cg = wnd ? DPalette::Active : DPalette::Inactive;
auto palette = DPaletteHelper::instance()->palette(option.widget);

if (opt.state & QStyle::State_Selected) {
QColor highlightColor = palette.color(cg, DPalette::HighlightedText);
opt.palette.setColor(QPalette::Text, highlightColor);
opt.palette.setColor(QPalette::WindowText, highlightColor);
} else {
QColor normalColor = palette.color(cg, DPalette::Text);
opt.palette.setColor(QPalette::Text, normalColor);
opt.palette.setColor(QPalette::WindowText, normalColor);
}

QStyledItemDelegate::paint(painter, opt, index);
}
19 changes: 19 additions & 0 deletions deepin-devicemanager/src/Widget/headerinfotableDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef HEADERINFOTABLEDELEGATE_H
#define HEADERINFOTABLEDELEGATE_H

#include <QStyledItemDelegate>

class HeaderInfoDelegate : public QStyledItemDelegate
{
public:
explicit HeaderInfoDelegate(QObject *parent = nullptr);

void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const override;
};

#endif
125 changes: 125 additions & 0 deletions deepin-devicemanager/src/Widget/headerinfotablewidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "headerinfotablewidget.h"
#include "headerinfotableDelegate.h"
#include "MacroDefinition.h"

#include <DApplication>
#include <DPaletteHelper>

#include <QHeaderView>
#include <QPainter>
#include <QPainterPath>

DWIDGET_USE_NAMESPACE

static constexpr int kColumnCount { 2 };

HeaderInfoTableWidget::HeaderInfoTableWidget(DWidget *parent)
: DTableWidget(parent)
{
initUI();
}

void HeaderInfoTableWidget::updateData(const QList<QPair<QString, QString>> &data)
Comment thread
GongHeng2017 marked this conversation as resolved.
{
resetTableContents();
int nRow = data.size();
setRowCount(nRow);

QWidget *wnd = DApplication::activeWindow();
DPalette::ColorGroup cg = wnd ? DPalette::Active : DPalette::Inactive;
auto palette = DPaletteHelper::instance()->palette(this);
QColor colorEven = palette.color(cg, DPalette::Base);
QColor colorOdd = palette.color(cg, DPalette::ItemBackground);

for (int i = 0; i < nRow; ++i) {
QTableWidgetItem *itemFirst = new QTableWidgetItem(data[i].first);
itemFirst->setFlags(itemFirst->flags() & ~Qt::ItemIsSelectable);
itemFirst->setBackground(i % 2 == 0 ? colorEven : colorOdd);
setItem(i, 0, itemFirst);
QTableWidgetItem *itemSecond = new QTableWidgetItem(data[i].second);
itemSecond->setFlags(itemSecond->flags() & ~Qt::ItemIsSelectable);
itemSecond->setBackground(i % 2 == 0 ? colorEven : colorOdd);
setItem(i, 1, itemSecond);
}

// 调整控件高度,使内容刚好完全显示,不出现垂直滚动条
if (nRow > 0) {
// 为了保持底部圆角,给表格高度留出 2px 余量;避免内容铺满viewport导致圆角被覆盖
setFixedHeight(ROW_HEIGHT * nRow + 2);
} else {
setFixedHeight(0);
}
Comment thread
GongHeng2017 marked this conversation as resolved.
}

void HeaderInfoTableWidget::initUI()
{
setColumnCount(kColumnCount);
this->setEditTriggers(QAbstractItemView::NoEditTriggers);
this->setVerticalScrollMode(QAbstractItemView::ScrollMode::ScrollPerPixel);
setSelectionMode(QAbstractItemView::NoSelection);
setSelectionBehavior(QAbstractItemView::SelectItems);
this->setFocusPolicy(Qt::NoFocus);
// 设置无边框, 避免原始方形外框干扰圆角绘制
this->setFrameStyle(QFrame::NoFrame);
this->setShowGrid(false);
this->viewport()->setAutoFillBackground(true);
m_delegate = new HeaderInfoDelegate(this);
this->setItemDelegate(m_delegate);
setAlternatingRowColors(true);
this->verticalHeader()->setVisible(false);
this->horizontalHeader()->setVisible(false);
this->setSortingEnabled(false);
this->horizontalHeader()->setStretchLastSection(true);
this->verticalHeader()->setDefaultSectionSize(ROW_HEIGHT);
this->horizontalHeader()->setDefaultSectionSize(180);
this->setAttribute(Qt::WA_TranslucentBackground);
this->setWindowFlags(Qt::FramelessWindowHint);
}

void HeaderInfoTableWidget::paintEvent(QPaintEvent *event)
{
DTableWidget::paintEvent(event);

QWidget *wnd = DApplication::activeWindow();
DPalette::ColorGroup cg = wnd ? DPalette::Active : DPalette::Inactive;

auto palette = DPaletteHelper::instance()->palette(this);

QRect rect = viewport()->rect().adjusted(0, 0, -1, -1);
int width = 1;
int radius = 8;

QPainter painter(this->viewport());
painter.setRenderHint(QPainter::Antialiasing, true);

QPainterPath paintPathOut;
paintPathOut.addRoundedRect(rect, radius, radius);

QRect rectIn = QRect(rect.x() + width, rect.y() + width, rect.width() - width * 2, rect.height() - width * 2);
QPainterPath paintPathIn;
paintPathIn.addRoundedRect(rectIn, radius, radius);

QPainterPath paintPath = paintPathOut.subtracted(paintPathIn);
QBrush bgBrush(palette.color(cg, DPalette::FrameBorder));
painter.fillPath(paintPath, bgBrush);

QPen pen = painter.pen();
pen.setWidth(width);
pen.setColor(palette.color(cg, DPalette::FrameBorder));
painter.setPen(pen);
painter.drawRoundedRect(rectIn, radius, radius);

// Draw vertical divider between first and second columns (same as DetailTreeView)
QLine vline(rect.topLeft().x() + 179, rect.topLeft().y(), rect.bottomLeft().x() + 179, rect.bottomLeft().y());
painter.drawLine(vline);
}
Comment thread
GongHeng2017 marked this conversation as resolved.

void HeaderInfoTableWidget::resetTableContents()
{
DTableWidget::clear();
setRowCount(0);
}
29 changes: 29 additions & 0 deletions deepin-devicemanager/src/Widget/headerinfotablewidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef HEADERINFOTABLEWIDGET_H
#define HEADERINFOTABLEWIDGET_H

#include <DTableWidget>
#include <DWidget>

#include <QObject>

class HeaderInfoTableWidget : public DTK_WIDGET_NAMESPACE::DTableWidget
{
Q_OBJECT
public:
explicit HeaderInfoTableWidget(DTK_WIDGET_NAMESPACE::DWidget *parent = nullptr);
void updateData(const QList<QPair<QString, QString>> &data);

protected:
void paintEvent(QPaintEvent *event) override;

private:
void initUI();
void resetTableContents();
class HeaderInfoDelegate *m_delegate = nullptr;
};

#endif
Loading