Copy/paste model values to system clipboard
Previously they were copy/pasted internally, and not visible across LMMS instances.
This commit is contained in:
committed by
Colin Wallace
parent
7593b2ee58
commit
56b4740146
@@ -96,11 +96,6 @@ public:
|
||||
virtual ~AutomatableModel();
|
||||
|
||||
|
||||
static float copiedValue()
|
||||
{
|
||||
return s_copiedValue;
|
||||
}
|
||||
|
||||
bool isAutomated() const;
|
||||
bool isAutomatedOrControlled() const
|
||||
{
|
||||
@@ -288,8 +283,6 @@ public:
|
||||
|
||||
public slots:
|
||||
virtual void reset();
|
||||
virtual void copyValue();
|
||||
virtual void pasteValue();
|
||||
void unlinkControllerConnection();
|
||||
|
||||
|
||||
@@ -352,8 +345,6 @@ private:
|
||||
ControllerConnection* m_controllerConnection;
|
||||
|
||||
|
||||
static float s_copiedValue;
|
||||
|
||||
ValueBuffer m_valueBuffer;
|
||||
long m_lastUpdatedPeriod;
|
||||
static long s_periodCounter;
|
||||
|
||||
@@ -75,7 +75,6 @@ protected:
|
||||
|
||||
QString m_description;
|
||||
QString m_unit;
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
#include "Mixer.h"
|
||||
#include "ProjectJournal.h"
|
||||
|
||||
float AutomatableModel::s_copiedValue = 0;
|
||||
long AutomatableModel::s_periodCounter = 0;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
#include <QMenu>
|
||||
#include <QMouseEvent>
|
||||
|
||||
@@ -37,6 +39,7 @@
|
||||
#include "AutomationEditor.h"
|
||||
|
||||
|
||||
static float floatFromClipboard(bool* ok=nullptr);
|
||||
|
||||
AutomatableModelView::AutomatableModelView( ::Model* model, QWidget* _this ) :
|
||||
ModelView( model, _this ),
|
||||
@@ -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() ) );
|
||||
amvSlots, SLOT( copyToClipboard() ) );
|
||||
|
||||
menu->addAction( embed::getIconPixmap( "edit_paste" ),
|
||||
AutomatableModel::tr( "&Paste value (%1%2)").
|
||||
arg( model->displayValue( AutomatableModel::copiedValue() ) ).
|
||||
arg( m_unit ),
|
||||
model, SLOT( pasteValue() ) );
|
||||
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();
|
||||
|
||||
@@ -162,7 +170,6 @@ void AutomatableModelView::mousePressEvent( QMouseEvent* event )
|
||||
|
||||
|
||||
|
||||
|
||||
AutomatableModelViewSlots::AutomatableModelViewSlots( AutomatableModelView* amv, QObject* parent ) :
|
||||
QObject(),
|
||||
m_amv( amv )
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user