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 LineEditClear;
37class QAbstractItemModel;
38class QActionGroup;
39class QMimeData;
40class QMovie;
41class QSortFilterProxyModel;
42class QStackedWidget;
43class QTimer;
44class QWidget;
45
46class ElementsModel;
47class PlaylistIconView;
48
49class ElementsDock : public QDockWidget
50{
51 Q_OBJECT
52
53public:
54 enum class Page {
55 Emojis = 0,
56 Sounds = 1,
57 Text = 2,
58 Transitions = 3,
59 Graphics = 4,
60 };
61
62 explicit ElementsDock(QWidget *parent = nullptr);
63 ~ElementsDock();
64
68 QMimeData *buildMimeData(const QString &sourcePath,
69 const QString &categoryName,
70 bool autoFilter,
71 bool isSoundEffect = false,
72 bool makeUnique = false,
73 QString *destPath = nullptr,
74 bool *didCreate = nullptr);
75
76protected:
77 void resizeEvent(QResizeEvent *event) override;
78 bool eventFilter(QObject *watched, QEvent *event) override;
79
80private:
81 struct CategoryPage
82 {
83 QString name;
84 bool autoFilter{false};
85 ElementsModel *model{nullptr};
86 QSortFilterProxyModel *proxyModel{nullptr};
87 PlaylistIconView *view{nullptr};
88 };
89
90 struct ElementPolicy
91 {
92 int pageIndex{-1};
93 QString filePath;
94 QString categoryName;
95 bool autoFilter{false};
96 bool isSound{false};
97 bool makeUnique{false};
98
99 bool valid() const { return pageIndex >= 0 && !filePath.isEmpty(); }
100 };
101
102 void setupCategoryPage(
103 Page page, const QString &name, const QIcon &icon, bool autoFilter, const QDir &dir);
104 void setupSearchPage();
105 void showSearchOrCategory();
106 void connectView(PlaylistIconView *view);
107 QModelIndex sourceIndex(const QSortFilterProxyModel *proxy, const QModelIndex &viewIndex) const;
108 int pageIndexForModel(const QAbstractItemModel *model) const;
109 int pageIndexForView(const PlaylistIconView *view) const;
110 ElementPolicy policyFor(const PlaylistIconView *view, const QModelIndex &viewIndex) const;
111 void openElement(const ElementPolicy &policy);
112 void previewElement(const ElementPolicy &policy);
113 void startDrag(PlaylistIconView *view);
114 PlaylistIconView *viewForViewport(QObject *watched) const;
115 void updateToolbarStyle();
116 void stopHoverPreview();
117 void stopAudioPreview();
118 void startAudioPreview(const QString &filePath);
119 void startHoverAnimation(const QModelIndex &sourceIndex, const QString &webpPath);
120 QString destPath(const QString &sourcePath, const QString &categoryName) const;
121 Mlt::Producer *copyAndCreateProducer(const QString &sourcePath,
122 const QString &categoryName,
123 bool autoFilter,
124 bool isSoundEffect = false,
125 bool makeUnique = false,
126 QString *destPath = nullptr,
127 bool *didCreate = nullptr);
128 static void attachSizeFilter(Mlt::Producer *producer, QSize fixedSize = QSize());
129 static QIcon makeTextIcon(const QString &text, const QColor &color = QColor());
130
131 QWidget *m_categoryToolbar{nullptr};
132 LineEditClear *m_searchField{nullptr};
133 QActionGroup *m_categoryGroup{nullptr};
134 QStackedWidget *m_stack{nullptr};
135 QList<CategoryPage> m_pages;
136 QSortFilterProxyModel *m_searchProxy{nullptr};
137 PlaylistIconView *m_searchView{nullptr};
138 int m_searchPageIndex{-1};
139 int m_currentPage{0};
140
141 QMovie *m_activeMovie{nullptr};
142 QTimer *m_previewTimer{nullptr};
143 QString m_previewFilePath;
144 QPersistentModelIndex m_hoveredProxyIndex;
145 QPersistentModelIndex m_hoveredSourceIndex;
146 ElementsModel *m_hoveredModel{nullptr};
147 QPoint m_dragStartPos;
148 std::unique_ptr<Mlt::Consumer> m_audioConsumer;
149};
150
151#endif // ELEMENTSDOCK_H