Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Widget highlighting and shortcut system implementation #7488

Open
wants to merge 81 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
97b682f
InteractiveModelView_class_implementation
szeli1 Aug 29, 2024
36f1259
InteractiveModelView_fixing_errors
szeli1 Aug 30, 2024
884964c
StringPairDrag_implementing_stringpair_enum
szeli1 Aug 30, 2024
a61b4bf
CMakeLists_adding_new_class
szeli1 Aug 30, 2024
05aedb8
FileBrowser_implementing_stringpair_enum
szeli1 Aug 30, 2024
d31683a
PluginBrowser_implementing_stringpair_enum
szeli1 Aug 30, 2024
b8fe07e
AutomationClipView_implementing_stringpair_enum
szeli1 Aug 30, 2024
c6d0b6b
Track_adding_comment
szeli1 Aug 31, 2024
93da665
ClipView_implementing_stringpair_enum
szeli1 Aug 31, 2024
55f87e9
TrackView_implementing_stringpair_enum
szeli1 Aug 31, 2024
c2c2e6e
Clipboard_adding_new_enum_items
szeli1 Aug 31, 2024
a278b5c
InteractiveModelView_static_list_declaration
szeli1 Aug 31, 2024
0835867
SampleClipView_implementing_stringpair_enum
szeli1 Aug 31, 2024
19eb5a0
AutomationEditor_implementing_stringpair_enum
szeli1 Aug 31, 2024
83ffcaf
PatternEditor_implementing_sringpair_enum
szeli1 Aug 31, 2024
460b583
TrackContainerView_implementing_stringpair_enum
szeli1 Aug 31, 2024
6bb6576
EnvelopeAndLfoView_implementing_stringpair_enum
szeli1 Aug 31, 2024
3884277
InsrumentTrackWindow_implementing_stringpair_enum
szeli1 Aug 31, 2024
d5d87b2
PianoView_implementing_stringpair_enum
szeli1 Aug 31, 2024
31ef8a0
AutomationTraclView_implementing_stringpair_enum
szeli1 Aug 31, 2024
6b6020b
TrackContentWidget_implementing_stringpair_enum
szeli1 Aug 31, 2024
72f4edc
SampleTrackView_implementing_stringpair_enum
szeli1 Aug 31, 2024
2042f06
TrackOpeartionsWidget_implementing_stingpair_enum
szeli1 Aug 31, 2024
ad346d7
AutomatableButton_implemening_stringpair_enum
szeli1 Aug 31, 2024
6b05a09
FloatModelEditorBase_implementing_stringpair_enum
szeli1 Aug 31, 2024
e1e1718
Graph_implementing_stringpair_enum
szeli1 Aug 31, 2024
05bf3f7
Patman_implementing_stringpair_enum
szeli1 Aug 31, 2024
9e14b85
SlicerTView_implementing_stringpair_enum
szeli1 Aug 31, 2024
e570f6a
Vestige_implementing_stringpair_enum
szeli1 Aug 31, 2024
abb3866
ZynAddSubFx_implementing_stringpair_enum
szeli1 Aug 31, 2024
ca9373a
AudioFileProcessorView_implementing_stringpair_enum
szeli1 Aug 31, 2024
bab9b37
IntractiveModelView_implementing_SimpleTextFloat
szeli1 Sep 1, 2024
febe6b0
FloatModelEditorBase_implementing_InteractiveModelView
szeli1 Sep 1, 2024
6f50a10
SimpleTextFloat_Implementing_new_function
szeli1 Sep 1, 2024
5293080
Clipboard_fixed_bug
szeli1 Sep 1, 2024
a8342f8
InteractiveModelView_changed_processPaste
szeli1 Sep 1, 2024
053bb0f
FloatModelEditorBase_reimplemening_processPaste
szeli1 Sep 1, 2024
6d5a6c8
style_implementing_InteractiveModelView
szeli1 Sep 1, 2024
701243e
InteraciteveModelView_implementing_highlighting
szeli1 Sep 1, 2024
61b42b1
Clipboard_style_change
szeli1 Sep 1, 2024
53630dc
StringPairDrag_adding_auto_widget_highlighting
szeli1 Sep 1, 2024
7b86c23
FloatModelEditorBase_implementing_widget_highlighting
szeli1 Sep 1, 2024
1ee53f6
BarModelEditor_implementing_widget_highlighting
szeli1 Sep 1, 2024
cc38ff9
Knob_implementing_widget_highlighting
szeli1 Sep 1, 2024
98c28bd
InteractiveModelView_fixed_SimpleTextFloat_position
szeli1 Sep 1, 2024
6c5d940
FloatModelEditorBase_changed_function_order
szeli1 Sep 4, 2024
c6b34ab
InteractiveModelView_fixing_issues
szeli1 Sep 5, 2024
67e93eb
ClipView_implementing_InteractiveModelView
szeli1 Sep 5, 2024
d7dde0d
Rubberband_changing_inheritance
szeli1 Sep 5, 2024
7bd3571
AutomationClipView_implementing_InteractiveModelView
szeli1 Sep 5, 2024
36eaa37
SampleClipView_implementing_InteractiveModelView
szeli1 Sep 5, 2024
0aeb7bb
FloatModelEditorBase_changing_function_order
szeli1 Sep 5, 2024
42bd0e0
MidiClipView_implemented_highlighting
szeli1 Sep 5, 2024
a8c1820
PatternClipView_implementing_clip_highlighting
szeli1 Sep 5, 2024
7433b3f
PianoView_changing_focus_code
szeli1 Sep 5, 2024
e337969
Clipboard_removeing_array
szeli1 Sep 6, 2024
111d321
StringPairDrag_replacing_clipboard_array
szeli1 Sep 6, 2024
a7280c8
AutomatableModelView_renaming_function
szeli1 Sep 6, 2024
ee284c7
PianoView_renaming_function
szeli1 Sep 6, 2024
1b31b25
FloatModelEditorBase_renaming_function
szeli1 Sep 6, 2024
ba25d44
StringPairDrag_format_changes
szeli1 Sep 6, 2024
7d8f655
ClipView_separating_processPaste
szeli1 Sep 7, 2024
dcd50b6
InteractiveModelView_separating_processPaste
szeli1 Sep 7, 2024
8ca4596
AutomationClipView_separating_processPaste
szeli1 Sep 7, 2024
9ca52f3
SampleClipView_separating_processPate
szeli1 Sep 7, 2024
00dc936
FloatModelEditorBase_separating_processPaste
szeli1 Sep 7, 2024
2ab4e2f
TrackContentWidget_replacing_mimeData_with_key_value_pairs
szeli1 Sep 7, 2024
703e37a
InteractiveModelView_fixing_focusing_issues
szeli1 Nov 2, 2024
7f8e294
InteractiveModelView_removing_unused_code
szeli1 Nov 2, 2024
957c33d
MainWindow_adding_InteractiveModelView_focus_helper_functions
szeli1 Nov 2, 2024
ca37609
PianoView_fixing_merge_conflict
szeli1 Nov 2, 2024
c0cdcf7
InteractiveModelView_changing_shortcut_class_to_struct
szeli1 Nov 2, 2024
c409413
InteractiveModelView_updating_highlight_timer
szeli1 Nov 2, 2024
42a099e
FloatModelEditorBase_making_shortcut_array_static
szeli1 Nov 2, 2024
ee5ac8c
InteractiveModelView_changing_method
szeli1 Nov 2, 2024
17fdab5
ClipView_making_shortcut_array_static
szeli1 Nov 2, 2024
5cd61a6
AutomationClipView_making_shortcut_array_static
szeli1 Nov 2, 2024
2012037
MainWindow_remove_qDebug
szeli1 Nov 2, 2024
c3c9d86
Lv2Instrument_updating_StringPair_usage
szeli1 Nov 3, 2024
9aad0cf
Lv2Instrument_fixing_error
szeli1 Nov 3, 2024
7ef78cd
AutomationClipView_fixing_shortcuts
szeli1 Nov 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions data/themes/classic/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ QMdiArea {
background-image: url("resources:background_artwork.png");
}

