Skip to content

Commit

Permalink
Add download URLs API to page action
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasKroes committed Dec 17, 2024
1 parent 5d7465b commit 3f94928
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 11 deletions.
6 changes: 3 additions & 3 deletions ManiVault/src/PluginFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,21 @@ class CORE_EXPORT PluginFactory : public QObject
* Set plugin global settings group action to \p pluginGlobalSettingsGroupAction
* @param pluginGlobalSettingsGroupAction Pointer to plugin global settings group action (maybe a nullptr)
*/
virtual void setGlobalSettingsGroupAction(gui::PluginGlobalSettingsGroupAction* pluginGlobalSettingsGroupAction) final;
void setGlobalSettingsGroupAction(gui::PluginGlobalSettingsGroupAction* pluginGlobalSettingsGroupAction);

public: // Status bar

/**
* Get plugin status bar action
* @return Pointer to plugin status bar action (maybe nullptr)
*/
virtual gui::PluginStatusBarAction* getStatusBarAction() const final;
gui::PluginStatusBarAction* getStatusBarAction() const;

/**
* Set plugin status bar action to \p statusBarAction
* @param statusBarAction Pointer to plugin status bar action (maybe a nullptr)
*/
virtual void setStatusBarAction(gui::PluginStatusBarAction* statusBarAction) final;
void setStatusBarAction(gui::PluginStatusBarAction* statusBarAction);

public: // Help

Expand Down
1 change: 0 additions & 1 deletion ManiVault/src/private/FileMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include <Application.h>
#include <CoreInterface.h>
#include <AbstractWorkspaceManager.h>
#include <QOperatingSystemVersion>

#define TEST_STYLESHEET
Expand Down
1 change: 1 addition & 0 deletions ManiVault/src/private/PageAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ void PageAction::setEditorData(const QModelIndex& index)
setSubtitle(index.siblingAtColumn(static_cast<int>(PageActionsModel::Column::Subtitle)).data(Qt::EditRole).toString());
setMetaData(index.siblingAtColumn(static_cast<int>(PageActionsModel::Column::MetaData)).data(Qt::EditRole).toString());
setPreviewImage(index.siblingAtColumn(static_cast<int>(PageActionsModel::Column::PreviewImage)).data(Qt::UserRole + 1).value<QImage>());
setDownloadUrls(index.siblingAtColumn(static_cast<int>(PageActionsModel::Column::DownloadUrls)).data(Qt::EditRole).toStringList());
setContributors(index.siblingAtColumn(static_cast<int>(PageActionsModel::Column::Contributors)).data(Qt::UserRole + 1).toStringList());
}

Expand Down
6 changes: 5 additions & 1 deletion ManiVault/src/private/PageAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ class PageAction final
QStringList getContributors() const { return _contributors; }
void setContributors(const QStringList& contributors) { _contributors = contributors; }

QStringList getDownloadUrls() const { return _downloadUrls; }
void setDownloadUrls(const QStringList& downloadUrls) { _downloadUrls = downloadUrls; }

ClickedCallback getClickedCallback() const { return _clickedCallback; }
void setClickedCallback(const ClickedCallback& clickedCallback) { _clickedCallback = clickedCallback; }

Expand Down Expand Up @@ -107,10 +110,11 @@ class PageAction final
QString _comments; /** Comments are show on the top right */
QStringList _tags; /** Tags (might be empty) */
QString _subtitle; /** Subtitle */
QString _metaData; /** Meta data (might be empty) */
QString _metaData; /** Metadata (might be empty) */
QImage _previewImage; /** Preview image (might be empty) */
QString _tooltip; /** Tooltip (might be empty) */
QStringList _contributors; /** List of contributors */
QStringList _downloadUrls; /** Action download URLs */
ClickedCallback _clickedCallback; /** Callback function that is called when the action row is clicked */

