Skip to content

Commit

Permalink
Merge pull request #1046 from adamlamar/prepare-qt6
Browse files Browse the repository at this point in the history
Initial Qt6 support
  • Loading branch information
kelson42 authored Mar 4, 2024
2 parents ef14891 + e543bbc commit 6c03254
Show file tree
Hide file tree
Showing 25 changed files with 285 additions and 69 deletions.
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@
*.exe
*.out
*.app
/kiwix-desktop

# QtCreator Environment Settings (not suitable for sharing)
kiwix-desktop.pro.user

# Qt autogenerated files
/qrc_*.cpp
/ui_*.h
/moc_*.h
/moc_*.cpp
/Makefile
/.qmake.stash

# IDE files
/.vscode
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,38 @@ You may want to simply open the kiwix-desktop project in QtCreator and
then compile the project from there (don't forget to update
`PKG_CONFIG_PATH` if necessary).

Compilation with Qt6
--------------------

There is initial support for Qt6. Additional packages are needed:

```bash
sudo apt install qt6-base-dev qt6-base-dev-tools qt6-webengine-dev libqt6webenginecore6-bin libqt6svg6
```

And `qmake` needs to be configured to use Qt6. First confirm `qmake` is using the right version:

```bash
qtchooser -install qt6 $(which qmake6) # run once
export QT_SELECT=qt6 # set in environments where Qt6 builds are desired
qmake --version
```

produces this output:

```bash
$ qmake --version
QMake version 3.1
Using Qt version 6.2.4 in /usr/lib/aarch64-linux-gnu
```

then build as normal:

```bash
qmake .
make
```

Installation
------------

Expand Down
3 changes: 2 additions & 1 deletion kiwix-desktop.pro
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0


SOURCES += \
Expand Down Expand Up @@ -124,6 +124,7 @@ HEADERS += \
src/fullscreennotification.h \
src/menuproxystyle.h \
src/zimview.h \
src/portutils.h \

FORMS += \
src/choiceitem.ui \
Expand Down
1 change: 1 addition & 0 deletions resources/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
"ok":"ok",
"no-filter":"no filter",
"open-link-in-web-browser":"Open link in web browser",
"open-link-new-tab":"Open link in new tab",
"download-dir-dialog-title":"Are you sure you want to change the download directory?",
"download-dir-dialog-msg":"The new download directory path will be:\n{{DIRECTORY}}",
"invalid-port":"Invalid port",
Expand Down
1 change: 1 addition & 0 deletions src/blobbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

