QTfrontend/pagenetgame.cpp
branchhedgeroid
changeset 6224 42b256eca362
parent 6055 88cfcd9161d3
parent 6223 cc3eb9b7230f
child 6226 3106add9a5bf
equal deleted inserted replaced
6055:88cfcd9161d3 6224:42b256eca362
     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 PageNetGame::PageNetGame(QWidget* parent, QSettings * gameSettings, SDLInteraction * sdli) : AbstractPage(parent)
       
    31 {
       
    32     QGridLayout * pageLayout = new QGridLayout(this);
       
    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, gameSettings, 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     QPushButton * btnSetup = new QPushButton(this);
       
    50     btnSetup->setText(QPushButton::tr("Setup"));
       
    51     connect(btnSetup, SIGNAL(clicked()), this, SIGNAL(SetupClicked()));
       
    52     pageLayout->addWidget(btnSetup, 1, 0);
       
    53 
       
    54     pNetTeamsWidget = new TeamSelWidget(this);
       
    55     pNetTeamsWidget->setAcceptOuter(true);
       
    56     pageLayout->addWidget(pNetTeamsWidget, 0, 1, 2, 1);
       
    57 
       
    58 
       
    59     QHBoxLayout * bottomLayout = new QHBoxLayout;
       
    60     pageLayout->addLayout(bottomLayout, 4, 0, 1, 2);
       
    61 
       
    62 
       
    63     BtnBack = addButton(":/res/Exit.png", bottomLayout, 0, true);
       
    64     connect(BtnBack, SIGNAL(clicked()), this, SIGNAL(goBack()));
       
    65 
       
    66 
       
    67     leRoomName = new QLineEdit(this);
       
    68     leRoomName->setMaxLength(60);
       
    69     leRoomName->setMinimumWidth(200);
       
    70     leRoomName->setMaximumWidth(400);
       
    71     bottomLayout->addWidget(leRoomName, 8,0);
       
    72     BtnUpdate = addButton(QAction::tr("Update"), bottomLayout, 1, false);
       
    73 
       
    74     BtnGo = new QPushButton(this);
       
    75     BtnGo->setToolTip(QPushButton::tr("Ready"));
       
    76     BtnGo->setIcon(QIcon(":/res/lightbulb_off.png"));
       
    77     BtnGo->setIconSize(QSize(25, 34));
       
    78     BtnGo->setMinimumWidth(50);
       
    79     BtnGo->setMinimumHeight(50);
       
    80     bottomLayout->addWidget(BtnGo, 4);
       
    81 
       
    82 
       
    83     BtnMaster = addButton(tr("Control"), bottomLayout, 2);
       
    84     QMenu * menu = new QMenu(BtnMaster);
       
    85     restrictJoins = new QAction(QAction::tr("Restrict Joins"), menu);
       
    86     restrictJoins->setCheckable(true);
       
    87     restrictTeamAdds = new QAction(QAction::tr("Restrict Team Additions"), menu);
       
    88     restrictTeamAdds->setCheckable(true);
       
    89     //menu->addAction(startGame);
       
    90     menu->addAction(restrictJoins);
       
    91     menu->addAction(restrictTeamAdds);
       
    92 
       
    93     BtnMaster->setMenu(menu);
       
    94 
       
    95     BtnStart = addButton(QAction::tr("Start"), bottomLayout, 3);
       
    96 
       
    97     bottomLayout->insertStretch(3, 100);
       
    98 
       
    99     connect(BtnUpdate, SIGNAL(clicked()), this, SLOT(onUpdateClick()));
       
   100 }
       
   101 
       
   102 void PageNetGame::setReadyStatus(bool isReady)
       
   103 {
       
   104     if(isReady)
       
   105         BtnGo->setIcon(QIcon(":/res/lightbulb_on.png"));
       
   106     else
       
   107         BtnGo->setIcon(QIcon(":/res/lightbulb_off.png"));
       
   108 }
       
   109 
       
   110 void PageNetGame::onUpdateClick()
       
   111 {
       
   112     if (leRoomName->text().size())
       
   113         emit askForUpdateRoomName(leRoomName->text());
       
   114     else
       
   115         QMessageBox::critical(this,
       
   116                 tr("Error"),
       
   117                 tr("Please enter room name"),
       
   118                 tr("OK"));
       
   119 }
       
   120 
       
   121 void PageNetGame::setMasterMode(bool isMaster)
       
   122 {
       
   123     BtnMaster->setVisible(isMaster);
       
   124     BtnStart->setVisible(isMaster);
       
   125     BtnUpdate->setVisible(isMaster);
       
   126     leRoomName->setVisible(isMaster);
       
   127 }