static bool compactView;
Expand Down
28 changes: 27 additions & 1 deletion ManiVault/src/private/PageActionDelegateEditorWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ PageActionDelegateEditorWidget::PageActionDelegateEditorWidget(QWidget* parent /
_previewIconLabel(Application::getIconFont("FontAwesome").getIcon("image")),
_metaDataIconLabel(Application::getIconFont("FontAwesome").getIcon("file-alt")),
_tagsIconLabel(Application::getIconFont("FontAwesome").getIcon("tags")),
_downloadUrls(Application::getIconFont("FontAwesome").getIcon("download")),
_contributorsIconLabel(Application::getIconFont("FontAwesome").getIcon("user"))
{
setObjectName("PageActionDelegateEditorWidget");
Expand Down Expand Up @@ -60,6 +61,7 @@ PageActionDelegateEditorWidget::PageActionDelegateEditorWidget(QWidget* parent /
_infoLayout.addWidget(&_previewIconLabel);
_infoLayout.addWidget(&_metaDataIconLabel);
_infoLayout.addWidget(&_tagsIconLabel);
_infoLayout.addWidget(&_downloadUrls);
_infoLayout.addWidget(&_contributorsIconLabel);
_infoLayout.addStretch(1);

Expand All @@ -79,6 +81,7 @@ PageActionDelegateEditorWidget::PageActionDelegateEditorWidget(QWidget* parent /
_infoLayout.addWidget(&_previewIconLabel);
_infoLayout.addWidget(&_metaDataIconLabel);
_infoLayout.addWidget(&_tagsIconLabel);
_infoLayout.addWidget(&_downloadUrls);
_infoLayout.addWidget(&_contributorsIconLabel);
_infoLayout.addStretch(1);

Expand All @@ -103,7 +106,7 @@ PageActionDelegateEditorWidget::PageActionDelegateEditorWidget(QWidget* parent /

_previewIconLabel.setTooltipCallback([this, getTooltipHtml]() -> QString {
if (!_index.isValid())
return QString();
return {};

PageAction pageAction(_index);

Expand Down Expand Up @@ -163,6 +166,28 @@ PageActionDelegateEditorWidget::PageActionDelegateEditorWidget(QWidget* parent /
return getTooltipHtml(tagsHtml);
});

_downloadUrls.setTooltipCallback([this, getTooltipHtml]() -> QString {
if (!_index.isValid())
return {};

PageAction pageAction(_index);

const auto downloadUrls = pageAction.getDownloadUrls();

QStringList downloads;

for (const auto& downloadUrl : downloadUrls)
downloads << QString("<p>%1</p>").arg(downloadUrl);

if (downloadUrls.size() == 1)
return getTooltipHtml(QString("<p><b>One download from: </b></p>%1").arg(downloads.first()));

if (downloadUrls.size() > 1)
return getTooltipHtml(QString("<p><b>%1 downloads from: </b></p>%2").arg(QString::number(downloadUrls.size()), downloadUrls.join("</br>")));

return {};
});

_contributorsIconLabel.setTooltipCallback([this, getTooltipHtml]() -> QString {
if (!_index.isValid())
return {};
Expand Down Expand Up @@ -195,6 +220,7 @@ void PageActionDelegateEditorWidget::setEditorData(const QModelIndex& index)

_previewIconLabel.setVisible(!pageAction.getPreviewImage().isNull());
_tagsIconLabel.setVisible(!pageAction.getTags().isEmpty());
_downloadUrls.setVisible(!pageAction.getDownloadUrls().isEmpty());
_contributorsIconLabel.setVisible(!pageAction.getContributors().isEmpty());
}

Expand Down
3 changes: 2 additions & 1 deletion ManiVault/src/private/PageActionDelegateEditorWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,14 @@ class PageActionDelegateEditorWidget : public QWidget
QVBoxLayout _textLayout; /** Right text layout */
QHBoxLayout _primaryTextLayout; /** Primary layout with title and comments labels */
QLabel _titleLabel; /** Title label */
QLabel _metaDataLabel; /** Label with meta data (may be empty) */
QLabel _metaDataLabel; /** Label with metadata (maybe empty) */
QHBoxLayout _secondaryTextLayout; /** Secondary layout with subtitle and info labels */
QLabel _subtitleLabel; /** Subtitle label */
QWidget _infoWidget; /** Widget for info labels */
QHBoxLayout _infoLayout; /** Layout for preview, tags and meta info popups */
mv::gui::IconLabel _previewIconLabel; /** Icon label for preview image */
mv::gui::IconLabel _metaDataIconLabel; /** Icon label for meta data */
mv::gui::IconLabel _tagsIconLabel; /** Icon label for tags */
mv::gui::IconLabel _downloadUrls; /** Icon label for requires download */
mv::gui::IconLabel _contributorsIconLabel; /** Icon label for contributors */
};
3 changes: 3 additions & 0 deletions ManiVault/src/private/PageActionsModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ QMap<PageActionsModel::Column, QPair<QString, QString>> PageActionsModel::column
{ Column::MetaData, { "Meta Data", "Meta Data" }},
{ Column::PreviewImage, { "Preview", "Preview image" }},
{ Column::Tooltip, { "Tooltip", "Tooltip" }},
{ Column::DownloadUrls, { "Download URLs", "Download URLs" }},
{ Column::Contributors, { "Contributors", "Contributors" }},
{ Column::ClickedCallback, { "Clicked Callback", "Callback which is called when the action is clicked" }},
{ Column::SummaryDelegate, { "Summary", "Delegate item with title and subtitle" }}
Expand Down Expand Up @@ -55,6 +56,7 @@ void PageActionsModel::add(const PageAction& pageAction)
new QStandardItem(pageAction.getMetaData()),
new QStandardItem(),
new QStandardItem(pageAction.getTooltip()),
new QStandardItem(pageAction.getDownloadUrls().join(", ")),
new QStandardItem(),
new QStandardItem(),
new QStandardItem()
Expand All @@ -64,6 +66,7 @@ void PageActionsModel::add(const PageAction& pageAction)
pageActionRow[static_cast<int>(Column::Tags)]->setData(QVariant::fromValue(pageAction.getTags()), Qt::EditRole);
pageActionRow[static_cast<int>(Column::PreviewImage)]->setData(QVariant::fromValue(pageAction.getPreviewImage()));
pageActionRow[static_cast<int>(Column::Contributors)]->setData(QVariant::fromValue(pageAction.getContributors()));
pageActionRow[static_cast<int>(Column::DownloadUrls)]->setData(QVariant::fromValue(pageAction.getDownloadUrls()), Qt::EditRole);
pageActionRow[static_cast<int>(Column::ClickedCallback)]->setData(QVariant::fromValue(pageAction.getClickedCallback()));

for (auto item : pageActionRow)
Expand Down
9 changes: 5 additions & 4 deletions ManiVault/src/private/PageActionsModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ class PageActionsModel final : public QStandardItemModel
enum class Column {
Icon, /** Icon */
Title, /** Title */
Description, /** Description (may be empty) */
Comments, /** Comments (may be empty) */
Tags, /** Tags (may be empty) */
Subtitle, /** Sub title */
Description, /** Description (maybe empty) */
Comments, /** Comments (maybe empty) */
Tags, /** Tags (maybe empty) */
Subtitle, /** Subtitle */
MetaData, /** Meta information */
PreviewImage, /** Action preview image */
Tooltip, /** Action tooltip */
Contributors, /** Action contributors */
DownloadUrls, /** Download URLs */
ClickedCallback, /** Callback which is called when the action is clicked */
SummaryDelegate /** Delegate item with title and subtitle */
};
Expand Down
1 change: 1 addition & 0 deletions ManiVault/src/private/PageActionsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ PageActionsWidget::PageActionsWidget(QWidget* parent, const QString& title, bool
treeView.setColumnHidden(static_cast<int>(PageActionsModel::Column::MetaData), true);
treeView.setColumnHidden(static_cast<int>(PageActionsModel::Column::PreviewImage), true);
treeView.setColumnHidden(static_cast<int>(PageActionsModel::Column::Tooltip), true);
treeView.setColumnHidden(static_cast<int>(PageActionsModel::Column::DownloadUrls), true);
treeView.setColumnHidden(static_cast<int>(PageActionsModel::Column::Contributors), true);
treeView.setColumnHidden(static_cast<int>(PageActionsModel::Column::ClickedCallback), true);

Expand Down
1 change: 1 addition & 0 deletions ManiVault/src/private/PageTutorialsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ void PageTutorialsWidget::updateActions()

tutorialAction.setComments(tutorial->hasProject() ? QString("A tutorial project will be downloaded from: %1.").arg(tutorial->getProject()) : "Creates a project with a tutorial plugin.");
tutorialAction.setTags(tutorial->getTags());
tutorialAction.setDownloadUrls({ tutorial->getProject() });

getModel().add(tutorialAction);
}
Expand Down

0 comments on commit 3f94928

Please sign in to comment.