Qt: add view menu option to change between icon/list views

This commit is contained in:
Brad Parker 2018-05-07 02:36:00 -04:00
parent faf52937c5
commit 649216c700
7 changed files with 198 additions and 29 deletions

View File

@ -3497,6 +3497,14 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_FILE_DOES_NOT_EXIST,
"ファイルは存在しません。")
MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_MENU_VIEW_OPTIONS_SUGGEST_LOADED_CORE_FIRST,
"ロードしたコアを最初に優先する")
MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_ZOOM,
"ズーム")
MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_VIEW,
"表示")
MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_VIEW_TYPE_ICONS,
"アイコン")
MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_VIEW_TYPE_LIST,
"一覧")
MSG_HASH(MENU_ENUM_LABEL_VALUE_QUICK_MENU_OVERRIDE_OPTIONS,
"Configuration Override options")
MSG_HASH(MENU_ENUM_SUBLABEL_QUICK_MENU_OVERRIDE_OPTIONS,

View File

@ -3646,6 +3646,14 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_FILE_DOES_NOT_EXIST,
"File does not exist.")
MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_MENU_VIEW_OPTIONS_SUGGEST_LOADED_CORE_FIRST,
"Suggest loaded core first")
MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_ZOOM,
"Zoom")
MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_VIEW,
"View")
MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_VIEW_TYPE_ICONS,
"Icons")
MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_VIEW_TYPE_LIST,
"List")
MSG_HASH(MENU_ENUM_LABEL_VALUE_QUICK_MENU_OVERRIDE_OPTIONS,
"Configuration Override options")
MSG_HASH(MENU_ENUM_SUBLABEL_QUICK_MENU_OVERRIDE_OPTIONS,

View File

@ -1846,6 +1846,10 @@ enum msg_hash_enums
MENU_ENUM_LABEL_VALUE_QT_FILE_IS_EMPTY,
MENU_ENUM_LABEL_VALUE_QT_FILE_READ_OPEN_FAILED,
MENU_ENUM_LABEL_VALUE_QT_FILE_DOES_NOT_EXIST,
MENU_ENUM_LABEL_VALUE_QT_ZOOM,
MENU_ENUM_LABEL_VALUE_QT_VIEW,
MENU_ENUM_LABEL_VALUE_QT_VIEW_TYPE_ICONS,
MENU_ENUM_LABEL_VALUE_QT_VIEW_TYPE_LIST,
MSG_LAST
};

View File

