Commit 3f844191 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle

Add Bin sorting menu (now works in icon view)

parent 5e9b8ed0
Pipeline #12420 passed with stage
in 14 minutes and 40 seconds
......@@ -218,7 +218,7 @@ QVariant AbstractProjectItem::getData(DataType type) const
int AbstractProjectItem::supportedDataCount() const
{
return 3;
return 4;
}
QString AbstractProjectItem::name() const
......
......@@ -64,6 +64,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QDrag>
#include <QFile>
#include <QMenu>
#include <QActionGroup>
#include <QSlider>
#include <QTimeLine>
#include <QUndoCommand>
......@@ -805,6 +806,55 @@ Bin::Bin(std::shared_ptr<ProjectItemModel> model, QWidget *parent)
}
pCore->window()->actionCollection()->addAction(QStringLiteral("bin_view_mode_icon"), iconViewAction);
// Sort menu
m_sortDescend = new QAction(i18n("Descending"), this);
m_sortDescend->setCheckable(true);
m_sortDescend->setChecked(KdenliveSettings::binSorting() > 99);
connect(m_sortDescend, &QAction::triggered, [&] () {
if (m_sortGroup->checkedAction()) {
if ((m_itemView != nullptr) && m_listType == BinTreeView) {
auto *view = static_cast<QTreeView *>(m_itemView);
view->header()->setSortIndicator(m_sortGroup->checkedAction()->data().toInt(), m_sortDescend->isChecked() ? Qt::DescendingOrder : Qt::AscendingOrder);
} else {
m_proxyModel->sort(m_sortGroup->checkedAction()->data().toInt(), m_sortDescend->isChecked() ? Qt::DescendingOrder : Qt::AscendingOrder);
}
}
});
QMenu *sort = new QMenu(i18n("Sort By"), this);
int binSort = KdenliveSettings::binSorting() % 100;
m_sortGroup = new QActionGroup(sort);
QAction *sortByName = new QAction(i18n("Name"), m_sortGroup);
sortByName->setCheckable(true);
sortByName->setData(0);
sortByName->setChecked(binSort == 0);
QAction *sortByDate = new QAction(i18n("Date"), m_sortGroup);
sortByDate->setCheckable(true);
sortByDate->setData(1);
sortByDate->setChecked(binSort == 1);
QAction *sortByDesc = new QAction(i18n("Description"), m_sortGroup);
sortByDesc->setCheckable(true);
sortByDesc->setData(2);
sortByDesc->setChecked(binSort == 2);
QAction *sortByType = new QAction(i18n("Type"), m_sortGroup);
sortByType->setCheckable(true);
sortByType->setData(3);
sortByType->setChecked(binSort == 3);
sort->addAction(sortByName);
sort->addAction(sortByDate);
sort->addAction(sortByType);
sort->addAction(sortByDesc);
sort->addSeparator();
sort->addAction(m_sortDescend);
connect(m_sortGroup, &QActionGroup::triggered, [&] (QAction *ac) {
if ((m_itemView != nullptr) && m_listType == BinTreeView) {
auto *view = static_cast<QTreeView *>(m_itemView);
view->header()->setSortIndicator(ac->data().toInt(), m_sortDescend->isChecked() ? Qt::DescendingOrder : Qt::AscendingOrder);
} else {
m_proxyModel->sort(ac->data().toInt(), m_sortDescend->isChecked() ? Qt::DescendingOrder : Qt::AscendingOrder);
}
});
QAction *disableEffects = new QAction(i18n("Disable Bin Effects"), this);
connect(disableEffects, &QAction::triggered, [this](bool disable) { this->setBinEffectsEnabled(!disable); });
disableEffects->setIcon(QIcon::fromTheme(QStringLiteral("favorite")));
......@@ -823,6 +873,7 @@ Bin::Bin(std::shared_ptr<ProjectItemModel> model, QWidget *parent)
sliderMenu->setIcon(QIcon::fromTheme(QStringLiteral("zoom-in")));
sliderMenu->addAction(widgetslider);
settingsMenu->addMenu(sliderMenu);
settingsMenu->addMenu(sort);
// Column show / hide actions
m_showDate = new QAction(i18n("Show date"), this);
......@@ -1018,6 +1069,21 @@ void Bin::slotSaveHeaders()
auto *view = static_cast<QTreeView *>(m_itemView);
m_headerInfo = view->header()->saveState();
KdenliveSettings::setTreeviewheaders(m_headerInfo.toBase64());
int ix = view->header()->sortIndicatorSection();
updateSortingAction(ix);
m_sortDescend->setChecked(view->header()->sortIndicatorOrder() == Qt::DescendingOrder);
}
if (m_sortGroup->checkedAction()) {
KdenliveSettings::setBinSorting(m_sortGroup->checkedAction()->data().toInt() + (m_sortDescend->isChecked() ? 100 : 0));
}
}
void Bin::updateSortingAction(int ix)
{
for (QAction *ac : m_sortGroup->actions()) {
if (ac->data().toInt() == ix) {
ac->setChecked(true);
}
}
}
......@@ -1539,12 +1605,14 @@ void Bin::slotInitView(QAction *action)
connect(view, &MyTreeView::displayBinFrame, this, &Bin::showBinFrame);
if (!m_headerInfo.isEmpty()) {
view->header()->restoreState(m_headerInfo);
m_sortDescend->setChecked(view->header()->sortIndicatorOrder() == Qt::DescendingOrder);
} else {
view->header()->resizeSections(QHeaderView::ResizeToContents);
view->resizeColumnToContents(0);
view->setColumnHidden(1, true);
view->setColumnHidden(2, true);
}
view->setColumnHidden(3, true);
m_showDate->setChecked(!view->isColumnHidden(1));
m_showDesc->setChecked(!view->isColumnHidden(2));
connect(view->header(), &QHeaderView::sectionResized, this, &Bin::slotSaveHeaders);
......
......@@ -59,6 +59,7 @@ class QToolBar;
class QToolButton;
class QUndoCommand;
class QVBoxLayout;
class QActionGroup;
class SmallJobLabel;
namespace Mlt {
......@@ -388,6 +389,7 @@ private:
QAction *m_inTimelineAction;
QAction *m_showDate;
QAction *m_showDesc;
QAction *m_sortDescend;
/** @brief Default view type (icon, tree, ...) */
BinViewType m_listType;
/** @brief Default icon size for the views. */
......@@ -414,6 +416,7 @@ private:
QAction *m_discardCurrentClipJobs;
QAction *m_discardPendingJobs;
QAction *m_upAction;
QActionGroup *m_sortGroup;
SmallJobLabel *m_infoLabel;
/** @brief The info widget for failed jobs. */
KMessageWidget *m_infoMessage;
......@@ -440,6 +443,7 @@ private:
void showTitleWidget(const std::shared_ptr<ProjectClip> &clip);
void showSlideshowWidget(const std::shared_ptr<ProjectClip> &clip);
void processAudioThumbs();
void updateSortingAction(int ix);
int wheelAccumulatedDelta;
signals:
......
......@@ -88,6 +88,9 @@ int ProjectItemModel::mapToColumn(int column) const
case 2:
return AbstractProjectItem::DataDescription;
break;
case 3:
return AbstractProjectItem::ClipType;
break;
default:
return AbstractProjectItem::DataName;
}
......@@ -231,6 +234,9 @@ QVariant ProjectItemModel::headerData(int section, Qt::Orientation orientation,
case 2:
columnName = i18n("Description");
break;
case 3:
columnName = i18n("Type");
break;
default:
columnName = i18n("Unknown");
break;
......
......@@ -28,6 +28,7 @@ ProjectSortProxyModel::ProjectSortProxyModel(QObject *parent)
: QSortFilterProxyModel(parent)
{
m_collator.setNumericMode(true);
m_collator.setCaseSensitivity(Qt::CaseInsensitive);
m_selection = new QItemSelectionModel(this);
connect(m_selection, &QItemSelectionModel::selectionChanged, this, &ProjectSortProxyModel::onCurrentRowChanged);
setDynamicSortFilter(true);
......@@ -91,7 +92,6 @@ bool ProjectSortProxyModel::lessThan(const QModelIndex &left, const QModelIndex
int leftType = sourceModel()->data(left, AbstractProjectItem::ItemTypeRole).toInt();
int rightType = sourceModel()->data(right, AbstractProjectItem::ItemTypeRole).toInt();
if (leftType == rightType) {
// Let the normal alphabetical sort happen
// Let the normal alphabetical sort happen
QVariant leftData;
QVariant rightData;
......
......@@ -9,6 +9,10 @@
<label>Bin treeview headers state.</label>
<default></default>
</entry>
<entry name="binSorting" type="Int">
<label>Bin sorting column.</label>
<default>0</default>
</entry>
<entry name="binMode" type="Int">
<label>Bin view mode.</label>
<default>0</default>
......
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