-
-
Notifications
You must be signed in to change notification settings - Fork 994
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
base: master
Are you sure you want to change the base?
Changes from all commits
a08420d
c6e9f44
3eb9d73
d759c68
f8e49f9
dd7672e
934d977
7133e5c
6ae7952
27c1900
7998e90
8063e28
00a5417
5999d47
4653e67
e832309
f087db1
c75a9b3
b7b726b
07ea739
d13ebd0
1841421
f37f4a4
6f2c059
9b74e7c
3c13751
18f55ac
a7005d7
3bc6877
6a108e6
4b29820
41796ca
8f111c1
2de649e
aff8ca7
c36469d
09da72e
cc660de
79af76b
d70cb49
7edd8a8
ae489e0
398c155
0698b6d
2c7d61b
c07ba45
25f2d87
00b7d45
ebdcc88
b1b0b49
6884fb0
a6d7185
b97de0c
6f88093
aa20d41
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Constructors and other methods are already implicitly |
||
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 |
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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
orPairType
orPairDataType
or maybeCarriedDataType
? I thinkDataType
doesn't say anything about theStringPairDrag
system and it could be confusing because there is also aDefault
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.