QTfrontend/pagenetgame.cpp
changeset 6060 fdfc01419815
parent 6059 ddf020d0941a
child 6061 15b4b485a1c5
equal deleted inserted replaced
6059:ddf020d0941a 6060:fdfc01419815
     1 /*
       
     2  * Hedgewars, a free turn based strategy game
       
     3  * Copyright (c) 2006-2011 Andrey Korotaev <unC0Rr@gmail.com>
       
     4  *
       
     5  * This program is free software; you can redistribute it and/or modify
       
     6  * it under the terms of the GNU General Public License as published by
       
     7  * the Free Software Foundation; version 2 of the License
       
     8  *
       
     9  * This program is distributed in the hope that it will be useful,
       
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12  * GNU General Public License for more details.
       
    13  *
       
    14  * You should have received a copy of the GNU General Public License
       
    15  * along with this program; if not, write to the Free Software
       
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
       
    17  */
       
    18 
       
    19 #include <QGridLayout>
       
    20 #include <QPushButton>
       
    21 #include <QAction>
       
    22 #include <QMenu>
       
    23 #include <QMessageBox>
       
    24 
       
    25 #include "pagenetgame.h"
       
    26 #include "gamecfgwidget.h"
       
    27 #include "teamselect.h"
       
    28 #include "chatwidget.h"
       
    29 
       
    30 QLayout * PageNetGame::bodyLayoutDefinition()
       
    31 {
       
    32     QGridLayout * pageLayout = new QGridLayout();
       
    33     pageLayout->setSizeConstraint(QLayout::SetMinimumSize);
       
    34     //pageLayout->setSpacing(1);
       
    35     pageLayout->setColumnStretch(0, 50);
       
    36     pageLayout->setColumnStretch(1, 50);
       
    37 
       
    38     // chatwidget
       
    39     pChatWidget = new HWChatWidget(this, m_gameSettings, m_sdli, true);
       
    40     pChatWidget->setShowReady(true); // show status bulbs by default
       
    41     pChatWidget->setShowFollow(false); // don't show follow in nicks' context menus
       
    42     pageLayout->addWidget(pChatWidget, 2, 0, 1, 2);
       
    43     pageLayout->setRowStretch(1, 100);
       
    44     pageLayout->setRowStretch(2, 100);
       
    45 
       
    46     pGameCFG = new GameCFGWidget(this);
       
    47     pageLayout->addWidget(pGameCFG, 0, 0);
       
    48 
       
    49     btnSetup = new QPushButton(this);
       
    50     btnSetup->setText(QPushButton::tr("Setup"));
       
    51     pageLayout->addWidget(btnSetup, 1, 0);
       
    52 
       
    53     pNetTeamsWidget = new TeamSelWidget(this);
       
    54     pNetTeamsWidget->setAcceptOuter(true);
       
    55     pageLayout->addWidget(pNetTeamsWidget, 0, 1, 2, 1);
       
    56 
       
    57     return pageLayout;
       
    58 }
       
    59 
       
    60 QLayout * PageNetGame::footerLayoutDefinition()
       
    61 {
       
    62     QHBoxLayout * bottomLayout = new QHBoxLayout;
       
    63 
       
    64     leRoomName = new QLineEdit(this);
       
    65     leRoomName->setMaxLength(60);
       
    66     leRoomName->setMinimumWidth(200);
       
    67     leRoomName->setMaximumWidth(400);
       
    68 
       
    69     BtnGo = new QPushButton(this);
       
    70     BtnGo->setToolTip(QPushButton::tr("Ready"));
       
    71     BtnGo->setIcon(QIcon(":/res/lightbulb_off.png"));
       
    72     BtnGo->setIconSize(QSize(25, 34));
       
    73     BtnGo->setMinimumWidth(50);
       
    74     BtnGo->setMinimumHeight(50);
       
    75 
       
    76 
       
    77     bottomLayout->addWidget(leRoomName);
       
    78     BtnUpdate = addButton(QAction::tr("Update"), bottomLayout, 1, false);
       
    79     bottomLayout->addWidget(BtnGo);
       
    80 
       
    81     BtnMaster = addButton(tr("Control"), bottomLayout, 3);
       
    82     bottomLayout->insertStretch(3, 100);
       
    83 
       
    84     BtnStart = addButton(QAction::tr("Start"), bottomLayout, 3);
       
    85 
       
    86     return bottomLayout;
       
    87 }
       
    88 
       
    89 void PageNetGame::connectSignals()
       
    90 {
       
    91     connect(btnSetup, SIGNAL(clicked()), this, SIGNAL(SetupClicked()));
       
    92 
       
    93     connect(BtnUpdate, SIGNAL(clicked()), this, SLOT(onUpdateClick()));
       
    94 }
       
    95 
       
    96 PageNetGame::PageNetGame(QWidget* parent, QSettings * gameSettings, SDLInteraction * sdli) : AbstractPage(parent)
       
    97 {
       
    98     m_gameSettings = gameSettings;
       
    99     m_sdli = sdli;
       
   100 
       
   101     initPage();
       
   102 
       
   103     QMenu * menu = new QMenu(BtnMaster);
       
   104 
       
   105     restrictJoins = new QAction(QAction::tr("Restrict Joins"), menu);
       
   106     restrictJoins->setCheckable(true);
       
   107     restrictTeamAdds = new QAction(QAction::tr("Restrict Team Additions"), menu);
       
   108     restrictTeamAdds->setCheckable(true);
       
   109     //menu->addAction(startGame);
       
   110     menu->addAction(restrictJoins);
       
   111     menu->addAction(restrictTeamAdds);
       
   112 
       
   113     BtnMaster->setMenu(menu);
       
   114 
       
   115 }
       
   116 
       
   117 void PageNetGame::setReadyStatus(bool isReady)
       
   118 {
       
   119     if(isReady)
       
   120         BtnGo->setIcon(QIcon(":/res/lightbulb_on.png"));
       
   121     else
       
   122         BtnGo->setIcon(QIcon(":/res/lightbulb_off.png"));
       
   123 }
       
   124 
       
   125 void PageNetGame::onUpdateClick()
       
   126 {
       
   127     if (leRoomName->text().size())
       
   128         emit askForUpdateRoomName(leRoomName->text());
       
   129     else
       
   130         QMessageBox::critical(this,
       
   131                 tr("Error"),
       
   132                 tr("Please enter room name"),
       
   133                 tr("OK"));
       
   134 }
       
   135 
       
   136 void PageNetGame::setMasterMode(bool isMaster)
       
   137 {
       
   138     BtnMaster->setVisible(isMaster);
       
   139     BtnStart->setVisible(isMaster);
       
   140     BtnUpdate->setVisible(isMaster);
       
   141     leRoomName->setVisible(isMaster);
       
   142 }