Qt: hook up grid view click/doubleclick events
This commit is contained in:
parent
1293447aab
commit
c8a814ae40
|
@ -534,6 +534,8 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||||
,m_viewType(VIEW_TYPE_LIST)
|
,m_viewType(VIEW_TYPE_LIST)
|
||||||
,m_gridProgressBar(NULL)
|
,m_gridProgressBar(NULL)
|
||||||
,m_gridProgressWidget(NULL)
|
,m_gridProgressWidget(NULL)
|
||||||
|
,m_currentGridHash()
|
||||||
|
,m_lastViewType(m_viewType)
|
||||||
{
|
{
|
||||||
settings_t *settings = config_get_ptr();
|
settings_t *settings = config_get_ptr();
|
||||||
QDir playlistDir(settings->paths.directory_playlist);
|
QDir playlistDir(settings->paths.directory_playlist);
|
||||||
|
@ -776,6 +778,34 @@ MainWindow::~MainWindow()
|
||||||
removeGridItems();
|
removeGridItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::onGridItemClicked()
|
||||||
|
{
|
||||||
|
QHash<QString, QString> hash;
|
||||||
|
ThumbnailWidget *w = static_cast<ThumbnailWidget*>(sender());
|
||||||
|
|
||||||
|
if (!w)
|
||||||
|
return;
|
||||||
|
|
||||||
|
hash = w->property("hash").value<QHash<QString, QString> >();
|
||||||
|
|
||||||
|
m_currentGridHash = hash;
|
||||||
|
|
||||||
|
currentItemChanged(hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onGridItemDoubleClicked()
|
||||||
|
{
|
||||||
|
QHash<QString, QString> hash;
|
||||||
|
ThumbnailWidget *w = static_cast<ThumbnailWidget*>(sender());
|
||||||
|
|
||||||
|
if (!w)
|
||||||
|
return;
|
||||||
|
|
||||||
|
hash = w->property("hash").value<QHash<QString, QString> >();
|
||||||
|
|
||||||
|
loadContent(hash);
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::onIconViewClicked()
|
void MainWindow::onIconViewClicked()
|
||||||
{
|
{
|
||||||
setCurrentViewType(VIEW_TYPE_ICONS);
|
setCurrentViewType(VIEW_TYPE_ICONS);
|
||||||
|
@ -1896,9 +1926,12 @@ QHash<QString, QString> MainWindow::getSelectedCore()
|
||||||
QHash<QString, QString> coreHash;
|
QHash<QString, QString> coreHash;
|
||||||
QHash<QString, QString> contentHash;
|
QHash<QString, QString> contentHash;
|
||||||
QTableWidgetItem *contentItem = m_tableWidget->currentItem();
|
QTableWidgetItem *contentItem = m_tableWidget->currentItem();
|
||||||
|
ViewType viewType = getCurrentViewType();
|
||||||
|
|
||||||
if (contentItem)
|
if (viewType == VIEW_TYPE_LIST && contentItem)
|
||||||
contentHash = contentItem->data(Qt::UserRole).value<QHash<QString, QString> >();
|
contentHash = contentItem->data(Qt::UserRole).value<QHash<QString, QString> >();
|
||||||
|
else if (viewType == VIEW_TYPE_ICONS)
|
||||||
|
contentHash = m_currentGridHash;
|
||||||
|
|
||||||
switch(coreSelection)
|
switch(coreSelection)
|
||||||
{
|
{
|
||||||
|
@ -1949,12 +1982,19 @@ QHash<QString, QString> MainWindow::getSelectedCore()
|
||||||
return coreHash;
|
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<QString, QString> &contentHash)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_MENU
|
#ifdef HAVE_MENU
|
||||||
content_ctx_info_t content_info;
|
content_ctx_info_t content_info;
|
||||||
QHash<QString, QString> contentHash;
|
|
||||||
QTableWidgetItem *item = m_tableWidget->currentItem();
|
|
||||||
QByteArray corePathArray;
|
QByteArray corePathArray;
|
||||||
QByteArray contentPathArray;
|
QByteArray contentPathArray;
|
||||||
QByteArray contentLabelArray;
|
QByteArray contentLabelArray;
|
||||||
|
@ -1964,35 +2004,23 @@ void MainWindow::onRunClicked()
|
||||||
QVariantMap coreMap = m_launchWithComboBox->currentData(Qt::UserRole).value<QVariantMap>();
|
QVariantMap coreMap = m_launchWithComboBox->currentData(Qt::UserRole).value<QVariantMap>();
|
||||||
CoreSelection coreSelection = static_cast<CoreSelection>(coreMap.value("core_selection").toInt());
|
CoreSelection coreSelection = static_cast<CoreSelection>(coreMap.value("core_selection").toInt());
|
||||||
|
|
||||||
if (!item)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (m_pendingRun)
|
if (m_pendingRun)
|
||||||
coreSelection = CORE_SELECTION_CURRENT;
|
coreSelection = CORE_SELECTION_CURRENT;
|
||||||
|
|
||||||
contentHash = item->data(Qt::UserRole).value<QHash<QString, QString> >();
|
|
||||||
|
|
||||||
if (coreSelection == CORE_SELECTION_ASK)
|
if (coreSelection == CORE_SELECTION_ASK)
|
||||||
{
|
{
|
||||||
QTableWidgetItem *item = m_tableWidget->currentItem();
|
|
||||||
QStringList extensionFilters;
|
QStringList extensionFilters;
|
||||||
|
|
||||||
if (item)
|
if (contentHash.contains("path"))
|
||||||
{
|
{
|
||||||
QHash<QString, QString> hash;
|
int lastIndex = contentHash["path"].lastIndexOf('.');
|
||||||
|
|
||||||
hash = item->data(Qt::UserRole).value<QHash<QString, QString> >();
|
|
||||||
|
|
||||||
if (hash.contains("path"))
|
|
||||||
{
|
|
||||||
int lastIndex = hash["path"].lastIndexOf('.');
|
|
||||||
QString extensionStr;
|
QString extensionStr;
|
||||||
QByteArray pathArray = hash["path"].toUtf8();
|
QByteArray pathArray = contentHash["path"].toUtf8();
|
||||||
const char *pathData = pathArray.constData();
|
const char *pathData = pathArray.constData();
|
||||||
|
|
||||||
if (lastIndex >= 0)
|
if (lastIndex >= 0)
|
||||||
{
|
{
|
||||||
extensionStr = hash["path"].mid(lastIndex + 1);
|
extensionStr = contentHash["path"].mid(lastIndex + 1);
|
||||||
|
|
||||||
if (!extensionStr.isEmpty())
|
if (!extensionStr.isEmpty())
|
||||||
{
|
{
|
||||||
|
@ -2023,7 +2051,6 @@ void MainWindow::onRunClicked()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
m_pendingRun = true;
|
m_pendingRun = true;
|
||||||
onLoadCoreClicked(extensionFilters);
|
onLoadCoreClicked(extensionFilters);
|
||||||
|
@ -2096,6 +2123,25 @@ void MainWindow::onRunClicked()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::onRunClicked()
|
||||||
|
{
|
||||||
|
#ifdef HAVE_MENU
|
||||||
|
QTableWidgetItem *item = m_tableWidget->currentItem();
|
||||||
|
ViewType viewType = getCurrentViewType();
|
||||||
|
QHash<QString, QString> contentHash;
|
||||||
|
|
||||||
|
if (!item)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (viewType == VIEW_TYPE_LIST)
|
||||||
|
contentHash = item->data(Qt::UserRole).value<QHash<QString, QString> >();
|
||||||
|
else if (viewType == VIEW_TYPE_ICONS)
|
||||||
|
contentHash = m_currentGridHash;
|
||||||
|
|
||||||
|
loadContent(contentHash);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
bool MainWindow::isContentLessCore()
|
bool MainWindow::isContentLessCore()
|
||||||
{
|
{
|
||||||
rarch_system_info_t *system = runloop_get_system_info();
|
rarch_system_info_t *system = runloop_get_system_info();
|
||||||
|
@ -2164,6 +2210,7 @@ void MainWindow::setCoreActions()
|
||||||
{
|
{
|
||||||
QTableWidgetItem *currentContentItem = m_tableWidget->currentItem();
|
QTableWidgetItem *currentContentItem = m_tableWidget->currentItem();
|
||||||
QListWidgetItem *currentPlaylistItem = m_listWidget->currentItem();
|
QListWidgetItem *currentPlaylistItem = m_listWidget->currentItem();
|
||||||
|
ViewType viewType = getCurrentViewType();
|
||||||
QHash<QString, QString> hash;
|
QHash<QString, QString> hash;
|
||||||
|
|
||||||
m_launchWithComboBox->clear();
|
m_launchWithComboBox->clear();
|
||||||
|
@ -2182,8 +2229,10 @@ void MainWindow::setCoreActions()
|
||||||
m_launchWithComboBox->addItem(m_currentCore, QVariant::fromValue(comboBoxMap));
|
m_launchWithComboBox->addItem(m_currentCore, QVariant::fromValue(comboBoxMap));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentContentItem)
|
if (viewType == VIEW_TYPE_LIST && currentContentItem)
|
||||||
hash = currentContentItem->data(Qt::UserRole).value<QHash<QString, QString> >();
|
hash = currentContentItem->data(Qt::UserRole).value<QHash<QString, QString> >();
|
||||||
|
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))
|
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();
|
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->clear();
|
||||||
m_tableWidget->setColumnCount(0);
|
m_tableWidget->setColumnCount(0);
|
||||||
m_tableWidget->setRowCount(0);
|
m_tableWidget->setRowCount(0);
|
||||||
|
@ -2355,6 +2407,9 @@ void MainWindow::onTabWidgetIndexChanged(int index)
|
||||||
{
|
{
|
||||||
QListWidgetItem *item = m_listWidget->currentItem();
|
QListWidgetItem *item = m_listWidget->currentItem();
|
||||||
|
|
||||||
|
if (m_lastViewType != getCurrentViewType())
|
||||||
|
setCurrentViewType(m_lastViewType);
|
||||||
|
|
||||||
m_tableWidget->clear();
|
m_tableWidget->clear();
|
||||||
m_tableWidget->setColumnCount(0);
|
m_tableWidget->setColumnCount(0);
|
||||||
m_tableWidget->setRowCount(0);
|
m_tableWidget->setRowCount(0);
|
||||||
|
@ -2544,19 +2599,25 @@ void MainWindow::onSearchEnterPressed()
|
||||||
|
|
||||||
void MainWindow::onCurrentTableItemChanged(QTableWidgetItem *current, QTableWidgetItem *)
|
void MainWindow::onCurrentTableItemChanged(QTableWidgetItem *current, QTableWidgetItem *)
|
||||||
{
|
{
|
||||||
settings_t *settings = config_get_ptr();
|
|
||||||
QHash<QString, QString> hash;
|
QHash<QString, QString> hash;
|
||||||
QString label;
|
|
||||||
QString playlist_name;
|
|
||||||
QByteArray extension;
|
|
||||||
QString extensionStr;
|
|
||||||
int lastIndex = -1;
|
|
||||||
|
|
||||||
if (!current)
|
if (!current)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
hash = current->data(Qt::UserRole).value<QHash<QString, QString> >();
|
hash = current->data(Qt::UserRole).value<QHash<QString, QString> >();
|
||||||
|
|
||||||
|
currentItemChanged(hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::currentItemChanged(const QHash<QString, QString> &hash)
|
||||||
|
{
|
||||||
|
settings_t *settings = config_get_ptr();
|
||||||
|
QString label;
|
||||||
|
QString playlist_name;
|
||||||
|
QByteArray extension;
|
||||||
|
QString extensionStr;
|
||||||
|
int lastIndex = -1;
|
||||||
|
|
||||||
label = hash["label_noext"];
|
label = hash["label_noext"];
|
||||||
label.replace(m_fileSanitizerRegex, "_");
|
label.replace(m_fileSanitizerRegex, "_");
|
||||||
|
|
||||||
|
@ -2674,6 +2735,7 @@ void MainWindow::resizeThumbnails(bool one, bool two, bool three)
|
||||||
|
|
||||||
void MainWindow::setCurrentViewType(ViewType viewType)
|
void MainWindow::setCurrentViewType(ViewType viewType)
|
||||||
{
|
{
|
||||||
|
m_lastViewType = m_viewType;
|
||||||
m_viewType = viewType;
|
m_viewType = viewType;
|
||||||
|
|
||||||
switch (viewType)
|
switch (viewType)
|
||||||
|
@ -3092,6 +3154,11 @@ void MainWindow::addPlaylistItemsToGrid(const QString &pathString, bool setProgr
|
||||||
item->widget->setLayout(new QVBoxLayout());
|
item->widget->setLayout(new QVBoxLayout());
|
||||||
item->widget->setStyleSheet("background-color: #555555");
|
item->widget->setStyleSheet("background-color: #555555");
|
||||||
|
|
||||||
|
item->widget->setProperty("hash", QVariant::fromValue<QHash<QString, QString> >(hash));
|
||||||
|
|
||||||
|
connect(item->widget, SIGNAL(mouseDoubleClicked()), this, SLOT(onGridItemDoubleClicked()));
|
||||||
|
connect(item->widget, SIGNAL(mousePressed()), this, SLOT(onGridItemClicked()));
|
||||||
|
|
||||||
label = new ThumbnailLabel(item->widget);
|
label = new ThumbnailLabel(item->widget);
|
||||||
|
|
||||||
item->label = label;
|
item->label = label;
|
||||||
|
|
|
@ -61,6 +61,20 @@ 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)
|
void ThumbnailWidget::paintEvent(QPaintEvent *event)
|
||||||
{
|
{
|
||||||
QStyleOption o;
|
QStyleOption o;
|
||||||
|
@ -497,6 +511,9 @@ static void* ui_companion_qt_init(void)
|
||||||
mainwindow->setCurrentViewType(MainWindow::VIEW_TYPE_ICONS);
|
mainwindow->setCurrentViewType(MainWindow::VIEW_TYPE_ICONS);
|
||||||
else
|
else
|
||||||
mainwindow->setCurrentViewType(MainWindow::VIEW_TYPE_LIST);
|
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
|
else
|
||||||
mainwindow->setCurrentViewType(MainWindow::VIEW_TYPE_LIST);
|
mainwindow->setCurrentViewType(MainWindow::VIEW_TYPE_LIST);
|
||||||
|
|
|
@ -88,11 +88,16 @@ public:
|
||||||
ThumbnailWidget(QWidget *parent = 0);
|
ThumbnailWidget(QWidget *parent = 0);
|
||||||
QSize sizeHint() const;
|
QSize sizeHint() const;
|
||||||
void setSizeHint(QSize size);
|
void setSizeHint(QSize size);
|
||||||
|
signals:
|
||||||
|
void mouseDoubleClicked();
|
||||||
|
void mousePressed();
|
||||||
private:
|
private:
|
||||||
QSize m_sizeHint;
|
QSize m_sizeHint;
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *event);
|
void paintEvent(QPaintEvent *event);
|
||||||
void resizeEvent(QResizeEvent *event);
|
void resizeEvent(QResizeEvent *event);
|
||||||
|
void mouseDoubleClickEvent(QMouseEvent *event);
|
||||||
|
void mousePressEvent(QMouseEvent *event);
|
||||||
};
|
};
|
||||||
|
|
||||||
class ThumbnailLabel : public QWidget
|
class ThumbnailLabel : public QWidget
|
||||||
|
@ -281,6 +286,8 @@ public:
|
||||||
const QString& customThemeString() const;
|
const QString& customThemeString() const;
|
||||||
GridItem* doDeferredImageLoad(GridItem *item, QString path);
|
GridItem* doDeferredImageLoad(GridItem *item, QString path);
|
||||||
void setCurrentViewType(ViewType viewType);
|
void setCurrentViewType(ViewType viewType);
|
||||||
|
QString getCurrentViewTypeString();
|
||||||
|
ViewType getCurrentViewType();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void thumbnailChanged(const QPixmap &pixmap);
|
void thumbnailChanged(const QPixmap &pixmap);
|
||||||
|
@ -300,6 +307,7 @@ public slots:
|
||||||
void onShowHiddenDockWidgetAction();
|
void onShowHiddenDockWidgetAction();
|
||||||
void setCoreActions();
|
void setCoreActions();
|
||||||
void onRunClicked();
|
void onRunClicked();
|
||||||
|
void loadContent(const QHash<QString, QString> &contentHash);
|
||||||
void onStartCoreClicked();
|
void onStartCoreClicked();
|
||||||
void onTableWidgetEnterPressed();
|
void onTableWidgetEnterPressed();
|
||||||
void selectBrowserDir(QString path);
|
void selectBrowserDir(QString path);
|
||||||
|
@ -325,6 +333,7 @@ private slots:
|
||||||
void onCoreLoaded();
|
void onCoreLoaded();
|
||||||
void onCurrentListItemChanged(QListWidgetItem *current, QListWidgetItem *previous);
|
void onCurrentListItemChanged(QListWidgetItem *current, QListWidgetItem *previous);
|
||||||
void onCurrentTableItemChanged(QTableWidgetItem *current, QTableWidgetItem *previous);
|
void onCurrentTableItemChanged(QTableWidgetItem *current, QTableWidgetItem *previous);
|
||||||
|
void currentItemChanged(const QHash<QString, QString> &hash);
|
||||||
void onSearchEnterPressed();
|
void onSearchEnterPressed();
|
||||||
void onSearchLineEditEdited(const QString &text);
|
void onSearchLineEditEdited(const QString &text);
|
||||||
void addPlaylistItemsToTable(QString path);
|
void addPlaylistItemsToTable(QString path);
|
||||||
|
@ -342,6 +351,8 @@ private slots:
|
||||||
void onContentGridInited();
|
void onContentGridInited();
|
||||||
void onUpdateGridItemPixmapFromImage(GridItem *item);
|
void onUpdateGridItemPixmapFromImage(GridItem *item);
|
||||||
void onPendingItemUpdates();
|
void onPendingItemUpdates();
|
||||||
|
void onGridItemDoubleClicked();
|
||||||
|
void onGridItemClicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setCurrentCoreLabel();
|
void setCurrentCoreLabel();
|
||||||
|
@ -352,8 +363,6 @@ private:
|
||||||
void loadImageDeferred(GridItem *item, QString path);
|
void loadImageDeferred(GridItem *item, QString path);
|
||||||
void calcGridItemSize(GridItem *item, int zoomValue);
|
void calcGridItemSize(GridItem *item, int zoomValue);
|
||||||
QVector<QHash<QString, QString> > getPlaylistItems(QString pathString);
|
QVector<QHash<QString, QString> > getPlaylistItems(QString pathString);
|
||||||
QString getCurrentViewTypeString();
|
|
||||||
ViewType getCurrentViewType();
|
|
||||||
|
|
||||||
LoadCoreWindow *m_loadCoreWindow;
|
LoadCoreWindow *m_loadCoreWindow;
|
||||||
QTimer *m_timer;
|
QTimer *m_timer;
|
||||||
|
@ -406,6 +415,8 @@ private:
|
||||||
ViewType m_viewType;
|
ViewType m_viewType;
|
||||||
QProgressBar *m_gridProgressBar;
|
QProgressBar *m_gridProgressBar;
|
||||||
QWidget *m_gridProgressWidget;
|
QWidget *m_gridProgressWidget;
|
||||||
|
QHash<QString, QString> m_currentGridHash;
|
||||||
|
ViewType m_lastViewType;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent *event);
|
void closeEvent(QCloseEvent *event);
|
||||||
|
|
Loading…
Reference in New Issue