diff --git a/config.cc b/config.cc index 112e0ce1..2c9992ce 100644 --- a/config.cc +++ b/config.cc @@ -94,6 +94,7 @@ Preferences::Preferences(): doubleClickTranslates( true ), selectWordBySingleClick( false ), escKeyHidesMainWindow( false ), + alwaysOnTop ( false ), enableMainWindowHotkey( true ), mainWindowHotkey( QKeySequence( "Ctrl+F11,F11" ) ), @@ -613,6 +614,7 @@ Class load() throw( exError ) c.preferences.startToTray = ( preferences.namedItem( "startToTray" ).toElement().text() == "1" ); c.preferences.closeToTray = ( preferences.namedItem( "closeToTray" ).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() ) 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 ) ); preferences.appendChild( opt ); + opt = dd.createElement( "alwaysOnTop" ); + opt.appendChild( dd.createTextNode( c.preferences.alwaysOnTop ? "1" : "0" ) ); + preferences.appendChild( opt ); + { QDomElement proxy = dd.createElement( "proxyserver" ); preferences.appendChild( proxy ); diff --git a/config.hh b/config.hh index a9a47aa9..326421a8 100644 --- a/config.hh +++ b/config.hh @@ -158,6 +158,7 @@ struct Preferences bool doubleClickTranslates; bool selectWordBySingleClick; bool escKeyHidesMainWindow; + bool alwaysOnTop; bool enableMainWindowHotkey; HotKey mainWindowHotkey; diff --git a/mainwindow.cc b/mainwindow.cc index a063652a..5d753b65 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -386,6 +386,9 @@ MainWindow::MainWindow( Config::Class & cfg_ ): ui.menuView->addSeparator(); ui.menuView->addAction( &showDictBarNamesAction ); ui.menuView->addAction( &useSmallIconsInToolbarsAction ); + ui.menuView->addSeparator(); + ui.alwaysOnTop->setChecked( cfg.preferences.alwaysOnTop ); + ui.menuView->addAction( ui.alwaysOnTop ); // Dictionary bar @@ -609,6 +612,11 @@ MainWindow::MainWindow( Config::Class & cfg_ ): // Initialize global hotkeys installHotKeys(); + if ( cfg.preferences.alwaysOnTop ) + { + on_alwaysOnTop_triggered( true ); + } + // Only show window initially if it wasn't configured differently if ( !cfg.preferences.enableTrayIcon || !cfg.preferences.startToTray ) { @@ -2772,6 +2780,35 @@ void MainWindow::on_rescanFiles_triggered() 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() { cfg.preferences.zoomFactor += 0.1; diff --git a/mainwindow.hh b/mainwindow.hh index f17859c8..1e7491dd 100644 --- a/mainwindow.hh +++ b/mainwindow.hh @@ -376,6 +376,7 @@ private slots: void on_showHideHistory_triggered(); void on_exportHistory_triggered(); void on_importHistory_triggered(); + void on_alwaysOnTop_triggered( bool checked ); void focusWordList(); void updateSearchPaneAndBar(); diff --git a/mainwindow.ui b/mainwindow.ui index a594a269..e56d780c 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -61,7 +61,7 @@ 0 0 653 - 18 + 21 @@ -432,6 +432,20 @@ &Import + + + true + + + Always on Top + + + Always on Top + + + Ctrl+O + +