Skip to content

Commit

Permalink
cmakelists: migrate to qt6
Browse files Browse the repository at this point in the history
Migrates Memento to Qt6. This is important since Plasma 6 is out of beta
in February. There will likely not be a new release until then. Reworks
SubtitleListWidget to use std::shared_ptr since what was safe in Qt5
using QList is no longer safe in Qt6 due to the merging of the QList and
QVector implementations.
  • Loading branch information
ripose-jp committed Mar 10, 2024
1 parent e4684e4 commit 2070c4b
Show file tree
Hide file tree
Showing 40 changed files with 204 additions and 217 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@ on:

jobs:
linux:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4

- name: Install Dependencies
run: |
sudo add-apt-repository ppa:beineri/opt-qt-5.15.2-focal
sudo apt-get update
sudo apt-get install qt515base qt515x11extras qt515svg libmpv-dev libsqlite3-dev libmecab-dev mecab-ipadic libjson-c-dev libzip-dev mesa-common-dev python3-dev
/opt/qt515/bin/qt515-env.sh
sudo apt-get install qt6-base-dev libqt6svg6-dev libmpv-dev libsqlite3-dev libmecab-dev mecab-ipadic libjson-c-dev libzip-dev mesa-common-dev python3-dev
- name: CMake Build
run: |
Expand All @@ -48,7 +46,7 @@ jobs:
mingw-w64-x86_64-gcc
mingw-w64-x86_64-cmake
mingw-w64-x86_64-sqlite3
mingw-w64-x86_64-qt5
mingw-w64-x86_64-qt6
mingw-w64-x86_64-mpv
mingw-w64-x86_64-mecab
mingw-w64-x86_64-json-c
Expand All @@ -73,7 +71,7 @@ jobs:
- name: Install Dependencies
run: |
brew update || true
brew install cmake sqlite3 qt5 mpv mecab mecab-ipadic json-c libzip python || true
brew install cmake sqlite3 qt6 mpv mecab mecab-ipadic json-c libzip python || true
- name: CMake Build
run: |
Expand Down
37 changes: 25 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,18 @@ if(APPLE AND NOT MAC_CROSSCOMPILE_X86)
MEMENTO_INCLUDE_DIRS

# arm64 locations
"/opt/homebrew/opt/qt5/include"
"/opt/homebrew/opt/qt6/include"
"/opt/homebrew/include"

# x86_64 locations
"/usr/local/opt/qt5/include/"
"/usr/local/opt/qt6/include/"
"/usr/local/include"
)
elseif(APPLE AND MAC_CROSSCOMPILE_X86)
# This is a crosscomile target, x86_64 users shouldn't need to use this
set(
MEMENTO_INCLUDE_DIRS
"/usr/local/opt/qt5/include/"
"/usr/local/opt/qt6/include/"
"/usr/local/include"
)
endif()
Expand All @@ -136,18 +136,31 @@ find_package(JsonC REQUIRED)
find_package(libzip REQUIRED)
find_package(MeCab REQUIRED)
find_package(mpv REQUIRED)
if(UNIX AND NOT APPLE)
find_package(SQLite3 REQUIRED)
if (UNIX AND NOT APPLE)
find_package(
Qt6 REQUIRED
COMPONENTS
Concurrent
DBus
Gui
Network
OpenGLWidgets
Svg
Widgets
)
else()
find_package(
Qt5
COMPONENTS Widgets Network DBus X11Extras Svg Concurrent REQUIRED
Qt6 REQUIRED
COMPONENTS
Concurrent
Gui
Network
OpenGLWidgets
Svg
Widgets
)
list(APPEND MEMENTO_INCLUDE_DIRS ${Qt5Gui_PRIVATE_INCLUDE_DIRS})
elseif(APPLE)
find_package(Qt5 COMPONENTS Widgets Network Svg Concurrent REQUIRED)
elseif(WIN32)
find_package(Qt5 COMPONENTS Widgets Network Svg Concurrent REQUIRED)
endif()
find_package(SQLite3 REQUIRED)

# Include CMake Modules
include(FetchContent)
Expand Down
15 changes: 5 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,9 @@ To do so, open Flatseal, select Anki, and add the `/tmp` directory under **Other

## Dependencies