@ -1,7 +1,15 @@
#include <QString>
/* %1 is a placeholder for palette(highlight) or the equivalent chosen by the user */
static const QString qt_theme_default_stylesheet = QStringLiteral("");
static const QString qt_theme_default_stylesheet = QStringLiteral(""
"QPushButton[flat=\"true\"] {\n"
" min-height:20px;\n"
" min-width:80px;\n"
" padding:1px 3px 1px 3px;\n"
" background-color: transparent;\n"
" border: 1px solid #ddd;\n"
"}\n"
);
static const QString qt_theme_dark_stylesheet = QStringLiteral(""
"QWidget {\n"
@ -232,6 +240,10 @@ static const QString qt_theme_dark_stylesheet = QStringLiteral(""
" border:1px solid %1;\n"
" border-radius:4px;\n"
"}\n"
"QPushButton[flat=\"true\"] {\n"
" background-color: transparent;\n"
" border: 1px solid #ddd;\n"
"}\n"
"QRadioButton::indicator {\n"
" width:18px;\n"
" height:18px;\n"

View File

@ -530,6 +530,7 @@ MainWindow::MainWindow(QWidget *parent) :
,m_zoomSlider(NULL)
,m_lastZoomSliderValue(0)
,m_pendingItemUpdates()
,m_viewType(VIEW_TYPE_LIST)
{
settings_t *settings = config_get_ptr();
QDir playlistDir(settings->paths.directory_playlist);
@ -537,9 +538,21 @@ MainWindow::MainWindow(QWidget *parent) :
QToolButton *searchResetButton = NULL;
QWidget *zoomWidget = new QWidget();
QHBoxLayout *zoomLayout = new QHBoxLayout();
QLabel *zoomLabel = new QLabel("Zoom:", zoomWidget);
QLabel *zoomLabel = new QLabel(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_ZOOM), zoomWidget);
QPushButton *viewTypePushButton = new QPushButton(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_VIEW), zoomWidget);
QMenu *viewTypeMenu = new QMenu(viewTypePushButton);
QAction *viewTypeIconsAction = NULL;
QAction *viewTypeListAction = NULL;
int i = 0;
viewTypePushButton->setObjectName("viewTypePushButton");
viewTypePushButton->setFlat(true);
viewTypeIconsAction = viewTypeMenu->addAction(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_VIEW_TYPE_ICONS));
viewTypeListAction = viewTypeMenu->addAction(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_VIEW_TYPE_LIST));
viewTypePushButton->setMenu(viewTypeMenu);
zoomLabel->setObjectName("zoomLabel");
m_zoomSlider = new QSlider(Qt::Horizontal, zoomWidget);
@ -569,6 +582,7 @@ MainWindow::MainWindow(QWidget *parent) :
zoomLayout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Preferred));
zoomLayout->addWidget(zoomLabel);
zoomLayout->addWidget(m_zoomSlider);
zoomLayout->addWidget(viewTypePushButton);
m_gridWidget->layout()->addWidget(zoomWidget);
@ -688,12 +702,13 @@ MainWindow::MainWindow(QWidget *parent) :
connect(m_coreInfoPushButton, SIGNAL(clicked()), m_coreInfoDialog, SLOT(showCoreInfo()));
connect(m_runPushButton, SIGNAL(clicked()), this, SLOT(onRunClicked()));
connect(m_stopPushButton, SIGNAL(clicked()), this, SLOT(onStopClicked()));
connect(m_browserAndPlaylistTabWidget, SIGNAL(currentChanged(int)), this, SLOT(onTabWidgetIndexChanged(int)));
connect(m_dirTree, SIGNAL(itemsSelected(QModelIndexList)), this, SLOT(onTreeViewItemsSelected(QModelIndexList)));
connect(m_dirTree, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(onFileBrowserTreeContextMenuRequested(const QPoint&)));
connect(m_listWidget, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(onPlaylistWidgetContextMenuRequested(const QPoint&)));
connect(m_launchWithComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onLaunchWithComboBoxIndexChanged(int)));
connect(m_zoomSlider, SIGNAL(valueChanged(int)), this, SLOT(onZoomValueChanged(int)));
connect(viewTypeIconsAction, SIGNAL(triggered()), this, SLOT(onIconViewClicked()));
connect(viewTypeListAction, SIGNAL(triggered()), this, SLOT(onListViewClicked()));
/* make sure these use an auto connection so it will be queued if called from a different thread (some facilities in RA log messages from other threads) */
connect(this, SIGNAL(gotLogMessage(const QString&)), this, SLOT(onGotLogMessage(const QString&)), Qt::AutoConnection);
@ -711,16 +726,6 @@ MainWindow::MainWindow(QWidget *parent) :
qApp->processEvents();
QTimer::singleShot(0, this, SLOT(onBrowserStartClicked()));
for (i = 0; i < m_listWidget->count() && m_listWidget->count() > 0; i++)
{
/* select the first non-hidden row */
if (!m_listWidget->isRowHidden(i))
{
m_listWidget->setCurrentRow(i);
break;
}
}
m_searchLineEdit->setFocus();
m_loadCoreWindow->setWindowModality(Qt::ApplicationModal);
@ -741,6 +746,18 @@ MainWindow::~MainWindow()
removeGridItems();
}
void MainWindow::onIconViewClicked()
{
setCurrentViewType(VIEW_TYPE_ICONS);
onCurrentListItemChanged(m_listWidget->currentItem(), NULL);
}
void MainWindow::onListViewClicked()
{
setCurrentViewType(VIEW_TYPE_LIST);
onCurrentListItemChanged(m_listWidget->currentItem(), NULL);
}
inline void MainWindow::calcGridItemSize(GridItem *item, int zoomValue)
{
int newSize = 0;
@ -2625,16 +2642,58 @@ void MainWindow::resizeThumbnails(bool one, bool two, bool three)
}
}
void MainWindow::setCurrentViewType(ViewType viewType)
{
m_viewType = viewType;
switch (viewType)
{
case VIEW_TYPE_ICONS:
{
m_tableWidget->hide();
m_gridWidget->show();
break;
}
case VIEW_TYPE_LIST:
default:
{
m_gridWidget->hide();
m_tableWidget->show();
break;
}
}
}
MainWindow::ViewType MainWindow::getCurrentViewType()
{
return m_viewType;
}
void MainWindow::onCurrentListItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
{
ViewType viewType = getCurrentViewType();
Q_UNUSED(current)
Q_UNUSED(previous)
if (m_browserAndPlaylistTabWidget->tabText(m_browserAndPlaylistTabWidget->currentIndex()) != msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_TAB_PLAYLISTS))
return;
//initContentTableWidget();
initContentGridLayout();
switch (viewType)
{
case VIEW_TYPE_ICONS:
{
initContentGridLayout();
break;
}
case VIEW_TYPE_LIST:
default:
{
initContentTableWidget();
break;
}
}
setCoreActions();
}
@ -3041,6 +3100,8 @@ void MainWindow::onContentGridInited()
m_gridLayoutWidget->resize(m_gridScrollArea->viewport()->size());
onZoomValueChanged(m_zoomSlider->value());
onSearchEnterPressed();
}
void MainWindow::initContentTableWidget()
@ -3213,6 +3274,24 @@ QSettings* MainWindow::settings()
return m_settings;
}
QString MainWindow::getCurrentViewTypeString()
{
switch (m_viewType)
{
case VIEW_TYPE_ICONS:
{
return QStringLiteral("icons");
}
case VIEW_TYPE_LIST:
default:
{
return QStringLiteral("list");
}
}
return QStringLiteral("list");
}
void MainWindow::closeEvent(QCloseEvent *event)
{
if (m_settings->value("save_geometry", false).toBool())
@ -3222,6 +3301,8 @@ void MainWindow::closeEvent(QCloseEvent *event)
if (m_settings->value("save_last_tab", false).toBool())
m_settings->setValue("last_tab", m_browserAndPlaylistTabWidget->currentIndex());
m_settings->setValue("view_type", getCurrentViewTypeString());
QMainWindow::closeEvent(event);
}

