bin.cpp 185 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
/*
Copyright (C) 2012  Till Theato <root@ttill.de>
Copyright (C) 2014  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
11
by the membership of KDE e.V.), which shall act as a proxy
12
13
14
15
16
17
18
19
20
21
22
23
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 "bin.h"
Nicolas Carion's avatar
Nicolas Carion committed
24
#include "bincommands.h"
25
#include "clipcreator.hpp"
Nicolas Carion's avatar
Nicolas Carion committed
26
27
28
29
30
#include "core.h"
#include "dialogs/clipcreationdialog.h"
#include "doc/documentchecker.h"
#include "doc/docundostack.hpp"
#include "doc/kdenlivedoc.h"
Nicolas Carion's avatar
Nicolas Carion committed
31
#include "effects/effectstack/model/effectstackmodel.hpp"
32
#include "jobs/audiothumbjob.hpp"
33
34
#include "jobs/jobmanager.h"
#include "jobs/loadjob.hpp"
35
#include "jobs/thumbjob.hpp"
36
#include "kdenlive_debug.h"
37
#include "kdenlivesettings.h"
Nicolas Carion's avatar
Nicolas Carion committed
38
39
40
41
42
#include "mainwindow.h"
#include "mlt++/Mlt.h"
#include "mltcontroller/clipcontroller.h"
#include "mltcontroller/clippropertiescontroller.h"
#include "monitor/monitor.h"
43
#include "project/dialogs/slideshowclip.h"
Nicolas Carion's avatar
Nicolas Carion committed
44
#include "project/invaliddialog.h"
45
#include "project/projectcommands.h"
Nicolas Carion's avatar
Nicolas Carion committed
46
47
48
49
#include "project/projectmanager.h"
#include "projectclip.h"
#include "projectfolder.h"
#include "projectitemmodel.h"
50
#include "projectsortproxymodel.h"
Nicolas Carion's avatar
Nicolas Carion committed
51
#include "projectsubclip.h"
52
#include "tagwidget.hpp"
Nicolas Carion's avatar
Nicolas Carion committed
53
54
#include "titler/titlewidget.h"
#include "ui_qtextclip_ui.h"
Nicolas Carion's avatar
Nicolas Carion committed
55
#include "undohelper.hpp"
56
#include "xml/xml.hpp"
57
#include <dialogs/textbasededit.h>
58
59
60
#include <memory>
#include <profiles/profilemodel.hpp>
#include <utils/thumbnailcache.hpp>
61

62
#include <KColorScheme>
63
#include <KRatingPainter>
64
#include <KMessageBox>
65
#include <KXMLGUIFactory>
66
#include <KIO/OpenFileManagerWindowJob>
67

68
#include <QToolBar>
Nicolas Carion's avatar
Nicolas Carion committed
69
#include <QCryptographicHash>
70
#include <QDrag>
Nicolas Carion's avatar
Nicolas Carion committed
71
#include <QFile>
72
#include <QMenu>
73
#include <QActionGroup>
Nicolas Carion's avatar
Nicolas Carion committed
74
75
#include <QSlider>
#include <QTimeLine>
76
#include <QUndoCommand>
Nicolas Carion's avatar
Nicolas Carion committed
77
78
#include <QUrl>
#include <QVBoxLayout>
Nicolas Carion's avatar
Nicolas Carion committed
79
#include <utility>
80

81
82
83
84
85
86
87
88
89
90
/**
 * @class BinItemDelegate
 * @brief This class is responsible for drawing items in the QTreeView.
 */

class BinItemDelegate : public QStyledItemDelegate
{
public:
    explicit BinItemDelegate(QObject *parent = nullptr)
        : QStyledItemDelegate(parent)
Nicolas Carion's avatar
Nicolas Carion committed
91

92
    {
93
        connect(this, &QStyledItemDelegate::closeEditor, [&]() { m_editorOpen = false; });
94
    }
95
96
97
98
99
100
101
    void setEditorData(QWidget *w, const QModelIndex &i) const override
    {
        if (!m_editorOpen) {
            QStyledItemDelegate::setEditorData(w, i);
            m_editorOpen = true;
        }
    }
102
    bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override
103
104
    {
        if (event->type() == QEvent::MouseButtonPress) {
105
            auto *me = static_cast<QMouseEvent *>(event);
106
107
108
109
110
111
112
113
            if (index.column() == 0) {
                if (m_audioDragRect.contains(me->pos())) {
                    dragType = PlaylistState::AudioOnly;
                } else if (m_videoDragRect.contains(me->pos())) {
                    dragType = PlaylistState::VideoOnly;
                } else {
                    dragType = PlaylistState::Disabled;
                }
114
115
            } else {
                dragType = PlaylistState::Disabled;
116
117
                if (index.column() == 7) {
                    // Rating
118
                    QRect rect = option.rect;
119
                    rect.adjust(option.rect.width() / 12, 0, 0, 0);
120
121
                    int rate = 0;
                    if (me->pos().x() > rect.x()) {
122
                        rate = KRatingPainter::getRatingFromPosition(rect, Qt::AlignLeft | Qt::AlignVCenter, qApp->layoutDirection(), me->pos());
123
                    }
124
125
126
127
128
                    if (rate > -1) {
                        // Full star rating only
                        if (rate %2 == 1) {
                            rate++;
                        }
129
                        emit static_cast<ProjectSortProxyModel *>(model)->updateRating(index, uint(rate));
130
131
                    }
                }
132
133
134
135
136
137
138
139
            }
        }
        event->ignore();
        return false;
    }
    void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override
    {
        if (index.column() != 0) {
140
141
            QStyledItemDelegate::updateEditorGeometry(editor, option, index);
            return;
142
143
144
145
146
        }
        QStyleOptionViewItem opt = option;
        initStyleOption(&opt, index);
        QRect r1 = option.rect;
        int type = index.data(AbstractProjectItem::ItemTypeRole).toInt();
147
        int decoWidth = 0;
148
        if (opt.decorationSize.height() > 0) {
Vincent Pinon's avatar
Vincent Pinon committed
149
            decoWidth += int(r1.height() * pCore->getCurrentDar());
150
        }
151
        int mid = 0;
152
        if (type == AbstractProjectItem::ClipItem || type == AbstractProjectItem::SubClipItem) {
153
            mid = int((r1.height() / 2));
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
        }
        r1.adjust(decoWidth, 0, 0, -mid);
        QFont ft = option.font;
        ft.setBold(true);
        QFontMetricsF fm(ft);
        QRect r2 = fm.boundingRect(r1, Qt::AlignLeft | Qt::AlignTop, index.data(AbstractProjectItem::DataName).toString()).toRect();
        editor->setGeometry(r2);
    }

    QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
    {
        QSize hint = QStyledItemDelegate::sizeHint(option, index);
        QString text = index.data(AbstractProjectItem::DataName).toString();
        QRectF r = option.rect;
        QFont ft = option.font;
        ft.setBold(true);
        QFontMetricsF fm(ft);
        QStyle *style = option.widget ? option.widget->style() : QApplication::style();
        const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
173
        int width = int(fm.boundingRect(r, Qt::AlignLeft | Qt::AlignTop, text).width() + option.decorationSize.width()) + 2 * textMargin;
174
175
        hint.setWidth(width);
        int type = index.data(AbstractProjectItem::ItemTypeRole).toInt();
176
        if (type == AbstractProjectItem::FolderItem) {
177
178
179
180
181
182
            return QSize(hint.width(), qMin(option.fontMetrics.lineSpacing() + 4, hint.height()));
        }
        if (type == AbstractProjectItem::ClipItem) {
            return QSize(hint.width(), qMax(option.fontMetrics.lineSpacing() * 2 + 4, qMax(hint.height(), option.decorationSize.height())));
        }
        if (type == AbstractProjectItem::SubClipItem) {
183
            return QSize(hint.width(), qMax(option.fontMetrics.lineSpacing() * 2 + 4, qMin(hint.height(), int(option.decorationSize.height() / 1.5))));
184
185
186
187
188
        }
        QIcon icon = qvariant_cast<QIcon>(index.data(Qt::DecorationRole));
        QString line1 = index.data(Qt::DisplayRole).toString();
        QString line2 = index.data(Qt::UserRole).toString();

Vincent Pinon's avatar
Vincent Pinon committed
189
        int textW = qMax(option.fontMetrics.horizontalAdvance(line1), option.fontMetrics.horizontalAdvance(line2));
190
        QSize iconSize = icon.actualSize(option.decorationSize);
Nicolas Carion's avatar
Nicolas Carion committed
191
        return {qMax(textW, iconSize.width()) + 4, option.fontMetrics.lineSpacing() * 2 + 4};
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
    }

