Skip to content

Commit

Permalink
feat: QT6 adaptation
Browse files Browse the repository at this point in the history
QT6 adaptation

Log: QT6 adaptation
  • Loading branch information
pengfeixx committed Jan 14, 2025
1 parent 0158c56 commit db3ac9f
Show file tree
Hide file tree
Showing 44 changed files with 543 additions and 86 deletions.
11 changes: 8 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@ SET(CMAKE_AUTOMOC ON)
SET(CMAKE_AUTORCC ON)
SET(CMAKE_VERBOSE_MAKEFILE ON)

FIND_PACKAGE(Qt5 COMPONENTS Core Gui Svg Sql Xml DBus Network REQUIRED)
FIND_PACKAGE(DtkWidget REQUIRED)
FIND_PACKAGE(DtkGui REQUIRED)
set(QT_VERSION_MAJOR 6)
if (${QT_VERSION_MAJOR} GREATER_EQUAL 6)
set(DTK_VERSION 6)
endif()

FIND_PACKAGE(Qt${QT_VERSION_MAJOR} COMPONENTS Core Gui Svg Sql Xml DBus Network REQUIRED)
FIND_PACKAGE(Dtk${DTK_VERSION}Widget REQUIRED)
FIND_PACKAGE(Dtk${DTK_VERSION}Gui REQUIRED)
FIND_PACKAGE(Freetype REQUIRED)
FIND_PACKAGE(PkgConfig REQUIRED)

