lmms
Cross-platform music production software
Loading...
Searching...
No Matches
ClipView.h
Go to the documentation of this file.
1/*
2 * ClipView.h - declaration of ClipView class
3 *
4 * Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
5 *
6 * This file is part of LMMS - https://lmms.io
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program (see COPYING); if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301 USA.
22 *
23 */
24
25#ifndef LMMS_GUI_CLIP_VIEW_H
26#define LMMS_GUI_CLIP_VIEW_H
27
28#include <optional>
29
30#include <QVector>
31
32#include "ModelView.h"
33#include "Rubberband.h"
34#include "Clip.h"
35
36
37class QMenu;
38
39namespace lmms
40{
41
42class DataFile;
43
44namespace gui
45{
46
47class TextFloat;
48class TrackView;
49
50
51class ClipView : public selectableObject, public ModelView
52{
53 Q_OBJECT
54
55// theming qproperties
56 Q_PROPERTY( QColor mutedColor READ mutedColor WRITE setMutedColor )
58 Q_PROPERTY( QColor selectedColor READ selectedColor WRITE setSelectedColor )
59 Q_PROPERTY( QColor textColor READ textColor WRITE setTextColor )
61 Q_PROPERTY( QColor textShadowColor READ textShadowColor WRITE setTextShadowColor )
63 Q_PROPERTY( bool gradient READ gradient WRITE setGradient )
64 Q_PROPERTY(QColor markerColor READ markerColor WRITE setMarkerColor)
65
66public:
67 const static int BORDER_WIDTH = 2;
68
72 ClipView(Clip* clip, TrackView* tv);
73
75 ~ClipView() override;
76
79 bool fixedClips();
80
81 inline Clip * getClip()
82 {
83 return m_clip;
84 }
85
87 {
88 return m_trackView;
89 }
90
91 // qproperty access functions, to be inherited & used by Clipviews
92 QColor mutedColor() const { return m_mutedColor; }
94 QColor selectedColor() const { return m_selectedColor; }
95 QColor textColor() const { return m_textColor; }
96 QColor textBackgroundColor() const { return m_textBackgroundColor; }
97 QColor textShadowColor() const { return m_textShadowColor; }
99 bool gradient() const { return m_gradient; }
100 QColor markerColor() const { return m_markerColor; }
101 void setMutedColor(const QColor& c) { m_mutedColor = QColor(c); }
102 void setMutedBackgroundColor(const QColor& c) { m_mutedBackgroundColor = QColor(c); }
103 void setSelectedColor(const QColor& c) { m_selectedColor = QColor(c); }
104 void setTextColor(const QColor& c) { m_textColor = QColor(c); }
105 void setTextBackgroundColor(const QColor& c) { m_textBackgroundColor = QColor(c); }
106 void setTextShadowColor(const QColor& c) { m_textShadowColor = QColor(c); }
107 void setPatternClipBackground(const QColor& c) { m_patternClipBackground = QColor(c); }
108 void setGradient(const bool& b) { m_gradient = b; }
109 void setMarkerColor(const QColor& c) { m_markerColor = QColor(c); }
110
111 bool needsUpdate() const { return m_needsUpdate; }
112 void setNeedsUpdate(bool b) { m_needsUpdate = b; }
113
114 // Method to get a QVector of Clips to be affected by a context menu action
115 QVector<ClipView *> getClickedClips();
116
117 // Methods to remove, copy, cut, paste and mute a QVector of Clip views
118 void copy( QVector<ClipView *> clipvs );
119 void cut( QVector<ClipView *> clipvs );
120 void paste();
121 // remove and toggleMute are static because they don't depend
122 // being called from a particular Clip view, but can be called anywhere as long
123 // as a valid Clip view list is given, while copy/cut require an instance for
124 // some metadata to be written to the clipboard.
125 static void remove( QVector<ClipView *> clipvs );
126 static void toggleMute( QVector<ClipView *> clipvs );
127
129
130 QColor getColorForDisplay( QColor );
131
132 void inline setMarkerPos(int x) { m_markerPos = x; }
133 void inline setMarkerEnabled(bool e) { m_marker = e; }
134
135public slots:
136
142 virtual bool close();
143
148 void remove();
149
153 void update() override;
154
155 void selectColor();
156 void randomizeColor();
157 void resetColor();
158
159protected:
161 {
162 Remove,
163 Cut,
164 Copy,
165 Paste,
166 Mute
167 };
168
172
173 bool m_marker = false;
174 int m_markerPos = 0;
175
176 virtual void constructContextMenu( QMenu * )
177 {
178 }
179
185 void contextMenuEvent( QContextMenuEvent * cme ) override;
186
188
194 void dragEnterEvent(QDragEnterEvent* dee) override;
195
202 void dropEvent( QDropEvent * de ) override;
203
216 void mousePressEvent(QMouseEvent* me) override;
217
229 void mouseMoveEvent(QMouseEvent* me) override;
230
236 void mouseReleaseEvent(QMouseEvent* me) override;
237
238 void resizeEvent( QResizeEvent * re ) override
239 {
240 m_needsUpdate = true;
241 selectableObject::resizeEvent( re );
242 }
243
244 bool unquantizedModHeld( QMouseEvent * me );
246
249 float pixelsPerBar() const;
250
258 DataFile createClipDataFiles(const QVector<ClipView *> & clips) const;
259
260 virtual void paintTextLabel(QString const & text, QPainter & painter);
261
262 auto hasCustomColor() const -> bool;
263
264protected slots:
269 void updateLength();
270
275 void updatePosition();
276
277private:
278 enum class Action
279 {
281 Move,
282 MoveSelection,
283 Resize,
284 ResizeLeft,
285 Split,
286 CopySelection,
287 ToggleSelected
288 } ;
289
298
303 QVector<TimePos> m_initialOffsets;
304
306
307// qproperty fields
317
319 inline void setInitialPos( QPoint pos )
320 {
321 m_initialMousePos = pos;
322 m_initialMouseGlobalPos = mapToGlobal( pos );
325 }
326
328 void setInitialOffsets();
329
333 bool mouseMovedDistance(QMouseEvent* me, int distance);
334
337 TimePos draggedClipPos(QMouseEvent* me);
338
339 int knifeMarkerPos( QMouseEvent * me );
340
343 void setColor(const std::optional<QColor>& color);
344
347 int resizeGripWidth() const;
348
350 virtual bool isResizableBeforeStart() { return true; };
351
352
356 bool splitClip(const TimePos pos);
357
364 virtual bool destructiveSplitClip(const TimePos pos)
365 {
366 return splitClip(pos);
367 }
368
371 void updateCursor(QMouseEvent* me);
372} ;
373
374
375} // namespace gui
376
377} // namespace lmms
378
379#endif // LMMS_GUI_CLIP_VIEW_H
Definition Clip.h:50
const TimePos & startPosition() const
Definition Clip.h:82
const TimePos & length() const
Definition Clip.h:93
Definition DataFile.h:44
Definition TimePos.h:68
TrackView * getTrackView()
Definition ClipView.h:86
void setTextBackgroundColor(const QColor &c)
Definition ClipView.h:105
ContextMenuAction
Definition ClipView.h:161
void setMutedBackgroundColor(const QColor &c)
Definition ClipView.h:102
QVector< ClipView * > getClickedClips()
Definition ClipView.cpp:975
void setPatternClipBackground(const QColor &c)
Definition ClipView.h:107
DataFile createClipDataFiles(const QVector< ClipView * > &clips) const
Create a DataFile suitable for copying multiple clips.
Definition ClipView.cpp:366
void setGradient(const bool &b)
Definition ClipView.h:108
float pixelsPerBar() const
How many pixels a bar takes for this ClipView.
Definition ClipView.cpp:1068
QColor mutedBackgroundColor() const
Definition ClipView.h:93
QColor mutedColor
Definition ClipView.h:56
void resizeEvent(QResizeEvent *re) override
Definition ClipView.h:238
QColor textColor() const
Definition ClipView.h:95
bool needsUpdate() const
Definition ClipView.h:111
int knifeMarkerPos(QMouseEvent *me)
Definition ClipView.cpp:1146
void dropEvent(QDropEvent *de) override
Handle something being dropped on this ClipObjectView.
Definition ClipView.cpp:299
QColor selectedColor() const
Definition ClipView.h:94
QColor m_mutedColor
Definition ClipView.h:308
QColor m_textShadowColor
Definition ClipView.h:313
bool m_marker
Definition ClipView.h:173
bool m_needsUpdate
Definition ClipView.h:318
void updatePosition()
Updates a ClipView's position.
Definition ClipView.cpp:212
void toggleSelectedAutoResize()
Definition ClipView.cpp:1055
QColor m_textBackgroundColor
Definition ClipView.h:312
virtual bool isResizableBeforeStart()
Definition ClipView.h:350
void copy(QVector< ClipView * > clipvs)
Definition ClipView.cpp:1007
void mousePressEvent(QMouseEvent *me) override
Handle a mouse press on this ClipView.
Definition ClipView.cpp:446
void paste()
Definition ClipView.cpp:1029
void setInitialOffsets()
Save the offsets between all selected tracks and a clicked track.
Definition ClipView.cpp:1074
bool unquantizedModHeld(QMouseEvent *me)
Definition ClipView.cpp:1104
virtual bool close()
Close a ClipView.
Definition ClipView.cpp:160
void dragEnterEvent(QDragEnterEvent *dee) override
Change the ClipView's display when something being dragged enters it.
Definition ClipView.cpp:280
static const int BORDER_WIDTH
Definition ClipView.h:67
QPoint m_initialMouseGlobalPos
Definition ClipView.h:302
void setTextColor(const QColor &c)
Definition ClipView.h:104
void cut(QVector< ClipView * > clipvs)
Definition ClipView.cpp:1020
void setNeedsUpdate(bool b)
Definition ClipView.h:112
bool fixedClips()
Checks if the containing trackView has fixed Clips.
Definition ClipView.cpp:152
QColor m_mutedBackgroundColor
Definition ClipView.h:309
void setTextShadowColor(const QColor &c)
Definition ClipView.h:106
QVector< TimePos > m_initialOffsets
Definition ClipView.h:303
QColor markerColor() const
Definition ClipView.h:100
QColor getColorForDisplay(QColor)
Definition ClipView.cpp:1188
TimePos draggedClipPos(QMouseEvent *me)
Calculate the new position of a dragged Clip from a mouse event.
Definition ClipView.cpp:1112
void setInitialPos(QPoint pos)
Definition ClipView.h:319
void contextMenuAction(ContextMenuAction action)
Definition ClipView.cpp:950
void selectColor()
Definition ClipView.cpp:220
bool mouseMovedDistance(QMouseEvent *me, int distance)
Detect whether the mouse moved more than n pixels on screen.
Definition ClipView.cpp:1094
ClipView(Clip *clip, TrackView *tv)
Creates a new clip view for the given clip in the given track view.
Definition ClipView.cpp:67
QColor m_textColor
Definition ClipView.h:311
void remove()
Removes a ClipView from its track view.
Definition ClipView.cpp:169
void setMarkerPos(int x)
Definition ClipView.h:132
int m_markerPos
Definition ClipView.h:174
QPoint m_initialMousePos
Definition ClipView.h:301
TimePos m_initialClipPos
Definition ClipView.h:170
bool splitClip(const TimePos pos)
Split this Clip into two clips.
Definition ClipView.cpp:1231
Clip * getClip()
Definition ClipView.h:81
void resetColor()
Definition ClipView.cpp:234
void setColor(const std::optional< QColor > &color)
Change color of all selected clips.
Definition ClipView.cpp:239
static TextFloat * s_textFloat
A pointer for the text bubble used when moving segments, etc.
Definition ClipView.h:297
void setSelectedColor(const QColor &c)
Definition ClipView.h:103
QColor markerColor
Definition ClipView.h:64
QColor m_selectedColor
Definition ClipView.h:310
bool gradient
Definition ClipView.h:63
bool m_gradient
Definition ClipView.h:315
void setMutedColor(const QColor &c)
Definition ClipView.h:101
TimePos quantizeSplitPos(TimePos)
Definition ClipView.cpp:1168
QColor textShadowColor
Definition ClipView.h:61
int resizeGripWidth() const
Definition ClipView.cpp:272
Clip * m_clip
Definition ClipView.h:299
QColor m_patternClipBackground
Definition ClipView.h:314
TimePos m_initialClipEnd
Definition ClipView.h:171
QColor textColor
Definition ClipView.h:59
QColor mutedColor() const
Definition ClipView.h:92
Action
Definition ClipView.h:279
void contextMenuEvent(QContextMenuEvent *cme) override
Set up the context menu for this ClipView.
Definition ClipView.cpp:868
bool gradient() const
Definition ClipView.h:99
void setMarkerColor(const QColor &c)
Definition ClipView.h:109
QColor selectedColor
Definition ClipView.h:58
void mouseMoveEvent(QMouseEvent *me) override
Handle a mouse movement (drag) on this ClipView.
Definition ClipView.cpp:604
TextFloat * m_hint
Definition ClipView.h:305
void mouseReleaseEvent(QMouseEvent *me) override
Handle a mouse release on this ClipView.
Definition ClipView.cpp:826
auto hasCustomColor() const -> bool
Definition ClipView.cpp:1226
QColor m_markerColor
Definition ClipView.h:316
Action m_action
Definition ClipView.h:300
void randomizeColor()
Definition ClipView.cpp:229
QColor patternClipBackground
Definition ClipView.h:62
void updateLength()
Updates a ClipView's length.
Definition ClipView.cpp:194
QColor textShadowColor() const
Definition ClipView.h:97
void update() override
Update a ClipView.
Definition ClipView.cpp:140
QColor mutedBackgroundColor
Definition ClipView.h:57
virtual bool destructiveSplitClip(const TimePos pos)
Destructively split this Clip into two clips.
Definition ClipView.h:364
TrackView * m_trackView
Definition ClipView.h:169
virtual void constructContextMenu(QMenu *)
Definition ClipView.h:176
virtual void paintTextLabel(QString const &text, QPainter &painter)
Definition ClipView.cpp:413
QColor patternClipBackground() const
Definition ClipView.h:98
static void toggleMute(QVector< ClipView * > clipvs)
Definition ClipView.cpp:1046
void setMarkerEnabled(bool e)
Definition ClipView.h:133
void updateCursor(QMouseEvent *me)
Chooses the correct cursor to be displayed on the widget.
Definition ClipView.cpp:344
QColor textBackgroundColor() const
Definition ClipView.h:96
QColor textBackgroundColor
Definition ClipView.h:60
ModelView(Model *model, QWidget *widget)
Definition ModelView.cpp:33
Definition TextFloat.h:38
Definition TrackView.h:60
selectableObject(QWidget *_parent)
Definition Rubberband.h:40
Definition AudioPortAudio.cpp:209
Definition RemotePluginBase.cpp:34
@ None
Definition LadspaBase.h:49