lmms--gui--InteractiveModelView {
qproperty-highlightColor: rgb(38, 237, 231);
}

lmms--gui--Knob {
qproperty-lineInactiveColor: rgb(120, 120, 120);
qproperty-arcInactiveColor: rgba(120, 120, 120, 70);
Expand Down
4 changes: 4 additions & 0 deletions data/themes/default/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ lmms--gui--FileBrowser QCheckBox
color: white;
}

lmms--gui--InteractiveModelView {
qproperty-highlightColor: rgb(42, 219, 49);
}

lmms--gui--Knob {
qproperty-lineInactiveColor: rgb(120, 120, 120);
qproperty-arcInactiveColor: rgba(120, 120, 120, 70);
Expand Down
10 changes: 9 additions & 1 deletion include/AutomationClipView.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,20 @@ protected slots:
void paintEvent( QPaintEvent * pe ) override;
void dragEnterEvent( QDragEnterEvent * _dee ) override;
void dropEvent( QDropEvent * _de ) override;


const std::vector<ModelShortcut>& getShortcuts() override;
void processShortcutPressed(size_t shortcutLocation, QKeyEvent* event) override;
QString getShortcutMessage() override;
bool canAcceptClipboardData(Clipboard::StringPairDataType dataType) override;
bool processPasteImplementation(Clipboard::StringPairDataType type, QString& value) override;

private:
AutomationClip * m_clip;
QPixmap m_paintPixmap;

static QString m_shortcutMessage;
static std::vector<InteractiveModelView::ModelShortcut> s_shortcutArray;

QStaticText m_staticTextName;
void scaleTimemapToFit( float oldMin, float oldMax );
} ;
Expand Down
16 changes: 15 additions & 1 deletion include/ClipView.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "ModelView.h"
#include "Rubberband.h"
#include "Clip.h"
#include "Clipboard.h"


