Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 4ec38cf9 authored by Yuri Chornoivan's avatar Yuri Chornoivan

Copy root value or (x,y) pair to clipboard

BUG: 308168
Differential Revision: https://phabricator.kde.org/D17403
parent b872d232
......@@ -406,9 +406,31 @@ url="http://edu.kde.org/">http://edu.kde.org/</ulink></para></abstract>
</varlistentry>
</variablelist>
<para>Depending on the plot type, there will also be up to three tools available:</para>
<para>Depending on the plot type, there will also be up to five tools available:</para>
<variablelist>
<varlistentry>
<term><menuchoice><guimenuitem>Copy (x, y)</guimenuitem>
</menuchoice></term>
<listitem>
<para>Copies the current value on the plot to the system clipboard.
This tool can be useful for creating tables of function values outside of &kmplot;.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><menuchoice><guimenuitem>Copy Root Value</guimenuitem>
</menuchoice></term>
<listitem>
<para>Copies the root <literal>x</literal> value to the system clipboard.
Only up to the first five digits after the decimal point can be copied.
Use some <ulink url="https://en.wikipedia.org/wiki/Computer_algebra_system">computer algebra system</ulink> to determine this root with arbitrary precision.
This tool is only available when the current tracking position is close to a root.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><menuchoice><guimenuitem>Plot Area...</guimenuitem>
</menuchoice></term>
......
......@@ -26,6 +26,7 @@
#include "maindlg.h"
// Qt includes
#include <QClipboard>
#include <QDebug>
#include <QFileDialog>
#include <QIcon>
......@@ -131,7 +132,8 @@ MainDlg::MainDlg(QWidget *parentWidget, QObject *parent, const QVariantList& ) :
KParts::ReadWritePart( parent ),
m_recentFiles( 0 ),
m_modified(false),
m_parent(parentWidget)
m_parent(parentWidget),
m_rootValue( 0 )
{
assert( !m_self ); // this class should only be constructed once
m_self = this;
......@@ -389,6 +391,28 @@ void MainDlg::setupActions()
m_popupmenu->addAction( mnuMinValue );
m_popupmenu->addAction( mnuMaxValue );
m_popupmenu->addAction( mnuArea );
QAction * copyXY = actionCollection()->addAction( "copyXY" );
copyXY->setText(i18n("Copy (x, y)"));
connect( copyXY, &QAction::triggered, []{
QClipboard * cb = QApplication::clipboard();
QPointF currentXY = View::self()->getCrosshairPosition();
cb->setText( i18nc("Copied pair of coordinates (x, y)", "(%1, %2)", QLocale().toString( currentXY.x(), 'f', 5 ), QLocale().toString( currentXY.y(), 'f', 5 )), QClipboard::Clipboard );
} );
m_popupmenu->addAction( copyXY );
QAction * copyRootValue = actionCollection()->addAction( "copyRootValue" );
copyRootValue->setText(i18n("Copy Root Value"));
connect( View::self(), &View::updateRootValue, [this, copyRootValue]( bool haveRoot, double rootValue ){
copyRootValue->setVisible(haveRoot);
m_rootValue = rootValue;
} );
connect( copyRootValue, &QAction::triggered, [this]{
QClipboard * cb = QApplication::clipboard();
cb->setText( QLocale().toString( m_rootValue, 'f', 5 ), QClipboard::Clipboard );
} );
m_popupmenu->addAction( copyRootValue );
//END function popup menu
}
......
......@@ -215,6 +215,9 @@ private:
/// A pointer to ourselves
static MainDlg * m_self;
/// Root value for copying into clipboard
double m_rootValue;
protected slots:
/**
* When you click on a File->Open Recent file, it'll open
......
......@@ -96,6 +96,7 @@ View::View( bool readOnly, QMenu * functionPopup, QWidget* parent )
setAttribute( Qt::WA_StaticContents );
m_haveRoot = false;
emit updateRootValue( false, 0 );
m_xmin = m_xmax = m_ymin = m_ymax = 0.0;
m_printHeaderTable = false;
m_printBackground = false;
......@@ -3511,10 +3512,14 @@ bool View::updateCrosshairPosition()
str += i18n("root") + ": x" + SubscriptZeroSymbol + " = ";
setStatusBar( str+QString().sprintf("%+.5f", x0), RootSection );
m_haveRoot=true;
emit updateRootValue( true, x0 );
}
}
else
{
m_haveRoot=false;
emit updateRootValue( false, 0 );
}
}
// For Cartesian plots, only adjust the cursor position if it is not at the ends of the view
......@@ -4248,6 +4253,11 @@ void View::setPrintHeight( double height )
m_printHeight = height;
}
QPointF View::getCrosshairPosition() const
{
return m_crosshairPosition;
}
//END class View
......
......@@ -209,6 +209,11 @@ class View : public QWidget
SectionCount = 4
};
/**
* Crosshair position in real coordinates
*/
QPointF getCrosshairPosition() const;
public slots:
/// Called when the user want to cancel the drawing
void stopDrawing();
......@@ -235,6 +240,7 @@ class View : public QWidget
signals:
void setStatusBarText(const QString &);
void updateRootValue(bool haveRoot, double rootValue);
protected:
/// called when focus is lost
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment