Prepare assets for favorite selection (wip)

parent b26de129
......@@ -72,6 +72,7 @@ protected:
double version;
QDomElement xml;
AssetType type;
bool favorite = false;
};
// Reads the blacklist file and populate appropriate structure
......@@ -79,6 +80,7 @@ protected:
void init();
virtual Mlt::Properties *retrieveListFromMlt() = 0;
virtual void parseFavorites() = 0;
/* @brief Parse some info from a mlt structure
@param res Datastructure to fill
......@@ -112,6 +114,7 @@ protected:
std::unordered_map<QString, Info> m_assets;
QSet<QString> m_blacklist;
QSet<QString> m_favorites;
};
#include "abstractassetsrepository.ipp"
......
......@@ -44,6 +44,7 @@ template <typename AssetType> void AbstractAssetsRepository<AssetType>::init()
// Parse effects blacklist
parseBlackList(assetBlackListPath());
parseFavorites();
// Retrieve the list of MLT's available assets.
QScopedPointer<Mlt::Properties> assets(retrieveListFromMlt());
......@@ -174,10 +175,10 @@ template <typename AssetType> QString AbstractAssetsRepository<AssetType>::getDe
return m_assets.at(assetId).description;
}
template <typename AssetType> bool AbstractAssetsRepository<AssetType>::isFavorite(const QString & /*assetId*/) const
template <typename AssetType> bool AbstractAssetsRepository<AssetType>::isFavorite(const QString & assetId) const
{
// TODO
return true;
Q_ASSERT(m_assets.count(assetId) > 0);
return m_assets.at(assetId).favorite;
}
template <typename AssetType> bool AbstractAssetsRepository<AssetType>::parseInfoFromXml(const QDomElement &currentAsset, Info &res) const
......
......@@ -54,6 +54,25 @@ QString AssetTreeModel::getName(const QModelIndex &index) const
return item->dataColumn(AssetTreeModel::nameCol).toString();
}
bool AssetTreeModel::isFavorite(const QModelIndex &index) const
{
if (!index.isValid()) {
return false;
}
std::shared_ptr<TreeItem> item = getItemById((int)index.internalId());
if (item->depth() == 1) {
return false;
}
auto id = item->dataColumn(AssetTreeModel::idCol).toString();
if (EffectsRepository::get()->exists(id)) {
return EffectsRepository::get()->isFavorite(id);
}
if (TransitionsRepository::get()->exists(id)) {
return TransitionsRepository::get()->isFavorite(id);
}
return false;
}
QString AssetTreeModel::getDescription(const QModelIndex &index) const
{
if (!index.isValid()) {
......
......@@ -39,6 +39,8 @@ public:
QString getName(const QModelIndex &index) const;
// Helper function to retrieve description
QString getDescription(const QModelIndex &index) const;
// Helper function to retrieve if an effect is categorized as favorite
bool isFavorite(const QModelIndex &index) const;
QHash<int, QByteArray> roleNames() const override;
QVariant data(const QModelIndex &index, int role) const override;
......
......@@ -60,6 +60,11 @@ QString AssetListWidget::getName(const QModelIndex &index) const
return m_model->getName(m_proxyModel->mapToSource(index));
}
bool AssetListWidget::isFavorite(const QModelIndex &index) const
{
return m_model->isFavorite(m_proxyModel->mapToSource(index));
}
QString AssetListWidget::getDescription(const QModelIndex &index) const
{
return m_model->getDescription(m_proxyModel->mapToSource(index));
......
......@@ -45,6 +45,9 @@ public:
/* @brief Returns the name of the asset given its model index */
QString getName(const QModelIndex &index) const;
/* @brief Returns true if this effect belongs to favorites */
bool isFavorite(const QModelIndex &index) const;
/* @brief Returns the description of the asset given its model index */
QString getDescription(const QModelIndex &index) const;
......
......@@ -257,18 +257,38 @@ Rectangle {
text: assetlist.getName(styleData.index)
}
}
Menu {
id: assetContextMenu
MenuItem {
text: "Add to favorites"
onTriggered: {
console.log('Asset selected: ', styleData.value, ' Fav: ', assetlist.isFavorite(styleData.index))
}
}
}
MouseArea {
id: dragArea
anchors.fill: parent
hoverEnabled: true
drag.target: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton
drag.target: undefined
onReleased: {
drag.target = undefined
}
onPressed: {
if (isItem) {
parent.grabToImage(function(result) {
parent.Drag.imageSource = result.url
})
sel.setCurrentIndex(styleData.index, ItemSelectionModel.ClearAndSelect)
if (mouse.button === Qt.LeftButton) {
drag.target = parent
parent.grabToImage(function(result) {
parent.Drag.imageSource = result.url
})
} else {
console.log('left mouse pressed!!')
drag.target = undefined
assetContextMenu.popup()
}
console.log(parent.Drag.keys)
} else {
if (treeView.isExpanded(styleData.index)) {
......
......@@ -80,19 +80,38 @@ QImage AssetIconProvider::makeIcon(const QString &effectId, const QString &effec
QString t = QStringLiteral("#") + QString::number(hex, 16).toUpper().left(6);
QColor col(t);
bool isAudio = false;
bool isFavorite = false;
if (m_effect) {
isAudio = EffectsRepository::get()->getType(effectId) == EffectType::Audio;
isFavorite = EffectsRepository::get()->isFavorite(effectId);
} else {
auto type = TransitionsRepository::get()->getType(effectId);
isAudio = (type == TransitionType::AudioComposition) || (type == TransitionType::AudioTransition);
isFavorite = TransitionsRepository::get()->isFavorite(effectId);
}
if (isAudio) {
if (isAudio || isFavorite) {
pix.fill(Qt::transparent);
} else {
pix.fill(col);
}
QPainter p(&pix);
if (isAudio) {
if (isFavorite) {
p.setPen(Qt::NoPen);
p.setBrush(col);
static const QPointF points[3] = {
QPointF(2, 23),
QPointF(15, 0),
QPointF(28, 23)
};
p.drawPolygon(points, 3);
static const QPointF points2[3] = {
QPointF(2, 8),
QPointF(15, 30),
QPointF(28, 8)
};
p.drawPolygon(points2, 3);
p.setPen(QPen());
} else if (isAudio) {
p.setPen(Qt::NoPen);
p.setBrush(col);
p.drawEllipse(pix.rect());
......
......@@ -61,7 +61,7 @@ public:
{
}
Q_INVOKABLE QString getName(const QModelIndex &index) const { return q->getName(index); }
Q_INVOKABLE int isFavorite(const QModelIndex &index) const { return q->isFavorite(index); }
Q_INVOKABLE QString getDescription(const QModelIndex &index) const { return q->getDescription(index); }
Q_INVOKABLE QVariantMap getMimeData(const QString &assetId) const { return q->getMimeData(assetId); }
......
......@@ -44,6 +44,11 @@ Mlt::Properties *EffectsRepository::retrieveListFromMlt()
return pCore->getMltRepository()->filters();
}
void EffectsRepository::parseFavorites()
{
m_favorites = {QStringLiteral("sepia")};
}
Mlt::Properties *EffectsRepository::getMetadata(const QString &effectId)
{
return pCore->getMltRepository()->metadata(filter_type, effectId.toLatin1().data());
......@@ -63,6 +68,9 @@ void EffectsRepository::parseCustomAssetFile(const QString &file_name, std::unor
info.type = EffectType::Custom;
QString tag = base.attribute(QStringLiteral("tag"), QString());
QString id = base.hasAttribute(QStringLiteral("id")) ? base.attribute(QStringLiteral("id")) : tag;
if (m_favorites.contains(id)) {
info.favorite = true;
}
QString name = base.attribute(QStringLiteral("name"), QString());
info.name = name;
......@@ -110,6 +118,9 @@ void EffectsRepository::parseCustomAssetFile(const QString &file_name, std::unor
} else {
result.type = EffectType::Video;
}
if (m_favorites.contains(result.id)) {
result.favorite = true;
}
customAssets[result.id] = result;
}
......@@ -129,11 +140,13 @@ QStringList EffectsRepository::assetDirs() const
void EffectsRepository::parseType(QScopedPointer<Mlt::Properties> &metadata, Info &res)
{
res.type = EffectType::Video;
Mlt::Properties tags((mlt_properties)metadata->get_data("tags"));
if (QString(tags.get(0)) == QLatin1String("Audio")) {
res.type = EffectType::Audio;
}
if (m_favorites.contains(res.id)) {
res.favorite = true;
}
}
QString EffectsRepository::assetBlackListPath() const
......
......@@ -55,6 +55,9 @@ protected:
/* Retrieves the list of all available effects from Mlt*/
Mlt::Properties *retrieveListFromMlt() override;
/* Retrieves the list of favorite effects */
void parseFavorites() override;
/* @brief Retrieves additional info about effects from a custom XML file
The resulting assets are stored in customAssets
*/
......
......@@ -57,7 +57,7 @@ public:
{
}
Q_INVOKABLE QString getName(const QModelIndex &index) const { return q->getName(index); }
Q_INVOKABLE bool isFavorite(const QModelIndex &index) const { return q->isFavorite(index); }
Q_INVOKABLE QString getDescription(const QModelIndex &index) const { return q->getDescription(index); }
Q_INVOKABLE QVariantMap getMimeData(const QString &assetId) const { return q->getMimeData(assetId); }
......
......@@ -45,6 +45,10 @@ Mlt::Properties *TransitionsRepository::retrieveListFromMlt()
return pCore->getMltRepository()->transitions();
}
void TransitionsRepository::parseFavorites()
{
}
Mlt::Properties *TransitionsRepository::getMetadata(const QString &assetId)
{
return pCore->getMltRepository()->metadata(transition_type, assetId.toLatin1().data());
......
......@@ -61,6 +61,9 @@ protected:
/* Retrieves the list of all available effects from Mlt*/
Mlt::Properties *retrieveListFromMlt() override;
/* Retrieves the list of favorite effects */
void parseFavorites() override;
/* @brief Retrieves additional info about effects from a custom XML file
The resulting assets are stored in customAssets
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment