From c46ad66a659a93e111ce16d4f3c96698c9ea96fc Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Sat, 7 May 2011 13:04:32 +0000 Subject: [PATCH] task bar button for server is not shown if it is minizied (minimized to tast bar icon) --- src/llconserverdlg.cpp | 53 +++++++++++++++++++++++++++++++-------- src/llconserverdlg.h | 9 ++++--- src/llconserverdlgbase.ui | 29 +-------------------- 3 files changed, 49 insertions(+), 42 deletions(-) diff --git a/src/llconserverdlg.cpp b/src/llconserverdlg.cpp index 608eb8bd..93b973a0 100755 --- a/src/llconserverdlg.cpp +++ b/src/llconserverdlg.cpp @@ -140,6 +140,12 @@ CLlconServerDlg::CLlconServerDlg ( CServer* pNServP, ListViewClients->setColumnWidth ( 2, 60 ); ListViewClients->clear(); + +// TEST workaround for resize problem of window after iconize in task bar +ListViewClients->setMinimumWidth ( 170 + 130 + 60 + 205 ); +ListViewClients->setMinimumHeight ( 140 ); + + // insert items in reverse order because in Windows all of them are // always visible -> put first item on the top vecpListViewItems.Init ( USED_NUM_CHANNELS ); @@ -204,8 +210,17 @@ CLlconServerDlg::CLlconServerDlg ( CServer* pNServP, UpdateGUIDependencies(); + // View menu -------------------------------------------------------------- + QMenu* pViewMenu = new QMenu ( "&Window", this ); + + pViewMenu->addAction ( tr ( "E&xit" ), this, + SLOT ( close() ), QKeySequence ( Qt::CTRL + Qt::Key_Q ) ); + + // Main menu bar ----------------------------------------------------------- pMenu = new QMenuBar ( this ); + + pMenu->addMenu ( pViewMenu ); pMenu->addMenu ( new CLlconHelpMenu ( this ) ); // Now tell the layout about the menu @@ -245,6 +260,10 @@ CLlconServerDlg::CLlconServerDlg ( CServer* pNServP, QObject::connect ( pServer, SIGNAL ( Stopped() ), this, SLOT ( OnServerStopped() ) ); + QObject::connect ( &SystemTrayIcon, + SIGNAL ( activated ( QSystemTrayIcon::ActivationReason ) ), + this, SLOT ( OnSysTrayActivated ( QSystemTrayIcon::ActivationReason ) ) ); + // Timers ------------------------------------------------------------------ // start timer for GUI controls @@ -333,6 +352,15 @@ void CLlconServerDlg::OnComboBoxLocationCountryActivated ( int iCntryListItem ) pServer->UpdateServerList(); } +void CLlconServerDlg::OnSysTrayActivated ( QSystemTrayIcon::ActivationReason ActReason ) +{ + // on double click on the icon, show window in fore ground + if ( ActReason == QSystemTrayIcon::DoubleClick ) + { + ShowWindowInForeground(); + } +} + void CLlconServerDlg::OnTimer() { CVector vecHostAddresses; @@ -431,28 +459,31 @@ void CLlconServerDlg::UpdateSystemTrayIcon ( const bool bIsActive ) } } -void CLlconServerDlg::hideEvent ( QHideEvent* ) +void CLlconServerDlg::changeEvent ( QEvent* pEvent ) { -// TODO seems not to work correctly... -/* // if we have a system tray icon, we make the window invisible if it is // minimized - if ( bSystemTrayIconAvaialbe ) + if ( bSystemTrayIconAvaialbe && + ( pEvent->type() == QEvent::WindowStateChange ) ) { - setVisible ( false ); + if ( isMinimized() ) + { + // we have to call the hide function from another thread -> use + // the timer for this purpose + QTimer::singleShot ( 0, this, SLOT ( hide() ) ); + } } -*/ } -void CLlconServerDlg::customEvent ( QEvent* Event ) +void CLlconServerDlg::customEvent ( QEvent* pEvent ) { - if ( Event->type() == QEvent::User + 11 ) + if ( pEvent->type() == QEvent::User + 11 ) { ListViewMutex.lock(); { - const int iMessType = ( (CLlconEvent*) Event )->iMessType; - const int iStatus = ( (CLlconEvent*) Event )->iStatus; - const int iChanNum = ( (CLlconEvent*) Event )->iChanNum; + const int iMessType = ( (CLlconEvent*) pEvent )->iMessType; + const int iStatus = ( (CLlconEvent*) pEvent )->iStatus; + const int iChanNum = ( (CLlconEvent*) pEvent )->iChanNum; switch(iMessType) { diff --git a/src/llconserverdlg.h b/src/llconserverdlg.h index 9f02a912..c9b6a1d5 100755 --- a/src/llconserverdlg.h +++ b/src/llconserverdlg.h @@ -61,10 +61,12 @@ public: Qt::WindowFlags f = 0 ); protected: - virtual void customEvent ( QEvent* Event ); - virtual void hideEvent ( QHideEvent* ); + virtual void customEvent ( QEvent* pEvent ); + virtual void changeEvent ( QEvent* pEvent ); + void UpdateGUIDependencies(); void UpdateSystemTrayIcon ( const bool bIsActive ); + void ShowWindowInForeground() { showNormal(); raise(); } QTimer Timer; CServer* pServer; @@ -90,6 +92,7 @@ public slots: void OnTimer(); void OnServerStarted() { UpdateSystemTrayIcon ( true ); } void OnServerStopped() { UpdateSystemTrayIcon ( false ); } - void OnSysTrayMenuOpen() { showNormal(); raise(); } + void OnSysTrayMenuOpen() { ShowWindowInForeground(); } void OnSysTrayMenuExit() { close(); } + void OnSysTrayActivated ( QSystemTrayIcon::ActivationReason ActReason ); }; diff --git a/src/llconserverdlgbase.ui b/src/llconserverdlgbase.ui index dbff253d..d2f06167 100755 --- a/src/llconserverdlgbase.ui +++ b/src/llconserverdlgbase.ui @@ -169,16 +169,6 @@ - - - - E&xit - - - true - - - @@ -186,22 +176,5 @@ - - - buttonOk - clicked() - CLlconServerDlgBase - accept() - - - 20 - 20 - - - 20 - 20 - - - - +