Skip to content

Commit

Permalink
Copy/paste model values to system clipboard
Browse files Browse the repository at this point in the history
Previously they were copy/pasted internally, and not visible across LMMS
instances.
  • Loading branch information
Wallacoloo committed Mar 20, 2018
1 parent 7593b2e commit 56b4740
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 34 deletions.
9 changes: 0 additions & 9 deletions include/AutomatableModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,6 @@ class EXPORT AutomatableModel : public Model, public JournallingObject
virtual ~AutomatableModel();


static float copiedValue()
{
return s_copiedValue;
}

bool isAutomated() const;
bool isAutomatedOrControlled() const
{
Expand Down Expand Up @@ -288,8 +283,6 @@ class EXPORT AutomatableModel : public Model, public JournallingObject

public slots:
virtual void reset();
virtual void copyValue();
virtual void pasteValue();
void unlinkControllerConnection();


Expand Down Expand Up @@ -352,8 +345,6 @@ public slots:
ControllerConnection* m_controllerConnection;


static float s_copiedValue;

ValueBuffer m_valueBuffer;
long m_lastUpdatedPeriod;
static long s_periodCounter;
Expand Down
6 changes: 5 additions & 1 deletion include/AutomatableModelView.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ class EXPORT AutomatableModelView : public ModelView

QString m_description;
QString m_unit;

} ;


Expand All @@ -94,6 +93,11 @@ public slots:
void unlinkAllModels();
void removeSongGlobalAutomation();

private slots:
/// Copy the model's value to the clipboard.
void copyToClipboard();
/// Paste the model's value from the clipboard.
void pasteFromClipboard();

protected:
AutomatableModelView* m_amv;
Expand Down
16 changes: 0 additions & 16 deletions src/core/AutomatableModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include "Mixer.h"
#include "ProjectJournal.h"

float AutomatableModel::s_copiedValue = 0;
long AutomatableModel::s_periodCounter = 0;


Expand Down Expand Up @@ -635,21 +634,6 @@ void AutomatableModel::reset()



void AutomatableModel::copyValue()
{
s_copiedValue = value<float>();
}




void AutomatableModel::pasteValue()
{
setValue( copiedValue() );
}



float AutomatableModel::globalAutomationValueAt( const MidiTime& time )
{
// get patterns that connect to this model
Expand Down
44 changes: 36 additions & 8 deletions src/gui/AutomatableModelView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*
*/

#include <QApplication>
#include <QClipboard>
#include <QMenu>
#include <QMouseEvent>

Expand All @@ -37,6 +39,7 @@
#include "AutomationEditor.h"


static float floatFromClipboard(bool* ok=nullptr);

AutomatableModelView::AutomatableModelView( ::Model* model, QWidget* _this ) :
ModelView( model, _this ),
Expand Down Expand Up @@ -74,13 +77,18 @@ void AutomatableModelView::addDefaultActions( QMenu* menu )
AutomatableModel::tr( "&Copy value (%1%2)" ).
arg( model->displayValue( model->value<float>() ) ).
arg( m_unit ),
model, SLOT( copyValue() ) );

menu->addAction( embed::getIconPixmap( "edit_paste" ),
AutomatableModel::tr( "&Paste value (%1%2)").
arg( model->displayValue( AutomatableModel::copiedValue() ) ).
arg( m_unit ),
model, SLOT( pasteValue() ) );
amvSlots, SLOT( copyToClipboard() ) );

bool canPaste = true;
const float valueToPaste = floatFromClipboard(&canPaste);
const QString pasteDesc = canPaste ?
AutomatableModel::tr( "&Paste value (%1%2)").
arg( model->displayValue( valueToPaste ) ).
arg( m_unit )
: AutomatableModel::tr( "&Paste value");
QAction* pasteAction = menu->addAction( embed::getIconPixmap( "edit_paste" ),
pasteDesc, amvSlots, SLOT( pasteFromClipboard() ) );
pasteAction->setEnabled(canPaste);

menu->addSeparator();

Expand Down Expand Up @@ -162,7 +170,6 @@ void AutomatableModelView::mousePressEvent( QMouseEvent* event )




AutomatableModelViewSlots::AutomatableModelViewSlots( AutomatableModelView* amv, QObject* parent ) :
QObject(),
m_amv( amv )
Expand Down Expand Up @@ -245,5 +252,26 @@ void AutomatableModelViewSlots::unlinkAllModels()
m_amv->modelUntyped()->unlinkAllModels();
}

void AutomatableModelViewSlots::copyToClipboard()
{
QClipboard* clipboard = QApplication::clipboard();
clipboard->setText(QString::number(m_amv->value<float>()));
}

void AutomatableModelViewSlots::pasteFromClipboard()
{
bool isNumber = false;
const float number = floatFromClipboard(&isNumber);
if (isNumber) {
m_amv->modelUntyped()->setValue(number);
}
}


/// Attempt to parse a float from the clipboard
static float floatFromClipboard(bool* ok)
{
const QClipboard* clipboard = QApplication::clipboard();
return clipboard->text().toFloat(ok);
}

0 comments on commit 56b4740

Please sign in to comment.