diff --git a/doc/index.docbook b/doc/index.docbook --- a/doc/index.docbook +++ b/doc/index.docbook @@ -406,9 +406,31 @@ - Depending on the plot type, there will also be up to three tools available: + Depending on the plot type, there will also be up to five tools available: + + Copy (x, y) + + + 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;. + + + + + + Copy Root Value + + + Copies the root x value to the system clipboard. + Only up to the first five digits after the decimal point can be copied. + Use some computer algebra system to determine this root with arbitrary precision. + This tool is only available when the current tracking position is close to a root. + + + + Plot Area... diff --git a/kmplot/maindlg.h b/kmplot/maindlg.h --- a/kmplot/maindlg.h +++ b/kmplot/maindlg.h @@ -215,6 +215,9 @@ /// 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 diff --git a/kmplot/maindlg.cpp b/kmplot/maindlg.cpp --- a/kmplot/maindlg.cpp +++ b/kmplot/maindlg.cpp @@ -26,6 +26,7 @@ #include "maindlg.h" // Qt includes +#include #include #include #include @@ -131,7 +132,8 @@ 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 @@ 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 } diff --git a/kmplot/view.h b/kmplot/view.h --- a/kmplot/view.h +++ b/kmplot/view.h @@ -209,6 +209,11 @@ 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 @@ signals: void setStatusBarText(const QString &); + void updateRootValue(bool haveRoot, double rootValue); protected: /// called when focus is lost diff --git a/kmplot/view.cpp b/kmplot/view.cpp --- a/kmplot/view.cpp +++ b/kmplot/view.cpp @@ -96,6 +96,7 @@ 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 @@ 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 @@ m_printHeight = height; } +QPointF View::getCrosshairPosition() const +{ + return m_crosshairPosition; +} + //END class View