    void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
    {
        if (index.column() == 0 && !index.data().isNull()) {
            QRect r1 = option.rect;
            painter->save();
            painter->setClipRect(r1);
            QStyleOptionViewItem opt(option);
            initStyleOption(&opt, index);
            int type = index.data(AbstractProjectItem::ItemTypeRole).toInt();
            QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
            const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
            // QRect r = QStyle::alignedRect(opt.direction, Qt::AlignVCenter | Qt::AlignLeft, opt.decorationSize, r1);

            style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
208
            if ((option.state & static_cast<int>(QStyle::State_Selected)) != 0) {
209
210
211
212
213
214
215
216
217
                painter->setPen(option.palette.highlightedText().color());
            } else {
                painter->setPen(option.palette.text().color());
            }
            QRect r = r1;
            QFont font = painter->font();
            font.setBold(true);
            painter->setFont(font);
            if (type == AbstractProjectItem::ClipItem || type == AbstractProjectItem::SubClipItem) {
218
                int decoWidth = 0;
219
                FileStatus::ClipStatus clipStatus = FileStatus::ClipStatus(index.data(AbstractProjectItem::ClipStatus).toInt());
220
                if (opt.decorationSize.height() > 0) {
221
                    r.setWidth(int(r.height() * pCore->getCurrentDar()));
222
                    QPixmap pix = opt.icon.pixmap(opt.icon.actualSize(r.size()));
223
224
225
226
227
228
                    if (!pix.isNull()) {
                        // Draw icon
                        decoWidth += r.width() + textMargin;
                        r.setWidth(r.height() * pix.width() / pix.height());
                        painter->drawPixmap(r, pix, QRect(0, 0, pix.width(), pix.height()));
                    }
229
                    m_thumbRect = r;
230
                }
231
                // Draw frame in case of missing source
232
                int cType = index.data(AbstractProjectItem::ClipType).toInt();
233
                if (clipStatus == FileStatus::StatusMissing || clipStatus == FileStatus::StatusProxyOnly) {
234
                    painter->save();
235
                    painter->setPen(QPen(clipStatus == FileStatus::StatusProxyOnly ? Qt::yellow : Qt::red, 3));
236
                    painter->drawRect(m_thumbRect.adjusted(0, 0, -1, -1));
237
                    painter->restore();
238
239
240
241
242
243
244
245
246
247
248
                } else if (cType == ClipType::Image || cType == ClipType::SlideShow) {
                    // Draw 'photo' frame to identify image clips
                    painter->save();
                    int penWidth = m_thumbRect.height() / 14;
                    penWidth += penWidth % 2;
                    painter->setPen(QPen(QColor(255, 255, 255, 160), penWidth));
                    penWidth /= 2;
                    painter->drawRoundedRect(m_thumbRect.adjusted(penWidth, penWidth, -penWidth - 1, -penWidth - 1), 4, 4);
                    painter->setPen(QPen(Qt::black, 1));
                    painter->drawRoundedRect(m_thumbRect.adjusted(0, 0, -1, -1), 4, 4);
                    painter->restore();
249
                }
250
                int mid = int((r1.height() / 2));
251
252
253
254
255
256
257
258
                r1.adjust(decoWidth, 0, 0, -mid);
                QRect r2 = option.rect;
                r2.adjust(decoWidth, mid, 0, 0);
                QRectF bounding;
                painter->drawText(r1, Qt::AlignLeft | Qt::AlignTop, index.data(AbstractProjectItem::DataName).toString(), &bounding);
                font.setBold(false);
                painter->setFont(font);
                QString subText = index.data(AbstractProjectItem::DataDuration).toString();
259
260
261
                QString tags = index.data(AbstractProjectItem::DataTag).toString();
                if (!tags.isEmpty()) {
                    QStringList t = tags.split(QLatin1Char(';'));
262
263
264
                    QRectF tagRect = m_thumbRect.adjusted(2, 2, 0, 2);
                    tagRect.setWidth(r1.height() / 3.5);
                    tagRect.setHeight(tagRect.width());
Vincent Pinon's avatar
Vincent Pinon committed
265
                    for (const QString &color : qAsConst(t)) {
266
267
268
                        painter->setBrush(QColor(color));
                        painter->drawRoundedRect(tagRect, tagRect.height() / 2, tagRect.height() / 2);
                        tagRect.moveTop(tagRect.bottom() + tagRect.height() / 4);
269
270
                    }
                }
271
                if (!subText.isEmpty()) {
272
                    r2.adjust(0, int(bounding.bottom() - r2.top()), 0, 0);
273
274
275
276
277
278
                    QColor subTextColor = painter->pen().color();
                    subTextColor.setAlphaF(.5);
                    painter->setPen(subTextColor);
                    // Draw usage counter
                    int usage = index.data(AbstractProjectItem::UsageCount).toInt();
                    if (usage > 0) {
Laurent Montel's avatar
Laurent Montel committed
279
                        subText.append(QString::asprintf(" [%d]", usage));
280
281
                    }
                    painter->drawText(r2, Qt::AlignLeft | Qt::AlignTop, subText, &bounding);
282
                    // Add audio/video icons for selective drag
283
284
                    bool hasAudioAndVideo = index.data(AbstractProjectItem::ClipHasAudioAndVideo).toBool();
                    if (hasAudioAndVideo && (cType == ClipType::AV || cType == ClipType::Playlist) && (opt.state & QStyle::State_MouseOver)) {
285
286
287
288
289
290
291
292
293
294
295
                        bounding.moveLeft(bounding.right() + (2 * textMargin));
                        bounding.adjust(0, textMargin, 0, -textMargin);
                        QIcon aDrag = QIcon::fromTheme(QStringLiteral("audio-volume-medium"));
                        m_audioDragRect = bounding.toRect();
                        m_audioDragRect.setWidth(m_audioDragRect.height());
                        aDrag.paint(painter, m_audioDragRect, Qt::AlignLeft);
                        m_videoDragRect = m_audioDragRect;
                        m_videoDragRect.moveLeft(m_audioDragRect.right());
                        QIcon vDrag = QIcon::fromTheme(QStringLiteral("kdenlive-show-video"));
                        vDrag.paint(painter, m_videoDragRect, Qt::AlignLeft);
                    } else {
296
297
                        //m_audioDragRect = QRect();
                        //m_videoDragRect = QRect();
298
299
300
301
302
303
304
                    }
                }
                if (type == AbstractProjectItem::ClipItem) {
                    // Overlay icon if necessary
                    QVariant v = index.data(AbstractProjectItem::IconOverlay);
                    if (!v.isNull()) {
                        QIcon reload = QIcon::fromTheme(v.toString());
305
306
                        r.setTop(int(r.bottom() - bounding.height()));
                        r.setWidth(int(bounding.height()));
307
308
309
                        reload.paint(painter, r);
                    }
                    int jobProgress = index.data(AbstractProjectItem::JobProgress).toInt();
Nicolas Carion's avatar
Nicolas Carion committed
310
                    auto status = index.data(AbstractProjectItem::JobStatus).value<JobManagerStatus>();
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
                    if (status == JobManagerStatus::Pending || status == JobManagerStatus::Running) {
                        // Draw job progress bar
                        int progressWidth = option.fontMetrics.averageCharWidth() * 8;
                        int progressHeight = option.fontMetrics.ascent() / 4;
                        QRect progress(r1.x() + 1, opt.rect.bottom() - progressHeight - 2, progressWidth, progressHeight);
                        painter->setPen(Qt::NoPen);
                        painter->setBrush(Qt::darkGray);
                        if (status == JobManagerStatus::Running) {
                            painter->drawRoundedRect(progress, 2, 2);
                            painter->setBrush((option.state & static_cast<int>((QStyle::State_Selected) != 0)) != 0 ? option.palette.text()
                                                                                                                    : option.palette.highlight());
                            progress.setWidth((progressWidth - 2) * jobProgress / 100);
                            painter->drawRoundedRect(progress, 2, 2);
                        } else {
                            // Draw kind of a pause icon
                            progress.setWidth(3);
                            painter->drawRect(progress);
                            progress.moveLeft(progress.right() + 3);
                            painter->drawRect(progress);
                        }
                    }
                    bool jobsucceeded = index.data(AbstractProjectItem::JobSuccess).toBool();
                    if (!jobsucceeded) {
                        QIcon warning = QIcon::fromTheme(QStringLiteral("process-stop"));
                        warning.paint(painter, r2);
                    }
                }
            } else {
339
                // Folder
340
341
                int decoWidth = 0;
                if (opt.decorationSize.height() > 0) {
342
                    r.setWidth(int(r.height() * pCore->getCurrentDar()));
343
                    QPixmap pix = opt.icon.pixmap(opt.icon.actualSize(r.size()));
344
                    // Draw icon
345
346
347
                    decoWidth += r.width() + textMargin;
                    r.setWidth(r.height() * pix.width() / pix.height());
                    painter->drawPixmap(r, pix, QRect(0, 0, pix.width(), pix.height()));
348
349
350
351
352
353
                }
                r1.adjust(decoWidth, 0, 0, 0);
                QRectF bounding;
                painter->drawText(r1, Qt::AlignLeft | Qt::AlignTop, index.data(AbstractProjectItem::DataName).toString(), &bounding);
            }
            painter->restore();
354
        } else if (index.column() == 7) {
355
356
357
            QStyleOptionViewItem opt(option);
            initStyleOption(&opt, index);
            QRect r1 = opt.rect;
358
359
            // Tweak bg opacity since breeze dark star has same color as highlighted background
            painter->setOpacity(0.5);
360
361
            QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
            style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
362
            painter->setOpacity(1);
363
            if (index.data(AbstractProjectItem::ItemTypeRole).toInt() != AbstractProjectItem::FolderItem) {
364
                r1.adjust(r1.width() / 12, 0, 0, 0);
365
                KRatingPainter::paintRating(painter, r1, Qt::AlignLeft | Qt::AlignVCenter, index.data().toInt());
366
            }
367
368
369
370
        } else {
            QStyledItemDelegate::paint(painter, option, index);
        }
    }
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404

