Skip to content

Commit

Permalink
feat: qt6 adaptation (#72)
Browse files Browse the repository at this point in the history
qt6 adaptation
  • Loading branch information
JWWTSL authored Jan 16, 2025
1 parent cbfde24 commit f16ac2e
Show file tree
Hide file tree
Showing 30 changed files with 320 additions and 100 deletions.
16 changes: 10 additions & 6 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ Maintainer: Deepin Packages Builder <[email protected]>
Uploaders: Ma Aiguo <[email protected]>,
Build-Depends: debhelper-compat (=11),
python3,
qt5-qmake,
qttools5-dev-tools,
qtbase5-dev,
qt6-base-dev,
qt6-base-dev-tools,
qt6-base-private-dev,
qt6-l10n-tools,
qt6-tools-dev-tools,
qt6-tools-dev,
qt6-svg-dev,
pkg-config,
libxcb-util0-dev,
libmtdev-dev,
Expand All @@ -16,9 +20,9 @@ Build-Depends: debhelper-compat (=11),
libfontconfig-dev,
libegl1-mesa-dev,
libstartup-notification0-dev,
libdtkwidget-dev,
libdtk6widget-dev,
libgtest-dev,
libpolkit-qt5-1-dev
libpolkit-qt6-1-dev
Standards-Version: 4.5.1
Homepage: https://github.com/linuxdeepin/deepin-boot-maker
Vcs-Git: https://salsa.debian.org/pkg-deepin-team/deepin-boot-maker.git
Expand All @@ -28,7 +32,7 @@ Package: deepin-boot-maker
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, p7zip-full, mtools, udisks2,
syslinux [linux-amd64 linux-i386],
syslinux-common [linux-amd64 linux-i386],genisoimage,dde-qt5integration
syslinux-common [linux-amd64 linux-i386],genisoimage,dde-qt6integration
Description: Simple tool for user to create a boot usb stick quickly and easily
It's designed to support deepin system iso, it can works for Debian and ubuntu
iso too.
27 changes: 23 additions & 4 deletions debian/rules
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
#!/usr/bin/make -f

export QT_SELECT=qt5
# 设置 Qt6 环境
export QT_SELECT=qt6
# 使用系统 PATH 中的 qmake6
export QMAKE=qmake6

include /usr/share/dpkg/default.mk

override_dh_auto_configure:
dh_auto_configure -- DAPP_VERSION=$(DEB_VERSION_UPSTREAM) DEFINES+="VERSION=$(DEB_VERSION_UPSTREAM)" LIB_INSTALL_DIR=/usr/lib/$(DEB_HOST_MULTIARCH)
# 指定使用 qmake 构建系统
export DH_OPTIONS := --buildsystem=qmake

%:
dh $@
dh $@ --buildsystem=qmake

override_dh_auto_configure:
$(QMAKE) \
VERSION=$(VERSION) \
PREFIX=/usr \
LIB_INSTALL_DIR=/usr/lib/$(DEB_HOST_MULTIARCH) \
VERSION_UPSTREAM=$(DEB_VERSION_UPSTREAM) \
DEFINES+="VERSION=$(DEB_VERSION_UPSTREAM)"
override_dh_shlibdeps:
dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info

override_dh_auto_test:
# Skip running tests
echo "Skipping tests"

8 changes: 4 additions & 4 deletions rpm/deepin-boot-maker.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Source0: %{name}_%{version}.orig.tar.xz


BuildRequires: python3
BuildRequires: qt5-devel
#BuildRequires: qt6-devel
BuildRequires: xcb-util-devel
BuildRequires: mtdev-devel
BuildRequires: libXrender-devel
Expand Down Expand Up @@ -48,9 +48,9 @@ Requires: genisoimage


%build
# help find (and prefer) qt5 utilities, e.g. qmake, lrelease
export PATH=%{_qt5_bindir}:$PATH
%qmake_qt5 DAPP_VERSION=%{version} DEFINES+="VERSION=%{version}"
# help find (and prefer) qt6 utilities, e.g. qmake, lrelease
export PATH=%{_qt6_bindir}:$PATH
%qmake_qt6 DAPP_VERSION=%{version} DEFINES+="VERSION=%{version}"
%make_build


Expand Down
9 changes: 8 additions & 1 deletion src/app/app.pro
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,19 @@ QMAKE_CXXFLAGS += -fstack-protector-all
# QMAKE_LFLAGS += -g -fsanitize=address -O2
#}


QT += core gui widgets concurrent network svg

CONFIG += c++11 link_pkgconfig
CONFIG += resources_big

versionAtLeast(QT_VERSION, 6.0.0) {
PKGCONFIG += dtk6widget
PKGCONFIG += polkit-qt6-1
} else {
PKGCONFIG += dtkwidget
PKGCONFIG += polkit-qt5-1
}

RESOURCES += \
../translate.qrc \
view/resource/resource.qrc
Expand Down
22 changes: 18 additions & 4 deletions src/app/bmwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <DTitlebar>

Check warning on line 13 in src/app/bmwindow.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 14 in src/app/bmwindow.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 15 in src/app/bmwindow.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.
#include <DApplicationHelper>
#include <DGuiApplicationHelper>

Check warning on line 16 in src/app/bmwindow.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 17 in src/app/bmwindow.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

#include <QDebug>

Check warning on line 19 in src/app/bmwindow.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDebug> not found. Please note: Cppcheck does not need standard library headers to get proper results.
Expand Down Expand Up @@ -56,7 +56,12 @@ BMWindow::BMWindow(QWidget *parent)

setFixedSize(440, 550);

// TODO
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
d->interface = BMInterface::instance();
#else
d->interface = &BMInterface::ref();
#endif

// init about info
QString descriptionText = tr("Boot Maker is a simple tool to write system image files into USB flash drives and other media.");
Expand All @@ -80,7 +85,8 @@ BMWindow::BMWindow(QWidget *parent)
titlebar()->setWindowFlags(flags);

QPalette pal(palette());
pal.setColor(QPalette::Background, Qt::white);
pal.setColor(QPalette::Window, QColor(255, 255, 255));

setAutoFillBackground(true);
setPalette(pal);
#endif
Expand All @@ -92,7 +98,7 @@ BMWindow::BMWindow(QWidget *parent)

auto viewWidth = 440;
QStackedLayout *actionsLayout = new QStackedLayout;
actionsLayout->setMargin(0);
actionsLayout->setContentsMargins(0, 0, 0, 0);
d->isoWidget = new ISOSelectView();
d->isoWidget->setAccessibleName("centralWidget_isoSelectWidget");
d->isoWidget->resize(440, 466);
Expand Down Expand Up @@ -128,7 +134,7 @@ BMWindow::BMWindow(QWidget *parent)
d->wsib->setPointDistance(12);

QVBoxLayout *mainLayout = new QVBoxLayout();
mainLayout->setMargin(0);
mainLayout->setContentsMargins(0, 0, 0, 0);
mainLayout->setSpacing(0);
mainLayout->addLayout(actionsLayout);
mainLayout->addWidget(d->wsib);
Expand Down Expand Up @@ -265,14 +271,22 @@ void BMWindow :: slot_ThemeChange()
DGuiApplicationHelper::ColorType themeType = DGuiApplicationHelper::instance()->themeType();
if (themeType == DGuiApplicationHelper::LightType) {
pa = d->wsib->palette();
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
pa.setColor(DPalette::Background, QColor(255, 255, 255));
#else
pa.setColor(DPalette::Window, QColor(255, 255, 255));
#endif
d->wsib->setPalette(pa);
d->wsib->setPointColor(QColor("#2CA7F8"));
// d->wsib->setSecondaryPointColor(QColor("#96ACBD"));
d->wsib->setSecondaryPointColor(QColor(150, 172, 189, 51));
} else if (themeType == DGuiApplicationHelper::DarkType) {
pa = d->wsib->palette();
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
pa.setColor(DPalette::Background, QColor("#292929"));
#else
pa.setColor(DPalette::Window, QColor("#292929"));
#endif
d->wsib->setPalette(pa);
d->wsib->setPointColor(QColor("#0082FA"));
// d->wsib->setSecondaryPointColor(QColor("#555555"));
Expand Down
15 changes: 9 additions & 6 deletions src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
#include "bmwindow.h"

Check warning on line 9 in src/app/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "bmwindow.h" not found.
#include <bminterface.h>

Check warning on line 10 in src/app/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <bminterface.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <util/utils.h>

Check warning on line 11 in src/app/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

#include <QDebug>

Check warning on line 12 in src/app/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDebug> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <DLog>
#include <DApplication>
#include <DWidgetUtil>
#include <DApplicationSettings>
#include <DGuiApplicationHelper>

DCORE_USE_NAMESPACE
Expand Down Expand Up @@ -65,8 +64,8 @@ int main(int argc, char **argv)

// DApplication::loadDXcbPlugin(); //去除为兼容wayland环境
DApplication app(argc, argv);
app.setAttribute(Qt::AA_UseHighDpiPixmaps);
app.setAttribute(Qt::AA_EnableHighDpiScaling);
// app.setAttribute(Qt::AA_UseHighDpiPixmaps);
// app.setAttribute(Qt::AA_EnableHighDpiScaling);
app.setOrganizationName("deepin");
app.setApplicationName("deepin-boot-maker");
app.setApplicationVersion(DApplication::buildVersion("20191031"));
Expand Down Expand Up @@ -99,15 +98,19 @@ int main(int argc, char **argv)
app.setApplicationDisplayName(QObject::tr("Boot Maker"));

qDebug() << "Boot Maker UI started.";

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
DApplicationSettings savetheme;
#endif
BMWindow w;
Dtk::Widget::moveToCenter(&w);
w.show();
// w.waitAuth();

auto ret = app.exec();
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
BMInterface::instance()->stop();
#else
BMInterface::ref().stop();
#endif
return ret;
}

Expand Down
26 changes: 18 additions & 8 deletions src/app/vendor.pri
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
include($$PWD/../vendor/env.pri)

QT += dtkwidget

unix{
QT += network
CONFIG += link_pkgconfig
}

linux{
QT += x11extras dbus x11extras
CONFIG += link_pkgconfig
PKGCONFIG += dtkwidget
# PKGCONFIG += xcb-util libstartup-notification-1.0
# LIBS += -lxcb -lX11 -lXext
versionAtLeast(QT_VERSION, 6.0.0) {
# Qt 6 specific configurations
linux{
QT += dbus
CONFIG += link_pkgconfig
PKGCONFIG += dtk6widget
# PKGCONFIG += xcb-util libstartup-notification-1.0
# LIBS += -lxcb -lX11 -lXext
}
} else {
# Qt 5 specific configurations
linux{
QT += dbus
CONFIG += link_pkgconfig
PKGCONFIG += dtkwidget
# PKGCONFIG += xcb-util libstartup-notification-1.0
# LIBS += -lxcb -lX11 -lXext
}
}

win32{
Expand Down
10 changes: 5 additions & 5 deletions src/app/view/deviceinfoitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <DApplication>
#include <DProgressBar>
#include <DApplicationHelper>
#include <DGuiApplicationHelper>
#include <DFontSizeManager>

#include <QDebug>
Expand Down Expand Up @@ -44,8 +44,8 @@ DeviceInfoItem::DeviceInfoItem(const QString &name, const QString &device,

auto m_deviceLabel = new DLabel;
m_deviceLabel->setObjectName("DeviceInfoLabel");
DPalette pa = DApplicationHelper::instance()->palette(m_deviceLabel);
QBrush brush = DApplicationHelper::instance()->palette(m_deviceLabel).text();
QPalette pa = m_deviceLabel->palette();
QBrush brush = pa.text();
pa.setBrush(DPalette::Text, brush);
m_deviceLabel->setText(name);
m_deviceLabel->setFixedHeight(25);
Expand Down Expand Up @@ -79,12 +79,12 @@ DeviceInfoItem::DeviceInfoItem(const QString &name, const QString &device,

auto m_bodywidget = new DWidget;
auto bodyLayout = new QVBoxLayout(m_bodywidget);
bodyLayout->setMargin(0);
bodyLayout->setContentsMargins(0, 0, 0, 0);
auto m_middlewidget = new DWidget;
m_middlewidget->setFixedWidth(292);
m_middlewidget->setFixedHeight(18);
auto middleLayout = new QHBoxLayout(m_middlewidget);
middleLayout->setMargin(0);
middleLayout->setContentsMargins(0, 0, 0, 0);

middleLayout->addWidget(m_deviceDevName, 0, Qt::AlignLeft);
middleLayout->addWidget(m_deviceCapacity, 0, Qt::AlignRight);
Expand Down
13 changes: 12 additions & 1 deletion src/app/view/dropframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "dropframe.h"

#include <DApplicationHelper>
#include <DGuiApplicationHelper>

#include <QDropEvent>
#include <QMimeData>
Expand Down Expand Up @@ -69,12 +69,23 @@ void DropFrame::paintEvent(QPaintEvent *e)
{
if (this->property("active").toBool()) {
QPixmap pixmap;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
// Qt5: 使用 DGuiApplicationHelper
DGuiApplicationHelper::ColorType themeType = DGuiApplicationHelper::instance()->themeType();
if (themeType == DGuiApplicationHelper::LightType) {
pixmap = QPixmap(":/theme/light/image/dash.svg").scaled(this->size());
} else if (themeType == DGuiApplicationHelper::DarkType) {
pixmap = QPixmap(":/theme/dark/image/dash.svg").scaled(this->size());
}
#else
// Qt6: 使用 QPalette
QPalette palette = this->palette();
if (palette.color(QPalette::Window).lightnessF() > 0.5) {
pixmap = QPixmap(":/theme/light/image/dash.svg").scaled(this->size());
} else {
pixmap = QPixmap(":/theme/dark/image/dash.svg").scaled(this->size());
}
#endif
QPainter painter(this);
painter.drawPixmap(this->rect(), pixmap);
}
Expand Down
6 changes: 3 additions & 3 deletions src/app/view/formatdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ NewStr autoCutText(const QString &text, DLabel *pDesLbl)
QFont font; // 应用使用字体对象
QFontMetrics font_label(font);
QString strText = text;
int titlewidth = font_label.width(strText);
int titlewidth = font_label.horizontalAdvance(strText);
QString str;
NewStr newstr;
int width = pDesLbl->width();
Expand All @@ -29,8 +29,8 @@ NewStr autoCutText(const QString &text, DLabel *pDesLbl)
} else {
for (int i = 0; i < strText.count(); i++) {
str += strText.at(i);

if (font_label.width(str) > width) { //根据label宽度调整每行字符数
if (font_label.horizontalAdvance(str) > width) { //根据label宽度调整每行字符数
str.remove(str.count() - 1, 1);
newstr.strList.append(str);
newstr.resultStr += str + "\n";
Expand Down
Loading

0 comments on commit f16ac2e

Please sign in to comment.