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 55 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
a08420d
InteractiveModelView_class_implementation
szeli1 Aug 29, 2024
c6e9f44
InteractiveModelView_fixing_errors
szeli1 Aug 30, 2024
3eb9d73
StringPairDrag_implementing_stringpair_enum
szeli1 Aug 30, 2024
d759c68
CMakeLists_adding_new_class
szeli1 Aug 30, 2024
f8e49f9
FileBrowser_implementing_stringpair_enum
szeli1 Aug 30, 2024
dd7672e
PluginBrowser_implementing_stringpair_enum
szeli1 Aug 30, 2024
934d977
AutomationClipView_implementing_stringpair_enum
szeli1 Aug 30, 2024
7133e5c
Track_adding_comment
szeli1 Aug 31, 2024
6ae7952
ClipView_implementing_stringpair_enum
szeli1 Aug 31, 2024
27c1900
TrackView_implementing_stringpair_enum
szeli1 Aug 31, 2024
7998e90
Clipboard_adding_new_enum_items
szeli1 Aug 31, 2024
8063e28
InteractiveModelView_static_list_declaration
szeli1 Aug 31, 2024
00a5417
SampleClipView_implementing_stringpair_enum
szeli1 Aug 31, 2024
5999d47
AutomationEditor_implementing_stringpair_enum
szeli1 Aug 31, 2024
4653e67
PatternEditor_implementing_sringpair_enum
szeli1 Aug 31, 2024
e832309
TrackContainerView_implementing_stringpair_enum
szeli1 Aug 31, 2024
f087db1
EnvelopeAndLfoView_implementing_stringpair_enum
szeli1 Aug 31, 2024
c75a9b3
InsrumentTrackWindow_implementing_stringpair_enum
szeli1 Aug 31, 2024
b7b726b
PianoView_implementing_stringpair_enum
szeli1 Aug 31, 2024
07ea739
AutomationTraclView_implementing_stringpair_enum
szeli1 Aug 31, 2024
d13ebd0
TrackContentWidget_implementing_stringpair_enum
szeli1 Aug 31, 2024
1841421
SampleTrackView_implementing_stringpair_enum
szeli1 Aug 31, 2024
f37f4a4
TrackOpeartionsWidget_implementing_stingpair_enum
szeli1 Aug 31, 2024
6f2c059
AutomatableButton_implemening_stringpair_enum
szeli1 Aug 31, 2024
9b74e7c
FloatModelEditorBase_implementing_stringpair_enum
szeli1 Aug 31, 2024
3c13751
Graph_implementing_stringpair_enum
szeli1 Aug 31, 2024
18f55ac
Patman_implementing_stringpair_enum
szeli1 Aug 31, 2024
a7005d7
SlicerTView_implementing_stringpair_enum
szeli1 Aug 31, 2024
3bc6877
Vestige_implementing_stringpair_enum
szeli1 Aug 31, 2024
6a108e6
ZynAddSubFx_implementing_stringpair_enum
szeli1 Aug 31, 2024
4b29820
AudioFileProcessorView_implementing_stringpair_enum
szeli1 Aug 31, 2024
41796ca
IntractiveModelView_implementing_SimpleTextFloat
szeli1 Sep 1, 2024
8f111c1
FloatModelEditorBase_implementing_InteractiveModelView
szeli1 Sep 1, 2024
2de649e
SimpleTextFloat_Implementing_new_function
szeli1 Sep 1, 2024
aff8ca7
Clipboard_fixed_bug
szeli1 Sep 1, 2024
c36469d
InteractiveModelView_changed_processPaste
szeli1 Sep 1, 2024
09da72e
FloatModelEditorBase_reimplemening_processPaste
szeli1 Sep 1, 2024
cc660de
style_implementing_InteractiveModelView
szeli1 Sep 1, 2024
79af76b
InteraciteveModelView_implementing_highlighting
szeli1 Sep 1, 2024
d70cb49
Clipboard_style_change
szeli1 Sep 1, 2024
7edd8a8
StringPairDrag_adding_auto_widget_highlighting
szeli1 Sep 1, 2024
ae489e0
FloatModelEditorBase_implementing_widget_highlighting
szeli1 Sep 1, 2024
398c155
BarModelEditor_implementing_widget_highlighting
szeli1 Sep 1, 2024
0698b6d
Knob_implementing_widget_highlighting
szeli1 Sep 1, 2024
2c7d61b
InteractiveModelView_fixed_SimpleTextFloat_position
szeli1 Sep 1, 2024
c07ba45
FloatModelEditorBase_changed_function_order
szeli1 Sep 4, 2024
25f2d87
InteractiveModelView_fixing_issues
szeli1 Sep 5, 2024
00b7d45
ClipView_implementing_InteractiveModelView
szeli1 Sep 5, 2024
ebdcc88
Rubberband_changing_inheritance
szeli1 Sep 5, 2024
b1b0b49
AutomationClipView_implementing_InteractiveModelView
szeli1 Sep 5, 2024
6884fb0
SampleClipView_implementing_InteractiveModelView
szeli1 Sep 5, 2024
a6d7185
FloatModelEditorBase_changing_function_order
szeli1 Sep 5, 2024
b97de0c
MidiClipView_implemented_highlighting
szeli1 Sep 5, 2024
6f88093
PatternClipView_implementing_clip_highlighting
szeli1 Sep 5, 2024
aa20d41
PianoView_changing_focus_code
szeli1 Sep 5, 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
9 changes: 8 additions & 1 deletion include/AutomationClipView.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,19 @@ protected slots:
void paintEvent( QPaintEvent * pe ) override;
void dragEnterEvent( QDragEnterEvent * _dee ) override;
void dropEvent( QDropEvent * _de ) override;