    int getFrame(QModelIndex index, int mouseX)
    {
        int type = index.data(AbstractProjectItem::ItemTypeRole).toInt();
        if ((type != AbstractProjectItem::ClipItem && type != AbstractProjectItem::SubClipItem) || mouseX < m_thumbRect.x() || mouseX > m_thumbRect.right()) {
            return 0;
        }
        return 100 * (mouseX - m_thumbRect.x()) / m_thumbRect.width();
    }

private:
    mutable bool m_editorOpen{false};
    mutable QRect m_audioDragRect;
    mutable QRect m_videoDragRect;
    mutable QRect m_thumbRect;

public:
    PlaylistState::ClipState dragType{PlaylistState::Disabled};
};

/**
 * @class BinListItemDelegate
 * @brief This class is responsible for drawing items in the QListView.
 */

class BinListItemDelegate : public QStyledItemDelegate
{
public:
    explicit BinListItemDelegate(QObject *parent = nullptr)
        : QStyledItemDelegate(parent)

    {
        connect(this, &QStyledItemDelegate::closeEditor, [&]() { m_editorOpen = false; });
    }
405
406
407
408
409
410
    bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override
    {
        Q_UNUSED(model);
        Q_UNUSED(option);
        Q_UNUSED(index);
        if (event->type() == QEvent::MouseButtonPress) {
411
            auto *me = static_cast<QMouseEvent *>(event);
412
413
414
415
416
417
418
419
420
421
422
            if (m_audioDragRect.contains(me->pos())) {
                dragType = PlaylistState::AudioOnly;
            } else if (m_videoDragRect.contains(me->pos())) {
                dragType = PlaylistState::VideoOnly;
            } else {
                dragType = PlaylistState::Disabled;
            }
        }
        event->ignore();
        return false;
    }
423
424
425
426

    void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
    {
        if (!index.data().isNull()) {
427
            QStyleOptionViewItem opt(option);
428
            initStyleOption(&opt, index);
429
            QStyledItemDelegate::paint(painter, option, index);
430
            int adjust = (opt.rect.width() - opt.decorationSize.width()) / 2;
431
            QRect rect(opt.rect.x(), opt.rect.y(), opt.decorationSize.width(), opt.decorationSize.height());
432
433
434
435
            if (adjust > 0 && adjust < rect.width()) {
                rect.translate(adjust, 0);
            }
            m_thumbRect = rect;
436

437
438
439
440
441
442
443
            //Tags
            QString tags = index.data(AbstractProjectItem::DataTag).toString();
            if (!tags.isEmpty()) {
                QStringList t = tags.split(QLatin1Char(';'));
                QRectF tagRect = m_thumbRect.adjusted(2, 2, 0, 2);
                tagRect.setWidth(m_thumbRect.height() / 5);
                tagRect.setHeight(tagRect.width());
Vincent Pinon's avatar
Vincent Pinon committed
444
                for (const QString &color : qAsConst(t)) {
445
446
447
448
449
                    painter->setBrush(QColor(color));
                    painter->drawRoundedRect(tagRect, tagRect.height() / 2, tagRect.height() / 2);
                    tagRect.moveTop(tagRect.bottom() + tagRect.height() / 4);
                }
            }
450

451
            // Add audio/video icons for selective drag
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
            int cType = index.data(AbstractProjectItem::ClipType).toInt();
            bool hasAudioAndVideo = index.data(AbstractProjectItem::ClipHasAudioAndVideo).toBool();
            if (hasAudioAndVideo && (cType == ClipType::AV || cType == ClipType::Playlist) && (opt.state & QStyle::State_MouseOver)) {
                QRect thumbRect = m_thumbRect;
                int iconSize = painter->boundingRect(thumbRect, Qt::AlignLeft, QStringLiteral("O")).height();
                thumbRect.setLeft(opt.rect.right() - iconSize - 4);
                thumbRect.setWidth(iconSize);
                thumbRect.setBottom(m_thumbRect.top() + iconSize);
                QIcon aDrag = QIcon::fromTheme(QStringLiteral("audio-volume-medium"));
                m_audioDragRect = thumbRect;
                aDrag.paint(painter, m_audioDragRect, Qt::AlignRight);
                m_videoDragRect = m_audioDragRect;
                m_videoDragRect.moveTop(thumbRect.bottom());
                QIcon vDrag = QIcon::fromTheme(QStringLiteral("kdenlive-show-video"));
                vDrag.paint(painter, m_videoDragRect, Qt::AlignRight);
            } else {
                //m_audioDragRect = QRect();
                //m_videoDragRect = QRect();
            }
471
            // Draw frame in case of missing source
472
            FileStatus::ClipStatus clipStatus = FileStatus::ClipStatus(index.data(AbstractProjectItem::ClipStatus).toInt());
473
            if (clipStatus == FileStatus::StatusMissing || clipStatus == FileStatus::StatusProxyOnly) {
474
                painter->save();
475
                painter->setPen(QPen(clipStatus == FileStatus::StatusProxyOnly ? Qt::yellow : Qt::red, 3));
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
                painter->drawRect(m_thumbRect);
                painter->restore();
            } else if (cType == ClipType::Image || cType == ClipType::SlideShow) {
                // Draw 'photo' frame to identify image clips
                painter->save();
                int penWidth = m_thumbRect.height() / 14;
                penWidth += penWidth % 2;
                painter->setPen(QPen(QColor(255, 255, 255, 160), penWidth));
                penWidth /= 2;
                painter->drawRoundedRect(m_thumbRect.adjusted(penWidth, penWidth, -penWidth - 1, -penWidth + 1), 4, 4);
                painter->setPen(QPen(Qt::black, 1));
                painter->drawRoundedRect(m_thumbRect.adjusted(0, 0, -1, 1), 4, 4);
                painter->restore();
            }
            int type = index.data(AbstractProjectItem::ItemTypeRole).toInt();
            if (type == AbstractProjectItem::ClipItem) {
                // Overlay icon if necessary
                QVariant v = index.data(AbstractProjectItem::IconOverlay);
                if (!v.isNull()) {
                    QRect r = m_thumbRect;
                    QIcon reload = QIcon::fromTheme(v.toString());
                    r.setTop(r.bottom() - (opt.rect.height() - r.height()));
                    r.setWidth(r.height());
                    reload.paint(painter, r);
                }
            }
502
503
504
        }
    }

505
506
507
    int getFrame(QModelIndex index, int mouseX)
    {
        int type = index.data(AbstractProjectItem::ItemTypeRole).toInt();
508
        if ((type != AbstractProjectItem::ClipItem && type != AbstractProjectItem::SubClipItem)|| mouseX < m_thumbRect.x() || mouseX > m_thumbRect.right()) {
509
510
511
512
            return 0;
        }
        return 100 * (mouseX - m_thumbRect.x()) / m_thumbRect.width();
    }
513
514

private:
Nicolas Carion's avatar
Nicolas Carion committed
515
    mutable bool m_editorOpen{false};
516
517
    mutable QRect m_audioDragRect;
    mutable QRect m_videoDragRect;
518
    mutable QRect m_thumbRect;
519
520

public:
Nicolas Carion's avatar
Nicolas Carion committed
521
    PlaylistState::ClipState dragType{PlaylistState::Disabled};
522
523
};