* Qt5 (>= 5.15)
* QtCore
* QtGui
* QtWidgets
* QtNetwork
* QtSvg
* QtDBus (Linux)
* X11Extras (Linux)
* Qt
* Base
* SVG
* mpv
* sqlite3
* MeCab
Expand Down Expand Up @@ -158,7 +153,7 @@ sudo make install
```
1. Install the necessary tools and dependencies:
```
pacman -S git make mingw-w64-x86_64-gcc mingw-w64-x86_64-ninja mingw-w64-x86_64-cmake mingw-w64-x86_64-python mingw-w64-x86_64-sqlite3 mingw-w64-x86_64-qt5 mingw-w64-x86_64-mpv mingw-w64-x86_64-mecab mingw-w64-x86_64-json-c mingw-w64-x86_64-libzip
pacman -S git make mingw-w64-x86_64-gcc mingw-w64-x86_64-ninja mingw-w64-x86_64-cmake mingw-w64-x86_64-python mingw-w64-x86_64-sqlite3 mingw-w64-x86_64-qt6 mingw-w64-x86_64-mpv mingw-w64-x86_64-mecab mingw-w64-x86_64-json-c mingw-w64-x86_64-libzip
```
1. Clone the repository:
```
Expand All @@ -184,7 +179,7 @@ sudo make install
```
1. Install the necessary tools and dependencies:
```
brew install git cmake sqlite3 qt5 mpv mecab mecab-ipadic json-c libzip
brew install git cmake sqlite3 qt6 mpv mecab mecab-ipadic json-c libzip
```
1. Clone the repository:
```
Expand Down
10 changes: 5 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ if(APPBUNDLE)
PRIVATE globalmediator
PRIVATE iconfactory
PRIVATE mainwindow
PRIVATE Qt5::Svg
PRIVATE Qt6::Svg
)

# Add in the dylibs
Expand Down Expand Up @@ -92,7 +92,7 @@ if(APPBUNDLE)

# Run macdeployqt to pick up any plugins dylibbundler missed
if (MAC_CROSSCOMPILE_X86)
set(MACDEPLOYQT_BIN "/usr/local/opt/qt5/bin/macdeployqt")
set(MACDEPLOYQT_BIN "/usr/local/opt/qt6/bin/macdeployqt")
else()
set(MACDEPLOYQT_BIN macdeployqt)
endif()
Expand Down Expand Up @@ -141,7 +141,7 @@ elseif(WIN32)
PRIVATE globalmediator
PRIVATE iconfactory
PRIVATE mainwindow
PRIVATE Qt5::Svg
PRIVATE Qt6::Svg
)

# This is a target that will create memento_debug.exe so that issues can be
Expand All @@ -162,7 +162,7 @@ elseif(WIN32)
PRIVATE globalmediator
PRIVATE iconfactory
PRIVATE mainwindow
PRIVATE Qt5::Svg
PRIVATE Qt6::Svg
)
elseif(UNIX)
add_executable(
Expand All @@ -180,7 +180,7 @@ elseif(UNIX)
PRIVATE globalmediator
PRIVATE iconfactory
PRIVATE mainwindow
PRIVATE Qt5::Svg
PRIVATE Qt6::Svg
)
else()
message(FATAL_ERROR "Unsupported operating system!")
Expand Down
6 changes: 3 additions & 3 deletions src/anki/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ target_link_libraries(
anki
PRIVATE globalmediator
PRIVATE mpvadapter
PRIVATE Qt5::Gui
PRIVATE Qt5::Network
PRIVATE Qt6::Gui
PRIVATE Qt6::Network
PRIVATE subtitlelist
PRIVATE utils
PUBLIC Qt5::Core
PUBLIC Qt6::Core
)
2 changes: 1 addition & 1 deletion src/anki/glossarybuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ QString GlossaryBuilder::addFile(
int dotIndex = path.indexOf('.', lastSlashIndex);
if (dotIndex != -1)
{
hash += path.rightRef(path.length() - dotIndex);
hash += path.right(path.length() - dotIndex);
}
fileMap << QPair<QString, QString>(basepath, hash);
return hash;
Expand Down
4 changes: 2 additions & 2 deletions src/audio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ target_link_libraries(
audioplayer
PRIVATE globalmediator
PRIVATE mpv::mpv
PRIVATE Qt5::Core
PRIVATE Qt5::Network
PRIVATE Qt6::Core
PRIVATE Qt6::Network
PRIVATE utils
)
4 changes: 2 additions & 2 deletions src/dict/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ target_include_directories(dictionary_db PRIVATE ${MEMENTO_INCLUDE_DIRS})
target_link_libraries(
dictionary_db
PRIVATE MeCab::MeCab
PRIVATE Qt5::Widgets
PRIVATE Qt6::Widgets
PRIVATE SQLite::SQLite3
PRIVATE yomidbbuilder
PUBLIC Qt5::Core
PUBLIC Qt6::Core
)
30 changes: 10 additions & 20 deletions src/dict/databasemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ QString DatabaseManager::queryTerms(const QString &query, QList<SharedTerm> &ter
}
if (isStepError(step))
{
ret = QString("Error when executing sqlite query. Code ") + step;
ret = "Error when executing sqlite query. Code " + QString::number(step);
goto error;
}

Expand Down Expand Up @@ -919,10 +919,10 @@ QString DatabaseManager::errorCodeToString(const int code) const
}
}

#define HALFWIDTH_LOW 0xFF61
#define HALFWIDTH_HIGH 0xFF9F
#define HALFWIDTH_VOICED 0xFF9E
#define HALFWIDTH_SEMI_VOICED 0xFF9F
static const QChar HALFWIDTH_LOW(0xFF61);
static const QChar HALFWIDTH_HIGH(0xFF9F);
static const QChar HALFWIDTH_VOICED(0xFF9E);
static const QChar HALFWIDTH_SEMI_VOICED(0xFF9F);