class BlobBuffer : public QBuffer
{
Q_OBJECT
public:
BlobBuffer(zim::Blob m_blob);
virtual ~BlobBuffer() = default;
Expand Down
2 changes: 1 addition & 1 deletion src/contentmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ ContentManager::BookInfo ContentManager::getBookInfos(QString id, const QStringL
QStringList tagList = QString::fromStdString(b->getTags()).split(';');
QMap<QString, bool> displayTagMap;
for(auto tag: tagList) {
if (tag[0] == "_") {
if (tag[0] == '_') {
auto splitTag = tag.split(":");
displayTagMap[splitTag[0]] = splitTag[1] == "yes" ? true:false;
}
Expand Down
13 changes: 9 additions & 4 deletions src/contentmanagerdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
#include "contentmanagerdelegate.h"
#include <QApplication>
#include <QDialog>
#include <QStyleOptionViewItemV4>
#include <QStyleOptionViewItem>
#include "kiwixapp.h"
#include <QStyleOptionViewItem>
#include "rownode.h"
#include "descriptionnode.h"
#include "portutils.h"

ContentManagerDelegate::ContentManagerDelegate(QObject *parent)
: QStyledItemDelegate(parent), baseButton(new QPushButton)
Expand Down Expand Up @@ -198,7 +199,11 @@ void ContentManagerDelegate::paint(QPainter *painter, const QStyleOptionViewItem
}
if (index.column() == 1) {
auto bFont = painter->font();
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
bFont.setWeight(60);
#else
bFont.setWeight(QFont::DemiBold);
#endif
eOpt.font = bFont;
}
QStyledItemDelegate::paint(painter, eOpt, index);
Expand All @@ -209,8 +214,8 @@ bool ContentManagerDelegate::editorEvent(QEvent *event, QAbstractItemModel *mode
if(event->type() == QEvent::MouseButtonRelease )
{
QMouseEvent * e = (QMouseEvent *)event;
int clickX = e->x();
int clickY = e->y();
int clickX = portutils::getX(*e);
int clickY = portutils::getY(*e);

QRect r = option.rect;
int x,y,w,h;
Expand Down Expand Up @@ -238,7 +243,7 @@ void ContentManagerDelegate::handleLastColumnClicked(const QModelIndex& index, Q
{
const auto node = static_cast<RowNode*>(index.internalPointer());
const auto id = node->getBookId();
int clickX = mouseEvent->x();
int clickX = portutils::getX(*mouseEvent);

QRect r = option.rect;
int x = r.left();
Expand Down
1 change: 1 addition & 0 deletions src/flowlayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
//! [0]
class FlowLayout : public QLayout
{
Q_OBJECT
public:
explicit FlowLayout(QWidget *parent, int margin = -1, int hSpacing = -1, int vSpacing = -1);
explicit FlowLayout(int margin = -1, int hSpacing = -1, int vSpacing = -1);
Expand Down
4 changes: 3 additions & 1 deletion src/fullscreenwindow.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
class QMenu;

#include "fullscreenwindow.h"
#include <QAction>

Expand Down Expand Up @@ -41,4 +43,4 @@ void FullScreenWindow::resizeEvent(QResizeEvent *event)
m_notification->setGeometry(notificationGeometry);

QWidget::resizeEvent(event);
}
}
3 changes: 2 additions & 1 deletion src/fullscreenwindow.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef FULLSCREENWINDOW_H
#define FULLSCREENWINDOW_H

class QMenu;
#include <QWidget>
#include <QWebEngineView>
#include "fullscreennotification.h"
Expand Down Expand Up @@ -28,4 +29,4 @@ class FullScreenWindow : public QWidget
QRect m_oldGeometry;
};

#endif // FULLSCREENWINDOW_H
#endif // FULLSCREENWINDOW_H
63 changes: 38 additions & 25 deletions src/kiwixapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,13 @@ KiwixApp::KiwixApp(int& argc, char *argv[])
QMessageBox::critical(nullptr, "Translation error", e.what());
return;
}
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
m_qtTranslator.load(QLocale(), "qt", "_",
QLibraryInfo::location(QLibraryInfo::TranslationsPath));
#else
m_qtTranslator.load(QLocale(), "qt", "_",
QLibraryInfo::path(QLibraryInfo::TranslationsPath));
#endif
installTranslator(&m_qtTranslator);

m_appTranslator.load(QLocale(), "kiwix-desktop", "_", ":/i18n/");
Expand Down Expand Up @@ -201,6 +206,7 @@ void KiwixApp::printPage()
{
if(!getTabWidget()->currentZimView())
return;

QPrinter* printer = new QPrinter();
QPrintDialog printDialog(printer, mp_mainWindow);
printDialog.setStyle(nullptr);
Expand All @@ -209,12 +215,19 @@ void KiwixApp::printPage()
auto webview = getTabWidget()->currentWebView();
if(!webview)
return;
webview->page()->print(printer, [=](bool success) {
if (!success) {
showMessage(gt("print-page-error"), gt("error-title"), QMessageBox::Critical);
}
delete printer;
});

const auto onPrintFinished = [=](bool success) {
if (!success) {
showMessage(gt("print-page-error"), gt("error-title"), QMessageBox::Critical);
}
delete printer;
};
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
webview->page()->print(printer, onPrintFinished);
#else
webview->print(printer);
connect(webview, &QWebEngineView::printFinished, this, onPrintFinished);
#endif
}
}

Expand Down Expand Up @@ -329,25 +342,25 @@ void KiwixApp::setMonitorDir(const QString &dir) {

void KiwixApp::createAction()
{
CREATE_ACTION_ICON_SHORTCUT(KiwixServeAction, "share", gt("local-kiwix-server"), QKeySequence(Qt::CTRL+Qt::Key_I));
CREATE_ACTION_ICON_SHORTCUT(KiwixServeAction, "share", gt("local-kiwix-server"), QKeySequence(Qt::CTRL | Qt::Key_I));

CREATE_ACTION_ICON_SHORTCUT(RandomArticleAction, "random", gt("random-article"), QKeySequence(Qt::CTRL+Qt::Key_R));
CREATE_ACTION_ICON_SHORTCUT(RandomArticleAction, "random", gt("random-article"), QKeySequence(Qt::CTRL | Qt::Key_R));
connect(mpa_actions[RandomArticleAction], &QAction::triggered,
this, [=]() { this->openRandomUrl(false); });

CREATE_ACTION_SHORTCUT(OpenHomePageAction, gt("home-page"), QKeySequence(Qt::ALT + Qt::Key_Home));
CREATE_ACTION_SHORTCUT(OpenHomePageAction, gt("home-page"), QKeySequence(Qt::ALT | Qt::Key_Home));

if (QGuiApplication::isLeftToRight()) {
CREATE_ACTION_ICON_SHORTCUT(HistoryBackAction, "history-left", gt("back"), QKeySequence(Qt::ALT + Qt::Key_Left));
CREATE_ACTION_ICON_SHORTCUT(HistoryBackAction, "history-left", gt("back"), QKeySequence(Qt::ALT | Qt::Key_Left));
} else {
CREATE_ACTION_ICON_SHORTCUT(HistoryBackAction, "history-right", gt("back"), QKeySequence(Qt::ALT + Qt::Key_Right));
CREATE_ACTION_ICON_SHORTCUT(HistoryBackAction, "history-right", gt("back"), QKeySequence(Qt::ALT | Qt::Key_Right));
}
DISABLE_ACTION(HistoryBackAction);

if (QGuiApplication::isLeftToRight()) {
CREATE_ACTION_ICON_SHORTCUT(HistoryForwardAction, "history-right", gt("forward"), QKeySequence(Qt::ALT + Qt::Key_Right));
CREATE_ACTION_ICON_SHORTCUT(HistoryForwardAction, "history-right", gt("forward"), QKeySequence(Qt::ALT | Qt::Key_Right));
} else {
CREATE_ACTION_ICON_SHORTCUT(HistoryForwardAction, "history-left", gt("forward"), QKeySequence(Qt::ALT + Qt::Key_Left));
CREATE_ACTION_ICON_SHORTCUT(HistoryForwardAction, "history-left", gt("forward"), QKeySequence(Qt::ALT | Qt::Key_Left));
}
DISABLE_ACTION(HistoryForwardAction);

Expand All @@ -357,13 +370,13 @@ void KiwixApp::createAction()

CREATE_ACTION_ICON_SHORTCUT(NewTabAction,"new-tab-icon", gt("new-tab"), QKeySequence::AddTab);

CREATE_ACTION_ICON_SHORTCUTS(CloseTabAction, "close", gt("close-tab"), QList<QKeySequence>({QKeySequence(Qt::CTRL + Qt::Key_F4), QKeySequence(Qt::CTRL + Qt::Key_W)}));
CREATE_ACTION_ICON_SHORTCUTS(CloseTabAction, "close", gt("close-tab"), QList<QKeySequence>({QKeySequence(Qt::CTRL | Qt::Key_F4), QKeySequence(Qt::CTRL | Qt::Key_W)}));
mpa_actions[CloseTabAction]->setIconVisibleInMenu(false);

CREATE_ACTION_SHORTCUT(ReopenClosedTabAction, gt("reopen-closed-tab"), QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_T));
CREATE_ACTION_SHORTCUT(ReopenClosedTabAction, gt("reopen-closed-tab"), QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_T));
HIDE_ACTION(ReopenClosedTabAction);

CREATE_ACTION_SHORTCUT(BrowseLibraryAction, gt("browse-library"), QKeySequence(Qt::CTRL+Qt::Key_E));
CREATE_ACTION_SHORTCUT(BrowseLibraryAction, gt("browse-library"), QKeySequence(Qt::CTRL | Qt::Key_E));
HIDE_ACTION(BrowseLibraryAction);

CREATE_ACTION_ICON_SHORTCUT(OpenFileAction, "open-file", gt("open-file"), QKeySequence::Open);
Expand All @@ -379,10 +392,10 @@ void KiwixApp::createAction()
HIDE_ACTION(SavePageAsAction);
*/

CREATE_ACTION_SHORTCUT(SearchArticleAction, gt("search-article"), QKeySequence(Qt::CTRL+Qt::Key_L));
CREATE_ACTION_SHORTCUT(SearchArticleAction, gt("search-article"), QKeySequence(Qt::CTRL | Qt::Key_L));
HIDE_ACTION(SearchArticleAction);

CREATE_ACTION_SHORTCUT(SearchLibraryAction, gt("search-in-library"), QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_R));
CREATE_ACTION_SHORTCUT(SearchLibraryAction, gt("search-in-library"), QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_R));
HIDE_ACTION(SearchLibraryAction);

CREATE_ACTION(FindInPageAction, gt("find-in-page"));
Expand All @@ -400,20 +413,20 @@ void KiwixApp::createAction()
});
mpa_actions[ToggleFullscreenAction]->setCheckable(true);

