fix: replace hhotkeyedit with qkeysequenceedit

related to #291
This commit is contained in:
Xiao YiFang 2022-12-30 01:11:22 +08:00
parent 8ffa1f6643
commit 794d4b934f
7 changed files with 20 additions and 31 deletions

View file

@ -1782,7 +1782,7 @@ void save( Class const & c )
preferences.appendChild( opt ); preferences.appendChild( opt );
opt = dd.createElement( "mainWindowHotkey" ); opt = dd.createElement( "mainWindowHotkey" );
opt.appendChild( dd.createTextNode( c.preferences.mainWindowHotkey.toKeySequence().toString() ) ); opt.appendChild( dd.createTextNode( c.preferences.mainWindowHotkey.toString() ) );
preferences.appendChild( opt ); preferences.appendChild( opt );
opt = dd.createElement( "enableClipboardHotkey" ); opt = dd.createElement( "enableClipboardHotkey" );
@ -1790,7 +1790,7 @@ void save( Class const & c )
preferences.appendChild( opt ); preferences.appendChild( opt );
opt = dd.createElement( "clipboardHotkey" ); opt = dd.createElement( "clipboardHotkey" );
opt.appendChild( dd.createTextNode( c.preferences.clipboardHotkey.toKeySequence().toString() ) ); opt.appendChild( dd.createTextNode( c.preferences.clipboardHotkey.toString() ) );
preferences.appendChild( opt ); preferences.appendChild( opt );
opt = dd.createElement( "startWithScanPopupOn" ); opt = dd.createElement( "startWithScanPopupOn" );

View file

@ -320,9 +320,9 @@ struct Preferences
bool searchInDock; bool searchInDock;
bool enableMainWindowHotkey; bool enableMainWindowHotkey;
HotKey mainWindowHotkey; QKeySequence mainWindowHotkey;
bool enableClipboardHotkey; bool enableClipboardHotkey;
HotKey clipboardHotkey; QKeySequence clipboardHotkey;
bool startWithScanPopupOn; bool startWithScanPopupOn;
bool enableScanPopupModifiers; bool enableScanPopupModifiers;

View file

@ -329,6 +329,12 @@ bool HotkeyWrapper::setGlobalKey( int key, int key2,
return true; return true;
} }
bool HotkeyWrapper::setGlobalKey( QKeySequence & seq, int handle )
{
Config::HotKey hk(seq);
return setGlobalKey(hk.key1,hk.key2,hk.modifiers,handle);
}
#if( QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) ) #if( QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) )
bool HotkeyWrapper::winEvent ( MSG * message, long * result ) bool HotkeyWrapper::winEvent ( MSG * message, long * result )
#else #else

View file

@ -68,6 +68,8 @@ public:
bool setGlobalKey( int key, int key2, Qt::KeyboardModifiers modifier, bool setGlobalKey( int key, int key2, Qt::KeyboardModifiers modifier,
int handle ); int handle );
bool setGlobalKey( QKeySequence & , int );
/// Unregisters everything /// Unregisters everything
void unregister(); void unregister();

View file

@ -2971,17 +2971,11 @@ void MainWindow::installHotKeys()
} }
if ( cfg.preferences.enableMainWindowHotkey ) if ( cfg.preferences.enableMainWindowHotkey )
hotkeyWrapper->setGlobalKey( cfg.preferences.mainWindowHotkey.key1, hotkeyWrapper->setGlobalKey( cfg.preferences.mainWindowHotkey,0 );
cfg.preferences.mainWindowHotkey.key2,
cfg.preferences.mainWindowHotkey.modifiers,
0 );
if ( cfg.preferences.enableClipboardHotkey && scanPopup.get() ) if ( cfg.preferences.enableClipboardHotkey && scanPopup.get() )
{ {
hotkeyWrapper->setGlobalKey( cfg.preferences.clipboardHotkey.key1, hotkeyWrapper->setGlobalKey( cfg.preferences.clipboardHotkey,1 );
cfg.preferences.clipboardHotkey.key2,
cfg.preferences.clipboardHotkey.modifiers,
1 );
} }
connect( hotkeyWrapper.get(), connect( hotkeyWrapper.get(),

View file

@ -178,9 +178,9 @@ Preferences::Preferences( QWidget * parent, Config::Class & cfg_ ):
#endif #endif
ui.enableMainWindowHotkey->setChecked( p.enableMainWindowHotkey ); ui.enableMainWindowHotkey->setChecked( p.enableMainWindowHotkey );
ui.mainWindowHotkey->setHotKey( p.mainWindowHotkey ); ui.mainWindowHotkey->setKeySequence( p.mainWindowHotkey );
ui.enableClipboardHotkey->setChecked( p.enableClipboardHotkey ); ui.enableClipboardHotkey->setChecked( p.enableClipboardHotkey );
ui.clipboardHotkey->setHotKey( p.clipboardHotkey ); ui.clipboardHotkey->setKeySequence( p.clipboardHotkey );
ui.startWithScanPopupOn->setChecked( p.startWithScanPopupOn ); ui.startWithScanPopupOn->setChecked( p.startWithScanPopupOn );
ui.enableScanPopupModifiers->setChecked( p.enableScanPopupModifiers ); ui.enableScanPopupModifiers->setChecked( p.enableScanPopupModifiers );
@ -398,9 +398,9 @@ Config::Preferences Preferences::getPreferences()
p.darkMode = ui.darkMode->isChecked(); p.darkMode = ui.darkMode->isChecked();
p.darkReaderMode = ui.darkReaderMode->isChecked(); p.darkReaderMode = ui.darkReaderMode->isChecked();
p.enableMainWindowHotkey = ui.enableMainWindowHotkey->isChecked(); p.enableMainWindowHotkey = ui.enableMainWindowHotkey->isChecked();
p.mainWindowHotkey = ui.mainWindowHotkey->getHotKey(); p.mainWindowHotkey = ui.mainWindowHotkey->keySequence();
p.enableClipboardHotkey = ui.enableClipboardHotkey->isChecked(); p.enableClipboardHotkey = ui.enableClipboardHotkey->isChecked();
p.clipboardHotkey = ui.clipboardHotkey->getHotKey(); p.clipboardHotkey = ui.clipboardHotkey->keySequence();
p.startWithScanPopupOn = ui.startWithScanPopupOn->isChecked(); p.startWithScanPopupOn = ui.startWithScanPopupOn->isChecked();
p.enableScanPopupModifiers = ui.enableScanPopupModifiers->isChecked(); p.enableScanPopupModifiers = ui.enableScanPopupModifiers->isChecked();

View file

@ -709,11 +709,7 @@ in the pressed state when the word selection changes.</string>
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="HotKeyEdit" name="mainWindowHotkey"> <widget class="QKeySequenceEdit" name="mainWindowHotkey"/>
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item> </item>
</layout> </layout>
</item> </item>
@ -740,11 +736,7 @@ in the pressed state when the word selection changes.</string>
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="HotKeyEdit" name="clipboardHotkey"> <widget class="QKeySequenceEdit" name="clipboardHotkey"/>
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item> </item>
</layout> </layout>
</item> </item>
@ -1760,11 +1752,6 @@ from Stardict, Babylon and GLS dictionaries</string>
</layout> </layout>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget>
<class>HotKeyEdit</class>
<extends>QLineEdit</extends>
<header>hotkeyedit.hh</header>
</customwidget>
<customwidget> <customwidget>
<class>StylesComboBox</class> <class>StylesComboBox</class>
<extends>QComboBox</extends> <extends>QComboBox</extends>