CuteLogger
Fast and simple logging solution for Qt based applications
elementsdock.h
1/*
2 * Copyright (c) 2026 Meltytech, LLC
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef ELEMENTSDOCK_H
19#define ELEMENTSDOCK_H
20
21#include <QColor>
22#include <QDir>
23#include <QDockWidget>
24#include <QIcon>
25#include <QModelIndex>
26#include <QSize>
27
28#include <MltConsumer.h>
29
30#include <memory>
31
32namespace Mlt {
33class Producer;
34}
35
36class QActionGroup;
37class QMimeData;
38class QMovie;
39class QSortFilterProxyModel;
40class QStackedWidget;
41class QTimer;
42class QWidget;
43
44class ElementsModel;
45class PlaylistIconView;
46
47class ElementsDock : public QDockWidget
48{
49 Q_OBJECT
50
51public:
52 enum class Page {
53 Emojis = 0,
54 Sounds = 1,
55 Text = 2,
56 Transitions = 3,
57 Graphics = 4,
58 };
59
60 explicit ElementsDock(QWidget *parent = nullptr);
61 ~ElementsDock();
62
66 QMimeData *buildMimeData(const QString &sourcePath,
67 const QString &categoryName,
68 bool autoFilter,
69 bool isSoundEffect = false,
70 bool makeUnique = false,
71 QString *destPath = nullptr,
72 bool *didCreate = nullptr);
73
74protected:
75 void resizeEvent(QResizeEvent *event) override;
76 bool eventFilter(QObject *watched, QEvent *event) override;
77
78private slots:
79 void onActivated(const QModelIndex &proxyIndex, Page page);
80
81private:
82 struct CategoryPage
83 {
84 QString name;
85 bool autoFilter;
86 ElementsModel *model{nullptr};
87 QSortFilterProxyModel *proxyModel{nullptr};
88 PlaylistIconView *view{nullptr};
89 };
90
91 void setupCategoryPage(
92 Page page, const QString &name, const QIcon &icon, bool autoFilter, const QDir &dir);
93 void updateToolbarStyle();
94 void stopHoverPreview();
95 void stopAudioPreview();
96 void startAudioPreview(const QString &filePath);
97 void startHoverAnimation(const QModelIndex &sourceIndex, const QString &webpPath);
98 QString destPath(const QString &sourcePath, const QString &categoryName) const;
99 Mlt::Producer *copyAndCreateProducer(const QString &sourcePath,
100 const QString &categoryName,
101 bool autoFilter,
102 bool isSoundEffect = false,
103 bool makeUnique = false,
104 QString *destPath = nullptr,
105 bool *didCreate = nullptr);
106 static void attachSizeFilter(Mlt::Producer *producer, QSize fixedSize = QSize());
107 static QIcon makeTextIcon(const QString &text, const QColor &color = QColor());
108
109 QWidget *m_categoryToolbar{nullptr};
110 QActionGroup *m_categoryGroup{nullptr};
111 QStackedWidget *m_stack{nullptr};
112 QList<CategoryPage> m_pages;
113
114 QMovie *m_activeMovie{nullptr};
115 QTimer *m_previewTimer{nullptr};
116 QString m_previewFilePath;
117 QPersistentModelIndex m_hoveredProxyIndex;
118 QPersistentModelIndex m_hoveredSourceIndex;
119 int m_hoveredPageIndex{-1};
120 QPoint m_dragStartPos;
121 int m_dragPageIndex{-1};
122 std::unique_ptr<Mlt::Consumer> m_audioConsumer;
123};
124
125#endif // ELEMENTSDOCK_H