Add option for word selection by single mouse click

This commit is contained in:
Abs62 2012-09-26 17:59:48 +04:00
parent 3c2990bf23
commit ad8ddc8daf
10 changed files with 58 additions and 14 deletions

View file

@ -908,6 +908,11 @@ bool ArticleView::canGoForward()
return ui.definition->history()->canGoForward();
}
void ArticleView::setSelectionBySingleClick( bool set )
{
ui.definition->setSelectionBySingleClick( set );
}
void ArticleView::back()
{
// Don't allow navigating back to page 0, which is usually the initial

View file

@ -104,6 +104,9 @@ public:
bool canGoBack();
bool canGoForward();
/// Called when preference changes
void setSelectionBySingleClick( bool set );
public slots:
/// Goes back in history

View file

@ -4,6 +4,7 @@
#include "articlewebview.hh"
#include <QMouseEvent>
#include <QWebFrame>
#include <QApplication>
void ArticleWebView::mousePressEvent( QMouseEvent * event )
{
@ -11,6 +12,12 @@ void ArticleWebView::mousePressEvent( QMouseEvent * event )
midButtonPressed = true;
QWebView::mousePressEvent( event );
if ( selectionBySingleClick && ( event->buttons() & Qt::LeftButton ) )
{
QMouseEvent ev( QEvent::MouseButtonDblClick, event->pos(), Qt::LeftButton, Qt::LeftButton, event->modifiers() );
QApplication::sendEvent( page(), &ev );
}
}
void ArticleWebView::mouseReleaseEvent( QMouseEvent * event )

View file

@ -19,11 +19,14 @@ class ArticleWebView: public QWebView
public:
ArticleWebView( QWidget * parent ): QWebView( parent ),
midButtonPressed( false )
midButtonPressed( false ),
selectionBySingleClick( false )
{}
bool isMidButtonPressed() const
{ return midButtonPressed; }
void setSelectionBySingleClick( bool set )
{ selectionBySingleClick = set; }
signals:
@ -43,6 +46,7 @@ protected:
private:
bool midButtonPressed;
bool selectionBySingleClick;
};
#endif

View file

@ -92,6 +92,7 @@ Preferences::Preferences():
closeToTray( true ),
autoStart( false ),
doubleClickTranslates( true ),
selectWordBySingleClick( false ),
escKeyHidesMainWindow( false ),
enableMainWindowHotkey( true ),
@ -610,6 +611,9 @@ Class load() throw( exError )
if ( !preferences.namedItem( "doubleClickTranslates" ).isNull() )
c.preferences.doubleClickTranslates = ( preferences.namedItem( "doubleClickTranslates" ).toElement().text() == "1" );
if ( !preferences.namedItem( "selectWordBySingleClick" ).isNull() )
c.preferences.selectWordBySingleClick = ( preferences.namedItem( "selectWordBySingleClick" ).toElement().text() == "1" );
if ( !preferences.namedItem( "escKeyHidesMainWindow" ).isNull() )
c.preferences.escKeyHidesMainWindow = ( preferences.namedItem( "escKeyHidesMainWindow" ).toElement().text() == "1" );
@ -1133,6 +1137,10 @@ void save( Class const & c ) throw( exError )
opt.appendChild( dd.createTextNode( c.preferences.doubleClickTranslates ? "1":"0" ) );
preferences.appendChild( opt );
opt = dd.createElement( "selectWordBySingleClick" );
opt.appendChild( dd.createTextNode( c.preferences.selectWordBySingleClick ? "1":"0" ) );
preferences.appendChild( opt );
opt = dd.createElement( "escKeyHidesMainWindow" );
opt.appendChild( dd.createTextNode( c.preferences.escKeyHidesMainWindow ? "1":"0" ) );
preferences.appendChild( opt );

View file

@ -88,6 +88,8 @@ struct Group
bool operator == ( Group const & other ) const
{ return id == other.id && name == other.name && icon == other.icon &&
dictionaries == other.dictionaries && shortcut == other.shortcut &&
mutedDictionaries == other.mutedDictionaries &&
popupMutedDictionaries == other.popupMutedDictionaries &&
iconData == iconData; }
bool operator != ( Group const & other ) const
@ -152,6 +154,7 @@ struct Preferences
bool closeToTray;
bool autoStart;
bool doubleClickTranslates;
bool selectWordBySingleClick;
bool escKeyHidesMainWindow;
bool enableMainWindowHotkey;

