Skip to content

Commit

Permalink
fix(build): suport build with Qt6 && Qt5
Browse files Browse the repository at this point in the history
使用条件编译将选择不同版本 Qt 接口
  • Loading branch information
kegechen committed Jun 19, 2023
1 parent 58095a7 commit b683e97
Show file tree
Hide file tree
Showing 14 changed files with 196 additions and 204 deletions.
3 changes: 2 additions & 1 deletion examples/dnd-example/dnd-test-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <QVBoxLayout>
#include <QProgressBar>
#include <QDebug>
#include <QRandomGenerator>

DGUI_USE_NAMESPACE

Expand Down Expand Up @@ -97,7 +98,7 @@ int main(int argc, char **argv)
});

QObject::connect(&t, &QTimer::timeout, [&t, &pg] {
if (qrand() & 1) {
if (QRandomGenerator::global()->generate() & 1) {
s->setProgress(++p);
pg.setValue(p);
if(p == 100) {
Expand Down
1 change: 0 additions & 1 deletion examples/test-taskbar/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <DFontManager>

#include <QApplication>
#include <QDesktopWidget>

#include "testtaskbarwindow.h"

Expand Down
35 changes: 27 additions & 8 deletions src/kernel/dguiapplicationhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,17 @@ class _DGuiApplicationHelper
{
// 临时存储一个无效的指针值, 用于此处条件变量的竞争
if (m_helper.testAndSetRelaxed(nullptr, INVALID_HELPER)) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
m_helper.storeRelaxed(creator());
m_helper.loadRelaxed()->initialize();
}
return m_helper.loadRelaxed();
#else
m_helper.store(creator());
m_helper.load()->initialize();
}

return m_helper.load();
#endif
}

inline void clear()
Expand Down Expand Up @@ -255,7 +261,7 @@ void DGuiApplicationHelperPrivate::staticInitApplication()
if (!_globalHelper.exists())
return;

if (DGuiApplicationHelper *helper = _globalHelper->m_helper.load())
if (DGuiApplicationHelper *helper = _globalHelper->helper())
helper->d_func()->initApplication(qGuiApp);
}

Expand Down Expand Up @@ -1211,13 +1217,21 @@ void DGuiApplicationHelper::setApplicationPalette(const DPalette &palette)
qWarning() << "DGuiApplicationHelper: Plase check 'QGuiApplication::setPalette', Don't use it on DTK application.";
}

auto resolve = [](const DPalette &palette) ->bool {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
return palette.resolveMask();
#else
return palette.resolve();
#endif
};

if (d->appPalette) {
if (palette.resolve()) {
if (resolve(palette)) {
*d->appPalette = palette;
} else {
d->appPalette.reset();
}
} else if (palette.resolve()) {
} else if (resolve(palette)) {
d->appPalette.reset(new DPalette(palette));
} else {
return;
Expand Down Expand Up @@ -1313,7 +1327,7 @@ DGuiApplicationHelper::ColorType DGuiApplicationHelper::toColorType(const QColor
*/
DGuiApplicationHelper::ColorType DGuiApplicationHelper::toColorType(const QPalette &palette)
{
return toColorType(palette.background().color());
return toColorType(palette.window().color());
}

/*!
Expand Down Expand Up @@ -1468,8 +1482,8 @@ bool DGuiApplicationHelper::setSingleInstance(const QString &key, DGuiApplicatio
qCInfo(dgAppHelper) << "New instance: pid=" << pid << "arguments=" << arguments;

// 通知新进程的信息
if (_globalHelper.exists() && _globalHelper->m_helper.load())
Q_EMIT _globalHelper->m_helper.load()->newProcessInstance(pid, arguments);
if (_globalHelper.exists() && _globalHelper->helper())
Q_EMIT _globalHelper->helper()->newProcessInstance(pid, arguments);
});

instance->flush(); //发送数据给新的实例
Expand Down Expand Up @@ -1589,7 +1603,12 @@ bool DGuiApplicationHelper::loadTranslator(const QString &fileName, const QList<
QStringList missingQmfiles;
for (const auto &locale : localeFallback) {
QStringList translateFilenames {QString("%1_%2").arg(fileName).arg(locale.name())};
const QStringList parseLocalNameList = locale.name().split("_", QString::SkipEmptyParts);
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
auto behavior = Qt::SkipEmptyParts;
#else
auto behavior = QString::SkipEmptyParts;
#endif
const QStringList parseLocalNameList = locale.name().split("_", behavior);
if (parseLocalNameList.length() > 0)
translateFilenames << QString("%1_%2").arg(fileName).arg(parseLocalNameList.at(0));

Expand Down
7 changes: 6 additions & 1 deletion src/kernel/dnativesettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,12 @@ QDebug operator<<(QDebug debug, const DTK_GUI_NAMESPACE::DNativeSettings &settin
const QByteArrayList &keys = settings.allKeys();

for (const QByteArray &key : keys) {
debug << key << settings.getSetting(key) << endl;
debug << key << settings.getSetting(key) <<
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
Qt::endl;
#else
endl;
#endif
}

return debug;
Expand Down
Loading

0 comments on commit b683e97

Please sign in to comment.