QLayout * PageEditTeam::bodyLayoutDefinition() { QGridLayout * pageLayout = new QGridLayout(); tbw = new QTabWidget(); QWidget * page1 = new QWidget(this); binder = new KeyBinder(this, tr("Select an action to choose a custom key bind for this team"), tr("Use my default"), tr("Reset all binds")); connect(binder, SIGNAL(resetAllBinds()), this, SLOT(resetAllBinds())); tbw->addTab(page1, tr("General")); tbw->addTab(binder, tr("Custom Controls")); pageLayout->addWidget(tbw, 0, 0, 1, 3); QHBoxLayout * page1Layout = new QHBoxLayout(page1); page1Layout->setAlignment(Qt::AlignTop); // ====== Page 1 ====== QVBoxLayout * vbox1 = new QVBoxLayout(); QVBoxLayout * vbox2 = new QVBoxLayout(); page1Layout->addLayout(vbox1); page1Layout->addLayout(vbox2); GBoxHedgehogs = new QGroupBox(this); GBoxHedgehogs->setTitle(QGroupBox::tr("Team Members")); GBoxHedgehogs->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); QGridLayout * GBHLayout = new QGridLayout(GBoxHedgehogs); GBHLayout->addWidget(new QLabel(tr("Hat")), 0, 0); GBHLayout->addWidget(new QLabel(tr("Name")), 0, 1); for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++) { HHHats[i] = new HatButton(GBoxHedgehogs); GBHLayout->addWidget(HHHats[i], i + 1, 0); HHNameEdit[i] = new QLineEdit(GBoxHedgehogs); HHNameEdit[i]->setMaxLength(64); HHNameEdit[i]->setMinimumWidth(120); HHNameEdit[i]->setFixedHeight(36); HHNameEdit[i]->setWhatsThis(tr("This hedgehog's name")); HHNameEdit[i]->setStyleSheet("padding: 6px;"); GBHLayout->addWidget(HHNameEdit[i], i + 1, 1, 1, 2); btnRandomHogName[i] = addButton(":/res/dice.png", GBHLayout, i + 1, 5, 1, 1, true); btnRandomHogName[i]->setFixedHeight(HHNameEdit[i]->height()); btnRandomHogName[i]->setWhatsThis(tr("Randomize this hedgehog's name")); } btnRandomHats = new QPushButton(); btnRandomHats->setText(tr("Random Hats")); btnRandomHats->setStyleSheet("padding: 6px 10px;"); GBHLayout->addWidget(btnRandomHats, 9, 1, 1, 1, Qt::AlignCenter); btnRandomHats->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); btnRandomNames = new QPushButton(); btnRandomNames->setText(tr("Random Names")); btnRandomNames->setStyleSheet("padding: 6px 10px;"); GBHLayout->addWidget(btnRandomNames, 9, 2, 1, 1, Qt::AlignCenter); btnRandomNames->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); vbox1->addWidget(GBoxHedgehogs); btnRandomTeam = new QPushButton(); btnRandomTeam->setText(tr("Random Team")); btnRandomTeam->setStyleSheet("padding: 6px 10px;"); btnRandomTeam->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); vbox1->addWidget(btnRandomTeam, 0, Qt::AlignCenter); GBoxTeam = new QGroupBox(this); GBoxTeam->setTitle(QGroupBox::tr("Team Settings")); GBoxTeam->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); QGridLayout * GBTLayout = new QGridLayout(GBoxTeam); QLabel * tmpLabel = new QLabel(GBoxTeam); tmpLabel->setText(QLabel::tr("Name")); GBTLayout->addWidget(tmpLabel, 0, 0); tmpLabel = new QLabel(GBoxTeam); tmpLabel->setText(QLabel::tr("Player")); GBTLayout->addWidget(tmpLabel, 1, 0); tmpLabel = new QLabel(GBoxTeam); tmpLabel->setText(QLabel::tr("Grave")); GBTLayout->addWidget(tmpLabel, 2, 0); tmpLabel = new QLabel(GBoxTeam); tmpLabel->setText(QLabel::tr("Flag")); GBTLayout->addWidget(tmpLabel, 3, 0); tmpLabel = new QLabel(GBoxTeam); tmpLabel->setText(QLabel::tr("Voice")); GBTLayout->addWidget(tmpLabel, 4, 0); TeamNameEdit = new QLineEdit(GBoxTeam); TeamNameEdit->setMaxLength(64); TeamNameEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); GBTLayout->addWidget(TeamNameEdit, 0, 1, 1, 2); vbox2->addWidget(GBoxTeam); CBTeamLvl = new QComboBox(GBoxTeam); CBTeamLvl->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); CBTeamLvl->setIconSize(QSize(32, 32)); CBTeamLvl->addItem(QIcon(":/res/botlevels/small0.png"), QComboBox::tr("Human")); for(int i = 5; i > 0; i--) CBTeamLvl->addItem( QIcon(QString(":/res/botlevels/small%1.png").arg(6 - i)), QComboBox::tr("Computer (Level %1)").arg(i) ); CBTeamLvl->setFixedHeight(38); GBTLayout->addWidget(CBTeamLvl, 1, 1, 1, 2); CBGrave = new QComboBox(GBoxTeam); CBGrave->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); CBGrave->setMaxCount(65535); CBGrave->setMaxVisibleItems(20); CBGrave->setIconSize(QSize(32, 32)); CBGrave->setFixedHeight(44); GBTLayout->addWidget(CBGrave, 2, 1, 1, 2); // Player flags, combobox to select flag CBFlag = new QComboBox(GBoxTeam); CBFlag->setMaxCount(65535); CBFlag->setMaxVisibleItems(50); CBFlag->setIconSize(QSize(22, 15)); CBFlag->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); GBTLayout->addWidget(CBFlag, 3, 1, 1, 2); // CPU level flag. Static image, only displayed when computer player is selected QImage imgBotlevels = QImage("physfs://Graphics/botlevels.png"); int botlevelOffsets[5]= { 19, 14, 10, 6, 0 }; for(int i=0; i<5; i++) { QImage imgCPU = QImage("physfs://Graphics/Flags/cpu.png"); QPainter painter(&imgCPU); painter.drawImage(botlevelOffsets[i], 0, imgBotlevels, botlevelOffsets[i]); pixCPU[i] = QPixmap::fromImage(imgCPU); } QHBoxLayout* hboxCPU = new QHBoxLayout(); hboxCPU->setContentsMargins(0, 0, 0, 0); hboxCPUWidget = new QWidget(); hboxCPUWidget->setLayout(hboxCPU); CPUFlag = new QLabel(); CPUFlag->setPixmap(pixCPU[0]); CPUFlag->setFixedHeight(38); hboxCPU->addWidget(CPUFlag); CPUFlagLabel = new QLabel("CPU"); CPUFlagLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); hboxCPU->addWidget(CPUFlagLabel); hboxCPUWidget->setHidden(true); GBTLayout->addWidget(hboxCPUWidget, 3, 1, 1, 1); btnRandomTeamName = addButton(":/res/dice.png", GBTLayout, 0, 3, 1, 1, true); btnRandomTeamName->setWhatsThis(tr("Randomize the team name")); btnRandomGrave = addButton(":/res/dice.png", GBTLayout, 2, 3, 1, 1, true); btnRandomGrave->setWhatsThis(tr("Randomize the grave")); btnRandomFlag = addButton(":/res/dice.png", GBTLayout, 3, 3, 1, 1, true); btnRandomFlag->setWhatsThis(tr("Randomize the flag")); CBVoicepack = new QComboBox(GBoxTeam); CBVoicepack->setMaxVisibleItems(50); CBVoicepack->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); GBTLayout->addWidget(CBVoicepack, 4, 1, 1, 1); btnTestSound = addSoundlessButton(":/res/PlaySound.png", GBTLayout, 4, 2, 1, 1, true); btnTestSound->setWhatsThis(tr("Play a random example of this voice")); btnRandomVoice = addButton(":/res/dice.png", GBTLayout, 4, 3, 1, 1, true); btnRandomVoice->setWhatsThis(tr("Randomize the voice")); GBoxFort = new QGroupBox(this); GBoxFort->setTitle(QGroupBox::tr("Fort")); QGridLayout * GBFLayout = new QGridLayout(GBoxFort); CBFort = new QComboBox(GBoxFort); CBFort->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); CBFort->setMaxVisibleItems(25); CBFort->setMaxCount(65535); GBFLayout->addWidget(CBFort, 0, 0); btnRandomFort = addButton(":/res/dice.png", GBFLayout, 0, 2, 1, 1, true); btnRandomFort->setWhatsThis(tr("Randomize the fort")); FortPreview = new SquareLabel(GBoxFort); FortPreview->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); FortPreview->setMinimumSize(128, 128); FortPreview->setPixmap(QPixmap()); // perhaps due to handling its own paintevents, SquareLabel doesn't play nice with the stars //FortPreview->setAttribute(Qt::WA_PaintOnScreen, true); GBFLayout->addWidget(FortPreview, 1, 0, 1, 2); vbox2->addWidget(GBoxFort); vbox1->addStretch(); vbox2->addStretch(); return pageLayout; }
KeyBinder::KeyBinder(QWidget * parent, const QString & helpText, const QString & defaultText, const QString & resetButtonText) : QWidget(parent) { this->defaultText = defaultText; enableSignal = false; // Two-column tab layout QHBoxLayout * pageKeysLayout = new QHBoxLayout(this); pageKeysLayout->setSpacing(0); pageKeysLayout->setContentsMargins(0, 0, 0, 0); // Table for category list QVBoxLayout * catListContainer = new QVBoxLayout(); catListContainer->setContentsMargins(10, 10, 10, 10); catList = new QListWidget(); catList->setFixedWidth(180); catList->setStyleSheet("QListWidget::item { font-size: 14px; } QListWidget:hover { border-color: #F6CB1C; } QListWidget::item:selected { background: #150A61; color: yellow; }"); catList->setFocusPolicy(Qt::NoFocus); connect(catList, SIGNAL(currentRowChanged(int)), this, SLOT(changeBindingsPage(int))); catListContainer->addWidget(catList); pageKeysLayout->addLayout(catListContainer); // Reset all binds button if (!resetButtonText.isEmpty()) { QPushButton * btnResetAll = new QPushButton(resetButtonText); catListContainer->addWidget(btnResetAll); btnResetAll->setFixedHeight(40); catListContainer->setStretch(1, 0); catListContainer->setSpacing(10); connect(btnResetAll, SIGNAL(clicked()), this, SIGNAL(resetAllBinds())); } // Container for pages of key bindings QWidget * bindingsPagesContainer = new QWidget(); QVBoxLayout * rightLayout = new QVBoxLayout(bindingsPagesContainer); // Scroll area for key bindings QScrollArea * scrollArea = new QScrollArea(); scrollArea->setContentsMargins(0, 0, 0, 0); scrollArea->setWidget(bindingsPagesContainer); scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); scrollArea->setWidgetResizable(true); scrollArea->setFrameShape(QFrame::NoFrame); scrollArea->setStyleSheet("background: #130F2A;"); // Add key binding pages to bindings tab pageKeysLayout->addWidget(scrollArea); pageKeysLayout->setStretch(1, 1); // Custom help text QLabel * helpLabel = new QLabel(); helpLabel->setText(helpText); helpLabel->setStyleSheet("color: #130F2A; background: #F6CB1C; border: solid 4px #F6CB1C; border-radius: 10px; padding: auto 20px;"); helpLabel->setFixedHeight(24); rightLayout->addWidget(helpLabel, 0, Qt::AlignCenter); // Category list and bind table row heights const int rowHeight = 20; QSize catSize, headerSize; catSize.setHeight(36); headerSize.setHeight(24); // Category list header QListWidgetItem * catListHeader = new QListWidgetItem(tr("Category")); catListHeader->setSizeHint(headerSize); catListHeader->setFlags(Qt::NoItemFlags); catListHeader->setForeground(QBrush(QColor("#130F2A"))); catListHeader->setBackground(QBrush(QColor("#F6CB1C"))); catListHeader->setTextAlignment(Qt::AlignCenter); catList->addItem(catListHeader); // Populate bindingsPages = new QHBoxLayout(); bindingsPages->setContentsMargins(0, 0, 0, 0); rightLayout->addLayout(bindingsPages); QWidget * curPage = NULL; QVBoxLayout * curLayout = NULL; QTableWidget * curTable = NULL; bool bFirstPage = true; selectedBindTable = NULL; bindComboBoxCellMappings = new QHash<QObject *, QTableWidgetItem *>(); bindCellComboBoxMappings = new QHash<QTableWidgetItem *, QComboBox *>(); for (int i = 0; i < BINDS_NUMBER; i++) { if (cbinds[i].category != NULL) { // Add stretch at end of previous layout if (curLayout != NULL) curLayout->insertStretch(-1, 1); // Category list item QListWidgetItem * catItem = new QListWidgetItem(HWApplication::translate("binds (categories)", cbinds[i].category)); catItem->setSizeHint(catSize); catList->addItem(catItem); // Create new page curPage = new QWidget(); curLayout = new QVBoxLayout(curPage); curLayout->setSpacing(2); bindingsPages->addWidget(curPage); if (!bFirstPage) curPage->setVisible(false); } // Description if (cbinds[i].description != NULL) { QLabel * desc = new QLabel(HWApplication::translate("binds (descriptions)", cbinds[i].description)); curLayout->addWidget(desc, 0); QFrame * divider = new QFrame(); divider->setFrameShape(QFrame::HLine); divider->setFrameShadow(QFrame::Plain); curLayout->addWidget(divider, 0); } // New table if (cbinds[i].category != NULL || cbinds[i].description != NULL) { curTable = new QTableWidget(0, 2); curTable->verticalHeader()->setVisible(false); curTable->horizontalHeader()->setVisible(false); curTable->horizontalHeader()->setResizeMode(QHeaderView::Stretch); curTable->verticalHeader()->setDefaultSectionSize(rowHeight); curTable->setShowGrid(false); curTable->setStyleSheet("QTableWidget { border: none; } "); curTable->setSelectionBehavior(QAbstractItemView::SelectRows); curTable->setSelectionMode(QAbstractItemView::SingleSelection); curTable->setFocusPolicy(Qt::NoFocus); connect(curTable, SIGNAL(itemSelectionChanged()), this, SLOT(bindSelectionChanged())); connect(curTable, SIGNAL(itemClicked(QTableWidgetItem *)), this, SLOT(bindCellClicked(QTableWidgetItem *))); curLayout->addWidget(curTable, 0); } // Hidden combo box QComboBox * comboBox = CBBind[i] = new QComboBox(curTable); comboBox->setModel((QAbstractItemModel*)DataManager::instance().bindsModel()); comboBox->setVisible(false); comboBox->setFixedWidth(200); // Table row int row = curTable->rowCount(); QTableWidgetItem * nameCell = new QTableWidgetItem(HWApplication::translate("binds", cbinds[i].name)); nameCell->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); curTable->insertRow(row); curTable->setItem(row, 0, nameCell); QTableWidgetItem * bindCell = new QTableWidgetItem(comboBox->currentText()); bindCell->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); curTable->setItem(row, 1, bindCell); curTable->resizeColumnsToContents(); curTable->setFixedHeight(curTable->verticalHeader()->length() + 10); // Updates the text in the table cell connect(comboBox, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(bindChanged(const QString &))); // Map combo box and that row's cells to each other bindComboBoxCellMappings->insert(comboBox, bindCell); bindCellComboBoxMappings->insert(nameCell, comboBox); bindCellComboBoxMappings->insert(bindCell, comboBox); }
QLayout * PageEditTeam::bodyLayoutDefinition() { QGridLayout * pageLayout = new QGridLayout(); tbw = new QTabWidget(); QWidget * page1 = new QWidget(this); binder = new KeyBinder(this, tr("Select an action to choose a custom key bind for this team"), tr("Use my default"), tr("Reset all binds")); connect(binder, SIGNAL(resetAllBinds()), this, SLOT(resetAllBinds())); tbw->addTab(page1, tr("General")); tbw->addTab(binder, tr("Custom Controls")); pageLayout->addWidget(tbw, 0, 0, 1, 3); QHBoxLayout * page1Layout = new QHBoxLayout(page1); page1Layout->setAlignment(Qt::AlignTop); // ====== Page 1 ====== QVBoxLayout * vbox1 = new QVBoxLayout(); QVBoxLayout * vbox2 = new QVBoxLayout(); page1Layout->addLayout(vbox1); page1Layout->addLayout(vbox2); GBoxHedgehogs = new QGroupBox(this); GBoxHedgehogs->setTitle(QGroupBox::tr("Team Members")); GBoxHedgehogs->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); QGridLayout * GBHLayout = new QGridLayout(GBoxHedgehogs); GBHLayout->addWidget(new QLabel(tr("Hat")), 0, 0); GBHLayout->addWidget(new QLabel(tr("Name")), 0, 1); for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++) { HHHats[i] = new HatButton(GBoxHedgehogs); GBHLayout->addWidget(HHHats[i], i + 1, 0); HHNameEdit[i] = new QLineEdit(GBoxHedgehogs); HHNameEdit[i]->setMaxLength(64); HHNameEdit[i]->setMinimumWidth(120); HHNameEdit[i]->setFixedHeight(36); HHNameEdit[i]->setWhatsThis(tr("This hedgehog's name")); HHNameEdit[i]->setStyleSheet("padding: 6px;"); GBHLayout->addWidget(HHNameEdit[i], i + 1, 1); btnRandomHogName[i] = addButton(":/res/dice.png", GBHLayout, i + 1, 3, 1, 1, true); btnRandomHogName[i]->setFixedHeight(HHNameEdit[i]->height()); btnRandomHogName[i]->setWhatsThis(tr("Randomize this hedgehog's name")); } btnRandomTeam = new QPushButton(); btnRandomTeam->setText(tr("Random Team")); btnRandomTeam->setStyleSheet("padding: 6px 10px;"); GBHLayout->addWidget(btnRandomTeam, 9, 0, 1, 4, Qt::AlignCenter); btnRandomTeam->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); vbox1->addWidget(GBoxHedgehogs); GBoxTeam = new QGroupBox(this); GBoxTeam->setTitle(QGroupBox::tr("Team Settings")); GBoxTeam->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); QGridLayout * GBTLayout = new QGridLayout(GBoxTeam); QLabel * tmpLabel = new QLabel(GBoxTeam); tmpLabel->setText(QLabel::tr("Name")); GBTLayout->addWidget(tmpLabel, 0, 0); tmpLabel = new QLabel(GBoxTeam); tmpLabel->setText(QLabel::tr("Type")); GBTLayout->addWidget(tmpLabel, 1, 0); tmpLabel = new QLabel(GBoxTeam); tmpLabel->setText(QLabel::tr("Grave")); GBTLayout->addWidget(tmpLabel, 2, 0); tmpLabel = new QLabel(GBoxTeam); tmpLabel->setText(QLabel::tr("Flag")); GBTLayout->addWidget(tmpLabel, 3, 0); tmpLabel = new QLabel(GBoxTeam); tmpLabel->setText(QLabel::tr("Voice")); GBTLayout->addWidget(tmpLabel, 4, 0); TeamNameEdit = new QLineEdit(GBoxTeam); TeamNameEdit->setMaxLength(64); GBTLayout->addWidget(TeamNameEdit, 0, 1); vbox2->addWidget(GBoxTeam); CBTeamLvl = new QComboBox(GBoxTeam); CBTeamLvl->setIconSize(QSize(48, 48)); CBTeamLvl->addItem(QIcon(":/res/botlevels/0.png"), QComboBox::tr("Human")); for(int i = 5; i > 0; i--) CBTeamLvl->addItem( QIcon(QString(":/res/botlevels/%1.png").arg(6 - i)), QString("%1 %2").arg(QComboBox::tr("Level")).arg(i) ); GBTLayout->addWidget(CBTeamLvl, 1, 1); CBGrave = new QComboBox(GBoxTeam); CBGrave->setMaxCount(65535); CBGrave->setIconSize(QSize(32, 32)); GBTLayout->addWidget(CBGrave, 2, 1); CBFlag = new QComboBox(GBoxTeam); CBFlag->setMaxCount(65535); CBFlag->setIconSize(QSize(22, 15)); GBTLayout->addWidget(CBFlag, 3, 1); QHBoxLayout * hbox = new QHBoxLayout(); CBVoicepack = new QComboBox(GBoxTeam); hbox->addWidget(CBVoicepack, 100); btnTestSound = addSoundlessButton(":/res/PlaySound.png", hbox, 1, true); hbox->setStretchFactor(btnTestSound, 1); GBTLayout->addLayout(hbox, 4, 1); GBoxFort = new QGroupBox(this); GBoxFort->setTitle(QGroupBox::tr("Fort")); QGridLayout * GBFLayout = new QGridLayout(GBoxFort); CBFort = new QComboBox(GBoxFort); CBFort->setMaxCount(65535); GBFLayout->addWidget(CBFort, 0, 0); FortPreview = new SquareLabel(GBoxFort); FortPreview->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); FortPreview->setMinimumSize(128, 128); FortPreview->setPixmap(QPixmap()); // perhaps due to handling its own paintevents, SquareLabel doesn't play nice with the stars //FortPreview->setAttribute(Qt::WA_PaintOnScreen, true); GBFLayout->addWidget(FortPreview, 1, 0); vbox2->addWidget(GBoxFort); vbox1->addStretch(); vbox2->addStretch(); return pageLayout; }