QTfrontend/ui/page/pagenetgame.cpp
changeset 8415 02acf6b92f52
parent 8382 67e257b98422
child 8424 225ede46e3dc
equal deleted inserted replaced
8414:c1ac0b64315e 8415:02acf6b92f52
    30 
    30 
    31 QLayout * PageNetGame::bodyLayoutDefinition()
    31 QLayout * PageNetGame::bodyLayoutDefinition()
    32 {
    32 {
    33     QGridLayout * pageLayout = new QGridLayout();
    33     QGridLayout * pageLayout = new QGridLayout();
    34     pageLayout->setSizeConstraint(QLayout::SetMinimumSize);
    34     pageLayout->setSizeConstraint(QLayout::SetMinimumSize);
    35     //pageLayout->setSpacing(1);
    35     pageLayout->setColumnStretch(0, 1);
    36     pageLayout->setColumnStretch(0, 50);
    36     pageLayout->setColumnStretch(1, 1);
    37     pageLayout->setColumnStretch(1, 50);
    37     pageLayout->setRowStretch(0, 0);
    38 
    38     pageLayout->setRowStretch(1, 1);
    39     // chatwidget
    39     pageLayout->setRowStretch(2, 1);
       
    40 
       
    41     // Room config
       
    42 
       
    43     QHBoxLayout * roomConfigLayout = new QHBoxLayout();
       
    44     pageLayout->addLayout(roomConfigLayout, 0, 0, 1, 2);
       
    45     roomConfigLayout->setSpacing(0);
       
    46 
       
    47     leRoomName = new HistoryLineEdit(this, 10);
       
    48     leRoomName->setMaxLength(60);
       
    49     leRoomName->setMinimumWidth(400);
       
    50     leRoomName->setMaximumWidth(600);
       
    51     leRoomName->setFixedHeight(30);
       
    52     leRoomName->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
       
    53     roomConfigLayout->addWidget(leRoomName, 100);
       
    54 
       
    55     QLabel * lblRoomName = new QLabel(tr("Room name: "), leRoomName);
       
    56     lblRoomName->setStyleSheet("font: 12px; font-weight: bold;");
       
    57     lblRoomName->setStyleSheet(QString("font: 12px; font-weight: bold; background: none; margin-left: -%1px; margin-top: 8px;").arg(lblRoomName->width() - 20));
       
    58     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));
       
    59 
       
    60     BtnUpdate = new QPushButton();
       
    61     BtnUpdate->setEnabled(false);
       
    62     BtnUpdate->setText(tr("Update"));
       
    63     BtnUpdate->setFixedHeight(leRoomName->height() - 0);
       
    64     BtnUpdate->setStyleSheet("border-top-left-radius: 0px; border-bottom-left-radius: 0px; padding: auto 4px;");
       
    65     roomConfigLayout->addWidget(BtnUpdate, 0);
       
    66 
       
    67     lblRoomNameReadOnly = new QLabel();
       
    68     lblRoomNameReadOnly->setMinimumWidth(400);
       
    69     lblRoomNameReadOnly->setMaximumWidth(600);
       
    70     lblRoomNameReadOnly->setFixedHeight(30);
       
    71     lblRoomNameReadOnly->setObjectName("labelLikeLineEdit");
       
    72     lblRoomNameReadOnly->setStyleSheet("font: 12px;");
       
    73     lblRoomNameReadOnly->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
       
    74     lblRoomNameReadOnly->setVisible(false);
       
    75     roomConfigLayout->addWidget(lblRoomNameReadOnly, 100);
       
    76 
       
    77     roomConfigLayout->addSpacing(10);
       
    78 
       
    79     BtnMaster = new QPushButton();
       
    80     BtnMaster->setText(tr("Room controls"));
       
    81     BtnMaster->setFixedHeight(leRoomName->height() - 0);
       
    82     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; }");
       
    83     roomConfigLayout->addWidget(BtnMaster, 0);
       
    84 
       
    85     roomConfigLayout->addStretch(1);
       
    86 
       
    87     // Game config
       
    88 
       
    89     pGameCFG = new GameCFGWidget(this);
       
    90     pageLayout->addWidget(pGameCFG, 1, 0);
       
    91 
       
    92     // Teams
       
    93 
       
    94     pNetTeamsWidget = new TeamSelWidget(this);
       
    95     pNetTeamsWidget->setAcceptOuter(true);
       
    96     pNetTeamsWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
       
    97     pageLayout->addWidget(pNetTeamsWidget, 1, 1, 1, 1);
       
    98 
       
    99     // Chat
       
   100     
    40     chatWidget = new HWChatWidget(this, true);
   101     chatWidget = new HWChatWidget(this, true);
    41     chatWidget->setShowFollow(false); // don't show follow in nicks' context menus
   102     chatWidget->setShowFollow(false); // don't show follow in nicks' context menus
    42     chatWidget->setIgnoreListKick(true); // kick ignored players automatically
   103     chatWidget->setIgnoreListKick(true); // kick ignored players automatically
    43     pageLayout->addWidget(chatWidget, 1, 0, 1, 2);
   104     pageLayout->addWidget(chatWidget, 2, 0, 1, 2);
    44     pageLayout->setRowStretch(0, 0);
       
    45     pageLayout->setRowStretch(1, 0);
       
    46 
       
    47     pGameCFG = new GameCFGWidget(this);
       
    48     pageLayout->addWidget(pGameCFG, 0, 0);
       
    49 
       
    50     pNetTeamsWidget = new TeamSelWidget(this);
       
    51     pNetTeamsWidget->setAcceptOuter(true);
       
    52     pNetTeamsWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
       
    53     pageLayout->addWidget(pNetTeamsWidget, 0, 1, 1, 1);
       
    54 
   105 
    55     return pageLayout;
   106     return pageLayout;
    56 }
   107 }
    57 
   108 
    58 QLayout * PageNetGame::footerLayoutLeftDefinition()
   109 QLayout * PageNetGame::footerLayoutLeftDefinition()
    67 
   118 
    68 QLayout * PageNetGame::footerLayoutDefinition()
   119 QLayout * PageNetGame::footerLayoutDefinition()
    69 {
   120 {
    70     QHBoxLayout * bottomLayout = new QHBoxLayout;
   121     QHBoxLayout * bottomLayout = new QHBoxLayout;
    71 
   122 
    72     leRoomName = new HistoryLineEdit(this,10);
   123     // Ready button
    73     leRoomName->setMaxLength(60);
   124 
    74     leRoomName->setMinimumWidth(200);
       
    75     leRoomName->setMaximumWidth(400);
       
    76 
       
    77     //Button to signify whether the player is ready to start playing
       
    78     BtnGo = new QPushButton(this);
   125     BtnGo = new QPushButton(this);
    79     BtnGo->setIcon(QIcon(":/res/lightbulb_off.png"));
   126     BtnGo->setIcon(QIcon(":/res/lightbulb_off.png"));
    80     BtnGo->setIconSize(QSize(25, 34));
   127     BtnGo->setIconSize(QSize(25, 34));
    81     BtnGo->setMinimumWidth(50);
   128     BtnGo->setMinimumWidth(50);
    82     BtnGo->setMinimumHeight(50);
   129     BtnGo->setMinimumHeight(50);
    83 
   130 
    84     bottomLayout->addWidget(leRoomName);
       
    85     BtnUpdate = addButton(QAction::tr("Update"), bottomLayout, 1);
       
    86 
       
    87     bottomLayout->addStretch();
   131     bottomLayout->addStretch();
    88     bottomLayout->addWidget(BtnGo);
   132     bottomLayout->addWidget(BtnGo);
    89 
   133 
    90     BtnMaster = addButton(tr("Control"), bottomLayout, 3);
   134     // Start button
    91     bottomLayout->insertStretch(3, 100);
       
    92 
   135 
    93     const QIcon& lp = QIcon(":/res/Start.png");
   136     const QIcon& lp = QIcon(":/res/Start.png");
    94     QSize sz = lp.actualSize(QSize(65535, 65535));
   137     QSize sz = lp.actualSize(QSize(65535, 65535));
    95     BtnStart = new QPushButton();
   138     BtnStart = new QPushButton();
    96     BtnStart->setText(tr("Start"));
   139     BtnStart->setText(tr("Start"));
   108 void PageNetGame::connectSignals()
   151 void PageNetGame::connectSignals()
   109 {
   152 {
   110     connect(btnSetup, SIGNAL(clicked()), this, SIGNAL(SetupClicked()));
   153     connect(btnSetup, SIGNAL(clicked()), this, SIGNAL(SetupClicked()));
   111 
   154 
   112     connect(BtnUpdate, SIGNAL(clicked()), this, SLOT(onUpdateClick()));
   155     connect(BtnUpdate, SIGNAL(clicked()), this, SLOT(onUpdateClick()));
       
   156     connect(leRoomName, SIGNAL(returnPressed()), this, SLOT(onUpdateClick()));
       
   157 
       
   158     connect(leRoomName, SIGNAL(textChanged(const QString &)), this, SLOT(onRoomNameEdited()));
   113 }
   159 }
   114 
   160 
   115 PageNetGame::PageNetGame(QWidget* parent) : AbstractPage(parent)
   161 PageNetGame::PageNetGame(QWidget* parent) : AbstractPage(parent)
   116 {
   162 {
   117     initPage();
   163     initPage();
   120 
   166 
   121     restrictJoins = new QAction(QAction::tr("Restrict Joins"), menu);
   167     restrictJoins = new QAction(QAction::tr("Restrict Joins"), menu);
   122     restrictJoins->setCheckable(true);
   168     restrictJoins->setCheckable(true);
   123     restrictTeamAdds = new QAction(QAction::tr("Restrict Team Additions"), menu);
   169     restrictTeamAdds = new QAction(QAction::tr("Restrict Team Additions"), menu);
   124     restrictTeamAdds->setCheckable(true);
   170     restrictTeamAdds->setCheckable(true);
   125     //menu->addAction(startGame);
       
   126     menu->addAction(restrictJoins);
   171     menu->addAction(restrictJoins);
   127     menu->addAction(restrictTeamAdds);
   172     menu->addAction(restrictTeamAdds);
   128 
   173 
   129     BtnMaster->setMenu(menu);
   174     BtnMaster->setMenu(menu);
   130 }
   175 }
   153         BtnGo->setIcon(QIcon(":/res/lightbulb_on.png"));
   198         BtnGo->setIcon(QIcon(":/res/lightbulb_on.png"));
   154     else
   199     else
   155         BtnGo->setIcon(QIcon(":/res/lightbulb_off.png"));
   200         BtnGo->setIcon(QIcon(":/res/lightbulb_off.png"));
   156 }
   201 }
   157 
   202 
       
   203 void PageNetGame::onRoomNameEdited()
       
   204 {
       
   205     BtnUpdate->setEnabled(true);
       
   206 }
       
   207 
   158 void PageNetGame::onUpdateClick()
   208 void PageNetGame::onUpdateClick()
   159 {
   209 {
   160     if (!leRoomName->text().trimmed().isEmpty())
   210     if (!leRoomName->text().trimmed().isEmpty())
   161     {
   211     {
   162         emit askForUpdateRoomName(leRoomName->text());
   212         emit askForUpdateRoomName(leRoomName->text());
   163         leRoomName->rememberCurrentText();
   213         leRoomName->rememberCurrentText();
       
   214         BtnUpdate->setEnabled(false);
   164     }
   215     }
   165     else
   216     else
   166     {
   217     {
   167         leRoomName->clear();
   218         leRoomName->clear();
   168         QMessageBox roomMsg(this);
   219         QMessageBox roomMsg(this);
   177 
   228 
   178 void PageNetGame::setRoomName(const QString & roomName)
   229 void PageNetGame::setRoomName(const QString & roomName)
   179 {
   230 {
   180     leRoomName->setText(roomName);
   231     leRoomName->setText(roomName);
   181     leRoomName->rememberCurrentText();
   232     leRoomName->rememberCurrentText();
       
   233     lblRoomNameReadOnly->setText(roomName);
       
   234     BtnUpdate->setEnabled(false);
   182 }
   235 }
   183 
   236 
   184 void PageNetGame::setMasterMode(bool isMaster)
   237 void PageNetGame::setMasterMode(bool isMaster)
   185 {
   238 {
   186     BtnMaster->setVisible(isMaster);
   239     BtnMaster->setVisible(isMaster);
   187     BtnStart->setVisible(isMaster);
   240     BtnStart->setVisible(isMaster);
   188     BtnUpdate->setVisible(isMaster);
   241     BtnUpdate->setVisible(isMaster);
   189     leRoomName->setVisible(isMaster);
   242     leRoomName->setVisible(isMaster);
       
   243     lblRoomNameReadOnly->setVisible(!isMaster);
   190 }
   244 }
   191 
   245 
   192 void PageNetGame::setUser(const QString & nickname)
   246 void PageNetGame::setUser(const QString & nickname)
   193 {
   247 {
   194     chatWidget->setUser(nickname);
   248     chatWidget->setUser(nickname);