From 944639e7eeb5bf2a0676bf2748c76343f9654fd2 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Thu, 21 Apr 2011 07:04:58 +0000 Subject: [PATCH] prepared for the combo box functionality for server names --- src/connectdlg.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++ src/connectdlg.h | 2 ++ src/connectdlgbase.ui | 51 ++++++++++++++++++++++++++------------- src/llconclientdlg.h | 8 ++++--- 4 files changed, 96 insertions(+), 20 deletions(-) diff --git a/src/connectdlg.cpp b/src/connectdlg.cpp index 4fc0209a..34894099 100755 --- a/src/connectdlg.cpp +++ b/src/connectdlg.cpp @@ -34,10 +34,38 @@ CConnectDlg::CConnectDlg ( QWidget* parent, Qt::WindowFlags f ) // Add help text to controls ----------------------------------------------- + // server address + QString strServAddrH = tr ( "Server Address: The IP address or URL " + "of the server running the llcon server software must be set here. " + "A list of the most recent used server URLs is available for " + "selection. If an invalid address was chosen, an error message is " + "shown in the status bar." ); + + TextLabelServerAddr->setWhatsThis ( strServAddrH ); + LineEditServerAddr->setWhatsThis ( strServAddrH ); + + LineEditServerAddr->setAccessibleName ( tr ( "Server address edit box" ) ); + LineEditServerAddr->setAccessibleDescription ( tr ( "Holds the current server " + "URL. It also stores old URLs in the combo box list." ) ); + + + // init server address combo box (max MAX_NUM_SERVER_ADDR_ITEMS entries) + LineEditServerAddr->setMaxCount ( MAX_NUM_SERVER_ADDR_ITEMS ); + LineEditServerAddr->setInsertPolicy ( QComboBox::InsertAtTop ); + + // load data from ini file + for ( int iLEIdx = 0; iLEIdx < MAX_NUM_SERVER_ADDR_ITEMS; iLEIdx++ ) + { +// if ( !pClient->vstrIPAddress[iLEIdx].isEmpty() ) + { // TODO +// LineEditServerAddr->addItem ( pClient->vstrIPAddress[iLEIdx] ); + } + } + // set up list view for connected clients ListViewServers->setColumnWidth ( 0, 170 ); ListViewServers->setColumnWidth ( 1, 130 ); @@ -48,6 +76,13 @@ CConnectDlg::CConnectDlg ( QWidget* parent, Qt::WindowFlags f ) // Connections ------------------------------------------------------------- + // line edits + QObject::connect ( LineEditServerAddr, SIGNAL ( editTextChanged ( const QString ) ), + this, SLOT ( OnLineEditServerAddrTextChanged ( const QString ) ) ); + + QObject::connect ( LineEditServerAddr, SIGNAL ( activated ( int ) ), + this, SLOT ( OnLineEditServerAddrActivated ( int ) ) ); + // timers QObject::connect ( &TimerPing, SIGNAL ( timeout() ), this, SLOT ( OnTimerPing() ) ); @@ -177,6 +212,26 @@ void CConnectDlg::SetServerList ( const CHostAddress& InetAddr, TimerPing.start ( PING_UPDATE_TIME_SERVER_LIST_MS ); } +void CConnectDlg::OnLineEditServerAddrTextChanged ( const QString ) +{ + // if the maximum number of items in the combo box is reached, + // delete the last item so that the new item can be added (first + // in - first out) + if ( LineEditServerAddr->count() == MAX_NUM_SERVER_ADDR_ITEMS ) + { + LineEditServerAddr->removeItem ( MAX_NUM_SERVER_ADDR_ITEMS - 1 ); + } +} + +void CConnectDlg::OnLineEditServerAddrActivated ( int index ) +{ + // move activated list item to the top + const QString strCurIPAddress = LineEditServerAddr->itemText ( index ); + LineEditServerAddr->removeItem ( index ); + LineEditServerAddr->insertItem ( 0, strCurIPAddress ); + LineEditServerAddr->setCurrentIndex ( 0 ); +} + void CConnectDlg::OnTimerPing() { // send ping messages to the servers in the list diff --git a/src/connectdlg.h b/src/connectdlg.h index 3ed066f6..58d8c5f8 100755 --- a/src/connectdlg.h +++ b/src/connectdlg.h @@ -73,6 +73,8 @@ protected: bool bServerListReceived; public slots: + void OnLineEditServerAddrTextChanged ( const QString ); + void OnLineEditServerAddrActivated ( int index ); void OnTimerPing(); void OnTimerReRequestServList(); diff --git a/src/connectdlgbase.ui b/src/connectdlgbase.ui index 05dc0f30..a9710ac0 100755 --- a/src/connectdlgbase.ui +++ b/src/connectdlgbase.ui @@ -6,7 +6,7 @@ 0 0 584 - 355 + 256 @@ -55,18 +55,25 @@ - - - Server Address - - - - - - - true - - + + + + + Server Address + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + true + + + + @@ -77,16 +84,26 @@ - 40 - 20 + 351 + 25 - + - PushButton + C&ancel + + + + + + + &Connect + + + true diff --git a/src/llconclientdlg.h b/src/llconclientdlg.h index 2b943c7e..ee8d3c7b 100755 --- a/src/llconclientdlg.h +++ b/src/llconclientdlg.h @@ -74,9 +74,11 @@ class CLlconClientDlg : public QDialog, private Ui_CLlconClientDlgBase Q_OBJECT public: - CLlconClientDlg ( CClient* pNCliP, const bool bNewConnectOnStartup, - const bool bNewDisalbeLEDs, - QWidget* parent = 0, Qt::WindowFlags f = 0 ); + CLlconClientDlg ( CClient* pNCliP, + const bool bNewConnectOnStartup, + const bool bNewDisalbeLEDs, + QWidget* parent = 0, + Qt::WindowFlags f = 0 ); protected: void SetGUIDesign ( const EGUIDesign eNewDesign );