class QMenu;
Expand Down Expand Up @@ -125,6 +126,9 @@ class ClipView : public selectableObject, public ModelView

// Returns true if selection can be merged and false if not
static bool canMergeSelection(QVector<ClipView*> clipvs);

//! used for getting the correct clip `StringPairDataType` for a given track
static Clipboard::StringPairDataType getClipStringPairType(Track* track);

QColor getColorForDisplay( QColor );

Expand Down Expand Up @@ -174,6 +178,14 @@ public slots:
m_needsUpdate = true;
selectableObject::resizeEvent( re );
}

// InteractiveModelView methods
const std::vector<ModelShortcut>& getShortcuts() override;
void processShortcutPressed(size_t shortcutLocation, QKeyEvent* event) override;
QString getShortcutMessage() override;
bool canAcceptClipboardData(Clipboard::StringPairDataType dataType) override;
bool processPasteImplementation(Clipboard::StringPairDataType type, QString& value) override;
void overrideSetIsHighlighted(bool isHighlighted) override;

bool unquantizedModHeld( QMouseEvent * me );
TimePos quantizeSplitPos( TimePos, bool shiftMode );
Expand All @@ -191,7 +203,7 @@ protected slots:
void updateLength();
void updatePosition();


static QString getDefaultSortcutMessage();
private:
enum class Action
{
Expand All @@ -206,6 +218,8 @@ protected slots:
} ;

static TextFloat * s_textFloat;
static QString m_shortcutMessage;
static std::vector<InteractiveModelView::ModelShortcut> s_shortcutArray;

Clip * m_clip;
Action m_action;
Expand Down
50 changes: 46 additions & 4 deletions include/Clipboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,51 @@

class QMimeData;

