QTfrontend/pageroomslist.cpp
changeset 6042 8b5345758f62
parent 6009 14f6fc9869f2
equal deleted inserted replaced
6040:a740069c21e3 6042:8b5345758f62
    28 #include "ammoSchemeModel.h"
    28 #include "ammoSchemeModel.h"
    29 #include "pageroomslist.h"
    29 #include "pageroomslist.h"
    30 #include "hwconsts.h"
    30 #include "hwconsts.h"
    31 #include "chatwidget.h"
    31 #include "chatwidget.h"
    32 
    32 
    33 PageRoomsList::PageRoomsList(QWidget* parent, QSettings * gameSettings, SDLInteraction * sdli) :
    33 QLayout * PageRoomsList::bodyLayoutDefinition()
    34   AbstractPage(parent)
    34 {
    35 {
    35     QGridLayout * pageLayout = new QGridLayout();
    36     QGridLayout * pageLayout = new QGridLayout(this);
       
    37 
    36 
    38     QHBoxLayout * newRoomLayout = new QHBoxLayout();
    37     QHBoxLayout * newRoomLayout = new QHBoxLayout();
    39     QLabel * roomNameLabel = new QLabel(this);
    38     QLabel * roomNameLabel = new QLabel(this);
    40     roomNameLabel->setText(tr("Room Name:"));
    39     roomNameLabel->setText(tr("Room Name:"));
    41     roomName = new QLineEdit(this);
    40     roomName = new QLineEdit(this);
    55     pageLayout->setRowStretch(2, 100);
    54     pageLayout->setRowStretch(2, 100);
    56 
    55 
    57     QHBoxLayout * filterLayout = new QHBoxLayout();
    56     QHBoxLayout * filterLayout = new QHBoxLayout();
    58 
    57 
    59     QLabel * stateLabel = new QLabel(this);
    58     QLabel * stateLabel = new QLabel(this);
    60     stateLabel->setText(tr("State:"));
       
    61     CBState = new QComboBox(this);
    59     CBState = new QComboBox(this);
    62     CBState->addItem(QComboBox::tr("Any"));
    60 
    63     CBState->addItem(QComboBox::tr("In lobby"));
       
    64     CBState->addItem(QComboBox::tr("In progress"));
       
    65     filterLayout->addWidget(stateLabel);
    61     filterLayout->addWidget(stateLabel);
    66     filterLayout->addWidget(CBState);
    62     filterLayout->addWidget(CBState);
    67     filterLayout->addSpacing(30);
    63     filterLayout->addSpacing(30);
    68 
    64 
    69     QLabel * ruleLabel = new QLabel(this);
    65     QLabel * ruleLabel = new QLabel(this);
    70     ruleLabel->setText(tr("Rules:"));
    66     ruleLabel->setText(tr("Rules:"));
    71     CBRules = new QComboBox(this);
    67     CBRules = new QComboBox(this);
    72     CBRules->addItem(QComboBox::tr("Any"));
    68 
    73     // not the most elegant solution but it works
       
    74     ammoSchemeModel = new AmmoSchemeModel(this, NULL);
       
    75     for (int i = 0; i < ammoSchemeModel->predefSchemesNames.count(); i++)
       
    76         CBRules->addItem(ammoSchemeModel->predefSchemesNames.at(i).toAscii().constData());
       
    77     filterLayout->addWidget(ruleLabel);
    69     filterLayout->addWidget(ruleLabel);
    78     filterLayout->addWidget(CBRules);
    70     filterLayout->addWidget(CBRules);
    79     filterLayout->addSpacing(30);
    71     filterLayout->addSpacing(30);
    80 
    72 
    81     QLabel * weaponLabel = new QLabel(this);
    73     QLabel * weaponLabel = new QLabel(this);
    82     weaponLabel->setText(tr("Weapons:"));
    74     weaponLabel->setText(tr("Weapons:"));
    83     CBWeapons = new QComboBox(this);
    75     CBWeapons = new QComboBox(this);
    84     CBWeapons->addItem(QComboBox::tr("Any"));
    76 
    85     for (int i = 0; i < cDefaultAmmos.count(); i++) {
       
    86         QPair<QString,QString> ammo = cDefaultAmmos.at(i);
       
    87         CBWeapons->addItem(ammo.first.toAscii().constData());
       
    88     }
       
    89     filterLayout->addWidget(weaponLabel);
    77     filterLayout->addWidget(weaponLabel);
    90     filterLayout->addWidget(CBWeapons);
    78     filterLayout->addWidget(CBWeapons);
    91     filterLayout->addSpacing(30);
    79     filterLayout->addSpacing(30);
    92 
    80 
    93     QLabel * searchLabel = new QLabel(this);
    81     QLabel * searchLabel = new QLabel(this);
    97     filterLayout->addWidget(searchLabel);
    85     filterLayout->addWidget(searchLabel);
    98     filterLayout->addWidget(searchText);
    86     filterLayout->addWidget(searchText);
    99 
    87 
   100     pageLayout->addLayout(filterLayout, 4, 0, 1, 2);
    88     pageLayout->addLayout(filterLayout, 4, 0, 1, 2);
   101 
    89 
   102     chatWidget = new HWChatWidget(this, gameSettings, sdli, false);
    90     chatWidget = new HWChatWidget(this, m_gameSettings, m_sdli, false);
   103     pageLayout->addWidget(chatWidget, 5, 0, 1, 3);
    91     pageLayout->addWidget(chatWidget, 5, 0, 1, 3);
   104     pageLayout->setRowStretch(5, 350);
    92     pageLayout->setRowStretch(5, 350);
   105 
    93 
   106     BtnCreate = addButton(tr("Create"), pageLayout, 0, 2);
    94     BtnCreate = addButton(tr("Create"), pageLayout, 0, 2);
   107     BtnJoin = addButton(tr("Join"), pageLayout, 1, 2);
    95     BtnJoin = addButton(tr("Join"), pageLayout, 1, 2);
   108     BtnRefresh = addButton(tr("Refresh"), pageLayout, 3, 2);
    96     BtnRefresh = addButton(tr("Refresh"), pageLayout, 3, 2);
   109     BtnClear = addButton(tr("Clear"), pageLayout, 4, 2);
    97     BtnClear = addButton(tr("Clear"), pageLayout, 4, 2);
   110 
    98 
   111 
    99     CBRules->addItem(QComboBox::tr("Any"));
   112     BtnBack = addButton(":/res/Exit.png", pageLayout, 6, 0, true);
   100     CBState->addItem(QComboBox::tr("Any"));
   113     connect(BtnBack, SIGNAL(clicked()), this, SIGNAL(goBack()));
   101     CBState->addItem(QComboBox::tr("In lobby"));
   114 
   102     CBState->addItem(QComboBox::tr("In progress"));
       
   103 
       
   104     return pageLayout;
       
   105 }
       
   106 
       
   107 QLayout * PageRoomsList::footerLayoutDefinition()
       
   108 {
       
   109     QGridLayout * bottomLayout = new QGridLayout();
   115 
   110 
   116     lblCount = new QLabel(this);
   111     lblCount = new QLabel(this);
   117     pageLayout->addWidget(lblCount, 6, 1, Qt::AlignHCenter);
   112     bottomLayout->addWidget(lblCount, 0, 0, Qt::AlignHCenter);
   118     lblCount->setText("?");
   113     lblCount->setText("?");
   119     lblCount->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
   114     lblCount->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
   120 
   115 
       
   116     BtnAdmin = addButton(tr("Admin features"), bottomLayout, 6, 2);
       
   117 
       
   118     return bottomLayout;
       
   119 }
       
   120 
       
   121 void PageRoomsList::connectSignals()
       
   122 {
   121     connect(chatWidget, SIGNAL(nickCountUpdate(const int)), this, SLOT(updateNickCounter(const int)));
   123     connect(chatWidget, SIGNAL(nickCountUpdate(const int)), this, SLOT(updateNickCounter(const int)));
   122 
       
   123     BtnAdmin = addButton(tr("Admin features"), pageLayout, 6, 2);
       
   124 
   124 
   125     connect(BtnCreate, SIGNAL(clicked()), this, SLOT(onCreateClick()));
   125     connect(BtnCreate, SIGNAL(clicked()), this, SLOT(onCreateClick()));
   126     connect(BtnJoin, SIGNAL(clicked()), this, SLOT(onJoinClick()));
   126     connect(BtnJoin, SIGNAL(clicked()), this, SLOT(onJoinClick()));
   127     connect(BtnRefresh, SIGNAL(clicked()), this, SLOT(onRefreshClick()));
   127     connect(BtnRefresh, SIGNAL(clicked()), this, SLOT(onRefreshClick()));
   128     connect(BtnClear, SIGNAL(clicked()), this, SLOT(onClearClick()));
   128     connect(BtnClear, SIGNAL(clicked()), this, SLOT(onClearClick()));
   130     connect(CBState, SIGNAL(currentIndexChanged (int)), this, SLOT(onRefreshClick()));
   130     connect(CBState, SIGNAL(currentIndexChanged (int)), this, SLOT(onRefreshClick()));
   131     connect(CBRules, SIGNAL(currentIndexChanged (int)), this, SLOT(onRefreshClick()));
   131     connect(CBRules, SIGNAL(currentIndexChanged (int)), this, SLOT(onRefreshClick()));
   132     connect(CBWeapons, SIGNAL(currentIndexChanged (int)), this, SLOT(onRefreshClick()));
   132     connect(CBWeapons, SIGNAL(currentIndexChanged (int)), this, SLOT(onRefreshClick()));
   133     connect(searchText, SIGNAL(textChanged (const QString &)), this, SLOT(onRefreshClick()));
   133     connect(searchText, SIGNAL(textChanged (const QString &)), this, SLOT(onRefreshClick()));
   134     connect(this, SIGNAL(askJoinConfirmation (const QString &)), this, SLOT(onJoinConfirmation(const QString &)), Qt::QueuedConnection);
   134     connect(this, SIGNAL(askJoinConfirmation (const QString &)), this, SLOT(onJoinConfirmation(const QString &)), Qt::QueuedConnection);
       
   135 }
       
   136 
       
   137 
       
   138 PageRoomsList::PageRoomsList(QWidget* parent, QSettings * gameSettings, SDLInteraction * sdli) :
       
   139   AbstractPage(parent)
       
   140 {
       
   141     m_gameSettings = gameSettings;
       
   142     m_sdli = sdli;
       
   143 
       
   144     initPage();
       
   145 
       
   146     // not the most elegant solution but it works
       
   147     ammoSchemeModel = new AmmoSchemeModel(this, NULL);
       
   148     for (int i = 0; i < ammoSchemeModel->predefSchemesNames.count(); i++)
       
   149         CBRules->addItem(ammoSchemeModel->predefSchemesNames.at(i).toAscii().constData());
       
   150 
       
   151     CBWeapons->addItem(QComboBox::tr("Any"));
       
   152     for (int i = 0; i < cDefaultAmmos.count(); i++) {
       
   153         QPair<QString,QString> ammo = cDefaultAmmos.at(i);
       
   154         CBWeapons->addItem(ammo.first.toAscii().constData());
       
   155     }
   135 
   156 
   136     gameInLobby = false;
   157     gameInLobby = false;
   137 }
   158 }
   138 
   159 
   139 void PageRoomsList::setAdmin(bool flag)
   160 void PageRoomsList::setAdmin(bool flag)
   394 
   415 
   395 void PageRoomsList::updateNickCounter(int cnt)
   416 void PageRoomsList::updateNickCounter(int cnt)
   396 {
   417 {
   397     lblCount->setText(tr("%1 players online", 0, cnt).arg(cnt));
   418     lblCount->setText(tr("%1 players online", 0, cnt).arg(cnt));
   398 }
   419 }
   399