CREATE_ACTION_SHORTCUT(ToggleTOCAction, gt("table-of-content"), QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_1));
CREATE_ACTION_SHORTCUT(ToggleTOCAction, gt("table-of-content"), QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_1));
HIDE_ACTION(ToggleTOCAction);

CREATE_ACTION_ONOFF_ICON_SHORTCUT(ToggleReadingListAction, "reading-list-active", "reading-list", gt("reading-list"), QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_2));
CREATE_ACTION_ONOFF_ICON_SHORTCUT(ToggleReadingListAction, "reading-list-active", "reading-list", gt("reading-list"), QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_2));

CREATE_ACTION_SHORTCUTS(ZoomInAction, gt("zoom-in"), QList<QKeySequence>({QKeySequence::ZoomIn, QKeySequence(Qt::CTRL+Qt::Key_Equal)}));
CREATE_ACTION_SHORTCUTS(ZoomInAction, gt("zoom-in"), QList<QKeySequence>({QKeySequence::ZoomIn, QKeySequence(Qt::CTRL | Qt::Key_Equal)}));

CREATE_ACTION_SHORTCUT(ZoomOutAction, gt("zoom-out"), QKeySequence::ZoomOut);

CREATE_ACTION_SHORTCUT(ZoomResetAction, gt("zoom-reset"), QKeySequence(Qt::CTRL+Qt::Key_0));
CREATE_ACTION_SHORTCUT(ZoomResetAction, gt("zoom-reset"), QKeySequence(Qt::CTRL | Qt::Key_0));

