From 8b0389c192d77c219116aa101b4ae50e5a4aeb85 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Tue, 15 Jan 2008 22:54:04 +0000 Subject: [PATCH] third attempt to port to QT4, not working, still a lot to do... --- src/global.h | 3 + src/llconserverdlg.cpp | 48 +++---- src/main.cpp | 289 ++++++++++++++++++++--------------------- src/multicolorled.cpp | 26 ++-- src/server.cpp | 2 +- 5 files changed, 178 insertions(+), 190 deletions(-) diff --git a/src/global.h b/src/global.h index bdd4f9df..2a4867df 100755 --- a/src/global.h +++ b/src/global.h @@ -105,6 +105,9 @@ #define TIME_MOV_AV_RESPONSE 30 // seconds #define LEN_MOV_AV_RESPONSE ( TIME_MOV_AV_RESPONSE * 1000 / MIN_BLOCK_DURATION_MS ) +// GUI definition: width/heigth size of LED pixmaps +#define LED_WIDTH_HEIGHT_SIZE_PIXEL 13 + #define _MAXSHORT 32767 #define _MAXBYTE 255 // binary: 11111111 diff --git a/src/llconserverdlg.cpp b/src/llconserverdlg.cpp index 33d6301d..0f0de0f6 100755 --- a/src/llconserverdlg.cpp +++ b/src/llconserverdlg.cpp @@ -27,40 +27,29 @@ /* Implementation *************************************************************/ CLlconServerDlg::CLlconServerDlg ( CServer* pNServP, QWidget* parent ) - : pServer ( pNServP ), QDialog ( parent ) + : pServer ( pNServP ), QDialog ( parent ), + BitmCubeGreen ( LED_WIDTH_HEIGHT_SIZE_PIXEL, LED_WIDTH_HEIGHT_SIZE_PIXEL ), + BitmCubeRed ( LED_WIDTH_HEIGHT_SIZE_PIXEL, LED_WIDTH_HEIGHT_SIZE_PIXEL ), + BitmCubeYellow ( LED_WIDTH_HEIGHT_SIZE_PIXEL, LED_WIDTH_HEIGHT_SIZE_PIXEL ) { /* set text for version and application name */ TextLabelNameVersion->setText ( QString ( APP_NAME ) + tr ( " server " ) + QString ( VERSION ) ); /* Create bitmaps */ - /* Define size of the bitmaps */ - const int iXSize = 13; - const int iYSize = 13; - BitmCubeGreen.resize ( iXSize, iYSize ); BitmCubeGreen.fill ( QColor ( 0, 255, 0 ) ); - BitmCubeRed.resize ( iXSize, iYSize ); BitmCubeRed.fill ( QColor ( 255, 0, 0 ) ); - BitmCubeYellow.resize ( iXSize, iYSize ); BitmCubeYellow.fill ( QColor ( 255, 255, 0 ) ); - /* set up list view for connected clients (We assume that one column is - already there) */ - ListViewClients->setColumnText ( 0, tr ( "Client IP : Port" ) ); + // set up list view for connected clients ListViewClients->setColumnWidth ( 0, 170 ); - ListViewClients->addColumn ( tr ( "Name" ) ); - ListViewClients->setColumnAlignment ( 1, Qt::AlignLeft ); +// ListViewClients->setColumnAlignment ( 1, Qt::AlignLeft ); ListViewClients->setColumnWidth ( 1, 150 ); - ListViewClients->addColumn ( tr ( "Put" ) ); - ListViewClients->setColumnAlignment ( 2, Qt::AlignCenter ); - ListViewClients->addColumn ( tr ( "Get" ) ); - ListViewClients->setColumnAlignment ( 3, Qt::AlignCenter ); - ListViewClients->addColumn ( tr ( "Jitter buffer size" ) ); - ListViewClients->setColumnAlignment ( 4, Qt::AlignRight ); - ListViewClients->addColumn ( tr ( "Block Size In" ) ); - ListViewClients->setColumnAlignment ( 5, Qt::AlignRight ); - ListViewClients->addColumn ( tr ( "Block Size Out" ) ); - ListViewClients->setColumnAlignment ( 6, Qt::AlignRight ); +// ListViewClients->setColumnAlignment ( 2, Qt::AlignCenter ); +// ListViewClients->setColumnAlignment ( 3, Qt::AlignCenter ); +// ListViewClients->setColumnAlignment ( 4, Qt::AlignRight ); +// ListViewClients->setColumnAlignment ( 5, Qt::AlignRight ); +// ListViewClients->setColumnAlignment ( 6, Qt::AlignRight ); ListViewClients->clear(); /* insert items in reverse order because in Windows all of them are @@ -74,26 +63,27 @@ CLlconServerDlg::CLlconServerDlg ( CServer* pNServP, QWidget* parent ) #endif } - /* Init timing jitter text label */ + // Init timing jitter text label TextLabelResponseTime->setText ( "" ); /* Main menu bar -------------------------------------------------------- */ pMenu = new QMenuBar ( this ); - pMenu->insertItem ( tr ( "&?" ), new CLlconHelpMenu ( this ) ); - pMenu->setSeparator ( QMenuBar::InWindowsStyle ); +// pMenu->insertItem ( tr ( "&?" ), new CLlconHelpMenu ( this ) ); + pMenu->addMenu ( new CLlconHelpMenu ( this ) ); + //pMenu->setSeparator ( QMenuBar::InWindowsStyle ); - /* Now tell the layout about the menu */ - CLlconServerDlgBaseLayout->setMenuBar ( pMenu ); + // Now tell the layout about the menu + layout()->setMenuBar ( pMenu ); /* connections ---------------------------------------------------------- */ - /* timers */ + // timers QObject::connect ( &Timer, SIGNAL ( timeout() ), this, SLOT ( OnTimer() ) ); /* timers --------------------------------------------------------------- */ - /* start timer for GUI controls */ + // start timer for GUI controls Timer.start ( GUI_CONTRL_UPDATE_TIME ); } diff --git a/src/main.cpp b/src/main.cpp index 9c94dad9..aebbc77f 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -45,66 +45,66 @@ int main ( int argc, char** argv ) bool bUseServerLogging = false; std::string strIniFileName = ""; - /* QT docu: argv()[0] is the program name, argv()[1] is the first - argument and argv()[argc()-1] is the last argument. - Start with first argument, therefore "i = 1" */ - for ( int i = 1; i < argc; i++ ) - { - /* Server mode flag ------------------------------------------------------- */ - if ( GetFlagArgument ( argc, argv, i, "-s", "--server" ) == TRUE ) - { - bIsClient = false; - -cerr << "server "; - - continue; - } - - /* Use GUI flag ----------------------------------------------------------- */ - if ( GetFlagArgument ( argc, argv, i, "-n", "--nogui" ) == TRUE ) - { - bUseGUI = false; - -cerr << "nogui "; - - continue; - } - - /* Use logging flag ------------------------------------------------------- */ - if ( GetFlagArgument ( argc, argv, i, "-l", "--log" ) == TRUE ) - { - bUseServerLogging = true; - -cerr << "logging "; - - continue; - } - - /* Initialization file ---------------------------------------------------- */ - if ( GetStringArgument ( argc, argv, i, "-i", "--inifile", strArgument ) == TRUE ) - { - strIniFileName = strArgument; - continue; - } - - /* Help (usage) flag ------------------------------------------------------ */ - if ( ( !strcmp ( argv[i], "--help" ) ) || - ( !strcmp ( argv[i], "-h" ) ) || ( !strcmp ( argv[i], "-?" ) ) ) - { - const std::string strHelp = UsageArguments(argv); - cerr << strHelp; - exit ( 1 ); - } - - /* Unknown option --------------------------------------------------------- */ - cerr << argv[0] << ": "; - cerr << "Unknown option '" << argv[i] << "' -- use '--help' for help" - << endl; - - exit ( 1 ); + /* QT docu: argv()[0] is the program name, argv()[1] is the first + argument and argv()[argc()-1] is the last argument. + Start with first argument, therefore "i = 1" */ + for ( int i = 1; i < argc; i++ ) + { + /* Server mode flag ------------------------------------------------------- */ + if ( GetFlagArgument ( argc, argv, i, "-s", "--server" ) == TRUE ) + { + bIsClient = false; + +cerr << "server "; + + continue; + } + + /* Use GUI flag ----------------------------------------------------------- */ + if ( GetFlagArgument ( argc, argv, i, "-n", "--nogui" ) == TRUE ) + { + bUseGUI = false; + +cerr << "nogui "; + + continue; + } + + /* Use logging flag ------------------------------------------------------- */ + if ( GetFlagArgument ( argc, argv, i, "-l", "--log" ) == TRUE ) + { + bUseServerLogging = true; + +cerr << "logging "; + + continue; + } + + /* Initialization file ---------------------------------------------------- */ + if ( GetStringArgument ( argc, argv, i, "-i", "--inifile", strArgument ) == TRUE ) + { + strIniFileName = strArgument; + continue; + } + + /* Help (usage) flag ------------------------------------------------------ */ + if ( ( !strcmp ( argv[i], "--help" ) ) || + ( !strcmp ( argv[i], "-h" ) ) || ( !strcmp ( argv[i], "-?" ) ) ) + { + const std::string strHelp = UsageArguments(argv); + cerr << strHelp; + exit ( 1 ); + } + + /* Unknown option --------------------------------------------------------- */ + cerr << argv[0] << ": "; + cerr << "Unknown option '" << argv[i] << "' -- use '--help' for help" + << endl; + + exit ( 1 ); } - /* Application object */ + // Application object QApplication app ( argc, argv, bUseGUI ); if ( bIsClient ) @@ -118,10 +118,10 @@ cerr << "logging "; Settings.Load ( strIniFileName ); // GUI object - CLlconClientDlg ClientDlg ( &Client, 0, 0, FALSE, Qt::WStyle_MinMax ); + CLlconClientDlg ClientDlg ( &Client, 0 ); // set main window - app.setMainWidget ( &ClientDlg ); + app.setActiveWindow ( &ClientDlg ); pApp = &app; // Needed for post-event routine // show dialog @@ -140,11 +140,10 @@ cerr << "logging "; if ( bUseGUI ) { // GUI object for the server - CLlconServerDlg ServerDlg ( &Server, 0, 0, FALSE, - Qt::WStyle_MinMax ); + CLlconServerDlg ServerDlg ( &Server, 0 ); // set main window - app.setMainWidget ( &ServerDlg ); + app.setActiveWindow ( &ServerDlg ); pApp = &app; // needed for post-event routine // show dialog @@ -154,7 +153,7 @@ cerr << "logging "; else { // only start application without using the GUI - qDebug ( CAboutDlg::GetVersionAndNameStr ( false ) ); + qDebug() << CAboutDlg::GetVersionAndNameStr ( false ); app.exec(); } } @@ -166,86 +165,86 @@ cerr << "logging "; /******************************************************************************\ * Command Line Argument Parsing * \******************************************************************************/ -std::string UsageArguments ( char **argv ) -{ - return - "Usage: " + std::string ( argv[0] ) + " [option] [argument]\n" - "Recognized options:\n" - " -s, --server start server\n" - " -n, --nogui disable GUI (only avaiable for server)\n" - " -l, --log enable logging\n" - " -i, --inifile initialization file name (only available for client)\n" - " -h, -?, --help this help text\n" - "Example: " + std::string ( argv[0] ) + " -l -inifile myinifile.ini\n"; -} - -bool GetFlagArgument ( int, char **argv, int &i, - std::string strShortOpt, std::string strLongOpt ) -{ - if ( ( !strShortOpt.compare ( argv[i] ) ) || ( !strLongOpt.compare ( argv[i] ) ) ) - { - return true; - } - else - { - return false; - } -} - -bool GetStringArgument ( int argc, char **argv, int &i, - std::string strShortOpt, std::string strLongOpt, - std::string & strArg ) -{ - if ( ( !strShortOpt.compare ( argv[i] ) ) || ( !strLongOpt.compare ( argv[i] ) ) ) - { - if ( ++i >= argc ) - { - cerr << argv[0] << ": "; - cerr << "'" << strLongOpt << "' needs a string argument" << endl; - exit ( 1 ); - } - - strArg = argv[i]; - - return true; - } - else - { - return false; - } -} - -bool GetNumericArgument ( int argc, char **argv, int &i, - std::string strShortOpt, std::string strLongOpt, - double rRangeStart, double rRangeStop, - double & rValue) -{ - if ( ( !strShortOpt.compare ( argv[i] ) ) || ( !strLongOpt.compare ( argv[i] ) ) ) - { - if ( ++i >= argc ) - { - cerr << argv[0] << ": "; - cerr << "'" << strLongOpt << "' needs a numeric argument between " - << rRangeStart << " and " << rRangeStop << endl; - exit ( 1 ); - } - - char *p; - rValue = strtod ( argv[i], &p ); - if ( *p || rValue < rRangeStart || rValue > rRangeStop ) - { - cerr << argv[0] << ": "; - cerr << "'" << strLongOpt << "' needs a numeric argument between " - << rRangeStart << " and " << rRangeStop << endl; - exit ( 1 ); - } - - return true; - } - else - { - return false; - } +std::string UsageArguments ( char **argv ) +{ + return + "Usage: " + std::string ( argv[0] ) + " [option] [argument]\n" + "Recognized options:\n" + " -s, --server start server\n" + " -n, --nogui disable GUI (only avaiable for server)\n" + " -l, --log enable logging\n" + " -i, --inifile initialization file name (only available for client)\n" + " -h, -?, --help this help text\n" + "Example: " + std::string ( argv[0] ) + " -l -inifile myinifile.ini\n"; +} + +bool GetFlagArgument ( int, char **argv, int &i, + std::string strShortOpt, std::string strLongOpt ) +{ + if ( ( !strShortOpt.compare ( argv[i] ) ) || ( !strLongOpt.compare ( argv[i] ) ) ) + { + return true; + } + else + { + return false; + } +} + +bool GetStringArgument ( int argc, char **argv, int &i, + std::string strShortOpt, std::string strLongOpt, + std::string & strArg ) +{ + if ( ( !strShortOpt.compare ( argv[i] ) ) || ( !strLongOpt.compare ( argv[i] ) ) ) + { + if ( ++i >= argc ) + { + cerr << argv[0] << ": "; + cerr << "'" << strLongOpt << "' needs a string argument" << endl; + exit ( 1 ); + } + + strArg = argv[i]; + + return true; + } + else + { + return false; + } +} + +bool GetNumericArgument ( int argc, char **argv, int &i, + std::string strShortOpt, std::string strLongOpt, + double rRangeStart, double rRangeStop, + double & rValue) +{ + if ( ( !strShortOpt.compare ( argv[i] ) ) || ( !strLongOpt.compare ( argv[i] ) ) ) + { + if ( ++i >= argc ) + { + cerr << argv[0] << ": "; + cerr << "'" << strLongOpt << "' needs a numeric argument between " + << rRangeStart << " and " << rRangeStop << endl; + exit ( 1 ); + } + + char *p; + rValue = strtod ( argv[i], &p ); + if ( *p || rValue < rRangeStart || rValue > rRangeStop ) + { + cerr << argv[0] << ": "; + cerr << "'" << strLongOpt << "' needs a numeric argument between " + << rRangeStart << " and " << rRangeStop << endl; + exit ( 1 ); + } + + return true; + } + else + { + return false; + } } @@ -262,6 +261,6 @@ void PostWinMessage ( const _MESSAGE_IDENT MessID, const int iMessageParam, new CLlconEvent ( MessID, iMessageParam, iChanNum ); // Qt will delete the event object when done - QThread::postEvent ( pApp->mainWidget(), LlconEv ); +// QThread::postEvent ( pApp->mainWidget(), LlconEv ); } } diff --git a/src/multicolorled.cpp b/src/multicolorled.cpp index c0bbbb90..7b781b90 100755 --- a/src/multicolorled.cpp +++ b/src/multicolorled.cpp @@ -30,20 +30,16 @@ /* Implementation *************************************************************/ -CMultiColorLEDbase::CMultiColorLEDbase() +CMultiColorLEDbase::CMultiColorLEDbase() : + BitmCubeGreen ( LED_WIDTH_HEIGHT_SIZE_PIXEL, LED_WIDTH_HEIGHT_SIZE_PIXEL ), + BitmCubeRed ( LED_WIDTH_HEIGHT_SIZE_PIXEL, LED_WIDTH_HEIGHT_SIZE_PIXEL ), + BitmCubeGrey ( LED_WIDTH_HEIGHT_SIZE_PIXEL, LED_WIDTH_HEIGHT_SIZE_PIXEL ), + BitmCubeYellow ( LED_WIDTH_HEIGHT_SIZE_PIXEL, LED_WIDTH_HEIGHT_SIZE_PIXEL ) { - /* Define size of the bitmaps */ - const int iXSize = 13; - const int iYSize = 13; - /* Create bitmaps */ - BitmCubeGreen.resize ( iXSize, iYSize ); BitmCubeGreen.fill ( QColor ( 0, 255, 0 ) ); - BitmCubeRed.resize ( iXSize, iYSize ); BitmCubeRed.fill ( QColor ( 255, 0, 0 ) ); - BitmCubeGrey.resize ( iXSize, iYSize ); BitmCubeGrey.fill ( QColor ( 192, 192, 192 ) ); - BitmCubeYellow.resize ( iXSize, iYSize ); BitmCubeYellow.fill ( QColor ( 255, 255, 0 ) ); /* Init color flags */ @@ -141,21 +137,21 @@ void CMultiColorLEDbase::SetLight ( int iNewStatus ) switch ( iNewStatus ) { case MUL_COL_LED_GREEN: - /* Green light */ + // Green light bFlagGreenLi = true; - TimerGreenLight.changeInterval ( iUpdateTime ); + TimerGreenLight.setInterval ( iUpdateTime ); break; case MUL_COL_LED_YELLOW: - /* Yellow light */ + // Yellow light bFlagYellowLi = true; - TimerYellowLight.changeInterval ( iUpdateTime ); + TimerYellowLight.setInterval ( iUpdateTime ); break; case MUL_COL_LED_RED: - /* Red light */ + // Red light bFlagRedLi = true; - TimerRedLight.changeInterval ( iUpdateTime ); + TimerRedLight.setInterval ( iUpdateTime ); break; } diff --git a/src/server.cpp b/src/server.cpp index b584424b..53c8a8b2 100755 --- a/src/server.cpp +++ b/src/server.cpp @@ -89,7 +89,7 @@ void CServer::Stop() // logging QString strLogStr = CLogTimeDate::toString() + "Server stopped"; - qDebug ( strLogStr ); // on console + qDebug() << strLogStr; // on console Logging << strLogStr; // in log file }