View File

@ -237,6 +237,8 @@ static void* ui_companion_qt_init(void)
QAction *exitAction = NULL;
QComboBox *launchWithComboBox = NULL;
QSettings *qsettings = NULL;
QListWidget *listWidget = NULL;
int i = 0;
if (!handle)
return NULL;
@ -257,6 +259,8 @@ static void* ui_companion_qt_init(void)
mainwindow->setWindowTitle("RetroArch");
mainwindow->setDockOptions(QMainWindow::AnimatedDocks | QMainWindow::AllowNestedDocks | QMainWindow::AllowTabbedDocks | GROUPED_DRAGGING);
listWidget = mainwindow->playlistListWidget();
widget = new QWidget(mainwindow);
widget->setObjectName("tableWidget");
@ -264,8 +268,6 @@ static void* ui_companion_qt_init(void)
layout->addWidget(mainwindow->contentTableWidget());
layout->addWidget(mainwindow->contentGridWidget());
mainwindow->contentTableWidget()->hide();
widget->setLayout(layout);
mainwindow->setCentralWidget(widget);
@ -295,6 +297,10 @@ static void* ui_companion_qt_init(void)
QObject::connect(viewClosedDocksMenu, SIGNAL(aboutToShow()), mainwindow, SLOT(onViewClosedDocksAboutToShow()));
viewMenu->addSeparator();
viewMenu->addAction(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_VIEW_TYPE_ICONS), mainwindow, SLOT(onIconViewClicked()));
viewMenu->addAction(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_VIEW_TYPE_LIST), mainwindow, SLOT(onListViewClicked()));
viewMenu->addSeparator();
viewMenu->addAction(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_MENU_VIEW_OPTIONS), mainwindow->viewOptionsDialog(), SLOT(showDialog()));
playlistWidget = new QWidget();
@ -464,17 +470,6 @@ static void* ui_companion_qt_init(void)
if (qsettings->contains("dock_positions"))
mainwindow->restoreState(qsettings->value("dock_positions").toByteArray());
if (qsettings->contains("save_last_tab"))
{
if (qsettings->contains("last_tab"))
{
int lastTabIndex = qsettings->value("last_tab", 0).toInt();
if (lastTabIndex >= 0 && browserAndPlaylistTabWidget->count() > lastTabIndex)
browserAndPlaylistTabWidget->setCurrentIndex(lastTabIndex);
}
}
if (qsettings->contains("theme"))
{
QString themeStr = qsettings->value("theme").toString();
@ -492,6 +487,55 @@ static void* ui_companion_qt_init(void)
else
mainwindow->setTheme();
if (qsettings->contains("view_type"))
{
QString viewType = qsettings->value("view_type", "list").toString();
if (viewType == "list")
mainwindow->setCurrentViewType(MainWindow::VIEW_TYPE_LIST);
else if (viewType == "icons")
mainwindow->setCurrentViewType(MainWindow::VIEW_TYPE_ICONS);
else
mainwindow->setCurrentViewType(MainWindow::VIEW_TYPE_LIST);
}
else
mainwindow->setCurrentViewType(MainWindow::VIEW_TYPE_LIST);
/* We make sure to hook up the tab widget callback only after the tabs themselves have been added,
* but before changing to a specific one, to avoid the callback firing before the view type is set.
*/
QObject::connect(browserAndPlaylistTabWidget, SIGNAL(currentChanged(int)), mainwindow, SLOT(onTabWidgetIndexChanged(int)));
/* setting the last tab must come after setting the view type */
if (qsettings->contains("save_last_tab"))
{
if (qsettings->contains("last_tab"))
{
int lastTabIndex = qsettings->value("last_tab", 0).toInt();
if (lastTabIndex >= 0 && browserAndPlaylistTabWidget->count() > lastTabIndex)
{
browserAndPlaylistTabWidget->setCurrentIndex(lastTabIndex);
mainwindow->onTabWidgetIndexChanged(lastTabIndex);
}
}
}
else
{
browserAndPlaylistTabWidget->setCurrentIndex(0);
mainwindow->onTabWidgetIndexChanged(0);
}
for (i = 0; i < listWidget->count() && listWidget->count() > 0; i++)
{
/* select the first non-hidden row */
if (!listWidget->isRowHidden(i))
{
listWidget->setCurrentRow(i);
break;
}
}
return handle;
}

