From 355aca41be549a6597dce50351f0b4757ee2d00b Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Sat, 13 Jun 2009 08:14:11 +0000 Subject: [PATCH] added command line argument and function to disable all LEDs on main window to save CPU on slow computers --- src/llconclientdlg.cpp | 15 +++++--- src/llconclientdlg.h | 1 + src/main.cpp | 14 ++++++- src/multicolorled.cpp | 83 +++++++++++++++++++++++++++--------------- src/multicolorled.h | 12 +++++- 5 files changed, 88 insertions(+), 37 deletions(-) diff --git a/src/llconclientdlg.cpp b/src/llconclientdlg.cpp index 8bf9db24..8f5950f9 100755 --- a/src/llconclientdlg.cpp +++ b/src/llconclientdlg.cpp @@ -28,6 +28,7 @@ /* Implementation *************************************************************/ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, const bool bNewConnectOnStartup, + const bool bNewDisalbeLEDs, QWidget* parent, Qt::WindowFlags f ) : pClient ( pNCliP ), QDialog ( parent, f ), ClientSettingsDlg ( pNCliP, parent @@ -129,11 +130,6 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, MultiColorLEDBarInputLevelR->setValue ( 0 ); -// TEST -MultiColorLEDBarInputLevelL->setEnabled ( false ); - - - // init slider controls --- // audio in fader SliderAudInFader->setRange ( AUD_FADER_IN_MIN, AUD_FADER_IN_MAX ); @@ -169,6 +165,15 @@ MultiColorLEDBarInputLevelL->setEnabled ( false ); } + // disable controls on request --- + // disable LEDs in main window if requested + if ( bNewDisalbeLEDs ) + { + MultiColorLEDBarInputLevelL->setEnabled ( false ); + LEDOverallStatus->setEnabled ( false ); + } + + // Settings menu ---------------------------------------------------------- pSettingsMenu = new QMenu ( "&View", this ); pSettingsMenu->addAction ( tr ( "&Chat..." ), this, diff --git a/src/llconclientdlg.h b/src/llconclientdlg.h index faf2ee76..62e04ecb 100755 --- a/src/llconclientdlg.h +++ b/src/llconclientdlg.h @@ -67,6 +67,7 @@ class CLlconClientDlg : public QDialog, private Ui_CLlconClientDlgBase public: CLlconClientDlg ( CClient* pNCliP, const bool bNewConnectOnStartup, + const bool bNewDisalbeLEDs, QWidget* parent = 0, Qt::WindowFlags f = 0 ); virtual ~CLlconClientDlg(); diff --git a/src/main.cpp b/src/main.cpp index 90e63632..357d0e64 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -47,6 +47,7 @@ int main ( int argc, char** argv ) bool bIsClient = true; bool bUseGUI = true; bool bConnectOnStartup = false; + bool bDisalbeLEDs = false; int iUploadRateLimitKbps = DEF_MAX_UPLOAD_RATE_KBPS; quint16 iPortNumber = LLCON_DEFAULT_PORT_NUMBER; std::string strIniFileName = ""; @@ -78,6 +79,15 @@ int main ( int argc, char** argv ) } + // disable LEDs flag --------------------------------------------------- + if ( GetFlagArgument ( argc, argv, i, "-d", "--disableleds" ) ) + { + bDisalbeLEDs = true; + cout << "disable LEDs in main window" << std::endl; + continue; + } + + // use logging --------------------------------------------------------- if ( GetStringArgument ( argc, argv, i, "-l", "--log", strArgument ) ) { @@ -203,7 +213,7 @@ int main ( int argc, char** argv ) // GUI object CLlconClientDlg ClientDlg ( - &Client, bConnectOnStartup, + &Client, bConnectOnStartup, bDisalbeLEDs, 0 #ifdef _WIN32 // this somehow only works reliable on Windows @@ -303,6 +313,8 @@ std::string UsageArguments ( char **argv ) " -u, --maxuploadrate maximum upload rate (only avaiable for server)\n" " -c, --connect connect to last server on startup (only\n" " available for client)\n" + " -d, --disableleds disable LEDs in main window (only available\n" + " for client)\n" " -h, -?, --help this help text\n" "Example: " + std::string ( argv[0] ) + " -l -inifile myinifile.ini\n"; } diff --git a/src/multicolorled.cpp b/src/multicolorled.cpp index 056c6ae7..a7e0aec6 100755 --- a/src/multicolorled.cpp +++ b/src/multicolorled.cpp @@ -31,10 +31,11 @@ /* Implementation *************************************************************/ CMultiColorLED::CMultiColorLED ( QWidget* parent, Qt::WindowFlags f ) : QLabel ( parent, f ), - BitmCubeGrey ( QString::fromUtf8 ( ":/png/LEDs/res/CLEDGreySmall.png" ) ), - BitmCubeGreen ( QString::fromUtf8 ( ":/png/LEDs/res/CLEDGreenSmall.png" ) ), - BitmCubeYellow ( QString::fromUtf8 ( ":/png/LEDs/res/CLEDYellowSmall.png" ) ), - BitmCubeRed ( QString::fromUtf8 ( ":/png/LEDs/res/CLEDRedSmall.png" ) ) + BitmCubeDisabled ( QString::fromUtf8 ( ":/png/LEDs/res/CLEDDisabledSmall.png" ) ), + BitmCubeGrey ( QString::fromUtf8 ( ":/png/LEDs/res/CLEDGreySmall.png" ) ), + BitmCubeGreen ( QString::fromUtf8 ( ":/png/LEDs/res/CLEDGreenSmall.png" ) ), + BitmCubeYellow ( QString::fromUtf8 ( ":/png/LEDs/res/CLEDYellowSmall.png" ) ), + BitmCubeRed ( QString::fromUtf8 ( ":/png/LEDs/res/CLEDRedSmall.png" ) ) { // init color flags Reset(); @@ -63,14 +64,22 @@ CMultiColorLED::CMultiColorLED ( QWidget* parent, Qt::WindowFlags f ) this, SLOT ( OnNewPixmap ( const QPixmap& ) ) ); } -void CMultiColorLED::Reset() +void CMultiColorLED::changeEvent ( QEvent* curEvent ) { - // reset color flags - bFlagRedLi = false; - bFlagGreenLi = false; - bFlagYellowLi = false; - - UpdateColor(); + // act on enabled changed state + if ( curEvent->type() == QEvent::EnabledChange ) + { + if ( this->isEnabled() ) + { + emit newPixmap ( BitmCubeGrey ); + eColorFlag = RL_GREY; + } + else + { + emit newPixmap ( BitmCubeDisabled ); + eColorFlag = RL_DISABLED; + } + } } void CMultiColorLED::OnTimerRedLight() @@ -134,30 +143,46 @@ void CMultiColorLED::UpdateColor() } } +void CMultiColorLED::Reset() +{ + if ( this->isEnabled() ) + { + // reset color flags + bFlagRedLi = false; + bFlagGreenLi = false; + bFlagYellowLi = false; + + UpdateColor(); + } +} + void CMultiColorLED::SetLight ( const int iNewStatus ) { - switch ( iNewStatus ) + if ( this->isEnabled() ) { - case MUL_COL_LED_GREEN: - // green light - bFlagGreenLi = true; - TimerGreenLight.start(); - break; + switch ( iNewStatus ) + { + case MUL_COL_LED_GREEN: + // green light + bFlagGreenLi = true; + TimerGreenLight.start(); + break; - case MUL_COL_LED_YELLOW: - // yellow light - bFlagYellowLi = true; - TimerYellowLight.start(); - break; + case MUL_COL_LED_YELLOW: + // yellow light + bFlagYellowLi = true; + TimerYellowLight.start(); + break; - case MUL_COL_LED_RED: - // red light - bFlagRedLi = true; - TimerRedLight.start(); - break; + case MUL_COL_LED_RED: + // red light + bFlagRedLi = true; + TimerRedLight.start(); + break; + } + + UpdateColor(); } - - UpdateColor(); } void CMultiColorLED::SetUpdateTime ( const int iNUTi ) diff --git a/src/multicolorled.h b/src/multicolorled.h index c5596475..abd6661e 100755 --- a/src/multicolorled.h +++ b/src/multicolorled.h @@ -60,11 +60,20 @@ public: void SetLight ( const int iNewStatus ); protected: - enum ELightColor { RL_GREY, RL_GREEN, RL_YELLOW, RL_RED }; + enum ELightColor + { + RL_DISABLED, + RL_GREY, + RL_GREEN, + RL_YELLOW, + RL_RED + }; ELightColor eColorFlag; + virtual void changeEvent ( QEvent* curEvent ); void UpdateColor(); + QPixmap BitmCubeDisabled; QPixmap BitmCubeGrey; QPixmap BitmCubeGreen; QPixmap BitmCubeYellow; @@ -142,5 +151,4 @@ protected: CMultColLEDListViewItem LED0, LED1; }; - #endif // _MULTCOLORLED_H__FD6B49B5_87DF_48DD_A873_804E1606C2AC__INCLUDED_