refactor: fix deprecation up to Qt 6
Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
parent
e58158c3cd
commit
c363423718
@ -47,7 +47,7 @@ QStringList splitArgs(QString args)
|
|||||||
if (cchar == '\\')
|
if (cchar == '\\')
|
||||||
escape = true;
|
escape = true;
|
||||||
else if (cchar == inquotes)
|
else if (cchar == inquotes)
|
||||||
inquotes = 0;
|
inquotes = QChar::Null;
|
||||||
else
|
else
|
||||||
current += cchar;
|
current += cchar;
|
||||||
// otherwise
|
// otherwise
|
||||||
|
@ -346,7 +346,7 @@ bool checkProblemticPathJava(QDir folder)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Win32 crap
|
// Win32 crap
|
||||||
#if defined Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
|
|
||||||
bool called_coinit = false;
|
bool called_coinit = false;
|
||||||
|
|
||||||
@ -366,7 +366,7 @@ HRESULT CreateLink(LPCSTR linkPath, LPCSTR targetPath, LPCSTR args)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IShellLink *link;
|
IShellLinkA *link;
|
||||||
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink,
|
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink,
|
||||||
(LPVOID *)&link);
|
(LPVOID *)&link);
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ bool GZip::zip(const QByteArray &uncompressedBytes, QByteArray &compressedBytes)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned compLength = std::min(uncompressedBytes.size(), 16);
|
unsigned compLength = qMin(uncompressedBytes.size(), 16);
|
||||||
compressedBytes.clear();
|
compressedBytes.clear();
|
||||||
compressedBytes.resize(compLength);
|
compressedBytes.resize(compLength);
|
||||||
|
|
||||||
|
@ -421,7 +421,7 @@ bool MMCZip::collectFileListRecursively(const QString& rootDir, const QString& s
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
files->append(e.filePath()); // we want the original paths for MMCZip::compressDirFiles
|
files->append(e); // we want the original paths for MMCZip::compressDirFiles
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QStringView>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
|
||||||
class QUrl;
|
class QUrl;
|
||||||
@ -39,13 +40,21 @@ private:
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||||
|
auto numPart = QStringView{m_fullString}.left(cutoff);
|
||||||
|
#else
|
||||||
auto numPart = m_fullString.leftRef(cutoff);
|
auto numPart = m_fullString.leftRef(cutoff);
|
||||||
|
#endif
|
||||||
if(numPart.size())
|
if(numPart.size())
|
||||||
{
|
{
|
||||||
numValid = true;
|
numValid = true;
|
||||||
m_numPart = numPart.toInt();
|
m_numPart = numPart.toInt();
|
||||||
}
|
}
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||||
|
auto stringPart = QStringView{m_fullString}.mid(cutoff);
|
||||||
|
#else
|
||||||
auto stringPart = m_fullString.midRef(cutoff);
|
auto stringPart = m_fullString.midRef(cutoff);
|
||||||
|
#endif
|
||||||
if(stringPart.size())
|
if(stringPart.size())
|
||||||
{
|
{
|
||||||
m_stringPart = stringPart.toString();
|
m_stringPart = stringPart.toString();
|
||||||
|
@ -195,7 +195,7 @@ QList<JavaInstallPtr> JavaUtils::FindJavaFromRegistryKey(DWORD keyType, QString
|
|||||||
DWORD subKeyNameSize, numSubKeys, retCode;
|
DWORD subKeyNameSize, numSubKeys, retCode;
|
||||||
|
|
||||||
// Get the number of subkeys
|
// Get the number of subkeys
|
||||||
RegQueryInfoKey(jreKey, NULL, NULL, NULL, &numSubKeys, NULL, NULL, NULL, NULL, NULL,
|
RegQueryInfoKeyA(jreKey, NULL, NULL, NULL, &numSubKeys, NULL, NULL, NULL, NULL, NULL,
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
|
|
||||||
// Iterate until RegEnumKeyEx fails
|
// Iterate until RegEnumKeyEx fails
|
||||||
@ -204,31 +204,36 @@ QList<JavaInstallPtr> JavaUtils::FindJavaFromRegistryKey(DWORD keyType, QString
|
|||||||
for (DWORD i = 0; i < numSubKeys; i++)
|
for (DWORD i = 0; i < numSubKeys; i++)
|
||||||
{
|
{
|
||||||
subKeyNameSize = 255;
|
subKeyNameSize = 255;
|
||||||
retCode = RegEnumKeyEx(jreKey, i, subKeyName, &subKeyNameSize, NULL, NULL, NULL,
|
retCode = RegEnumKeyExA(jreKey, i, subKeyName, &subKeyNameSize, NULL, NULL, NULL,
|
||||||
NULL);
|
NULL);
|
||||||
|
#ifdef _UNICODE
|
||||||
|
QString newSubkeyName = QString::fromWCharArray(subKeyName);
|
||||||
|
#else
|
||||||
|
QString newSubkeyName = QString::fromLocal8Bit(subKeyName);
|
||||||
|
#endif
|
||||||
if (retCode == ERROR_SUCCESS)
|
if (retCode == ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
// Now open the registry key for the version that we just got.
|
// Now open the registry key for the version that we just got.
|
||||||
QString newKeyName = keyName + "\\" + subKeyName + subkeySuffix;
|
QString newKeyName = keyName + "\\" + newSubkeyName + subkeySuffix;
|
||||||
|
|
||||||
HKEY newKey;
|
HKEY newKey;
|
||||||
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, newKeyName.toStdString().c_str(), 0,
|
if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, newKeyName.toStdString().c_str(), 0,
|
||||||
KEY_READ | KEY_WOW64_64KEY, &newKey) == ERROR_SUCCESS)
|
KEY_READ | KEY_WOW64_64KEY, &newKey) == ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
// Read the JavaHome value to find where Java is installed.
|
// Read the JavaHome value to find where Java is installed.
|
||||||
value = new char[0];
|
value = new char[0];
|
||||||
valueSz = 0;
|
valueSz = 0;
|
||||||
if (RegQueryValueEx(newKey, keyJavaDir.toStdString().c_str(), NULL, NULL, (BYTE *)value,
|
if (RegQueryValueExA(newKey, keyJavaDir.toStdString().c_str(), NULL, NULL, (BYTE *)value,
|
||||||
&valueSz) == ERROR_MORE_DATA)
|
&valueSz) == ERROR_MORE_DATA)
|
||||||
{
|
{
|
||||||
value = new char[valueSz];
|
value = new char[valueSz];
|
||||||
RegQueryValueEx(newKey, keyJavaDir.toStdString().c_str(), NULL, NULL, (BYTE *)value,
|
RegQueryValueExA(newKey, keyJavaDir.toStdString().c_str(), NULL, NULL, (BYTE *)value,
|
||||||
&valueSz);
|
&valueSz);
|
||||||
|
|
||||||
// Now, we construct the version object and add it to the list.
|
// Now, we construct the version object and add it to the list.
|
||||||
JavaInstallPtr javaVersion(new JavaInstall());
|
JavaInstallPtr javaVersion(new JavaInstall());
|
||||||
|
|
||||||
javaVersion->id = subKeyName;
|
javaVersion->id = newSubkeyName;
|
||||||
javaVersion->arch = archType;
|
javaVersion->arch = archType;
|
||||||
javaVersion->path =
|
javaVersion->path =
|
||||||
QDir(FS::PathCombine(value, "bin")).absoluteFilePath("javaw.exe");
|
QDir(FS::PathCombine(value, "bin")).absoluteFilePath("javaw.exe");
|
||||||
|
@ -24,8 +24,10 @@ int main(int argc, char *argv[])
|
|||||||
return 42;
|
return 42;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if QT_VERSION <= QT_VERSION_CHECK(6, 0, 0)
|
||||||
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||||
QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||||
|
#endif
|
||||||
|
|
||||||
// initialize Qt
|
// initialize Qt
|
||||||
Application app(argc, argv);
|
Application app(argc, argv);
|
||||||
|
@ -321,7 +321,8 @@ bool World::install(const QString &to, const QString &name)
|
|||||||
|
|
||||||
if(ok && !name.isEmpty() && m_actualName != name)
|
if(ok && !name.isEmpty() && m_actualName != name)
|
||||||
{
|
{
|
||||||
World newWorld(finalPath);
|
QFileInfo finalPathInfo(finalPath);
|
||||||
|
World newWorld(finalPathInfo);
|
||||||
if(newWorld.isValid())
|
if(newWorld.isValid())
|
||||||
{
|
{
|
||||||
newWorld.rename(name);
|
newWorld.rename(name);
|
||||||
|
@ -301,7 +301,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||||
|
QVariant retrieveData(const QString &mimetype, QMetaType type) const
|
||||||
|
#else
|
||||||
QVariant retrieveData(const QString &mimetype, QVariant::Type type) const
|
QVariant retrieveData(const QString &mimetype, QVariant::Type type) const
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
QList<QUrl> urls;
|
QList<QUrl> urls;
|
||||||
for(auto &world: m_worlds)
|
for(auto &world: m_worlds)
|
||||||
|
@ -317,7 +317,8 @@ bool ModFolderModel::installMod(const QString &filename)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
FS::updateTimestamp(newpath);
|
FS::updateTimestamp(newpath);
|
||||||
installedMod.repath(newpath);
|
QFileInfo newpathInfo(newpath);
|
||||||
|
installedMod.repath(newpathInfo);
|
||||||
update();
|
update();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -335,7 +336,8 @@ bool ModFolderModel::installMod(const QString &filename)
|
|||||||
qWarning() << "Copy of folder from" << originalPath << "to" << newpath << "has (potentially partially) failed.";
|
qWarning() << "Copy of folder from" << originalPath << "to" << newpath << "has (potentially partially) failed.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
installedMod.repath(newpath);
|
QFileInfo newpathInfo(newpath);
|
||||||
|
installedMod.repath(newpathInfo);
|
||||||
update();
|
update();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
#include <list>
|
||||||
|
|
||||||
#include "Version.h"
|
#include "Version.h"
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
|
|
||||||
#include "ATLPackInstallTask.h"
|
#include "ATLPackInstallTask.h"
|
||||||
|
|
||||||
#include <QtConcurrent/QtConcurrent>
|
#include <QtConcurrent>
|
||||||
|
|
||||||
#include <quazip/quazip.h>
|
#include <quazip/quazip.h>
|
||||||
|
|
||||||
@ -557,7 +557,11 @@ void PackInstallTask::extractConfigs()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||||
|
m_extractFuture = QtConcurrent::run(QThreadPool::globalInstance(), QOverload<QString, QString>::of(MMCZip::extractDir), archivePath, extractDir.absolutePath() + "/minecraft");
|
||||||
|
#else
|
||||||
m_extractFuture = QtConcurrent::run(QThreadPool::globalInstance(), MMCZip::extractDir, archivePath, extractDir.absolutePath() + "/minecraft");
|
m_extractFuture = QtConcurrent::run(QThreadPool::globalInstance(), MMCZip::extractDir, archivePath, extractDir.absolutePath() + "/minecraft");
|
||||||
|
#endif
|
||||||
connect(&m_extractFutureWatcher, &QFutureWatcher<QStringList>::finished, this, [&]()
|
connect(&m_extractFutureWatcher, &QFutureWatcher<QStringList>::finished, this, [&]()
|
||||||
{
|
{
|
||||||
downloadMods();
|
downloadMods();
|
||||||
@ -702,7 +706,11 @@ void PackInstallTask::onModsDownloaded() {
|
|||||||
jobPtr.reset();
|
jobPtr.reset();
|
||||||
|
|
||||||
if(!modsToExtract.empty() || !modsToDecomp.empty() || !modsToCopy.empty()) {
|
if(!modsToExtract.empty() || !modsToDecomp.empty() || !modsToCopy.empty()) {
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||||
|
m_modExtractFuture = QtConcurrent::run(QThreadPool::globalInstance(), &PackInstallTask::extractMods, this, modsToExtract, modsToDecomp, modsToCopy);
|
||||||
|
#else
|
||||||
m_modExtractFuture = QtConcurrent::run(QThreadPool::globalInstance(), this, &PackInstallTask::extractMods, modsToExtract, modsToDecomp, modsToCopy);
|
m_modExtractFuture = QtConcurrent::run(QThreadPool::globalInstance(), this, &PackInstallTask::extractMods, modsToExtract, modsToDecomp, modsToCopy);
|
||||||
|
#endif
|
||||||
connect(&m_modExtractFutureWatcher, &QFutureWatcher<QStringList>::finished, this, &PackInstallTask::onModsExtracted);
|
connect(&m_modExtractFutureWatcher, &QFutureWatcher<QStringList>::finished, this, &PackInstallTask::onModsExtracted);
|
||||||
connect(&m_modExtractFutureWatcher, &QFutureWatcher<QStringList>::canceled, this, [&]()
|
connect(&m_modExtractFutureWatcher, &QFutureWatcher<QStringList>::canceled, this, [&]()
|
||||||
{
|
{
|
||||||
|
@ -103,7 +103,7 @@ bool PackFetchTask::parseAndAddPacks(QByteArray &data, PackType packType, Modpac
|
|||||||
|
|
||||||
if(!doc.setContent(data, false, &errorMsg, &errorLine, &errorCol))
|
if(!doc.setContent(data, false, &errorMsg, &errorLine, &errorCol))
|
||||||
{
|
{
|
||||||
auto fullErrMsg = QString("Failed to fetch modpack data: %1 %2:3d!").arg(errorMsg, errorLine, errorCol);
|
auto fullErrMsg = QString("Failed to fetch modpack data: %1 %2:%3!").arg(errorMsg).arg(errorLine).arg(errorCol);
|
||||||
qWarning() << fullErrMsg;
|
qWarning() << fullErrMsg;
|
||||||
data.clear();
|
data.clear();
|
||||||
return false;
|
return false;
|
||||||
|
@ -88,7 +88,11 @@ void PackInstallTask::unzip()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||||
|
m_extractFuture = QtConcurrent::run(QThreadPool::globalInstance(), QOverload<QString, QString>::of(MMCZip::extractDir), archivePath, extractDir.absolutePath() + "/unzip");
|
||||||
|
#else
|
||||||
m_extractFuture = QtConcurrent::run(QThreadPool::globalInstance(), MMCZip::extractDir, archivePath, extractDir.absolutePath() + "/unzip");
|
m_extractFuture = QtConcurrent::run(QThreadPool::globalInstance(), MMCZip::extractDir, archivePath, extractDir.absolutePath() + "/unzip");
|
||||||
|
#endif
|
||||||
connect(&m_extractFutureWatcher, &QFutureWatcher<QStringList>::finished, this, &PackInstallTask::onUnzipFinished);
|
connect(&m_extractFutureWatcher, &QFutureWatcher<QStringList>::finished, this, &PackInstallTask::onUnzipFinished);
|
||||||
connect(&m_extractFutureWatcher, &QFutureWatcher<QStringList>::canceled, this, &PackInstallTask::onUnzipCanceled);
|
connect(&m_extractFutureWatcher, &QFutureWatcher<QStringList>::canceled, this, &PackInstallTask::onUnzipCanceled);
|
||||||
m_extractFutureWatcher.setFuture(m_extractFuture);
|
m_extractFutureWatcher.setFuture(m_extractFuture);
|
||||||
|
@ -106,7 +106,7 @@ auto NetJob::abort() -> bool
|
|||||||
m_todo.clear();
|
m_todo.clear();
|
||||||
|
|
||||||
// abort active downloads
|
// abort active downloads
|
||||||
auto toKill = m_doing.toList();
|
auto toKill = m_doing.values();
|
||||||
for (auto index : toKill) {
|
for (auto index : toKill) {
|
||||||
auto part = m_downloads[index];
|
auto part = m_downloads[index];
|
||||||
fullyAborted &= part->abort();
|
fullyAborted &= part->abort();
|
||||||
|
@ -61,7 +61,7 @@ void NewsChecker::rssDownloadFinished()
|
|||||||
// Parse the XML.
|
// Parse the XML.
|
||||||
if (!doc.setContent(newsData, false, &errorMsg, &errorLine, &errorCol))
|
if (!doc.setContent(newsData, false, &errorMsg, &errorLine, &errorCol))
|
||||||
{
|
{
|
||||||
QString fullErrorMsg = QString("Error parsing RSS feed XML. %s at %d:%d.").arg(errorMsg, errorLine, errorCol);
|
QString fullErrorMsg = QString("Error parsing RSS feed XML. %1 at %2:%3.").arg(errorMsg).arg(errorLine).arg(errorCol);
|
||||||
fail(fullErrorMsg);
|
fail(fullErrorMsg);
|
||||||
newsData.clear();
|
newsData.clear();
|
||||||
return;
|
return;
|
||||||
|
@ -29,7 +29,7 @@ INIFile::INIFile()
|
|||||||
QString INIFile::unescape(QString orig)
|
QString INIFile::unescape(QString orig)
|
||||||
{
|
{
|
||||||
QString out;
|
QString out;
|
||||||
QChar prev = 0;
|
QChar prev = QChar::Null;
|
||||||
for(auto c: orig)
|
for(auto c: orig)
|
||||||
{
|
{
|
||||||
if(prev == '\\')
|
if(prev == '\\')
|
||||||
@ -42,7 +42,7 @@ QString INIFile::unescape(QString orig)
|
|||||||
out += '#';
|
out += '#';
|
||||||
else
|
else
|
||||||
out += c;
|
out += c;
|
||||||
prev = 0;
|
prev = QChar::Null;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -52,7 +52,7 @@ QString INIFile::unescape(QString orig)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
out += c;
|
out += c;
|
||||||
prev = 0;
|
prev = QChar::Null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
@ -117,7 +117,9 @@ bool INIFile::loadFile(QString fileName)
|
|||||||
bool INIFile::loadFile(QByteArray file)
|
bool INIFile::loadFile(QByteArray file)
|
||||||
{
|
{
|
||||||
QTextStream in(file);
|
QTextStream in(file);
|
||||||
|
#if QT_VERSION <= QT_VERSION_CHECK(6, 0, 0)
|
||||||
in.setCodec("UTF-8");
|
in.setCodec("UTF-8");
|
||||||
|
#endif
|
||||||
|
|
||||||
QStringList lines = in.readAll().split('\n');
|
QStringList lines = in.readAll().split('\n');
|
||||||
for (int i = 0; i < lines.count(); i++)
|
for (int i = 0; i < lines.count(); i++)
|
||||||
|
@ -64,7 +64,9 @@ QString getCreditsHtml()
|
|||||||
{
|
{
|
||||||
QString output;
|
QString output;
|
||||||
QTextStream stream(&output);
|
QTextStream stream(&output);
|
||||||
|
#if QT_VERSION <= QT_VERSION_CHECK(6, 0, 0)
|
||||||
stream.setCodec(QTextCodec::codecForName("UTF-8"));
|
stream.setCodec(QTextCodec::codecForName("UTF-8"));
|
||||||
|
#endif
|
||||||
stream << "<center>\n";
|
stream << "<center>\n";
|
||||||
|
|
||||||
//: %1 is the name of the launcher, determined at build time, e.g. "PolyMC Developers"
|
//: %1 is the name of the launcher, determined at build time, e.g. "PolyMC Developers"
|
||||||
|
@ -16,7 +16,7 @@ NewsDialog::NewsDialog(QList<NewsEntryPtr> entries, QWidget* parent) : QDialog(p
|
|||||||
m_article_list_hidden = ui->articleListWidget->isHidden();
|
m_article_list_hidden = ui->articleListWidget->isHidden();
|
||||||
|
|
||||||
auto first_item = ui->articleListWidget->item(0);
|
auto first_item = ui->articleListWidget->item(0);
|
||||||
ui->articleListWidget->setItemSelected(first_item, true);
|
first_item->setSelected(true);
|
||||||
|
|
||||||
auto article_entry = m_entries.constFind(first_item->text()).value();
|
auto article_entry = m_entries.constFind(first_item->text()).value();
|
||||||
ui->articleTitleLabel->setText(QString("<a href='%1'>%2</a>").arg(article_entry->link, first_item->text()));
|
ui->articleTitleLabel->setText(QString("<a href='%1'>%2</a>").arg(article_entry->link, first_item->text()));
|
||||||
|
@ -425,7 +425,12 @@ void InstanceView::mouseReleaseEvent(QMouseEvent *event)
|
|||||||
{
|
{
|
||||||
emit clicked(index);
|
emit clicked(index);
|
||||||
}
|
}
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||||
|
QStyleOptionViewItem option;
|
||||||
|
initViewItemOption(&option);
|
||||||
|
#else
|
||||||
QStyleOptionViewItem option = viewOptions();
|
QStyleOptionViewItem option = viewOptions();
|
||||||
|
#endif
|
||||||
if (m_pressedAlreadySelected)
|
if (m_pressedAlreadySelected)
|
||||||
{
|
{
|
||||||
option.state |= QStyle::State_Selected;
|
option.state |= QStyle::State_Selected;
|
||||||
@ -461,7 +466,12 @@ void InstanceView::mouseDoubleClickEvent(QMouseEvent *event)
|
|||||||
QPersistentModelIndex persistent = index;
|
QPersistentModelIndex persistent = index;
|
||||||
emit doubleClicked(persistent);
|
emit doubleClicked(persistent);
|
||||||
|
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||||
|
QStyleOptionViewItem option;
|
||||||
|
initViewItemOption(&option);
|
||||||
|
#else
|
||||||
QStyleOptionViewItem option = viewOptions();
|
QStyleOptionViewItem option = viewOptions();
|
||||||
|
#endif
|
||||||
if ((model()->flags(index) & Qt::ItemIsEnabled) && !style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, &option, this))
|
if ((model()->flags(index) & Qt::ItemIsEnabled) && !style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, &option, this))
|
||||||
{
|
{
|
||||||
emit activated(index);
|
emit activated(index);
|
||||||
@ -474,7 +484,12 @@ void InstanceView::paintEvent(QPaintEvent *event)
|
|||||||
|
|
||||||
QPainter painter(this->viewport());
|
QPainter painter(this->viewport());
|
||||||
|
|
||||||
QStyleOptionViewItem option(viewOptions());
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||||
|
QStyleOptionViewItem option;
|
||||||
|
initViewItemOption(&option);
|
||||||
|
#else
|
||||||
|
QStyleOptionViewItem option = viewOptions();
|
||||||
|
#endif
|
||||||
option.widget = this;
|
option.widget = this;
|
||||||
|
|
||||||
int wpWidth = viewport()->width();
|
int wpWidth = viewport()->width();
|
||||||
@ -528,9 +543,9 @@ void InstanceView::paintEvent(QPaintEvent *event)
|
|||||||
#if 0
|
#if 0
|
||||||
if (!m_lastDragPosition.isNull())
|
if (!m_lastDragPosition.isNull())
|
||||||
{
|
{
|
||||||
QPair<Group *, int> pair = rowDropPos(m_lastDragPosition);
|
std::pair<VisualGroup *, VisualGroup::HitResults> pair = rowDropPos(m_lastDragPosition);
|
||||||
Group *category = pair.first;
|
VisualGroup *category = pair.first;
|
||||||
int row = pair.second;
|
VisualGroup::HitResults row = pair.second;
|
||||||
if (category)
|
if (category)
|
||||||
{
|
{
|
||||||
int internalRow = row - category->firstItemIndex;
|
int internalRow = row - category->firstItemIndex;
|
||||||
@ -618,7 +633,7 @@ void InstanceView::dropEvent(QDropEvent *event)
|
|||||||
{
|
{
|
||||||
if(event->possibleActions() & Qt::MoveAction)
|
if(event->possibleActions() & Qt::MoveAction)
|
||||||
{
|
{
|
||||||
QPair<VisualGroup *, VisualGroup::HitResults> dropPos = rowDropPos(event->pos());
|
std::pair<VisualGroup *, VisualGroup::HitResults> dropPos = rowDropPos(event->pos());
|
||||||
const VisualGroup *group = dropPos.first;
|
const VisualGroup *group = dropPos.first;
|
||||||
auto hitresult = dropPos.second;
|
auto hitresult = dropPos.second;
|
||||||
|
|
||||||
@ -709,10 +724,18 @@ QRect InstanceView::geometryRect(const QModelIndex &index) const
|
|||||||
int x = pos.first;
|
int x = pos.first;
|
||||||
// int y = pos.second;
|
// int y = pos.second;
|
||||||
|
|
||||||
|
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||||
|
QStyleOptionViewItem option;
|
||||||
|
initViewItemOption(&option);
|
||||||
|
#else
|
||||||
|
QStyleOptionViewItem option = viewOptions();
|
||||||
|
#endif
|
||||||
|
|
||||||
QRect out;
|
QRect out;
|
||||||
out.setTop(cat->verticalPosition() + cat->headerHeight() + 5 + cat->rowTopOf(index));
|
out.setTop(cat->verticalPosition() + cat->headerHeight() + 5 + cat->rowTopOf(index));
|
||||||
out.setLeft(m_spacing + x * (itemWidth() + m_spacing));
|
out.setLeft(m_spacing + x * (itemWidth() + m_spacing));
|
||||||
out.setSize(itemDelegate()->sizeHint(viewOptions(), index));
|
out.setSize(itemDelegate()->sizeHint(option, index));
|
||||||
geometryCache.insert(row, new QRect(out));
|
geometryCache.insert(row, new QRect(out));
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
@ -759,7 +782,12 @@ QPixmap InstanceView::renderToPixmap(const QModelIndexList &indices, QRect *r) c
|
|||||||
QPixmap pixmap(r->size());
|
QPixmap pixmap(r->size());
|
||||||
pixmap.fill(Qt::transparent);
|
pixmap.fill(Qt::transparent);
|
||||||
QPainter painter(&pixmap);
|
QPainter painter(&pixmap);
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||||
|
QStyleOptionViewItem option;
|
||||||
|
initViewItemOption(&option);
|
||||||
|
#else
|
||||||
QStyleOptionViewItem option = viewOptions();
|
QStyleOptionViewItem option = viewOptions();
|
||||||
|
#endif
|
||||||
option.state |= QStyle::State_Selected;
|
option.state |= QStyle::State_Selected;
|
||||||
for (int j = 0; j < paintPairs.count(); ++j)
|
for (int j = 0; j < paintPairs.count(); ++j)
|
||||||
{
|
{
|
||||||
@ -770,16 +798,16 @@ QPixmap InstanceView::renderToPixmap(const QModelIndexList &indices, QRect *r) c
|
|||||||
return pixmap;
|
return pixmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QPair<QRect, QModelIndex>> InstanceView::draggablePaintPairs(const QModelIndexList &indices, QRect *r) const
|
QList<std::pair<QRect, QModelIndex>> InstanceView::draggablePaintPairs(const QModelIndexList &indices, QRect *r) const
|
||||||
{
|
{
|
||||||
Q_ASSERT(r);
|
Q_ASSERT(r);
|
||||||
QRect &rect = *r;
|
QRect &rect = *r;
|
||||||
QList<QPair<QRect, QModelIndex>> ret;
|
QList<std::pair<QRect, QModelIndex>> ret;
|
||||||
for (int i = 0; i < indices.count(); ++i)
|
for (int i = 0; i < indices.count(); ++i)
|
||||||
{
|
{
|
||||||
const QModelIndex &index = indices.at(i);
|
const QModelIndex &index = indices.at(i);
|
||||||
const QRect current = geometryRect(index);
|
const QRect current = geometryRect(index);
|
||||||
ret += qMakePair(current, index);
|
ret += std::make_pair(current, index);
|
||||||
rect |= current;
|
rect |= current;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
@ -790,11 +818,11 @@ bool InstanceView::isDragEventAccepted(QDropEvent *event)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QPair<VisualGroup *, VisualGroup::HitResults> InstanceView::rowDropPos(const QPoint &pos)
|
std::pair<VisualGroup *, VisualGroup::HitResults> InstanceView::rowDropPos(const QPoint &pos)
|
||||||
{
|
{
|
||||||
VisualGroup::HitResults hitresult;
|
VisualGroup::HitResults hitresult;
|
||||||
auto group = categoryAt(pos + offset(), hitresult);
|
auto group = categoryAt(pos + offset(), hitresult);
|
||||||
return qMakePair<VisualGroup*, int>(group, hitresult);
|
return std::make_pair(group, hitresult);
|
||||||
}
|
}
|
||||||
|
|
||||||
QPoint InstanceView::offset() const
|
QPoint InstanceView::offset() const
|
||||||
|
@ -143,11 +143,11 @@ private: /* methods */
|
|||||||
int calculateItemsPerRow() const;
|
int calculateItemsPerRow() const;
|
||||||
int verticalScrollToValue(const QModelIndex &index, const QRect &rect, QListView::ScrollHint hint) const;
|
int verticalScrollToValue(const QModelIndex &index, const QRect &rect, QListView::ScrollHint hint) const;
|
||||||
QPixmap renderToPixmap(const QModelIndexList &indices, QRect *r) const;
|
QPixmap renderToPixmap(const QModelIndexList &indices, QRect *r) const;
|
||||||
QList<QPair<QRect, QModelIndex>> draggablePaintPairs(const QModelIndexList &indices, QRect *r) const;
|
QList<std::pair<QRect, QModelIndex>> draggablePaintPairs(const QModelIndexList &indices, QRect *r) const;
|
||||||
|
|
||||||
bool isDragEventAccepted(QDropEvent *event);
|
bool isDragEventAccepted(QDropEvent *event);
|
||||||
|
|
||||||
QPair<VisualGroup *, VisualGroup::HitResults> rowDropPos(const QPoint &pos);
|
std::pair<VisualGroup *, VisualGroup::HitResults> rowDropPos(const QPoint &pos);
|
||||||
|
|
||||||
QPoint offset() const;
|
QPoint offset() const;
|
||||||
};
|
};
|
||||||
|
@ -55,7 +55,14 @@ void VisualGroup::update()
|
|||||||
positionInRow = 0;
|
positionInRow = 0;
|
||||||
maxRowHeight = 0;
|
maxRowHeight = 0;
|
||||||
}
|
}
|
||||||
auto itemHeight = view->itemDelegate()->sizeHint(view->viewOptions(), item).height();
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||||
|
QStyleOptionViewItem viewItemOption;
|
||||||
|
view->initViewItemOption(&viewItemOption);
|
||||||
|
#else
|
||||||
|
QStyleOptionViewItem viewItemOption = view->viewOptions();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
auto itemHeight = view->itemDelegate()->sizeHint(viewItemOption, item).height();
|
||||||
if(itemHeight > maxRowHeight)
|
if(itemHeight > maxRowHeight)
|
||||||
{
|
{
|
||||||
maxRowHeight = itemHeight;
|
maxRowHeight = itemHeight;
|
||||||
|
Loading…
Reference in New Issue
Block a user