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

View file

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