Replace icon view "back" button with an "Up" icon in bin toolbar

Related to #287
parent 94c7b59e
Pipeline #11378 passed with stage
in 14 minutes and 22 seconds
......@@ -10,7 +10,6 @@ set(kdenlive_SRCS
bin/model/markerlistmodel.cpp
bin/projectclip.cpp
bin/projectfolder.cpp
bin/projectfolderup.cpp
bin/projectitemmodel.cpp
bin/projectsortproxymodel.cpp
bin/projectsubclip.cpp
......
......@@ -50,7 +50,7 @@ class AbstractProjectItem : public QObject, public TreeItem
Q_OBJECT
public:
enum PROJECTITEMTYPE { FolderUpItem = 0, FolderItem = 1, ClipItem = 2, SubClipItem = 3 };
enum PROJECTITEMTYPE { FolderItem, ClipItem, SubClipItem };
/**
* @brief Constructor.
......
......@@ -46,7 +46,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "project/projectmanager.h"
#include "projectclip.h"
#include "projectfolder.h"
#include "projectfolderup.h"
#include "projectitemmodel.h"
#include "projectsortproxymodel.h"
#include "projectsubclip.h"
......@@ -151,7 +150,7 @@ public:
int width = fm.boundingRect(r, Qt::AlignLeft | Qt::AlignTop, text).width() + option.decorationSize.width() + 2 * textMargin;
hint.setWidth(width);
int type = index.data(AbstractProjectItem::ItemTypeRole).toInt();
if (type == AbstractProjectItem::FolderItem || type == AbstractProjectItem::FolderUpItem) {
if (type == AbstractProjectItem::FolderItem) {
return QSize(hint.width(), qMin(option.fontMetrics.lineSpacing() + 4, hint.height()));
}
if (type == AbstractProjectItem::ClipItem) {
......@@ -1381,7 +1380,7 @@ std::vector<QString> Bin::selectedClipsIds(bool excludeFolders)
// We define the lambda that will be executed on each item of the subset of nodes of the tree that are selected
auto itemAdder = [excludeFolders, &ids](std::vector<QString> &ids_vec, std::shared_ptr<TreeItem> item) {
auto binItem = std::static_pointer_cast<AbstractProjectItem>(item);
if (!excludeFolders || (binItem->itemType() != AbstractProjectItem::FolderItem && binItem->itemType() != AbstractProjectItem::FolderUpItem)) {
if (!excludeFolders || binItem->itemType() != AbstractProjectItem::FolderItem) {
ids.push_back(binItem->clipId());
}
return ids_vec;
......@@ -1423,14 +1422,11 @@ void Bin::slotInitView(QAction *action)
m_headerInfo = view->header()->saveState();
m_showDate->setEnabled(true);
m_showDesc->setEnabled(true);
m_upAction->setVisible(true);
m_upAction->setEnabled(false);
} else {
// remove the current folderUp item if any
if (m_folderUp) {
if (m_folderUp->parent()) {
m_folderUp->parent()->removeChild(m_folderUp);
}
m_folderUp.reset();
}
m_upAction->setVisible(false);
}
m_listType = static_cast<BinViewType>(viewType);
}
......@@ -1441,7 +1437,6 @@ void Bin::slotInitView(QAction *action)
switch (m_listType) {
case BinIconView:
m_itemView = new MyListView(this);
m_folderUp = ProjectFolderUp::construct(m_itemModel);
m_showDate->setEnabled(false);
m_showDesc->setEnabled(false);
break;
......@@ -1647,21 +1642,8 @@ void Bin::slotItemDoubleClicked(const QModelIndex &ix, const QPoint &pos)
std::shared_ptr<AbstractProjectItem> item = m_itemModel->getBinItemByIndex(m_proxyModel->mapToSource(ix));
if (m_listType == BinIconView) {
if (item->childCount() > 0 || item->itemType() == AbstractProjectItem::FolderItem) {
m_folderUp->changeParent(std::static_pointer_cast<TreeItem>(item));
m_itemView->setRootIndex(ix);
return;
}
if (item == m_folderUp) {
std::shared_ptr<AbstractProjectItem> parentItem = item->parent();
if (parentItem->parent() != m_itemModel->getRootFolder()) {
// We are entering a parent folder
QModelIndex parentId = getIndexForId(parentItem->parent()->clipId(), parentItem->parent()->itemType() == AbstractProjectItem::FolderItem);
m_folderUp->changeParent(std::static_pointer_cast<TreeItem>(parentItem->parent()));
m_itemView->setRootIndex(m_proxyModel->mapFromSource(parentId));
} else {
m_folderUp->changeParent(std::shared_ptr<TreeItem>());
m_itemView->setRootIndex(QModelIndex());
}
m_upAction->setEnabled(true);
return;
}
} else {
......@@ -2075,11 +2057,13 @@ void Bin::setupMenu()
QAction *createFolder =
addAction(QStringLiteral("create_folder"), i18n("Create Folder"), QIcon::fromTheme(QStringLiteral("folder-new")));
connect(createFolder, &QAction::triggered, this, &Bin::slotAddFolder);
m_upAction = KStandardAction::up(this, SLOT(slotBack()), pCore->window()->actionCollection());
// Setup actions
QAction *first = m_toolbar->actions().at(0);
m_toolbar->insertAction(first, m_deleteAction);
m_toolbar->insertAction(m_deleteAction, createFolder);
m_toolbar->insertAction(createFolder, m_upAction);
auto *m = new QMenu(this);
m->addActions(addClipMenu->actions());
......@@ -2087,7 +2071,7 @@ void Bin::setupMenu()
m_addButton->setMenu(m);
m_addButton->setDefaultAction(addClip);
m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
m_toolbar->insertWidget(createFolder, m_addButton);
m_toolbar->insertWidget(m_upAction, m_addButton);
m_menu = new QMenu(this);
m_propertiesDock = pCore->window()->addDock(i18n("Clip Properties"), QStringLiteral("clip_properties"), m_propertiesPanel);
m_propertiesDock->close();
......@@ -3199,7 +3183,6 @@ void Bin::setCurrent(const std::shared_ptr<AbstractProjectItem> &item)
openProducer(subClip->getMasterClip(), zone.x(), zone.y());
break;
}
case AbstractProjectItem::FolderUpItem:
case AbstractProjectItem::FolderItem:
default:
break;
......@@ -3298,3 +3281,32 @@ QSize Bin::sizeHint() const
{
return QSize(350, pCore->window()->height() / 2);
}
void Bin::slotBack()
{
QModelIndex currentRootIx = m_itemView->rootIndex();
if (!currentRootIx.isValid()) {
return;
}
std::shared_ptr<AbstractProjectItem> item = m_itemModel->getBinItemByIndex(m_proxyModel->mapToSource(currentRootIx));
if (!item) {
qDebug()<<"=== ERRO CANNOT FIND ROOT FOR CURRENT VIEW";
return;
}
std::shared_ptr<AbstractProjectItem> parentItem = item->parent();
if (!parentItem) {
qDebug()<<"=== ERRO CANNOT FIND PARENT FOR CURRENT VIEW";
return;
}
if (parentItem != m_itemModel->getRootFolder()) {
// We are entering a parent folder
QModelIndex parentId = getIndexForId(parentItem->clipId(), parentItem->itemType() == AbstractProjectItem::FolderItem);
if (parentId.isValid()) {
m_itemView->setRootIndex(m_proxyModel->mapFromSource(parentId));
}
} else {
m_itemView->setRootIndex(QModelIndex());
m_upAction->setEnabled(false);
}
}
......@@ -49,7 +49,6 @@ class KdenliveDoc;
class Monitor;
class ProjectClip;
class ProjectFolder;
class ProjectFolderUp;
class ProjectItemModel;
class ProjectSortProxyModel;
class QDockWidget;
......@@ -266,6 +265,7 @@ public:
// TODO refac: remove this and call directly the function in ProjectItemModel
void cleanup();
private slots:
void slotAddClip();
void slotReloadClip();
......@@ -274,7 +274,8 @@ private slots:
/** @brief Show/hide date column */
void slotShowDateColumn(bool show);
void slotShowDescColumn(bool show);
/** @brief Go to parent folder */
void slotBack();
/** @brief Setup the bin view type (icon view, tree view, ...).
* @param action The action whose data defines the view type or nullptr to keep default view */
void slotInitView(QAction *action);
......@@ -376,8 +377,6 @@ protected:
private:
std::shared_ptr<ProjectItemModel> m_itemModel;
QAbstractItemView *m_itemView;
/** @brief An "Up" item that is inserted in bin when using icon view so that user can navigate up */
std::shared_ptr<ProjectFolderUp> m_folderUp;
BinItemDelegate *m_binTreeViewDelegate;
BinListItemDelegate *m_binListViewDelegate;
std::unique_ptr<ProjectSortProxyModel> m_proxyModel;
......@@ -416,6 +415,7 @@ private:
QAction *m_cancelJobs;
QAction *m_discardCurrentClipJobs;
QAction *m_discardPendingJobs;
QAction *m_upAction;
SmallJobLabel *m_infoLabel;
/** @brief The info widget for failed jobs. */
KMessageWidget *m_infoMessage;
......
/*
Copyright (C) 2015 Jean-Baptiste Mardelle <jb@kdenlive.org>
This file is part of Kdenlive. See www.kdenlive.org.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License or (at your option) version 3 or any later version
accepted by the membership of KDE e.V. (or its successor approved
by the membership of KDE e.V.), which shall act as a proxy
defined in Section 14 of version 3 of the license.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "projectfolderup.h"
#include "projectclip.h"
#include <KLocalizedString>
#include <QDomElement>
#include <utility>
ProjectFolderUp::ProjectFolderUp(const std::shared_ptr<ProjectItemModel> &model)
: AbstractProjectItem(AbstractProjectItem::FolderUpItem, QString(), model)
{
m_thumbnail = QIcon::fromTheme(QStringLiteral("go-previous"));
m_name = i18n("Back");
}
std::shared_ptr<ProjectFolderUp> ProjectFolderUp::construct(std::shared_ptr<ProjectItemModel> model)
{
std::shared_ptr<ProjectFolderUp> self(new ProjectFolderUp(std::move(model)));
baseFinishConstruct(self);
return self;
}
ProjectFolderUp::~ProjectFolderUp() = default;
std::shared_ptr<ProjectClip> ProjectFolderUp::clip(const QString &id)
{
Q_UNUSED(id)
return std::shared_ptr<ProjectClip>();
}
QString ProjectFolderUp::getToolTip() const
{
return i18n("Go up");
}
std::shared_ptr<ProjectFolder> ProjectFolderUp::folder(const QString &id)
{
Q_UNUSED(id);
return std::shared_ptr<ProjectFolder>();
}
std::shared_ptr<ProjectClip> ProjectFolderUp::clipAt(int index)
{
Q_UNUSED(index);
return std::shared_ptr<ProjectClip>();
}
void ProjectFolderUp::setBinEffectsEnabled(bool) {}
QDomElement ProjectFolderUp::toXml(QDomDocument &document, bool, bool)
{
return document.documentElement();
}
bool ProjectFolderUp::rename(const QString &, int)
{
return false;
}
ClipType::ProducerType ProjectFolderUp::clipType() const
{
return ClipType::Unknown;
}
bool ProjectFolderUp::hasAudioAndVideo() const
{
return false;
}
/*
Copyright (C) 2015 Jean-Baptiste Mardelle <jb@kdenlive.org>
This file is part of Kdenlive. See www.kdenlive.org.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License or (at your option) version 3 or any later version
accepted by the membership of KDE e.V. (or its successor approved
by the membership of KDE e.V.), which shall act as a proxy
defined in Section 14 of version 3 of the license.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PROJECTFOLDERUP_H
#define PROJECTFOLDERUP_H
#include "abstractprojectitem.h"
/**
* @class ProjectFolderUpUp
* @brief A simple "folder up" item allowing to navigate up when the bin is in icon view.
*/
class ProjectClip;
class ProjectFolderUp : public AbstractProjectItem
{
Q_OBJECT
public:
/**
* @brief Creates the supplied folder and loads its children.
* @param description element describing the folder and its children
*/
static std::shared_ptr<ProjectFolderUp> construct(std::shared_ptr<ProjectItemModel> model);
protected:
explicit ProjectFolderUp(const std::shared_ptr<ProjectItemModel> &model);
public:
~ProjectFolderUp() override;
/**
* @brief Returns the clip if it is a child (also indirect).
* @param id id of the child which should be returned
*/
std::shared_ptr<ProjectClip> clip(const QString &id) override;
/**
* @brief Returns itself or a child folder that matches the requested id.
* @param id id of the child which should be returned
*/
std::shared_ptr<ProjectFolder> folder(const QString &id) override;
/**
* @brief Returns the clip if it is a child (also indirect).
* @param index index of the child which should be returned
*/
std::shared_ptr<ProjectClip> clipAt(int index) override;
/** @brief Recursively disable/enable bin effects. */
void setBinEffectsEnabled(bool enabled) override;
/** @brief Returns an xml description of the folder. */
QDomElement toXml(QDomDocument &document, bool includeMeta = false, bool includeProfile = true) override;
QString getToolTip() const override;
bool rename(const QString &name, int column) override;
ClipType::ProducerType clipType() const override;
/** @brief Returns true if item has both audio and video enabled. */
bool hasAudioAndVideo() const override;
private:
Bin *m_bin;
};
#endif
......@@ -158,9 +158,6 @@ Qt::ItemFlags ProjectItemModel::flags(const QModelIndex &index) const
case AbstractProjectItem::SubClipItem:
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled;
break;
case AbstractProjectItem::FolderUpItem:
return Qt::ItemIsEnabled;
break;
default:
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
}
......
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