From db3ac9f3d420a6b0db169dd4c3a749ffa17d3d89 Mon Sep 17 00:00:00 2001 From: xiepengfei Date: Tue, 14 Jan 2025 15:42:47 +0800 Subject: [PATCH] feat: QT6 adaptation QT6 adaptation Log: QT6 adaptation --- CMakeLists.txt | 11 ++- deepin-font-manager/CMakeLists.txt | 18 ++++- .../interfaces/dfmxmlwrapper.cpp | 4 +- .../interfaces/dfontmenumanager.cpp | 4 + .../interfaces/dfontpreviewer.cpp | 8 ++ .../interfaces/dfontpreviewitemdelegate.cpp | 11 +++ .../interfaces/dfontpreviewlistdatathread.cpp | 14 +++- .../interfaces/dfontpreviewlistview.cpp | 46 +++++++++++- deepin-font-manager/main.cpp | 4 + deepin-font-manager/singlefontapplication.cpp | 4 + deepin-font-manager/views/dfdeletedialog.cpp | 37 ++++++++- .../views/dfinstallerrordialog.cpp | 30 ++++++-- .../views/dfinstallerrorlistview.cpp | 20 ++++- .../views/dfinstallnormalwindow.cpp | 20 ++--- deepin-font-manager/views/dfontinfodialog.cpp | 75 ++++++++++++++++++- .../views/dfontinfoscrollarea.cpp | 20 +++++ .../views/dfontmgrmainwindow.cpp | 67 ++++++++++++----- .../views/dfontmgrmainwindow.h | 1 + .../views/dfquickinstallwindow.cpp | 19 ++++- .../views/dsplitlistwidget.cpp | 26 +++++++ deepin-font-preview-plugin/CMakeLists.txt | 10 +-- libdeepin-font-manager/dcopyfilesmanager.h | 4 + libdeepin-font-manager/dfontinfomanager.cpp | 11 +++ libdeepin-font-manager/dfontpreview.cpp | 20 +++++ libdeepin-font-manager/dfontwidget.cpp | 2 +- libdeepin-font-manager/fontmanagercore.cpp | 10 +-- tests/CMakeLists.txt | 22 +++++- .../interfaces/ut_dfontbasedialog.cpp | 3 +- .../interfaces/ut_dfontmenumanager.cpp | 2 + .../ut_dfontpreviewitemdelegate.cpp | 2 + .../ut_dfontpreviewlistdatathread.cpp | 2 +- .../interfaces/ut_dfontpreviewlistview.cpp | 41 ++++++++-- .../views/ut_dfdeletedialog.cpp | 6 ++ .../views/ut_dfinstallerrordialog.cpp | 2 + .../views/ut_dfinstallerrorlistview.cpp | 2 + .../views/ut_dfinstallnormalwindow.cpp | 2 + .../views/ut_dfontInfo.cpp | 2 +- .../views/ut_dfontinfodialog.cpp | 26 ++++++- .../views/ut_dfontmgrmainwindow.cpp | 6 ++ .../views/ut_dfquickinstallwindow.cpp | 2 + .../views/ut_dsplitlistwidget.cpp | 5 +- tests/src/ut_dfontmanager.cpp | 4 +- tests/src/ut_dfontpreview.cpp | 2 + tests/src/ut_dfontpreviewLib.cpp | 2 + 44 files changed, 543 insertions(+), 86 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e33440a2..0701f11d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/deepin-font-manager/CMakeLists.txt b/deepin-font-manager/CMakeLists.txt index 10ad6b61..fd66c2cd 100644 --- a/deepin-font-manager/CMakeLists.txt +++ b/deepin-font-manager/CMakeLists.txt @@ -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}) diff --git a/deepin-font-manager/interfaces/dfmxmlwrapper.cpp b/deepin-font-manager/interfaces/dfmxmlwrapper.cpp index d64822a3..c6344b10 100644 --- a/deepin-font-manager/interfaces/dfmxmlwrapper.cpp +++ b/deepin-font-manager/interfaces/dfmxmlwrapper.cpp @@ -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; } } diff --git a/deepin-font-manager/interfaces/dfontmenumanager.cpp b/deepin-font-manager/interfaces/dfontmenumanager.cpp index 0dd0633d..640a058e 100644 --- a/deepin-font-manager/interfaces/dfontmenumanager.cpp +++ b/deepin-font-manager/interfaces/dfontmenumanager.cpp @@ -5,7 +5,11 @@ #include "interfaces/dfontmenumanager.h" +#include + +#if QT_VERSION_MAJOR <= 5 #include +#endif #include DWIDGET_USE_NAMESPACE diff --git a/deepin-font-manager/interfaces/dfontpreviewer.cpp b/deepin-font-manager/interfaces/dfontpreviewer.cpp index 7e02a8ad..dee47b1e 100644 --- a/deepin-font-manager/interfaces/dfontpreviewer.cpp +++ b/deepin-font-manager/interfaces/dfontpreviewer.cpp @@ -6,12 +6,16 @@ #include "dfontpreviewer.h" #include "utils.h" +#if QT_VERSION_MAJOR <= 5 #include +#endif +#include #include #include #include +DGUI_USE_NAMESPACE DFontPreviewer::DFontPreviewer(QWidget *parent) : QWidget(parent) { @@ -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); diff --git a/deepin-font-manager/interfaces/dfontpreviewitemdelegate.cpp b/deepin-font-manager/interfaces/dfontpreviewitemdelegate.cpp index 3787f1c5..2f284f3f 100644 --- a/deepin-font-manager/interfaces/dfontpreviewitemdelegate.cpp +++ b/deepin-font-manager/interfaces/dfontpreviewitemdelegate.cpp @@ -29,7 +29,9 @@ #include "utils.h" #include +#if QT_VERSION_MAJOR <= 5 #include +#endif #include #include @@ -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()) { @@ -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(&option), pa, DPalette::ItemBackground); painter->setBrush(QBrush(fillColor)); diff --git a/deepin-font-manager/interfaces/dfontpreviewlistdatathread.cpp b/deepin-font-manager/interfaces/dfontpreviewlistdatathread.cpp index da67176f..ba266c05 100644 --- a/deepin-font-manager/interfaces/dfontpreviewlistdatathread.cpp +++ b/deepin-font-manager/interfaces/dfontpreviewlistdatathread.cpp @@ -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); } @@ -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(); @@ -614,17 +614,25 @@ void DFontPreviewListDataThread:: refreshFontListData(bool isStartup, const QStr m_diffFontModelList.clear(); //根据文件路径比较出不同的字体文件 +#if QT_VERSION_MAJOR > 5 + QSet allFontListSet(m_allFontPathList.begin(), m_allFontPathList.end()); +#else QSet allFontListSet = m_allFontPathList.toSet(); +#endif QSet diffSet = allFontListSet.subtract(dbFilePathSet); qInfo() << "diffSet count:" << diffSet.count(); if (diffSet.count() > 0) { int maxFontId = m_dbManager->getCurrMaxFontId(); +#if QT_VERSION_MAJOR > 5 + QSet diffFilePathList(diffSet.begin(), diffSet.end()); +#else QList 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); diff --git a/deepin-font-manager/interfaces/dfontpreviewlistview.cpp b/deepin-font-manager/interfaces/dfontpreviewlistview.cpp index 6258264b..7289041a 100644 --- a/deepin-font-manager/interfaces/dfontpreviewlistview.cpp +++ b/deepin-font-manager/interfaces/dfontpreviewlistview.cpp @@ -12,6 +12,10 @@ #include "performancemonitor.h" #include "dcomworker.h" +#if QT_VERSION_MAJOR > 5 +#include +#include +#endif #include @@ -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); @@ -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()); +#else qSort(deleteFontList.begin(), deleteFontList.end(), qGreater()); +#endif QVariant varModel = m_fontPreviewProxyModel->data(deleteFontList.last(), Qt::DisplayRole); //获取首个选中字体,判断是否为系统字体 FontData fdata = varModel.value(); @@ -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); @@ -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); @@ -1093,7 +1105,7 @@ void DFontPreviewListView::onMouseRightBtnPressed(const QModelIndex &modelIndex, } //记录焦点状态 syncRecoveryTabStatus(); - qDebug() << hasFocus() << endl; + qDebug() << hasFocus() << Qt::endl; setFontViewHasFocus(hasFocus()); //弹出右键菜单 onListViewShowContextMenu(); @@ -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); @@ -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()); +#else qSort(list.begin(), list.end(), qGreater()); +#endif //判断当前shift+上下键选中 if (QApplication::keyboardModifiers() == Qt::ShiftModifier && list.count() > 0) { if (event->key() == Qt::Key_Up) { @@ -1635,7 +1655,11 @@ void DFontPreviewListView::onRightMenuShortCutActivated() DFontMgrMainWindow *mw = qobject_cast(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 @@ -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()); +#else if (isFromActiveFont) qSort(itemIndexes.begin(), itemIndexes.end(), qGreater()); +#endif //记录禁用前选中位置 getAtListViewPosition(); @@ -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()); +#else if (isFromCollectFont) qSort(indexList.begin(), indexList.end(), qGreater()); +#endif m_selectAfterDel = indexList.last().row(); getAtListViewPosition(); @@ -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()); +#else qSort(indexes.begin(), indexes.end(), qGreater()); +#endif bool needScroll = true; for (auto &idx : indexes) { QRect rect = visualRect(idx); diff --git a/deepin-font-manager/main.cpp b/deepin-font-manager/main.cpp index 94ab43d0..cd711c9a 100644 --- a/deepin-font-manager/main.cpp +++ b/deepin-font-manager/main.cpp @@ -13,7 +13,9 @@ #include #include #include +#if QT_VERSION_MAJOR <= 5 #include +#endif #include #include @@ -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(); diff --git a/deepin-font-manager/singlefontapplication.cpp b/deepin-font-manager/singlefontapplication.cpp index 269b6f89..4c4fed78 100644 --- a/deepin-font-manager/singlefontapplication.cpp +++ b/deepin-font-manager/singlefontapplication.cpp @@ -225,7 +225,11 @@ void SingleFontApplication::activateWindow() void SingleFontApplication::slotBatchInstallFonts() { qDebug() << "batch install fonts"; +#if QT_VERSION_MAJOR > 5 + m_selectedFiles << QList(waitForInstallSet.begin(), waitForInstallSet.end()); +#else m_selectedFiles << waitForInstallSet.toList(); +#endif activateWindow(); m_selectedFiles.clear(); waitForInstallSet.clear(); diff --git a/deepin-font-manager/views/dfdeletedialog.cpp b/deepin-font-manager/views/dfdeletedialog.cpp index a50a3927..be99212d 100644 --- a/deepin-font-manager/views/dfdeletedialog.cpp +++ b/deepin-font-manager/views/dfdeletedialog.cpp @@ -9,7 +9,9 @@ #include "dfontmgrmainwindow.h" #include +#if QT_VERSION_MAJOR <= 5 #include +#endif #include #include @@ -37,7 +39,11 @@ NewStr autoCutText(const QString &text, DLabel *pDesLbl) QFont font; // 应用使用字体对象 QFontMetrics font_label(font); QString strText = text; +#if QT_VERSION_MAJOR > 5 + int titlewidth = font_label.boundingRect(strText).width(); +#else int titlewidth = font_label.width(strText); +#endif QString str; NewStr newstr; int width = pDesLbl->width(); @@ -48,7 +54,11 @@ NewStr autoCutText(const QString &text, DLabel *pDesLbl) for (int i = 0; i < strText.count(); i++) { str += strText.at(i); +#if QT_VERSION_MAJOR > 5 + if (font_label.boundingRect(str).width() > width) { //根据label宽度调整每行字符数 +#else if (font_label.width(str) > width) { //根据label宽度调整每行字符数 +#endif str.remove(str.count() - 1, 1); newstr.strList.append(str); newstr.resultStr += str + "\n"; @@ -169,7 +179,11 @@ void DFDeleteDialog::initConnections() connect(qApp, &DApplication::fontChanged, this, &DFDeleteDialog::onFontChanged); +#if QT_VERSION_MAJOR > 5 + connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, &DFDeleteDialog::setTheme); +#else connect(DApplicationHelper::instance(), &DApplicationHelper::themeTypeChanged, this, &DFDeleteDialog::setTheme); +#endif } /************************************************************************* @@ -290,11 +304,19 @@ void DFDeleteDialog::keyPressEvent(QKeyEvent *event) void DFDeleteDialog::setTheme() { // 根据主题设置文字颜色 +#if QT_VERSION_MAJOR > 5 + DPalette pamessageTitle = messageTitle->palette(); + DPalette pamessageDetail = messageDetail->palette(); + QColor pamessageTitleColor = pamessageTitle.color(DPalette::Active, DPalette::BrightText); + QColor pamessageDetailColor = pamessageDetail.color(DPalette::Active, DPalette::BrightText); + if (DGuiApplicationHelper::DarkType == DGuiApplicationHelper::instance()->themeType()) { +#else DPalette pamessageTitle = DApplicationHelper::instance()->palette(messageTitle); DPalette pamessageDetail = DApplicationHelper::instance()->palette(messageDetail); QColor pamessageTitleColor = pamessageTitle.color(DPalette::Active, DPalette::BrightText); QColor pamessageDetailColor = pamessageDetail.color(DPalette::Active, DPalette::BrightText); if (DApplicationHelper::DarkType == DApplicationHelper::instance()->themeType()) { +#endif pamessageTitleColor.setAlphaF(1.0); pamessageDetailColor.setAlphaF(0.7); } else { @@ -302,9 +324,14 @@ void DFDeleteDialog::setTheme() pamessageDetailColor.setAlphaF(0.7); } pamessageTitle.setColor(DPalette::Active, DPalette::WindowText, pamessageTitleColor); - DApplicationHelper::instance()->setPalette(messageTitle, pamessageTitle); pamessageDetail.setColor(DPalette::Active, DPalette::WindowText, pamessageDetailColor); +#if QT_VERSION_MAJOR > 5 + messageTitle->setPalette(pamessageTitle); + messageDetail->setPalette(pamessageDetail); +#else + DApplicationHelper::instance()->setPalette(messageTitle, pamessageTitle); DApplicationHelper::instance()->setPalette(messageDetail, pamessageDetail); +#endif } DFHandleTTCDialog::DFHandleTTCDialog(DFontMgrMainWindow *win, QString &file, QWidget *parent) @@ -452,11 +479,15 @@ QLayout *DFHandleTTCDialog::initBottomButtons() setConfirmBtnText(); DVerticalLine *verticalSplite = new DVerticalLine(this); +#if QT_VERSION_MAJOR > 5 + DPalette pa = verticalSplite->palette(); +#else DPalette pa = DApplicationHelper::instance()->palette(verticalSplite); +#endif QColor splitColor = pa.color(DPalette::ItemBackground); - pa.setBrush(DPalette::Background, splitColor); + pa.setBrush(DPalette::Window, splitColor); verticalSplite->setPalette(pa); - verticalSplite->setBackgroundRole(QPalette::Background); + verticalSplite->setBackgroundRole(QPalette::Window); verticalSplite->setAutoFillBackground(true); verticalSplite->setFixedSize(3, 28); diff --git a/deepin-font-manager/views/dfinstallerrordialog.cpp b/deepin-font-manager/views/dfinstallerrordialog.cpp index 3b521580..bb834060 100644 --- a/deepin-font-manager/views/dfinstallerrordialog.cpp +++ b/deepin-font-manager/views/dfinstallerrordialog.cpp @@ -9,7 +9,9 @@ #include "utils.h" #include +#if QT_VERSION_MAJOR <= 5 #include +#endif #include #include @@ -62,12 +64,12 @@ DFInstallErrorDialog::DFInstallErrorDialog(QWidget *parent, const QStringList &e *************************************************************************/ DFInstallErrorDialog::~DFInstallErrorDialog() { - qDebug() << __func__ << "start" << endl; + qDebug() << __func__ << "start" << Qt::endl; emit m_signalManager->hideInstallErrorDialog(); m_errorInstallFiles.clear(); m_installErrorFontModelList.clear(); // m_NeedSelectFiles.clear(); - qDebug() << __func__ << "end" << endl; + qDebug() << __func__ << "end" << Qt::endl; } /************************************************************************* @@ -137,7 +139,11 @@ void DFInstallErrorDialog::initData() void DFInstallErrorDialog::initUI() { setContentsMargins(0, 0, 0, 0); +#if QT_VERSION_MAJOR > 5 + setIcon(Utils::renderSVG("://exception-logo.svg", QSize(32, 32))); +#else setIconPixmap(Utils::renderSVG("://exception-logo.svg", QSize(32, 32))); +#endif setWindowTitle(DApplication::translate("ExceptionWindow", "Font Verification")); this->setFixedSize(448, 302); @@ -155,11 +161,15 @@ void DFInstallErrorDialog::initUI() DVerticalLine *verticalSplit = new DVerticalLine; verticalSplit->setFixedWidth(1); verticalSplit->setFixedHeight(28); +#if QT_VERSION_MAJOR > 5 + DPalette pa = verticalSplit->palette(); +#else DPalette pa = DApplicationHelper::instance()->palette(verticalSplit); +#endif QBrush splitBrush = pa.brush(DPalette::ItemBackground); - pa.setBrush(DPalette::Background, splitBrush); + pa.setBrush(DPalette::Window, splitBrush); verticalSplit->setPalette(pa); - verticalSplit->setBackgroundRole(QPalette::Background); + verticalSplit->setBackgroundRole(QPalette::Window); verticalSplit->setAutoFillBackground(true); m_installErrorListView = new DFInstallErrorListView(m_installErrorFontModelList, this); @@ -358,7 +368,7 @@ void DFInstallErrorDialog::onListItemsClicked(const QModelIndexList &indexList) qvariant_cast(m_installErrorListView->getErrorListSourceModel()->data(firstIndex)); for (auto &it : indexList) { - qDebug() << it.row() << "++++++++++++++++++++++++++++++" << endl; + qDebug() << it.row() << "++++++++++++++++++++++++++++++" << Qt::endl; DFInstallErrorItemModel itemModel2 = qvariant_cast(m_installErrorListView->getErrorListSourceModel()->data(it)); if (itemModel2.bIsNormalUserFont) { @@ -387,7 +397,7 @@ void DFInstallErrorDialog::addData(QStringList &errorFileList, QStringList &half for (auto &it : errorFileList) { fontInfo = fontInfoManager->getFontInfo(it); - qDebug() << "getfontinfo success!!!!!!!!!!1" << endl; + qDebug() << "getfontinfo success!!!!!!!!!!1" << Qt::endl; DFInstallErrorItemModel itemModel; if (fontInfo.isError) { QFileInfo fileInfo(it); @@ -489,10 +499,18 @@ void DFInstallErrorDialog::slotSizeModeChanged(DGuiApplicationHelper::SizeMode s Utils::clearImgCache(); if (sizeMode == DGuiApplicationHelper::SizeMode::CompactMode) { this->setFixedSize(448, 259); +#if QT_VERSION_MAJOR > 5 + setIcon(Utils::renderSVG("://exception-logo.svg", QSize(25, 25))); +#else setIconPixmap(Utils::renderSVG("://exception-logo.svg", QSize(25, 25))); +#endif } else { this->setFixedSize(448, 302); +#if QT_VERSION_MAJOR > 5 + setIcon(Utils::renderSVG("://exception-logo.svg", QSize(32, 32))); +#else setIconPixmap(Utils::renderSVG("://exception-logo.svg", QSize(32, 32))); +#endif } } #endif diff --git a/deepin-font-manager/views/dfinstallerrorlistview.cpp b/deepin-font-manager/views/dfinstallerrorlistview.cpp index 53b497c4..08b41226 100644 --- a/deepin-font-manager/views/dfinstallerrorlistview.cpp +++ b/deepin-font-manager/views/dfinstallerrorlistview.cpp @@ -9,7 +9,9 @@ #include #include +#if QT_VERSION_MAJOR <= 5 #include +#endif #include #include @@ -124,10 +126,18 @@ void DFInstallErrorListDelegate::drawFontName(QPainter *painter, const QStyleOpt int fontNameLeft = FTM_ERROR_ITEM_FONTNAME_LEFT; QFontMetrics fontMetric(nameFont); +#if QT_VERSION_MAJOR > 5 + int m_StatusWidth = fontMetric.boundingRect(strStatus).width(); +#else int m_StatusWidth = fontMetric.width(strStatus); +#endif if (m_StatusWidth > statusLabelMaxWidth) m_StatusWidth = statusLabelMaxWidth; +#if QT_VERSION_MAJOR > 5 + int m_NameWidth = fontMetric.boundingRect(strFontFileName).width(); +#else int m_NameWidth = fontMetric.width(strFontFileName); +#endif int fontFileNameRectHeight = 30; QRect fontFileNameRect = QRect(bgRect.left() + fontNameLeft, @@ -239,7 +249,6 @@ void DFInstallErrorListDelegate::drawSelectStatus(QPainter *painter, const QStyl if (m_parentView->getIsTabFocus() == true) { paintTabFocusBackground(painter, option, bgRect); } else { - DPalette pa = DApplicationHelper::instance()->applicationPalette(); DStyleHelper styleHelper; QColor fillColor = styleHelper.getColor(static_cast(&option), DPalette::ToolTipText); fillColor.setAlphaF(0.2); @@ -292,7 +301,6 @@ void DFInstallErrorListDelegate::paintTabFocusBackground(QPainter *painter, cons painter->fillPath(path2, painter->brush()); DStyleHelper styleHelper; - DPalette pa = DApplicationHelper::instance()->applicationPalette(); QColor fillColor3 = styleHelper.getColor(static_cast(&option), DPalette::ToolTipText); fillColor3.setAlphaF(0.2); @@ -323,7 +331,11 @@ QString DFInstallErrorListDelegate::lengthAutoFeed(QPainter *painter, QString so m_Suffix.append(sourceStr.right(5)); m_TargetStr.append(m_Suffix); +#if QT_VERSION_MAJOR > 5 + int m_TargetStrWidth = fontMetric.boundingRect(m_TargetStr).width(); +#else int m_TargetStrWidth = fontMetric.width(m_TargetStr); +#endif int m_index = 1; @@ -331,7 +343,11 @@ QString DFInstallErrorListDelegate::lengthAutoFeed(QPainter *painter, QString so // 每次插入一个字符,直到长度超过最大范围 m_TargetStr.insert(m_index, sourceStr.at(m_index)); +#if QT_VERSION_MAJOR > 5 + m_TargetStrWidth = fontMetric.boundingRect(m_TargetStr).width(); +#else m_TargetStrWidth = fontMetric.width(m_TargetStr); +#endif m_index++; } diff --git a/deepin-font-manager/views/dfinstallnormalwindow.cpp b/deepin-font-manager/views/dfinstallnormalwindow.cpp index d81ff340..3dd12846 100644 --- a/deepin-font-manager/views/dfinstallnormalwindow.cpp +++ b/deepin-font-manager/views/dfinstallnormalwindow.cpp @@ -84,7 +84,7 @@ DFInstallNormalWindow::DFInstallNormalWindow(const QStringList &files, QWidget * *************************************************************************/ DFInstallNormalWindow::~DFInstallNormalWindow() { - qDebug() << __func__ << "start" << endl; + qDebug() << __func__ << "start" << Qt::endl; // 结束线程 m_pthread->quit(); @@ -111,7 +111,7 @@ DFInstallNormalWindow::~DFInstallNormalWindow() //恢复标志位 m_skipStateRecovery = false; } - qDebug() << __func__ << "end" << this << endl; + qDebug() << __func__ << "end" << this << Qt::endl; } /************************************************************************* @@ -220,7 +220,7 @@ void DFInstallNormalWindow::getAllSysfiles() QString systemFileName; systemFileName.append(font.fontInfo.familyName).append(font.fontInfo.styleName); m_fontName.append(font.fontData.strFontName); - qDebug() << font.fontInfo.fullname << endl; + qDebug() << font.fontInfo.fullname << Qt::endl; m_AllSysFilesfamilyName.append(systemFileName); } @@ -389,17 +389,17 @@ bool DFInstallNormalWindow::isSystemFont(DFontInfo &f) *************************************************************************/ void DFInstallNormalWindow::checkShowMessage() { - qDebug() << "Install over" << endl; + qDebug() << "Install over" << Qt::endl; if (getInstallMessage == true && getReInstallMessage == true) { qDebug() << "install refresh over"; finishInstall(); } else if (getInstallMessage == true && m_popedInstallErrorDialg == false) { if (ifNeedShowExceptionWindow()) { - qDebug() << "need reinstall " << endl; + qDebug() << "need reinstall " << Qt::endl; Q_EMIT sigShowInstallErrDlg(); } else { - qDebug() << "no need reinstall" << endl; + qDebug() << "no need reinstall" << Qt::endl; //不需恢复添加按钮tab状态 m_skipStateRecovery = true; finishInstall(); @@ -530,7 +530,7 @@ void DFInstallNormalWindow::batchInstall() // qDebug() << " Prepare install file: " << it + "|" + familyName; } -// qDebug() << installListWithFamliyName << endl; +// qDebug() << installListWithFamliyName << Qt::endl; if (ifNeedShowExceptionWindow()) { m_fontManager->setCacheStatus(FontManagerCore::CacheLater); @@ -555,7 +555,7 @@ void DFInstallNormalWindow::batchInstall() *************************************************************************/ void DFInstallNormalWindow::batchReInstall(const QStringList &reinstallFiles) { - qDebug() << "start" << __FUNCTION__ << endl; + qDebug() << "start" << __FUNCTION__ << Qt::endl; QStringList installListWithFamliyName; for (auto &it : reinstallFiles) { @@ -585,7 +585,7 @@ void DFInstallNormalWindow::batchHalfwayInstall(const QStringList &filelist) m_installFiles = filelist; verifyFontFiles(); - qDebug() << m_newHalfInstalledFiles.count() << "*" << m_oldHalfInstalledFiles.count() << endl; + qDebug() << m_newHalfInstalledFiles.count() << "*" << m_oldHalfInstalledFiles.count() << Qt::endl; m_halfInstalledFiles.append(m_newHalfInstalledFiles); //当安装的字体是需要新添加到字体验证框时或者已经添加到字体验证框时,刷新listview. @@ -799,7 +799,7 @@ void DFInstallNormalWindow::showInstallErrDlg() finishInstall(); }); - qDebug() << geometry().center() << "+" << m_pexceptionDlg->rect().center() << endl; + qDebug() << geometry().center() << "+" << m_pexceptionDlg->rect().center() << Qt::endl; m_pexceptionDlg->move(geometry().center() - m_pexceptionDlg->rect().center()); m_pexceptionDlg->exec(); diff --git a/deepin-font-manager/views/dfontinfodialog.cpp b/deepin-font-manager/views/dfontinfodialog.cpp index 8f7cd165..b5d47add 100644 --- a/deepin-font-manager/views/dfontinfodialog.cpp +++ b/deepin-font-manager/views/dfontinfodialog.cpp @@ -10,7 +10,9 @@ #include "dfontinfoscrollarea.h" #include +#if QT_VERSION_MAJOR <= 5 #include +#endif #include #include @@ -56,13 +58,21 @@ QString DFontInfoDialog::AutoFeed(QString text) { QFont m_CurrentFont = this->font(); QFontMetrics fm(m_CurrentFont); +#if QT_VERSION_MAJOR > 5 + int n_TextSize = fm.boundingRect(text).width(); +#else int n_TextSize = fm.width(text); +#endif int count = 0; if (n_TextSize > NAME_TITLE_WIDTH) { int n_position = 0; long n_curSumWidth = 0; for (int i = 0; i < text.size(); i++) { +#if QT_VERSION_MAJOR > 5 + n_curSumWidth += fm.boundingRect(text.at(i)).width(); +#else n_curSumWidth += fm.width(text.at(i)); +#endif if (n_curSumWidth >= NAME_TITLE_WIDTH * (count + 1)) { n_position = i; text.insert(n_position, "\n"); @@ -93,12 +103,21 @@ QString DFontInfoDialog::AutoFeed(QString text) *************************************************************************/ QString DFontInfoDialog::adaptiveLengthForNameTitle(QFontMetrics fm, QString thirdLineText, int lineWidth) { +#if QT_VERSION_MAJOR > 5 + if (fm.boundingRect(thirdLineText).width() > lineWidth) { +#else if (fm.width(thirdLineText) > lineWidth) { +#endif QString s = thirdLineText.right(6); int width = 0; for (int i = 0; i < thirdLineText.size(); i++) { +#if QT_VERSION_MAJOR > 5 + width += fm.boundingRect(thirdLineText.at(i)).width(); + if (width > (lineWidth - (fm.boundingRect(s).width() + fm.boundingRect("...").width()))) { +#else width += fm.width(thirdLineText.at(i)); if (width > (lineWidth - (fm.width(s) + fm.width("...")))) { +#endif thirdLineText.remove(i, thirdLineText.size()); thirdLineText.append("...").append(s); break; @@ -157,7 +176,11 @@ void DFontInfoDialog::initUI() m_fontFileName->setText(text); // Set color +#if QT_VERSION_MAJOR > 5 + DPalette pa = m_fontFileName->palette(); +#else DPalette pa = DApplicationHelper::instance()->palette(m_fontFileName); +#endif pa.setBrush(DPalette::WindowText, pa.color(DPalette::ToolTipText)); m_fontFileName->setPalette(pa); @@ -174,7 +197,7 @@ void DFontInfoDialog::initUI() p.drawRoundedRect(bmp.rect(), 12, 12); p.setRenderHint(QPainter::Antialiasing); - m_scrollArea->viewport()->setMask(bmp); + m_scrollArea->viewport()->setMask(QBitmap::fromPixmap(bmp)); m_scrollArea->setFrameShape(QFrame::Shape::NoFrame); m_fontinfoArea = new dfontinfoscrollarea(m_fontInfo, this); @@ -193,19 +216,35 @@ void DFontInfoDialog::initUI() m_mainFrame->setLayout(mainLayout); addContent(m_mainFrame); +#if QT_VERSION_MAJOR > 5 + if (DGuiApplicationHelper::DarkType == DGuiApplicationHelper::instance()->themeType()) { + DPalette paFrame = m_scrollArea->viewport()->palette(); +#else if (DApplicationHelper::DarkType == DGuiApplicationHelper::instance()->themeType()) { DPalette paFrame = DApplicationHelper::instance()->palette(m_scrollArea->viewport()); +#endif QColor colorFrame = paFrame.textLively().color(); colorFrame.setAlphaF(0.05); paFrame.setColor(DPalette::Base, colorFrame); +#if QT_VERSION_MAJOR > 5 + m_scrollArea->viewport()->setPalette(paFrame); + + } else if (DGuiApplicationHelper::LightType == DGuiApplicationHelper::instance()->themeType()) { + DPalette paFrame = m_scrollArea->viewport()->palette(); +#else DApplicationHelper::instance()->setPalette(m_scrollArea->viewport(), paFrame); } else if (DApplicationHelper::LightType == DGuiApplicationHelper::instance()->themeType()) { DPalette paFrame = DApplicationHelper::instance()->palette(m_scrollArea->viewport()); +#endif QColor colorFrame = paFrame.textLively().color(); colorFrame.setAlphaF(0.70); paFrame.setColor(DPalette::Base, colorFrame); +#if QT_VERSION_MAJOR > 5 + m_scrollArea->viewport()->setPalette(paFrame); +#else DApplicationHelper::instance()->setPalette(m_scrollArea->viewport(), paFrame); +#endif } m_fontinfoArea->autoHeight(); m_scrollArea->setFocus(Qt::MouseFocusReason); @@ -221,6 +260,33 @@ void DFontInfoDialog::initUI() *************************************************************************/ void DFontInfoDialog::initConnections() { +#if QT_VERSION_MAJOR > 5 + connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, [ = ] { + DGuiApplicationHelper::ColorType themeType = DGuiApplicationHelper::instance()->themeType(); + + if (DGuiApplicationHelper::DarkType == themeType) + { + DPalette paFrame = m_scrollArea->viewport()->palette(); + QColor colorFrame = paFrame.textLively().color(); + colorFrame.setAlphaF(0.05); + paFrame.setColor(DPalette::Base, colorFrame); + m_scrollArea->viewport()->setPalette(paFrame); + //通过m_fontFileName->setPalette(pa)未实现更新字体颜色,在此根据主题变化同步更新字体名称标签的颜色属性 + m_fontFileName->setPalette(paFrame); + + } else if (DGuiApplicationHelper::LightType == themeType) + { + DPalette paFrame = m_scrollArea->viewport()->palette(); + //使用构造函数中有关设置,会导致颜色重叠的异常的情况,故在此使用固定颜色,与textLively中#FFFFFF同色号 + QColor colorFrame(255, 255, 255); + colorFrame.setAlphaF(0.70); + paFrame.setColor(DPalette::Base, colorFrame); + m_scrollArea->viewport()->setPalette(paFrame); + //同时更新字体名称标签的颜色属性,跟随主题,原因同上 + m_fontFileName->setPalette(paFrame); + } + }); +#else connect(DApplicationHelper::instance(), &DApplicationHelper::themeTypeChanged, this, [ = ] { DGuiApplicationHelper::ColorType themeType = DGuiApplicationHelper::instance()->themeType(); @@ -246,6 +312,7 @@ void DFontInfoDialog::initConnections() DApplicationHelper::instance()->setPalette(m_fontFileName, paFrame); } }); +#endif } /************************************************************************* @@ -290,7 +357,11 @@ void DFontInfoDialog::autoHeight(int height) p.setBrush(Qt::black); p.drawRoundedRect(bmp.rect(), 12, 12); p.setRenderHint(QPainter::Antialiasing); +#if QT_VERSION_MAJOR > 5 + m_scrollArea->viewport()->setMask(QBitmap::fromPixmap(bmp)); +#else m_scrollArea->viewport()->setMask(bmp); +#endif m_scrollArea->viewport()->setFixedHeight(static_cast(height * 1.1 + 10)); m_scrollArea->setFixedHeight(static_cast(height * 1.1 + 10)); } else { @@ -302,7 +373,7 @@ void DFontInfoDialog::autoHeight(int height) p.setBrush(Qt::black); p.drawRoundedRect(bmp.rect(), 12, 12); p.setRenderHint(QPainter::Antialiasing); - m_scrollArea->viewport()->setMask(bmp); + m_scrollArea->viewport()->setMask(QBitmap::fromPixmap(bmp)); m_scrollArea->viewport()->setFixedHeight(375); m_scrollArea->setFixedHeight(375); } diff --git a/deepin-font-manager/views/dfontinfoscrollarea.cpp b/deepin-font-manager/views/dfontinfoscrollarea.cpp index f53fdc51..d2baff03 100644 --- a/deepin-font-manager/views/dfontinfoscrollarea.cpp +++ b/deepin-font-manager/views/dfontinfoscrollarea.cpp @@ -258,18 +258,30 @@ QString dfontinfoscrollarea::elideText(QString &titleName) const int curWidth = 0; for (auto str : titleName) { +#if QT_VERSION_MAJOR > 5 + if (str == "\t") { + curWidth += fontMetric.boundingRect("a").width(); + } else { + curWidth += fontMetric.boundingRect(str).width(); + } +#else if (str == "\t") { curWidth += fontMetric.width("a"); } else { curWidth += fontMetric.width(str); } +#endif m_curTitle += str; if (curWidth > TITLE_VISIBLE_WIDTH) { if (m_curTitle == titleName) { finalTitle = titleName; break; } else { +#if QT_VERSION_MAJOR > 5 + if (fontMetric.boundingRect("...").width() > IS_NEED_ELLIPSIS) { +#else if (fontMetric.width("...") > IS_NEED_ELLIPSIS) { +#endif finalTitle = m_curTitle; } else { finalTitle = m_curTitle.append("..."); @@ -299,13 +311,21 @@ QString dfontinfoscrollarea::elideText(const QString &text, const QFont &font, i { QFontMetrics fm(font); QString strText = text; +#if QT_VERSION_MAJOR > 5 + int n_TextSize = fm.boundingRect(strText).width(); +#else int n_TextSize = fm.width(strText); +#endif int count = 0; if (n_TextSize > nLabelSize) { int n_position = 0; long n_curSumWidth = 0; for (int i = 0; i < strText.size(); i++) { +#if QT_VERSION_MAJOR > 5 + n_curSumWidth += fm.boundingRect(strText.at(i)).width(); +#else n_curSumWidth += fm.width(strText.at(i)); +#endif if (n_curSumWidth > nLabelSize * (count + 1)) { n_position = i; strText.insert(n_position, "\n"); diff --git a/deepin-font-manager/views/dfontmgrmainwindow.cpp b/deepin-font-manager/views/dfontmgrmainwindow.cpp index a6cae8d2..8ca1a3d5 100644 --- a/deepin-font-manager/views/dfontmgrmainwindow.cpp +++ b/deepin-font-manager/views/dfontmgrmainwindow.cpp @@ -16,7 +16,9 @@ #include #include +#if QT_VERSION_MAJOR <= 5 #include +#endif #include #include #include @@ -47,6 +49,9 @@ #include #include #include +#if QT_VERSION_MAJOR > 5 +#include +#endif /************************************************************************* DFontMgrMainWindow @@ -449,12 +454,12 @@ void DFontMgrMainWindow::initShortcuts() connect(m_scDeleteFont, &QShortcut::activated, this, [this] { //Only can't delete user font //first disable delete - qDebug() << m_cacheFinish << m_installFinish << "______________" << endl; + qDebug() << m_cacheFinish << m_installFinish << "______________" << Qt::endl; if (m_fIsInstalling) return; m_fontPreviewListView->syncRecoveryTabStatus(); delCurrentFont(false); - }, Qt::UniqueConnection); + }); } //ShowMenu --> Alt+M//SP3--Alt+M菜单--快捷键 @@ -501,7 +506,7 @@ void DFontMgrMainWindow::initShortcuts() m_fontPreviewListView->onRightMenuShortCutActivated(); emit m_signalManager->menuHidden(); } - }, Qt::UniqueConnection); + }); } //Add Font --> Ctrl+O @@ -669,11 +674,15 @@ void DFontMgrMainWindow::initMainVeiws() handle->setFixedWidth(2); handle->setDisabled(true); +#if QT_VERSION_MAJOR > 5 + DPalette pa = handle->palette(); +#else DPalette pa = DApplicationHelper::instance()->palette(handle); +#endif QBrush splitBrush = pa.brush(DPalette::ItemBackground); - pa.setBrush(DPalette::Background, splitBrush); + pa.setBrush(DPalette::Window, splitBrush); handle->setPalette(pa); - handle->setBackgroundRole(QPalette::Background); + handle->setBackgroundRole(QPalette::Window); handle->setAutoFillBackground(true); } @@ -788,7 +797,9 @@ void DFontMgrMainWindow::initFontPreviewListView(QWidget *parent) Q_D(DFontMgrMainWindow); QVBoxLayout *listViewVBoxLayout = new QVBoxLayout(); +#if QT_VERSION_MAJOR <= 5 listViewVBoxLayout->setMargin(0); +#endif listViewVBoxLayout->setContentsMargins(0, 0, 0, 0); listViewVBoxLayout->setSpacing(0); @@ -1078,7 +1089,7 @@ bool DFontMgrMainWindow::installFont(const QStringList &files, bool isAddBtnHasT } //ut000442 bug 54129 - qDebug() << m_fIsInstalling << endl; + qDebug() << m_fIsInstalling << Qt::endl; if (m_fIsInstalling || m_fontLoadingSpinner->isVisible()) { qDebug() << "Already exist a installtion flow"; return false; @@ -1089,7 +1100,7 @@ bool DFontMgrMainWindow::installFont(const QStringList &files, bool isAddBtnHasT m_installFinish = false; //m_fontPreviewListView->clearSelection();//取消安装不清空选中状态 - qDebug() << "installFont new DFInstallNormalWindow " << installFiles.size() << endl; + qDebug() << "installFont new DFInstallNormalWindow " << installFiles.size() << Qt::endl; m_installTm = QDateTime::currentMSecsSinceEpoch(); m_dfNormalInstalldlg = new DFInstallNormalWindow(installFiles, this); connect(m_dfNormalInstalldlg, &DFInstallNormalWindow::destroyed, this, &DFontMgrMainWindow::onInstallWindowDestroyed); @@ -1316,7 +1327,7 @@ void DFontMgrMainWindow::onSearchTextChanged(const QString &currStr) //QString strSearchFontName = currStr; const QString strSearchFontName = currStr; - qDebug() << "SearchFontName:" << strSearchFontName << endl; + qDebug() << "SearchFontName:" << strSearchFontName << Qt::endl; m_searchTextStatusIsEmpty = strSearchFontName.isEmpty(); @@ -1327,7 +1338,7 @@ void DFontMgrMainWindow::onSearchTextChanged(const QString &currStr) filterModel->setFilterFontNamePattern(strSearchFontName); //filterModel->setEditStatus(m_searchTextStatusIsEmpty); - qDebug() << __FUNCTION__ << "filter Count:" << filterModel->rowCount() << endl; + qDebug() << __FUNCTION__ << "filter Count:" << filterModel->rowCount() << Qt::endl; //记录搜索输入框焦点状态 bool seachEditHasFocus = d->searchFontEdit->lineEdit()->hasFocus(); onFontListViewRowCountChanged(); @@ -1372,7 +1383,7 @@ void DFontMgrMainWindow::onFontSizeChanged(int fontSize) } DFontPreviewProxyModel *filterModel = m_fontPreviewListView->getFontPreviewProxyModel(); - qDebug() << __FUNCTION__ << "filter Count:" << filterModel->rowCount() << endl; + qDebug() << __FUNCTION__ << "filter Count:" << filterModel->rowCount() << Qt::endl; for (int rowIndex = 0; rowIndex < filterModel->rowCount(); rowIndex++) { QModelIndex modelIndex = filterModel->index(rowIndex, 0); @@ -1394,7 +1405,11 @@ void DFontMgrMainWindow::showFontFilePostion() { DFontPreviewItemData currItemData = m_fontPreviewListView->currModelData(); +#if QT_VERSION_MAJOR > 5 + if (-1 != currItemData.strFontId.toInt() && currItemData.fontInfo.filePath.length() > 0) { +#else if (-1 != currItemData.strFontId && currItemData.fontInfo.filePath.length() > 0) { +#endif DDesktopServices::showFileItem(currItemData.fontInfo.filePath); } } @@ -1419,7 +1434,7 @@ void DFontMgrMainWindow::onLeftSiderBarItemClicked(int index, bool needClearSele m_leftIndex = static_cast(index); //获取当前左侧列表选中的分组 filterGroup = qvariant_cast(index); - qDebug() << "filterGroup" << filterGroup << endl; + qDebug() << "filterGroup" << filterGroup << Qt::endl; //获取右侧预览列表proxymodel DFontPreviewProxyModel *filterModel = m_fontPreviewListView->getFontPreviewProxyModel(); filterModel->setFilterKeyColumn(0); @@ -1697,7 +1712,7 @@ void DFontMgrMainWindow::onconfirmDelDlgAccept() //disable file system watcher onShowSpinner(true, false, DFontSpinnerWidget::Delete); Q_EMIT DFontPreviewListDataThread::instance(m_fontPreviewListView)->requestRemoveFileWatchers(m_menuDelFontList); - qDebug() << m_menuDelFontList.count() << "!!!!!!!!!!!!!!!!11" << endl; + qDebug() << m_menuDelFontList.count() << "!!!!!!!!!!!!!!!!11" << Qt::endl; FontManagerCore::instance()->setType(FontManagerCore::UnInstall); FontManagerCore::instance()->setUnInstallFile(m_menuDelFontList); FontManagerCore::instance()->start(); @@ -2154,7 +2169,7 @@ void DFontMgrMainWindow::dropEvent(QDropEvent *event) installFont(installFileList, false); }); - qDebug() << installFileList << "drop in files :" << endl; + qDebug() << installFileList << "drop in files :" << Qt::endl; } else { event->ignore(); } @@ -2383,7 +2398,7 @@ void DFontMgrMainWindow::hideSpinner() emit m_signalManager->setSpliteWidgetScrollEnable(false); m_cacheFinish = false; m_installFinish = false; - qDebug() << __func__ << "install finish" << endl; + qDebug() << __func__ << "install finish" << Qt::endl; m_fIsInstalling = false; m_installOutFileList.clear(); @@ -2444,7 +2459,7 @@ void DFontMgrMainWindow::onPreviewTextChanged() DFontPreviewProxyModel *filterModel = m_fontPreviewListView->getFontPreviewProxyModel(); int total = filterModel->rowCount(); - qDebug() << __FUNCTION__ << "filter Count:" << filterModel->rowCount() << endl; + qDebug() << __FUNCTION__ << "filter Count:" << filterModel->rowCount() << Qt::endl; for (int rowIndex = 0; rowIndex < total; rowIndex++) { QModelIndex modelIndex = filterModel->index(rowIndex, 0); @@ -2505,11 +2520,15 @@ QStringList DFontMgrMainWindow::checkFilesSpace(const QStringList &files, bool m if (totalSelectSpace >= currentDiskSpace) { break; } else { +#if QT_VERSION_MAJOR > 5 + map.insert(fileInfo.size(), file); +#else map.insertMulti(fileInfo.size(), file); +#endif } } - qDebug() << currentDiskSpace << totalSelectSpace << endl; + qDebug() << currentDiskSpace << totalSelectSpace << Qt::endl; return map.values(); } @@ -2609,16 +2628,28 @@ void DFontMgrMainWindow::mainwindowFocusInCheck(QObject *obj, QEvent *event) void DFontMgrMainWindow::autoLabelWidth(QString text, DLabel *lab, QFontMetrics fm) { QString str = text; +#if QT_VERSION_MAJOR > 5 + if (fm.boundingRect(text).width() <= 65) { +#else if (fm.width(text) <= 65) { +#endif lab->setFixedWidth(65); - } else if (fm.width(text) > 45) { +#if QT_VERSION_MAJOR > 5 + } else if (fm.boundingRect(text).width() > 45) { +#else + } else if (fm.width(text) > 45) { +#endif lab->setFixedWidth(80); for (int i = 0; i < text.size(); i++) { str = str.left(str.length() - 1); if (str.length() == 1) { break; } +#if QT_VERSION_MAJOR > 5 + if (fm.boundingRect(str).width() < 80) { +#else if (fm.width(str) < 80) { +#endif break; } } @@ -2642,7 +2673,7 @@ void DFontMgrMainWindow::keyPressEvent(QKeyEvent *event) D_D(DFontMgrMainWindow); if (Qt::Key_Left == event->key() || Qt::Key_Down == event->key()) { - qDebug() << d->fontScaleSlider << endl; + qDebug() << d->fontScaleSlider << Qt::endl; if (d->fontScaleSlider->hasFocus()) { d->fontScaleSlider->setValue(d->fontScaleSlider->value() - 1); } else if (Qt::Key_Left == event->key() && (m_fontPreviewListView->hasFocus() || m_noInstallListView->hasFocus())) { diff --git a/deepin-font-manager/views/dfontmgrmainwindow.h b/deepin-font-manager/views/dfontmgrmainwindow.h index aaf9af10..3df0dac7 100644 --- a/deepin-font-manager/views/dfontmgrmainwindow.h +++ b/deepin-font-manager/views/dfontmgrmainwindow.h @@ -324,6 +324,7 @@ public slots: void slotSizeModeChanged(DGuiApplicationHelper::SizeMode sizeMode); #endif + protected: DFontPreviewListView *m_fontPreviewListView; DListView *m_noResultListView; diff --git a/deepin-font-manager/views/dfquickinstallwindow.cpp b/deepin-font-manager/views/dfquickinstallwindow.cpp index 72f1dca4..da16d470 100644 --- a/deepin-font-manager/views/dfquickinstallwindow.cpp +++ b/deepin-font-manager/views/dfquickinstallwindow.cpp @@ -16,7 +16,9 @@ #include #include #include +#if QT_VERSION_MAJOR <= 5 #include +#endif #include #include @@ -63,7 +65,7 @@ void DFQuickInstallWindow::initUI() setWindowIcon(QIcon::fromTheme(DEEPIN_FONT_MANAGER)); //Clear titlebar's background - titlebar()->setBackgroundRole(QPalette::Background); + titlebar()->setBackgroundRole(QPalette::Window); titlebar()->setAutoFillBackground(false); titlebar()->setFixedHeight(44); @@ -105,10 +107,17 @@ void DFQuickInstallWindow::initUI() m_stateLabel->setFixedHeight(m_stateLabel->fontMetrics().height()); m_stateLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); // m_stateLabel->setFont(actionFont); +#if QT_VERSION_MAJOR > 5 + DPalette pa = m_stateLabel->palette(); + pa.setBrush(DPalette::WindowText, pa.color(DPalette::TextTips)); + m_stateLabel->setPalette(pa); + m_oldPaStateLbl = m_stateLabel->palette(); +#else DPalette pa = DApplicationHelper::instance()->palette(m_stateLabel); pa.setBrush(DPalette::WindowText, pa.color(DPalette::TextTips)); m_stateLabel->setPalette(pa); m_oldPaStateLbl = DApplicationHelper::instance()->palette(m_stateLabel); +#endif m_actionBtn = new DPushButton(this); m_actionBtn->setFixedSize(QSize(120, 40)); @@ -193,7 +202,11 @@ void DFQuickInstallWindow::onFileSelected(const QStringList &fileList) DFontInfo fontInfo = m_fontInfoManager->getFontInfo(file); if (fontInfo.isError) { m_stateLabel->setText(DApplication::translate("QuickInstallWindow", "Broken file")); +#if QT_VERSION_MAJOR > 5 + DPalette pa = m_stateLabel->palette(); +#else DPalette pa = DApplicationHelper::instance()->palette(m_stateLabel); +#endif pa.setBrush(DPalette::WindowText, pa.color(DPalette::TextWarning)); m_stateLabel->setPalette(pa); @@ -202,7 +215,11 @@ void DFQuickInstallWindow::onFileSelected(const QStringList &fileList) m_fontType->addItem(DApplication::translate("QuickInstallWindow", "Unknown")); } else { if (fontInfo.isInstalled) { +#if QT_VERSION_MAJOR > 5 + DPalette pa = m_stateLabel->palette(); +#else DPalette pa = DApplicationHelper::instance()->palette(m_stateLabel); +#endif pa.setBrush(DPalette::WindowText, QColor("#417505")/* pa.color(DPalette::TextWarning)*/); m_stateLabel->setPalette(pa); m_stateLabel->setText(DApplication::translate("QuickInstallWindow", "Installed")); diff --git a/deepin-font-manager/views/dsplitlistwidget.cpp b/deepin-font-manager/views/dsplitlistwidget.cpp index 78cbd590..1556c4cc 100644 --- a/deepin-font-manager/views/dsplitlistwidget.cpp +++ b/deepin-font-manager/views/dsplitlistwidget.cpp @@ -9,7 +9,9 @@ #include #include +#if QT_VERSION_MAJOR <= 5 #include +#endif #include #include @@ -74,7 +76,11 @@ void DNoFocusDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti lineRect.setWidth(option.rect.width() - 20); lineRect.setHeight(2); //绘制分割线 +#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(&option), pa, DPalette::ItemBackground); painter->fillRect(lineRect, fillColor); @@ -184,7 +190,11 @@ void DNoFocusDelegate::paintBackground(QPainter *painter, const QStyleOptionView QColor fillColor = option.palette.color(cg, DPalette::Highlight); //如果为hover状态,颜色亮度需要加亮 if (option.state & QStyle::State_MouseOver) { +#if QT_VERSION_MAJOR > 5 + fillColor = fillColor.lighter(120); +#else fillColor = fillColor.light(120); +#endif } painter->setBrush(QBrush(fillColor)); painter->fillPath(pathFirst, painter->brush()); @@ -232,7 +242,11 @@ void DNoFocusDelegate::paintTabBackground(QPainter *painter, const QStyleOptionV //如果为hover状态,颜色亮度需要加亮 if (isHover) { +#if QT_VERSION_MAJOR > 5 + fillColor = fillColor.lighter(120); +#else fillColor = fillColor.light(120); +#endif } painter->setBrush(QBrush(fillColor)); painter->fillPath(pathFirst, painter->brush()); @@ -297,12 +311,20 @@ QString DNoFocusDelegate::adjustLength(QString &titleName, QFont &font) const for (auto str : titleName) { m_curTitle += str; +#if QT_VERSION_MAJOR > 5 + if (fontMetric.boundingRect(m_curTitle).width() > TITLE_VISIBLE_WIDTH) { +#else if (fontMetric.width(m_curTitle) > TITLE_VISIBLE_WIDTH) { +#endif if (m_curTitle == titleName) { finalTitle = m_curTitle; break; } else { +#if QT_VERSION_MAJOR > 5 + if (fontMetric.boundingRect("...").width() > IS_NEED_ELLIPSIS) { +#else if (fontMetric.width("...") > IS_NEED_ELLIPSIS) { +#endif finalTitle = m_curTitle; } else { finalTitle = m_curTitle.append("..."); @@ -509,7 +531,11 @@ void DSplitListWidget::wheelEvent(QWheelEvent *event) else now = selectedIndexes().last().row(); int next = now; +#if QT_VERSION_MAJOR > 5 + if (event->angleDelta().y() > 0) { +#else if (event->delta() > 0) { +#endif if (now > 0) { if (now == 6) { next = now - 2; diff --git a/deepin-font-preview-plugin/CMakeLists.txt b/deepin-font-preview-plugin/CMakeLists.txt index 7fd23c04..33b99d0a 100644 --- a/deepin-font-preview-plugin/CMakeLists.txt +++ b/deepin-font-preview-plugin/CMakeLists.txt @@ -53,11 +53,11 @@ endif() set(LIBS ${FREETYPE_LIBRARIES} PkgConfig::FontConfig - ${DtkWidget_LIBRARIES} - Qt5::Core - Qt5::Widgets - Qt5::Gui - Qt5::Sql + Dtk${DTK_VERSION}::Widget + Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::Widgets + Qt${QT_VERSION_MAJOR}::Gui + Qt${QT_VERSION_MAJOR}::Sql ) if (dfm-base_FOUND) list(APPEND LIBS dfm-base) diff --git a/libdeepin-font-manager/dcopyfilesmanager.h b/libdeepin-font-manager/dcopyfilesmanager.h index 34f99bb4..64e98a07 100644 --- a/libdeepin-font-manager/dcopyfilesmanager.h +++ b/libdeepin-font-manager/dcopyfilesmanager.h @@ -98,7 +98,11 @@ class DCopyFilesManager : public QObject int end = fonts.size() / 2; for (int i = 0; i < end; ++i) { +#if QT_VERSION_MAJOR > 5 + fonts.swapItemsAt(i, fonts.size() - 1 - i); +#else fonts.swap(i, fonts.size() - 1 - i); +#endif } } diff --git a/libdeepin-font-manager/dfontinfomanager.cpp b/libdeepin-font-manager/dfontinfomanager.cpp index 902a77dd..f694f1ed 100644 --- a/libdeepin-font-manager/dfontinfomanager.cpp +++ b/libdeepin-font-manager/dfontinfomanager.cpp @@ -14,6 +14,9 @@ #include #include #include +#if QT_VERSION_MAJOR > 5 +#include +#endif #include #include @@ -447,7 +450,11 @@ void DFontInfoManager::setFontInfo(DFontInfo& fontInfo) fontInfo.familyName = familyName; } else { +#if QT_VERSION_MAJOR > 5 + fontInfo.familyName = familyName.replace(QRegularExpression(QString("[ -]" + fontInfo.styleName + "$")), ""); +#else fontInfo.familyName = familyName.replace(QRegExp(QString("[ -]" + fontInfo.styleName + "$")), ""); +#endif } } return; @@ -584,7 +591,11 @@ DFontInfo DFontInfoManager:: getFontInfo(const QString &filePath, bool withPrevi //compitable with SP2 update1 and previous versions if (!fontInfo.fullname.isEmpty()) { // 例如Consolas-Regular(或Consolas Regular)获取到Consolas +#if QT_VERSION_MAJOR > 5 + fontInfo.familyName = fontInfo.fullname.replace(QRegularExpression(QString("[ -]" + fontInfo.styleName + "$")), ""); +#else fontInfo.familyName = fontInfo.fullname.replace(QRegExp(QString("[ -]" + fontInfo.styleName + "$")), ""); +#endif } if (fontInfo.familyName.trimmed().length() < 1) { diff --git a/libdeepin-font-manager/dfontpreview.cpp b/libdeepin-font-manager/dfontpreview.cpp index 0769abd1..2781ea17 100644 --- a/libdeepin-font-manager/dfontpreview.cpp +++ b/libdeepin-font-manager/dfontpreview.cpp @@ -127,7 +127,11 @@ void DFontPreview::paintEvent(QPaintEvent *e) /*根据获取的新point进行绘制 UT000539 fix bug 27030*/ if (checkFontContainText(m_face, lowerTextStock)) { +#if QT_VERSION_MAJOR > 5 + const int lowerWidth = metrics.boundingRect(lowerTextStock).width(); +#else const int lowerWidth = metrics.width(lowerTextStock); +#endif isNeedScroll(lowerWidth); const int lowerHeight = metrics.height(); QPoint baseLinePoint = adjustPreviewFontBaseLinePoint(QRect(x, y + padding, lowerWidth, lowerHeight), metrics); @@ -136,7 +140,11 @@ void DFontPreview::paintEvent(QPaintEvent *e) } if (checkFontContainText(m_face, upperTextStock)) { +#if QT_VERSION_MAJOR > 5 + const int upperWidth = metrics.boundingRect(upperTextStock).width(); +#else const int upperWidth = metrics.width(upperTextStock); +#endif isNeedScroll(upperWidth); const int upperHeight = metrics.height(); QPoint baseLinePoint = adjustPreviewFontBaseLinePoint(QRect(x, y + padding, upperWidth, upperHeight), metrics); @@ -145,7 +153,11 @@ void DFontPreview::paintEvent(QPaintEvent *e) } if (checkFontContainText(m_face, punctuationTextStock)) { +#if QT_VERSION_MAJOR > 5 + const int punWidth = metrics.boundingRect(punctuationTextStock).width(); +#else const int punWidth = metrics.width(punctuationTextStock); +#endif isNeedScroll(punWidth); int punHeight = metrics.height(); QPoint baseLinePoint = adjustPreviewFontBaseLinePoint(QRect(x, y + padding, punWidth, punHeight), metrics); @@ -159,7 +171,11 @@ void DFontPreview::paintEvent(QPaintEvent *e) painter.setFont(font); QFontMetrics met(font); +#if QT_VERSION_MAJOR > 5 + int sampleWidth = met.boundingRect(sampleString).width(); +#else int sampleWidth = met.width(sampleString); +#endif isNeedScroll(sampleWidth); int sampleHeight = met.height(); @@ -286,7 +302,11 @@ QString DFontPreview::getLanguageSampleString(const QString &language) if (m_contents.contains(language)) { key = language; } else { +#if QT_VERSION_MAJOR > 5 + const QStringList parseList = language.split("_", Qt::SkipEmptyParts); +#else const QStringList parseList = language.split("_", QString::SkipEmptyParts); +#endif if (parseList.length() > 0 && m_contents.contains(parseList.first())) { key = parseList.first(); diff --git a/libdeepin-font-manager/dfontwidget.cpp b/libdeepin-font-manager/dfontwidget.cpp index 05833ff4..45ececa9 100644 --- a/libdeepin-font-manager/dfontwidget.cpp +++ b/libdeepin-font-manager/dfontwidget.cpp @@ -45,7 +45,7 @@ DFontWidget::DFontWidget(QWidget *parent) m_area->setWidget(m_preview); QPalette pal = palette(); - pal.setColor(QPalette::Background, QColor(0x00, 0xff, 0x00, 0x00)); + pal.setColor(QPalette::Window, QColor(0x00, 0xff, 0x00, 0x00)); m_area->setPalette(pal); setPalette(pal); diff --git a/libdeepin-font-manager/fontmanagercore.cpp b/libdeepin-font-manager/fontmanagercore.cpp index 5cd65989..5a4b6d94 100644 --- a/libdeepin-font-manager/fontmanagercore.cpp +++ b/libdeepin-font-manager/fontmanagercore.cpp @@ -71,7 +71,7 @@ FontManagerCore::~FontManagerCore() *************************************************************************/ void FontManagerCore::setType(Type type) { - qDebug() << type << endl; + qDebug() << type << Qt::endl; m_type = type; } @@ -86,7 +86,7 @@ void FontManagerCore::setType(Type type) *************************************************************************/ void FontManagerCore::setInstallFileList(const QStringList &list) { - qDebug() << __FUNCTION__ << "start" << endl; + qDebug() << __FUNCTION__ << "start" << Qt::endl; if (!m_instFileList.isEmpty()) { m_instFileList.clear(); } @@ -120,7 +120,7 @@ void FontManagerCore::setUnInstallFile(const QStringList &filePath) *************************************************************************/ void FontManagerCore::run() { - qInfo() << __FUNCTION__ << "start" << m_type << endl; + qInfo() << __FUNCTION__ << "start" << m_type << Qt::endl; switch (m_type) { case Install: case HalfwayInstall: @@ -151,7 +151,7 @@ void FontManagerCore::run() void FontManagerCore::doCmd(QStringList &arguments) { qDebug() << "QProcess start"; - qDebug() << m_type << endl; + qDebug() << m_type << Qt::endl; switch (m_type) { case Install: case ReInstall: @@ -209,7 +209,7 @@ void FontManagerCore::handleUnInstall() *************************************************************************/ void FontManagerCore::doInstall(QStringList &fileList) { - qDebug() << __func__ << "s" << endl; + qDebug() << __func__ << "s" << Qt::endl; m_installOutList.clear(); m_installCanceled = false; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ca0b24d8..c013ea56 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -19,7 +19,7 @@ if(CMAKE_SAFETYTEST STREQUAL "CMAKE_SAFETYTEST_ARG_ON") endif() -FIND_PACKAGE(Qt5Test REQUIRED) +FIND_PACKAGE(Qt${QT_VERSION_MAJOR}Test REQUIRED) FIND_PACKAGE(GTest REQUIRED) INCLUDE_DIRECTORIES(${GTEST_INCLUDE_DIRS}) @@ -80,9 +80,23 @@ TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME_TEST} PUBLIC ${DtkWidget_INCLUDE_DIRS} ${DtkCore_INCLUDE_DIRS} ${DtkGui_INCLUDE_DIRS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME_TEST} Qt5::Core Qt5::Widgets Qt5::Gui Qt5::Sql Qt5::Xml Qt5::Svg Qt5::DBus Qt5::Network - Qt5::Test ${DtkCore_LIBRARIES} ${DtkWidget_LIBRARIES} ${FREETYPE_LIBRARIES} - ${FREETYPE_LIBRARIES} PkgConfig::FontConfig ${GTEST_LIBRARYS} ${GTEST_MAIN_LIBRARYS}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME_TEST} + 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 + Qt${QT_VERSION_MAJOR}::Test + Dtk${DTK_VERSION}::Core + Dtk${DTK_VERSION}::Widget + ${FREETYPE_LIBRARIES} + ${FREETYPE_LIBRARIES} + PkgConfig::FontConfig + ${GTEST_LIBRARYS} + ${GTEST_MAIN_LIBRARYS}) ADD_CUSTOM_TARGET( test # #执行mkdir -p 创建 coverageResult diff --git a/tests/src/deepin-font-manager-test/interfaces/ut_dfontbasedialog.cpp b/tests/src/deepin-font-manager-test/interfaces/ut_dfontbasedialog.cpp index 2077ca87..50a0aa95 100644 --- a/tests/src/deepin-font-manager-test/interfaces/ut_dfontbasedialog.cpp +++ b/tests/src/deepin-font-manager-test/interfaces/ut_dfontbasedialog.cpp @@ -38,11 +38,12 @@ class TestDFontBaseDialog : public testing::Test TEST_F(TestDFontBaseDialog, checkSetIconPixmap) { +#if QT_VERSION_MAJOR <= 5 QPixmap map(Utils::renderSVG("://ok.svg", QSize(32, 32))); fm->setIconPixmap(map); - EXPECT_TRUE(*fm->m_logoIcon->pixmap() == map); +#endif } TEST_F(TestDFontBaseDialog, checkGetCloseButton) diff --git a/tests/src/deepin-font-manager-test/interfaces/ut_dfontmenumanager.cpp b/tests/src/deepin-font-manager-test/interfaces/ut_dfontmenumanager.cpp index 2314c6bc..b3c9bccf 100644 --- a/tests/src/deepin-font-manager-test/interfaces/ut_dfontmenumanager.cpp +++ b/tests/src/deepin-font-manager-test/interfaces/ut_dfontmenumanager.cpp @@ -5,7 +5,9 @@ #include "interfaces/dfontmenumanager.h" +#if QT_VERSION_MAJOR <= 5 #include +#endif #include #include #include diff --git a/tests/src/deepin-font-manager-test/interfaces/ut_dfontpreviewitemdelegate.cpp b/tests/src/deepin-font-manager-test/interfaces/ut_dfontpreviewitemdelegate.cpp index e1b734b4..0b5adadd 100644 --- a/tests/src/deepin-font-manager-test/interfaces/ut_dfontpreviewitemdelegate.cpp +++ b/tests/src/deepin-font-manager-test/interfaces/ut_dfontpreviewitemdelegate.cpp @@ -11,7 +11,9 @@ #include "commonheaderfile.h" #include +#if QT_VERSION_MAJOR <= 5 #include +#endif #include #include #include diff --git a/tests/src/deepin-font-manager-test/interfaces/ut_dfontpreviewlistdatathread.cpp b/tests/src/deepin-font-manager-test/interfaces/ut_dfontpreviewlistdatathread.cpp index 4a82e66a..7be930f8 100644 --- a/tests/src/deepin-font-manager-test/interfaces/ut_dfontpreviewlistdatathread.cpp +++ b/tests/src/deepin-font-manager-test/interfaces/ut_dfontpreviewlistdatathread.cpp @@ -133,7 +133,7 @@ TEST_F(TestDFontPreviewListDataThread, checkRefreshFontListData) QSignalSpy spy2(dfdatathead->m_view, SIGNAL(multiItemsAdded(QList &, DFontSpinnerWidget::SpinnerStyles))); dfdatathead->refreshFontListData(true, QStringList()); - qDebug() << spy2.count() << endl; + qDebug() << spy2.count() << Qt::endl; EXPECT_TRUE(dfdatathead->m_allFontPathList.isEmpty()); EXPECT_TRUE(spy2.count() == 1); EXPECT_FALSE(dfdatathead->m_fontModelList.isEmpty()); diff --git a/tests/src/deepin-font-manager-test/interfaces/ut_dfontpreviewlistview.cpp b/tests/src/deepin-font-manager-test/interfaces/ut_dfontpreviewlistview.cpp index bac27c64..8ff14931 100644 --- a/tests/src/deepin-font-manager-test/interfaces/ut_dfontpreviewlistview.cpp +++ b/tests/src/deepin-font-manager-test/interfaces/ut_dfontpreviewlistview.cpp @@ -65,7 +65,7 @@ bool stub_False() bool stub_True() { - qDebug() << "!!!!!!!!!!!11111" << endl; + qDebug() << "!!!!!!!!!!!11111" << Qt::endl; return true; } @@ -458,7 +458,7 @@ TEST_F(TestDFontPreviewListView, checkDeleteCurFonts) list << "first"; listview->deleteCurFonts(list, true); - qDebug() << spy.count() << endl; + qDebug() << spy.count() << Qt::endl; EXPECT_TRUE(spy.count() == 2); list.clear(); list << ""; @@ -483,7 +483,7 @@ TEST_F(TestDFontPreviewListView, checkUpdateChangedDir) listview->updateChangedDir(); - qDebug() << spy.count() << "!!!!!!!!!!" << spy2.count() << endl; + qDebug() << spy.count() << "!!!!!!!!!!" << spy2.count() << Qt::endl; EXPECT_TRUE(spy.count() == 1); EXPECT_TRUE(spy2.count() == 1); } @@ -658,7 +658,7 @@ TEST_F(TestDFontPreviewListView, checkOnCollectBtnClicked) FontData itemData = qvariant_cast(listview->m_fontPreviewProxyModel->data(index)); //mark - qDebug() << itemData.fontState << endl; + qDebug() << itemData.fontState << Qt::endl; EXPECT_TRUE(itemData.fontState == 0x03); qDebug() << spy.count(); @@ -697,7 +697,7 @@ TEST_F(TestDFontPreviewListView, checkOnEnableBtnClickedEnable) FontData itemData = qvariant_cast(listview->m_fontPreviewProxyModel->data(index)); - qDebug() << itemData.fontState << endl; + qDebug() << itemData.fontState << Qt::endl; EXPECT_TRUE(itemData.fontState == 0x00); DFontMgrMainWindow *mw = new DFontMgrMainWindow; @@ -743,7 +743,10 @@ bool stub_contains(void *, const QPoint &, bool) TEST_F(TestDFontPreviewListView, checkHoverState) { Stub s; + +#if QT_VERSION_MAJOR <= 5 s.set(ADDR(QWidget, mapFromGlobal), stub_pos); +#endif typedef QModelIndex(*fptr)(const QPoint &); fptr DFontPreviewListView_indexAt = (fptr)(&DFontPreviewListView::indexAt); s.set(DFontPreviewListView_indexAt, stub_indexAt); @@ -1004,30 +1007,50 @@ TEST_F(TestDFontPreviewListView, checkMousePressEventMid) { listview->m_fontPreviewProxyModel->insertRows(0, 5); listview->selectAll(); +#if QT_VERSION_MAJOR > 5 + QMouseEvent *e = new QMouseEvent(QEvent::MouseButtonPress, QPoint(), Qt::MiddleButton, Qt::NoButton, Qt::NoModifier); +#else QMouseEvent *e = new QMouseEvent(QEvent::MouseButtonPress, QPoint(), Qt::MidButton, Qt::NoButton, Qt::NoModifier); +#endif listview->mousePressEvent(e); EXPECT_TRUE(listview->selectionModel()->selectedRows().count() == 1); SAFE_DELETE_ELE(e); listview->clearSelection(); +#if QT_VERSION_MAJOR > 5 + QMouseEvent *e2 = new QMouseEvent(QEvent::MouseButtonPress, QPoint(), Qt::MiddleButton, Qt::NoButton, Qt::ShiftModifier); +#else QMouseEvent *e2 = new QMouseEvent(QEvent::MouseButtonPress, QPoint(), Qt::MidButton, Qt::NoButton, Qt::ShiftModifier); +#endif listview->mousePressEvent(e2); EXPECT_FALSE(listview->m_IsTabFocus); SAFE_DELETE_ELE(e2); listview->selectAll(); +#if QT_VERSION_MAJOR > 5 + QMouseEvent *e3 = new QMouseEvent(QEvent::MouseButtonPress, QPoint(), Qt::MiddleButton, Qt::NoButton, Qt::ShiftModifier); +#else QMouseEvent *e3 = new QMouseEvent(QEvent::MouseButtonPress, QPoint(), Qt::MidButton, Qt::NoButton, Qt::ShiftModifier); +#endif listview->mousePressEvent(e3); SAFE_DELETE_ELE(e3); +#if QT_VERSION_MAJOR > 5 + QMouseEvent *e4 = new QMouseEvent(QEvent::MouseButtonPress, QPoint(), Qt::MiddleButton, Qt::NoButton, Qt::ControlModifier); +#else QMouseEvent *e4 = new QMouseEvent(QEvent::MouseButtonPress, QPoint(), Qt::MidButton, Qt::NoButton, Qt::ControlModifier); +#endif listview->mousePressEvent(e4); SAFE_DELETE_ELE(e4); Stub s; s.set(ADDR(QModelIndex, isValid), stub_False); listview->selectAll(); +#if QT_VERSION_MAJOR > 5 + QMouseEvent *e5 = new QMouseEvent(QEvent::MouseButtonPress, QPoint(), Qt::MiddleButton, Qt::NoButton, Qt::NoModifier); +#else QMouseEvent *e5 = new QMouseEvent(QEvent::MouseButtonPress, QPoint(), Qt::MidButton, Qt::NoButton, Qt::NoModifier); +#endif listview->mousePressEvent(e5); EXPECT_TRUE(listview->selectionModel()->selectedRows().count() == 0); @@ -1047,7 +1070,7 @@ TEST_F(TestDFontPreviewListView, checkLoadLeftFonts) emit listview->m_dataLoadThread->dataLoadFinish(str); - qDebug() << spy.count() << endl; + qDebug() << spy.count() << Qt::endl; EXPECT_TRUE(spy.count() == 1); } @@ -1179,7 +1202,11 @@ TEST_F(TestDFontPreviewListView, checkMouseReleaseEvent) s.set(ADDR(DFontPreviewListView, onMouseLeftBtnReleased), stub_Return); +#if QT_VERSION_MAJOR > 5 + QMouseEvent *e1 = new QMouseEvent(QEvent::MouseButtonRelease, QPoint(623, 23), Qt::MiddleButton, Qt::NoButton, Qt::NoModifier); +#else QMouseEvent *e1 = new QMouseEvent(QEvent::MouseButtonRelease, QPoint(623, 23), Qt::MidButton, Qt::NoButton, Qt::NoModifier); +#endif listview->mouseReleaseEvent(e1); QMouseEvent *e2 = new QMouseEvent(QEvent::MouseButtonRelease, QPoint(623, 23), Qt::LeftButton, Qt::NoButton, Qt::NoModifier); @@ -1272,7 +1299,7 @@ TEST_F(TestDFontPreviewListView, checkSelectedFontsNotElse) listview->selectedFonts(data, &deleteCnt, &disableSysCnt, &systemCnt, &curFontCnt, &disableCnt, &list, &indexlist, &disableIndexList, &allMinusSysFontList); - qDebug() << deleteCnt << disableSysCnt << systemCnt << curFontCnt << disableCnt << list.count() << disableIndexList.count() << allMinusSysFontList.count() << endl; + qDebug() << deleteCnt << disableSysCnt << systemCnt << curFontCnt << disableCnt << list.count() << disableIndexList.count() << allMinusSysFontList.count() << Qt::endl; EXPECT_TRUE(deleteCnt == 5); EXPECT_TRUE(disableCnt == 5); diff --git a/tests/src/deepin-font-manager-test/views/ut_dfdeletedialog.cpp b/tests/src/deepin-font-manager-test/views/ut_dfdeletedialog.cpp index 7da4fcf9..a7d0c2f2 100644 --- a/tests/src/deepin-font-manager-test/views/ut_dfdeletedialog.cpp +++ b/tests/src/deepin-font-manager-test/views/ut_dfdeletedialog.cpp @@ -21,7 +21,9 @@ #include #include +#if QT_VERSION_MAJOR <= 5 #include +#endif #include #include #include @@ -63,7 +65,11 @@ TEST_F(TestDFDeleteDialog, checksetTheme) Stub s1; s1.set(ADDR(DGuiApplicationHelper, themeType), stub_themeType); fm->setTheme(); +#if QT_VERSION_MAJOR > 5 + DPalette pamessageTitle = fm->messageTitle->palette(); +#else DPalette pamessageTitle = DApplicationHelper::instance()->palette(fm->messageTitle); +#endif QColor pamessageTitleColor = pamessageTitle.color(DPalette::Active, DPalette::BrightText); pamessageTitleColor.setAlphaF(1.0); EXPECT_TRUE(pamessageTitle.color(DPalette::Active, DPalette::WindowText) == pamessageTitleColor); diff --git a/tests/src/deepin-font-manager-test/views/ut_dfinstallerrordialog.cpp b/tests/src/deepin-font-manager-test/views/ut_dfinstallerrordialog.cpp index 31fe014a..48f8121a 100644 --- a/tests/src/deepin-font-manager-test/views/ut_dfinstallerrordialog.cpp +++ b/tests/src/deepin-font-manager-test/views/ut_dfinstallerrordialog.cpp @@ -24,7 +24,9 @@ #include #include #include +#if QT_VERSION_MAJOR <= 5 #include +#endif #include #include #include diff --git a/tests/src/deepin-font-manager-test/views/ut_dfinstallerrorlistview.cpp b/tests/src/deepin-font-manager-test/views/ut_dfinstallerrorlistview.cpp index 0b8c8be9..374304b0 100644 --- a/tests/src/deepin-font-manager-test/views/ut_dfinstallerrorlistview.cpp +++ b/tests/src/deepin-font-manager-test/views/ut_dfinstallerrorlistview.cpp @@ -21,7 +21,9 @@ #include #include #include +#if QT_VERSION_MAJOR <= 5 #include +#endif #include #include diff --git a/tests/src/deepin-font-manager-test/views/ut_dfinstallnormalwindow.cpp b/tests/src/deepin-font-manager-test/views/ut_dfinstallnormalwindow.cpp index f068bcd1..40616673 100644 --- a/tests/src/deepin-font-manager-test/views/ut_dfinstallnormalwindow.cpp +++ b/tests/src/deepin-font-manager-test/views/ut_dfinstallnormalwindow.cpp @@ -26,7 +26,9 @@ #include #include +#if QT_VERSION_MAJOR <= 5 #include +#endif #include #include diff --git a/tests/src/deepin-font-manager-test/views/ut_dfontInfo.cpp b/tests/src/deepin-font-manager-test/views/ut_dfontInfo.cpp index dbb489c4..792392f6 100644 --- a/tests/src/deepin-font-manager-test/views/ut_dfontInfo.cpp +++ b/tests/src/deepin-font-manager-test/views/ut_dfontInfo.cpp @@ -172,7 +172,7 @@ TEST_F(TestDFontInfoManager, checkGetFileNames) path = "/usr/share/fonts/truetype/"; list = dfm->getFileNames(path); //通过这行看编译环境中可能存在的字体文件,用来调整测试用例 - qDebug() << list << "+++++++++++++++++++++++++++++++++++++++++++" << endl; + qDebug() << list << "+++++++++++++++++++++++++++++++++++++++++++" << Qt::endl; EXPECT_TRUE(list.count() != 0); } diff --git a/tests/src/deepin-font-manager-test/views/ut_dfontinfodialog.cpp b/tests/src/deepin-font-manager-test/views/ut_dfontinfodialog.cpp index f1d23679..43e8f43d 100644 --- a/tests/src/deepin-font-manager-test/views/ut_dfontinfodialog.cpp +++ b/tests/src/deepin-font-manager-test/views/ut_dfontinfodialog.cpp @@ -25,7 +25,9 @@ #include #include +#if QT_VERSION_MAJOR <= 5 #include +#endif #include #include #include @@ -81,14 +83,14 @@ TEST_F(TestDFontInfoDialog, checkAutoFeed) { QString str; str.fill('a', 100); - qDebug() << str << endl; + qDebug() << str << Qt::endl; str = dFontInforDialog->AutoFeed(str); //进行处理之后字符串长度发生变化 EXPECT_TRUE(str.size() != 100); str.fill('a', 300); - qDebug() << str << endl; + qDebug() << str << Qt::endl; str = dFontInforDialog->AutoFeed(str); //进行处理之后字符串长度发生变化 EXPECT_TRUE(str.size() != 300); @@ -114,13 +116,23 @@ TEST_F(TestDFontInfoDialog, checkinitConnections001) Stub s; s.set(ADDR(DGuiApplicationHelper, themeType), stub_darktype); +#if QT_VERSION_MAJOR > 5 + DPalette paFrame = dFontInforDialog->m_scrollArea->viewport()->palette(); +#else DPalette paFrame = DApplicationHelper::instance()->palette(dFontInforDialog->m_scrollArea->viewport()); +#endif QColor colorFrame = paFrame.textLively().color(); colorFrame.setAlphaF(0.05); paFrame.setColor(DPalette::Base, colorFrame); +#if QT_VERSION_MAJOR > 5 + emit DGuiApplicationHelper::instance()->themeTypeChanged(DGuiApplicationHelper::DarkType); + + EXPECT_TRUE(dFontInforDialog->m_fontFileName->palette() == paFrame); +#else emit DApplicationHelper::instance()->themeTypeChanged(DApplicationHelper::DarkType); EXPECT_TRUE(DApplicationHelper::instance()->palette(dFontInforDialog->m_fontFileName) == paFrame); +#endif } TEST_F(TestDFontInfoDialog, checkinitConnections002) @@ -128,6 +140,15 @@ TEST_F(TestDFontInfoDialog, checkinitConnections002) Stub s; s.set(ADDR(DGuiApplicationHelper, themeType), stub_lighttype); +#if QT_VERSION_MAJOR > 5 + DPalette paFrame = dFontInforDialog->m_scrollArea->viewport()->palette(); + QColor colorFrame(255, 255, 255); + colorFrame.setAlphaF(0.70); + paFrame.setColor(DPalette::Base, colorFrame); + emit DGuiApplicationHelper::instance()->themeTypeChanged(DGuiApplicationHelper::LightType); + + EXPECT_TRUE(dFontInforDialog->m_fontFileName->palette() == paFrame); +#else DPalette paFrame = DApplicationHelper::instance()->palette(dFontInforDialog->m_scrollArea->viewport()); QColor colorFrame(255, 255, 255); colorFrame.setAlphaF(0.70); @@ -135,6 +156,7 @@ TEST_F(TestDFontInfoDialog, checkinitConnections002) emit DApplicationHelper::instance()->themeTypeChanged(DApplicationHelper::LightType); EXPECT_TRUE(DApplicationHelper::instance()->palette(dFontInforDialog->m_fontFileName) == paFrame); +#endif } diff --git a/tests/src/deepin-font-manager-test/views/ut_dfontmgrmainwindow.cpp b/tests/src/deepin-font-manager-test/views/ut_dfontmgrmainwindow.cpp index 02f7d94e..3821f12b 100644 --- a/tests/src/deepin-font-manager-test/views/ut_dfontmgrmainwindow.cpp +++ b/tests/src/deepin-font-manager-test/views/ut_dfontmgrmainwindow.cpp @@ -51,7 +51,9 @@ #include "dobject.h" #include +#if QT_VERSION_MAJOR <= 5 #include +#endif #include #include #include @@ -177,7 +179,11 @@ QStringList stub_checkFilesSpace() DFontPreviewItemData stub_currModelData() { DFontPreviewItemData data; +#if QT_VERSION_MAJOR > 5 + data.strFontId = QString::number(1); +#else data.strFontId = 1; +#endif data.fontInfo.filePath = "first"; return data; diff --git a/tests/src/deepin-font-manager-test/views/ut_dfquickinstallwindow.cpp b/tests/src/deepin-font-manager-test/views/ut_dfquickinstallwindow.cpp index 0c878233..8e549ff1 100644 --- a/tests/src/deepin-font-manager-test/views/ut_dfquickinstallwindow.cpp +++ b/tests/src/deepin-font-manager-test/views/ut_dfquickinstallwindow.cpp @@ -23,7 +23,9 @@ #include #include #include +#if QT_VERSION_MAJOR <= 5 #include +#endif #include #include diff --git a/tests/src/deepin-font-manager-test/views/ut_dsplitlistwidget.cpp b/tests/src/deepin-font-manager-test/views/ut_dsplitlistwidget.cpp index 0ca0a9bf..b30f6150 100644 --- a/tests/src/deepin-font-manager-test/views/ut_dsplitlistwidget.cpp +++ b/tests/src/deepin-font-manager-test/views/ut_dsplitlistwidget.cpp @@ -19,7 +19,9 @@ #include #include +#if QT_VERSION_MAJOR <= 5 #include +#endif #include #include @@ -145,6 +147,7 @@ TEST_F(TestDSplitListWidget, checkKyPressEvent) } +#if QT_VERSION_MAJOR <= 5 TEST_F(TestDSplitListWidget, checkWheelEventDeltaP) { QWheelEvent *e = new QWheelEvent(QPoint(45, 200), QPoint(600, 500), 10, Qt::NoButton, Qt::NoModifier); @@ -194,7 +197,7 @@ TEST_F(TestDSplitListWidget, checkWheelEventDeltaN) SAFE_DELETE_ELE(e) } - +#endif TEST_F(TestDSplitListWidget, checkMouseMoveEvent) { diff --git a/tests/src/ut_dfontmanager.cpp b/tests/src/ut_dfontmanager.cpp index 93ed4d2f..2e29c48d 100644 --- a/tests/src/ut_dfontmanager.cpp +++ b/tests/src/ut_dfontmanager.cpp @@ -278,6 +278,7 @@ TEST_F(TestDfontmanager, checkCancelInstall) EXPECT_TRUE(fm->m_installCanceled); } +#if QT_VERSION_MAJOR <= 5 TEST_F(TestDfontmanager, checkDoCache) { Stub s; @@ -294,8 +295,9 @@ TEST_F(TestDfontmanager, checkDoCache) fm->m_installCanceled = false; EXPECT_TRUE(fm->needCache()); delete fm; -// fm->deleteLater(); + // fm->deleteLater(); } +#endif diff --git a/tests/src/ut_dfontpreview.cpp b/tests/src/ut_dfontpreview.cpp index 8ec90a74..4b0f6286 100644 --- a/tests/src/ut_dfontpreview.cpp +++ b/tests/src/ut_dfontpreview.cpp @@ -14,7 +14,9 @@ #include #include +#if QT_VERSION_MAJOR <= 5 #include +#endif #include "dfmdbmanager.h" #include diff --git a/tests/src/ut_dfontpreviewLib.cpp b/tests/src/ut_dfontpreviewLib.cpp index 0d3316a5..accfded5 100644 --- a/tests/src/ut_dfontpreviewLib.cpp +++ b/tests/src/ut_dfontpreviewLib.cpp @@ -8,7 +8,9 @@ #include #include +#if QT_VERSION_MAJOR <= 5 #include +#endif #include #include #include