00001
00007
00008 #include "config.h"
00009
00010 #include <QDebug>
00011
00012 Config::Config( QWidget *parent ) : QDialog( parent )
00013 {
00014
00015 _contentsWidget = new QListWidget() ;
00016 _contentsWidget->setViewMode( QListView::IconMode ) ;
00017 _contentsWidget->setIconSize( QSize(96, 84) ) ;
00018 _contentsWidget->setMovement( QListView::Static ) ;
00019 _contentsWidget->setMaximumWidth( 150 ) ;
00020 _contentsWidget->setSpacing( 12 ) ;
00021 _contentsWidget->setCurrentRow( 0 ) ;
00022
00023 connect( _contentsWidget, SIGNAL( currentItemChanged( QListWidgetItem*, QListWidgetItem* ) ), this, SLOT( changePage( QListWidgetItem *, QListWidgetItem* ) ) ) ;
00024
00025 _general = new QListWidgetItem( _contentsWidget ) ;
00026 _general->setText( trUtf8("General") ) ;
00027 _general->setTextAlignment( Qt::AlignHCenter ) ;
00028 _general->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled ) ;
00029
00030 _network = new QListWidgetItem( _contentsWidget ) ;
00031 _network->setText( trUtf8("Network") ) ;
00032 _network->setTextAlignment( Qt::AlignHCenter ) ;
00033 _network->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled ) ;
00034
00035 _view = new QListWidgetItem( _contentsWidget ) ;
00036 _view->setText( trUtf8("View") ) ;
00037 _view->setTextAlignment( Qt::AlignHCenter ) ;
00038 _view->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled ) ;
00039
00040
00041
00042 _generalConfig = new QWidget( this ) ;
00043
00044 QGroupBox *pathBox = new QGroupBox( trUtf8( "Path" ) ) ;
00045
00046 QLabel *userPathLabel = new QLabel( trUtf8( "Default user" ) , this ) ;
00047 _userPathEdit = new QLineEdit( _generalConfig ) ;
00048
00049 QLabel *railsFileLabel = new QLabel( trUtf8( "Rail renderer" ) , this ) ;
00050 _railsFileEdit = new QLineEdit( _generalConfig ) ;
00051
00052 QGridLayout *pathLayout = new QGridLayout ;
00053 pathLayout->addWidget( userPathLabel, 0, 0 ) ;
00054 pathLayout->addWidget( _userPathEdit, 0, 1 ) ;
00055 pathLayout->addWidget( railsFileLabel, 1, 0 ) ;
00056 pathLayout->addWidget( _railsFileEdit, 1, 1 ) ;
00057 pathBox->setLayout( pathLayout ) ;
00058
00059 QVBoxLayout *boxLayout = new QVBoxLayout( _generalConfig ) ;
00060 boxLayout->addWidget( pathBox ) ;
00061 boxLayout->addStretch( 1 ) ;
00062
00063 _generalConfig->setLayout( boxLayout ) ;
00064
00065
00066
00067
00068 _networkConfig = new QWidget( this ) ;
00069
00070 QGroupBox *netBox = new QGroupBox( trUtf8( "Network parameters" ) );
00071
00072 QLabel *addressLabel = new QLabel( trUtf8( "Server address:" ) ) ;
00073 _addressEdit = new QLineEdit ;
00074 _addressEdit->setAlignment( Qt::AlignRight ) ;
00075
00076 QLabel *portLabel = new QLabel( trUtf8( "Server port:" ) ) ;
00077 _portEdit = new QLineEdit ;
00078 _portEdit->setAlignment( Qt::AlignRight ) ;
00079
00080 QLabel *protocolLabel = new QLabel( trUtf8( "Protocol:" ) ) ;
00081 _protocolCombo = new QComboBox() ;
00082 _protocolCombo->addItem( tr( "srcp 0.7.3" ) ) ;
00083 _protocolCombo->addItem( tr( "srcp 0.8.3" ) ) ;
00084
00085 QGridLayout *netLayout = new QGridLayout ;
00086 netLayout->addWidget( addressLabel, 0, 0 ) ;
00087 netLayout->addWidget( _addressEdit, 0, 1 ) ;
00088 netLayout->addWidget( portLabel, 1, 0 ) ;
00089 netLayout->addWidget( _portEdit, 1, 1 ) ;
00090 netLayout->addWidget( protocolLabel, 2, 0 ) ;
00091 netLayout->addWidget( _protocolCombo, 2, 1 ) ;
00092 netBox->setLayout( netLayout ) ;
00093
00094 QVBoxLayout *netBoxLayout = new QVBoxLayout( _networkConfig ) ;
00095 netBoxLayout->addWidget( netBox ) ;
00096 netBoxLayout->addStretch( 1 ) ;
00097
00098
00099
00100
00101
00102 _viewConfig = new QWidget( this ) ;
00103
00104 QGroupBox *uiBox = new QGroupBox( trUtf8( "User Interface Mode" ) ) ;
00105
00106 _uiModeCombo = new QComboBox( uiBox ) ;
00107 _uiModeCombo->addItem( trUtf8( "Docked Window" ) ) ;
00108 _uiModeCombo->addItem( trUtf8( "Multiple Top-Level Windows" ) ) ;
00109
00110
00111 QVBoxLayout *uiLayout = new QVBoxLayout ;
00112 uiLayout->addWidget( _uiModeCombo );
00113 uiLayout->addStretch( 1 ) ;
00114 uiBox->setLayout( uiLayout ) ;
00115
00116 QVBoxLayout *viewBoxLayout = new QVBoxLayout( _viewConfig ) ;
00117 viewBoxLayout->addWidget( uiBox ) ;
00118 viewBoxLayout->addStretch( 1 ) ;
00119
00120 _viewConfig->setLayout( viewBoxLayout ) ;
00121
00122
00123
00124 _pagesWidget = new QStackedWidget;
00125 _pagesWidget->addWidget( _generalConfig ) ;
00126 _pagesWidget->addWidget( _networkConfig ) ;
00127 _pagesWidget->addWidget( _viewConfig ) ;
00128
00129 QPushButton *applyButton = new QPushButton( QIcon( ":img/apply.svg"), trUtf8( "Apply" ) ) ;
00130 connect( applyButton, SIGNAL( clicked() ), this, SLOT( accept() ) ) ;
00131
00132 QPushButton *cancelButton = new QPushButton( QIcon( ":img/cancel.svg"), trUtf8( "Cancel" ) ) ;
00133 connect( cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) ) ;
00134
00135 QHBoxLayout *buttonsLayout = new QHBoxLayout() ;
00136 buttonsLayout->addStretch( 1 ) ;
00137 buttonsLayout->addWidget( applyButton ) ;
00138 buttonsLayout->addWidget( cancelButton ) ;
00139
00140 QHBoxLayout *horizontalLayout = new QHBoxLayout ;
00141 horizontalLayout->addWidget( _contentsWidget ) ;
00142 horizontalLayout->addWidget( _pagesWidget, 1 ) ;
00143
00144 QVBoxLayout *mainLayout = new QVBoxLayout( this ) ;
00145 mainLayout->addLayout( horizontalLayout ) ;
00146 mainLayout->addSpacing( 12 ) ;
00147 mainLayout->addLayout( buttonsLayout ) ;
00148 setLayout( mainLayout ) ;
00149
00150 setWindowTitle( trUtf8( "orK Configuration" ) ) ;
00151
00152 resize( 500, 450 ) ;
00153 createIcons() ;
00154 }
00155
00156 void Config::createIcons()
00157 {
00158 setWindowIcon( QIcon( ":img/ork.svg" ) ) ;
00159
00160 _general->setIcon( QIcon(":img/config_general.svg") );
00161 _network->setIcon( QIcon(":img/config_network.svg") );
00162 _view->setIcon( QIcon(":img/config_view.svg") );
00163
00164 }
00165
00166
00167 void Config::changePage( QListWidgetItem *current, QListWidgetItem *previous )
00168 {
00169 if( ! current )
00170 current = previous ;
00171
00172 _pagesWidget->setCurrentIndex( _contentsWidget->row( current ) ) ;
00173 }
00174
00175
00176 void Config::readConfig()
00177 {
00178 QSettings settings( "OrK", "client" ) ;
00179
00180 _multiWinFlag = settings.value( "multiWin", "false" ).toBool() ;
00181 emit viewMultiWinModeChanged( _multiWinFlag ) ;
00182
00183 _userPath = settings.value( "userPath", QDir::home().path() ).toString() ;
00184 emit userPathChanged( _userPath ) ;
00185
00186 _railsFile = settings.value( "railsFile", "../shared/rails/default.svg" ).toString() ;
00187 emit railsFileChanged( _railsFile ) ;
00188
00189 _protocol = settings.value( "protocol", "0" ).toInt() ;
00190
00191 _serverAddress = settings.value( "serverAddress", "Localhost" ).toString() ;
00192 emit serverAdressChanged( _serverAddress ) ;
00193
00194 _serverPort = settings.value( "serverPort", "4303" ).toInt() ;
00195 emit serverPortChanged( _serverPort ) ;
00196
00197 _clientPort = settings.value( "clientPort", "6000" ).toInt() ;
00198 emit clientPortChanged( _clientPort ) ;
00199 }
00200
00201 void Config::writeConfig()
00202 {
00203 QSettings settings( "OrK", "client" ) ;
00204
00205 settings.setValue( "multiWin", _multiWinFlag ) ;
00206
00207 settings.setValue( "userPath", _userPath ) ;
00208 settings.setValue( "railsFile", _railsFile ) ;
00209
00210 settings.setValue( "protocol", _protocol ) ;
00211 settings.setValue( "serverAddress", _serverAddress ) ;
00212 settings.setValue( "serverPort", _serverPort ) ;
00213 settings.setValue( "clientPort", _clientPort ) ;
00214
00215 }
00216
00217 void Config::showEvent( QShowEvent *event )
00218 {
00219 _uiModeCombo->setCurrentIndex( _multiWinFlag ) ;
00220
00221 _userPathEdit->setText( _userPath ) ;
00222 _railsFileEdit->setText( _railsFile ) ;
00223
00224 _addressEdit->setText( _serverAddress ) ;
00225 _portEdit->setText( QString( _serverPort ) ) ;
00226
00227
00228 _pagesWidget->setCurrentIndex( 0 ) ;
00229 _contentsWidget->setCurrentRow( 0 ) ;
00230
00231 event->accept() ;
00232 }
00233
00234 void Config::accept()
00235 {
00236 if ( _multiWinFlag != _uiModeCombo->currentIndex() )
00237 {
00238 _multiWinFlag = _uiModeCombo->currentIndex() ;
00239 emit viewMultiWinModeChanged( _multiWinFlag ) ;
00240 }
00241
00242 if ( _userPath != _userPathEdit->text() )
00243 {
00244 _userPath = _userPathEdit->text() ;
00245 emit userPathChanged( _userPath ) ;
00246 }
00247
00248 if ( _railsFile != _railsFileEdit->text() )
00249 {
00250 _railsFile = _railsFileEdit->text() ;
00251 emit railsFileChanged( _railsFile ) ;
00252 }
00253
00254 if ( _serverAddress != _addressEdit->text() )
00255 {
00256 _serverAddress = _addressEdit->text() ;
00257 emit serverAdressChanged( _serverAddress ) ;
00258 }
00259
00260 if ( _serverPort != _portEdit->text().toInt() )
00261 {
00262 _serverPort = _railsFileEdit->text().toInt() ;
00263 emit serverPortChanged( _serverPort ) ;
00264 }
00265
00266
00267
00268
00269 hide() ;
00270 }