524

525
526
MyListView::MyListView(QWidget *parent)
    : QListView(parent)
527
528
529
530
{
    setViewMode(QListView::IconMode);
    setMovement(QListView::Static);
    setResizeMode(QListView::Adjust);
531
    setWordWrap(true);
532
533
534
535
536
537
538
539
540
    setDragDropMode(QAbstractItemView::DragDrop);
    setAcceptDrops(true);
    setDragEnabled(true);
    viewport()->setAcceptDrops(true);
}

void MyListView::focusInEvent(QFocusEvent *event)
{
    QListView::focusInEvent(event);
541
542
543
    if (event->reason() == Qt::MouseFocusReason) {
        emit focusView();
    }
544
545
}

546
547
548
void MyListView::enterEvent(QEvent *event)
{
    QListView::enterEvent(event);
549
    pCore->setWidgetKeyBinding(i18n("<b>Double click</b> to add a file to the project"));
550
551
552
553
554
}

void MyListView::leaveEvent(QEvent *event)
{
    QListView::leaveEvent(event);
555
    pCore->setWidgetKeyBinding();
556
557
}

558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
void MyListView::mousePressEvent(QMouseEvent *event)
{
    QListView::mousePressEvent(event);
    if (event->button() == Qt::LeftButton) {
        m_startPos = event->pos();
        QModelIndex ix = indexAt(m_startPos);
        if (ix.isValid()) {
            QAbstractItemDelegate *del = itemDelegate(ix);
            m_dragType = static_cast<BinListItemDelegate *>(del)->dragType;
        } else {
            m_dragType = PlaylistState::Disabled;
        }
        emit updateDragMode(m_dragType);
    }
}

574
575
void MyListView::mouseMoveEvent(QMouseEvent *event)
{
576
577
578
579
    QModelIndex index = indexAt(event->pos());
    if (index.isValid()) {
        QAbstractItemDelegate *del = itemDelegate(index);
        if (KdenliveSettings::hoverPreview()) {
580
581
582
583
584
585
586
587
588
            if (del) {
                auto delegate = static_cast<BinListItemDelegate *>(del);
                QRect vRect = visualRect(index);
                int frame = delegate->getFrame(index, event->pos().x() - vRect.x());
                emit displayBinFrame(index, frame);
            } else {
                qDebug()<<"<<< NO DELEGATE!!!";
            }
        }
589
        pCore->window()->showKeyBinding(i18n("<b>F2</b> to rename selected item"));
590
591
    } else {
        pCore->window()->showKeyBinding();
592
593
594
595
    }
    QListView::mouseMoveEvent(event);
}

596
597
MyTreeView::MyTreeView(QWidget *parent)
    : QTreeView(parent)
598
599
{
    setEditing(false);
600
    setAcceptDrops(true);
601
}
602
603
604

void MyTreeView::mousePressEvent(QMouseEvent *event)
{
605
    QTreeView::mousePressEvent(event);
606
607
    if (event->button() == Qt::LeftButton) {
        m_startPos = event->pos();
608
609
610
        QModelIndex ix = indexAt(m_startPos);
        if (ix.isValid()) {
            QAbstractItemDelegate *del = itemDelegate(ix);
611
            m_dragType = static_cast<BinItemDelegate *>(del)->dragType;
612
613
614
        } else {
            m_dragType = PlaylistState::Disabled;
        }
615
616
617
    }
}

618
619
620
void MyTreeView::focusInEvent(QFocusEvent *event)
{
    QTreeView::focusInEvent(event);
621
622
623
    if (event->reason() == Qt::MouseFocusReason) {
        emit focusView();
    }
624
625
}

626
627
628
void MyTreeView::enterEvent(QEvent *event)
{
    QTreeView::enterEvent(event);
629
    pCore->setWidgetKeyBinding(i18n("<b>Double click</b> to add a file to the project"));
630
631
632
633
634
}

void MyTreeView::leaveEvent(QEvent *event)
{
    QTreeView::leaveEvent(event);
635
    pCore->setWidgetKeyBinding();
636
637
}

