bool wxHeaderCtrlBase::ShowColumnsMenu(const wxPoint& pt, const wxString& title) { // construct the menu with the entries for all columns wxMenu menu; if ( !title.empty() ) menu.SetTitle(title); AddColumnsItems(menu); // ... and an extra one to show the customization dialog if the user is // allowed to reorder the columns too const unsigned count = GetColumnCount(); if ( HasFlag(wxHD_ALLOW_REORDER) ) { menu.AppendSeparator(); menu.Append(count, _("&Customize...")); } // do show the menu and get the user selection const int rc = GetPopupMenuSelectionFromUser(menu, pt); if ( rc == wxID_NONE ) return false; if ( static_cast<unsigned>(rc) == count ) { return ShowCustomizeDialog(); } else // a column selected from the menu { UpdateColumnVisibility(rc, !GetColumn(rc).IsShown()); } return true; }
void GameList::SetSearchTerm(const QString& term) { m_model->SetSearchTerm(term); m_list_proxy->invalidate(); m_grid_proxy->invalidate(); UpdateColumnVisibility(); }
bool wxHeaderCtrlBase::ShowCustomizeDialog() { #if wxUSE_REARRANGECTRL // prepare the data for showing the dialog wxArrayInt order = GetColumnsOrder(); const unsigned count = GetColumnCount(); // notice that titles are always in the index order, they will be shown // rearranged according to the display order in the dialog wxArrayString titles; titles.reserve(count); for ( unsigned n = 0; n < count; n++ ) titles.push_back(GetColumn(n).GetTitle()); // this loop is however over positions and not indices unsigned pos; for ( pos = 0; pos < count; pos++ ) { int& idx = order[pos]; if ( GetColumn(idx).IsHidden() ) { // indicate that this one is hidden idx = ~idx; } } // do show it wxHeaderColumnsRearrangeDialog dlg(this, order, titles); if ( dlg.ShowModal() == wxID_OK ) { // and apply the changes order = dlg.GetOrder(); for ( pos = 0; pos < count; pos++ ) { int& idx = order[pos]; const bool show = idx >= 0; if ( !show ) { // make all indices positive for passing them to SetColumnsOrder() idx = ~idx; } if ( show != GetColumn(idx).IsShown() ) UpdateColumnVisibility(idx, show); } UpdateColumnsOrder(order); SetColumnsOrder(order); return true; } #endif // wxUSE_REARRANGECTRL return false; }
void GameList::OnHeaderViewChanged() { static bool block = false; if (block) return; block = true; UpdateColumnVisibility(); // So here's the deal: Qt's way of resizing stuff around stretched columns sucks ass // That's why instead of using Stretch, we'll just make resizable columns take all the available // space ourselves! int available_width = width() - style()->pixelMetric(QStyle::PM_ScrollBarExtent); int previous_width = 0; std::vector<int> candidate_columns; // Iterate through all columns for (int i = 0; i < GameListModel::NUM_COLS; i++) { if (m_list->isColumnHidden(i)) continue; if (m_list->horizontalHeader()->sectionResizeMode(i) == QHeaderView::Fixed) { available_width -= m_list->columnWidth(i); } else { candidate_columns.push_back(i); previous_width += m_list->columnWidth(i); } } for (int column : candidate_columns) { int column_width = static_cast<int>( std::max(5.f, std::ceil(available_width * (static_cast<float>(m_list->columnWidth(column)) / previous_width)))); m_list->setColumnWidth(column, column_width); } block = false; }
void GameList::MakeListView() { m_list = new QTableView(this); m_list->setModel(m_list_proxy); m_list->setSelectionMode(QAbstractItemView::ExtendedSelection); m_list->setSelectionBehavior(QAbstractItemView::SelectRows); m_list->setAlternatingRowColors(true); m_list->setShowGrid(false); m_list->setSortingEnabled(true); m_list->setCurrentIndex(QModelIndex()); m_list->setContextMenuPolicy(Qt::CustomContextMenu); m_list->setWordWrap(false); // Have 1 pixel of padding above and below the 32 pixel banners. m_list->verticalHeader()->setDefaultSectionSize(32 + 2); connect(m_list, &QTableView::customContextMenuRequested, this, &GameList::ShowContextMenu); connect(m_list->selectionModel(), &QItemSelectionModel::selectionChanged, [this](const QItemSelection&, const QItemSelection&) { emit SelectionChanged(GetSelectedGame()); }); QHeaderView* hor_header = m_list->horizontalHeader(); hor_header->restoreState( Settings::GetQSettings().value(QStringLiteral("tableheader/state")).toByteArray()); hor_header->setContextMenuPolicy(Qt::CustomContextMenu); connect(hor_header, &QWidget::customContextMenuRequested, this, &GameList::ShowHeaderContextMenu); connect(hor_header, &QHeaderView::sortIndicatorChanged, this, &GameList::OnHeaderViewChanged); connect(hor_header, &QHeaderView::sectionCountChanged, this, &GameList::OnHeaderViewChanged); connect(hor_header, &QHeaderView::sectionMoved, this, &GameList::OnHeaderViewChanged); connect(hor_header, &QHeaderView::sectionResized, this, &GameList::OnSectionResized); if (!Settings::GetQSettings().contains(QStringLiteral("tableheader/state"))) m_list->sortByColumn(GameListModel::COL_TITLE, Qt::AscendingOrder); hor_header->setSectionResizeMode(GameListModel::COL_PLATFORM, QHeaderView::Fixed); hor_header->setSectionResizeMode(GameListModel::COL_BANNER, QHeaderView::Fixed); hor_header->setSectionResizeMode(GameListModel::COL_TITLE, QHeaderView::Interactive); hor_header->setSectionResizeMode(GameListModel::COL_DESCRIPTION, QHeaderView::Interactive); hor_header->setSectionResizeMode(GameListModel::COL_MAKER, QHeaderView::Interactive); hor_header->setSectionResizeMode(GameListModel::COL_ID, QHeaderView::Fixed); hor_header->setSectionResizeMode(GameListModel::COL_COUNTRY, QHeaderView::Fixed); hor_header->setSectionResizeMode(GameListModel::COL_SIZE, QHeaderView::Fixed); hor_header->setSectionResizeMode(GameListModel::COL_FILE_NAME, QHeaderView::Interactive); hor_header->setSectionResizeMode(GameListModel::COL_TAGS, QHeaderView::Interactive); // There's some odd platform-specific behavior with default minimum section size hor_header->setMinimumSectionSize(38); // Cells have 3 pixels of padding, so the width of these needs to be image width + 6. Banners are // 96 pixels wide, platform and country icons are 32 pixels wide. m_list->setColumnWidth(GameListModel::COL_BANNER, 102); m_list->setColumnWidth(GameListModel::COL_PLATFORM, 38); m_list->setColumnWidth(GameListModel::COL_COUNTRY, 38); m_list->setColumnWidth(GameListModel::COL_SIZE, 85); m_list->setColumnWidth(GameListModel::COL_ID, 70); UpdateColumnVisibility(); m_list->verticalHeader()->hide(); m_list->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); m_list->setFrameStyle(QFrame::NoFrame); hor_header->setSectionsMovable(true); hor_header->setHighlightSections(false); }