mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-04-30 06:34:27 +02:00
Add checkboxes to resource downloader (#3516)
This commit is contained in:
commit
6b4f07e976
@ -44,7 +44,7 @@ ResourceAPI::SearchArgs ModModel::createSearchArguments()
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceAPI::VersionSearchArgs ModModel::createVersionsArguments(QModelIndex& entry)
|
ResourceAPI::VersionSearchArgs ModModel::createVersionsArguments(const QModelIndex& entry)
|
||||||
{
|
{
|
||||||
auto& pack = *m_packs[entry.row()];
|
auto& pack = *m_packs[entry.row()];
|
||||||
auto profile = static_cast<MinecraftInstance const&>(m_base_instance).getPackProfile();
|
auto profile = static_cast<MinecraftInstance const&>(m_base_instance).getPackProfile();
|
||||||
@ -62,7 +62,7 @@ ResourceAPI::VersionSearchArgs ModModel::createVersionsArguments(QModelIndex& en
|
|||||||
return { pack, versions, loaders };
|
return { pack, versions, loaders };
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceAPI::ProjectInfoArgs ModModel::createInfoArguments(QModelIndex& entry)
|
ResourceAPI::ProjectInfoArgs ModModel::createInfoArguments(const QModelIndex& entry)
|
||||||
{
|
{
|
||||||
auto& pack = *m_packs[entry.row()];
|
auto& pack = *m_packs[entry.row()];
|
||||||
return { pack };
|
return { pack };
|
||||||
|
@ -39,8 +39,8 @@ class ModModel : public ResourceModel {
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
ResourceAPI::SearchArgs createSearchArguments() override;
|
ResourceAPI::SearchArgs createSearchArguments() override;
|
||||||
ResourceAPI::VersionSearchArgs createVersionsArguments(QModelIndex&) override;
|
ResourceAPI::VersionSearchArgs createVersionsArguments(const QModelIndex&) override;
|
||||||
ResourceAPI::ProjectInfoArgs createInfoArguments(QModelIndex&) override;
|
ResourceAPI::ProjectInfoArgs createInfoArguments(const QModelIndex&) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
auto documentToArray(QJsonDocument& obj) const -> QJsonArray override = 0;
|
auto documentToArray(QJsonDocument& obj) const -> QJsonArray override = 0;
|
||||||
|
@ -59,7 +59,6 @@ namespace ResourceDownload {
|
|||||||
ModPage::ModPage(ModDownloadDialog* dialog, BaseInstance& instance) : ResourcePage(dialog, instance)
|
ModPage::ModPage(ModDownloadDialog* dialog, BaseInstance& instance) : ResourcePage(dialog, instance)
|
||||||
{
|
{
|
||||||
connect(m_ui->resourceFilterButton, &QPushButton::clicked, this, &ModPage::filterMods);
|
connect(m_ui->resourceFilterButton, &QPushButton::clicked, this, &ModPage::filterMods);
|
||||||
connect(m_ui->packView, &QListView::doubleClicked, this, &ModPage::onResourceSelected);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModPage::setFilterWidget(unique_qobject_ptr<ModFilterWidget>& widget)
|
void ModPage::setFilterWidget(unique_qobject_ptr<ModFilterWidget>& widget)
|
||||||
|
@ -35,8 +35,9 @@ class ModPage : public ResourcePage {
|
|||||||
page->setFilterWidget(filter_widget);
|
page->setFilterWidget(filter_widget);
|
||||||
model->setFilter(page->getFilter());
|
model->setFilter(page->getFilter());
|
||||||
|
|
||||||
connect(model, &ResourceModel::versionListUpdated, page, &ResourcePage::updateVersionList);
|
connect(model, &ResourceModel::versionListUpdated, page, &ResourcePage::versionListUpdated);
|
||||||
connect(model, &ResourceModel::projectInfoUpdated, page, &ResourcePage::updateUi);
|
connect(model, &ResourceModel::projectInfoUpdated, page, &ResourcePage::updateUi);
|
||||||
|
connect(model, &QAbstractListModel::modelReset, page, &ResourcePage::modelReset);
|
||||||
|
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
@ -82,8 +82,8 @@ auto ResourceModel::data(const QModelIndex& index, int role) const -> QVariant
|
|||||||
return pack->name;
|
return pack->name;
|
||||||
case UserDataTypes::DESCRIPTION:
|
case UserDataTypes::DESCRIPTION:
|
||||||
return pack->description;
|
return pack->description;
|
||||||
case UserDataTypes::SELECTED:
|
case Qt::CheckStateRole:
|
||||||
return pack->isAnyVersionSelected();
|
return pack->isAnyVersionSelected() ? Qt::Checked : Qt::Unchecked;
|
||||||
case UserDataTypes::INSTALLED:
|
case UserDataTypes::INSTALLED:
|
||||||
return this->isPackInstalled(pack);
|
return this->isPackInstalled(pack);
|
||||||
default:
|
default:
|
||||||
@ -103,7 +103,6 @@ QHash<int, QByteArray> ResourceModel::roleNames() const
|
|||||||
roles[Qt::UserRole] = "pack";
|
roles[Qt::UserRole] = "pack";
|
||||||
roles[UserDataTypes::TITLE] = "title";
|
roles[UserDataTypes::TITLE] = "title";
|
||||||
roles[UserDataTypes::DESCRIPTION] = "description";
|
roles[UserDataTypes::DESCRIPTION] = "description";
|
||||||
roles[UserDataTypes::SELECTED] = "selected";
|
|
||||||
roles[UserDataTypes::INSTALLED] = "installed";
|
roles[UserDataTypes::INSTALLED] = "installed";
|
||||||
|
|
||||||
return roles;
|
return roles;
|
||||||
@ -193,7 +192,7 @@ void ResourceModel::search()
|
|||||||
runSearchJob(job);
|
runSearchJob(job);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourceModel::loadEntry(QModelIndex& entry)
|
void ResourceModel::loadEntry(const QModelIndex& entry)
|
||||||
{
|
{
|
||||||
auto const& pack = m_packs[entry.row()];
|
auto const& pack = m_packs[entry.row()];
|
||||||
|
|
||||||
@ -504,7 +503,7 @@ void ResourceModel::versionRequestSucceeded(QJsonDocument& doc, ModPlatform::Ind
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
emit versionListUpdated();
|
emit versionListUpdated(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourceModel::infoRequestSucceeded(QJsonDocument& doc, ModPlatform::IndexedPack& pack, const QModelIndex& index)
|
void ResourceModel::infoRequestSucceeded(QJsonDocument& doc, ModPlatform::IndexedPack& pack, const QModelIndex& index)
|
||||||
@ -531,7 +530,7 @@ void ResourceModel::infoRequestSucceeded(QJsonDocument& doc, ModPlatform::Indexe
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
emit projectInfoUpdated();
|
emit projectInfoUpdated(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourceModel::addPack(ModPlatform::IndexedPack::Ptr pack,
|
void ResourceModel::addPack(ModPlatform::IndexedPack::Ptr pack,
|
||||||
|
@ -80,17 +80,17 @@ class ResourceModel : public QAbstractListModel {
|
|||||||
virtual ResourceAPI::SearchArgs createSearchArguments() = 0;
|
virtual ResourceAPI::SearchArgs createSearchArguments() = 0;
|
||||||
virtual ResourceAPI::SearchCallbacks createSearchCallbacks() { return {}; }
|
virtual ResourceAPI::SearchCallbacks createSearchCallbacks() { return {}; }
|
||||||
|
|
||||||
virtual ResourceAPI::VersionSearchArgs createVersionsArguments(QModelIndex&) = 0;
|
virtual ResourceAPI::VersionSearchArgs createVersionsArguments(const QModelIndex&) = 0;
|
||||||
virtual ResourceAPI::VersionSearchCallbacks createVersionsCallbacks(QModelIndex&) { return {}; }
|
virtual ResourceAPI::VersionSearchCallbacks createVersionsCallbacks(const QModelIndex&) { return {}; }
|
||||||
|
|
||||||
virtual ResourceAPI::ProjectInfoArgs createInfoArguments(QModelIndex&) = 0;
|
virtual ResourceAPI::ProjectInfoArgs createInfoArguments(const QModelIndex&) = 0;
|
||||||
virtual ResourceAPI::ProjectInfoCallbacks createInfoCallbacks(QModelIndex&) { return {}; }
|
virtual ResourceAPI::ProjectInfoCallbacks createInfoCallbacks(const QModelIndex&) { return {}; }
|
||||||
|
|
||||||
/** Requests the API for more entries. */
|
/** Requests the API for more entries. */
|
||||||
virtual void search();
|
virtual void search();
|
||||||
|
|
||||||
/** Applies any processing / extra requests needed to fully load the specified entry's information. */
|
/** Applies any processing / extra requests needed to fully load the specified entry's information. */
|
||||||
virtual void loadEntry(QModelIndex&);
|
virtual void loadEntry(const QModelIndex&);
|
||||||
|
|
||||||
/** Schedule a refresh, clearing the current state. */
|
/** Schedule a refresh, clearing the current state. */
|
||||||
void refresh();
|
void refresh();
|
||||||
@ -170,8 +170,8 @@ class ResourceModel : public QAbstractListModel {
|
|||||||
void infoRequestSucceeded(QJsonDocument&, ModPlatform::IndexedPack&, const QModelIndex&);
|
void infoRequestSucceeded(QJsonDocument&, ModPlatform::IndexedPack&, const QModelIndex&);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void versionListUpdated();
|
void versionListUpdated(const QModelIndex& index);
|
||||||
void projectInfoUpdated();
|
void projectInfoUpdated(const QModelIndex& index);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ResourceDownload
|
} // namespace ResourceDownload
|
||||||
|
@ -20,13 +20,13 @@ ResourceAPI::SearchArgs ResourcePackResourceModel::createSearchArguments()
|
|||||||
return { ModPlatform::ResourceType::RESOURCE_PACK, m_next_search_offset, m_search_term, sort };
|
return { ModPlatform::ResourceType::RESOURCE_PACK, m_next_search_offset, m_search_term, sort };
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceAPI::VersionSearchArgs ResourcePackResourceModel::createVersionsArguments(QModelIndex& entry)
|
ResourceAPI::VersionSearchArgs ResourcePackResourceModel::createVersionsArguments(const QModelIndex& entry)
|
||||||
{
|
{
|
||||||
auto& pack = m_packs[entry.row()];
|
auto& pack = m_packs[entry.row()];
|
||||||
return { *pack };
|
return { *pack };
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceAPI::ProjectInfoArgs ResourcePackResourceModel::createInfoArguments(QModelIndex& entry)
|
ResourceAPI::ProjectInfoArgs ResourcePackResourceModel::createInfoArguments(const QModelIndex& entry)
|
||||||
{
|
{
|
||||||
auto& pack = m_packs[entry.row()];
|
auto& pack = m_packs[entry.row()];
|
||||||
return { *pack };
|
return { *pack };
|
||||||
|
@ -31,8 +31,8 @@ class ResourcePackResourceModel : public ResourceModel {
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
ResourceAPI::SearchArgs createSearchArguments() override;
|
ResourceAPI::SearchArgs createSearchArguments() override;
|
||||||
ResourceAPI::VersionSearchArgs createVersionsArguments(QModelIndex&) override;
|
ResourceAPI::VersionSearchArgs createVersionsArguments(const QModelIndex&) override;
|
||||||
ResourceAPI::ProjectInfoArgs createInfoArguments(QModelIndex&) override;
|
ResourceAPI::ProjectInfoArgs createInfoArguments(const QModelIndex&) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const BaseInstance& m_base_instance;
|
const BaseInstance& m_base_instance;
|
||||||
|
@ -14,9 +14,7 @@
|
|||||||
namespace ResourceDownload {
|
namespace ResourceDownload {
|
||||||
|
|
||||||
ResourcePackResourcePage::ResourcePackResourcePage(ResourceDownloadDialog* dialog, BaseInstance& instance) : ResourcePage(dialog, instance)
|
ResourcePackResourcePage::ResourcePackResourcePage(ResourceDownloadDialog* dialog, BaseInstance& instance) : ResourcePage(dialog, instance)
|
||||||
{
|
{}
|
||||||
connect(m_ui->packView, &QListView::doubleClicked, this, &ResourcePackResourcePage::onResourceSelected);
|
|
||||||
}
|
|
||||||
|
|
||||||
/******** Callbacks to events in the UI (set up in the derived classes) ********/
|
/******** Callbacks to events in the UI (set up in the derived classes) ********/
|
||||||
|
|
||||||
|
@ -25,8 +25,9 @@ class ResourcePackResourcePage : public ResourcePage {
|
|||||||
auto page = new T(dialog, instance);
|
auto page = new T(dialog, instance);
|
||||||
auto model = static_cast<ResourcePackResourceModel*>(page->getModel());
|
auto model = static_cast<ResourcePackResourceModel*>(page->getModel());
|
||||||
|
|
||||||
connect(model, &ResourceModel::versionListUpdated, page, &ResourcePage::updateVersionList);
|
connect(model, &ResourceModel::versionListUpdated, page, &ResourcePage::versionListUpdated);
|
||||||
connect(model, &ResourceModel::projectInfoUpdated, page, &ResourcePage::updateUi);
|
connect(model, &ResourceModel::projectInfoUpdated, page, &ResourcePage::updateUi);
|
||||||
|
connect(model, &QAbstractListModel::modelReset, page, &ResourcePage::modelReset);
|
||||||
|
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
@ -78,10 +78,15 @@ ResourcePage::ResourcePage(ResourceDownloadDialog* parent, BaseInstance& base_in
|
|||||||
|
|
||||||
m_ui->verticalLayout->insertWidget(1, &m_fetchProgress);
|
m_ui->verticalLayout->insertWidget(1, &m_fetchProgress);
|
||||||
|
|
||||||
m_ui->packView->setItemDelegate(new ProjectItemDelegate(this));
|
auto delegate = new ProjectItemDelegate(this);
|
||||||
|
m_ui->packView->setItemDelegate(delegate);
|
||||||
m_ui->packView->installEventFilter(this);
|
m_ui->packView->installEventFilter(this);
|
||||||
|
m_ui->packView->viewport()->installEventFilter(this);
|
||||||
|
|
||||||
connect(m_ui->packDescription, &QTextBrowser::anchorClicked, this, &ResourcePage::openUrl);
|
connect(m_ui->packDescription, &QTextBrowser::anchorClicked, this, &ResourcePage::openUrl);
|
||||||
|
|
||||||
|
connect(m_ui->packView, &QListView::doubleClicked, this, &ResourcePage::onResourceToggle);
|
||||||
|
connect(delegate, &ProjectItemDelegate::checkboxClicked, this, &ResourcePage::onResourceToggle);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourcePage::~ResourcePage()
|
ResourcePage::~ResourcePage()
|
||||||
@ -128,17 +133,20 @@ auto ResourcePage::eventFilter(QObject* watched, QEvent* event) -> bool
|
|||||||
m_searchTimer.start(350);
|
m_searchTimer.start(350);
|
||||||
}
|
}
|
||||||
} else if (watched == m_ui->packView) {
|
} else if (watched == m_ui->packView) {
|
||||||
|
// stop the event from going to the confirm button
|
||||||
if (keyEvent->key() == Qt::Key_Return) {
|
if (keyEvent->key() == Qt::Key_Return) {
|
||||||
onResourceSelected();
|
onResourceToggle(m_ui->packView->currentIndex());
|
||||||
|
|
||||||
// To have the 'select mod' button outlined instead of the 'review and confirm' one
|
|
||||||
m_ui->resourceSelectionButton->setFocus(Qt::FocusReason::ShortcutFocusReason);
|
|
||||||
m_ui->packView->setFocus(Qt::FocusReason::NoFocusReason);
|
|
||||||
|
|
||||||
keyEvent->accept();
|
keyEvent->accept();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (watched == m_ui->packView->viewport() && event->type() == QEvent::MouseButtonPress) {
|
||||||
|
auto* mouseEvent = static_cast<QMouseEvent*>(event);
|
||||||
|
|
||||||
|
if (mouseEvent->button() == Qt::MiddleButton) {
|
||||||
|
onResourceToggle(m_ui->packView->indexAt(mouseEvent->pos()));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return QWidget::eventFilter(watched, event);
|
return QWidget::eventFilter(watched, event);
|
||||||
@ -177,8 +185,11 @@ ModPlatform::IndexedPack::Ptr ResourcePage::getCurrentPack() const
|
|||||||
return m_model->data(m_ui->packView->currentIndex(), Qt::UserRole).value<ModPlatform::IndexedPack::Ptr>();
|
return m_model->data(m_ui->packView->currentIndex(), Qt::UserRole).value<ModPlatform::IndexedPack::Ptr>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourcePage::updateUi()
|
void ResourcePage::updateUi(const QModelIndex& index)
|
||||||
{
|
{
|
||||||
|
if (index != m_ui->packView->currentIndex())
|
||||||
|
return;
|
||||||
|
|
||||||
auto current_pack = getCurrentPack();
|
auto current_pack = getCurrentPack();
|
||||||
if (!current_pack) {
|
if (!current_pack) {
|
||||||
m_ui->packDescription->setHtml({});
|
m_ui->packDescription->setHtml({});
|
||||||
@ -268,8 +279,9 @@ void ResourcePage::updateSelectionButton()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourcePage::updateVersionList()
|
void ResourcePage::versionListUpdated(const QModelIndex& index)
|
||||||
{
|
{
|
||||||
|
if (index == m_ui->packView->currentIndex()) {
|
||||||
auto current_pack = getCurrentPack();
|
auto current_pack = getCurrentPack();
|
||||||
|
|
||||||
m_ui->versionSelectionBox->blockSignals(true);
|
m_ui->versionSelectionBox->blockSignals(true);
|
||||||
@ -300,7 +312,15 @@ void ResourcePage::updateVersionList()
|
|||||||
m_ui->resourceSelectionButton->setText(tr("Cannot select invalid version :("));
|
m_ui->resourceSelectionButton->setText(tr("Cannot select invalid version :("));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_enableQueue.contains(index.row())) {
|
||||||
|
m_enableQueue.remove(index.row());
|
||||||
|
onResourceToggle(index);
|
||||||
|
} else
|
||||||
updateSelectionButton();
|
updateSelectionButton();
|
||||||
|
} else if (m_enableQueue.contains(index.row())) {
|
||||||
|
m_enableQueue.remove(index.row());
|
||||||
|
onResourceToggle(index);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourcePage::onSelectionChanged(QModelIndex curr, [[maybe_unused]] QModelIndex prev)
|
void ResourcePage::onSelectionChanged(QModelIndex curr, [[maybe_unused]] QModelIndex prev)
|
||||||
@ -318,16 +338,20 @@ void ResourcePage::onSelectionChanged(QModelIndex curr, [[maybe_unused]] QModelI
|
|||||||
|
|
||||||
request_load = true;
|
request_load = true;
|
||||||
} else {
|
} else {
|
||||||
updateVersionList();
|
versionListUpdated(curr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current_pack && !current_pack->extraDataLoaded)
|
if (current_pack && !current_pack->extraDataLoaded)
|
||||||
request_load = true;
|
request_load = true;
|
||||||
|
|
||||||
|
// we are already requesting this
|
||||||
|
if (m_enableQueue.contains(curr.row()))
|
||||||
|
request_load = false;
|
||||||
|
|
||||||
if (request_load)
|
if (request_load)
|
||||||
m_model->loadEntry(curr);
|
m_model->loadEntry(curr);
|
||||||
|
|
||||||
updateUi();
|
updateUi(curr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourcePage::onVersionSelectionChanged(int index)
|
void ResourcePage::onVersionSelectionChanged(int index)
|
||||||
@ -354,6 +378,11 @@ void ResourcePage::addResourceToPage(ModPlatform::IndexedPack::Ptr pack,
|
|||||||
m_model->addPack(pack, ver, base_model, is_indexed);
|
m_model->addPack(pack, ver, base_model, is_indexed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ResourcePage::modelReset()
|
||||||
|
{
|
||||||
|
m_enableQueue.clear();
|
||||||
|
}
|
||||||
|
|
||||||
void ResourcePage::removeResourceFromPage(const QString& name)
|
void ResourcePage::removeResourceFromPage(const QString& name)
|
||||||
{
|
{
|
||||||
m_model->removePack(name);
|
m_model->removePack(name);
|
||||||
@ -385,6 +414,48 @@ void ResourcePage::onResourceSelected()
|
|||||||
m_ui->packView->repaint();
|
m_ui->packView->repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ResourcePage::onResourceToggle(const QModelIndex& index)
|
||||||
|
{
|
||||||
|
const bool isSelected = index == m_ui->packView->currentIndex();
|
||||||
|
auto pack = m_model->data(index, Qt::UserRole).value<ModPlatform::IndexedPack::Ptr>();
|
||||||
|
|
||||||
|
if (pack->versionsLoaded) {
|
||||||
|
if (pack->isAnyVersionSelected())
|
||||||
|
removeResourceFromDialog(pack->name);
|
||||||
|
else {
|
||||||
|
auto version = std::find_if(pack->versions.begin(), pack->versions.end(), [this](const ModPlatform::IndexedVersion& version) {
|
||||||
|
return m_model->checkVersionFilters(version);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (version == pack->versions.end()) {
|
||||||
|
auto errorMessage = new QMessageBox(
|
||||||
|
QMessageBox::Warning, tr("No versions available"),
|
||||||
|
tr("No versions for '%1' are available.\nThe author likely blocked third-party launchers.").arg(pack->name),
|
||||||
|
QMessageBox::Ok, this);
|
||||||
|
|
||||||
|
errorMessage->open();
|
||||||
|
} else
|
||||||
|
addResourceToDialog(pack, *version);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isSelected)
|
||||||
|
updateSelectionButton();
|
||||||
|
|
||||||
|
// force update
|
||||||
|
QVariant variant;
|
||||||
|
variant.setValue(pack);
|
||||||
|
m_model->setData(index, variant, Qt::UserRole);
|
||||||
|
} else {
|
||||||
|
// the model is just 1 dimensional so this is fine
|
||||||
|
m_enableQueue.insert(index.row());
|
||||||
|
|
||||||
|
// we can't be sure that this hasn't already been requested...
|
||||||
|
// but this does the job well enough and there's not much point preventing edgecases
|
||||||
|
if (!isSelected)
|
||||||
|
m_model->loadEntry(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ResourcePage::openUrl(const QUrl& url)
|
void ResourcePage::openUrl(const QUrl& url)
|
||||||
{
|
{
|
||||||
// do not allow other url schemes for security reasons
|
// do not allow other url schemes for security reasons
|
||||||
|
@ -71,15 +71,17 @@ class ResourcePage : public QWidget, public BasePage {
|
|||||||
void addSortings();
|
void addSortings();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void updateUi();
|
virtual void updateUi(const QModelIndex& index);
|
||||||
virtual void updateSelectionButton();
|
virtual void updateSelectionButton();
|
||||||
virtual void updateVersionList();
|
virtual void versionListUpdated(const QModelIndex& index);
|
||||||
|
|
||||||
void addResourceToDialog(ModPlatform::IndexedPack::Ptr, ModPlatform::IndexedVersion&);
|
void addResourceToDialog(ModPlatform::IndexedPack::Ptr, ModPlatform::IndexedVersion&);
|
||||||
void removeResourceFromDialog(const QString& pack_name);
|
void removeResourceFromDialog(const QString& pack_name);
|
||||||
virtual void removeResourceFromPage(const QString& name);
|
virtual void removeResourceFromPage(const QString& name);
|
||||||
virtual void addResourceToPage(ModPlatform::IndexedPack::Ptr, ModPlatform::IndexedVersion&, std::shared_ptr<ResourceFolderModel>);
|
virtual void addResourceToPage(ModPlatform::IndexedPack::Ptr, ModPlatform::IndexedVersion&, std::shared_ptr<ResourceFolderModel>);
|
||||||
|
|
||||||
|
virtual void modelReset();
|
||||||
|
|
||||||
QList<DownloadTaskPtr> selectedPacks() { return m_model->selectedPacks(); }
|
QList<DownloadTaskPtr> selectedPacks() { return m_model->selectedPacks(); }
|
||||||
bool hasSelectedPacks() { return !(m_model->selectedPacks().isEmpty()); }
|
bool hasSelectedPacks() { return !(m_model->selectedPacks().isEmpty()); }
|
||||||
|
|
||||||
@ -91,6 +93,7 @@ class ResourcePage : public QWidget, public BasePage {
|
|||||||
void onSelectionChanged(QModelIndex first, QModelIndex second);
|
void onSelectionChanged(QModelIndex first, QModelIndex second);
|
||||||
void onVersionSelectionChanged(int index);
|
void onVersionSelectionChanged(int index);
|
||||||
void onResourceSelected();
|
void onResourceSelected();
|
||||||
|
void onResourceToggle(const QModelIndex& index);
|
||||||
|
|
||||||
// NOTE: Can't use [[nodiscard]] here because of https://bugreports.qt.io/browse/QTBUG-58628 on Qt 5.12
|
// NOTE: Can't use [[nodiscard]] here because of https://bugreports.qt.io/browse/QTBUG-58628 on Qt 5.12
|
||||||
|
|
||||||
@ -115,6 +118,8 @@ class ResourcePage : public QWidget, public BasePage {
|
|||||||
QTimer m_searchTimer;
|
QTimer m_searchTimer;
|
||||||
|
|
||||||
bool m_doNotJumpToMod = false;
|
bool m_doNotJumpToMod = false;
|
||||||
|
|
||||||
|
QSet<int> m_enableQueue;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ResourceDownload
|
} // namespace ResourceDownload
|
||||||
|
@ -20,13 +20,13 @@ ResourceAPI::SearchArgs ShaderPackResourceModel::createSearchArguments()
|
|||||||
return { ModPlatform::ResourceType::SHADER_PACK, m_next_search_offset, m_search_term, sort };
|
return { ModPlatform::ResourceType::SHADER_PACK, m_next_search_offset, m_search_term, sort };
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceAPI::VersionSearchArgs ShaderPackResourceModel::createVersionsArguments(QModelIndex& entry)
|
ResourceAPI::VersionSearchArgs ShaderPackResourceModel::createVersionsArguments(const QModelIndex& entry)
|
||||||
{
|
{
|
||||||
auto& pack = m_packs[entry.row()];
|
auto& pack = m_packs[entry.row()];
|
||||||
return { *pack };
|
return { *pack };
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceAPI::ProjectInfoArgs ShaderPackResourceModel::createInfoArguments(QModelIndex& entry)
|
ResourceAPI::ProjectInfoArgs ShaderPackResourceModel::createInfoArguments(const QModelIndex& entry)
|
||||||
{
|
{
|
||||||
auto& pack = m_packs[entry.row()];
|
auto& pack = m_packs[entry.row()];
|
||||||
return { *pack };
|
return { *pack };
|
||||||
|
@ -31,8 +31,8 @@ class ShaderPackResourceModel : public ResourceModel {
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
ResourceAPI::SearchArgs createSearchArguments() override;
|
ResourceAPI::SearchArgs createSearchArguments() override;
|
||||||
ResourceAPI::VersionSearchArgs createVersionsArguments(QModelIndex&) override;
|
ResourceAPI::VersionSearchArgs createVersionsArguments(const QModelIndex&) override;
|
||||||
ResourceAPI::ProjectInfoArgs createInfoArguments(QModelIndex&) override;
|
ResourceAPI::ProjectInfoArgs createInfoArguments(const QModelIndex&) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const BaseInstance& m_base_instance;
|
const BaseInstance& m_base_instance;
|
||||||
|
@ -15,10 +15,7 @@
|
|||||||
|
|
||||||
namespace ResourceDownload {
|
namespace ResourceDownload {
|
||||||
|
|
||||||
ShaderPackResourcePage::ShaderPackResourcePage(ShaderPackDownloadDialog* dialog, BaseInstance& instance) : ResourcePage(dialog, instance)
|
ShaderPackResourcePage::ShaderPackResourcePage(ShaderPackDownloadDialog* dialog, BaseInstance& instance) : ResourcePage(dialog, instance) {}
|
||||||
{
|
|
||||||
connect(m_ui->packView, &QListView::doubleClicked, this, &ShaderPackResourcePage::onResourceSelected);
|
|
||||||
}
|
|
||||||
|
|
||||||
/******** Callbacks to events in the UI (set up in the derived classes) ********/
|
/******** Callbacks to events in the UI (set up in the derived classes) ********/
|
||||||
|
|
||||||
|
@ -25,8 +25,9 @@ class ShaderPackResourcePage : public ResourcePage {
|
|||||||
auto page = new T(dialog, instance);
|
auto page = new T(dialog, instance);
|
||||||
auto model = static_cast<ShaderPackResourceModel*>(page->getModel());
|
auto model = static_cast<ShaderPackResourceModel*>(page->getModel());
|
||||||
|
|
||||||
connect(model, &ResourceModel::versionListUpdated, page, &ResourcePage::updateVersionList);
|
connect(model, &ResourceModel::versionListUpdated, page, &ResourcePage::versionListUpdated);
|
||||||
connect(model, &ResourceModel::projectInfoUpdated, page, &ResourcePage::updateUi);
|
connect(model, &ResourceModel::projectInfoUpdated, page, &ResourcePage::updateUi);
|
||||||
|
connect(model, &QAbstractListModel::modelReset, page, &ResourcePage::modelReset);
|
||||||
|
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ ResourceAPI::SearchArgs TexturePackResourceModel::createSearchArguments()
|
|||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceAPI::VersionSearchArgs TexturePackResourceModel::createVersionsArguments(QModelIndex& entry)
|
ResourceAPI::VersionSearchArgs TexturePackResourceModel::createVersionsArguments(const QModelIndex& entry)
|
||||||
{
|
{
|
||||||
auto args = ResourcePackResourceModel::createVersionsArguments(entry);
|
auto args = ResourcePackResourceModel::createVersionsArguments(entry);
|
||||||
if (!m_version_list->isLoaded()) {
|
if (!m_version_list->isLoaded()) {
|
||||||
|
@ -18,7 +18,7 @@ class TexturePackResourceModel : public ResourcePackResourceModel {
|
|||||||
[[nodiscard]] inline ::Version maximumTexturePackVersion() const { return { "1.6" }; }
|
[[nodiscard]] inline ::Version maximumTexturePackVersion() const { return { "1.6" }; }
|
||||||
|
|
||||||
ResourceAPI::SearchArgs createSearchArguments() override;
|
ResourceAPI::SearchArgs createSearchArguments() override;
|
||||||
ResourceAPI::VersionSearchArgs createVersionsArguments(QModelIndex&) override;
|
ResourceAPI::VersionSearchArgs createVersionsArguments(const QModelIndex&) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Meta::VersionList::Ptr m_version_list;
|
Meta::VersionList::Ptr m_version_list;
|
||||||
|
@ -27,8 +27,9 @@ class TexturePackResourcePage : public ResourcePackResourcePage {
|
|||||||
auto page = new T(dialog, instance);
|
auto page = new T(dialog, instance);
|
||||||
auto model = static_cast<TexturePackResourceModel*>(page->getModel());
|
auto model = static_cast<TexturePackResourceModel*>(page->getModel());
|
||||||
|
|
||||||
connect(model, &ResourceModel::versionListUpdated, page, &ResourcePage::updateVersionList);
|
connect(model, &ResourceModel::versionListUpdated, page, &ResourcePage::versionListUpdated);
|
||||||
connect(model, &ResourceModel::projectInfoUpdated, page, &ResourcePage::updateUi);
|
connect(model, &ResourceModel::projectInfoUpdated, page, &ResourcePage::updateUi);
|
||||||
|
connect(model, &QAbstractListModel::modelReset, page, &ResourcePage::modelReset);
|
||||||
|
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
@ -39,10 +40,7 @@ class TexturePackResourcePage : public ResourcePackResourcePage {
|
|||||||
[[nodiscard]] inline QString resourceString() const override { return tr("texture pack"); }
|
[[nodiscard]] inline QString resourceString() const override { return tr("texture pack"); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
TexturePackResourcePage(TexturePackDownloadDialog* dialog, BaseInstance& instance) : ResourcePackResourcePage(dialog, instance)
|
TexturePackResourcePage(TexturePackDownloadDialog* dialog, BaseInstance& instance) : ResourcePackResourcePage(dialog, instance) {}
|
||||||
{
|
|
||||||
connect(m_ui->packView, &QListView::doubleClicked, this, &TexturePackResourcePage::onResourceSelected);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ResourceDownload
|
} // namespace ResourceDownload
|
||||||
|
@ -82,8 +82,6 @@ QVariant ListModel::data(const QModelIndex& index, int role) const
|
|||||||
return pack.name;
|
return pack.name;
|
||||||
case UserDataTypes::DESCRIPTION:
|
case UserDataTypes::DESCRIPTION:
|
||||||
return pack.description;
|
return pack.description;
|
||||||
case UserDataTypes::SELECTED:
|
|
||||||
return false;
|
|
||||||
case UserDataTypes::INSTALLED:
|
case UserDataTypes::INSTALLED:
|
||||||
return false;
|
return false;
|
||||||
default:
|
default:
|
||||||
|
@ -65,8 +65,6 @@ QVariant ListModel::data(const QModelIndex& index, int role) const
|
|||||||
return pack.name;
|
return pack.name;
|
||||||
case UserDataTypes::DESCRIPTION:
|
case UserDataTypes::DESCRIPTION:
|
||||||
return pack.description;
|
return pack.description;
|
||||||
case UserDataTypes::SELECTED:
|
|
||||||
return false;
|
|
||||||
case UserDataTypes::INSTALLED:
|
case UserDataTypes::INSTALLED:
|
||||||
return false;
|
return false;
|
||||||
default:
|
default:
|
||||||
|
@ -122,7 +122,7 @@ ResourceAPI::SearchArgs FlameTexturePackModel::createSearchArguments()
|
|||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceAPI::VersionSearchArgs FlameTexturePackModel::createVersionsArguments(QModelIndex& entry)
|
ResourceAPI::VersionSearchArgs FlameTexturePackModel::createVersionsArguments(const QModelIndex& entry)
|
||||||
{
|
{
|
||||||
auto args = TexturePackResourceModel::createVersionsArguments(entry);
|
auto args = TexturePackResourceModel::createVersionsArguments(entry);
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ class FlameTexturePackModel : public TexturePackResourceModel {
|
|||||||
void loadIndexedPackVersions(ModPlatform::IndexedPack& m, QJsonArray& arr) override;
|
void loadIndexedPackVersions(ModPlatform::IndexedPack& m, QJsonArray& arr) override;
|
||||||
|
|
||||||
ResourceAPI::SearchArgs createSearchArguments() override;
|
ResourceAPI::SearchArgs createSearchArguments() override;
|
||||||
ResourceAPI::VersionSearchArgs createVersionsArguments(QModelIndex&) override;
|
ResourceAPI::VersionSearchArgs createVersionsArguments(const QModelIndex&) override;
|
||||||
|
|
||||||
auto documentToArray(QJsonDocument& obj) const -> QJsonArray override;
|
auto documentToArray(QJsonDocument& obj) const -> QJsonArray override;
|
||||||
};
|
};
|
||||||
|
@ -125,8 +125,6 @@ QVariant ListModel::data(const QModelIndex& index, int role) const
|
|||||||
return pack.name;
|
return pack.name;
|
||||||
case UserDataTypes::DESCRIPTION:
|
case UserDataTypes::DESCRIPTION:
|
||||||
return tr("Minecraft %1").arg(pack.mcVersion);
|
return tr("Minecraft %1").arg(pack.mcVersion);
|
||||||
case UserDataTypes::SELECTED:
|
|
||||||
return false;
|
|
||||||
case UserDataTypes::INSTALLED:
|
case UserDataTypes::INSTALLED:
|
||||||
return false;
|
return false;
|
||||||
default:
|
default:
|
||||||
|
@ -195,8 +195,6 @@ QVariant ListModel::data(const QModelIndex& index, int role) const
|
|||||||
return pack.name;
|
return pack.name;
|
||||||
case UserDataTypes::DESCRIPTION:
|
case UserDataTypes::DESCRIPTION:
|
||||||
return pack.description;
|
return pack.description;
|
||||||
case UserDataTypes::SELECTED:
|
|
||||||
return false;
|
|
||||||
case UserDataTypes::INSTALLED:
|
case UserDataTypes::INSTALLED:
|
||||||
return false;
|
return false;
|
||||||
default:
|
default:
|
||||||
|
@ -106,8 +106,6 @@ auto ModpackListModel::data(const QModelIndex& index, int role) const -> QVarian
|
|||||||
return pack.name;
|
return pack.name;
|
||||||
case UserDataTypes::DESCRIPTION:
|
case UserDataTypes::DESCRIPTION:
|
||||||
return pack.description;
|
return pack.description;
|
||||||
case UserDataTypes::SELECTED:
|
|
||||||
return false;
|
|
||||||
case UserDataTypes::INSTALLED:
|
case UserDataTypes::INSTALLED:
|
||||||
return false;
|
return false;
|
||||||
default:
|
default:
|
||||||
|
@ -89,8 +89,6 @@ QVariant Technic::ListModel::data(const QModelIndex& index, int role) const
|
|||||||
return pack.name;
|
return pack.name;
|
||||||
case UserDataTypes::DESCRIPTION:
|
case UserDataTypes::DESCRIPTION:
|
||||||
return pack.description;
|
return pack.description;
|
||||||
case UserDataTypes::SELECTED:
|
|
||||||
return false;
|
|
||||||
case UserDataTypes::INSTALLED:
|
case UserDataTypes::INSTALLED:
|
||||||
return false;
|
return false;
|
||||||
default:
|
default:
|
||||||
|
@ -18,6 +18,10 @@
|
|||||||
|
|
||||||
#include "HintOverrideProxyStyle.h"
|
#include "HintOverrideProxyStyle.h"
|
||||||
|
|
||||||
|
HintOverrideProxyStyle::HintOverrideProxyStyle(QStyle* style) : QProxyStyle(style) {
|
||||||
|
setObjectName(style->objectName());
|
||||||
|
}
|
||||||
|
|
||||||
int HintOverrideProxyStyle::styleHint(QStyle::StyleHint hint,
|
int HintOverrideProxyStyle::styleHint(QStyle::StyleHint hint,
|
||||||
const QStyleOption* option,
|
const QStyleOption* option,
|
||||||
const QWidget* widget,
|
const QWidget* widget,
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
class HintOverrideProxyStyle : public QProxyStyle {
|
class HintOverrideProxyStyle : public QProxyStyle {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
HintOverrideProxyStyle(QStyle* style) : QProxyStyle(style) {}
|
explicit HintOverrideProxyStyle(QStyle* style);
|
||||||
|
|
||||||
int styleHint(QStyle::StyleHint hint,
|
int styleHint(QStyle::StyleHint hint,
|
||||||
const QStyleOption* option = nullptr,
|
const QStyleOption* option = nullptr,
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
#include "ProjectItem.h"
|
#include "ProjectItem.h"
|
||||||
|
|
||||||
#include "Common.h"
|
#include <QApplication>
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include "Common.h"
|
||||||
|
|
||||||
ProjectItemDelegate::ProjectItemDelegate(QWidget* parent) : QStyledItemDelegate(parent) {}
|
ProjectItemDelegate::ProjectItemDelegate(QWidget* parent) : QStyledItemDelegate(parent) {}
|
||||||
|
|
||||||
@ -14,13 +16,20 @@ void ProjectItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o
|
|||||||
QStyleOptionViewItem opt(option);
|
QStyleOptionViewItem opt(option);
|
||||||
initStyleOption(&opt, index);
|
initStyleOption(&opt, index);
|
||||||
|
|
||||||
|
const QStyle* style = opt.widget == nullptr ? QApplication::style() : opt.widget->style();
|
||||||
|
|
||||||
auto rect = opt.rect;
|
auto rect = opt.rect;
|
||||||
|
|
||||||
if (opt.state & QStyle::State_Selected) {
|
style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
|
||||||
painter->fillRect(rect, opt.palette.highlight());
|
|
||||||
|
if (option.state & QStyle::State_Selected && style->objectName() != "windowsvista")
|
||||||
painter->setPen(opt.palette.highlightedText().color());
|
painter->setPen(opt.palette.highlightedText().color());
|
||||||
} else if (opt.state & QStyle::State_MouseOver) {
|
|
||||||
painter->fillRect(rect, opt.palette.window());
|
if (opt.features & QStyleOptionViewItem::HasCheckIndicator) {
|
||||||
|
QStyleOptionViewItem checkboxOpt = makeCheckboxStyleOption(opt, style);
|
||||||
|
style->drawPrimitive(QStyle::PE_IndicatorItemViewItemCheck, &checkboxOpt, painter, opt.widget);
|
||||||
|
|
||||||
|
rect.setX(checkboxOpt.rect.right());
|
||||||
}
|
}
|
||||||
|
|
||||||
// The default icon size will be a square (and height is usually the lower value).
|
// The default icon size will be a square (and height is usually the lower value).
|
||||||
@ -42,6 +51,9 @@ void ProjectItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o
|
|||||||
int x = rect.x() + icon_x_margin;
|
int x = rect.x() + icon_x_margin;
|
||||||
int y = rect.y() + icon_y_margin;
|
int y = rect.y() + icon_y_margin;
|
||||||
|
|
||||||
|
if (opt.features & QStyleOptionViewItem::HasCheckIndicator)
|
||||||
|
rect.translate(icon_x_margin / 2, 0);
|
||||||
|
|
||||||
// Prevent 'scaling null pixmap' warnings
|
// Prevent 'scaling null pixmap' warnings
|
||||||
if (icon_width > 0 && icon_height > 0)
|
if (icon_width > 0 && icon_height > 0)
|
||||||
opt.icon.paint(painter, x, y, icon_width, icon_height);
|
opt.icon.paint(painter, x, y, icon_width, icon_height);
|
||||||
@ -56,26 +68,12 @@ void ProjectItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o
|
|||||||
{ // Title painting
|
{ // Title painting
|
||||||
auto title = index.data(UserDataTypes::TITLE).toString();
|
auto title = index.data(UserDataTypes::TITLE).toString();
|
||||||
|
|
||||||
|
if (index.data(UserDataTypes::INSTALLED).toBool())
|
||||||
|
title = tr("%1 [installed]").arg(title);
|
||||||
|
|
||||||
painter->save();
|
painter->save();
|
||||||
|
|
||||||
auto font = opt.font;
|
auto font = opt.font;
|
||||||
if (index.data(UserDataTypes::SELECTED).toBool()) {
|
|
||||||
// Set nice font
|
|
||||||
font.setBold(true);
|
|
||||||
font.setUnderline(true);
|
|
||||||
}
|
|
||||||
if (index.data(UserDataTypes::INSTALLED).toBool()) {
|
|
||||||
auto hRect = opt.rect;
|
|
||||||
hRect.setX(hRect.x() + 1);
|
|
||||||
hRect.setY(hRect.y() + 1);
|
|
||||||
hRect.setHeight(hRect.height() - 2);
|
|
||||||
hRect.setWidth(hRect.width() - 2);
|
|
||||||
// Set nice font
|
|
||||||
font.setItalic(true);
|
|
||||||
font.setOverline(true);
|
|
||||||
painter->drawRect(hRect);
|
|
||||||
}
|
|
||||||
|
|
||||||
font.setPointSize(font.pointSize() + 2);
|
font.setPointSize(font.pointSize() + 2);
|
||||||
painter->setFont(font);
|
painter->setFont(font);
|
||||||
|
|
||||||
@ -132,3 +130,56 @@ void ProjectItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o
|
|||||||
|
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ProjectItemDelegate::editorEvent(QEvent* event,
|
||||||
|
QAbstractItemModel* model,
|
||||||
|
const QStyleOptionViewItem& option,
|
||||||
|
const QModelIndex& index)
|
||||||
|
{
|
||||||
|
if (!(event->type() == QEvent::MouseButtonRelease || event->type() == QEvent::MouseButtonPress ||
|
||||||
|
event->type() == QEvent::MouseButtonDblClick))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
auto mouseEvent = (QMouseEvent*)event;
|
||||||
|
|
||||||
|
if (mouseEvent->button() != Qt::LeftButton)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
QStyleOptionViewItem opt(option);
|
||||||
|
initStyleOption(&opt, index);
|
||||||
|
|
||||||
|
const QStyle* style = opt.widget == nullptr ? QApplication::style() : opt.widget->style();
|
||||||
|
|
||||||
|
const QStyleOptionViewItem checkboxOpt = makeCheckboxStyleOption(opt, style);
|
||||||
|
|
||||||
|
if (!checkboxOpt.rect.contains(mouseEvent->x(), mouseEvent->y()))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// swallow other events
|
||||||
|
// (prevents item being selected or double click action triggering)
|
||||||
|
if (event->type() != QEvent::MouseButtonRelease)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
emit checkboxClicked(index);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStyleOptionViewItem ProjectItemDelegate::makeCheckboxStyleOption(const QStyleOptionViewItem& opt, const QStyle* style) const
|
||||||
|
{
|
||||||
|
QStyleOptionViewItem checkboxOpt = opt;
|
||||||
|
|
||||||
|
checkboxOpt.state &= ~QStyle::State_HasFocus;
|
||||||
|
|
||||||
|
if (checkboxOpt.checkState == Qt::Checked)
|
||||||
|
checkboxOpt.state |= QStyle::State_On;
|
||||||
|
else
|
||||||
|
checkboxOpt.state |= QStyle::State_Off;
|
||||||
|
|
||||||
|
QRect checkboxRect = style->subElementRect(QStyle::SE_ItemViewItemCheckIndicator, &checkboxOpt, opt.widget);
|
||||||
|
// 5px is the typical top margin for image
|
||||||
|
// we don't want the checkboxes to be all over the place :)
|
||||||
|
checkboxOpt.rect = QRect(opt.rect.x() + 5, opt.rect.y() + (opt.rect.height() / 2 - checkboxRect.height() / 2), checkboxRect.width(),
|
||||||
|
checkboxRect.height());
|
||||||
|
|
||||||
|
return checkboxOpt;
|
||||||
|
}
|
||||||
|
@ -6,8 +6,7 @@
|
|||||||
enum UserDataTypes {
|
enum UserDataTypes {
|
||||||
TITLE = 257, // QString
|
TITLE = 257, // QString
|
||||||
DESCRIPTION = 258, // QString
|
DESCRIPTION = 258, // QString
|
||||||
SELECTED = 259, // bool
|
INSTALLED = 259 // bool
|
||||||
INSTALLED = 260 // bool
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** This is an item delegate composed of:
|
/** This is an item delegate composed of:
|
||||||
@ -22,4 +21,12 @@ class ProjectItemDelegate final : public QStyledItemDelegate {
|
|||||||
ProjectItemDelegate(QWidget* parent);
|
ProjectItemDelegate(QWidget* parent);
|
||||||
|
|
||||||
void paint(QPainter*, const QStyleOptionViewItem&, const QModelIndex&) const override;
|
void paint(QPainter*, const QStyleOptionViewItem&, const QModelIndex&) const override;
|
||||||
|
|
||||||
|
bool editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index) override;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void checkboxClicked(const QModelIndex& index);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QStyleOptionViewItem makeCheckboxStyleOption(const QStyleOptionViewItem& opt, const QStyle* style) const;
|
||||||
};
|
};
|
||||||
|
@ -43,8 +43,8 @@ class DummyResourceModel : public ResourceModel {
|
|||||||
[[nodiscard]] auto metaEntryBase() const -> QString override { return ""; }
|
[[nodiscard]] auto metaEntryBase() const -> QString override { return ""; }
|
||||||
|
|
||||||
ResourceAPI::SearchArgs createSearchArguments() override { return {}; }
|
ResourceAPI::SearchArgs createSearchArguments() override { return {}; }
|
||||||
ResourceAPI::VersionSearchArgs createVersionsArguments(QModelIndex&) override { return {}; }
|
ResourceAPI::VersionSearchArgs createVersionsArguments(const QModelIndex&) override { return {}; }
|
||||||
ResourceAPI::ProjectInfoArgs createInfoArguments(QModelIndex&) override { return {}; }
|
ResourceAPI::ProjectInfoArgs createInfoArguments(const QModelIndex&) override { return {}; }
|
||||||
|
|
||||||
QJsonArray documentToArray(QJsonDocument& doc) const override { return doc.object().value("hits").toArray(); }
|
QJsonArray documentToArray(QJsonDocument& doc) const override { return doc.object().value("hits").toArray(); }
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user