Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: QT6 adaptation #19

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ set(CMAKE_AUTOMOC ON) #打开全局moc
set(CMAKE_AUTORCC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(QT_VERSION_MAJOR 6)
if (${QT_VERSION_MAJOR} GREATER_EQUAL 6)
set(DTK_VERSION 6)
endif()


#对DApplication 进行加速
set(CMAKE_EXE_LINKER_FLAGS "-pie")
Expand Down
2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Source: com.deepin.lianliankan
Section: utils
Priority: optional
Maintainer: Packages <[email protected]>
Build-Depends: debhelper (>= 11),cmake, pkg-config, qtbase5-dev, qtchooser (>= 55-gc9562a1-1~),qt5-qmake, libdtkwidget-dev, qttools5-dev-tools, libqt5svg5-dev, qttools5-dev,libgtest-dev, libgmock-dev, qtmultimedia5-dev
Build-Depends: debhelper (>= 11),cmake, pkg-config, qt6-base-dev, qtchooser (>= 55-gc9562a1-1~),qmake6, libdtk6widget-dev, qt6-tools-dev-tools, qt6-svg-dev, qt6-tools-dev,libgtest-dev, libgmock-dev, qt6-multimedia-dev
Standards-Version: 4.1.3

Package: com.deepin.lianliankan
Expand Down
27 changes: 13 additions & 14 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ endif()
# Find the library
include(FindPkgConfig)
find_package(PkgConfig REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5LinguistTools REQUIRED)
find_package(DtkWidget REQUIRED)
find_package(Qt5 COMPONENTS Multimedia REQUIRED)
pkg_search_module(DtkWidget REQUIRED dtkwidget)
find_package(Qt${QT_VERSION_MAJOR}Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Multimedia REQUIRED)
find_package(Dtk${DTK_VERSION}Core REQUIRED)
find_package(Dtk${DTK_VERSION}Widget REQUIRED)
find_package(Dtk${DTK_VERSION}Gui REQUIRED)

#lupdate start
set(TS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../translations")
Expand All @@ -45,25 +45,24 @@ file(GLOB INSTALL_QM_FILES ../translations/*.qm)

#源文件、头文件和资源文件
include_directories(${PROJECT_SOURCE_DIR})
include_directories(${DtkWidget_INCLUDE_DIRS})
include_directories(${DtkCore_INCLUDE_DIRS})
include_directories(${DtkGui_INCLUDE_DIRS})
file(GLOB_RECURSE c_files RELATIVE ${PROJECT_SOURCE_DIR} source/*.cpp source/*.c ../main.cpp)
file(GLOB_RECURSE h_files RELATIVE ${PROJECT_SOURCE_DIR} source/*.h *.h)
file(GLOB_RECURSE res_files RELATIVE ${PROJECT_SOURCE_DIR} *.qrc)

#添加资源文件
QT5_ADD_RESOURCES(QRC_FILES ${res_files})
file(GLOB_RECURSE QRC_SOURCE_FILES ./*.qrc)
qt_add_resources(QRC_FILES ${QRC_SOURCE_FILES})

#生成可执行程序
add_executable(${EXE_NAME} ${c_files} ${h_files} ${QRC_FILES})


target_include_directories(${EXE_NAME} PUBLIC ${DtkWidget_INCLUDE_DIRS} ${OBJECT_BINARY_DIR})
target_include_directories(${EXE_NAME} PUBLIC ${OBJECT_BINARY_DIR})
target_link_libraries(${EXE_NAME}
${DtkWidget_LIBRARIES}
${Qt5Widgets_LIBRARIES}
Qt5::Multimedia
Dtk${DTK_VERSION}::Core
Dtk${DTK_VERSION}::Gui
Dtk${DTK_VERSION}::Widget
Qt${QT_VERSION_MAJOR}::Widgets
Qt${QT_VERSION_MAJOR}::Multimedia
)

# Install files
Expand Down
4 changes: 4 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
#include "source/mainwindow.h"
#include "source/lianliankanapplication.h"

#include <DApplication>

Check warning on line 10 in src/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 11 in src/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 12 in src/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DWidgetUtil> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#if QT_VERSION_MAJOR <= 5
#include <DApplicationSettings>

Check warning on line 14 in src/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 16 in src/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 17 in src/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 18 in src/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

#include <QPropertyAnimation>
Expand Down Expand Up @@ -52,7 +54,9 @@

DLogManager::registerConsoleAppender();
DLogManager::registerFileAppender();
#if QT_VERSION_MAJOR <= 5
DApplicationSettings saveTheme;
#endif

// QTime t;
// t.start();
Expand Down
1 change: 0 additions & 1 deletion src/source/closewindowdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@

#include "closewindowdialog.h"

#include <DApplicationHelper>
#include <DFontSizeManager>

Check warning on line 8 in src/source/closewindowdialog.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

#include <QApplication>

Check warning on line 10 in src/source/closewindowdialog.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QApplication> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QMap>
#include <QDebug>
#include <QMessageBox>
Expand Down
12 changes: 12 additions & 0 deletions src/source/gamebutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ void GameButton::paintEvent(QPaintEvent *e)

QFontMetricsF mertic(m_font);
qreal fontHeight = mertic.height();
#if QT_VERSION_MAJOR > 5
qreal fontWidth = mertic.boundingRect(m_text).width();
#else
qreal fontWidth = mertic.width(m_text);
#endif
qreal textX = (rect().width() - fontWidth) / 2;
qreal textY = (rect().height() - fontHeight - fontHeight / 2) / 2;
p.setFont(shadowFont);
Expand Down Expand Up @@ -199,7 +203,11 @@ void GameButton::mouseReleaseEvent(QMouseEvent *e)
return QPushButton::mouseReleaseEvent(e);
}

#if QT_VERSION_MAJOR > 5
void GameButton::enterEvent(QEnterEvent *event)
#else
void GameButton::enterEvent(QEvent *event)
#endif
{
if (!this->isEnabled()) {
return;
Expand Down Expand Up @@ -269,7 +277,11 @@ void GameButton::drawBackdrop(QPainter &p)
QPen pen;
pen.setWidth(0);
p.setPen(pen);
#if QT_VERSION_MAJOR > 5
p.drawRoundedRect(this->rect().x() + 3, this->rect().y() + 5, 42, 42, 40, 40);
#else
p.drawRoundRect(this->rect().x() + 3, this->rect().y() + 5, 42, 42, 40, 40);
#endif
}

void GameButton::setBtnMask(QPixmap &pic)
Expand Down
4 changes: 4 additions & 0 deletions src/source/gamebutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ class GameButton : public QPushButton
void paintEvent(QPaintEvent *event) override;
void mousePressEvent(QMouseEvent *e) override;
void mouseReleaseEvent(QMouseEvent *e) override;
#if QT_VERSION_MAJOR > 5
void enterEvent(QEnterEvent *event) override;
#else
void enterEvent(QEvent *event) override;
#endif
void leaveEvent(QEvent *event) override;

private:
Expand Down
4 changes: 4 additions & 0 deletions src/source/gamelinescene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ void GameLineScene::paintEvent(QPaintEvent *event)
} else {
QPainter painter(this);
//反走样
#if QT_VERSION_MAJOR > 5
painter.setRenderHint(QPainter::Antialiasing, true);
#else
painter.setRenderHint(QPainter::HighQualityAntialiasing, true);
#endif
//获取爆炸图片
const QPixmap &pic = GameControl::m_picMap.value(qMakePair(ExplodePic, Default));
QPen pen;
Expand Down
4 changes: 4 additions & 0 deletions src/source/gameoverblureffectwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ void GameoverBlurEffectWidget::initUI()

void GameoverBlurEffectWidget::initConnect()
{
#if QT_VERSION_MAJOR > 5
connect(m_OverBtnGroup, &QButtonGroup::idClicked, this, &GameoverBlurEffectWidget::onButtonPressed);
#else
connect(m_OverBtnGroup, QOverload<int>::of(&QButtonGroup::buttonClicked), this, &GameoverBlurEffectWidget::onButtonPressed);
#endif
}

void GameoverBlurEffectWidget::updateLabel(QString text)
Expand Down
25 changes: 22 additions & 3 deletions src/source/gamepage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@

#include <DGuiApplicationHelper>

#include <QHBoxLayout>

Check warning on line 13 in src/source/gamepage.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QHBoxLayout> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QGraphicsDropShadowEffect>
#include <QtMultimedia/QSound>
#include <QDebug>
#include <QTime>
#include <QGraphicsBlurEffect>
Expand All @@ -35,10 +34,16 @@
m_hintPicOffTimer = new QTimer(this);
m_hintPicOffTimer->setInterval(200);
m_flashCount = BtnFlashCount;
#if QT_VERSION_MAJOR > 5
m_player = new QMediaPlayer(this);
m_audioOutput = new QAudioOutput(this);
m_player->setAudioOutput(m_audioOutput);
#else
QSound *serachSuccess = new QSound(":/assets/Sound/ConnectSuccess.wav", this);
QSound *serachFailed = new QSound(":/assets/Sound/ConnectFailed.wav", this);
m_soundMap.insert("success", serachSuccess);
m_soundMap.insert("failed", serachFailed);
#endif
initUI();
initConnect();
}
Expand Down Expand Up @@ -237,7 +242,11 @@

void GamePage::initConnect()
{
#if QT_VERSION_MAJOR > 5
QObject::connect(m_controlGrp, &QButtonGroup::idClicked, this, &GamePage::onControlBtnControl);
#else
QObject::connect(m_controlGrp, QOverload<int>::of(&QButtonGroup::buttonClicked), this, &GamePage::onControlBtnControl);
#endif
QObject::connect(m_animalGrp, QOverload<QAbstractButton *>::of(&QButtonGroup::buttonPressed), this, &GamePage::onAnimalBtnControl);
QObject::connect(m_progress, &GameProgressBar::valueChanged, this, &GamePage::onProgressChanged);
QObject::connect(m_hintPicOnTimer, &QTimer::timeout, this, &GamePage::onhintPicOnTimerOut);
Expand Down Expand Up @@ -330,8 +339,13 @@
updateConnection(preBtn, currentBtn);

//连线成功音效
if (m_soundSwitch)
if (m_soundSwitch) {
#if QT_VERSION_MAJOR > 5
m_player->setSource(QUrl("qrc:/assets/Sound/ConnectSuccess.wav"));
#else
m_soundMap.value("success")->play();
#endif
}
//更新地图
GameControl::m_map[currentBtn->location().x()][currentBtn->location().y()] = GameBtnFlag::ButtonBlank;
GameControl::m_map[preBtn->location().x()][preBtn->location().y()] = GameBtnFlag::ButtonBlank;
Expand Down Expand Up @@ -366,8 +380,13 @@
void GamePage::failedAction(GameButton *preBtn, GameButton *currentBtn)
{
//连线失败音效
if (m_soundSwitch)
if (m_soundSwitch) {
#if QT_VERSION_MAJOR > 5
m_player->setSource(QUrl("qrc:/assets/Sound/ConnectFailed.wav"));
#else
m_soundMap.value("failed")->play();
#endif
}
//添加当前选中按钮,pop前一个按钮
m_locationVec.append(currentBtn);
m_locationVec.pop_front();
Expand Down
10 changes: 10 additions & 0 deletions src/source/gamepage.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
#include <QButtonGroup>
#include <QTimer>
#include <QVector>
#if QT_VERSION_MAJOR > 5
#include <QMediaPlayer>
#include <QAudioOutput>
#else
#include <QtMultimedia/QSound>
#endif

class GameLineScene;
DWIDGET_USE_NAMESPACE
Expand Down Expand Up @@ -200,7 +205,12 @@ public slots:
QGridLayout *m_gameBtngridLayout; //游戏按钮布局
QButtonGroup *m_animalGrp; //游戏动物按钮组
QButtonGroup *m_controlGrp; //控制按钮组
#if QT_VERSION_MAJOR > 5
QMediaPlayer *m_player;
QAudioOutput *m_audioOutput;
#else
QMap<QString, QSound *> m_soundMap; //游戏音效
#endif
QTimer *m_timer; //定时器
QTimer *m_hintPicOnTimer;//提示闪烁定时器(展示)
QTimer *m_hintPicOffTimer;//提示闪烁定时器(隐藏)
Expand Down
4 changes: 4 additions & 0 deletions src/source/gameprogressbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ void GameProgressBar::paintEvent(QPaintEvent *e)
BackFont.setWeight(QFont::DemiBold);
BackFont.setPointSize(15);
QFontMetricsF mertic(textFont);
#if QT_VERSION_MAJOR > 5
qreal merticWidth = mertic.boundingRect(text).width();
#else
qreal merticWidth = mertic.width(text);
#endif
qreal merticHeight = mertic.height();

//绘制字体阴影效果
Expand Down
4 changes: 4 additions & 0 deletions src/source/mainpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ void MainPage::initUI()

void MainPage::initConnect()
{
#if QT_VERSION_MAJOR > 5
connect(m_btnGrp, &QButtonGroup::idClicked, this, &MainPage::buttonPress);
#else
connect(m_btnGrp, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked), this, &MainPage::buttonPress);
#endif
connect(m_soundBtn, &GameButton::pressed, this, [&] {
this->setSoundState(!m_soundState);
});
Expand Down
13 changes: 9 additions & 4 deletions src/source/shadowlabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ ShadowLabel::ShadowLabel(QWidget *parent) : DLabel (parent)
{
m_font.setFamily("Noto Sans CJK SC");
m_font.setPixelSize(21);
#if QT_VERSION_MAJOR > 5
m_font.setWeight(QFont::Medium);
#else
m_font.setWeight(580);
#endif
setFont(m_font);
}

Expand All @@ -23,10 +27,11 @@ void ShadowLabel::paintEvent(QPaintEvent *event)
painterText.setRenderHint(QPainter::Antialiasing, true);

QFontMetrics fm(m_font);
int textWidth = fm.boundingRect(text).width();
//设置渐变区域,参数为区域右上角和右下角。表示垂直线性渐变
QLinearGradient lg(rect().width()/2 - fm.width(text)/2,
QLinearGradient lg(rect().width()/2 - textWidth/2,
rect().y(),
rect().width()/2 - fm.width(text)/2,
rect().width()/2 - textWidth/2,
rect().y() + fm.height());
lg.setSpread(QGradient::RepeatSpread);
if (m_result) {
Expand All @@ -45,8 +50,8 @@ void ShadowLabel::paintEvent(QPaintEvent *event)
QPen textcolor;
textcolor.setBrush(lg);
painterText.setPen(textcolor);
painterText.drawText(QRectF(rect().width()/2 - fm.width(text)/2,
painterText.drawText(QRectF(rect().width()/2 - textWidth/2,
rect().y(),
fm.width(text),
textWidth,
fm.height()), text);
}
Loading
Loading