QTfrontend/gameuiconfig.cpp
branchflibqtfrontend
changeset 8363 0b4ac686fc44
parent 8358 274afc318dca
child 8385 9e8924ff9813
equal deleted inserted replaced
8306:50fe80adbfcb 8363:0b4ac686fc44
    22 #include <QInputDialog>
    22 #include <QInputDialog>
    23 #include <QCryptographicHash>
    23 #include <QCryptographicHash>
    24 #include <QStandardItemModel>
    24 #include <QStandardItemModel>
    25 #include <QNetworkProxy>
    25 #include <QNetworkProxy>
    26 #include <QNetworkProxyFactory>
    26 #include <QNetworkProxyFactory>
       
    27 #include <utility>
    27 
    28 
    28 #include "gameuiconfig.h"
    29 #include "gameuiconfig.h"
    29 #include "hwform.h"
    30 #include "hwform.h"
    30 #include "pageoptions.h"
    31 #include "pageoptions.h"
    31 #include "pagevideos.h"
    32 #include "pagevideos.h"
    32 #include "pagenetserver.h"
    33 #include "pagenetserver.h"
    33 #include "hwconsts.h"
    34 #include "hwconsts.h"
    34 #include "fpsedit.h"
    35 #include "fpsedit.h"
    35 #include "HWApplication.h"
    36 #include "HWApplication.h"
    36 #include "DataManager.h"
    37 #include "DataManager.h"
       
    38 #include "SDL.h"
    37 
    39 
    38 
    40 
    39 const QNetworkProxy::ProxyType proxyTypesMap[] = {
    41 const QNetworkProxy::ProxyType proxyTypesMap[] = {
    40     QNetworkProxy::NoProxy
    42     QNetworkProxy::NoProxy
    41     , QNetworkProxy::NoProxy // dummy value
    43     , QNetworkProxy::NoProxy // dummy value
    50 
    52 
    51     setIniCodec("UTF-8");
    53     setIniCodec("UTF-8");
    52 
    54 
    53     connect(Form->ui.pageOptions->CBFrontendMusic, SIGNAL(toggled(bool)), Form, SLOT(Music(bool)));
    55     connect(Form->ui.pageOptions->CBFrontendMusic, SIGNAL(toggled(bool)), Form, SLOT(Music(bool)));
    54 
    56 
       
    57     for(int i = 0; i < BINDS_NUMBER; i++)
       
    58     {
       
    59         m_binds.append(BindAction());
       
    60         m_binds[i].action = cbinds[i].action;
       
    61         m_binds[i].strbind = cbinds[i].strbind;
       
    62     }
       
    63 
    55     //Form->resize(value("frontend/width", 640).toUInt(), value("frontend/height", 450).toUInt());
    64     //Form->resize(value("frontend/width", 640).toUInt(), value("frontend/height", 450).toUInt());
    56     resizeToConfigValues();
    65     resizeToConfigValues();
    57 
    66 
    58     reloadValues();
    67     reloadValues();
    59 #ifdef VIDEOREC
    68 #ifdef VIDEOREC
    63 
    72 
    64 void GameUIConfig::reloadValues(void)
    73 void GameUIConfig::reloadValues(void)
    65 {
    74 {
    66     Form->ui.pageOptions->WeaponTooltip->setChecked(value("misc/weaponTooltips", true).toBool());
    75     Form->ui.pageOptions->WeaponTooltip->setChecked(value("misc/weaponTooltips", true).toBool());
    67 
    76 
    68     int t = Form->ui.pageOptions->CBResolution->findText(value("video/resolution").toString());
    77     int t = Form->ui.pageOptions->CBResolution->findText(value("video/fullscreenResolution").toString());
    69     if (t < 0)
    78     if (t < 0)
    70     {
    79     {
    71         if (Form->ui.pageOptions->CBResolution->count() > 1)
    80         if (Form->ui.pageOptions->CBResolution->count() > 1)
    72             Form->ui.pageOptions->CBResolution->setCurrentIndex(1);
    81             Form->ui.pageOptions->CBResolution->setCurrentIndex(1);
    73         else
    82         else
    74             Form->ui.pageOptions->CBResolution->setCurrentIndex(0);
    83             Form->ui.pageOptions->CBResolution->setCurrentIndex(0);
    75     }
    84     }
    76     else Form->ui.pageOptions->CBResolution->setCurrentIndex(t);
    85     else Form->ui.pageOptions->CBResolution->setCurrentIndex(t);
       
    86     
       
    87     // Default the windowed resolution to 5/6 of the screen size
       
    88     int screenWidth = SDL_GetVideoInfo()->current_w * 5 / 6;
       
    89     int screenHeight = SDL_GetVideoInfo()->current_h * 5 / 6;
       
    90     QString widthStr; widthStr.setNum(screenWidth);
       
    91     QString heightStr; heightStr.setNum(screenHeight);
       
    92     QString wWidth = value("video/windowedWidth", widthStr).toString();
       
    93     QString wHeight = value("video/windowedHeight", heightStr).toString();
       
    94     // If left blank reset the resolution to the default
       
    95     wWidth = (wWidth == "" ? widthStr : wWidth);
       
    96     wHeight = (wHeight == "" ? heightStr : wHeight);
       
    97     Form->ui.pageOptions->windowWidthEdit->setText(wWidth);
       
    98     Form->ui.pageOptions->windowHeightEdit->setText(wHeight);
       
    99     
    77     Form->ui.pageOptions->CBResolution->setCurrentIndex((t < 0) ? 1 : t);
   100     Form->ui.pageOptions->CBResolution->setCurrentIndex((t < 0) ? 1 : t);
    78     Form->ui.pageOptions->CBFullscreen->setChecked(value("video/fullscreen", false).toBool());
   101     Form->ui.pageOptions->CBFullscreen->setChecked(value("video/fullscreen", false).toBool());
    79     bool ffscr=value("frontend/fullscreen", false).toBool();
   102     bool ffscr=value("frontend/fullscreen", false).toBool();
    80     Form->ui.pageOptions->CBFrontendFullscreen->setChecked(ffscr);
   103     Form->ui.pageOptions->CBFrontendFullscreen->setChecked(ffscr);
    81 
   104 
   128     Form->ui.pageOptions->leProxy->setText(value("proxy/host", "").toString());
   151     Form->ui.pageOptions->leProxy->setText(value("proxy/host", "").toString());
   129     Form->ui.pageOptions->sbProxyPort->setValue(value("proxy/port", "8080").toInt());
   152     Form->ui.pageOptions->sbProxyPort->setValue(value("proxy/port", "8080").toInt());
   130     Form->ui.pageOptions->leProxyLogin->setText(value("proxy/login", "").toString());
   153     Form->ui.pageOptions->leProxyLogin->setText(value("proxy/login", "").toString());
   131     Form->ui.pageOptions->leProxyPassword->setText(value("proxy/password", "").toString());
   154     Form->ui.pageOptions->leProxyPassword->setText(value("proxy/password", "").toString());
   132 
   155 
   133     depth = HWApplication::desktop()->depth();
       
   134     if (depth < 16) depth = 16;
       
   135     else if (depth > 16) depth = 32;
       
   136 
       
   137     { // load colors
   156     { // load colors
   138         QStandardItemModel * model = DataManager::instance().colorsModel();
   157         QStandardItemModel * model = DataManager::instance().colorsModel();
   139         for(int i = model->rowCount() - 1; i >= 0; --i)
   158         for(int i = model->rowCount() - 1; i >= 0; --i)
   140             model->item(i)->setData(QColor(value(QString("colors/color%1").arg(i), model->item(i)->data().value<QColor>()).value<QColor>()));
   159             model->item(i)->setData(QColor(value(QString("colors/color%1").arg(i), model->item(i)->data().value<QColor>()).value<QColor>()));
       
   160     }
       
   161 
       
   162     { // load binds
       
   163         QStandardItemModel * binds = DataManager::instance().bindsModel();
       
   164         for(int i = 0; i < BINDS_NUMBER; i++)
       
   165         {
       
   166             m_binds[i].strbind = value(QString("Binds/%1").arg(m_binds[i].action), cbinds[i].strbind).toString();
       
   167             if (m_binds[i].strbind.isEmpty() || m_binds[i].strbind == "default") m_binds[i].strbind = cbinds[i].strbind;
       
   168         }
   141     }
   169     }
   142 }
   170 }
   143 
   171 
   144 void GameUIConfig::reloadVideosValues(void)
   172 void GameUIConfig::reloadVideosValues(void)
   145 {
   173 {
   201     Form->move(center);
   229     Form->move(center);
   202 }
   230 }
   203 
   231 
   204 void GameUIConfig::SaveOptions()
   232 void GameUIConfig::SaveOptions()
   205 {
   233 {
   206     setValue("video/resolution", Form->ui.pageOptions->CBResolution->currentText());
   234     setValue("video/fullscreenResolution", Form->ui.pageOptions->CBResolution->currentText());
       
   235     setValue("video/windowedWidth", Form->ui.pageOptions->windowWidthEdit->text());
       
   236     setValue("video/windowedHeight", Form->ui.pageOptions->windowHeightEdit->text());
   207     setValue("video/fullscreen", vid_Fullscreen());
   237     setValue("video/fullscreen", vid_Fullscreen());
   208 
   238 
   209     setValue("video/quality", Form->ui.pageOptions->SLQuality->value());
   239     setValue("video/quality", Form->ui.pageOptions->SLQuality->value());
   210     setValue("video/stereo", stereoMode());
   240     setValue("video/stereo", stereoMode());
   211 
   241 
   321 QString GameUIConfig::language()
   351 QString GameUIConfig::language()
   322 {
   352 {
   323     return Form->ui.pageOptions->CBLanguage->itemData(Form->ui.pageOptions->CBLanguage->currentIndex()).toString();
   353     return Form->ui.pageOptions->CBLanguage->itemData(Form->ui.pageOptions->CBLanguage->currentIndex()).toString();
   324 }
   354 }
   325 
   355 
   326 QRect GameUIConfig::vid_Resolution()
   356 std::pair<QRect, QRect> GameUIConfig::vid_ResolutionPair() {
   327 {
   357     // returns a pair of both the fullscreen and the windowed resolution
   328     QRect result(0, 0, 640, 480);
   358     QRect full(0, 0, 640, 480);
       
   359     QRect windowed(0, 0, 640, 480);
   329     QStringList wh = Form->ui.pageOptions->CBResolution->currentText().split('x');
   360     QStringList wh = Form->ui.pageOptions->CBResolution->currentText().split('x');
   330     if (wh.size() == 2)
   361     if (wh.size() == 2)
   331     {
   362     {
   332         result.setWidth(wh[0].toInt());
   363         full.setWidth(wh[0].toInt());
   333         result.setHeight(wh[1].toInt());
   364         full.setHeight(wh[1].toInt());
   334     }
   365     }
   335     return result;
   366     windowed.setWidth(Form->ui.pageOptions->windowWidthEdit->text().toInt());
       
   367     windowed.setHeight(Form->ui.pageOptions->windowHeightEdit->text().toInt());
       
   368     return std::make_pair(full, windowed);
       
   369 }
       
   370 
       
   371 QRect GameUIConfig::vid_Resolution()
       
   372 {
       
   373     std::pair<QRect, QRect> result = vid_ResolutionPair();
       
   374     if(Form->ui.pageOptions->CBFullscreen->isChecked())
       
   375         return result.first;
       
   376     else 
       
   377         return result.second;
   336 }
   378 }
   337 
   379 
   338 bool GameUIConfig::vid_Fullscreen()
   380 bool GameUIConfig::vid_Fullscreen()
   339 {
   381 {
   340     return Form->ui.pageOptions->CBFullscreen->isChecked();
   382     return Form->ui.pageOptions->CBFullscreen->isChecked();
   447 quint8 GameUIConfig::timerInterval()
   489 quint8 GameUIConfig::timerInterval()
   448 {
   490 {
   449     return 35 - Form->ui.pageOptions->fpsedit->value();
   491     return 35 - Form->ui.pageOptions->fpsedit->value();
   450 }
   492 }
   451 
   493 
   452 quint8 GameUIConfig::bitDepth()
       
   453 {
       
   454     return depth;
       
   455 }
       
   456 
       
   457 QString GameUIConfig::netNick()
   494 QString GameUIConfig::netNick()
   458 {
   495 {
   459     return Form->ui.pageOptions->editNetNick->text();
   496     return Form->ui.pageOptions->editNetNick->text();
   460 }
   497 }
   461 
   498 
   588 
   625 
   589 bool GameUIConfig::recordAudio()
   626 bool GameUIConfig::recordAudio()
   590 {
   627 {
   591     return Form->ui.pageOptions->checkRecordAudio->isChecked();
   628     return Form->ui.pageOptions->checkRecordAudio->isChecked();
   592 }
   629 }
       
   630 
       
   631 // Gets a bind for a bindID
       
   632 QString GameUIConfig::bind(int bindID)
       
   633 {
       
   634     return m_binds[bindID].strbind;
       
   635 }
       
   636 
       
   637 // Sets a bind for a bindID and saves it
       
   638 void GameUIConfig::setBind(int bindID, QString & strbind)
       
   639 {
       
   640     m_binds[bindID].strbind = strbind;
       
   641     setValue(QString("Binds/%1").arg(m_binds[bindID].action), strbind);
       
   642 }