638
void MyTreeView::mouseMoveEvent(QMouseEvent *event)
639
640
{
    bool dragged = false;
641
    if ((event->buttons() & Qt::LeftButton) != 0u) {
642
        int distance = (event->pos() - m_startPos).manhattanLength();
643
644
645
        if (distance >= QApplication::startDragDistance()) {
            dragged = performDrag();
        }
646
    } else {
647
648
        QModelIndex index = indexAt(event->pos());
        if (index.isValid()) {
649
650
651
652
653
            if (KdenliveSettings::hoverPreview()) {
                QAbstractItemDelegate *del = itemDelegate(index);
                int frame = static_cast<BinItemDelegate *>(del)->getFrame(index, event->pos().x());
                emit displayBinFrame(index, frame);
            }
654
            pCore->window()->showKeyBinding(i18n("<b>F2</b> to rename selected item"));
655
656
        } else {
            pCore->window()->showKeyBinding();
657
        }
658
659
660
    }
    if (!dragged) {
        QTreeView::mouseMoveEvent(event);
661
662
663
    }
}

664
665
666
667
668
669
670
671
672
673
674
675
void MyTreeView::closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint)
{
    QAbstractItemView::closeEditor(editor, hint);
    setEditing(false);
}

void MyTreeView::editorDestroyed(QObject *editor)
{
    QAbstractItemView::editorDestroyed(editor);
    setEditing(false);
}

Laurent Montel's avatar
Laurent Montel committed
676
bool MyTreeView::isEditing() const
677
{
678
    return state() == QAbstractItemView::EditingState;
679
680
681
682
}

void MyTreeView::setEditing(bool edit)
{
683
    setState(edit ? QAbstractItemView::EditingState : QAbstractItemView::NoState);
684
685
686
687
    if (!edit) {
        // Ensure edited item is selected
        emit selectCurrent();
    }
688
689
}

690
691
692
693
694
695
696
697
698
bool MyTreeView::performDrag()
{
    QModelIndexList bases = selectedIndexes();
    QModelIndexList indexes;
    for (int i = 0; i < bases.count(); i++) {
        if (bases.at(i).column() == 0) {
            indexes << bases.at(i);
        }
    }
699
700
701
    if (indexes.isEmpty()) {
        return false;
    }
702
703
    // Check if we want audio or video only
    emit updateDragMode(m_dragType);
Nicolas Carion's avatar
Nicolas Carion committed
704
    auto *drag = new QDrag(this);
705
    drag->setMimeData(model()->mimeData(indexes));
Laurent Montel's avatar
Laurent Montel committed
706
    QModelIndex ix = indexes.constFirst();
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
    if (ix.isValid()) {
        QIcon icon = ix.data(AbstractProjectItem::DataThumbnail).value<QIcon>();
        QPixmap pix = icon.pixmap(iconSize());
        QSize size = pix.size();
        QImage image(size, QImage::Format_ARGB32_Premultiplied);
        image.fill(Qt::transparent);
        QPainter p(&image);
        p.setOpacity(0.7);
        p.drawPixmap(0, 0, pix);
        p.setOpacity(1);
        if (indexes.count() > 1) {
            QPalette palette;
            int radius = size.height() / 3;
            p.setBrush(palette.highlight());
            p.setPen(palette.highlightedText().color());
            p.drawEllipse(QPoint(size.width() / 2, size.height() / 2), radius, radius);
            p.drawText(size.width() / 2 - radius, size.height() / 2 - radius, 2 * radius, 2 * radius, Qt::AlignCenter, QString::number(indexes.count()));
        }
        p.end();
        drag->setPixmap(QPixmap::fromImage(image));
    }
    drag->exec();
729
    emit processDragEnd();
730
731
732
    return true;
}

733
734
SmallJobLabel::SmallJobLabel(QWidget *parent)
    : QPushButton(parent)
Nicolas Carion's avatar
Nicolas Carion committed
735

736
737
738
739
{
    setFixedWidth(0);
    setFlat(true);
    m_timeLine = new QTimeLine(500, this);
Laurent Montel's avatar
Laurent Montel committed
740
741
    QObject::connect(m_timeLine, &QTimeLine::valueChanged, this, &SmallJobLabel::slotTimeLineChanged);
    QObject::connect(m_timeLine, &QTimeLine::finished, this, &SmallJobLabel::slotTimeLineFinished);
742
743
744
745
746
    hide();
}

const QString SmallJobLabel::getStyleSheet(const QPalette &p)
{
747
    KColorScheme scheme(p.currentColorGroup(), KColorScheme::Window);
748
749
    QColor bg = scheme.background(KColorScheme::LinkBackground).color();
    QColor fg = scheme.foreground(KColorScheme::LinkText).color();
Nicolas Carion's avatar
Nicolas Carion committed
750
751
752
753
754
755
756
757
    QString style =
        QStringLiteral("QPushButton {margin:3px;padding:2px;background-color: rgb(%1, %2, %3);border-radius: 4px;border: none;color: rgb(%4, %5, %6)}")
            .arg(bg.red())
            .arg(bg.green())
            .arg(bg.blue())
            .arg(fg.red())
            .arg(fg.green())
            .arg(fg.blue());
758

759
760
    bg = scheme.background(KColorScheme::ActiveBackground).color();
    fg = scheme.foreground(KColorScheme::ActiveText).color();
Nicolas Carion's avatar
Nicolas Carion committed
761
762
763
764
765
766
767
768
    style.append(
        QStringLiteral("\nQPushButton:hover {margin:3px;padding:2px;background-color: rgb(%1, %2, %3);border-radius: 4px;border: none;color: rgb(%4, %5, %6)}")
            .arg(bg.red())
            .arg(bg.green())
            .arg(bg.blue())
            .arg(fg.red())
            .arg(fg.green())
            .arg(fg.blue()));
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
769

770
771
772
773
774
775
776
777
778
779
    return style;
}

void SmallJobLabel::setAction(QAction *action)
{
    m_action = action;
}

void SmallJobLabel::slotTimeLineChanged(qreal value)
{
780
    setFixedWidth(int(qMin(value * 2, qreal(1.0)) * sizeHint().width()));
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
    update();
}

void SmallJobLabel::slotTimeLineFinished()
{
    if (m_timeLine->direction() == QTimeLine::Forward) {
        // Show
        m_action->setVisible(true);
    } else {
        // Hide
        m_action->setVisible(false);
        setText(QString());
    }
}

