QTfrontend/ui/page/pagenetgame.cpp
branchwebgl
changeset 8444 75db7bb8dce8
parent 8434 4821897a0f10
child 8453 06541556df53
equal deleted inserted replaced
8340:46a9fde631f4 8444:75db7bb8dce8
    26 #include "pagenetgame.h"
    26 #include "pagenetgame.h"
    27 #include "gamecfgwidget.h"
    27 #include "gamecfgwidget.h"
    28 #include "teamselect.h"
    28 #include "teamselect.h"
    29 #include "chatwidget.h"
    29 #include "chatwidget.h"
    30 
    30 
       
    31 const int cutoffHeight = 688; /* Don't make this number below 605, or else it'll
       
    32                                  let the GameCFGWidget shrink too much before switching to tabbed mode. */
       
    33 
    31 QLayout * PageNetGame::bodyLayoutDefinition()
    34 QLayout * PageNetGame::bodyLayoutDefinition()
    32 {
    35 {
    33     QGridLayout * pageLayout = new QGridLayout();
    36     QGridLayout * pageLayout = new QGridLayout();
    34     pageLayout->setSizeConstraint(QLayout::SetMinimumSize);
    37     pageLayout->setSizeConstraint(QLayout::SetMinimumSize);
    35     //pageLayout->setSpacing(1);
    38     pageLayout->setColumnStretch(0, 1);
    36     pageLayout->setColumnStretch(0, 50);
    39     pageLayout->setColumnStretch(1, 1);
    37     pageLayout->setColumnStretch(1, 50);
    40     pageLayout->setRowStretch(0, 0);
    38 
    41     pageLayout->setRowStretch(1, 0);
    39     // chatwidget
    42     pageLayout->setRowStretch(2, 1);
       
    43 
       
    44     // Room config
       
    45 
       
    46     QHBoxLayout * roomConfigLayout = new QHBoxLayout();
       
    47     pageLayout->addLayout(roomConfigLayout, 0, 0, 1, 2);
       
    48     roomConfigLayout->setSpacing(0);
       
    49 
       
    50     leRoomName = new HistoryLineEdit(this, 10);
       
    51     leRoomName->setMaxLength(60);
       
    52     leRoomName->setMinimumWidth(400);
       
    53     leRoomName->setMaximumWidth(600);
       
    54     leRoomName->setFixedHeight(30);
       
    55     leRoomName->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
       
    56     roomConfigLayout->addWidget(leRoomName, 100);
       
    57 
       
    58     QLabel * lblRoomName = new QLabel(tr("Room name: "), leRoomName);
       
    59     lblRoomName->setStyleSheet("font: 12px; font-weight: bold;");
       
    60     lblRoomName->setStyleSheet(QString("font: 12px; font-weight: bold; background: none; margin-left: -%1px; margin-top: 8px;").arg(lblRoomName->width() - 20));
       
    61     leRoomName->setStyleSheet(QString("font: 12px; border-right: 0; padding-left: %1px; padding-bottom: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px;").arg(lblRoomName->width() - 14));
       
    62 
       
    63     BtnUpdate = new QPushButton();
       
    64     BtnUpdate->setEnabled(false);
       
    65     BtnUpdate->setText(tr("Update"));
       
    66     BtnUpdate->setFixedHeight(leRoomName->height() - 0);
       
    67     BtnUpdate->setStyleSheet("border-top-left-radius: 0px; border-bottom-left-radius: 0px; padding: auto 4px;");
       
    68     roomConfigLayout->addWidget(BtnUpdate, 0);
       
    69 
       
    70     lblRoomNameReadOnly = new QLabel();
       
    71     lblRoomNameReadOnly->setMinimumWidth(400);
       
    72     lblRoomNameReadOnly->setMaximumWidth(600);
       
    73     lblRoomNameReadOnly->setFixedHeight(30);
       
    74     lblRoomNameReadOnly->setObjectName("labelLikeLineEdit");
       
    75     lblRoomNameReadOnly->setStyleSheet("font: 12px;");
       
    76     lblRoomNameReadOnly->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
       
    77     lblRoomNameReadOnly->setVisible(false);
       
    78     roomConfigLayout->addWidget(lblRoomNameReadOnly, 100);
       
    79 
       
    80     roomConfigLayout->addSpacing(10);
       
    81 
       
    82     BtnMaster = new QPushButton();
       
    83     BtnMaster->setText(tr("Room controls"));
       
    84     BtnMaster->setFixedHeight(leRoomName->height() - 0);
       
    85     BtnMaster->setStyleSheet("QPushButton { padding: auto 4px; } QPushButton:pressed { background-color: #ffcc00; border-color: #ffcc00; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; color: #11084A; }");
       
    86     roomConfigLayout->addWidget(BtnMaster, 0);
       
    87 
       
    88     roomConfigLayout->addStretch(1);
       
    89 
       
    90     // Game config
       
    91 
       
    92     pGameCFG = new GameCFGWidget(this);
       
    93     pageLayout->addWidget(pGameCFG, 1, 0);
       
    94 
       
    95     // Teams
       
    96 
       
    97     pNetTeamsWidget = new TeamSelWidget(this);
       
    98     pNetTeamsWidget->setAcceptOuter(true);
       
    99     pNetTeamsWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
       
   100     pageLayout->addWidget(pNetTeamsWidget, 1, 1);
       
   101 
       
   102     // Chat
       
   103 
    40     chatWidget = new HWChatWidget(this, true);
   104     chatWidget = new HWChatWidget(this, true);
    41     chatWidget->setShowFollow(false); // don't show follow in nicks' context menus
   105     chatWidget->setShowFollow(false); // don't show follow in nicks' context menus
    42     chatWidget->setIgnoreListKick(true); // kick ignored players automatically
   106     chatWidget->setIgnoreListKick(true); // kick ignored players automatically
       
   107     chatWidget->setMinimumHeight(50);
       
   108     chatWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
    43     pageLayout->addWidget(chatWidget, 2, 0, 1, 2);
   109     pageLayout->addWidget(chatWidget, 2, 0, 1, 2);
    44     pageLayout->setRowStretch(1, 100);
       
    45     pageLayout->setRowStretch(2, 100);
       
    46 
       
    47     pGameCFG = new GameCFGWidget(this);
       
    48     pageLayout->addWidget(pGameCFG, 0, 0);
       
    49 
       
    50     btnSetup = new QPushButton(this);
       
    51     btnSetup->setText(QPushButton::tr("Setup"));
       
    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 
   110 
    58     return pageLayout;
   111     return pageLayout;
    59 }
   112 }
    60 
   113 
       
   114 QLayout * PageNetGame::footerLayoutLeftDefinition()
       
   115 {
       
   116     QHBoxLayout * bottomLeftLayout = new QHBoxLayout();
       
   117 
       
   118     btnSetup = addButton(":/res/Settings.png", bottomLeftLayout, 0, true);
       
   119     btnSetup->setWhatsThis(tr("Edit game preferences"));
       
   120 
       
   121     return bottomLeftLayout;
       
   122 }
       
   123 
    61 QLayout * PageNetGame::footerLayoutDefinition()
   124 QLayout * PageNetGame::footerLayoutDefinition()
    62 {
   125 {
    63     QHBoxLayout * bottomLayout = new QHBoxLayout;
   126     QHBoxLayout * bottomLayout = new QHBoxLayout;
    64 
   127 
    65     leRoomName = new HistoryLineEdit(this,10);
   128     // Ready button
    66     leRoomName->setMaxLength(60);
   129 
    67     leRoomName->setMinimumWidth(200);
       
    68     leRoomName->setMaximumWidth(400);
       
    69 
       
    70     //Button to signify whether the player is ready to start playing
       
    71     BtnGo = new QPushButton(this);
   130     BtnGo = new QPushButton(this);
    72     BtnGo->setToolTip(QPushButton::tr("Ready"));
       
    73     BtnGo->setIcon(QIcon(":/res/lightbulb_off.png"));
   131     BtnGo->setIcon(QIcon(":/res/lightbulb_off.png"));
    74     BtnGo->setIconSize(QSize(25, 34));
   132     BtnGo->setIconSize(QSize(25, 34));
    75     BtnGo->setMinimumWidth(50);
   133     BtnGo->setMinimumWidth(50);
    76     BtnGo->setMinimumHeight(50);
   134     BtnGo->setMinimumHeight(50);
    77 
   135 
    78     bottomLayout->addWidget(leRoomName);
       
    79     BtnUpdate = addButton(QAction::tr("Update"), bottomLayout, 1);
       
    80 
       
    81     bottomLayout->addStretch();
   136     bottomLayout->addStretch();
    82     bottomLayout->addWidget(BtnGo);
   137     bottomLayout->addWidget(BtnGo);
    83 
   138 
    84     BtnMaster = addButton(tr("Control"), bottomLayout, 3);
   139     // Start button
    85     bottomLayout->insertStretch(3, 100);
   140 
    86 
   141     const QIcon& lp = QIcon(":/res/Start.png");
    87     BtnStart = addButton(QAction::tr("Start"), bottomLayout, 3);
   142     QSize sz = lp.actualSize(QSize(65535, 65535));
       
   143     BtnStart = new QPushButton();
       
   144     BtnStart->setText(tr("Start"));
       
   145     BtnStart->setMinimumWidth(sz.width() + 60);
       
   146     BtnStart->setIcon(lp);
       
   147     BtnStart->setFixedHeight(50);
       
   148     BtnStart->setIconSize(sz);
       
   149     BtnStart->setFlat(true);
       
   150     BtnStart->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
       
   151     bottomLayout->addWidget(BtnStart);
    88 
   152 
    89     return bottomLayout;
   153     return bottomLayout;
    90 }
   154 }
    91 
   155 
    92 void PageNetGame::connectSignals()
   156 void PageNetGame::connectSignals()
    93 {
   157 {
    94     connect(btnSetup, SIGNAL(clicked()), this, SIGNAL(SetupClicked()));
   158     connect(btnSetup, SIGNAL(clicked()), this, SIGNAL(SetupClicked()));
    95 
   159 
    96     connect(BtnUpdate, SIGNAL(clicked()), this, SLOT(onUpdateClick()));
   160     connect(BtnUpdate, SIGNAL(clicked()), this, SLOT(onUpdateClick()));
       
   161     connect(leRoomName, SIGNAL(returnPressed()), this, SLOT(onUpdateClick()));
       
   162 
       
   163     connect(leRoomName, SIGNAL(textChanged(const QString &)), this, SLOT(onRoomNameEdited()));
    97 }
   164 }
    98 
   165 
    99 PageNetGame::PageNetGame(QWidget* parent) : AbstractPage(parent)
   166 PageNetGame::PageNetGame(QWidget* parent) : AbstractPage(parent)
   100 {
   167 {
   101     initPage();
   168     initPage();
   104 
   171 
   105     restrictJoins = new QAction(QAction::tr("Restrict Joins"), menu);
   172     restrictJoins = new QAction(QAction::tr("Restrict Joins"), menu);
   106     restrictJoins->setCheckable(true);
   173     restrictJoins->setCheckable(true);
   107     restrictTeamAdds = new QAction(QAction::tr("Restrict Team Additions"), menu);
   174     restrictTeamAdds = new QAction(QAction::tr("Restrict Team Additions"), menu);
   108     restrictTeamAdds->setCheckable(true);
   175     restrictTeamAdds->setCheckable(true);
   109     //menu->addAction(startGame);
       
   110     menu->addAction(restrictJoins);
   176     menu->addAction(restrictJoins);
   111     menu->addAction(restrictTeamAdds);
   177     menu->addAction(restrictTeamAdds);
   112 
   178 
   113     BtnMaster->setMenu(menu);
   179     BtnMaster->setMenu(menu);
   114 }
   180 
   115 
   181     if (height() < cutoffHeight)
       
   182         pGameCFG->setTabbed(true);
       
   183 }
       
   184 
       
   185 void PageNetGame::resizeEvent(QResizeEvent * event)
       
   186 {
       
   187     int oldHeight = event->oldSize().height();
       
   188     int newHeight = event->size().height();
       
   189 
       
   190     if (newHeight < cutoffHeight && oldHeight >= cutoffHeight)
       
   191         pGameCFG->setTabbed(true);
       
   192     else if (newHeight >= cutoffHeight && oldHeight < cutoffHeight)
       
   193         pGameCFG->setTabbed(false);
       
   194 }
   116 
   195 
   117 void PageNetGame::displayError(const QString & message)
   196 void PageNetGame::displayError(const QString & message)
   118 {
   197 {
   119     chatWidget->displayError(message);
   198     chatWidget->displayError(message);
   120 }
   199 }
   137         BtnGo->setIcon(QIcon(":/res/lightbulb_on.png"));
   216         BtnGo->setIcon(QIcon(":/res/lightbulb_on.png"));
   138     else
   217     else
   139         BtnGo->setIcon(QIcon(":/res/lightbulb_off.png"));
   218         BtnGo->setIcon(QIcon(":/res/lightbulb_off.png"));
   140 }
   219 }
   141 
   220 
       
   221 void PageNetGame::onRoomNameEdited()
       
   222 {
       
   223     BtnUpdate->setEnabled(true);
       
   224 }
       
   225 
   142 void PageNetGame::onUpdateClick()
   226 void PageNetGame::onUpdateClick()
   143 {
   227 {
   144     if (!leRoomName->text().trimmed().isEmpty())
   228     if (!leRoomName->text().trimmed().isEmpty())
   145     {
   229     {
   146         emit askForUpdateRoomName(leRoomName->text());
   230         emit askForUpdateRoomName(leRoomName->text());
   147         leRoomName->rememberCurrentText();
   231         leRoomName->rememberCurrentText();
       
   232         BtnUpdate->setEnabled(false);
   148     }
   233     }
   149     else
   234     else
   150     {
   235     {
   151         leRoomName->clear();
   236         leRoomName->clear();
   152         QMessageBox roomMsg(this);
   237         QMessageBox roomMsg(this);
   161 
   246 
   162 void PageNetGame::setRoomName(const QString & roomName)
   247 void PageNetGame::setRoomName(const QString & roomName)
   163 {
   248 {
   164     leRoomName->setText(roomName);
   249     leRoomName->setText(roomName);
   165     leRoomName->rememberCurrentText();
   250     leRoomName->rememberCurrentText();
       
   251     lblRoomNameReadOnly->setText(roomName);
       
   252     BtnUpdate->setEnabled(false);
   166 }
   253 }
   167 
   254 
   168 void PageNetGame::setMasterMode(bool isMaster)
   255 void PageNetGame::setMasterMode(bool isMaster)
   169 {
   256 {
   170     BtnMaster->setVisible(isMaster);
   257     BtnMaster->setVisible(isMaster);
   171     BtnStart->setVisible(isMaster);
   258     BtnStart->setVisible(isMaster);
   172     BtnUpdate->setVisible(isMaster);
   259     BtnUpdate->setVisible(isMaster);
   173     leRoomName->setVisible(isMaster);
   260     leRoomName->setVisible(isMaster);
       
   261     lblRoomNameReadOnly->setVisible(!isMaster);
   174 }
   262 }
   175 
   263 
   176 void PageNetGame::setUser(const QString & nickname)
   264 void PageNetGame::setUser(const QString & nickname)
   177 {
   265 {
   178     chatWidget->setUser(nickname);
   266     chatWidget->setUser(nickname);