QString DatabaseManager::halfToFull(const QString &query) const
{
Expand Down Expand Up @@ -1065,15 +1065,10 @@ QString DatabaseManager::halfToFull(const QString &query) const
return res;
}

#undef HALFWIDTH_LOW
#undef HALFWIDTH_HIGH
#undef HALFWIDTH_VOICED
#undef HALFWIDTH_SEMI_VOICED

#define KATAKANA_LOW 0x30A1
#define KATAKANA_HIGH 0x30F6
#define HIRAGANA_LOW 0x3041
#define HIRAGANA_HIGH 0x3096
static const QChar KATAKANA_LOW(0x30A1);
static const QChar KATAKANA_HIGH(0x30F6);
static const QChar HIRAGANA_LOW(0x3041);
[[maybe_unused]] static const QChar HIRAGANA_HIGH(0x3096);

QString DatabaseManager::kataToHira(QString query) const
{
Expand All @@ -1082,17 +1077,12 @@ QString DatabaseManager::kataToHira(QString query) const
ushort code = ch.unicode();
if (code >= KATAKANA_LOW && code <= KATAKANA_HIGH)
{
ch = QChar(HIRAGANA_LOW + (code - KATAKANA_LOW));
ch = QChar(HIRAGANA_LOW.unicode() + (code - KATAKANA_LOW.unicode()));
}
}
return query;
}

#undef KATAKANA_LOW
#undef KATAKANA_HIGH
#undef HIRAGANA_LOW
#undef HIRAGANA_HIGH

QStringList DatabaseManager::jsonArrayToStringList(const char *jsonstr) const
{
QJsonDocument document = QJsonDocument::fromJson(jsonstr);
Expand Down
14 changes: 5 additions & 9 deletions src/dict/dictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,21 @@ static QByteArray toWindowsShortPath(const QString &path)
{
QByteArray pathArr = path.toUtf8();
DWORD length = 0;
TCHAR *buf = NULL;

length = GetShortPathName(pathArr.constData(), NULL, 0);
length = GetShortPathNameA(pathArr.constData(), NULL, 0);
if (length == 0)
{
return "";
}

buf = new TCHAR[length];
length = GetShortPathName(pathArr, buf, length);
QByteArray buf(length, '\0');
length = GetShortPathNameA(pathArr, buf.data(), length);
if (length == 0)
{
delete[] buf;
return "";
}

QByteArray ret = QByteArray(buf);
delete[] buf;
return ret;
buf.chop(1);
return buf;
}

/**
Expand Down
13 changes: 4 additions & 9 deletions src/dict/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct Tag
/* Score of the tag. Used for ordering. */
int score;

bool operator==(const Tag &lhs)
bool operator==(const Tag &lhs) const
{
return name == lhs.name &&
category == lhs.category &&
Expand Down Expand Up @@ -257,13 +257,8 @@ struct Kanji : public CommonExpFields
QList<KanjiDefinition> definitions;
};

typedef QSharedPointer<Term> SharedTerm;
Q_DECLARE_METATYPE(SharedTerm)

typedef QSharedPointer<QList<SharedTerm>> SharedTermList;
Q_DECLARE_METATYPE(SharedTermList)

typedef QSharedPointer<Kanji> SharedKanji;
Q_DECLARE_METATYPE(SharedKanji)
using SharedTerm = QSharedPointer<Term>;
using SharedTermList = QSharedPointer<QList<SharedTerm>>;
using SharedKanji = QSharedPointer<Kanji>;

#endif // EXPRESSION_H
3 changes: 2 additions & 1 deletion src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ target_include_directories(mainwindow PRIVATE ${MEMENTO_INCLUDE_DIRS})
target_link_libraries(
mainwindow
PRIVATE "$<$<BOOL:${APPLE}>:cocoa_event_handler>"
PRIVATE "$<$<BOOL:${WIN32}>:Qt6::GuiPrivate>"
PRIVATE aboutwindow
PRIVATE mpvadapter
PRIVATE optionswindow
PRIVATE playeroverlay
PRIVATE searchwidget
PUBLIC Qt5::Widgets
PUBLIC Qt6::Widgets
)
9 changes: 5 additions & 4 deletions src/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <QStyleFactory>

#if defined(Q_OS_WIN)
#include <QtPlatformHeaders/QWindowsWindowFunctions>
#include <qpa/qplatformwindow_p.h>
#endif

#include "dict/dictionary.h"
Expand Down Expand Up @@ -428,10 +428,11 @@ void MainWindow::initTheme()

/* Enable or disable the 1px border on Windows */
#if defined(Q_OS_WIN)
if (window()->windowHandle())
QWindowsWindow *windowsWindow =
dynamic_cast<QWindowsWindow *>(window()->windowHandle());
if (windowsWindow)
{
QWindowsWindowFunctions::setHasBorderInFullScreen(
window()->windowHandle(),
windowsWindow->setHasBorderInFullScreen(
settings.value(
Constants::Settings::Interface::Subtitle::MENUBAR_FULLSCREEN,
Constants::Settings::Interface::Subtitle::MENUBAR_FULLSCREEN_DEFAULT
Expand Down
Loading

0 comments on commit 2070c4b

Please sign in to comment.