QTfrontend/ui/page/pageroomslist.cpp
changeset 7011 f6f09a0954ea
parent 7003 e118ee168577
child 7769 1661680c6b59
equal deleted inserted replaced
7008:25563f054ef3 7011:f6f09a0954ea
   149     connect(CBState, SIGNAL(currentIndexChanged (int)), this, SLOT(onFilterChanged()));
   149     connect(CBState, SIGNAL(currentIndexChanged (int)), this, SLOT(onFilterChanged()));
   150     connect(CBRules, SIGNAL(currentIndexChanged (int)), this, SLOT(onFilterChanged()));
   150     connect(CBRules, SIGNAL(currentIndexChanged (int)), this, SLOT(onFilterChanged()));
   151     connect(CBWeapons, SIGNAL(currentIndexChanged (int)), this, SLOT(onFilterChanged()));
   151     connect(CBWeapons, SIGNAL(currentIndexChanged (int)), this, SLOT(onFilterChanged()));
   152     connect(searchText, SIGNAL(textChanged (const QString &)), this, SLOT(onFilterChanged()));
   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     // save header state on change
       
   156     connect(roomsList->horizontalHeader(), SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)),
       
   157             this, SLOT(saveHeaderState()));
       
   158     connect(roomsList->horizontalHeader(), SIGNAL(sectionResized),
       
   159             this, SLOT(saveHeaderState()));
       
   160 
   154 
   161     // sorting
   155     // sorting
   162     connect(roomsList->horizontalHeader(), SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)),
   156     connect(roomsList->horizontalHeader(), SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)),
   163             this, SLOT(onSortIndicatorChanged(int, Qt::SortOrder)));
   157             this, SLOT(onSortIndicatorChanged(int, Qt::SortOrder)));
   164 }
   158 }
   536 
   530 
   537     roomsList->hideColumn(RoomsListModel::StateColumn);
   531     roomsList->hideColumn(RoomsListModel::StateColumn);
   538 
   532 
   539     QHeaderView * h = roomsList->horizontalHeader();
   533     QHeaderView * h = roomsList->horizontalHeader();
   540 
   534 
       
   535     h->setSortIndicatorShown(true);
       
   536     h->setSortIndicator(RoomsListModel::StateColumn, Qt::AscendingOrder);
       
   537     h->setResizeMode(RoomsListModel::NameColumn, QHeaderView::Stretch);
       
   538 
   541     if (!restoreHeaderState())
   539     if (!restoreHeaderState())
   542     {
   540     {
   543         h->resizeSection(RoomsListModel::PlayerCountColumn, 32);
   541         h->resizeSection(RoomsListModel::PlayerCountColumn, 32);
   544         h->resizeSection(RoomsListModel::TeamCountColumn, 32);
   542         h->resizeSection(RoomsListModel::TeamCountColumn, 32);
   545         h->resizeSection(RoomsListModel::OwnerColumn, 100);
   543         h->resizeSection(RoomsListModel::OwnerColumn, 100);
   546         h->resizeSection(RoomsListModel::MapColumn, 100);
   544         h->resizeSection(RoomsListModel::MapColumn, 100);
   547         h->resizeSection(RoomsListModel::SchemeColumn, 100);
   545         h->resizeSection(RoomsListModel::SchemeColumn, 100);
   548         h->resizeSection(RoomsListModel::WeaponsColumn, 100);
   546         h->resizeSection(RoomsListModel::WeaponsColumn, 100);
   549     }
   547     }
   550 
   548 
   551     h->setSortIndicatorShown(true);
   549 
   552     h->setResizeMode(RoomsListModel::NameColumn, QHeaderView::Stretch);
   550     // save header state on change
       
   551     connect(roomsList->horizontalHeader(), SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)),
       
   552             this, SLOT(saveHeaderState()));
       
   553     connect(roomsList->horizontalHeader(), SIGNAL(sectionResized(int, int, int)),
       
   554             this, SLOT(saveHeaderState()));
   553 }
   555 }
   554 
   556 
   555 
   557 
   556 void PageRoomsList::onSortIndicatorChanged(int logicalIndex, Qt::SortOrder order)
   558 void PageRoomsList::onSortIndicatorChanged(int logicalIndex, Qt::SortOrder order)
   557 {
   559 {
   558     if (roomsModel == NULL)
   560     if (roomsModel == NULL)
   559         return;
   561         return;
       
   562 
       
   563     if (logicalIndex == 0)
       
   564     {
       
   565         roomsModel->sort(0, Qt::AscendingOrder);
       
   566         return;
       
   567     }
   560 
   568 
   561     // three state sorting: asc -> dsc -> default (by room state)
   569     // three state sorting: asc -> dsc -> default (by room state)
   562     if ((order == Qt::AscendingOrder) && (logicalIndex == roomsModel->sortColumn()))
   570     if ((order == Qt::AscendingOrder) && (logicalIndex == roomsModel->sortColumn()))
   563         roomsList->horizontalHeader()->setSortIndicator(
   571         roomsList->horizontalHeader()->setSortIndicator(
   564             RoomsListModel::StateColumn, Qt::AscendingOrder);
   572             RoomsListModel::StateColumn, Qt::AscendingOrder);
   598 
   606 
   599 bool PageRoomsList::restoreHeaderState()
   607 bool PageRoomsList::restoreHeaderState()
   600 {
   608 {
   601     if (!m_gameSettings->contains("frontend/roomslist_header"))
   609     if (!m_gameSettings->contains("frontend/roomslist_header"))
   602         return false;
   610         return false;
   603     return roomsList->horizontalHeader()->restoreState(QByteArray::fromHex(
   611     return roomsList->horizontalHeader()->restoreState(QByteArray::fromBase64(
   604         (m_gameSettings->value("frontend/roomslist_header").toByteArray())));
   612         (m_gameSettings->value("frontend/roomslist_header").toString().toAscii())));
   605 }
   613 }
   606 
   614 
   607 void PageRoomsList::saveHeaderState()
   615 void PageRoomsList::saveHeaderState()
   608 {
   616 {
   609     m_gameSettings->setValue("frontend/roomslist_header",
   617     m_gameSettings->setValue("frontend/roomslist_header",
   610         roomsList->horizontalHeader()->saveState().toHex());
   618         QString(roomsList->horizontalHeader()->saveState().toBase64()));
   611 }
   619 }