GameSelector::GameSelector(AbstractClient *_client, const TabSupervisor *_tabSupervisor, TabRoom *_room, const QMap<int, QString> &_rooms, const QMap<int, GameTypeMap> &_gameTypes, QWidget *parent) : QGroupBox(parent), client(_client), tabSupervisor(_tabSupervisor), room(_room) { gameListView = new QTreeView; gameListModel = new GamesModel(_rooms, _gameTypes, this); gameListProxyModel = new GamesProxyModel(this, tabSupervisor->getUserInfo()); gameListProxyModel->setSourceModel(gameListModel); gameListProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); gameListView->setModel(gameListProxyModel); gameListView->setSortingEnabled(true); gameListView->setAlternatingRowColors(true); gameListView->setRootIsDecorated(true); if (_room) gameListView->header()->hideSection(1); else gameListProxyModel->setUnavailableGamesVisible(true); gameListView->header()->setResizeMode(1, QHeaderView::ResizeToContents); filterButton = new QPushButton; filterButton->setIcon(QIcon(":/resources/icon_search.svg")); connect(filterButton, SIGNAL(clicked()), this, SLOT(actSetFilter())); clearFilterButton = new QPushButton; clearFilterButton->setIcon(QIcon(":/resources/icon_clearsearch.svg")); clearFilterButton->setEnabled(false); connect(clearFilterButton, SIGNAL(clicked()), this, SLOT(actClearFilter())); if (room) { createButton = new QPushButton; connect(createButton, SIGNAL(clicked()), this, SLOT(actCreate())); } else createButton = 0; joinButton = new QPushButton; spectateButton = new QPushButton; QHBoxLayout *buttonLayout = new QHBoxLayout; buttonLayout->addWidget(filterButton); buttonLayout->addWidget(clearFilterButton); buttonLayout->addStretch(); if (room) buttonLayout->addWidget(createButton); buttonLayout->addWidget(joinButton); buttonLayout->addWidget(spectateButton); buttonLayout->setAlignment(Qt::AlignTop); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(gameListView); mainLayout->addLayout(buttonLayout); retranslateUi(); setLayout(mainLayout); setMinimumWidth((qreal) (gameListView->columnWidth(0) * gameListModel->columnCount()) / 1.5); setMinimumHeight(200); connect(joinButton, SIGNAL(clicked()), this, SLOT(actJoin())); connect(spectateButton, SIGNAL(clicked()), this, SLOT(actJoin())); }
GameSelector::GameSelector(AbstractClient *_client, int _roomId, QWidget *parent) : QGroupBox(parent), client(_client), roomId(_roomId) { gameListView = new QTreeView; gameListModel = new GamesModel(this); gameListProxyModel = new GamesProxyModel(this); gameListProxyModel->setSourceModel(gameListModel); gameListView->setModel(gameListProxyModel); gameListView->header()->setResizeMode(0, QHeaderView::ResizeToContents); showFullGamesCheckBox = new QCheckBox; createButton = new QPushButton; joinButton = new QPushButton; spectateButton = new QPushButton; QHBoxLayout *buttonLayout = new QHBoxLayout; buttonLayout->addWidget(showFullGamesCheckBox); buttonLayout->addStretch(); buttonLayout->addWidget(createButton); buttonLayout->addWidget(joinButton); buttonLayout->addWidget(spectateButton); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(gameListView); mainLayout->addLayout(buttonLayout); retranslateUi(); setLayout(mainLayout); setMinimumWidth(gameListView->columnWidth(0) * gameListModel->columnCount()); setMinimumHeight(400); connect(showFullGamesCheckBox, SIGNAL(stateChanged(int)), this, SLOT(showFullGamesChanged(int))); connect(createButton, SIGNAL(clicked()), this, SLOT(actCreate())); connect(joinButton, SIGNAL(clicked()), this, SLOT(actJoin())); connect(spectateButton, SIGNAL(clicked()), this, SLOT(actJoin())); }