void SmallJobLabel::slotSetJobCount(int jobCount)
{
Nicolas Carion's avatar
Nicolas Carion committed
798
    QMutexLocker lk(&m_locker);
799
800
801
802
    if (jobCount > 0) {
        // prepare animation
        setText(i18np("%1 job", "%1 jobs", jobCount));
        setToolTip(i18np("%1 pending job", "%1 pending jobs", jobCount));
803

Nicolas Carion's avatar
Nicolas Carion committed
804
        if (style()->styleHint(QStyle::SH_Widget_Animate, nullptr, this) != 0) {
805
806
807
808
            setFixedWidth(sizeHint().width());
            m_action->setVisible(true);
            return;
        }
809

810
811
812
813
814
        if (m_action->isVisible()) {
            setFixedWidth(sizeHint().width());
            update();
            return;
        }
815

816
817
818
819
820
821
822
823
        setFixedWidth(0);
        m_action->setVisible(true);
        int wantedWidth = sizeHint().width();
        setGeometry(-wantedWidth, 0, wantedWidth, height());
        m_timeLine->setDirection(QTimeLine::Forward);
        if (m_timeLine->state() == QTimeLine::NotRunning) {
            m_timeLine->start();
        }
824
    } else {
Nicolas Carion's avatar
Nicolas Carion committed
825
        if (style()->styleHint(QStyle::SH_Widget_Animate, nullptr, this) != 0) {
826
827
828
829
830
831
832
833
834
835
836
837
            setFixedWidth(0);
            m_action->setVisible(false);
            return;
        }
        // hide
        m_timeLine->setDirection(QTimeLine::Backward);
        if (m_timeLine->state() == QTimeLine::NotRunning) {
            m_timeLine->start();
        }
    }
}

838
839
LineEventEater::LineEventEater(QObject *parent)
    : QObject(parent)
840
841
842
843
844
{
}

bool LineEventEater::eventFilter(QObject *obj, QEvent *event)
{
845
    switch (event->type()) {
846
    case QEvent::ShortcutOverride:
847
        if (static_cast<QKeyEvent *>(event)->key() == Qt::Key_Escape) {
848
849
850
851
852
            emit clearSearchLine();
        }
        break;
    case QEvent::Resize:
        // Workaround Qt BUG 54676
853
        emit showClearButton(static_cast<QResizeEvent *>(event)->size().width() > QFontMetrics(QApplication::font()).averageCharWidth() * 8);
854
855
856
        break;
    default:
        break;
857
858
859
860
    }
    return QObject::eventFilter(obj, event);
}

861
void ClipWidget::init(QDockWidget* m_DockClipWidget)
Vivek Yadav's avatar
Vivek Yadav committed
862
{
863
    ClipCreationDialog::clipWidget(m_DockClipWidget);
Vivek Yadav's avatar
Vivek Yadav committed
864
}
Vivek Yadav's avatar
Vivek Yadav committed
865

Nicolas Carion's avatar
Nicolas Carion committed
866
Bin::Bin(std::shared_ptr<ProjectItemModel> model, QWidget *parent)
867
868
    : QWidget(parent)
    , isLoading(false)
Nicolas Carion's avatar
Nicolas Carion committed
869
    , m_itemModel(std::move(model))
870
    , m_itemView(nullptr)
871
872
    , m_binTreeViewDelegate(nullptr)
    , m_binListViewDelegate(nullptr)
873
874
875
876
877
    , m_doc(nullptr)
    , m_extractAudioAction(nullptr)
    , m_transcodeAction(nullptr)
    , m_clipsActionsMenu(nullptr)
    , m_inTimelineAction(nullptr)
878
    , m_listType(BinViewType(KdenliveSettings::binMode()))
879
880
881
    , m_iconSize(160, 90)
    , m_propertiesPanel(nullptr)
    , m_blankThumb()
882
    , m_clipWidget()
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
883
    , m_filterGroup(this)
884
885
    , m_filterRateGroup(this)
    , m_filterTypeGroup(this)
886
887
888
889
    , m_invalidClipDialog(nullptr)
    , m_gainedFocus(false)
    , m_audioDuration(0)
    , m_processedAudio(0)
890
{
891
    m_layout = new QVBoxLayout(this);
892
893

    // Create toolbar for buttons
894
    m_toolbar = new QToolBar(this);
895
896
897
    int size = style()->pixelMetric(QStyle::PM_SmallIconSize);
    QSize iconSize(size, size);
    m_toolbar->setIconSize(iconSize);
898
    m_toolbar->setToolButtonStyle(Qt::ToolButtonIconOnly);
899
    m_layout->addWidget(m_toolbar);
900
901
902
903

    // Tags panel
    m_tagsWidget = new TagWidget(this);
    connect(m_tagsWidget, &TagWidget::switchTag, this, &Bin::switchTag);
904
    connect(m_tagsWidget, &TagWidget::updateProjectTags, this, &Bin::updateTags);
905
906
907
    m_tagsWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum);
    m_layout->addWidget(m_tagsWidget);
    m_tagsWidget->setVisible(false);
908

909
910
    m_layout->setSpacing(0);
    m_layout->setContentsMargins(0, 0, 0, 0);
911
    // Search line
912
913
    m_searchLine = new QLineEdit(this);
    m_searchLine->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
914
    m_searchLine->setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont));
Nicolas Carion's avatar
Nicolas Carion committed
915
    // m_searchLine->setClearButtonEnabled(true);
916
    m_searchLine->setPlaceholderText(i18n("Search..."));
917
    m_searchLine->setFocusPolicy(Qt::ClickFocus);
918
919
920
921
922
923
    connect(m_searchLine, &QLineEdit::textChanged, [this] (const QString &str) {
        m_proxyModel->slotSetSearchString(str);
        if (str.isEmpty()) {
            // focus last selected item when clearing search line
            QModelIndex current = m_proxyModel->selectionModel()->currentIndex();
            if (current.isValid()) {
924
                m_itemView->scrollTo(current, QAbstractItemView::EnsureVisible);
925
926
927
            }
        }
    });
