Improve the context menu actions when multiple TCOs are selected (#5601)
* Starts implementing the feature
The idea of this branch is to allow actions triggered through the context menu of a TCO on the song editor to affect all the selected TCOs. With this commit, only the "Mute/unmute" action affects all selected TCOs, while the others retain their old behavior (only affect the TCO that owns the context menu).
For that, a method was created that processes all actions (the triggered action is parsed as a parameter to the method). In the case of the "Mute" action, it checks if the song editor has selected TCOs, and if it does it mutes/unmutes all of them.
* Allows selected TCOs to be removed too
Now the "Remove" action from the context menu will remove all selected TCOs if there are any.
* Starts implementing selected TCO cut and copy
Now, when multiple TCOs are selected, the context menu actions Cut and Copy will write a DataFile to the clipboard containing the TCO information, so it can later be used to paste it.
The Paste action now checks if there's data in the QApplication clipboard. If there is, it will later paste the TCOs (for now it just prints the data with qWarning). If there's not, it uses the regular TCO paste method that uses the internal LMMS clipboard. Because it now have to decide between the QApplication clipboard and the LMMS internal clipboard, the Clipboard::copy() method now clears anything in the QApplication clipboard, making it empty so LMMS can know it should use the internal clipboard instead in that situation.
Adds safety checks for the selected TCO views.
* Overloads TCW paste selection methods
This commit is a step towards implementing the paste feature of the TCO context menu. It overloads the TrackContentWidget::canPasteSelection and TrackContentWidget::pasteSelection methods so they can be called without having a QDropEvent (only the QMimeData with the copied TCOs information). The overloaded canPasteSelection(MidiTime, QMimeData, bool) method required a third argument which says whether pasting over the same bar should be allowed or not, because it shouldn't when the QDropEvent comes from the same application but should when it doesn't. That is defined in the canPasteSelection(MidiTime, QDropEvent) method.
Also, the pasteSelection(MidiTime, QDropEvent) isn't optimal, since it calls canPasteSelection twice (more details in the comments, but it's basically because the two canPasteSelection methods can return different values depending on the origin of QDropEvent). This could later be fixed by calling canPasteSelection before pasteSelection and removing it from inside the method altogether.
Next step is to add the "tco_" key to the mimeData on the Copy/Cut operations and implementing the paste operation using those methods.
* Adds the TCO type to the clipboard
Adds the key with the TCO type ("tco_" + type number + ":" + TCO Data XML) to the clipboard, so it can be later used by the canPasteSelection and pasteSelection methods.
* Apply changes to "src/tracks/SampleTrack.cpp"
Change the SampleTCOView::contextMenuEvent() method so it behaves the same way as the TrackContentObjectView::contextMenuEvent() method. For that, I had to change the ContextMenuAction enum and the contextMenuAction methods to be protected instead of private, so SampleTCOView can access it.
* Implement the paste action
Now that the canPasteSelection and pasteSelection methods were overloaded, it was possible to implement the paste action using the same logic as the Drag&Drop copy/paste.
Other small changes:
- Removes the TCO views AFTER creating the TCO data file, instead of before (which probably resulted in an empty data file).
- Uses the StringPairDrag::mimeType() instead of Clipboard::mimeType() since that's the one the methods from StringPairDrag.cpp recognizes.
* Removes QDebug header
Forgot to remove the QDebug header on the last commit.
* Creates a Context Menu on the TCW for "paste"
Now it's possible to paste a selection of copied TCOs anywhere in the TCW, as long as the rules to paste are met (same rules as Drag&Drop copy/paste). If the rules are not met the "Paste" menu action shows but is disabled.
* Small code refactoring
Saving a few lines of code.
* Avoids double call to canPasteSelection
This commit adds a third parameter to the pasteSelection overloaded method, which will define whether we whould skip the canPasteSelection check. The only situation where we will want to skip it is if we are calling pasteSelection from inside the other pasteSelection method, which will already have checked it. Because of that the default value is false.
Organizes comments as well.
* Separates methods for the actions on selections
Now the remove, copy, cut, paste and toggle mute actions have a separate method for applying them to selections, which are then called from the contextMenuAction method. That made the code more organized and the contextMenuAction method smaller.
Also, the mouse shortcuts for muting and removing (CTRL+middle button, middle button, CTRL+right button) now apply the action on selections as well.
* Fixes small bug and reorganize code
Fixes a small bug where using a mouse shortcut or choosing an action on a TCO that is not selected while other TCOs were selected would result in the selection being affected.
Also reorganizes the code so the conditional for choosing between the selection action and the individual action stays inside the method.
* Move logic to the action methods
Since the methods that called the action+Selection() methods didn't need the list of selectableObjects, I moved it to the inside of the action+Selection() methods and removed the parameter from them.
* Changes logic structure and labels
As suggested by Spekular, the logic structure was changed. Now, the mousePressEvent and contextMenuAction methods determine whether the action should happen to a selection of TCOs or an individual TCO. The list of TCOs to be affected populate a QVector list called "active", which is parsed to the action method that will apply the action to each object in the list.
I changed the method names to removeActive, cutActive, copyActive and toggleMuteActive, since I believe that better describe the behavior. The paste method is still called pasteSelection for now, because the paste behavior isn't related to the active TCOs but to the content of the clipboard.
The contextMenuEvent method on both src/core/Track.cpp and src/tracks/SampleTrack.cpp were changed so they also check if the right-clicked TCO is part of a selection or an individual TCO, and the labels for the actions are changed to better describe the behavior (i.e.: "Delete" for individual TCO and "Delete selection" for multiple TCOs).
* Make removeActive and toggleMuteActive static
removeActive and toggleMuteActive methods are now static so they can be called from anywhere in the code since they don't require a TCO view instance to work. That makes it possible for them to be used in the future if any feature requires this type of action to be called from out of a TCO view instance.
The same couldn't be done for the copyActive and cutActive methods because those require an instance of the TCO view to call them, since when copying to the clipboard some metadata is written using information from the object instance.
* Renamed TCO View paste method
I renamed the TCO View paste method from pasteSelection to just paste, since the TCO view doesn't currently have a paste method (only the TCO class). It's also a name that accurately describes the action: it will paste either a group of TCOVs or a single TCOV on the current TCOV.
I also moved the logic for deciding between the multiple TCOV paste and single TCOV paste inside the paste method.
* Moves repeated code to a new method
This commit adds another method to TrackContentObjectView called getClickedTCOs, which will return a QVector with the TCO views that are supposed to be affected by a context menu action (either the individual right-clicked TCO or the selection of TCOs). Code was updated on the other methods to make use of this new method.
Method names for actions that affect multiple TCOs were changed. Instead of calling them copyActive, cutActive, toggleMuteActive and removeActive, they are just called copy, cut, toggleMute and remove, hence they are overloaded methods for those actions that affect multiple TCOs (their differenciation is the arguments list, which is a QVector list for those).
* Avoid unnecessary calls to getClickedTCOs()
We use a ternary operator inside TrackContentObjectView::mousePressEvent to avoid unnecessary calls to getClickedTCOs when the list is not going to be used.
The contextMenuEvent method on both Track.cpp and SampleTrack.cpp was reformated to use a more appropriate indentation and spacing between method calls.
* Fix indenting in a ternary operator assignment
This commit is contained in:
@@ -250,6 +250,20 @@ public:
|
||||
bool needsUpdate();
|
||||
void setNeedsUpdate( bool b );
|
||||
|
||||
// Method to get a QVector of TCOs to be affected by a context menu action
|
||||
QVector<TrackContentObjectView *> getClickedTCOs();
|
||||
|
||||
// Methods to remove, copy, cut, paste and mute a QVector of TCO views
|
||||
void copy( QVector<TrackContentObjectView *> tcovs );
|
||||
void cut( QVector<TrackContentObjectView *> tcovs );
|
||||
void paste();
|
||||
// remove and toggleMute are static because they don't depend
|
||||
// being called from a particular TCO view, but can be called anywhere as long
|
||||
// as a valid TCO view list is given, while copy/cut require an instance for
|
||||
// some metadata to be written to the clipboard.
|
||||
static void remove( QVector<TrackContentObjectView *> tcovs );
|
||||
static void toggleMute( QVector<TrackContentObjectView *> tcovs );
|
||||
|
||||
public slots:
|
||||
virtual bool close();
|
||||
void cut();
|
||||
@@ -257,11 +271,21 @@ public slots:
|
||||
void update() override;
|
||||
|
||||
protected:
|
||||
enum ContextMenuAction
|
||||
{
|
||||
Remove,
|
||||
Cut,
|
||||
Copy,
|
||||
Paste,
|
||||
Mute
|
||||
};
|
||||
|
||||
virtual void constructContextMenu( QMenu * )
|
||||
{
|
||||
}
|
||||
|
||||
void contextMenuEvent( QContextMenuEvent * cme ) override;
|
||||
void contextMenuAction( ContextMenuAction action );
|
||||
void dragEnterEvent( QDragEnterEvent * dee ) override;
|
||||
void dropEvent( QDropEvent * de ) override;
|
||||
void leaveEvent( QEvent * e ) override;
|
||||
@@ -370,7 +394,9 @@ public:
|
||||
}
|
||||
|
||||
bool canPasteSelection( MidiTime tcoPos, const QDropEvent *de );
|
||||
bool canPasteSelection( MidiTime tcoPos, const QMimeData *md, bool allowSameBar = false );
|
||||
bool pasteSelection( MidiTime tcoPos, QDropEvent * de );
|
||||
bool pasteSelection( MidiTime tcoPos, const QMimeData * md, bool skipSafetyCheck = false );
|
||||
|
||||
MidiTime endPosition( const MidiTime & posStart );
|
||||
|
||||
@@ -391,6 +417,13 @@ public slots:
|
||||
void changePosition( const MidiTime & newPos = MidiTime( -1 ) );
|
||||
|
||||
protected:
|
||||
enum ContextMenuAction
|
||||
{
|
||||
Paste
|
||||
};
|
||||
|
||||
void contextMenuEvent( QContextMenuEvent * cme ) override;
|
||||
void contextMenuAction( QContextMenuEvent * cme, ContextMenuAction action );
|
||||
void dragEnterEvent( QDragEnterEvent * dee ) override;
|
||||
void dropEvent( QDropEvent * de ) override;
|
||||
void mousePressEvent( QMouseEvent * me ) override;
|
||||
|
||||
@@ -22,6 +22,9 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
|
||||
#include "Clipboard.h"
|
||||
#include "JournallingObject.h"
|
||||
|
||||
@@ -35,6 +38,10 @@ void Clipboard::copy( JournallingObject * _obj )
|
||||
QDomElement parent = doc.createElement( "Clipboard" );
|
||||
_obj->saveState( doc, parent );
|
||||
content[_obj->nodeName()] = parent.firstChild().toElement();
|
||||
|
||||
// Clear the QApplication clipboard, so we don't have any conflicts when LMMS has to
|
||||
// decide between the QApplication clipboard and the internal clipboard data
|
||||
QApplication::clipboard()->clear( QClipboard::Clipboard );
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
#include <QPainter>
|
||||
#include <QStyleOption>
|
||||
#include <QVariant>
|
||||
#include <QClipboard>
|
||||
|
||||
|
||||
#include "AutomationPattern.h"
|
||||
@@ -734,6 +735,12 @@ void TrackContentObjectView::paintTextLabel(QString const & text, QPainter & pai
|
||||
*/
|
||||
void TrackContentObjectView::mousePressEvent( QMouseEvent * me )
|
||||
{
|
||||
// Right now, active is only used on right/mid clicks actions, so we use a ternary operator
|
||||
// to avoid the overhead of calling getClickedTCOs when it's not used
|
||||
auto active = me->button() == Qt::LeftButton
|
||||
? QVector<TrackContentObjectView *>()
|
||||
: getClickedTCOs();
|
||||
|
||||
setInitialPos( me->pos() );
|
||||
setInitialOffsets();
|
||||
if( !fixedTCOs() && me->button() == Qt::LeftButton )
|
||||
@@ -826,22 +833,22 @@ void TrackContentObjectView::mousePressEvent( QMouseEvent * me )
|
||||
{
|
||||
if( me->modifiers() & Qt::ControlModifier )
|
||||
{
|
||||
m_tco->toggleMute();
|
||||
toggleMute( active );
|
||||
}
|
||||
else if( me->modifiers() & Qt::ShiftModifier && !fixedTCOs() )
|
||||
{
|
||||
remove();
|
||||
remove( active );
|
||||
}
|
||||
}
|
||||
else if( me->button() == Qt::MidButton )
|
||||
{
|
||||
if( me->modifiers() & Qt::ControlModifier )
|
||||
{
|
||||
m_tco->toggleMute();
|
||||
toggleMute( active );
|
||||
}
|
||||
else if( !fixedTCOs() )
|
||||
{
|
||||
remove();
|
||||
remove( active );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1116,34 +1123,203 @@ void TrackContentObjectView::mouseReleaseEvent( QMouseEvent * me )
|
||||
*/
|
||||
void TrackContentObjectView::contextMenuEvent( QContextMenuEvent * cme )
|
||||
{
|
||||
// Depending on whether we right-clicked a selection or an individual TCO we will have
|
||||
// different labels for the actions.
|
||||
bool individualTCO = getClickedTCOs().size() <= 1;
|
||||
|
||||
if( cme->modifiers() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QMenu contextMenu( this );
|
||||
|
||||
if( fixedTCOs() == false )
|
||||
{
|
||||
contextMenu.addAction( embed::getIconPixmap( "cancel" ),
|
||||
tr( "Delete (middle mousebutton)" ),
|
||||
this, SLOT( remove() ) );
|
||||
contextMenu.addAction(
|
||||
embed::getIconPixmap( "cancel" ),
|
||||
tr( individualTCO
|
||||
? "Delete (middle mousebutton)"
|
||||
: "Delete selection (middle mousebutton)" ),
|
||||
[this](){ contextMenuAction( Remove ); } );
|
||||
|
||||
contextMenu.addSeparator();
|
||||
contextMenu.addAction( embed::getIconPixmap( "edit_cut" ),
|
||||
tr( "Cut" ), this, SLOT( cut() ) );
|
||||
|
||||
contextMenu.addAction(
|
||||
embed::getIconPixmap( "edit_cut" ),
|
||||
tr( individualTCO
|
||||
? "Cut"
|
||||
: "Cut selection" ),
|
||||
[this](){ contextMenuAction( Cut ); } );
|
||||
}
|
||||
contextMenu.addAction( embed::getIconPixmap( "edit_copy" ),
|
||||
tr( "Copy" ), m_tco, SLOT( copy() ) );
|
||||
contextMenu.addAction( embed::getIconPixmap( "edit_paste" ),
|
||||
tr( "Paste" ), m_tco, SLOT( paste() ) );
|
||||
|
||||
contextMenu.addAction(
|
||||
embed::getIconPixmap( "edit_copy" ),
|
||||
tr( individualTCO
|
||||
? "Copy"
|
||||
: "Copy selection" ),
|
||||
[this](){ contextMenuAction( Copy ); } );
|
||||
|
||||
contextMenu.addAction(
|
||||
embed::getIconPixmap( "edit_paste" ),
|
||||
tr( "Paste" ),
|
||||
[this](){ contextMenuAction( Paste ); } );
|
||||
|
||||
contextMenu.addSeparator();
|
||||
contextMenu.addAction( embed::getIconPixmap( "muted" ),
|
||||
tr( "Mute/unmute (<%1> + middle click)" ).arg(UI_CTRL_KEY),
|
||||
m_tco, SLOT( toggleMute() ) );
|
||||
|
||||
contextMenu.addAction(
|
||||
embed::getIconPixmap( "muted" ),
|
||||
tr( individualTCO
|
||||
? "Mute/unmute (<%1> + middle click)"
|
||||
: "Mute/unmute selection (<%1> + middle click)" ).arg(UI_CTRL_KEY),
|
||||
[this](){ contextMenuAction( Mute ); } );
|
||||
|
||||
constructContextMenu( &contextMenu );
|
||||
|
||||
contextMenu.exec( QCursor::pos() );
|
||||
}
|
||||
|
||||
// This method processes the actions from the context menu of the TCO View.
|
||||
void TrackContentObjectView::contextMenuAction( ContextMenuAction action )
|
||||
{
|
||||
QVector<TrackContentObjectView *> active = getClickedTCOs();
|
||||
// active will be later used for the remove, copy, cut or toggleMute methods
|
||||
|
||||
switch( action )
|
||||
{
|
||||
case Remove:
|
||||
remove( active );
|
||||
break;
|
||||
case Cut:
|
||||
cut( active );
|
||||
break;
|
||||
case Copy:
|
||||
copy( active );
|
||||
break;
|
||||
case Paste:
|
||||
paste();
|
||||
break;
|
||||
case Mute:
|
||||
toggleMute( active );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QVector<TrackContentObjectView *> TrackContentObjectView::getClickedTCOs()
|
||||
{
|
||||
// Get a list of selected selectableObjects
|
||||
QVector<selectableObject *> sos = gui->songEditor()->m_editor->selectedObjects();
|
||||
|
||||
// Convert to a list of selected TCOVs
|
||||
QVector<TrackContentObjectView *> selection;
|
||||
selection.reserve( sos.size() );
|
||||
for( auto so: sos )
|
||||
{
|
||||
TrackContentObjectView *tcov = dynamic_cast<TrackContentObjectView *> ( so );
|
||||
if( tcov != nullptr )
|
||||
{
|
||||
selection.append( tcov );
|
||||
}
|
||||
}
|
||||
|
||||
// If we clicked part of the selection, affect all selected clips. Otherwise affect the clip we clicked
|
||||
return selection.contains(this)
|
||||
? selection
|
||||
: QVector<TrackContentObjectView *>( 1, this );
|
||||
}
|
||||
|
||||
void TrackContentObjectView::remove( QVector<TrackContentObjectView *> tcovs )
|
||||
{
|
||||
for( auto tcov: tcovs )
|
||||
{
|
||||
// No need to check if it's nullptr because we check when building the QVector
|
||||
tcov->remove();
|
||||
}
|
||||
}
|
||||
|
||||
void TrackContentObjectView::copy( QVector<TrackContentObjectView *> tcovs )
|
||||
{
|
||||
// Checks if there are other selected TCOs and if so copy them as well
|
||||
if( tcovs.size() > 1 )
|
||||
{
|
||||
// Write the TCOs to a DataFile for copying
|
||||
DataFile dataFile = createTCODataFiles( tcovs );
|
||||
|
||||
// Add the TCO type as a key to the final string
|
||||
QString finalString = QString( "tco_%1:%2" ).arg( m_tco->getTrack()->type() ).arg( dataFile.toString() );
|
||||
|
||||
// Copy it to the clipboard
|
||||
QMimeData *tco_content = new QMimeData;
|
||||
tco_content->setData( StringPairDrag::mimeType(), finalString.toUtf8() );
|
||||
QApplication::clipboard()->setMimeData( tco_content, QClipboard::Clipboard );
|
||||
}
|
||||
else
|
||||
{
|
||||
tcovs.at(0)->getTrackContentObject()->copy();
|
||||
}
|
||||
}
|
||||
|
||||
void TrackContentObjectView::cut( QVector<TrackContentObjectView *> tcovs )
|
||||
{
|
||||
// Checks if there are other selected TCOs and if so cut them as well
|
||||
if( tcovs.size() > 1 )
|
||||
{
|
||||
// Write the TCOs to a DataFile for copying
|
||||
DataFile dataFile = createTCODataFiles( tcovs );
|
||||
|
||||
// Now that the dataFile is created we can delete the tracks, since we are cutting
|
||||
// TODO: Is it safe to call tcov->remove(); on the current TCOV instance?
|
||||
remove( tcovs );
|
||||
|
||||
// Add the TCO type as a key to the final string
|
||||
QString finalString = QString( "tco_%1:%2" ).arg( m_tco->getTrack()->type() ).arg( dataFile.toString() );
|
||||
|
||||
// Copy it to the clipboard
|
||||
QMimeData *tco_content = new QMimeData;
|
||||
tco_content->setData( StringPairDrag::mimeType(), finalString.toUtf8() );
|
||||
QApplication::clipboard()->setMimeData( tco_content, QClipboard::Clipboard );
|
||||
}
|
||||
else
|
||||
{
|
||||
tcovs.at(0)->cut();
|
||||
}
|
||||
}
|
||||
|
||||
void TrackContentObjectView::paste()
|
||||
{
|
||||
// NOTE: Because we give preference to the QApplication clipboard over the LMMS Clipboard class, we need to
|
||||
// clear the QApplication Clipboard during the LMMS Clipboard copy operations (Clipboard::copy does that)
|
||||
|
||||
// If we have TCO data on the clipboard paste it. If not, do our regular TCO paste.
|
||||
if( QApplication::clipboard()->mimeData( QClipboard::Clipboard )->hasFormat( StringPairDrag::mimeType() ) )
|
||||
{
|
||||
// Paste the selection on the MidiTime of the selected Track
|
||||
const QMimeData *md = QApplication::clipboard()->mimeData( QClipboard::Clipboard );
|
||||
MidiTime tcoPos = MidiTime( m_tco->startPosition() );
|
||||
|
||||
TrackContentWidget *tcw = getTrackView()->getTrackContentWidget();
|
||||
|
||||
if( tcw->pasteSelection( tcoPos, md ) == true )
|
||||
{
|
||||
// If we succeed on the paste we delete the TCO we pasted on
|
||||
remove();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
getTrackContentObject()->paste();
|
||||
}
|
||||
}
|
||||
|
||||
void TrackContentObjectView::toggleMute( QVector<TrackContentObjectView *> tcovs )
|
||||
{
|
||||
for( auto tcov: tcovs )
|
||||
{
|
||||
// No need to check for nullptr because we check while building the tcovs QVector
|
||||
tcov->getTrackContentObject()->toggleMute();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1519,9 +1695,19 @@ bool TrackContentWidget::canPasteSelection( MidiTime tcoPos, const QDropEvent* d
|
||||
{
|
||||
const QMimeData * mimeData = de->mimeData();
|
||||
|
||||
// If the source of the DropEvent is the current instance of LMMS we don't allow pasting in the same bar
|
||||
// if it's another instance of LMMS we allow it
|
||||
return de->source()
|
||||
? canPasteSelection( tcoPos, mimeData )
|
||||
: canPasteSelection( tcoPos, mimeData, true );
|
||||
}
|
||||
|
||||
// Overloaded method to make it possible to call this method without a Drag&Drop event
|
||||
bool TrackContentWidget::canPasteSelection( MidiTime tcoPos, const QMimeData* md , bool allowSameBar )
|
||||
{
|
||||
Track * t = getTrack();
|
||||
QString type = StringPairDrag::decodeMimeKey( mimeData );
|
||||
QString value = StringPairDrag::decodeMimeValue( mimeData );
|
||||
QString type = StringPairDrag::decodeMimeKey( md );
|
||||
QString value = StringPairDrag::decodeMimeValue( md );
|
||||
|
||||
// We can only paste into tracks of the same type
|
||||
if( type != ( "tco_" + QString::number( t->type() ) ) ||
|
||||
@@ -1547,9 +1733,9 @@ bool TrackContentWidget::canPasteSelection( MidiTime tcoPos, const QDropEvent* d
|
||||
const TrackContainer::TrackList tracks = t->trackContainer()->tracks();
|
||||
const int currentTrackIndex = tracks.indexOf( t );
|
||||
|
||||
// Don't paste if we're on the same bar
|
||||
// Don't paste if we're on the same bar and allowSameBar is false
|
||||
auto sourceTrackContainerId = metadata.attributeNode( "trackContainerId" ).value().toUInt();
|
||||
if( de->source() && sourceTrackContainerId == t->trackContainer()->id() &&
|
||||
if( !allowSameBar && sourceTrackContainerId == t->trackContainer()->id() &&
|
||||
tcoPos == grabbedTCOBar && currentTrackIndex == initialTrackIndex )
|
||||
{
|
||||
return false;
|
||||
@@ -1591,13 +1777,28 @@ bool TrackContentWidget::canPasteSelection( MidiTime tcoPos, const QDropEvent* d
|
||||
*/
|
||||
bool TrackContentWidget::pasteSelection( MidiTime tcoPos, QDropEvent * de )
|
||||
{
|
||||
const QMimeData * mimeData = de->mimeData();
|
||||
|
||||
if( canPasteSelection( tcoPos, de ) == false )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
QString type = StringPairDrag::decodeKey( de );
|
||||
QString value = StringPairDrag::decodeValue( de );
|
||||
// We set skipSafetyCheck to true because we already called canPasteSelection
|
||||
return pasteSelection( tcoPos, mimeData, true );
|
||||
}
|
||||
|
||||
// Overloaded method so we can call it without a Drag&Drop event
|
||||
bool TrackContentWidget::pasteSelection( MidiTime tcoPos, const QMimeData * md, bool skipSafetyCheck )
|
||||
{
|
||||
// When canPasteSelection was already called before, skipSafetyCheck will skip this
|
||||
if( !skipSafetyCheck && canPasteSelection( tcoPos, md ) == false )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
QString type = StringPairDrag::decodeMimeKey( md );
|
||||
QString value = StringPairDrag::decodeMimeValue( md );
|
||||
|
||||
getTrack()->addJournalCheckPoint();
|
||||
|
||||
@@ -1789,6 +1990,43 @@ MidiTime TrackContentWidget::endPosition( const MidiTime & posStart )
|
||||
return posStart + static_cast<int>( w * MidiTime::ticksPerBar() / ppb );
|
||||
}
|
||||
|
||||
void TrackContentWidget::contextMenuEvent( QContextMenuEvent * cme )
|
||||
{
|
||||
if( cme->modifiers() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// If we don't have TCO data in the clipboard there's no need to create this menu
|
||||
// since "paste" is the only action at the moment.
|
||||
const QMimeData *md = QApplication::clipboard()->mimeData( QClipboard::Clipboard );
|
||||
if( !md->hasFormat( StringPairDrag::mimeType() ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QMenu contextMenu( this );
|
||||
QAction *pasteA = contextMenu.addAction( embed::getIconPixmap( "edit_paste" ),
|
||||
tr( "Paste" ), [this, cme](){ contextMenuAction( cme, Paste ); } );
|
||||
// If we can't paste in the current TCW for some reason, disable the action so the user knows
|
||||
pasteA->setEnabled( canPasteSelection( getPosition( cme->x() ), md ) ? true : false );
|
||||
|
||||
contextMenu.exec( QCursor::pos() );
|
||||
}
|
||||
|
||||
void TrackContentWidget::contextMenuAction( QContextMenuEvent * cme, ContextMenuAction action )
|
||||
{
|
||||
switch( action )
|
||||
{
|
||||
case Paste:
|
||||
// Paste the selection on the MidiTime of the context menu event
|
||||
const QMimeData *md = QApplication::clipboard()->mimeData( QClipboard::Clipboard );
|
||||
MidiTime tcoPos = getPosition( cme->x() );
|
||||
|
||||
pasteSelection( tcoPos, md );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -343,29 +343,57 @@ void SampleTCOView::updateSample()
|
||||
|
||||
void SampleTCOView::contextMenuEvent( QContextMenuEvent * _cme )
|
||||
{
|
||||
// Depending on whether we right-clicked a selection or an individual TCO we will have
|
||||
// different labels for the actions.
|
||||
bool individualTCO = getClickedTCOs().size() <= 1;
|
||||
|
||||
if( _cme->modifiers() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QMenu contextMenu( this );
|
||||
|
||||
if( fixedTCOs() == false )
|
||||
{
|
||||
contextMenu.addAction( embed::getIconPixmap( "cancel" ),
|
||||
tr( "Delete (middle mousebutton)" ),
|
||||
this, SLOT( remove() ) );
|
||||
contextMenu.addAction(
|
||||
embed::getIconPixmap( "cancel" ),
|
||||
tr( individualTCO
|
||||
? "Delete (middle mousebutton)"
|
||||
: "Delete selection (middle mousebutton)" ),
|
||||
[this](){ contextMenuAction( Remove ); } );
|
||||
|
||||
contextMenu.addSeparator();
|
||||
contextMenu.addAction( embed::getIconPixmap( "edit_cut" ),
|
||||
tr( "Cut" ), this, SLOT( cut() ) );
|
||||
|
||||
contextMenu.addAction(
|
||||
embed::getIconPixmap( "edit_cut" ),
|
||||
tr( individualTCO
|
||||
? "Cut"
|
||||
: "Cut selection" ),
|
||||
[this](){ contextMenuAction( Cut ); } );
|
||||
}
|
||||
contextMenu.addAction( embed::getIconPixmap( "edit_copy" ),
|
||||
tr( "Copy" ), m_tco, SLOT( copy() ) );
|
||||
contextMenu.addAction( embed::getIconPixmap( "edit_paste" ),
|
||||
tr( "Paste" ), m_tco, SLOT( paste() ) );
|
||||
|
||||
contextMenu.addAction(
|
||||
embed::getIconPixmap( "edit_copy" ),
|
||||
tr( individualTCO
|
||||
? "Copy"
|
||||
: "Copy selection" ),
|
||||
[this](){ contextMenuAction( Copy ); } );
|
||||
|
||||
contextMenu.addAction(
|
||||
embed::getIconPixmap( "edit_paste" ),
|
||||
tr( "Paste" ),
|
||||
[this](){ contextMenuAction( Paste ); } );
|
||||
|
||||
contextMenu.addSeparator();
|
||||
contextMenu.addAction( embed::getIconPixmap( "muted" ),
|
||||
tr( "Mute/unmute (<%1> + middle click)" ).arg(UI_CTRL_KEY),
|
||||
m_tco, SLOT( toggleMute() ) );
|
||||
|
||||
contextMenu.addAction(
|
||||
embed::getIconPixmap( "muted" ),
|
||||
tr( individualTCO
|
||||
? "Mute/unmute (<%1> + middle click)"
|
||||
: "Mute/unmute selection (<%1> + middle click)" ).arg(UI_CTRL_KEY),
|
||||
[this](){ contextMenuAction( Mute ); } );
|
||||
|
||||
/*contextMenu.addAction( embed::getIconPixmap( "record" ),
|
||||
tr( "Set/clear record" ),
|
||||
m_tco, SLOT( toggleRecord() ) );*/
|
||||
|
||||
Reference in New Issue
Block a user