@ -64,7 +64,7 @@ bool GameListSearchField::KeyReleaseEater::eventFilter(QObject* obj, QEvent* eve
case Qt : : Key_Return :
case Qt : : Key_Return :
case Qt : : Key_Enter : {
case Qt : : Key_Enter : {
if ( gamelist - > search_field - > visible = = 1 ) {
if ( gamelist - > search_field - > visible = = 1 ) {
QString file_path = gamelist - > g etLastFilterResultItem( ) ;
const QString file_path = gamelist - > G etLastFilterResultItem( ) ;
// To avoid loading error dialog loops while confirming them using enter
// To avoid loading error dialog loops while confirming them using enter
// Also users usually want to run a different game after closing one
// Also users usually want to run a different game after closing one
@ -99,22 +99,25 @@ void GameListSearchField::setFilterResult(int visible, int total) {
QStringLiteral ( " %1 %2 %3 %4 " ) . arg ( visible ) . arg ( result_of_text ) . arg ( total ) . arg ( result_text ) ) ;
QStringLiteral ( " %1 %2 %3 %4 " ) . arg ( visible ) . arg ( result_of_text ) . arg ( total ) . arg ( result_text ) ) ;
}
}
QString GameList : : getLastFilterResultItem ( ) const {
QString GameList : : GetLastFilterResultItem ( ) const {
QStandardItem * folder ;
QStandardItem * child ;
QString file_path ;
QString file_path ;
const int folderCount = item_model - > rowCount ( ) ;
const int folderCount = item_model - > rowCount ( ) ;
for ( int i = 0 ; i < folderCount ; + + i ) {
for ( int i = 0 ; i < folderCount ; + + i ) {
folder = item_model - > item ( i , 0 ) ;
const QStandardItem * folder = item_model - > item ( i , 0 ) ;
const QModelIndex folder_index = folder - > index ( ) ;
const QModelIndex folder_index = folder - > index ( ) ;
const int children_count = folder - > rowCount ( ) ;
const int children_count = folder - > rowCount ( ) ;
for ( int j = 0 ; j < children_count ; + + j ) {
for ( int j = 0 ; j < children_count ; + + j ) {
if ( ! tree_view - > isRowHidden ( j , folder_index ) ) {
if ( tree_view - > isRowHidden ( j , folder_index ) ) {
child = folder - > child ( j , 0 ) ;
continue ;
file_path = child - > data ( GameListItemPath : : FullPathRole ) . toString ( ) ;
}
}
const QStandardItem * child = folder - > child ( j , 0 ) ;
file_path = child - > data ( GameListItemPath : : FullPathRole ) . toString ( ) ;
}
}
}
}
return file_path ;
return file_path ;
}
}
@ -139,7 +142,7 @@ GameListSearchField::GameListSearchField(GameList* parent) : QWidget{parent} {
edit_filter - > setPlaceholderText ( tr ( " Enter pattern to filter " ) ) ;
edit_filter - > setPlaceholderText ( tr ( " Enter pattern to filter " ) ) ;
edit_filter - > installEventFilter ( key_release_eater ) ;
edit_filter - > installEventFilter ( key_release_eater ) ;
edit_filter - > setClearButtonEnabled ( true ) ;
edit_filter - > setClearButtonEnabled ( true ) ;
connect ( edit_filter , & QLineEdit : : textChanged , parent , & GameList : : o nTextChanged) ;
connect ( edit_filter , & QLineEdit : : textChanged , parent , & GameList : : O nTextChanged) ;
label_filter_result = new QLabel ;
label_filter_result = new QLabel ;
button_filter_close = new QToolButton ( this ) ;
button_filter_close = new QToolButton ( this ) ;
button_filter_close - > setText ( QStringLiteral ( " X " ) ) ;
button_filter_close - > setText ( QStringLiteral ( " X " ) ) ;
@ -149,7 +152,7 @@ GameListSearchField::GameListSearchField(GameList* parent) : QWidget{parent} {
" #000000; font-weight: bold; background: #F0F0F0; } "
" #000000; font-weight: bold; background: #F0F0F0; } "
" QToolButton:hover{ border: none; padding: 0px; color: "
" QToolButton:hover{ border: none; padding: 0px; color: "
" #EEEEEE; font-weight: bold; background: #E81123} " ) ) ;
" #EEEEEE; font-weight: bold; background: #E81123} " ) ) ;
connect ( button_filter_close , & QToolButton : : clicked , parent , & GameList : : o nFilterCloseClicked) ;
connect ( button_filter_close , & QToolButton : : clicked , parent , & GameList : : O nFilterCloseClicked) ;
layout_filter - > setSpacing ( 10 ) ;
layout_filter - > setSpacing ( 10 ) ;
layout_filter - > addWidget ( label_filter ) ;
layout_filter - > addWidget ( label_filter ) ;
layout_filter - > addWidget ( edit_filter ) ;
layout_filter - > addWidget ( edit_filter ) ;
@ -175,16 +178,22 @@ static bool ContainsAllWords(const QString& haystack, const QString& userinput)
}
}
// Syncs the expanded state of Game Directories with settings to persist across sessions
// Syncs the expanded state of Game Directories with settings to persist across sessions
void GameList : : o nItemExpanded( const QModelIndex & item ) {
void GameList : : O nItemExpanded( const QModelIndex & item ) {
const auto type = item . data ( GameListItem : : TypeRole ) . value < GameListItemType > ( ) ;
const auto type = item . data ( GameListItem : : TypeRole ) . value < GameListItemType > ( ) ;
if ( type = = GameListItemType : : CustomDir | | type = = GameListItemType : : InstalledDir | |
const bool is_dir = type = = GameListItemType : : CustomDir | |
type = = GameListItemType : : SystemDir )
type = = GameListItemType : : InstalledDir | |
UISettings : : values . game_dirs [ item . data ( GameListDir : : GameDirRole ) . toInt ( ) ] . expanded =
type = = GameListItemType : : SystemDir ;
tree_view - > isExpanded ( item ) ;
if ( ! is_dir ) {
return ;
}
UISettings : : values . game_dirs [ item . data ( GameListDir : : GameDirRole ) . toInt ( ) ] . expanded =
tree_view - > isExpanded ( item ) ;
}
}
// Event in order to filter the gamelist after editing the searchfield
// Event in order to filter the gamelist after editing the searchfield
void GameList : : onTextChanged ( const QString & new_text ) {
void GameList : : O nTextChanged( const QString & new_text ) {
const int folder_count = tree_view - > model ( ) - > rowCount ( ) ;
const int folder_count = tree_view - > model ( ) - > rowCount ( ) ;
QString edit_filter_text = new_text . toLower ( ) ;
QString edit_filter_text = new_text . toLower ( ) ;
QStandardItem * folder ;
QStandardItem * folder ;
@ -240,7 +249,7 @@ void GameList::onTextChanged(const QString& new_text) {
}
}
}
}
void GameList : : o nUpdateThemedIcons( ) {
void GameList : : O nUpdateThemedIcons( ) {
for ( int i = 0 ; i < item_model - > invisibleRootItem ( ) - > rowCount ( ) ; i + + ) {
for ( int i = 0 ; i < item_model - > invisibleRootItem ( ) - > rowCount ( ) ; i + + ) {
QStandardItem * child = item_model - > invisibleRootItem ( ) - > child ( i ) ;
QStandardItem * child = item_model - > invisibleRootItem ( ) - > child ( i ) ;
@ -270,7 +279,7 @@ void GameList::onUpdateThemedIcons() {
}
}
}
}
void GameList : : o nFilterCloseClicked( ) {
void GameList : : O nFilterCloseClicked( ) {
main_window - > filterBarSetChecked ( false ) ;
main_window - > filterBarSetChecked ( false ) ;
}
}
@ -304,11 +313,11 @@ GameList::GameList(GMainWindow* parent) : QWidget{parent} {
item_model - > setHeaderData ( COLUMN_SIZE , Qt : : Horizontal , tr ( " Size " ) ) ;
item_model - > setHeaderData ( COLUMN_SIZE , Qt : : Horizontal , tr ( " Size " ) ) ;
item_model - > setSortRole ( GameListItemPath : : SortRole ) ;
item_model - > setSortRole ( GameListItemPath : : SortRole ) ;
connect ( main_window , & GMainWindow : : UpdateThemedIcons , this , & GameList : : o nUpdateThemedIcons) ;
connect ( main_window , & GMainWindow : : UpdateThemedIcons , this , & GameList : : O nUpdateThemedIcons) ;
connect ( tree_view , & QTreeView : : activated , this , & GameList : : ValidateEntry ) ;
connect ( tree_view , & QTreeView : : activated , this , & GameList : : ValidateEntry ) ;
connect ( tree_view , & QTreeView : : customContextMenuRequested , this , & GameList : : PopupContextMenu ) ;
connect ( tree_view , & QTreeView : : customContextMenuRequested , this , & GameList : : PopupContextMenu ) ;
connect ( tree_view , & QTreeView : : expanded , this , & GameList : : o nItemExpanded) ;
connect ( tree_view , & QTreeView : : expanded , this , & GameList : : O nItemExpanded) ;
connect ( tree_view , & QTreeView : : collapsed , this , & GameList : : o nItemExpanded) ;
connect ( tree_view , & QTreeView : : collapsed , this , & GameList : : O nItemExpanded) ;
// We must register all custom types with the Qt Automoc system so that we are able to use
// We must register all custom types with the Qt Automoc system so that we are able to use
// it with signals/slots. In this case, QList falls under the umbrells of custom types.
// it with signals/slots. In this case, QList falls under the umbrells of custom types.
@ -325,17 +334,17 @@ GameList::~GameList() {
emit ShouldCancelWorker ( ) ;
emit ShouldCancelWorker ( ) ;
}
}
void GameList : : s etFilterFocus( ) {
void GameList : : S etFilterFocus( ) {
if ( tree_view - > model ( ) - > rowCount ( ) > 0 ) {
if ( tree_view - > model ( ) - > rowCount ( ) > 0 ) {
search_field - > setFocus ( ) ;
search_field - > setFocus ( ) ;
}
}
}
}
void GameList : : s etFilterVisible( bool visibility ) {
void GameList : : S etFilterVisible( bool visibility ) {
search_field - > setVisible ( visibility ) ;
search_field - > setVisible ( visibility ) ;
}
}
void GameList : : s etDirectoryWatcherEnabled( bool enabled ) {
void GameList : : S etDirectoryWatcherEnabled( bool enabled ) {
if ( enabled ) {
if ( enabled ) {
connect ( watcher , & QFileSystemWatcher : : directoryChanged , this ,
connect ( watcher , & QFileSystemWatcher : : directoryChanged , this ,
& GameList : : RefreshGameDirectory , Qt : : UniqueConnection ) ;
& GameList : : RefreshGameDirectory , Qt : : UniqueConnection ) ;
@ -345,7 +354,7 @@ void GameList::setDirectoryWatcherEnabled(bool enabled) {
}
}
}
}
void GameList : : c learFilter( ) {
void GameList : : C learFilter( ) {
search_field - > clear ( ) ;
search_field - > clear ( ) ;
}
}
@ -384,21 +393,23 @@ void GameList::ValidateEntry(const QModelIndex& item) {
}
}
}
}
bool GameList : : i sEmpty( ) const {
bool GameList : : I sEmpty( ) const {
for ( int i = 0 ; i < item_model - > rowCount ( ) ; i + + ) {
for ( int i = 0 ; i < item_model - > rowCount ( ) ; i + + ) {
const QStandardItem * child = item_model - > invisibleRootItem ( ) - > child ( i ) ;
const QStandardItem * child = item_model - > invisibleRootItem ( ) - > child ( i ) ;
const auto type = static_cast < GameListItemType > ( child - > type ( ) ) ;
const auto type = static_cast < GameListItemType > ( child - > type ( ) ) ;
if ( ! child - > hasChildren ( ) & &
if ( ! child - > hasChildren ( ) & &
( type = = GameListItemType : : InstalledDir | | type = = GameListItemType : : SystemDir ) ) {
( type = = GameListItemType : : InstalledDir | | type = = GameListItemType : : SystemDir ) ) {
item_model - > invisibleRootItem ( ) - > removeRow ( child - > row ( ) ) ;
item_model - > invisibleRootItem ( ) - > removeRow ( child - > row ( ) ) ;
i - - ;
i - - ;
}
}
}
}
return ! item_model - > invisibleRootItem ( ) - > hasChildren ( ) ;
return ! item_model - > invisibleRootItem ( ) - > hasChildren ( ) ;
}
}
void GameList : : DonePopulating ( QStringList watch_list ) {
void GameList : : DonePopulating ( const QStringList & watch_list ) {
emit ShowList ( ! i sEmpty( ) ) ;
emit ShowList ( ! I sEmpty( ) ) ;
item_model - > invisibleRootItem ( ) - > appendRow ( new GameListAddDir ( ) ) ;
item_model - > invisibleRootItem ( ) - > appendRow ( new GameListAddDir ( ) ) ;
@ -689,12 +700,15 @@ void GameList::SaveInterfaceLayout() {
}
}
void GameList : : LoadInterfaceLayout ( ) {
void GameList : : LoadInterfaceLayout ( ) {
auto header = tree_view - > header ( ) ;
auto * header = tree_view - > header ( ) ;
if ( ! header - > restoreState ( UISettings : : values . gamelist_header_state ) ) {
// We are using the name column to display icons and titles
if ( header - > restoreState ( UISettings : : values . gamelist_header_state ) ) {
// so make it as large as possible as default.
return ;
header - > resizeSection ( COLUMN_NAME , header - > width ( ) ) ;
}
}
// We are using the name column to display icons and titles
// so make it as large as possible as default.
header - > resizeSection ( COLUMN_NAME , header - > width ( ) ) ;
}
}
const QStringList GameList : : supported_file_extensions = {
const QStringList GameList : : supported_file_extensions = {