std::vector<ModelShortcut> getShortcuts() override;
void processShortcutPressed(size_t shortcutLocation, QKeyEvent* event) override;
QString getShortcutMessage() override;
bool canAcceptClipboardData(Clipboard::StringPairDataType dataType) override;
bool processPaste(const QMimeData* mimeData) override;

private:
AutomationClip * m_clip;
QPixmap m_paintPixmap;

static QString m_shortcutMessage;

QStaticText m_staticTextName;
void scaleTimemapToFit( float oldMin, float oldMax );
} ;
Expand Down
15 changes: 14 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
std::vector<ModelShortcut> getShortcuts() override;
void processShortcutPressed(size_t shortcutLocation, QKeyEvent* event) override;
QString getShortcutMessage() override;
bool canAcceptClipboardData(Clipboard::StringPairDataType dataType) override;
bool processPaste(const QMimeData* mimeData) 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,7 @@ protected slots:
} ;

static TextFloat * s_textFloat;
static QString m_shortcutMessage;

Clip * m_clip;
Action m_action;
Expand Down
68 changes: 66 additions & 2 deletions include/Clipboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#ifndef LMMS_CLIPBOARD_H
#define LMMS_CLIPBOARD_H

#include <array>

#include <QDomElement>
#include <QMap>

Expand All @@ -40,6 +42,36 @@ namespace lmms::Clipboard
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
};

// Convenience Methods
const QMimeData * getMimeData();
Expand All @@ -50,10 +82,13 @@ 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 );
void copyStringPair(StringPairDataType key, const QString& value);
StringPairDataType decodeKey(const QMimeData* mimeData);
QString decodeValue( const QMimeData * mimeData );

QString clipboardEncodeFloatValue(float value);
QString clipboardEncodeAutomatableModelLink(size_t id);
szeli1 marked this conversation as resolved.
Show resolved Hide resolved

inline const char * mimeType( MimeType type )
{
switch( type )
Expand All @@ -68,6 +103,35 @@ namespace lmms::Clipboard
}
}

const std::array<QString, 22> StringPairDataTypeNames = {
szeli1 marked this conversation as resolved.
Show resolved Hide resolved
QString("None_error"),
QString("FloatValue"),
QString("AutomatableModelLink"),
QString("Instrument"),

QString("PresetFile"),
QString("PluginPresetFile"),
QString("SampleFile"),
QString("SoundFontFile"),
QString("PatchFile"),
QString("VstPluginFile"),
QString("ImportedProject"),
QString("ProjectFile"),

QString("SampleData"),

QString("InstrumentTrack"),
QString("PatternTrack"),
QString("SampleTrack"),
QString("AutomationTrack"),
QString("HiddenAutomationTrack"),

QString("MidiClip"),
QString("PatternClip"),
QString("SampleClip"),
QString("AutomationClip")
};

} // namespace lmms::Clipboard

#endif // LMMS_CLIPBOARD_H
11 changes: 10 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
std::vector<ModelShortcut> getShortcuts() override;
void processShortcutPressed(size_t shortcutLocation, QKeyEvent* event) override;
QString getShortcutMessage() override;
bool canAcceptClipboardData(Clipboard::StringPairDataType dataType) override;
bool processPaste(const QMimeData* mimeData) override;

virtual float getValue(const QPoint & p);

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

static SimpleTextFloat * s_textFloat;
static QString m_shortcutMessage;

BoolModel m_volumeKnob;
FloatModel m_volumeRatio;
Expand Down
159 changes: 159 additions & 0 deletions include/InteractiveModelView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/*
* 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;

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);
protected:
class ModelShortcut
Copy link
Member

Choose a reason for hiding this comment

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

Since this is a simple class that is just used for holding data, you could make it a struct and remove the "m_" prefix from the data members.

{
public:
inline ModelShortcut() {}
Copy link
Member

Choose a reason for hiding this comment

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

Constructors and other methods are already implicitly inline so the inline specifier can be removed.

inline ModelShortcut(Qt::Key key, Qt::KeyboardModifier modifier, unsigned int times, QString description, bool shouldLoop) :
m_key(key),
m_modifier(modifier),
m_times(times),
m_shortcutDescription(description),
m_shouldLoop(shouldLoop)
{
}

inline bool operator==(ModelShortcut& rhs)
{
return m_key == rhs.m_key
&& m_modifier == rhs.m_modifier
&& m_times == rhs.m_times
&& m_shouldLoop == rhs.m_shouldLoop;
}

inline void reset()
{
m_key = Qt::Key_F35;
m_modifier = Qt::NoModifier;
m_times = 0;
m_shortcutDescription = "";
m_shouldLoop = false;
}

Qt::Key m_key = Qt::Key_F35;
Qt::KeyboardModifier m_modifier = Qt::NoModifier;
//! how many times do the keys need to be pressed to activate this shortcut
unsigned int m_times = 0;
//! what the shortcut does
QString m_shortcutDescription = "";
//! should it loop back if m_times is reached
bool m_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 std::vector<ModelShortcut> getShortcuts() = 0;
//! called when a `getShortcuts()` shortcut shortcut is pressed
virtual void processShortcutPressed(size_t shortcutLocation, QKeyEvent* event) = 0;
//! called when a shortcut message needs to be displayed
//! should return the message built with `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 processPaste(const QMimeData* mimeData) = 0;
//! return isHighlighted
//! 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;

QWidget* m_focusedBeforeWidget;

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