mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
Implemented "Always on Top" functionality.
This feature has been frequently requested by various users.
This commit is contained in:
parent
402b481d74
commit
cb8724ce1c
|
@ -94,6 +94,7 @@ Preferences::Preferences():
|
||||||
doubleClickTranslates( true ),
|
doubleClickTranslates( true ),
|
||||||
selectWordBySingleClick( false ),
|
selectWordBySingleClick( false ),
|
||||||
escKeyHidesMainWindow( false ),
|
escKeyHidesMainWindow( false ),
|
||||||
|
alwaysOnTop ( false ),
|
||||||
|
|
||||||
enableMainWindowHotkey( true ),
|
enableMainWindowHotkey( true ),
|
||||||
mainWindowHotkey( QKeySequence( "Ctrl+F11,F11" ) ),
|
mainWindowHotkey( QKeySequence( "Ctrl+F11,F11" ) ),
|
||||||
|
@ -613,6 +614,7 @@ Class load() throw( exError )
|
||||||
c.preferences.startToTray = ( preferences.namedItem( "startToTray" ).toElement().text() == "1" );
|
c.preferences.startToTray = ( preferences.namedItem( "startToTray" ).toElement().text() == "1" );
|
||||||
c.preferences.closeToTray = ( preferences.namedItem( "closeToTray" ).toElement().text() == "1" );
|
c.preferences.closeToTray = ( preferences.namedItem( "closeToTray" ).toElement().text() == "1" );
|
||||||
c.preferences.autoStart = ( preferences.namedItem( "autoStart" ).toElement().text() == "1" );
|
c.preferences.autoStart = ( preferences.namedItem( "autoStart" ).toElement().text() == "1" );
|
||||||
|
c.preferences.alwaysOnTop = ( preferences.namedItem( "alwaysOnTop" ).toElement().text() == "1" );
|
||||||
|
|
||||||
if ( !preferences.namedItem( "doubleClickTranslates" ).isNull() )
|
if ( !preferences.namedItem( "doubleClickTranslates" ).isNull() )
|
||||||
c.preferences.doubleClickTranslates = ( preferences.namedItem( "doubleClickTranslates" ).toElement().text() == "1" );
|
c.preferences.doubleClickTranslates = ( preferences.namedItem( "doubleClickTranslates" ).toElement().text() == "1" );
|
||||||
|
@ -1268,6 +1270,10 @@ void save( Class const & c ) throw( exError )
|
||||||
opt.appendChild( dd.createTextNode( c.preferences.audioPlaybackProgram ) );
|
opt.appendChild( dd.createTextNode( c.preferences.audioPlaybackProgram ) );
|
||||||
preferences.appendChild( opt );
|
preferences.appendChild( opt );
|
||||||
|
|
||||||
|
opt = dd.createElement( "alwaysOnTop" );
|
||||||
|
opt.appendChild( dd.createTextNode( c.preferences.alwaysOnTop ? "1" : "0" ) );
|
||||||
|
preferences.appendChild( opt );
|
||||||
|
|
||||||
{
|
{
|
||||||
QDomElement proxy = dd.createElement( "proxyserver" );
|
QDomElement proxy = dd.createElement( "proxyserver" );
|
||||||
preferences.appendChild( proxy );
|
preferences.appendChild( proxy );
|
||||||
|
|
|
@ -158,6 +158,7 @@ struct Preferences
|
||||||
bool doubleClickTranslates;
|
bool doubleClickTranslates;
|
||||||
bool selectWordBySingleClick;
|
bool selectWordBySingleClick;
|
||||||
bool escKeyHidesMainWindow;
|
bool escKeyHidesMainWindow;
|
||||||
|
bool alwaysOnTop;
|
||||||
|
|
||||||
bool enableMainWindowHotkey;
|
bool enableMainWindowHotkey;
|
||||||
HotKey mainWindowHotkey;
|
HotKey mainWindowHotkey;
|
||||||
|
|
|
@ -386,6 +386,9 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
||||||
ui.menuView->addSeparator();
|
ui.menuView->addSeparator();
|
||||||
ui.menuView->addAction( &showDictBarNamesAction );
|
ui.menuView->addAction( &showDictBarNamesAction );
|
||||||
ui.menuView->addAction( &useSmallIconsInToolbarsAction );
|
ui.menuView->addAction( &useSmallIconsInToolbarsAction );
|
||||||
|
ui.menuView->addSeparator();
|
||||||
|
ui.alwaysOnTop->setChecked( cfg.preferences.alwaysOnTop );
|
||||||
|
ui.menuView->addAction( ui.alwaysOnTop );
|
||||||
|
|
||||||
// Dictionary bar
|
// Dictionary bar
|
||||||
|
|
||||||
|
@ -609,6 +612,11 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
||||||
// Initialize global hotkeys
|
// Initialize global hotkeys
|
||||||
installHotKeys();
|
installHotKeys();
|
||||||
|
|
||||||
|
if ( cfg.preferences.alwaysOnTop )
|
||||||
|
{
|
||||||
|
on_alwaysOnTop_triggered( true );
|
||||||
|
}
|
||||||
|
|
||||||
// Only show window initially if it wasn't configured differently
|
// Only show window initially if it wasn't configured differently
|
||||||
if ( !cfg.preferences.enableTrayIcon || !cfg.preferences.startToTray )
|
if ( !cfg.preferences.enableTrayIcon || !cfg.preferences.startToTray )
|
||||||
{
|
{
|
||||||
|
@ -2772,6 +2780,35 @@ void MainWindow::on_rescanFiles_triggered()
|
||||||
installHotKeys();
|
installHotKeys();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_alwaysOnTop_triggered( bool checked )
|
||||||
|
{
|
||||||
|
cfg.preferences.alwaysOnTop = checked;
|
||||||
|
|
||||||
|
bool wasVisible = isVisible();
|
||||||
|
|
||||||
|
Qt::WindowFlags flags = this->windowFlags();
|
||||||
|
if (checked)
|
||||||
|
{
|
||||||
|
setWindowFlags(flags | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint);
|
||||||
|
mainStatusBar->showMessage(
|
||||||
|
tr( "The main window is set to be always on top." ),
|
||||||
|
10000,
|
||||||
|
QPixmap( ":/icons/warning.png" ) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setWindowFlags(flags ^ (Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint));
|
||||||
|
mainStatusBar->clearMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( wasVisible )
|
||||||
|
{
|
||||||
|
show();
|
||||||
|
}
|
||||||
|
|
||||||
|
installHotKeys();
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::zoomin()
|
void MainWindow::zoomin()
|
||||||
{
|
{
|
||||||
cfg.preferences.zoomFactor += 0.1;
|
cfg.preferences.zoomFactor += 0.1;
|
||||||
|
|
|
@ -376,6 +376,7 @@ private slots:
|
||||||
void on_showHideHistory_triggered();
|
void on_showHideHistory_triggered();
|
||||||
void on_exportHistory_triggered();
|
void on_exportHistory_triggered();
|
||||||
void on_importHistory_triggered();
|
void on_importHistory_triggered();
|
||||||
|
void on_alwaysOnTop_triggered( bool checked );
|
||||||
void focusWordList();
|
void focusWordList();
|
||||||
|
|
||||||
void updateSearchPaneAndBar();
|
void updateSearchPaneAndBar();
|
||||||
|
|
|
@ -61,7 +61,7 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>653</width>
|
<width>653</width>
|
||||||
<height>18</height>
|
<height>21</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QMenu" name="menuFile">
|
<widget class="QMenu" name="menuFile">
|
||||||
|
@ -432,6 +432,20 @@
|
||||||
<string>&Import</string>
|
<string>&Import</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="alwaysOnTop">
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Always on Top</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Always on Top</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Ctrl+O</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
|
|
Loading…
Reference in a new issue