View File

@ -226,6 +226,12 @@ class MainWindow : public QMainWindow
Q_OBJECT
public:
enum ViewType
{
VIEW_TYPE_ICONS,
VIEW_TYPE_LIST
};
enum Theme
{
THEME_SYSTEM_DEFAULT,
@ -270,6 +276,7 @@ public:
void setCustomThemeString(QString qss);
const QString& customThemeString() const;
GridItem* doDeferredImageLoad(GridItem *item, QString path);
void setCurrentViewType(ViewType viewType);
signals:
void thumbnailChanged(const QPixmap &pixmap);
@ -303,6 +310,9 @@ public slots:
void deferReloadPlaylists();
void onGotReloadPlaylists();
void showWelcomeScreen();
void onIconViewClicked();
void onListViewClicked();
void onTabWidgetIndexChanged(int index);
private slots:
void onLoadCoreClicked(const QStringList &extensionFilters = QStringList());
@ -317,7 +327,6 @@ private slots:
void addPlaylistItemsToGrid(const QString &path);
void onContentItemDoubleClicked(QTableWidgetItem *item);
void onCoreLoadWindowClosed();
void onTabWidgetIndexChanged(int index);
void onTreeViewItemsSelected(QModelIndexList selectedIndexes);
void onSearchResetClicked();
void onLaunchWithComboBoxIndexChanged(int index);
@ -339,6 +348,8 @@ private:
void loadImageDeferred(GridItem *item, QString path);
void calcGridItemSize(GridItem *item, int zoomValue);
QVector<QHash<QString, QString> > getPlaylistItems(QString pathString);
QString getCurrentViewTypeString();
ViewType getCurrentViewType();
LoadCoreWindow *m_loadCoreWindow;
QTimer *m_timer;
@ -388,6 +399,7 @@ private:
QSlider *m_zoomSlider;
int m_lastZoomSliderValue;
QList<GridItem*> m_pendingItemUpdates;
ViewType m_viewType;
protected:
void closeEvent(QCloseEvent *event);