namespace lmms::Clipboard
namespace lmms
{

class AutomatableModel;

namespace Clipboard
{

enum class MimeType
{
StringPair,
Default
};

enum StringPairDataType
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name could probably be shortened to just DataType or something.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which one is better: KeyType or PairType or PairDataType or maybe CarriedDataType? I think DataType doesn't say anything about the StringPairDrag system and it could be confusing because there is also a Default mime type, but I guess this can be fixed with a comment.

I would like to get a finalized name because this change would effect 30 files.

{
None, //!< only use for error handling
FloatValue,
AutomatableModelLink,
Instrument,

PresetFile,
PluginPresetFile,
SampleFile,
SoundFontFile,
PatchFile,
VstPluginFile,
ImportedProject,
ProjectFile,

SampleData,

InstrumentTrack,
PatternTrack,
SampleTrack,
AutomationTrack,
HiddenAutomationTrack,

MidiClip,
PatternClip,
SampleClip,
AutomationClip,

Count //!< utility, do not use
};

// Convenience Methods
const QMimeData * getMimeData();
Expand All @@ -50,10 +87,14 @@ namespace lmms::Clipboard
QString getString( MimeType mT );

// Helper methods for String Pair data
void copyStringPair( const QString & key, const QString & value );
QString decodeKey( const QMimeData * mimeData );
QString getStringPairKeyName(StringPairDataType type);
void copyStringPair(StringPairDataType key, const QString& value);
StringPairDataType decodeKey(const QMimeData* mimeData);
QString decodeValue( const QMimeData * mimeData );

QString encodeFloatValue(float value);
QString encodeAutomatableModelLink(const AutomatableModel& model);

inline const char * mimeType( MimeType type )
{
switch( type )
Expand All @@ -67,7 +108,8 @@ namespace lmms::Clipboard
break;
}
}
} // namespace Clipboard

} // namespace lmms::Clipboard
} // namespace lmms

#endif // LMMS_CLIPBOARD_H
12 changes: 11 additions & 1 deletion include/FloatModelEditorBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@
#include <QPoint>

#include "AutomatableModelView.h"
#include "InteractiveModelView.h"


