diff --git a/ui/drivers/qt/ui_qt_window.cpp b/ui/drivers/qt/ui_qt_window.cpp index 9ea00b13ff..4b770c723b 100644 --- a/ui/drivers/qt/ui_qt_window.cpp +++ b/ui/drivers/qt/ui_qt_window.cpp @@ -534,6 +534,8 @@ MainWindow::MainWindow(QWidget *parent) : ,m_viewType(VIEW_TYPE_LIST) ,m_gridProgressBar(NULL) ,m_gridProgressWidget(NULL) + ,m_currentGridHash() + ,m_lastViewType(m_viewType) { settings_t *settings = config_get_ptr(); QDir playlistDir(settings->paths.directory_playlist); @@ -776,6 +778,34 @@ MainWindow::~MainWindow() removeGridItems(); } +void MainWindow::onGridItemClicked() +{ + QHash hash; + ThumbnailWidget *w = static_cast(sender()); + + if (!w) + return; + + hash = w->property("hash").value >(); + + m_currentGridHash = hash; + + currentItemChanged(hash); +} + +void MainWindow::onGridItemDoubleClicked() +{ + QHash hash; + ThumbnailWidget *w = static_cast(sender()); + + if (!w) + return; + + hash = w->property("hash").value >(); + + loadContent(hash); +} + void MainWindow::onIconViewClicked() { setCurrentViewType(VIEW_TYPE_ICONS); @@ -1896,9 +1926,12 @@ QHash MainWindow::getSelectedCore() QHash coreHash; QHash contentHash; QTableWidgetItem *contentItem = m_tableWidget->currentItem(); + ViewType viewType = getCurrentViewType(); - if (contentItem) + if (viewType == VIEW_TYPE_LIST && contentItem) contentHash = contentItem->data(Qt::UserRole).value >(); + else if (viewType == VIEW_TYPE_ICONS) + contentHash = m_currentGridHash; switch(coreSelection) { @@ -1949,12 +1982,19 @@ QHash MainWindow::getSelectedCore() return coreHash; } -void MainWindow::onRunClicked() +/* the hash typically has the following keys: +path - absolute path to the content file +core_path - absolute path to the core, or "DETECT" to ask the user +db_name - the display name of the rdb database this content is from +label - the display name of the content, usually comes from the database +crc32 - an upper-case, 8 byte string representation of the hex CRC32 checksum (e.g. ABCDEF12) followed by "|crc" +core_name - the display name of the core, or "DETECT" if unknown +label_noext - the display name of the content that is guaranteed not to contain a file extension +*/ +void MainWindow::loadContent(const QHash &contentHash) { #ifdef HAVE_MENU content_ctx_info_t content_info; - QHash contentHash; - QTableWidgetItem *item = m_tableWidget->currentItem(); QByteArray corePathArray; QByteArray contentPathArray; QByteArray contentLabelArray; @@ -1964,63 +2004,50 @@ void MainWindow::onRunClicked() QVariantMap coreMap = m_launchWithComboBox->currentData(Qt::UserRole).value(); CoreSelection coreSelection = static_cast(coreMap.value("core_selection").toInt()); - if (!item) - return; - if (m_pendingRun) coreSelection = CORE_SELECTION_CURRENT; - contentHash = item->data(Qt::UserRole).value >(); - if (coreSelection == CORE_SELECTION_ASK) { - QTableWidgetItem *item = m_tableWidget->currentItem(); QStringList extensionFilters; - if (item) + if (contentHash.contains("path")) { - QHash hash; + int lastIndex = contentHash["path"].lastIndexOf('.'); + QString extensionStr; + QByteArray pathArray = contentHash["path"].toUtf8(); + const char *pathData = pathArray.constData(); - hash = item->data(Qt::UserRole).value >(); - - if (hash.contains("path")) + if (lastIndex >= 0) { - int lastIndex = hash["path"].lastIndexOf('.'); - QString extensionStr; - QByteArray pathArray = hash["path"].toUtf8(); - const char *pathData = pathArray.constData(); + extensionStr = contentHash["path"].mid(lastIndex + 1); - if (lastIndex >= 0) + if (!extensionStr.isEmpty()) { - extensionStr = hash["path"].mid(lastIndex + 1); - - if (!extensionStr.isEmpty()) - { - extensionFilters.append(extensionStr.toLower()); - } + extensionFilters.append(extensionStr.toLower()); } + } - if (path_is_compressed_file(pathData)) + if (path_is_compressed_file(pathData)) + { + unsigned i = 0; + struct string_list *list = file_archive_get_file_list(pathData, NULL); + + if (list) { - unsigned i = 0; - struct string_list *list = file_archive_get_file_list(pathData, NULL); - - if (list) + if (list->size > 0) { - if (list->size > 0) + for (i = 0; i < list->size; i++) { - for (i = 0; i < list->size; i++) - { - const char *filePath = list->elems[i].data; - const char *extension = path_get_extension(filePath); + const char *filePath = list->elems[i].data; + const char *extension = path_get_extension(filePath); - if (!extensionFilters.contains(extension, Qt::CaseInsensitive)) - extensionFilters.append(extension); - } + if (!extensionFilters.contains(extension, Qt::CaseInsensitive)) + extensionFilters.append(extension); } - - string_list_free(list); } + + string_list_free(list); } } } @@ -2096,6 +2123,25 @@ void MainWindow::onRunClicked() #endif } +void MainWindow::onRunClicked() +{ +#ifdef HAVE_MENU + QTableWidgetItem *item = m_tableWidget->currentItem(); + ViewType viewType = getCurrentViewType(); + QHash contentHash; + + if (!item) + return; + + if (viewType == VIEW_TYPE_LIST) + contentHash = item->data(Qt::UserRole).value >(); + else if (viewType == VIEW_TYPE_ICONS) + contentHash = m_currentGridHash; + + loadContent(contentHash); +#endif +} + bool MainWindow::isContentLessCore() { rarch_system_info_t *system = runloop_get_system_info(); @@ -2164,6 +2210,7 @@ void MainWindow::setCoreActions() { QTableWidgetItem *currentContentItem = m_tableWidget->currentItem(); QListWidgetItem *currentPlaylistItem = m_listWidget->currentItem(); + ViewType viewType = getCurrentViewType(); QHash hash; m_launchWithComboBox->clear(); @@ -2182,8 +2229,10 @@ void MainWindow::setCoreActions() m_launchWithComboBox->addItem(m_currentCore, QVariant::fromValue(comboBoxMap)); } - if (currentContentItem) + if (viewType == VIEW_TYPE_LIST && currentContentItem) hash = currentContentItem->data(Qt::UserRole).value >(); + else if (viewType == VIEW_TYPE_ICONS) + hash = m_currentGridHash; if (m_browserAndPlaylistTabWidget->tabText(m_browserAndPlaylistTabWidget->currentIndex()) == msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_TAB_PLAYLISTS)) { @@ -2341,6 +2390,9 @@ void MainWindow::onTabWidgetIndexChanged(int index) { QModelIndex index = m_dirTree->currentIndex(); + /* force list view for file browser, will set it back to whatever the user had when switching back to playlist tab */ + setCurrentViewType(VIEW_TYPE_LIST); + m_tableWidget->clear(); m_tableWidget->setColumnCount(0); m_tableWidget->setRowCount(0); @@ -2355,6 +2407,9 @@ void MainWindow::onTabWidgetIndexChanged(int index) { QListWidgetItem *item = m_listWidget->currentItem(); + if (m_lastViewType != getCurrentViewType()) + setCurrentViewType(m_lastViewType); + m_tableWidget->clear(); m_tableWidget->setColumnCount(0); m_tableWidget->setRowCount(0); @@ -2544,19 +2599,25 @@ void MainWindow::onSearchEnterPressed() void MainWindow::onCurrentTableItemChanged(QTableWidgetItem *current, QTableWidgetItem *) { - settings_t *settings = config_get_ptr(); QHash hash; - QString label; - QString playlist_name; - QByteArray extension; - QString extensionStr; - int lastIndex = -1; if (!current) return; hash = current->data(Qt::UserRole).value >(); + currentItemChanged(hash); +} + +void MainWindow::currentItemChanged(const QHash &hash) +{ + settings_t *settings = config_get_ptr(); + QString label; + QString playlist_name; + QByteArray extension; + QString extensionStr; + int lastIndex = -1; + label = hash["label_noext"]; label.replace(m_fileSanitizerRegex, "_"); @@ -2674,6 +2735,7 @@ void MainWindow::resizeThumbnails(bool one, bool two, bool three) void MainWindow::setCurrentViewType(ViewType viewType) { + m_lastViewType = m_viewType; m_viewType = viewType; switch (viewType) @@ -3092,6 +3154,11 @@ void MainWindow::addPlaylistItemsToGrid(const QString &pathString, bool setProgr item->widget->setLayout(new QVBoxLayout()); item->widget->setStyleSheet("background-color: #555555"); + item->widget->setProperty("hash", QVariant::fromValue >(hash)); + + connect(item->widget, SIGNAL(mouseDoubleClicked()), this, SLOT(onGridItemDoubleClicked())); + connect(item->widget, SIGNAL(mousePressed()), this, SLOT(onGridItemClicked())); + label = new ThumbnailLabel(item->widget); item->label = label; diff --git a/ui/drivers/ui_qt.cpp b/ui/drivers/ui_qt.cpp index 5229843ab9..ba0644b285 100644 --- a/ui/drivers/ui_qt.cpp +++ b/ui/drivers/ui_qt.cpp @@ -61,17 +61,31 @@ ThumbnailWidget::ThumbnailWidget(QWidget *parent) : { } +void ThumbnailWidget::mousePressEvent(QMouseEvent *event) +{ + QWidget::mousePressEvent(event); + + emit mousePressed(); +} + +void ThumbnailWidget::mouseDoubleClickEvent(QMouseEvent *event) +{ + QWidget::mouseDoubleClickEvent(event); + + emit mouseDoubleClicked(); +} + void ThumbnailWidget::paintEvent(QPaintEvent *event) { - QStyleOption o; - QPainter p; - o.initFrom(this); - p.begin(this); - style()->drawPrimitive( - QStyle::PE_Widget, &o, &p, this); - p.end(); + QStyleOption o; + QPainter p; + o.initFrom(this); + p.begin(this); + style()->drawPrimitive( + QStyle::PE_Widget, &o, &p, this); + p.end(); - QWidget::paintEvent(event); + QWidget::paintEvent(event); } void ThumbnailWidget::resizeEvent(QResizeEvent *event) @@ -497,6 +511,9 @@ static void* ui_companion_qt_init(void) mainwindow->setCurrentViewType(MainWindow::VIEW_TYPE_ICONS); else mainwindow->setCurrentViewType(MainWindow::VIEW_TYPE_LIST); + + /* we set it to the same thing a second time so that m_lastViewType is also equal to the startup view type */ + mainwindow->setCurrentViewType(mainwindow->getCurrentViewType()); } else mainwindow->setCurrentViewType(MainWindow::VIEW_TYPE_LIST); diff --git a/ui/drivers/ui_qt.h b/ui/drivers/ui_qt.h index 20d8f99b76..941a49ba5e 100644 --- a/ui/drivers/ui_qt.h +++ b/ui/drivers/ui_qt.h @@ -88,11 +88,16 @@ public: ThumbnailWidget(QWidget *parent = 0); QSize sizeHint() const; void setSizeHint(QSize size); +signals: + void mouseDoubleClicked(); + void mousePressed(); private: QSize m_sizeHint; protected: void paintEvent(QPaintEvent *event); void resizeEvent(QResizeEvent *event); + void mouseDoubleClickEvent(QMouseEvent *event); + void mousePressEvent(QMouseEvent *event); }; class ThumbnailLabel : public QWidget @@ -281,6 +286,8 @@ public: const QString& customThemeString() const; GridItem* doDeferredImageLoad(GridItem *item, QString path); void setCurrentViewType(ViewType viewType); + QString getCurrentViewTypeString(); + ViewType getCurrentViewType(); signals: void thumbnailChanged(const QPixmap &pixmap); @@ -300,6 +307,7 @@ public slots: void onShowHiddenDockWidgetAction(); void setCoreActions(); void onRunClicked(); + void loadContent(const QHash &contentHash); void onStartCoreClicked(); void onTableWidgetEnterPressed(); void selectBrowserDir(QString path); @@ -325,6 +333,7 @@ private slots: void onCoreLoaded(); void onCurrentListItemChanged(QListWidgetItem *current, QListWidgetItem *previous); void onCurrentTableItemChanged(QTableWidgetItem *current, QTableWidgetItem *previous); + void currentItemChanged(const QHash &hash); void onSearchEnterPressed(); void onSearchLineEditEdited(const QString &text); void addPlaylistItemsToTable(QString path); @@ -342,6 +351,8 @@ private slots: void onContentGridInited(); void onUpdateGridItemPixmapFromImage(GridItem *item); void onPendingItemUpdates(); + void onGridItemDoubleClicked(); + void onGridItemClicked(); private: void setCurrentCoreLabel(); @@ -352,8 +363,6 @@ private: void loadImageDeferred(GridItem *item, QString path); void calcGridItemSize(GridItem *item, int zoomValue); QVector > getPlaylistItems(QString pathString); - QString getCurrentViewTypeString(); - ViewType getCurrentViewType(); LoadCoreWindow *m_loadCoreWindow; QTimer *m_timer; @@ -406,6 +415,8 @@ private: ViewType m_viewType; QProgressBar *m_gridProgressBar; QWidget *m_gridProgressWidget; + QHash m_currentGridHash; + ViewType m_lastViewType; protected: void closeEvent(QCloseEvent *event);