refactor: fix deprecation up to Qt 5.15
Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
parent
c1bcbf8c63
commit
984692dc62
@ -290,7 +290,6 @@ else()
|
||||
message(STATUS "Using system QuaZip")
|
||||
endif()
|
||||
add_subdirectory(libraries/rainbow) # Qt extension for colors
|
||||
add_subdirectory(libraries/iconfix) # fork of Qt's QIcon loader
|
||||
add_subdirectory(libraries/LocalPeer) # fork of a library from Qt solutions
|
||||
add_subdirectory(libraries/classparser) # class parser library
|
||||
add_subdirectory(libraries/optional-bare)
|
||||
|
@ -84,6 +84,7 @@
|
||||
#include <QDebug>
|
||||
#include <QStyleFactory>
|
||||
#include <QWindow>
|
||||
#include <QIcon>
|
||||
|
||||
#include "InstanceList.h"
|
||||
|
||||
@ -99,7 +100,6 @@
|
||||
#include "tools/JVisualVM.h"
|
||||
#include "tools/MCEditTool.h"
|
||||
|
||||
#include <xdgicon.h>
|
||||
#include "settings/INISettingsObject.h"
|
||||
#include "settings/Setting.h"
|
||||
|
||||
@ -1182,7 +1182,7 @@ void Application::setApplicationTheme(const QString& name, bool initial)
|
||||
|
||||
void Application::setIconTheme(const QString& name)
|
||||
{
|
||||
XdgIcon::setThemeName(name);
|
||||
QIcon::setThemeName(name);
|
||||
}
|
||||
|
||||
QIcon Application::getThemedIcon(const QString& name)
|
||||
@ -1190,7 +1190,7 @@ QIcon Application::getThemedIcon(const QString& name)
|
||||
if(name == "logo") {
|
||||
return QIcon(":/org.polymc.PolyMC.svg");
|
||||
}
|
||||
return XdgIcon::fromTheme(name);
|
||||
return QIcon::fromTheme(name);
|
||||
}
|
||||
|
||||
bool Application::openJsonEditor(const QString &filename)
|
||||
|
@ -2,10 +2,11 @@
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include "Json.h"
|
||||
|
||||
void ApplicationMessage::parse(const QByteArray & input) {
|
||||
auto doc = QJsonDocument::fromBinaryData(input);
|
||||
auto root = doc.object();
|
||||
auto doc = Json::requireDocument(input, "ApplicationMessage");
|
||||
auto root = Json::requireObject(doc, "ApplicationMessage");
|
||||
|
||||
command = root.value("command").toString();
|
||||
args.clear();
|
||||
@ -25,7 +26,5 @@ QByteArray ApplicationMessage::serialize() {
|
||||
}
|
||||
root.insert("args", outArgs);
|
||||
|
||||
QJsonDocument out;
|
||||
out.setObject(root);
|
||||
return out.toBinaryData();
|
||||
return Json::toText(root);
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ QVariant BaseVersionList::data(const QModelIndex &index, int role) const
|
||||
switch (role)
|
||||
{
|
||||
case VersionPointerRole:
|
||||
return qVariantFromValue(version);
|
||||
return QVariant::fromValue(version);
|
||||
|
||||
case VersionRole:
|
||||
return version->name();
|
||||
|
@ -963,6 +963,7 @@ target_link_libraries(Launcher_logic
|
||||
tomlc99
|
||||
BuildConfig
|
||||
Katabasis
|
||||
Qt5::Widgets
|
||||
)
|
||||
|
||||
if (UNIX AND NOT CYGWIN AND NOT APPLE)
|
||||
@ -979,7 +980,6 @@ target_link_libraries(Launcher_logic
|
||||
Qt5::Gui
|
||||
)
|
||||
target_link_libraries(Launcher_logic
|
||||
Launcher_iconfix
|
||||
QuaZip::QuaZip
|
||||
hoedown
|
||||
LocalPeer
|
||||
|
@ -49,8 +49,8 @@ class copy
|
||||
public:
|
||||
copy(const QString & src, const QString & dst)
|
||||
{
|
||||
m_src = src;
|
||||
m_dst = dst;
|
||||
m_src.setPath(src);
|
||||
m_dst.setPath(dst);
|
||||
}
|
||||
copy & followSymlinks(const bool follow)
|
||||
{
|
||||
|
@ -136,7 +136,7 @@ QVariant InstanceList::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
case InstancePointerRole:
|
||||
{
|
||||
QVariant v = qVariantFromValue((void *)pdata);
|
||||
QVariant v = QVariant::fromValue((void *)pdata);
|
||||
return v;
|
||||
}
|
||||
case InstanceIDRole:
|
||||
@ -252,7 +252,7 @@ void InstanceList::setInstanceGroup(const InstanceId& id, const GroupId& name)
|
||||
|
||||
QStringList InstanceList::getGroups()
|
||||
{
|
||||
return m_groupNameCache.toList();
|
||||
return m_groupNameCache.values();
|
||||
}
|
||||
|
||||
void InstanceList::deleteGroup(const QString& name)
|
||||
@ -353,7 +353,11 @@ QList< InstanceId > InstanceList::discoverInstances()
|
||||
out.append(id);
|
||||
qDebug() << "Found instance ID" << id;
|
||||
}
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
instanceSet = QSet<QString>(out.begin(), out.end());
|
||||
#else
|
||||
instanceSet = out.toSet();
|
||||
#endif
|
||||
m_instancesProbed = true;
|
||||
return out;
|
||||
}
|
||||
|
@ -22,14 +22,6 @@ void write(const QJsonArray &array, const QString &filename)
|
||||
write(QJsonDocument(array), filename);
|
||||
}
|
||||
|
||||
QByteArray toBinary(const QJsonObject &obj)
|
||||
{
|
||||
return QJsonDocument(obj).toBinaryData();
|
||||
}
|
||||
QByteArray toBinary(const QJsonArray &array)
|
||||
{
|
||||
return QJsonDocument(array).toBinaryData();
|
||||
}
|
||||
QByteArray toText(const QJsonObject &obj)
|
||||
{
|
||||
return QJsonDocument(obj).toJson(QJsonDocument::Compact);
|
||||
@ -48,12 +40,8 @@ QJsonDocument requireDocument(const QByteArray &data, const QString &what)
|
||||
{
|
||||
if (isBinaryJson(data))
|
||||
{
|
||||
QJsonDocument doc = QJsonDocument::fromBinaryData(data);
|
||||
if (doc.isNull())
|
||||
{
|
||||
throw JsonException(what + ": Invalid JSON (binary JSON detected)");
|
||||
}
|
||||
return doc;
|
||||
// FIXME: Is this needed?
|
||||
throw JsonException(what + ": Invalid JSON. Binary JSON unsupported");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -29,8 +29,6 @@ void write(const QJsonObject &object, const QString &filename);
|
||||
/// @throw FileSystemException
|
||||
void write(const QJsonArray &array, const QString &filename);
|
||||
|
||||
QByteArray toBinary(const QJsonObject &obj);
|
||||
QByteArray toBinary(const QJsonArray &array);
|
||||
QByteArray toText(const QJsonObject &obj);
|
||||
QByteArray toText(const QJsonArray &array);
|
||||
|
||||
|
@ -157,19 +157,6 @@ void LoggedProcess::on_stateChange(QProcess::ProcessState state)
|
||||
}
|
||||
}
|
||||
|
||||
#if defined Q_OS_WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
qint64 LoggedProcess::processId() const
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
return pid() ? pid()->dwProcessId : 0;
|
||||
#else
|
||||
return pid();
|
||||
#endif
|
||||
}
|
||||
|
||||
void LoggedProcess::setDetachable(bool detachable)
|
||||
{
|
||||
m_is_detachable = detachable;
|
||||
|
@ -43,7 +43,6 @@ public:
|
||||
|
||||
State state() const;
|
||||
int exitCode() const;
|
||||
qint64 processId() const;
|
||||
|
||||
void setDetachable(bool detachable);
|
||||
|
||||
|
@ -208,7 +208,8 @@ QVariant VersionProxyModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
return APPLICATION->getThemedIcon("bug");
|
||||
}
|
||||
auto pixmap = QPixmapCache::find("placeholder");
|
||||
QPixmap pixmap;
|
||||
QPixmapCache::find("placeholder", &pixmap);
|
||||
if(!pixmap)
|
||||
{
|
||||
QPixmap px(16,16);
|
||||
@ -216,7 +217,7 @@ QVariant VersionProxyModel::data(const QModelIndex &index, int role) const
|
||||
QPixmapCache::insert("placeholder", px);
|
||||
return px;
|
||||
}
|
||||
return *pixmap;
|
||||
return pixmap;
|
||||
}
|
||||
}
|
||||
default:
|
||||
|
@ -86,7 +86,11 @@ void IconList::directoryChanged(const QString &path)
|
||||
QString &foo = (*it);
|
||||
foo = m_dir.filePath(foo);
|
||||
}
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
QSet<QString> new_set(new_list.begin(), new_list.end());
|
||||
#else
|
||||
auto new_set = new_list.toSet();
|
||||
#endif
|
||||
QList<QString> current_list;
|
||||
for (auto &it : icons)
|
||||
{
|
||||
@ -94,7 +98,11 @@ void IconList::directoryChanged(const QString &path)
|
||||
continue;
|
||||
current_list.push_back(it.m_images[IconType::FileBased].filename);
|
||||
}
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
QSet<QString> current_set(current_list.begin(), current_list.end());
|
||||
#else
|
||||
QSet<QString> current_set = current_list.toSet();
|
||||
#endif
|
||||
|
||||
QSet<QString> to_remove = current_set;
|
||||
to_remove -= new_set;
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
#include "MMCIcon.h"
|
||||
#include <QFileInfo>
|
||||
#include <xdgicon.h>
|
||||
#include <QIcon>
|
||||
|
||||
IconType operator--(IconType &t, int)
|
||||
{
|
||||
@ -63,7 +63,7 @@ QIcon MMCIcon::icon() const
|
||||
if(!icon.isNull())
|
||||
return icon;
|
||||
// FIXME: inject this.
|
||||
return XdgIcon::fromTheme(m_images[m_current_type].key);
|
||||
return QIcon::fromTheme(m_images[m_current_type].key);
|
||||
}
|
||||
|
||||
void MMCIcon::remove(IconType rm_type)
|
||||
|
@ -105,7 +105,12 @@ void JavaChecker::finished(int exitcode, QProcess::ExitStatus status)
|
||||
bool success = true;
|
||||
|
||||
QMap<QString, QString> results;
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
QStringList lines = m_stdout.split("\n", Qt::SkipEmptyParts);
|
||||
#else
|
||||
QStringList lines = m_stdout.split("\n", QString::SkipEmptyParts);
|
||||
#endif
|
||||
for(QString line : lines)
|
||||
{
|
||||
line = line.trimmed();
|
||||
@ -114,7 +119,11 @@ void JavaChecker::finished(int exitcode, QProcess::ExitStatus status)
|
||||
continue;
|
||||
}
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
auto parts = line.split('=', Qt::SkipEmptyParts);
|
||||
#else
|
||||
auto parts = line.split('=', QString::SkipEmptyParts);
|
||||
#endif
|
||||
if(parts.size() != 2 || parts[0].isEmpty() || parts[1].isEmpty())
|
||||
{
|
||||
continue;
|
||||
|
@ -81,7 +81,7 @@ QVariant JavaInstallList::data(const QModelIndex &index, int role) const
|
||||
switch (role)
|
||||
{
|
||||
case VersionPointerRole:
|
||||
return qVariantFromValue(m_vlist[index.row()]);
|
||||
return QVariant::fromValue(m_vlist[index.row()]);
|
||||
case VersionIdRole:
|
||||
return version->descriptor();
|
||||
case VersionRole:
|
||||
|
@ -282,6 +282,23 @@ void LaunchTask::emitFailed(QString reason)
|
||||
Task::emitFailed(reason);
|
||||
}
|
||||
|
||||
void LaunchTask::substituteVariables(const QStringList &args) const
|
||||
{
|
||||
auto variables = m_instance->getVariables();
|
||||
auto envVariables = QProcessEnvironment::systemEnvironment();
|
||||
|
||||
for (auto arg : args) {
|
||||
for (auto key : variables)
|
||||
{
|
||||
arg.replace("$" + key, variables.value(key));
|
||||
}
|
||||
for (auto env : envVariables.keys())
|
||||
{
|
||||
arg.replace("$" + env, envVariables.value(env));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QString LaunchTask::substituteVariables(const QString &cmd) const
|
||||
{
|
||||
QString out = cmd;
|
||||
|
@ -85,6 +85,7 @@ public: /* methods */
|
||||
shared_qobject_ptr<LogModel> getLogModel();
|
||||
|
||||
public:
|
||||
void substituteVariables(const QStringList &args) const;
|
||||
QString substituteVariables(const QString &cmd) const;
|
||||
QString censorPrivateInfo(QString in);
|
||||
|
||||
|
@ -27,9 +27,19 @@ PostLaunchCommand::PostLaunchCommand(LaunchTask *parent) : LaunchStep(parent)
|
||||
|
||||
void PostLaunchCommand::executeTask()
|
||||
{
|
||||
//FIXME: where to put this?
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
|
||||
auto args = QProcess::splitCommand(m_command);
|
||||
m_parent->substituteVariables(args);
|
||||
|
||||
emit logLine(tr("Running Post-Launch command: %1").arg(args.join(' ')), MessageLevel::Launcher);
|
||||
const QString program = args.takeFirst();
|
||||
m_process.start(program, args);
|
||||
#else
|
||||
QString postlaunch_cmd = m_parent->substituteVariables(m_command);
|
||||
emit logLine(tr("Running Post-Launch command: %1").arg(postlaunch_cmd), MessageLevel::Launcher);
|
||||
m_process.start(postlaunch_cmd);
|
||||
#endif
|
||||
}
|
||||
|
||||
void PostLaunchCommand::on_state(LoggedProcess::State state)
|
||||
|
@ -28,9 +28,18 @@ PreLaunchCommand::PreLaunchCommand(LaunchTask *parent) : LaunchStep(parent)
|
||||
void PreLaunchCommand::executeTask()
|
||||
{
|
||||
//FIXME: where to put this?
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
|
||||
auto args = QProcess::splitCommand(m_command);
|
||||
m_parent->substituteVariables(args);
|
||||
|
||||
emit logLine(tr("Running Pre-Launch command: %1").arg(args.join(' ')), MessageLevel::Launcher);
|
||||
const QString program = args.takeFirst();
|
||||
m_process.start(program, args);
|
||||
#else
|
||||
QString prelaunch_cmd = m_parent->substituteVariables(m_command);
|
||||
emit logLine(tr("Running Pre-Launch command: %1").arg(prelaunch_cmd), MessageLevel::Launcher);
|
||||
m_process.start(prelaunch_cmd);
|
||||
#endif
|
||||
}
|
||||
|
||||
void PreLaunchCommand::on_state(LoggedProcess::State state)
|
||||
|
@ -540,7 +540,11 @@ QStringList MinecraftInstance::processMinecraftArgs(
|
||||
token_mapping["assets_root"] = absAssetsDir;
|
||||
token_mapping["assets_index_name"] = assets->id;
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
QStringList parts = args_pattern.split(' ', Qt::SkipEmptyParts);
|
||||
#else
|
||||
QStringList parts = args_pattern.split(' ', QString::SkipEmptyParts);
|
||||
#endif
|
||||
for (int i = 0; i < parts.length(); i++)
|
||||
{
|
||||
parts[i] = replaceTokensIn(parts[i], token_mapping);
|
||||
|
@ -296,7 +296,7 @@ QJsonDocument OneSixVersionFormat::versionFileToJson(const VersionFilePtr &patch
|
||||
}
|
||||
writeString(root, "appletClass", patch->appletClass);
|
||||
writeStringList(root, "+tweakers", patch->addTweakers);
|
||||
writeStringList(root, "+traits", patch->traits.toList());
|
||||
writeStringList(root, "+traits", patch->traits.values());
|
||||
if (!patch->libraries.isEmpty())
|
||||
{
|
||||
QJsonArray array;
|
||||
|
@ -688,7 +688,11 @@ void PackProfile::move(const int index, const MoveDirection direction)
|
||||
return;
|
||||
}
|
||||
beginMoveRows(QModelIndex(), index, index, QModelIndex(), togap);
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
|
||||
d->components.swapItemsAt(index, theirIndex);
|
||||
#else
|
||||
d->components.swap(index, theirIndex);
|
||||
#endif
|
||||
endMoveRows();
|
||||
invalidateLaunchProfile();
|
||||
scheduleSave();
|
||||
|
@ -141,24 +141,6 @@ bool saveJsonFile(const QJsonDocument doc, const QString & filename)
|
||||
return true;
|
||||
}
|
||||
|
||||
VersionFilePtr parseBinaryJsonFile(const QFileInfo &fileInfo)
|
||||
{
|
||||
QFile file(fileInfo.absoluteFilePath());
|
||||
if (!file.open(QFile::ReadOnly))
|
||||
{
|
||||
auto errorStr = QObject::tr("Unable to open the version file %1: %2.").arg(fileInfo.fileName(), file.errorString());
|
||||
return createErrorVersionFile(fileInfo.completeBaseName(), fileInfo.absoluteFilePath(), errorStr);
|
||||
}
|
||||
QJsonDocument doc = QJsonDocument::fromBinaryData(file.readAll());
|
||||
file.close();
|
||||
if (doc.isNull())
|
||||
{
|
||||
file.remove();
|
||||
throw JSONValidationError(QObject::tr("Unable to process the version file %1.").arg(fileInfo.fileName()));
|
||||
}
|
||||
return guardedParseJson(doc, fileInfo.completeBaseName(), fileInfo.absoluteFilePath(), false);
|
||||
}
|
||||
|
||||
void removeLwjglFromPatch(VersionFilePtr patch)
|
||||
{
|
||||
auto filter = [](QList<LibraryPtr>& libs)
|
||||
|
@ -19,9 +19,6 @@ VersionFilePtr parseJsonFile(const QFileInfo &fileInfo, const bool requireOrder)
|
||||
/// Save a JSON file (in any format)
|
||||
bool saveJsonFile(const QJsonDocument doc, const QString & filename);
|
||||
|
||||
/// Parse a version file in binary JSON format
|
||||
VersionFilePtr parseBinaryJsonFile(const QFileInfo &fileInfo);
|
||||
|
||||
/// Remove LWJGL from a patch file. This is applied to all Mojang-like profile files.
|
||||
void removeLwjglFromPatch(VersionFilePtr patch);
|
||||
|
||||
|
@ -195,7 +195,7 @@ QVariant WorldList::data(const QModelIndex &index, int role) const
|
||||
switch (column)
|
||||
{
|
||||
case SizeColumn:
|
||||
return qVariantFromValue<qlonglong>(world.bytes());
|
||||
return QVariant::fromValue<qlonglong>(world.bytes());
|
||||
|
||||
default:
|
||||
return data(index, Qt::DisplayRole);
|
||||
@ -215,7 +215,7 @@ QVariant WorldList::data(const QModelIndex &index, int role) const
|
||||
}
|
||||
case SeedRole:
|
||||
{
|
||||
return qVariantFromValue<qlonglong>(world.seed());
|
||||
return QVariant::fromValue<qlonglong>(world.seed());
|
||||
}
|
||||
case NameRole:
|
||||
{
|
||||
@ -227,7 +227,7 @@ QVariant WorldList::data(const QModelIndex &index, int role) const
|
||||
}
|
||||
case SizeRole:
|
||||
{
|
||||
return qVariantFromValue<qlonglong>(world.bytes());
|
||||
return QVariant::fromValue<qlonglong>(world.bytes());
|
||||
}
|
||||
case IconFileRole:
|
||||
{
|
||||
|
@ -116,9 +116,17 @@ bool ModFolderModel::update()
|
||||
|
||||
void ModFolderModel::finishUpdate()
|
||||
{
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
auto currentList = modsIndex.keys();
|
||||
QSet<QString> currentSet(currentList.begin(), currentList.end());
|
||||
auto & newMods = m_update->mods;
|
||||
auto newList = newMods.keys();
|
||||
QSet<QString> newSet(newList.begin(), newList.end());
|
||||
#else
|
||||
QSet<QString> currentSet = modsIndex.keys().toSet();
|
||||
auto & newMods = m_update->mods;
|
||||
QSet<QString> newSet = newMods.keys().toSet();
|
||||
#endif
|
||||
|
||||
// see if the kept mods changed in some way
|
||||
{
|
||||
|
@ -25,7 +25,7 @@ struct File
|
||||
bool resolved = false;
|
||||
QString fileName;
|
||||
QUrl url;
|
||||
QString targetFolder = QLatin1Literal("mods");
|
||||
QString targetFolder = QStringLiteral("mods");
|
||||
enum class Type
|
||||
{
|
||||
Unknown,
|
||||
|
@ -10,7 +10,13 @@ void PrivatePackManager::load()
|
||||
{
|
||||
try
|
||||
{
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
auto foo = QString::fromUtf8(FS::read(m_filename)).split('\n', Qt::SkipEmptyParts);
|
||||
currentPacks = QSet<QString>(foo.begin(), foo.end());
|
||||
#else
|
||||
currentPacks = QString::fromUtf8(FS::read(m_filename)).split('\n', QString::SkipEmptyParts).toSet();
|
||||
#endif
|
||||
|
||||
dirty = false;
|
||||
}
|
||||
catch(...)
|
||||
@ -28,7 +34,7 @@ void PrivatePackManager::save() const
|
||||
}
|
||||
try
|
||||
{
|
||||
QStringList list = currentPacks.toList();
|
||||
QStringList list = currentPacks.values();
|
||||
FS::write(m_filename, list.join('\n').toUtf8());
|
||||
dirty = false;
|
||||
}
|
||||
|
@ -97,7 +97,12 @@ auto NetJob::abort() -> bool
|
||||
bool fullyAborted = true;
|
||||
|
||||
// fail all downloads on the queue
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
QSet<int> todoSet(m_todo.begin(), m_todo.end());
|
||||
m_failed.unite(todoSet);
|
||||
#else
|
||||
m_failed.unite(m_todo.toSet());
|
||||
#endif
|
||||
m_todo.clear();
|
||||
|
||||
// abort active downloads
|
||||
|
@ -52,7 +52,7 @@
|
||||
|
||||
#include "Application.h"
|
||||
|
||||
const static QLatin1Literal defaultLangCode("en_US");
|
||||
const static QLatin1String defaultLangCode("en_US");
|
||||
|
||||
enum class FileType
|
||||
{
|
||||
@ -431,9 +431,7 @@ QVariant TranslationsModel::data(const QModelIndex& index, int role) const
|
||||
}
|
||||
case Column::Completeness:
|
||||
{
|
||||
QString text;
|
||||
text.sprintf("%3.1f %%", lang.percentTranslated());
|
||||
return text;
|
||||
return QString("%1%").arg(lang.percentTranslated(), 3, 'f', 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,31 +42,31 @@
|
||||
|
||||
#include "MainWindow.h"
|
||||
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtCore/QUrl>
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QFileInfo>
|
||||
#include <QVariant>
|
||||
#include <QUrl>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
|
||||
#include <QtGui/QKeyEvent>
|
||||
#include <QKeyEvent>
|
||||
#include <QAction>
|
||||
|
||||
#include <QtWidgets/QAction>
|
||||
#include <QtWidgets/QApplication>
|
||||
#include <QtWidgets/QButtonGroup>
|
||||
#include <QtWidgets/QHBoxLayout>
|
||||
#include <QtWidgets/QHeaderView>
|
||||
#include <QtWidgets/QMainWindow>
|
||||
#include <QtWidgets/QStatusBar>
|
||||
#include <QtWidgets/QToolBar>
|
||||
#include <QtWidgets/QWidget>
|
||||
#include <QtWidgets/QMenu>
|
||||
#include <QtWidgets/QMenuBar>
|
||||
#include <QtWidgets/QMessageBox>
|
||||
#include <QtWidgets/QInputDialog>
|
||||
#include <QtWidgets/QLabel>
|
||||
#include <QtWidgets/QToolButton>
|
||||
#include <QtWidgets/QWidgetAction>
|
||||
#include <QtWidgets/QProgressDialog>
|
||||
#include <QtWidgets/QShortcut>
|
||||
#include <QApplication>
|
||||
#include <QButtonGroup>
|
||||
#include <QHBoxLayout>
|
||||
#include <QHeaderView>
|
||||
#include <QMainWindow>
|
||||
#include <QStatusBar>
|
||||
#include <QToolBar>
|
||||
#include <QWidget>
|
||||
#include <QMenu>
|
||||
#include <QMenuBar>
|
||||
#include <QMessageBox>
|
||||
#include <QInputDialog>
|
||||
#include <QLabel>
|
||||
#include <QToolButton>
|
||||
#include <QWidgetAction>
|
||||
#include <QProgressDialog>
|
||||
#include <QShortcut>
|
||||
|
||||
#include <BaseInstance.h>
|
||||
#include <InstanceList.h>
|
||||
@ -1494,7 +1494,11 @@ void MainWindow::updateNotAvailable()
|
||||
|
||||
QList<int> stringToIntList(const QString &string)
|
||||
{
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
QStringList split = string.split(',', Qt::SkipEmptyParts);
|
||||
#else
|
||||
QStringList split = string.split(',', QString::SkipEmptyParts);
|
||||
#endif
|
||||
QList<int> out;
|
||||
for (int i = 0; i < split.size(); ++i)
|
||||
{
|
||||
|
@ -39,8 +39,14 @@ CopyInstanceDialog::CopyInstanceDialog(InstancePtr original, QWidget *parent)
|
||||
ui->iconButton->setIcon(APPLICATION->icons()->getIcon(InstIconKey));
|
||||
ui->instNameTextBox->setText(original->name());
|
||||
ui->instNameTextBox->setFocus();
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
auto groupList = APPLICATION->instances()->getGroups();
|
||||
QSet<QString> groups(groupList.begin(), groupList.end());
|
||||
groupList = QStringList(groups.values());
|
||||
#else
|
||||
auto groups = APPLICATION->instances()->getGroups().toSet();
|
||||
auto groupList = QStringList(groups.toList());
|
||||
#endif
|
||||
groupList.sort(Qt::CaseInsensitive);
|
||||
groupList.removeOne("");
|
||||
groupList.push_front("");
|
||||
|
@ -488,7 +488,11 @@ void ExportInstanceDialog::loadPackIgnore()
|
||||
}
|
||||
auto data = ignoreFile.readAll();
|
||||
auto string = QString::fromUtf8(data);
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
proxyModel->setBlockedPaths(string.split('\n', Qt::SkipEmptyParts));
|
||||
#else
|
||||
proxyModel->setBlockedPaths(string.split('\n', QString::SkipEmptyParts));
|
||||
#endif
|
||||
}
|
||||
|
||||
void ExportInstanceDialog::savePackIgnore()
|
||||
|
@ -46,7 +46,6 @@ NewComponentDialog::NewComponentDialog(const QString & initialName, const QStrin
|
||||
connect(ui->nameTextBox, &QLineEdit::textChanged, this, &NewComponentDialog::updateDialogState);
|
||||
connect(ui->uidTextBox, &QLineEdit::textChanged, this, &NewComponentDialog::updateDialogState);
|
||||
|
||||
auto groups = APPLICATION->instances()->getGroups().toSet();
|
||||
ui->nameTextBox->setFocus();
|
||||
|
||||
originalPlaceholderText = ui->uidTextBox->placeholderText();
|
||||
|
@ -54,8 +54,14 @@ NewInstanceDialog::NewInstanceDialog(const QString & initialGroup, const QString
|
||||
InstIconKey = "default";
|
||||
ui->iconButton->setIcon(APPLICATION->icons()->getIcon(InstIconKey));
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
auto groupList = APPLICATION->instances()->getGroups();
|
||||
auto groups = QSet<QString>(groupList.begin(), groupList.end());
|
||||
groupList = groups.values();
|
||||
#else
|
||||
auto groups = APPLICATION->instances()->getGroups().toSet();
|
||||
auto groupList = QStringList(groups.toList());
|
||||
#endif
|
||||
groupList.sort(Qt::CaseInsensitive);
|
||||
groupList.removeOne("");
|
||||
groupList.push_front(initialGroup);
|
||||
|
@ -24,7 +24,7 @@
|
||||
#include "InstanceView.h"
|
||||
#include "BaseInstance.h"
|
||||
#include "InstanceList.h"
|
||||
#include <xdgicon.h>
|
||||
#include <QIcon>
|
||||
#include <QTextEdit>
|
||||
|
||||
// Origin: Qt
|
||||
@ -61,7 +61,7 @@ void drawSelectionRect(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
painter->fillRect(rect, option.palette.brush(QPalette::Highlight));
|
||||
else
|
||||
{
|
||||
QColor backgroundColor = option.palette.color(QPalette::Background);
|
||||
QColor backgroundColor = option.palette.color(QPalette::Window);
|
||||
backgroundColor.setAlpha(160);
|
||||
painter->fillRect(rect, QBrush(backgroundColor));
|
||||
}
|
||||
@ -142,7 +142,7 @@ void drawBadges(QPainter *painter, const QStyleOptionViewItem &option, BaseInsta
|
||||
return;
|
||||
}
|
||||
// FIXME: inject this.
|
||||
auto icon = XdgIcon::fromTheme(it.next());
|
||||
auto icon = QIcon::fromTheme(it.next());
|
||||
// opt.icon.paint(painter, iconbox, Qt::AlignCenter, mode, state);
|
||||
const QPixmap pixmap;
|
||||
// itemSide
|
||||
|
@ -63,7 +63,7 @@ public:
|
||||
{
|
||||
case Qt::FontRole:
|
||||
return m_font;
|
||||
case Qt::TextColorRole:
|
||||
case Qt::ForegroundRole:
|
||||
{
|
||||
MessageLevel::Enum level = (MessageLevel::Enum) QIdentityProxyModel::data(index, LogModel::LevelRole).toInt();
|
||||
return m_colors->getFront(level);
|
||||
|
@ -270,7 +270,7 @@ ScreenshotsPage::ScreenshotsPage(QString path, QWidget *parent)
|
||||
ui->listView->setViewMode(QListView::IconMode);
|
||||
ui->listView->setResizeMode(QListView::Adjust);
|
||||
ui->listView->installEventFilter(this);
|
||||
ui->listView->setEditTriggers(0);
|
||||
ui->listView->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
ui->listView->setItemDelegate(new CenteredEditingDelegate(this));
|
||||
ui->listView->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(ui->listView, &QListView::customContextMenuRequested, this, &ScreenshotsPage::ShowContextMenu);
|
||||
|
@ -288,7 +288,11 @@ public:
|
||||
return false;
|
||||
}
|
||||
beginMoveRows(QModelIndex(), row, row, QModelIndex(), row - 1);
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
|
||||
m_servers.swapItemsAt(row-1, row);
|
||||
#else
|
||||
m_servers.swap(row-1, row);
|
||||
#endif
|
||||
endMoveRows();
|
||||
scheduleSave();
|
||||
return true;
|
||||
@ -306,7 +310,11 @@ public:
|
||||
return false;
|
||||
}
|
||||
beginMoveRows(QModelIndex(), row, row, QModelIndex(), row + 2);
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
|
||||
m_servers.swapItemsAt(row+1, row);
|
||||
#else
|
||||
m_servers.swap(row+1, row);
|
||||
#endif
|
||||
endMoveRows();
|
||||
scheduleSave();
|
||||
return true;
|
||||
|
@ -168,7 +168,7 @@ QVariant ListModel::data(const QModelIndex &index, int role) const
|
||||
((ListModel *)this)->requestLogo(pack.logo);
|
||||
return icon;
|
||||
}
|
||||
else if(role == Qt::TextColorRole)
|
||||
else if(role == Qt::ForegroundRole)
|
||||
{
|
||||
if(pack.broken)
|
||||
{
|
||||
|
@ -151,7 +151,7 @@ void Page::openedImpl()
|
||||
|
||||
ftbFetchTask->fetch();
|
||||
ftbPrivatePacks->load();
|
||||
ftbFetchTask->fetchPrivate(ftbPrivatePacks->getCurrentPackCodes().toList());
|
||||
ftbFetchTask->fetchPrivate(ftbPrivatePacks->getCurrentPackCodes().values());
|
||||
initialized = true;
|
||||
}
|
||||
suggestCurrent();
|
||||
|
@ -80,9 +80,7 @@ QSize LabeledToolButton::sizeHint() const
|
||||
if (popupMode() == MenuButtonPopup)
|
||||
w += style()->pixelMetric(QStyle::PM_MenuButtonIndicator, &opt, this);
|
||||
|
||||
QSize rawSize = style()->sizeFromContents(QStyle::CT_ToolButton, &opt, QSize(w, h), this);
|
||||
QSize sizeHint = rawSize.expandedTo(QApplication::globalStrut());
|
||||
return sizeHint;
|
||||
return style()->sizeFromContents(QStyle::CT_ToolButton, &opt, QSize(w, h), this);
|
||||
}
|
||||
|
||||
|
||||
|
@ -102,7 +102,7 @@ void LogView::rowsInserted(const QModelIndex& parent, int first, int last)
|
||||
{
|
||||
format.setFont(font.value<QFont>());
|
||||
}
|
||||
auto fg = m_model->data(idx, Qt::TextColorRole);
|
||||
auto fg = m_model->data(idx, Qt::ForegroundRole);
|
||||
if(fg.isValid())
|
||||
{
|
||||
format.setForeground(fg.value<QColor>());
|
||||
|
@ -171,7 +171,7 @@ void PageContainer::createUI()
|
||||
headerHLayout->addSpacerItem(new QSpacerItem(rightMargin, 0, QSizePolicy::Fixed, QSizePolicy::Ignored));
|
||||
headerHLayout->setContentsMargins(0, 6, 0, 0);
|
||||
|
||||
m_pageStack->setMargin(0);
|
||||
m_pageStack->setContentsMargins(0, 0, 0, 0);
|
||||
m_pageStack->addWidget(new QWidget(this));
|
||||
|
||||
m_layout = new QGridLayout;
|
||||
|
@ -136,7 +136,7 @@ void VersionListView::paintInfoLabel(QPaintEvent *event) const
|
||||
auto innerBounds = bounds;
|
||||
innerBounds.adjust(10, 10, -10, -10);
|
||||
|
||||
QColor background = QApplication::palette().color(QPalette::Foreground);
|
||||
QColor background = QApplication::palette().color(QPalette::WindowText);
|
||||
QColor foreground = QApplication::palette().color(QPalette::Base);
|
||||
foreground.setAlpha(190);
|
||||
painter.setFont(font);
|
||||
|
@ -46,6 +46,7 @@
|
||||
#include <QLocalServer>
|
||||
#include <QLocalSocket>
|
||||
#include <QDir>
|
||||
#include <QRegularExpression>
|
||||
#include "LockedFile.h"
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
@ -72,7 +73,7 @@ ApplicationId ApplicationId::fromTraditionalApp()
|
||||
protoId = protoId.toLower();
|
||||
#endif
|
||||
auto prefix = protoId.section(QLatin1Char('/'), -1);
|
||||
prefix.remove(QRegExp("[^a-zA-Z]"));
|
||||
prefix.remove(QRegularExpression("[^a-zA-Z]"));
|
||||
prefix.truncate(6);
|
||||
QByteArray idc = protoId.toUtf8();
|
||||
quint16 idNum = qChecksum(idc.constData(), idc.size());
|
||||
|
@ -1,20 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.9.4)
|
||||
project(iconfix)
|
||||
|
||||
find_package(Qt5Core REQUIRED QUIET)
|
||||
find_package(Qt5Widgets REQUIRED QUIET)
|
||||
|
||||
set(ICONFIX_SOURCES
|
||||
xdgicon.h
|
||||
xdgicon.cpp
|
||||
internal/qhexstring_p.h
|
||||
internal/qiconloader.cpp
|
||||
internal/qiconloader_p.h
|
||||
)
|
||||
|
||||
add_library(Launcher_iconfix STATIC ${ICONFIX_SOURCES})
|
||||
target_include_directories(Launcher_iconfix PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} "${CMAKE_CURRENT_BINARY_DIR}" )
|
||||
|
||||
target_link_libraries(Launcher_iconfix Qt5::Core Qt5::Widgets)
|
||||
|
||||
generate_export_header(Launcher_iconfix)
|
@ -1,100 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the QtGui module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
#include <QtCore/qpoint.h>
|
||||
#include <QtCore/qstring.h>
|
||||
#include <QtGui/qpolygon.h>
|
||||
#include <QtCore/qstringbuilder.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
// -------------
|
||||
//
|
||||
// This file is not part of the Qt API. It exists purely as an
|
||||
// implementation detail. This header file may change from version to
|
||||
// version without notice, or even be removed.
|
||||
//
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
// internal helper. Converts an integer value to an unique string token
|
||||
template <typename T> struct HexString
|
||||
{
|
||||
inline HexString(const T t) : val(t)
|
||||
{
|
||||
}
|
||||
|
||||
inline void write(QChar *&dest) const
|
||||
{
|
||||
const ushort hexChars[] = {'0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
||||
const char *c = reinterpret_cast<const char *>(&val);
|
||||
for (uint i = 0; i < sizeof(T); ++i)
|
||||
{
|
||||
*dest++ = hexChars[*c & 0xf];
|
||||
*dest++ = hexChars[(*c & 0xf0) >> 4];
|
||||
++c;
|
||||
}
|
||||
}
|
||||
const T val;
|
||||
};
|
||||
|
||||
// specialization to enable fast concatenating of our string tokens to a string
|
||||
template <typename T> struct QConcatenable<HexString<T>>
|
||||
{
|
||||
typedef HexString<T> type;
|
||||
enum
|
||||
{
|
||||
ExactSize = true
|
||||
};
|
||||
static int size(const HexString<T> &)
|
||||
{
|
||||
return sizeof(T) * 2;
|
||||
}
|
||||
static inline void appendTo(const HexString<T> &str, QChar *&out)
|
||||
{
|
||||
str.write(out);
|
||||
}
|
||||
typedef QString ConvertTo;
|
||||
};
|
@ -1,688 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the QtGui module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL21$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 or version 3 as published by the Free
|
||||
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
||||
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
||||
** following information to ensure the GNU Lesser General Public License
|
||||
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
#include "qiconloader_p.h"
|
||||
|
||||
#include <QtGui/QIconEnginePlugin>
|
||||
#include <QtGui/QPixmapCache>
|
||||
#include <QtGui/QIconEngine>
|
||||
#include <QtGui/QPalette>
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QHash>
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QSettings>
|
||||
#include <QtGui/QPainter>
|
||||
#include <QApplication>
|
||||
#include <QLatin1Literal>
|
||||
|
||||
#include "qhexstring_p.h"
|
||||
|
||||
namespace QtXdg
|
||||
{
|
||||
|
||||
Q_GLOBAL_STATIC(QIconLoader, iconLoaderInstance)
|
||||
|
||||
/* Theme to use in last resort, if the theme does not have the icon, neither the parents */
|
||||
|
||||
static QString fallbackTheme()
|
||||
{
|
||||
return QString("hicolor");
|
||||
}
|
||||
|
||||
QIconLoader::QIconLoader() : m_themeKey(1), m_supportsSvg(false), m_initialized(false)
|
||||
{
|
||||
}
|
||||
|
||||
// We lazily initialize the loader to make static icons
|
||||
// work. Though we do not officially support this.
|
||||
|
||||
static inline QString systemThemeName()
|
||||
{
|
||||
return QIcon::themeName();
|
||||
}
|
||||
|
||||
static inline QStringList systemIconSearchPaths()
|
||||
{
|
||||
auto paths = QIcon::themeSearchPaths();
|
||||
paths.push_front(":/icons");
|
||||
return paths;
|
||||
}
|
||||
|
||||
void QIconLoader::ensureInitialized()
|
||||
{
|
||||
if (!m_initialized)
|
||||
{
|
||||
m_initialized = true;
|
||||
|
||||
Q_ASSERT(qApp);
|
||||
|
||||
m_systemTheme = QIcon::themeName();
|
||||
|
||||
if (m_systemTheme.isEmpty())
|
||||
m_systemTheme = fallbackTheme();
|
||||
m_supportsSvg = true;
|
||||
}
|
||||
}
|
||||
|
||||
QIconLoader *QIconLoader::instance()
|
||||
{
|
||||
iconLoaderInstance()->ensureInitialized();
|
||||
return iconLoaderInstance();
|
||||
}
|
||||
|
||||
// Queries the system theme and invalidates existing
|
||||
// icons if the theme has changed.
|
||||
void QIconLoader::updateSystemTheme()
|
||||
{
|
||||
// Only change if this is not explicitly set by the user
|
||||
if (m_userTheme.isEmpty())
|
||||
{
|
||||
QString theme = systemThemeName();
|
||||
if (theme.isEmpty())
|
||||
theme = fallbackTheme();
|
||||
if (theme != m_systemTheme)
|
||||
{
|
||||
m_systemTheme = theme;
|
||||
invalidateKey();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QIconLoader::setThemeName(const QString &themeName)
|
||||
{
|
||||
m_userTheme = themeName;
|
||||
invalidateKey();
|
||||
}
|
||||
|
||||
void QIconLoader::setThemeSearchPath(const QStringList &searchPaths)
|
||||
{
|
||||
m_iconDirs = searchPaths;
|
||||
themeList.clear();
|
||||
invalidateKey();
|
||||
}
|
||||
|
||||
QStringList QIconLoader::themeSearchPaths() const
|
||||
{
|
||||
if (m_iconDirs.isEmpty())
|
||||
{
|
||||
m_iconDirs = systemIconSearchPaths();
|
||||
}
|
||||
return m_iconDirs;
|
||||
}
|
||||
|
||||
QIconTheme::QIconTheme(const QString &themeName) : m_valid(false)
|
||||
{
|
||||
QFile themeIndex;
|
||||
|
||||
QStringList iconDirs = systemIconSearchPaths();
|
||||
for (int i = 0; i < iconDirs.size(); ++i)
|
||||
{
|
||||
QDir iconDir(iconDirs[i]);
|
||||
QString themeDir = iconDir.path() + QLatin1Char('/') + themeName;
|
||||
themeIndex.setFileName(themeDir + QLatin1String("/index.theme"));
|
||||
if (themeIndex.exists())
|
||||
{
|
||||
m_contentDir = themeDir;
|
||||
m_valid = true;
|
||||
|
||||
foreach (QString path, iconDirs)
|
||||
{
|
||||
if (QFileInfo(path).isDir())
|
||||
m_contentDirs.append(path + QLatin1Char('/') + themeName);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// if there is no index file, abscond.
|
||||
if (!themeIndex.exists())
|
||||
return;
|
||||
|
||||
// otherwise continue reading index file
|
||||
const QSettings indexReader(themeIndex.fileName(), QSettings::IniFormat);
|
||||
QStringListIterator keyIterator(indexReader.allKeys());
|
||||
while (keyIterator.hasNext())
|
||||
{
|
||||
const QString key = keyIterator.next();
|
||||
if (!key.endsWith(QLatin1String("/Size")))
|
||||
continue;
|
||||
|
||||
// Note the QSettings ini-format does not accept
|
||||
// slashes in key names, hence we have to cheat
|
||||
int size = indexReader.value(key).toInt();
|
||||
if (!size)
|
||||
continue;
|
||||
|
||||
QString directoryKey = key.left(key.size() - 5);
|
||||
QIconDirInfo dirInfo(directoryKey);
|
||||
dirInfo.size = size;
|
||||
QString type =
|
||||
indexReader.value(directoryKey + QLatin1String("/Type")).toString();
|
||||
|
||||
if (type == QLatin1String("Fixed"))
|
||||
dirInfo.type = QIconDirInfo::Fixed;
|
||||
else if (type == QLatin1String("Scalable"))
|
||||
dirInfo.type = QIconDirInfo::Scalable;
|
||||
else
|
||||
dirInfo.type = QIconDirInfo::Threshold;
|
||||
|
||||
dirInfo.threshold =
|
||||
indexReader.value(directoryKey + QLatin1String("/Threshold"), 2)
|
||||
.toInt();
|
||||
|
||||
dirInfo.minSize =
|
||||
indexReader.value(directoryKey + QLatin1String("/MinSize"), size)
|
||||
.toInt();
|
||||
|
||||
dirInfo.maxSize =
|
||||
indexReader.value(directoryKey + QLatin1String("/MaxSize"), size)
|
||||
.toInt();
|
||||
m_keyList.append(dirInfo);
|
||||
}
|
||||
|
||||
// Parent themes provide fallbacks for missing icons
|
||||
m_parents = indexReader.value(QLatin1String("Icon Theme/Inherits")).toStringList();
|
||||
m_parents.removeAll(QString());
|
||||
|
||||
// Ensure a default platform fallback for all themes
|
||||
if (m_parents.isEmpty())
|
||||
{
|
||||
const QString fallback = fallbackTheme();
|
||||
if (!fallback.isEmpty())
|
||||
m_parents.append(fallback);
|
||||
}
|
||||
|
||||
// Ensure that all themes fall back to hicolor
|
||||
if (!m_parents.contains(QLatin1String("hicolor")))
|
||||
m_parents.append(QLatin1String("hicolor"));
|
||||
}
|
||||
|
||||
QThemeIconEntries QIconLoader::findIconHelper(const QString &themeName, const QString &iconName,
|
||||
QStringList &visited) const
|
||||
{
|
||||
QThemeIconEntries entries;
|
||||
Q_ASSERT(!themeName.isEmpty());
|
||||
|
||||
QPixmap pixmap;
|
||||
|
||||
// Used to protect against potential recursions
|
||||
visited << themeName;
|
||||
|
||||
QIconTheme theme = themeList.value(themeName);
|
||||
if (!theme.isValid())
|
||||
{
|
||||
theme = QIconTheme(themeName);
|
||||
if (!theme.isValid())
|
||||
theme = QIconTheme(fallbackTheme());
|
||||
|
||||
themeList.insert(themeName, theme);
|
||||
}
|
||||
|
||||
QStringList contentDirs = theme.contentDirs();
|
||||
const QVector<QIconDirInfo> subDirs = theme.keyList();
|
||||
|
||||
const QString svgext(QLatin1String(".svg"));
|
||||
const QString pngext(QLatin1String(".png"));
|
||||
const QString xpmext(QLatin1String(".xpm"));
|
||||
|
||||
// Add all relevant files
|
||||
for (int i = 0; i < subDirs.size(); ++i)
|
||||
{
|
||||
const QIconDirInfo &dirInfo = subDirs.at(i);
|
||||
QString subdir = dirInfo.path;
|
||||
|
||||
foreach (QString contentDir, contentDirs)
|
||||
{
|
||||
QDir currentDir(contentDir + '/' + subdir);
|
||||
|
||||
if (currentDir.exists(iconName + pngext))
|
||||
{
|
||||
PixmapEntry *iconEntry = new PixmapEntry;
|
||||
iconEntry->dir = dirInfo;
|
||||
iconEntry->filename = currentDir.filePath(iconName + pngext);
|
||||
// Notice we ensure that pixmap entries always come before
|
||||
// scalable to preserve search order afterwards
|
||||
entries.prepend(iconEntry);
|
||||
}
|
||||
else if (m_supportsSvg && currentDir.exists(iconName + svgext))
|
||||
{
|
||||
ScalableEntry *iconEntry = new ScalableEntry;
|
||||
iconEntry->dir = dirInfo;
|
||||
iconEntry->filename = currentDir.filePath(iconName + svgext);
|
||||
entries.append(iconEntry);
|
||||
break;
|
||||
}
|
||||
else if (currentDir.exists(iconName + xpmext))
|
||||
{
|
||||
PixmapEntry *iconEntry = new PixmapEntry;
|
||||
iconEntry->dir = dirInfo;
|
||||
iconEntry->filename = currentDir.filePath(iconName + xpmext);
|
||||
// Notice we ensure that pixmap entries always come before
|
||||
// scalable to preserve search order afterwards
|
||||
entries.append(iconEntry);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (entries.isEmpty())
|
||||
{
|
||||
const QStringList parents = theme.parents();
|
||||
// Search recursively through inherited themes
|
||||
for (int i = 0; i < parents.size(); ++i)
|
||||
{
|
||||
|
||||
const QString parentTheme = parents.at(i).trimmed();
|
||||
|
||||
if (!visited.contains(parentTheme)) // guard against recursion
|
||||
entries = findIconHelper(parentTheme, iconName, visited);
|
||||
|
||||
if (!entries.isEmpty()) // success
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
Author: Kaitlin Rupert <kaitlin.rupert@intel.com>
|
||||
Date: Aug 12, 2010
|
||||
Description: Make it so that the QIcon loader honors /usr/share/pixmaps
|
||||
directory. This is a valid directory per the Freedesktop.org
|
||||
icon theme specification.
|
||||
Bug: https://bugreports.qt.nokia.com/browse/QTBUG-12874
|
||||
*********************************************************************/
|
||||
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
|
||||
/* Freedesktop standard says to look in /usr/share/pixmaps last */
|
||||
if (entries.isEmpty())
|
||||
{
|
||||
const QString pixmaps(QLatin1String("/usr/share/pixmaps"));
|
||||
|
||||
QDir currentDir(pixmaps);
|
||||
QIconDirInfo dirInfo(pixmaps);
|
||||
if (currentDir.exists(iconName + pngext))
|
||||
{
|
||||
PixmapEntry *iconEntry = new PixmapEntry;
|
||||
iconEntry->dir = dirInfo;
|
||||
iconEntry->filename = currentDir.filePath(iconName + pngext);
|
||||
// Notice we ensure that pixmap entries always come before
|
||||
// scalable to preserve search order afterwards
|
||||
entries.prepend(iconEntry);
|
||||
}
|
||||
else if (m_supportsSvg && currentDir.exists(iconName + svgext))
|
||||
{
|
||||
ScalableEntry *iconEntry = new ScalableEntry;
|
||||
iconEntry->dir = dirInfo;
|
||||
iconEntry->filename = currentDir.filePath(iconName + svgext);
|
||||
entries.append(iconEntry);
|
||||
}
|
||||
else if (currentDir.exists(iconName + xpmext))
|
||||
{
|
||||
PixmapEntry *iconEntry = new PixmapEntry;
|
||||
iconEntry->dir = dirInfo;
|
||||
iconEntry->filename = currentDir.filePath(iconName + xpmext);
|
||||
// Notice we ensure that pixmap entries always come before
|
||||
// scalable to preserve search order afterwards
|
||||
entries.append(iconEntry);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (entries.isEmpty())
|
||||
{
|
||||
// Search for unthemed icons in main dir of search paths
|
||||
QStringList themeSearchPaths = QIcon::themeSearchPaths();
|
||||
foreach (QString contentDir, themeSearchPaths)
|
||||
{
|
||||
QDir currentDir(contentDir);
|
||||
|
||||
if (currentDir.exists(iconName + pngext))
|
||||
{
|
||||
PixmapEntry *iconEntry = new PixmapEntry;
|
||||
iconEntry->filename = currentDir.filePath(iconName + pngext);
|
||||
// Notice we ensure that pixmap entries always come before
|
||||
// scalable to preserve search order afterwards
|
||||
entries.prepend(iconEntry);
|
||||
}
|
||||
else if (m_supportsSvg && currentDir.exists(iconName + svgext))
|
||||
{
|
||||
ScalableEntry *iconEntry = new ScalableEntry;
|
||||
iconEntry->filename = currentDir.filePath(iconName + svgext);
|
||||
entries.append(iconEntry);
|
||||
break;
|
||||
}
|
||||
else if (currentDir.exists(iconName + xpmext))
|
||||
{
|
||||
PixmapEntry *iconEntry = new PixmapEntry;
|
||||
iconEntry->filename = currentDir.filePath(iconName + xpmext);
|
||||
// Notice we ensure that pixmap entries always come before
|
||||
// scalable to preserve search order afterwards
|
||||
entries.append(iconEntry);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
QThemeIconEntries QIconLoader::loadIcon(const QString &name) const
|
||||
{
|
||||
if (!themeName().isEmpty())
|
||||
{
|
||||
QStringList visited;
|
||||
return findIconHelper(themeName(), name, visited);
|
||||
}
|
||||
|
||||
return QThemeIconEntries();
|
||||
}
|
||||
|
||||
// -------- Icon Loader Engine -------- //
|
||||
|
||||
QIconLoaderEngineFixed::QIconLoaderEngineFixed(const QString &iconName)
|
||||
: m_iconName(iconName), m_key(0)
|
||||
{
|
||||
}
|
||||
|
||||
QIconLoaderEngineFixed::~QIconLoaderEngineFixed()
|
||||
{
|
||||
qDeleteAll(m_entries);
|
||||
}
|
||||
|
||||
QIconLoaderEngineFixed::QIconLoaderEngineFixed(const QIconLoaderEngineFixed &other)
|
||||
: QIconEngine(other), m_iconName(other.m_iconName), m_key(0)
|
||||
{
|
||||
}
|
||||
|
||||
QIconEngine *QIconLoaderEngineFixed::clone() const
|
||||
{
|
||||
return new QIconLoaderEngineFixed(*this);
|
||||
}
|
||||
|
||||
bool QIconLoaderEngineFixed::read(QDataStream &in)
|
||||
{
|
||||
in >> m_iconName;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool QIconLoaderEngineFixed::write(QDataStream &out) const
|
||||
{
|
||||
out << m_iconName;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool QIconLoaderEngineFixed::hasIcon() const
|
||||
{
|
||||
return !(m_entries.isEmpty());
|
||||
}
|
||||
|
||||
// Lazily load the icon
|
||||
void QIconLoaderEngineFixed::ensureLoaded()
|
||||
{
|
||||
if (!(QIconLoader::instance()->themeKey() == m_key))
|
||||
{
|
||||
|
||||
qDeleteAll(m_entries);
|
||||
|
||||
m_entries = QIconLoader::instance()->loadIcon(m_iconName);
|
||||
m_key = QIconLoader::instance()->themeKey();
|
||||
}
|
||||
}
|
||||
|
||||
void QIconLoaderEngineFixed::paint(QPainter *painter, const QRect &rect, QIcon::Mode mode,
|
||||
QIcon::State state)
|
||||
{
|
||||
QSize pixmapSize = rect.size();
|
||||
#if defined(Q_WS_MAC)
|
||||
pixmapSize *= qt_mac_get_scalefactor();
|
||||
#endif
|
||||
painter->drawPixmap(rect, pixmap(pixmapSize, mode, state));
|
||||
}
|
||||
|
||||
/*
|
||||
* This algorithm is defined by the freedesktop spec:
|
||||
* http://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html
|
||||
*/
|
||||
static bool directoryMatchesSize(const QIconDirInfo &dir, int iconsize)
|
||||
{
|
||||
if (dir.type == QIconDirInfo::Fixed)
|
||||
{
|
||||
return dir.size == iconsize;
|
||||
}
|
||||
else if (dir.type == QIconDirInfo::Scalable)
|
||||
{
|
||||
return dir.size <= dir.maxSize && iconsize >= dir.minSize;
|
||||
}
|
||||
else if (dir.type == QIconDirInfo::Threshold)
|
||||
{
|
||||
return iconsize >= dir.size - dir.threshold && iconsize <= dir.size + dir.threshold;
|
||||
}
|
||||
|
||||
Q_ASSERT(1); // Not a valid value
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* This algorithm is defined by the freedesktop spec:
|
||||
* http://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html
|
||||
*/
|
||||
static int directorySizeDistance(const QIconDirInfo &dir, int iconsize)
|
||||
{
|
||||
if (dir.type == QIconDirInfo::Fixed)
|
||||
{
|
||||
return qAbs(dir.size - iconsize);
|
||||
}
|
||||
else if (dir.type == QIconDirInfo::Scalable)
|
||||
{
|
||||
if (iconsize < dir.minSize)
|
||||
return dir.minSize - iconsize;
|
||||
else if (iconsize > dir.maxSize)
|
||||
return iconsize - dir.maxSize;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
else if (dir.type == QIconDirInfo::Threshold)
|
||||
{
|
||||
if (iconsize < dir.size - dir.threshold)
|
||||
return dir.minSize - iconsize;
|
||||
else if (iconsize > dir.size + dir.threshold)
|
||||
return iconsize - dir.maxSize;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
Q_ASSERT(1); // Not a valid value
|
||||
return INT_MAX;
|
||||
}
|
||||
|
||||
QIconLoaderEngineEntry *QIconLoaderEngineFixed::entryForSize(const QSize &size)
|
||||
{
|
||||
int iconsize = qMin(size.width(), size.height());
|
||||
|
||||
// Note that m_entries are sorted so that png-files
|
||||
// come first
|
||||
|
||||
const int numEntries = m_entries.size();
|
||||
|
||||
// Search for exact matches first
|
||||
for (int i = 0; i < numEntries; ++i)
|
||||
{
|
||||
QIconLoaderEngineEntry *entry = m_entries.at(i);
|
||||
if (directoryMatchesSize(entry->dir, iconsize))
|
||||
{
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
|
||||
// Find the minimum distance icon
|
||||
int minimalSize = INT_MAX;
|
||||
QIconLoaderEngineEntry *closestMatch = 0;
|
||||
for (int i = 0; i < numEntries; ++i)
|
||||
{
|
||||
QIconLoaderEngineEntry *entry = m_entries.at(i);
|
||||
int distance = directorySizeDistance(entry->dir, iconsize);
|
||||
if (distance < minimalSize)
|
||||
{
|
||||
minimalSize = distance;
|
||||
closestMatch = entry;
|
||||
}
|
||||
}
|
||||
return closestMatch;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the actual icon size. For scalable svg's this is equivalent
|
||||
* to the requested size. Otherwise the closest match is returned but
|
||||
* we can never return a bigger size than the requested size.
|
||||
*
|
||||
*/
|
||||
QSize QIconLoaderEngineFixed::actualSize(const QSize &size, QIcon::Mode mode,
|
||||
QIcon::State state)
|
||||
{
|
||||
ensureLoaded();
|
||||
|
||||
QIconLoaderEngineEntry *entry = entryForSize(size);
|
||||
if (entry)
|
||||
{
|
||||
const QIconDirInfo &dir = entry->dir;
|
||||
if (dir.type == QIconDirInfo::Scalable)
|
||||
return size;
|
||||
else
|
||||
{
|
||||
int result = qMin<int>(dir.size, qMin(size.width(), size.height()));
|
||||
return QSize(result, result);
|
||||
}
|
||||
}
|
||||
return QIconEngine::actualSize(size, mode, state);
|
||||
}
|
||||
|
||||
QPixmap PixmapEntry::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state)
|
||||
{
|
||||
Q_UNUSED(state);
|
||||
|
||||
// Ensure that basePixmap is lazily initialized before generating the
|
||||
// key, otherwise the cache key is not unique
|
||||
if (basePixmap.isNull())
|
||||
basePixmap.load(filename);
|
||||
|
||||
QSize actualSize = basePixmap.size();
|
||||
if (!actualSize.isNull() &&
|
||||
(actualSize.width() > size.width() || actualSize.height() > size.height()))
|
||||
actualSize.scale(size, Qt::KeepAspectRatio);
|
||||
|
||||
QString key = QLatin1String("$qt_theme_") % HexString<qint64>(basePixmap.cacheKey()) %
|
||||
HexString<int>(mode) %
|
||||
HexString<qint64>(QGuiApplication::palette().cacheKey()) %
|
||||
HexString<int>(actualSize.width()) % HexString<int>(actualSize.height());
|
||||
|
||||
QPixmap cachedPixmap;
|
||||
if (QPixmapCache::find(key, &cachedPixmap))
|
||||
{
|
||||
return cachedPixmap;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (basePixmap.size() != actualSize)
|
||||
{
|
||||
cachedPixmap = basePixmap.scaled(actualSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
}
|
||||
else
|
||||
{
|
||||
cachedPixmap = basePixmap;
|
||||
}
|
||||
QPixmapCache::insert(key, cachedPixmap);
|
||||
}
|
||||
return cachedPixmap;
|
||||
}
|
||||
|
||||
QPixmap ScalableEntry::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state)
|
||||
{
|
||||
if (svgIcon.isNull())
|
||||
{
|
||||
svgIcon = QIcon(filename);
|
||||
}
|
||||
|
||||
// Simply reuse svg icon engine
|
||||
return svgIcon.pixmap(size, mode, state);
|
||||
}
|
||||
|
||||
QPixmap QIconLoaderEngineFixed::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state)
|
||||
{
|
||||
ensureLoaded();
|
||||
|
||||
QIconLoaderEngineEntry *entry = entryForSize(size);
|
||||
if (entry)
|
||||
{
|
||||
return entry->pixmap(size, mode, state);
|
||||
}
|
||||
|
||||
return QPixmap();
|
||||
}
|
||||
|
||||
QString QIconLoaderEngineFixed::key() const
|
||||
{
|
||||
return QLatin1String("QIconLoaderEngineFixed");
|
||||
}
|
||||
|
||||
void QIconLoaderEngineFixed::virtual_hook(int id, void *data)
|
||||
{
|
||||
ensureLoaded();
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case QIconEngine::AvailableSizesHook:
|
||||
{
|
||||
QIconEngine::AvailableSizesArgument &arg =
|
||||
*reinterpret_cast<QIconEngine::AvailableSizesArgument *>(data);
|
||||
const int N = m_entries.size();
|
||||
QList<QSize> sizes;
|
||||
sizes.reserve(N);
|
||||
|
||||
// Gets all sizes from the DirectoryInfo entries
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
int size = m_entries.at(i)->dir.size;
|
||||
sizes.append(QSize(size, size));
|
||||
}
|
||||
arg.sizes.swap(sizes); // commit
|
||||
}
|
||||
break;
|
||||
case QIconEngine::IconNameHook:
|
||||
{
|
||||
QString &name = *reinterpret_cast<QString *>(data);
|
||||
name = m_iconName;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
QIconEngine::virtual_hook(id, data);
|
||||
}
|
||||
}
|
||||
|
||||
} // QtXdg
|
@ -1,219 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the QtGui module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL21$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 or version 3 as published by the Free
|
||||
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
||||
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
||||
** following information to ensure the GNU Lesser General Public License
|
||||
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
// -------------
|
||||
//
|
||||
// This file is not part of the Qt API. It exists purely as an
|
||||
// implementation detail. This header file may change from version to
|
||||
// version without notice, or even be removed.
|
||||
//
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
#include <QtGui/QIcon>
|
||||
#include <QtGui/QIconEngine>
|
||||
#include <QtGui/QPixmapCache>
|
||||
#include <QtCore/QHash>
|
||||
#include <QtCore/QVector>
|
||||
#include <QtCore/QTypeInfo>
|
||||
|
||||
|
||||
namespace QtXdg
|
||||
{
|
||||
|
||||
class QIconLoader;
|
||||
|
||||
struct QIconDirInfo
|
||||
{
|
||||
enum Type
|
||||
{
|
||||
Fixed,
|
||||
Scalable,
|
||||
Threshold
|
||||
};
|
||||
QIconDirInfo(const QString &_path = QString())
|
||||
: path(_path), size(0), maxSize(0), minSize(0), threshold(0), type(Threshold)
|
||||
{
|
||||
}
|
||||
QString path;
|
||||
short size;
|
||||
short maxSize;
|
||||
short minSize;
|
||||
short threshold;
|
||||
Type type : 4;
|
||||
};
|
||||
|
||||
class QIconLoaderEngineEntry
|
||||
{
|
||||
public:
|
||||
virtual ~QIconLoaderEngineEntry()
|
||||
{
|
||||
}
|
||||
virtual QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) = 0;
|
||||
QString filename;
|
||||
QIconDirInfo dir;
|
||||
static int count;
|
||||
};
|
||||
|
||||
struct ScalableEntry : public QIconLoaderEngineEntry
|
||||
{
|
||||
QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) Q_DECL_OVERRIDE;
|
||||
QIcon svgIcon;
|
||||
};
|
||||
|
||||
struct PixmapEntry : public QIconLoaderEngineEntry
|
||||
{
|
||||
QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) Q_DECL_OVERRIDE;
|
||||
QPixmap basePixmap;
|
||||
};
|
||||
|
||||
typedef QList<QIconLoaderEngineEntry *> QThemeIconEntries;
|
||||
|
||||
// class QIconLoaderEngine : public QIconEngine
|
||||
class QIconLoaderEngineFixed : public QIconEngine
|
||||
{
|
||||
public:
|
||||
QIconLoaderEngineFixed(const QString &iconName = QString());
|
||||
~QIconLoaderEngineFixed();
|
||||
|
||||
void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state);
|
||||
QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state);
|
||||
QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state);
|
||||
QIconEngine *clone() const;
|
||||
bool read(QDataStream &in);
|
||||
bool write(QDataStream &out) const;
|
||||
|
||||
private:
|
||||
QString key() const;
|
||||
bool hasIcon() const;
|
||||
void ensureLoaded();
|
||||
void virtual_hook(int id, void *data);
|
||||
QIconLoaderEngineEntry *entryForSize(const QSize &size);
|
||||
QIconLoaderEngineFixed(const QIconLoaderEngineFixed &other);
|
||||
QThemeIconEntries m_entries;
|
||||
QString m_iconName;
|
||||
uint m_key;
|
||||
|
||||
friend class QIconLoader;
|
||||
};
|
||||
|
||||
class QIconTheme
|
||||
{
|
||||
public:
|
||||
QIconTheme(const QString &name);
|
||||
QIconTheme() : m_valid(false)
|
||||
{
|
||||
}
|
||||
QStringList parents()
|
||||
{
|
||||
return m_parents;
|
||||
}
|
||||
QVector<QIconDirInfo> keyList()
|
||||
{
|
||||
return m_keyList;
|
||||
}
|
||||
QString contentDir()
|
||||
{
|
||||
return m_contentDir;
|
||||
}
|
||||
QStringList contentDirs()
|
||||
{
|
||||
return m_contentDirs;
|
||||
}
|
||||
bool isValid()
|
||||
{
|
||||
return m_valid;
|
||||
}
|
||||
|
||||
private:
|
||||
QString m_contentDir;
|
||||
QStringList m_contentDirs;
|
||||
QVector<QIconDirInfo> m_keyList;
|
||||
QStringList m_parents;
|
||||
bool m_valid;
|
||||
};
|
||||
|
||||
class QIconLoader
|
||||
{
|
||||
public:
|
||||
QIconLoader();
|
||||
QThemeIconEntries loadIcon(const QString &iconName) const;
|
||||
uint themeKey() const
|
||||
{
|
||||
return m_themeKey;
|
||||
}
|
||||
|
||||
QString themeName() const
|
||||
{
|
||||
return m_userTheme.isEmpty() ? m_systemTheme : m_userTheme;
|
||||
}
|
||||
void setThemeName(const QString &themeName);
|
||||
QIconTheme theme()
|
||||
{
|
||||
return themeList.value(themeName());
|
||||
}
|
||||
void setThemeSearchPath(const QStringList &searchPaths);
|
||||
QStringList themeSearchPaths() const;
|
||||
QIconDirInfo dirInfo(int dirindex);
|
||||
static QIconLoader *instance();
|
||||
void updateSystemTheme();
|
||||
void invalidateKey()
|
||||
{
|
||||
m_themeKey++;
|
||||
}
|
||||
void ensureInitialized();
|
||||
|
||||
private:
|
||||
QThemeIconEntries findIconHelper(const QString &themeName, const QString &iconName,
|
||||
QStringList &visited) const;
|
||||
uint m_themeKey;
|
||||
bool m_supportsSvg;
|
||||
bool m_initialized;
|
||||
|
||||
mutable QString m_userTheme;
|
||||
mutable QString m_systemTheme;
|
||||
mutable QStringList m_iconDirs;
|
||||
mutable QHash<QString, QIconTheme> themeList;
|
||||
};
|
||||
|
||||
} // QtXdg
|
||||
|
||||
// Note: class template specialization of 'QTypeInfo' must occur at
|
||||
// global scope
|
||||
Q_DECLARE_TYPEINFO(QtXdg::QIconDirInfo, Q_MOVABLE_TYPE);
|
@ -1,152 +0,0 @@
|
||||
/* BEGIN_COMMON_COPYRIGHT_HEADER
|
||||
* (c)LGPL2+
|
||||
*
|
||||
* Razor - a lightweight, Qt based, desktop toolset
|
||||
* http://razor-qt.org
|
||||
*
|
||||
* Copyright: 2010-2011 Razor team
|
||||
* Authors:
|
||||
* Alexander Sokoloff <sokoloff.a@gmail.com>
|
||||
*
|
||||
* This program or library is free software; you can redistribute it
|
||||
* and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Lesser General
|
||||
* Public License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
* END_COMMON_COPYRIGHT_HEADER */
|
||||
|
||||
#include "xdgicon.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QStringList>
|
||||
#include <QFileInfo>
|
||||
#include <QCache>
|
||||
#include "internal/qiconloader_p.h"
|
||||
#include <QCoreApplication>
|
||||
|
||||
/************************************************
|
||||
|
||||
************************************************/
|
||||
static void qt_cleanup_icon_cache();
|
||||
typedef QCache<QString, QIcon> IconCache;
|
||||
|
||||
namespace
|
||||
{
|
||||
struct QtIconCache : public IconCache
|
||||
{
|
||||
QtIconCache()
|
||||
{
|
||||
qAddPostRoutine(qt_cleanup_icon_cache);
|
||||
}
|
||||
};
|
||||
}
|
||||
Q_GLOBAL_STATIC(IconCache, qtIconCache)
|
||||
|
||||
static void qt_cleanup_icon_cache()
|
||||
{
|
||||
qtIconCache()->clear();
|
||||
}
|
||||
|
||||
/************************************************
|
||||
|
||||
************************************************/
|
||||
XdgIcon::XdgIcon()
|
||||
{
|
||||
}
|
||||
|
||||
/************************************************
|
||||
|
||||
************************************************/
|
||||
XdgIcon::~XdgIcon()
|
||||
{
|
||||
}
|
||||
|
||||
/************************************************
|
||||
Returns the name of the current icon theme.
|
||||
************************************************/
|
||||
QString XdgIcon::themeName()
|
||||
{
|
||||
return QIcon::themeName();
|
||||
}
|
||||
|
||||
/************************************************
|
||||
Sets the current icon theme to name.
|
||||
************************************************/
|
||||
void XdgIcon::setThemeName(const QString &themeName)
|
||||
{
|
||||
QIcon::setThemeName(themeName);
|
||||
QtXdg::QIconLoader::instance()->updateSystemTheme();
|
||||
}
|
||||
|
||||
/************************************************
|
||||
Returns the QIcon corresponding to name in the current icon theme. If no such icon
|
||||
is found in the current theme fallback is return instead.
|
||||
************************************************/
|
||||
QIcon XdgIcon::fromTheme(const QString &iconName, const QIcon &fallback)
|
||||
{
|
||||
if (iconName.isEmpty())
|
||||
return fallback;
|
||||
|
||||
bool isAbsolute = (iconName[0] == '/');
|
||||
|
||||
QString name = QFileInfo(iconName).fileName();
|
||||
if (name.endsWith(".png", Qt::CaseInsensitive) ||
|
||||
name.endsWith(".svg", Qt::CaseInsensitive) ||
|
||||
name.endsWith(".xpm", Qt::CaseInsensitive))
|
||||
{
|
||||
name.truncate(name.length() - 4);
|
||||
}
|
||||
|
||||
QIcon icon;
|
||||
|
||||
if (qtIconCache()->contains(name))
|
||||
{
|
||||
icon = *qtIconCache()->object(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
QIcon *cachedIcon;
|
||||
if (!isAbsolute)
|
||||
cachedIcon = new QIcon(new QtXdg::QIconLoaderEngineFixed(name));
|
||||
else
|
||||
cachedIcon = new QIcon(iconName);
|
||||
qtIconCache()->insert(name, cachedIcon);
|
||||
icon = *cachedIcon;
|
||||
}
|
||||
|
||||
// Note the qapp check is to allow lazy loading of static icons
|
||||
// Supporting fallbacks will not work for this case.
|
||||
if (qApp && !isAbsolute && icon.availableSizes().isEmpty())
|
||||
{
|
||||
return fallback;
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
|
||||
/************************************************
|
||||
Returns the QIcon corresponding to names in the current icon theme. If no such icon
|
||||
is found in the current theme fallback is return instead.
|
||||
************************************************/
|
||||
QIcon XdgIcon::fromTheme(const QStringList &iconNames, const QIcon &fallback)
|
||||
{
|
||||
foreach (QString iconName, iconNames)
|
||||
{
|
||||
QIcon icon = fromTheme(iconName);
|
||||
if (!icon.isNull())
|
||||
return icon;
|
||||
}
|
||||
|
||||
return fallback;
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
/* BEGIN_COMMON_COPYRIGHT_HEADER
|
||||
* (c)LGPL2+
|
||||
*
|
||||
* Razor - a lightweight, Qt based, desktop toolset
|
||||
* http://razor-qt.org
|
||||
*
|
||||
* Copyright: 2010-2011 Razor team
|
||||
* Authors:
|
||||
* Alexander Sokoloff <sokoloff.a@gmail.com>
|
||||
*
|
||||
* This program or library is free software; you can redistribute it
|
||||
* and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Lesser General
|
||||
* Public License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA
|
||||
*
|
||||
* END_COMMON_COPYRIGHT_HEADER */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QtGui/QIcon>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
#include "launcher_iconfix_export.h"
|
||||
|
||||
class LAUNCHER_ICONFIX_EXPORT XdgIcon
|
||||
{
|
||||
public:
|
||||
static QIcon fromTheme(const QString &iconName, const QIcon &fallback = QIcon());
|
||||
static QIcon fromTheme(const QStringList &iconNames, const QIcon &fallback = QIcon());
|
||||
|
||||
static QString themeName();
|
||||
static void setThemeName(const QString &themeName);
|
||||
|
||||
protected:
|
||||
explicit XdgIcon();
|
||||
virtual ~XdgIcon();
|
||||
};
|
@ -36,6 +36,7 @@ SOFTWARE.
|
||||
#include <QProcess>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QRegularExpression>
|
||||
|
||||
#include <functional>
|
||||
|
||||
@ -88,7 +89,9 @@ bool Sys::main_lsb_info(Sys::LsbInfo & out)
|
||||
{
|
||||
int status=0;
|
||||
QProcess lsbProcess;
|
||||
lsbProcess.start("lsb_release -a");
|
||||
QStringList arguments;
|
||||
arguments << "-a";
|
||||
lsbProcess.start("lsb_release", arguments);
|
||||
lsbProcess.waitForFinished();
|
||||
status = lsbProcess.exitStatus();
|
||||
QString output = lsbProcess.readAllStandardOutput();
|
||||
@ -170,7 +173,11 @@ void Sys::lsb_postprocess(Sys::LsbInfo & lsb, Sys::DistributionInfo & out)
|
||||
else
|
||||
{
|
||||
// ubuntu, debian, gentoo, scientific, slackware, ... ?
|
||||
auto parts = dist.split(QRegExp("\\s+"), QString::SkipEmptyParts);
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
auto parts = dist.split(QRegularExpression("\\s+"), Qt::SkipEmptyParts);
|
||||
#else
|
||||
auto parts = dist.split(QRegularExpression("\\s+"), QString::SkipEmptyParts);
|
||||
#endif
|
||||
if(parts.size())
|
||||
{
|
||||
dist = parts[0];
|
||||
@ -209,7 +216,11 @@ QString Sys::_extract_distribution(const QString & x)
|
||||
{
|
||||
return "sles";
|
||||
}
|
||||
QStringList list = release.split(QRegExp("\\s+"), QString::SkipEmptyParts);
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
QStringList list = release.split(QRegularExpression("\\s+"), Qt::SkipEmptyParts);
|
||||
#else
|
||||
QStringList list = release.split(QRegularExpression("\\s+"), QString::SkipEmptyParts);
|
||||
#endif
|
||||
if(list.size())
|
||||
{
|
||||
return list[0];
|
||||
@ -219,12 +230,16 @@ QString Sys::_extract_distribution(const QString & x)
|
||||
|
||||
QString Sys::_extract_version(const QString & x)
|
||||
{
|
||||
QRegExp versionish_string("\\d+(?:\\.\\d+)*$");
|
||||
QStringList list = x.split(QRegExp("\\s+"), QString::SkipEmptyParts);
|
||||
QRegularExpression versionish_string(QRegularExpression::anchoredPattern("\\d+(?:\\.\\d+)*$"));
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
QStringList list = x.split(QRegularExpression("\\s+"), Qt::SkipEmptyParts);
|
||||
#else
|
||||
QStringList list = x.split(QRegularExpression("\\s+"), QString::SkipEmptyParts);
|
||||
#endif
|
||||
for(int i = list.size() - 1; i >= 0; --i)
|
||||
{
|
||||
QString chunk = list[i];
|
||||
if(versionish_string.exactMatch(chunk))
|
||||
if(versionish_string.match(chunk).hasMatch())
|
||||
{
|
||||
return chunk;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user