Expand Down
18 changes: 15 additions & 3 deletions deepin-font-manager/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,21 @@ TARGET_INCLUDE_DIRECTORIES(${APP_BIN} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
TARGET_INCLUDE_DIRECTORIES(${APP_BIN} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/views)
TARGET_INCLUDE_DIRECTORIES(${APP_BIN} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/interfaces)

TARGET_LINK_LIBRARIES(${APP_BIN} PUBLIC Qt5::Core Qt5::Widgets Qt5::Gui Qt5::Sql Qt5::Xml Qt5::Svg Qt5::DBus Qt5::Network
${DtkCore_LIBRARIES} ${DtkWidget_LIBRARIES} ${FREETYPE_LIBRARIES}
${FREETYPE_LIBRARIES} PkgConfig::FontConfig)
TARGET_LINK_LIBRARIES(${APP_BIN} PUBLIC
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Widgets
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::Sql
Qt${QT_VERSION_MAJOR}::Xml
Qt${QT_VERSION_MAJOR}::Svg
Qt${QT_VERSION_MAJOR}::DBus
Qt${QT_VERSION_MAJOR}::Network
Dtk${DTK_VERSION}::Core
Dtk${DTK_VERSION}::Gui
Dtk${DTK_VERSION}::Widget
${FREETYPE_LIBRARIES}
${FREETYPE_LIBRARIES}
PkgConfig::FontConfig)

INSTALL(TARGETS ${APP_BIN} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

Expand Down
4 changes: 2 additions & 2 deletions deepin-font-manager/interfaces/dfmxmlwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,11 +500,11 @@ bool DFMXmlWrapper::deleteNodeWithTextList(const QString &fileName, const QStrin
if (parentNode.isElement()) {
parentNode.removeChild(removeNode);
} else {
qDebug() << "delete node failed!" << endl;
qDebug() << "delete node failed!" << Qt::endl;
return false;
}
} else {
qDebug() << "delete node failed!" << endl;
qDebug() << "delete node failed!" << Qt::endl;
}
}

Expand Down
4 changes: 4 additions & 0 deletions deepin-font-manager/interfaces/dfontmenumanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@

#include "interfaces/dfontmenumanager.h"

Check warning on line 6 in deepin-font-manager/interfaces/dfontmenumanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "interfaces/dfontmenumanager.h" not found.

#include <QActionGroup>

Check warning on line 8 in deepin-font-manager/interfaces/dfontmenumanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

#if QT_VERSION_MAJOR <= 5
#include <DApplicationHelper>

Check warning on line 11 in deepin-font-manager/interfaces/dfontmenumanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 13 in deepin-font-manager/interfaces/dfontmenumanager.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.

DWIDGET_USE_NAMESPACE
Expand Down
8 changes: 8 additions & 0 deletions deepin-font-manager/interfaces/dfontpreviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
#include "dfontpreviewer.h"
#include "utils.h"

Check warning on line 7 in deepin-font-manager/interfaces/dfontpreviewer.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "utils.h" not found.

#if QT_VERSION_MAJOR <= 5
#include <DApplicationHelper>

Check warning on line 10 in deepin-font-manager/interfaces/dfontpreviewer.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 12 in deepin-font-manager/interfaces/dfontpreviewer.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 <QPainter>

Check warning on line 14 in deepin-font-manager/interfaces/dfontpreviewer.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.
#include <QPaintEvent>

Check warning on line 15 in deepin-font-manager/interfaces/dfontpreviewer.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 16 in deepin-font-manager/interfaces/dfontpreviewer.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

DGUI_USE_NAMESPACE
DFontPreviewer::DFontPreviewer(QWidget *parent)
: QWidget(parent)
{
Expand Down Expand Up @@ -107,7 +111,11 @@ void DFontPreviewer::paintEvent(QPaintEvent *event)
QPen oldPen = painter.pen();

painter.setRenderHint(QPainter::Antialiasing);
#if QT_VERSION_MAJOR > 5
DPalette pa = this->palette();
#else
DPalette pa = DApplicationHelper::instance()->palette(this);
#endif
painter.setBrush(QBrush(pa.color(DPalette::Base)));
painter.setPen(Qt::transparent);

Expand Down
11 changes: 11 additions & 0 deletions deepin-font-manager/interfaces/dfontpreviewitemdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
#include "utils.h"

#include <DApplication>
#if QT_VERSION_MAJOR <= 5
#include <DApplicationHelper>
#endif
#include <DStyleHelper>

#include <QPainter>
Expand Down Expand Up @@ -115,8 +117,13 @@ void DFontPreviewItemDelegate::paintForegroundFontName(QPainter *painter, const
nameFont.setPixelSize(DFontSizeManager::instance()->fontPixelSize(DFontSizeManager::T6));
painter->setFont(nameFont);

#if QT_VERSION_MAJOR > 5
DGuiApplicationHelper *dAppHelper = DGuiApplicationHelper::instance();
DPalette palette = dAppHelper->applicationPalette();
#else
DApplicationHelper *dAppHelper = DApplicationHelper::instance();
DPalette palette = dAppHelper->applicationPalette();
#endif
QColor fillColor = palette.color(DPalette::TextTips);
// SP3--禁用置灰(539)
if (!itemData.isEnabled()) {
Expand Down Expand Up @@ -359,7 +366,11 @@ void DFontPreviewItemDelegate::paintBackground(QPainter *painter, const QStyleOp
painter->fillPath(path, fillColor);
}
} else {
#if QT_VERSION_MAJOR > 5
DPalette pa = DGuiApplicationHelper::instance()->applicationPalette();
#else
DPalette pa = DApplicationHelper::instance()->palette(m_parentView);
#endif
DStyleHelper styleHelper;
QColor fillColor = styleHelper.getColor(static_cast<const QStyleOption *>(&option), pa, DPalette::ItemBackground);
painter->setBrush(QBrush(fillColor));
Expand Down
14 changes: 11 additions & 3 deletions deepin-font-manager/interfaces/dfontpreviewlistdatathread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ void DFontPreviewListDataThread::onFileAdded(const QStringList &files)

if (m_mutex != nullptr)
QMutexLocker locker(m_mutex);
qDebug() << __func__ << "S" << QThread::currentThreadId() << endl;
qDebug() << __func__ << "S" << QThread::currentThreadId() << Qt::endl;
refreshFontListData(false, files);
}

Expand Down Expand Up @@ -418,7 +418,7 @@ void DFontPreviewListDataThread::withoutDbRefreshDb()
if(!m_dbManager->isDBDeleted()){
return;
}
qDebug() << "strAllFontList.size()" << m_allFontPathList.size() << endl;
qDebug() << "strAllFontList.size()" << m_allFontPathList.size() << Qt::endl;

int index = 0;
DFontInfoManager *fontInfoMgr = DFontInfoManager::instance();
Expand Down Expand Up @@ -614,17 +614,25 @@ void DFontPreviewListDataThread:: refreshFontListData(bool isStartup, const QStr
m_diffFontModelList.clear();

//根据文件路径比较出不同的字体文件
#if QT_VERSION_MAJOR > 5
QSet<QString> allFontListSet(m_allFontPathList.begin(), m_allFontPathList.end());
#else
QSet<QString> allFontListSet = m_allFontPathList.toSet();
#endif
QSet<QString> diffSet = allFontListSet.subtract(dbFilePathSet);

qInfo() << "diffSet count:" << diffSet.count();
if (diffSet.count() > 0) {
int maxFontId = m_dbManager->getCurrMaxFontId();
#if QT_VERSION_MAJOR > 5
QSet<QString> diffFilePathList(diffSet.begin(), diffSet.end());
#else
QList<QString> diffFilePathList = diffSet.toList();
#endif
int index = maxFontId + 1;
DFontInfoManager *fontInfoMgr = DFontInfoManager::instance();
DFontInfo info;
for (QString &filePath : diffFilePathList) {
for (const QString &filePath : diffFilePathList) {
if (m_dbManager->isSystemFont(filePath) || installFont.contains(filePath)) {
bool isEnabled = (isStartup && installFont.contains(filePath)) ? false : true;
info = fontInfoMgr->getFontInfo(filePath, true);
Expand Down
46 changes: 42 additions & 4 deletions deepin-font-manager/interfaces/dfontpreviewlistview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
#include "performancemonitor.h"
#include "dcomworker.h"

#if QT_VERSION_MAJOR > 5
#include <algorithm>
#include <functional>
#endif

#include <DMessageManager>

Expand Down Expand Up @@ -337,7 +341,7 @@ void DFontPreviewListView::loadLeftFonts()
if (isListDataLoadFinished()) {
m_fontLoadTimer->stop();
// m_parentWidget->showSpinner(DFontSpinnerWidget::Load);
qDebug() << DFMDBManager::recordList.count() << endl;
qDebug() << DFMDBManager::recordList.count() << Qt::endl;
qDebug() << QThread::currentThreadId() << __func__ << "------------";

m_dataLoadThread = new LoadFontDataThread(DFMDBManager::recordList, this);
Expand Down Expand Up @@ -408,7 +412,11 @@ void DFontPreviewListView::markPositionBeforeRemoved()
{
QModelIndexList deleteFontList = selectedIndexes();
if (deleteFontList.count() > 0) {
#if QT_VERSION_MAJOR > 5
std::sort(deleteFontList.begin(), deleteFontList.end(), std::greater<QModelIndex>());
#else
qSort(deleteFontList.begin(), deleteFontList.end(), qGreater<QModelIndex>());
#endif
QVariant varModel = m_fontPreviewProxyModel->data(deleteFontList.last(), Qt::DisplayRole);
//获取首个选中字体,判断是否为系统字体
FontData fdata = varModel.value<FontData>();
Expand Down Expand Up @@ -528,7 +536,7 @@ void DFontPreviewListView::updateModel(int deleteCount, bool showSpinner)
selectItemAfterRemoved(m_bListviewAtButtom, m_bListviewAtTop, false, false);

//删除之后设置焦点
qDebug() << m_FontViewHasFocus << endl;
qDebug() << m_FontViewHasFocus << Qt::endl;
if (m_FontViewHasFocus) {
refreshFocuses();
setFontViewHasFocus(false);
Expand Down Expand Up @@ -994,7 +1002,11 @@ void DFontPreviewListView::mousePressEvent(QMouseEvent *event)
onMouseLeftBtnPressed(modelIndex, clickPoint, isShiftMd, isCtrlMd);
} else if (event->button() == Qt::RightButton) {
onMouseRightBtnPressed(modelIndex, isShiftMd);
} else if (event->button() == Qt::MidButton) {
#if QT_VERSION_MAJOR > 5
} else if (event->button() == Qt::MiddleButton) {
#else
} else if (event->button() == Qt::MidButton) {
#endif
if (!isShiftMd && !isCtrlMd) {
clearSelection();
setCurrentIndex(modelIndex);
Expand Down Expand Up @@ -1093,7 +1105,7 @@ void DFontPreviewListView::onMouseRightBtnPressed(const QModelIndex &modelIndex,
}
//记录焦点状态
syncRecoveryTabStatus();
qDebug() << hasFocus() << endl;
qDebug() << hasFocus() << Qt::endl;
setFontViewHasFocus(hasFocus());
//弹出右键菜单
onListViewShowContextMenu();
Expand All @@ -1113,7 +1125,11 @@ void DFontPreviewListView::onMouseRightBtnPressed(const QModelIndex &modelIndex,
*************************************************************************/
void DFontPreviewListView::mouseReleaseEvent(QMouseEvent *event)
{
#if QT_VERSION_MAJOR > 5
if (Qt::MiddleButton == event->button()) {
#else
if (Qt::MidButton == event->button()) {
#endif
return;
}
QListView::mouseReleaseEvent(event);
Expand Down Expand Up @@ -1339,7 +1355,11 @@ void DFontPreviewListView::keyPressEvent(QKeyEvent *event)
} else {
if (event->key() == Qt::Key_Up || event->key() == Qt::Key_Down) {
QModelIndexList list = selectedIndexes();
#if QT_VERSION_MAJOR > 5
std::sort(list.begin(), list.end(), std::greater<QModelIndex>());
#else
qSort(list.begin(), list.end(), qGreater<QModelIndex>());
#endif
//判断当前shift+上下键选中
if (QApplication::keyboardModifiers() == Qt::ShiftModifier && list.count() > 0) {
if (event->key() == Qt::Key_Up) {
Expand Down Expand Up @@ -1635,7 +1655,11 @@ void DFontPreviewListView::onRightMenuShortCutActivated()
DFontMgrMainWindow *mw = qobject_cast<DFontMgrMainWindow *>(m_parentWidget);
QModelIndexList indexes = selectedIndexes();
//排序选中项
#if QT_VERSION_MAJOR > 5
std::sort(indexes.begin(), indexes.end());
#else
qSort(indexes.begin(), indexes.end());
#endif
//菜单弹出位置
QPoint showMenuPosition;
//记录鼠标位置下的QModelIndex
Expand Down Expand Up @@ -1733,8 +1757,13 @@ void DFontPreviewListView::onEnableBtnClicked(QModelIndexList &itemIndexes, int
QMutexLocker locker(&m_mutex);
QString fontName;

#if QT_VERSION_MAJOR > 5
if (isFromActiveFont)
std::sort(itemIndexes.begin(), itemIndexes.end(), std::greater<QModelIndex>());
#else
if (isFromActiveFont)
qSort(itemIndexes.begin(), itemIndexes.end(), qGreater<QModelIndex>());
#endif

//记录禁用前选中位置
getAtListViewPosition();
Expand Down Expand Up @@ -1863,8 +1892,13 @@ void DFontPreviewListView::onCollectBtnClicked(QModelIndexList &indexList, bool
qDebug() << __FUNCTION__ << " before " << currModelIndex().row() << currentIndex().row();

QMutexLocker locker(&m_mutex);
#if QT_VERSION_MAJOR > 5
if (isFromCollectFont)
std::sort(indexList.begin(), indexList.end(), std::greater<QModelIndex>());
#else
if (isFromCollectFont)
qSort(indexList.begin(), indexList.end(), qGreater<QModelIndex>());
#endif
m_selectAfterDel = indexList.last().row();

getAtListViewPosition();
Expand Down Expand Up @@ -2369,7 +2403,11 @@ void DFontPreviewListView::scrollWithTheSelected()
return;
}
QModelIndexList indexes = selectionModel()->selectedIndexes();
#if QT_VERSION_MAJOR > 5
std::sort(indexes.begin(), indexes.end(), std::greater<QModelIndex>());
#else
qSort(indexes.begin(), indexes.end(), qGreater<QModelIndex>());
#endif
bool needScroll = true;
for (auto &idx : indexes) {
QRect rect = visualRect(idx);
Expand Down
4 changes: 4 additions & 0 deletions deepin-font-manager/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
#include <DApplication>
#include <DLog>
#include <DWidgetUtil>
#if QT_VERSION_MAJOR <= 5
#include <DApplicationSettings>
#endif

#include <QDebug>
#include <QDBusConnection>
Expand Down Expand Up @@ -57,7 +59,9 @@ int main(int argc, char *argv[])
app.setApplicationDescription(DApplication::translate("Main", "Font Manager helps users install and manage fonts."));
app.setApplicationDisplayName(DApplication::translate("Main", "Font Manager"));

#if QT_VERSION_MAJOR <= 5
DApplicationSettings savetheme;
#endif

DLogManager::registerConsoleAppender();
DLogManager::registerFileAppender();
Expand Down
4 changes: 4 additions & 0 deletions deepin-font-manager/singlefontapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,11 @@ void SingleFontApplication::activateWindow()
void SingleFontApplication::slotBatchInstallFonts()
{
qDebug() << "batch install fonts";
#if QT_VERSION_MAJOR > 5
m_selectedFiles << QList<QString>(waitForInstallSet.begin(), waitForInstallSet.end());
#else
m_selectedFiles << waitForInstallSet.toList();
#endif
activateWindow();
m_selectedFiles.clear();
waitForInstallSet.clear();
Expand Down
Loading

0 comments on commit db3ac9f

Please sign in to comment.