View file

@ -843,10 +843,10 @@ void MainWindow::updateDictionaryBar()
return; // It's not enabled, therefore hidden -- don't waste time
unsigned currentId = groupList.getCurrentGroup();
Instances::Group * igrp = groupInstances.findGroup( currentId );
Instances::Group * grp = groupInstances.findGroup( currentId );
if ( igrp ) { // Should always be !0, but check as a safeguard
dictionaryBar.setDictionaries( igrp->dictionaries );
if ( grp ) { // Should always be !0, but check as a safeguard
dictionaryBar.setDictionaries( grp->dictionaries );
if( currentId == Instances::Group::AllGroupId )
dictionaryBar.setMutedDictionaries( &cfg.mutedDictionaries );
@ -1424,15 +1424,15 @@ void MainWindow::editPreferences()
needReload = false;
}
if( needReload )
for( int x = 0; x < ui.tabWidget->count(); ++x )
{
for( int x = 0; x < ui.tabWidget->count(); ++x )
{
ArticleView & view =
dynamic_cast< ArticleView & >( *( ui.tabWidget->widget( x ) ) );
ArticleView & view =
dynamic_cast< ArticleView & >( *( ui.tabWidget->widget( x ) ) );
view.setSelectionBySingleClick( p.selectWordBySingleClick );
if( needReload )
view.reload();
}
}
cfg.preferences = p;

View file

@ -96,6 +96,7 @@ Preferences::Preferences( QWidget * parent, Config::Preferences const & p ):
ui.closeToTray->setChecked( p.closeToTray );
ui.cbAutostart->setChecked( p.autoStart );
ui.doubleClickTranslates->setChecked( p.doubleClickTranslates );
ui.selectBySingleClick->setChecked( p.selectWordBySingleClick);
ui.escKeyHidesMainWindow->setChecked( p.escKeyHidesMainWindow );
ui.enableMainWindowHotkey->setChecked( p.enableMainWindowHotkey );
@ -215,6 +216,7 @@ Config::Preferences Preferences::getPreferences()
p.closeToTray = ui.closeToTray->isChecked();
p.autoStart = ui.cbAutostart->isChecked();
p.doubleClickTranslates = ui.doubleClickTranslates->isChecked();
p.selectWordBySingleClick = ui.selectBySingleClick->isChecked();
p.escKeyHidesMainWindow = ui.escKeyHidesMainWindow->isChecked();
p.enableMainWindowHotkey = ui.enableMainWindowHotkey->isChecked();

View file

@ -170,7 +170,7 @@ the application.</string>
</layout>
</widget>
</item>
<item row="6" column="0" colspan="2">
<item row="7" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLabel" name="label_6">
@ -223,7 +223,7 @@ the application.</string>
</item>
</layout>
</item>
<item row="7" column="0" colspan="2">
<item row="8" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -236,7 +236,7 @@ the application.</string>
</property>
</spacer>
</item>
<item row="5" column="0">
<item row="6" column="0">
<spacer name="verticalSpacer_9">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -259,7 +259,7 @@ the application.</string>
</property>
</widget>
</item>
<item row="4" column="0">
<item row="5" column="0">
<widget class="QCheckBox" name="escKeyHidesMainWindow">
<property name="toolTip">
<string>Normally, pressing ESC key moves focus to the translation line.
@ -270,6 +270,16 @@ With this on however, it will hide the main window.</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="selectBySingleClick">
<property name="toolTip">
<string>Turn this option on if you want to select words by single mouse click</string>
</property>
<property name="text">
<string>Select word by single click</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_4">

View file

@ -356,6 +356,8 @@ void ScanPopup::engagePopup( bool forcePopup, bool giveFocus )
return;
}
definition->setSelectionBySingleClick( cfg.preferences.selectWordBySingleClick );
/// Too large strings make window expand which is probably not what user
/// wants
ui.word->setText( elideInputWord() );