144 connect(BtnCreate, SIGNAL(clicked()), this, SLOT(onCreateClick())); |
144 connect(BtnCreate, SIGNAL(clicked()), this, SLOT(onCreateClick())); |
145 connect(BtnJoin, SIGNAL(clicked()), this, SLOT(onJoinClick())); |
145 connect(BtnJoin, SIGNAL(clicked()), this, SLOT(onJoinClick())); |
146 connect(BtnRefresh, SIGNAL(clicked()), this, SLOT(onRefreshClick())); |
146 connect(BtnRefresh, SIGNAL(clicked()), this, SLOT(onRefreshClick())); |
147 connect(BtnClear, SIGNAL(clicked()), this, SLOT(onClearClick())); |
147 connect(BtnClear, SIGNAL(clicked()), this, SLOT(onClearClick())); |
148 connect(roomsList, SIGNAL(doubleClicked (const QModelIndex &)), this, SLOT(onJoinClick())); |
148 connect(roomsList, SIGNAL(doubleClicked (const QModelIndex &)), this, SLOT(onJoinClick())); |
149 connect(CBState, SIGNAL(currentIndexChanged (int)), this, SLOT(onRefreshClick())); |
149 connect(CBState, SIGNAL(currentIndexChanged (int)), this, SLOT(onFilterChanged())); |
150 connect(CBRules, SIGNAL(currentIndexChanged (int)), this, SLOT(onRefreshClick())); |
150 connect(CBRules, SIGNAL(currentIndexChanged (int)), this, SLOT(onFilterChanged())); |
151 connect(CBWeapons, SIGNAL(currentIndexChanged (int)), this, SLOT(onRefreshClick())); |
151 connect(CBWeapons, SIGNAL(currentIndexChanged (int)), this, SLOT(onFilterChanged())); |
152 connect(searchText, SIGNAL(textChanged (const QString &)), this, SLOT(onRefreshClick())); |
152 connect(searchText, SIGNAL(textChanged (const QString &)), this, SLOT(onFilterChanged())); |
153 connect(this, SIGNAL(askJoinConfirmation (const QString &)), this, SLOT(onJoinConfirmation(const QString &)), Qt::QueuedConnection); |
153 connect(this, SIGNAL(askJoinConfirmation (const QString &)), this, SLOT(onJoinConfirmation(const QString &)), Qt::QueuedConnection); |
|
154 |
|
155 |
|
156 connect(roomsList->horizontalHeader(), SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)), |
|
157 this, SLOT(onSortIndicatorChanged(int, Qt::SortOrder))); |
154 } |
158 } |
155 |
159 |
156 |
160 |
157 PageRoomsList::PageRoomsList(QWidget* parent, QSettings * gameSettings) : |
161 PageRoomsList::PageRoomsList(QWidget* parent, QSettings * gameSettings) : |
158 AbstractPage(parent) |
162 AbstractPage(parent) |
159 { |
163 { |
160 m_gameSettings = gameSettings; |
164 m_gameSettings = gameSettings; |
|
165 |
|
166 roomsModel = NULL; |
|
167 stateFilteredModel = NULL; |
|
168 schemeFilteredModel = NULL; |
|
169 weaponsFilteredModel = NULL; |
161 |
170 |
162 initPage(); |
171 initPage(); |
163 |
172 |
164 // not the most elegant solution but it works |
173 // not the most elegant solution but it works |
165 ammoSchemeModel = new AmmoSchemeModel(this, NULL); |
174 ammoSchemeModel = new AmmoSchemeModel(this, NULL); |
477 void PageRoomsList::setUser(const QString & nickname) |
486 void PageRoomsList::setUser(const QString & nickname) |
478 { |
487 { |
479 chatWidget->setUser(nickname); |
488 chatWidget->setUser(nickname); |
480 } |
489 } |
481 |
490 |
482 void PageRoomsList::setModel(RoomsListModel *model) |
491 void PageRoomsList::setModel(RoomsListModel * model) |
483 { |
492 { |
484 roomsModel = new QSortFilterProxyModel(this); |
493 if (roomsModel == NULL) |
|
494 { |
|
495 roomsModel = new QSortFilterProxyModel(this); |
|
496 roomsModel->setDynamicSortFilter(true); |
|
497 roomsModel->setSortCaseSensitivity(Qt::CaseInsensitive); |
|
498 roomsModel->sort(RoomsListModel::StateColumn, Qt::AscendingOrder); |
|
499 |
|
500 stateFilteredModel = new QSortFilterProxyModel(this); |
|
501 schemeFilteredModel = new QSortFilterProxyModel(this); |
|
502 weaponsFilteredModel = new QSortFilterProxyModel(this); |
|
503 |
|
504 stateFilteredModel->setDynamicSortFilter(true); |
|
505 schemeFilteredModel->setDynamicSortFilter(true); |
|
506 weaponsFilteredModel->setDynamicSortFilter(true); |
|
507 |
|
508 roomsModel->setFilterKeyColumn(-1); // search in all columns |
|
509 stateFilteredModel->setFilterKeyColumn(RoomsListModel::StateColumn); |
|
510 schemeFilteredModel->setFilterKeyColumn(RoomsListModel::SchemeColumn); |
|
511 weaponsFilteredModel->setFilterKeyColumn(RoomsListModel::WeaponsColumn); |
|
512 |
|
513 roomsModel->setFilterCaseSensitivity(Qt::CaseInsensitive); |
|
514 schemeFilteredModel->setFilterCaseSensitivity(Qt::CaseInsensitive); |
|
515 weaponsFilteredModel->setFilterCaseSensitivity(Qt::CaseInsensitive); |
|
516 |
|
517 stateFilteredModel->setSourceModel(roomsModel); |
|
518 schemeFilteredModel->setSourceModel(stateFilteredModel); |
|
519 weaponsFilteredModel->setSourceModel(schemeFilteredModel); |
|
520 |
|
521 roomsList->setModel(schemeFilteredModel); |
|
522 } |
|
523 |
485 roomsModel->setSourceModel(model); |
524 roomsModel->setSourceModel(model); |
486 roomsModel->setDynamicSortFilter(true); |
|
487 roomsModel->setSortCaseSensitivity(Qt::CaseInsensitive); |
|
488 roomsModel->sort(RoomsListModel::StateColumn, Qt::AscendingOrder); |
|
489 roomsList->setModel(roomsModel); |
|
490 |
525 |
491 roomsList->hideColumn(RoomsListModel::StateColumn); |
526 roomsList->hideColumn(RoomsListModel::StateColumn); |
492 |
527 |
493 QHeaderView * h = roomsList->horizontalHeader(); |
528 QHeaderView * h = roomsList->horizontalHeader(); |
494 |
529 |
499 h->resizeSection(RoomsListModel::TeamCountColumn, 32); |
534 h->resizeSection(RoomsListModel::TeamCountColumn, 32); |
500 h->resizeSection(RoomsListModel::OwnerColumn, 100); |
535 h->resizeSection(RoomsListModel::OwnerColumn, 100); |
501 h->resizeSection(RoomsListModel::MapColumn, 100); |
536 h->resizeSection(RoomsListModel::MapColumn, 100); |
502 h->resizeSection(RoomsListModel::SchemeColumn, 100); |
537 h->resizeSection(RoomsListModel::SchemeColumn, 100); |
503 h->resizeSection(RoomsListModel::WeaponsColumn, 100); |
538 h->resizeSection(RoomsListModel::WeaponsColumn, 100); |
504 |
539 } |
505 connect(h, SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)), |
540 |
506 this, SLOT(onSortIndicatorChanged(int, Qt::SortOrder))); |
|
507 |
|
508 } |
|
509 |
541 |
510 void PageRoomsList::onSortIndicatorChanged(int logicalIndex, Qt::SortOrder order) |
542 void PageRoomsList::onSortIndicatorChanged(int logicalIndex, Qt::SortOrder order) |
511 { |
543 { |
|
544 if (roomsModel == NULL) |
|
545 return; |
|
546 |
512 // three state sorting: asc -> dsc -> default (by room state) |
547 // three state sorting: asc -> dsc -> default (by room state) |
513 if ((order == Qt::AscendingOrder) && (logicalIndex == roomsModel->sortColumn())) |
548 if ((order == Qt::AscendingOrder) && (logicalIndex == roomsModel->sortColumn())) |
514 roomsList->horizontalHeader()->setSortIndicator( |
549 roomsList->horizontalHeader()->setSortIndicator( |
515 RoomsListModel::StateColumn, Qt::AscendingOrder); |
550 RoomsListModel::StateColumn, Qt::AscendingOrder); |
516 else |
551 else |
517 roomsModel->sort(logicalIndex, order); |
552 roomsModel->sort(logicalIndex, order); |
518 } |
553 } |
|
554 |
|
555 |
|
556 void PageRoomsList::onFilterChanged() |
|
557 { |
|
558 if (roomsModel == NULL) |
|
559 return; |
|
560 |
|
561 roomsModel->setFilterWildcard(QString("*%1*").arg(searchText->text())); |
|
562 |
|
563 int stateIdx = CBState->currentIndex(); |
|
564 // any = 0, in lobby/false = 1, in progress/true = 2 |
|
565 |
|
566 if (stateIdx == 0) |
|
567 stateFilteredModel->setFilterWildcard("*"); // "any" |
|
568 else |
|
569 stateFilteredModel->setFilterFixedString(QString(stateIdx == 2)); |
|
570 |
|
571 if (CBRules->currentIndex() == 0) |
|
572 schemeFilteredModel->setFilterWildcard("*"); // "any" |
|
573 else |
|
574 schemeFilteredModel->setFilterWildcard( |
|
575 QString("*%1*").arg(CBRules->currentText())); |
|
576 |
|
577 if (CBWeapons->currentIndex() == 0) |
|
578 weaponsFilteredModel->setFilterWildcard("*"); // "any" |
|
579 else |
|
580 weaponsFilteredModel->setFilterWildcard( |
|
581 QString("*%1*").arg(CBWeapons->currentText())); |
|
582 } |