namespace lmms::gui
{

class SimpleTextFloat;

class LMMS_EXPORT FloatModelEditorBase : public QWidget, public FloatModelView
class LMMS_EXPORT FloatModelEditorBase : public InteractiveModelView, public FloatModelView
{
Q_OBJECT

Expand Down Expand Up @@ -84,6 +85,13 @@ class LMMS_EXPORT FloatModelEditorBase : public QWidget, public FloatModelView
void enterEvent(QEvent *event) override;
void leaveEvent(QEvent *event) override;

// InteractiveModelView methods
const std::vector<ModelShortcut>& getShortcuts() override;
void processShortcutPressed(size_t shortcutLocation, QKeyEvent* event) override;
QString getShortcutMessage() override;
bool canAcceptClipboardData(Clipboard::StringPairDataType dataType) override;
bool processPasteImplementation(Clipboard::StringPairDataType type, QString& value) override;

virtual float getValue(const QPoint & p);

private slots:
Expand All @@ -105,6 +113,8 @@ private slots:
}

static SimpleTextFloat * s_textFloat;
static QString m_shortcutMessage;
static std::vector<InteractiveModelView::ModelShortcut> s_shortcutArray;

BoolModel m_volumeKnob;
FloatModel m_volumeRatio;
Expand Down
161 changes: 161 additions & 0 deletions include/InteractiveModelView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/*
* InteractiveModelView.h - TODO
*
* Copyright (c) 2024 szeli1 <TODO/at/gmail/dot/com>
*
* This file is part of LMMS - https://lmms.io
*
* 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) any later version.
*
* 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 (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/

#ifndef LMMS_GUI_INTERACTIVE_MODEL_VIEW_H
#define LMMS_GUI_INTERACTIVE_MODEL_VIEW_H

#include <list>
#include <memory>
#include <vector>

#include <QApplication>
#include <QWidget>
#include <QColor>

#include "Clipboard.h"
#include "lmms_export.h"
#include "ModelView.h"

class QColor;
class QMimeData;
class QPainter;
class QTimer;

namespace lmms::gui
{

class SimpleTextFloat;

class LMMS_EXPORT InteractiveModelView : public QWidget
{
Q_OBJECT
Q_PROPERTY(QColor highlightColor READ getHighlightColor WRITE setHighlightColor)
public:
InteractiveModelView(QWidget* widget);
~InteractiveModelView() override;

//! highlight every InteractiveModelView that accepts dataType
static void startHighlighting(Clipboard::StringPairDataType dataType);
static void stopHighlighting();
static void showMessage(QString& message);
static void hideMessage();

static QColor getHighlightColor();
static void setHighlightColor(QColor& color);

// returns true if successful
bool HandleKeyPress(QKeyEvent* event);
protected:
struct ModelShortcut
{
ModelShortcut() {}
ModelShortcut(Qt::Key key, Qt::KeyboardModifier modifier, unsigned int times, QString description, bool shouldLoop) :
key(key),
modifier(modifier),
times(times),
shortcutDescription(description),
shouldLoop(shouldLoop)
{
}

bool operator==(ModelShortcut& rhs)
{
return key == rhs.key
&& modifier == rhs.modifier
&& times == rhs.times
&& shouldLoop == rhs.shouldLoop;
}

void reset()
{
key = Qt::Key_F35;
modifier = Qt::NoModifier;
times = 0;
shortcutDescription = "";
shouldLoop = false;
}

Qt::Key key = Qt::Key_F35;
Qt::KeyboardModifier modifier = Qt::NoModifier;
//! how many times do the keys need to be pressed to activate this shortcut
unsigned int times = 0;
//! what the shortcut does
QString shortcutDescription = "";
//! should it loop back if m_times is reached
bool shouldLoop = false;
};

void keyPressEvent(QKeyEvent* event) override;
void enterEvent(QEvent* event) override;
void leaveEvent(QEvent* event) override;

//! return the avalible shortcuts for the widget
virtual const std::vector<ModelShortcut>& getShortcuts() = 0;
//! called when a shortcut from `getShortcuts()` is pressed
virtual void processShortcutPressed(size_t shortcutLocation, QKeyEvent* event) = 0;
//! called when a shortcut message needs to be displayed
//! shortcut messages can be generated with `buildShortcutMessage()` (but it can be unoptimized to return `buildShortcutMessage()`)
virtual QString getShortcutMessage() = 0;
//! return true if the widget supports pasting / dropping `dataType` (used for StringPairDrag and Copying)
virtual bool canAcceptClipboardData(Clipboard::StringPairDataType dataType) = 0;
//! should implement dragging and dropping widgets or pasting from clipboard
//! should return if `QDropEvent` event can be accepted
//! force implement this method
virtual bool processPasteImplementation(Clipboard::StringPairDataType type, QString& value) = 0;
//! calls `processPasteImplementation()` to process paste
bool processPaste(const QMimeData* mimeData);
//! override this if the widget requires custom updating code
virtual void overrideSetIsHighlighted(bool isHighlighted);

//! draws the highlight automatically for the widget if highilighted
void drawAutoHighlight(QPainter* painter);
//! builds a string from `getShortcuts()`
QString buildShortcutMessage();

bool getIsHighlighted() const;
void setIsHighlighted(bool isHighlighted);
private slots:
inline static void timerStopHighlighting()
{
stopHighlighting();
}
private:
bool doesShortcutMatch(const ModelShortcut* shortcut, QKeyEvent* event) const;
bool doesShortcutMatch(const ModelShortcut* shortcutA, const ModelShortcut* shortcutB) const;


bool m_isHighlighted;

ModelShortcut m_lastShortcut;
unsigned int m_lastShortcutCounter;

static std::unique_ptr<QColor> s_highlightColor;
static QTimer* s_highlightTimer;
static SimpleTextFloat* s_simpleTextFloat;
static std::list<InteractiveModelView*> s_interactiveWidgets;
};

} // namespace lmms::gui

#endif // LMMS_GUI_INTERACTIVE_MODEL_VIEW_H
Loading
Loading