928

Nicolas Carion's avatar
Nicolas Carion committed
929
    auto *leventEater = new LineEventEater(this);
930
    m_searchLine->installEventFilter(leventEater);
Laurent Montel's avatar
Laurent Montel committed
931
    connect(leventEater, &LineEventEater::clearSearchLine, m_searchLine, &QLineEdit::clear);
932
    connect(leventEater, &LineEventEater::showClearButton, this, &Bin::showClearButton);
933

934
    setFocusPolicy(Qt::ClickFocus);
935

936
    connect(m_itemModel.get(), &ProjectItemModel::refreshPanel, this, &Bin::refreshPanel);
937
    connect(m_itemModel.get(), &ProjectItemModel::refreshClip, this, &Bin::refreshClip);
Nicolas Carion's avatar
Nicolas Carion committed
938
939
940
    connect(m_itemModel.get(), static_cast<void (ProjectItemModel::*)(const QStringList &, const QModelIndex &)>(&ProjectItemModel::itemDropped), this,
            static_cast<void (Bin::*)(const QStringList &, const QModelIndex &)>(&Bin::slotItemDropped));
    connect(m_itemModel.get(), static_cast<void (ProjectItemModel::*)(const QList<QUrl> &, const QModelIndex &)>(&ProjectItemModel::itemDropped), this,
941
            static_cast<const QString (Bin::*)(const QList<QUrl> &, const QModelIndex &)>(&Bin::slotItemDropped));
942
    connect(m_itemModel.get(), &ProjectItemModel::effectDropped, this, &Bin::slotEffectDropped);
943
    connect(m_itemModel.get(), &ProjectItemModel::addTag, this, &Bin::slotTagDropped);
944
    connect(m_itemModel.get(), &QAbstractItemModel::dataChanged, this, &Bin::slotItemEdited);
945
    connect(this, &Bin::refreshPanel, this, &Bin::doRefreshPanel);
946

947
    // Zoom slider
948
    QWidget *container = new QWidget(this);
Nicolas Carion's avatar
Nicolas Carion committed
949
    auto *lay = new QHBoxLayout;
950
951
    m_slider = new QSlider(Qt::Horizontal, this);
    m_slider->setMaximumWidth(100);
952
    m_slider->setMinimumWidth(40);
953
    m_slider->setRange(0, 10);
954
    m_slider->setValue(KdenliveSettings::bin_zoom());
Laurent Montel's avatar
Laurent Montel committed
955
    connect(m_slider, &QAbstractSlider::valueChanged, this, &Bin::slotSetIconSize);
Nicolas Carion's avatar
Nicolas Carion committed
956
    auto *tb1 = new QToolButton(this);
957
    tb1->setIcon(QIcon::fromTheme(QStringLiteral("zoom-in")));
Vincent Pinon's avatar
Vincent Pinon committed
958
    connect(tb1, &QToolButton::clicked, this, [&]() { m_slider->setValue(qMin(m_slider->value() + 1, m_slider->maximum())); });
Nicolas Carion's avatar
Nicolas Carion committed
959
    auto *tb2 = new QToolButton(this);
960
    tb2->setIcon(QIcon::fromTheme(QStringLiteral("zoom-out")));
Vincent Pinon's avatar
Vincent Pinon committed
961
    connect(tb2, &QToolButton::clicked, this, [&]() { m_slider->setValue(qMax(m_slider->value() - 1, m_slider->minimum())); });
962
    lay->addWidget(tb2);
963
964
    lay->addWidget(m_slider);
    lay->addWidget(tb1);
965
    container->setLayout(lay);
Nicolas Carion's avatar
Nicolas Carion committed
966
    auto *widgetslider = new QWidgetAction(this);
967
    widgetslider->setDefaultWidget(container);
968
969

    // View type
970
    KSelectAction *listType = new KSelectAction(QIcon::fromTheme(QStringLiteral("view-list-tree")), i18n("View Mode"), this);
971
    pCore->window()->actionCollection()->addAction(QStringLiteral("bin_view_mode"), listType);
Julius Künzel's avatar
Julius Künzel committed
972
    pCore->window()->actionCollection()->setShortcutsConfigurable(listType, false);
973
    QAction *treeViewAction = listType->addAction(QIcon::fromTheme(QStringLiteral("view-list-tree")), i18n("Tree View"));
974
    listType->addAction(treeViewAction);
975
976
977
978
    treeViewAction->setData(BinTreeView);
    if (m_listType == treeViewAction->data().toInt()) {
        listType->setCurrentAction(treeViewAction);
    }
979
    pCore->window()->actionCollection()->addAction(QStringLiteral("bin_view_mode_tree"), treeViewAction);
980

981
    QAction *iconViewAction = listType->addAction(QIcon::fromTheme(QStringLiteral("view-list-icons")), i18n("Icon View"));
982
983
984
985
    iconViewAction->setData(BinIconView);
    if (m_listType == iconViewAction->data().toInt()) {
        listType->setCurrentAction(iconViewAction);
    }
986
    pCore->window()->actionCollection()->addAction(QStringLiteral("bin_view_mode_icon"), iconViewAction);
987

988
989
990
991
    // Sort menu
    m_sortDescend = new QAction(i18n("Descending"), this);
    m_sortDescend->setCheckable(true);
    m_sortDescend->setChecked(KdenliveSettings::binSorting() > 99);
Vincent Pinon's avatar
Vincent Pinon committed
992
    connect(m_sortDescend, &QAction::triggered, this, [&] () {
993
        if (m_sortGroup->checkedAction()) {
994
            int actionData = m_sortGroup->checkedAction()->data().toInt();
995
996
            if ((m_itemView != nullptr) && m_listType == BinTreeView) {
                auto *view = static_cast<QTreeView *>(m_itemView);
997
                view->header()->setSortIndicator(actionData, m_sortDescend->isChecked() ? Qt::DescendingOrder : Qt::AscendingOrder);
998
            } else {
999
                m_proxyModel->sort(actionData, m_sortDescend->isChecked() ? Qt::DescendingOrder : Qt::AscendingOrder);