CREATE_ACTION_SHORTCUT(NextTabAction, gt("next-tab"), QKeySequence(Qt::CTRL + Qt::Key_Tab));
CREATE_ACTION_SHORTCUT(NextTabAction, gt("next-tab"), QKeySequence(Qt::CTRL | Qt::Key_Tab));

CREATE_ACTION_SHORTCUT(PreviousTabAction, gt("previous-tab"), QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Tab));
CREATE_ACTION_SHORTCUT(PreviousTabAction, gt("previous-tab"), QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_Tab));

CREATE_ACTION_SHORTCUT(HelpAction, gt("help"), QKeySequence::HelpContents);
HIDE_ACTION(HelpAction);
Expand All @@ -431,7 +444,7 @@ void KiwixApp::createAction()

CREATE_ACTION_ICON_SHORTCUT(SettingAction, "settings", gt("settings"), QKeySequence(Qt::Key_F12));

CREATE_ACTION_ICON_SHORTCUT(DonateAction, "donate", gt("donate-to-support-kiwix"), QKeySequence(Qt::CTRL+Qt::Key_D));
CREATE_ACTION_ICON_SHORTCUT(DonateAction, "donate", gt("donate-to-support-kiwix"), QKeySequence(Qt::CTRL | Qt::Key_D));

CREATE_ACTION_ICON_SHORTCUT(ExitAction, "exit", gt("exit"), QKeySequence::Quit);
}
Expand Down
8 changes: 8 additions & 0 deletions src/kprofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ KProfile::KProfile(QObject *parent) :
settings()->setAttribute(QWebEngineSettings::FullScreenSupportEnabled, true);
}

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
void KProfile::startDownload(QWebEngineDownloadItem* download)
#else
void KProfile::startDownload(QWebEngineDownloadRequest* download)
#endif
{
QString defaultFileName = download->url().fileName();
QString fileName = QFileDialog::getSaveFileName(KiwixApp::instance()->getMainWindow(),
Expand All @@ -30,7 +34,11 @@ void KProfile::startDownload(QWebEngineDownloadItem* download)
#else
download->setDownloadFileName(fileName);
#endif
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
connect(download, &QWebEngineDownloadItem::finished, this, &KProfile::downloadFinished);
#else
connect(download, &QWebEngineDownloadRequest::isFinished, this, &KProfile::downloadFinished);
#endif
download->accept();
}

Expand Down
10 changes: 10 additions & 0 deletions src/kprofile.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
#define KPROFILE_H

#include <QWebEngineProfile>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QWebEngineDownloadItem>
#else
#include <QWebEngineDownloadRequest>
#endif

#include "urlschemehandler.h"

Expand All @@ -16,7 +21,12 @@ class KProfile : public QWebEngineProfile

signals:
public slots:

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
void startDownload(QWebEngineDownloadItem*);
#else
void startDownload(QWebEngineDownloadRequest*);
#endif
void downloadFinished();
};

Expand Down
4 changes: 3 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ int main(int argc, char *argv[])
}
// End of hack ^^^


#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
// High DPI Scaling is enabled by default in Qt6. This attribute no longer exists in 6.0 and later
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
QWebEngineUrlScheme scheme("zim");
QWebEngineUrlScheme::registerScheme(scheme);
Expand Down
Loading

0 comments on commit 6c03254

Please sign in to comment.