Add "Copy as text" feature (issue #311)

This commit is contained in:
Abs62 2013-05-15 17:52:47 +04:00
parent 680c201b88
commit 1f5270c619
2 changed files with 20 additions and 1 deletions

View file

@ -57,6 +57,7 @@ ArticleView::ArticleView( QWidget * parent, ArticleNetworkAccessManager & nm,
goForwardAction( this ), goForwardAction( this ),
openSearchAction( this ), openSearchAction( this ),
selectCurrentArticleAction( this ), selectCurrentArticleAction( this ),
copyAsTextAction( this ),
searchIsOpened( false ), searchIsOpened( false ),
dictionaryBarToggled( dictionaryBarToggled_ ), dictionaryBarToggled( dictionaryBarToggled_ ),
groupComboBox( groupComboBox_ ) groupComboBox( groupComboBox_ )
@ -133,6 +134,12 @@ ArticleView::ArticleView( QWidget * parent, ArticleNetworkAccessManager & nm,
connect( &selectCurrentArticleAction, SIGNAL( triggered() ), connect( &selectCurrentArticleAction, SIGNAL( triggered() ),
this, SLOT( selectCurrentArticle() ) ); this, SLOT( selectCurrentArticle() ) );
copyAsTextAction.setShortcut( QKeySequence( "Ctrl+Shift+C" ) );
copyAsTextAction.setText( tr( "Copy as text" ) );
ui.definition->addAction( &copyAsTextAction );
connect( &copyAsTextAction, SIGNAL( triggered() ),
this, SLOT( copyAsText() ) );
ui.definition->installEventFilter( this ); ui.definition->installEventFilter( this );
ui.searchFrame->installEventFilter( this ); ui.searchFrame->installEventFilter( this );
@ -1395,6 +1402,7 @@ void ArticleView::contextMenuRequested( QPoint const & pos )
if ( selectedText.size() ) if ( selectedText.size() )
{ {
menu.addAction( ui.definition->pageAction( QWebPage::Copy ) ); menu.addAction( ui.definition->pageAction( QWebPage::Copy ) );
menu.addAction( &copyAsTextAction );
} }
else else
{ {
@ -1887,6 +1895,13 @@ void ArticleView::switchExpandOptionalParts()
reload(); reload();
} }
void ArticleView::copyAsText()
{
QString text = ui.definition->selectedText();
if( !text.isEmpty() )
QApplication::clipboard()->setText( text );
}
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
void ArticleView::readTag( const QString & from, QString & to, int & count ) void ArticleView::readTag( const QString & from, QString & to, int & count )

View file

@ -28,7 +28,8 @@ class ArticleView: public QFrame
Ui::ArticleView ui; Ui::ArticleView ui;
QAction pasteAction, articleUpAction, articleDownAction, QAction pasteAction, articleUpAction, articleDownAction,
goBackAction, goForwardAction, openSearchAction, selectCurrentArticleAction; goBackAction, goForwardAction, openSearchAction, selectCurrentArticleAction,
copyAsTextAction;
bool searchIsOpened; bool searchIsOpened;
bool expandOptionalParts; bool expandOptionalParts;
QString articleToJump; QString articleToJump;
@ -263,6 +264,9 @@ private slots:
/// Handles audio player error message /// Handles audio player error message
void audioPlayerError( QString const & message ); void audioPlayerError( QString const & message );
/// Copy current selection as plain text
void copyAsText();
private: private:
/// Deduces group from the url. If there doesn't seem to be any group, /// Deduces group from the url. If there doesn't seem to be any group,