(Qt) Combine filedropwidgets.cpp and settingswidgets.cpp into

qt_widgets.cpp - further binary size reduction
This commit is contained in:
twinaphex 2021-03-08 17:32:56 +01:00
parent 7fb09d1602
commit af1d9f7041
5 changed files with 247 additions and 255 deletions

View File

@ -490,14 +490,13 @@ ifeq ($(HAVE_QT), 1)
ui/drivers/qt/ui_qt_load_core_window.o \
ui/drivers/qt/gridview.o \
ui/drivers/qt/qt_dialogs.o \
ui/drivers/qt/filedropwidget.o \
ui/drivers/qt/qt_widgets.o \
ui/drivers/qt/qt_playlist.o \
ui/drivers/qt/thumbnaildownload.o \
ui/drivers/qt/thumbnailpackdownload.o \
ui/drivers/qt/playlistthumbnaildownload.o
ifeq ($(HAVE_MENU), 1)
OBJ += ui/drivers/qt/settingswidgets.o \
ui/drivers/qt/options/achievements.o \
OBJ += ui/drivers/qt/options/achievements.o \
ui/drivers/qt/options/audio.o \
ui/drivers/qt/options/generic.o \
ui/drivers/qt/options/input.o \

View File

@ -54,13 +54,12 @@ UI
#include "../ui/drivers/qt/ui_qt_load_core_window.cpp"
#include "../ui/drivers/qt/gridview.cpp"
#include "../ui/drivers/qt/qt_dialogs.cpp"
#include "../ui/drivers/qt/filedropwidget.cpp"
#include "../ui/drivers/qt/qt_widgets.cpp"
#include "../ui/drivers/qt/qt_playlist.cpp"
#include "../ui/drivers/qt/thumbnaildownload.cpp"
#include "../ui/drivers/qt/thumbnailpackdownload.cpp"
#include "../ui/drivers/qt/playlistthumbnaildownload.cpp"
#ifdef HAVE_MENU
#include "../ui/drivers/qt/settingswidgets.cpp"
#include "../ui/drivers/qt/options/generic.cpp"
#include "../ui/drivers/qt/options/video.cpp"
#include "../ui/drivers/qt/options/audio.cpp"

View File

@ -1,242 +0,0 @@
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QKeyEvent>
#include <QPaintEvent>
#include <QStyle>
#include <QStyleOption>
#include <QMimeData>
#include <QPainter>
#include <QAction>
#include <QFileInfo>
#include <QFileDialog>
#include <QMenu>
#include "filedropwidget.h"
#include "playlistentrydialog.h"
#include "../ui_qt.h"
#ifndef CXX_BUILD
extern "C" {
#endif
#include "../../../file_path_special.h"
#include "../../../configuration.h"
#include "../../../msg_hash.h"
#ifndef CXX_BUILD
}
#endif
FileDropWidget::FileDropWidget(QWidget *parent) :
QStackedWidget(parent)
{
setAcceptDrops(true);
}
void FileDropWidget::paintEvent(QPaintEvent *event)
{
QStyleOption o;
QPainter p;
o.initFrom(this);
p.begin(this);
style()->drawPrimitive(
QStyle::PE_Widget, &o, &p, this);
p.end();
QWidget::paintEvent(event);
}
void FileDropWidget::keyPressEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter)
{
event->accept();
emit enterPressed();
}
else if (event->key() == Qt::Key_Delete)
{
event->accept();
emit deletePressed();
}
else
QWidget::keyPressEvent(event);
}
void FileDropWidget::dragEnterEvent(QDragEnterEvent *event)
{
const QMimeData *data = event->mimeData();
if (data->hasUrls())
event->acceptProposedAction();
}
/* Workaround for QTBUG-72844. Without it, you can't drop on this if you first drag over another widget that doesn't accept drops. */
void FileDropWidget::dragMoveEvent(QDragMoveEvent *event)
{
event->acceptProposedAction();
}
void FileDropWidget::dropEvent(QDropEvent *event)
{
const QMimeData *data = event->mimeData();
if (data->hasUrls())
{
QList<QUrl> urls = data->urls();
QStringList files;
int i;
for (i = 0; i < urls.count(); i++)
{
QString path(urls.at(i).toLocalFile());
files.append(path);
}
emit filesDropped(files);
}
}
void MainWindow::onFileDropWidgetContextMenuRequested(const QPoint &pos)
{
QScopedPointer<QMenu> menu;
QScopedPointer<QAction> downloadThumbnailAction;
QScopedPointer<QAction> addEntryAction;
QScopedPointer<QAction> addFilesAction;
QScopedPointer<QAction> addFolderAction;
QScopedPointer<QAction> editAction;
QScopedPointer<QAction> deleteAction;
QPointer<QAction> selectedAction;
QPoint cursorPos = QCursor::pos();
QHash<QString, QString> contentHash = getCurrentContentHash();
bool specialPlaylist = currentPlaylistIsSpecial();
bool allPlaylist = currentPlaylistIsAll();
bool actionsAdded = false;
menu.reset(new QMenu(this));
if (!specialPlaylist)
{
downloadThumbnailAction.reset(new QAction(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_DOWNLOAD_THUMBNAIL)), this));
menu->addAction(downloadThumbnailAction.data());
}
if (!allPlaylist)
{
addEntryAction.reset(new QAction(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_ADD_ENTRY)), this));
menu->addAction(addEntryAction.data());
addFilesAction.reset(new QAction(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_ADD_FILES)), this));
menu->addAction(addFilesAction.data());
addFolderAction.reset(new QAction(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_ADD_FOLDER)), this));
menu->addAction(addFolderAction.data());
editAction.reset(new QAction(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_EDIT)), this));
deleteAction.reset(new QAction(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_DELETE)), this));
if (!contentHash.isEmpty())
{
menu->addAction(editAction.data());
menu->addAction(deleteAction.data());
}
actionsAdded = true;
}
if (actionsAdded)
selectedAction = menu->exec(cursorPos);
if (!selectedAction)
return;
if (!specialPlaylist)
{
if (selectedAction == downloadThumbnailAction.data())
{
QHash<QString, QString> hash = getCurrentContentHash();
QString system = QFileInfo(getCurrentPlaylistPath()).completeBaseName();
QString title = hash.value("label");
if (!title.isEmpty())
{
if (m_pendingThumbnailDownloadTypes.isEmpty())
{
m_pendingThumbnailDownloadTypes.append(THUMBNAIL_BOXART);
m_pendingThumbnailDownloadTypes.append(THUMBNAIL_SCREENSHOT);
m_pendingThumbnailDownloadTypes.append(THUMBNAIL_TITLE);
downloadThumbnail(system, title);
}
else
{
showMessageBox(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_DOWNLOAD_ALREADY_IN_PROGRESS), MainWindow::MSGBOX_TYPE_ERROR, Qt::ApplicationModal, false);
}
}
}
}
if (!allPlaylist)
{
if (selectedAction == addFilesAction.data())
{
QStringList filePaths = QFileDialog::getOpenFileNames(
this,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_SELECT_FILES));
if (!filePaths.isEmpty())
addFilesToPlaylist(filePaths);
}
else if (selectedAction == addEntryAction.data())
addFilesToPlaylist(QStringList());
else if (selectedAction == addFolderAction.data())
{
QString dirPath = QFileDialog::getExistingDirectory(
this,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_SELECT_FOLDER),
QString(), QFileDialog::ShowDirsOnly);
if (!dirPath.isEmpty())
addFilesToPlaylist(QStringList() << dirPath);
}
else if (selectedAction == editAction.data())
{
QString selectedDatabase;
QString selectedName;
QString selectedPath;
QHash<QString, QString> selectedCore;
PlaylistEntryDialog *playlistDialog = playlistEntryDialog();
QString currentPlaylistPath = getCurrentPlaylistPath();
if (!playlistDialog->showDialog(contentHash))
return;
selectedName = m_playlistEntryDialog->getSelectedName();
selectedPath = m_playlistEntryDialog->getSelectedPath();
selectedCore = m_playlistEntryDialog->getSelectedCore();
selectedDatabase = m_playlistEntryDialog->getSelectedDatabase();
if (selectedCore.isEmpty())
{
selectedCore["core_name"] = "DETECT";
selectedCore["core_path"] = "DETECT";
}
if (selectedDatabase.isEmpty())
selectedDatabase = QFileInfo(currentPlaylistPath).fileName().remove(".lpl");
contentHash["label"] = selectedName;
contentHash["path"] = selectedPath;
contentHash["core_name"] = selectedCore.value("core_name");
contentHash["core_path"] = selectedCore.value("core_path");
contentHash["db_name"] = selectedDatabase;
if (!updateCurrentPlaylistEntry(contentHash))
{
showMessageBox(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_COULD_NOT_UPDATE_PLAYLIST_ENTRY), MainWindow::MSGBOX_TYPE_ERROR, Qt::ApplicationModal, false);
return;
}
}
else if (selectedAction == deleteAction.data())
deleteCurrentPlaylistItem();
}
}

View File

@ -25,15 +25,10 @@
#include <QColor>
#include <QColorDialog>
#include <QLabel>
#ifdef HAVE_MENU
#include <QBitmap>
#include <QStackedLayout>
#include <QScrollBar>
#include "options/options.h"
#endif
#include "coreoptionsdialog.h"
#include "viewoptionsdialog.h"
#include "coreinfodialog.h"
@ -76,6 +71,10 @@ extern "C" {
}
#endif
#ifdef HAVE_MENU
#include "options/options.h"
#endif
#if defined(_MSC_VER) && !defined(_XBOX) && (_MSC_VER >= 1500 && _MSC_VER < 1900)
/* https://support.microsoft.com/en-us/kb/980263 */
#pragma execution_character_set("utf-8")

View File

@ -1,27 +1,49 @@
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QComboBox>
#include <QCheckBox>
#include <QPushButton>
#include <QSpinBox>
#include <QKeyEvent>
#include <QFormLayout>
#include <QFileInfo>
#include <QFileDialog>
#include <QGroupBox>
#include <QButtonGroup>
#include <QPaintEvent>
#include <QPainter>
#include <QStyle>
#include <QStyleOption>
#include <QMimeData>
#include <QAction>
#include <QMenu>
#include "filedropwidget.h"
#include "settingswidgets.h"
#include "playlistentrydialog.h"
#include "../ui_qt.h"
#include <math.h>
#ifndef CXX_BUILD
extern "C" {
#endif
#include <math.h>
#ifdef HAVE_CONFIG_H
#include "../../../config.h"
#endif
#include <string/stdstring.h>
#include "../../../configuration.h"
#include "../../../file_path_special.h"
#include "../../../msg_hash.h"
#ifndef CXX_BUILD
}
#endif
#ifdef HAVE_MENU
static const QRegularExpression decimalsRegex("%.(\\d)f");
static inline void add_sublabel_and_whats_this(
@ -45,7 +67,7 @@ static inline void add_sublabel_and_whats_this(
widget->setWhatsThis(tmp);
}
static QString sanitize_ampersand(QString input)
static inline QString sanitize_ampersand(QString input)
{
return input.replace("&", "&&");
}
@ -1136,3 +1158,218 @@ QColor FloatColorButton::color()
*m_green->value.target.fraction * 255,
*m_blue->value.target.fraction * 255);
}
#endif
FileDropWidget::FileDropWidget(QWidget *parent) :
QStackedWidget(parent)
{
setAcceptDrops(true);
}
void FileDropWidget::paintEvent(QPaintEvent *event)
{
QStyleOption o;
QPainter p;
o.initFrom(this);
p.begin(this);
style()->drawPrimitive(
QStyle::PE_Widget, &o, &p, this);
p.end();
QWidget::paintEvent(event);
}
void FileDropWidget::keyPressEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter)
{
event->accept();
emit enterPressed();
}
else if (event->key() == Qt::Key_Delete)
{
event->accept();
emit deletePressed();
}
else
QWidget::keyPressEvent(event);
}
void FileDropWidget::dragEnterEvent(QDragEnterEvent *event)
{
const QMimeData *data = event->mimeData();
if (data->hasUrls())
event->acceptProposedAction();
}
/* Workaround for QTBUG-72844. Without it, you can't drop on this if you first drag over another widget that doesn't accept drops. */
void FileDropWidget::dragMoveEvent(QDragMoveEvent *event)
{
event->acceptProposedAction();
}
void FileDropWidget::dropEvent(QDropEvent *event)
{
const QMimeData *data = event->mimeData();
if (data->hasUrls())
{
QList<QUrl> urls = data->urls();
QStringList files;
int i;
for (i = 0; i < urls.count(); i++)
{
QString path(urls.at(i).toLocalFile());
files.append(path);
}
emit filesDropped(files);
}
}
void MainWindow::onFileDropWidgetContextMenuRequested(const QPoint &pos)
{
QScopedPointer<QMenu> menu;
QScopedPointer<QAction> downloadThumbnailAction;
QScopedPointer<QAction> addEntryAction;
QScopedPointer<QAction> addFilesAction;
QScopedPointer<QAction> addFolderAction;
QScopedPointer<QAction> editAction;
QScopedPointer<QAction> deleteAction;
QPointer<QAction> selectedAction;
QPoint cursorPos = QCursor::pos();
QHash<QString, QString> contentHash = getCurrentContentHash();
bool specialPlaylist = currentPlaylistIsSpecial();
bool allPlaylist = currentPlaylistIsAll();
bool actionsAdded = false;
menu.reset(new QMenu(this));
if (!specialPlaylist)
{
downloadThumbnailAction.reset(new QAction(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_DOWNLOAD_THUMBNAIL)), this));
menu->addAction(downloadThumbnailAction.data());
}
if (!allPlaylist)
{
addEntryAction.reset(new QAction(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_ADD_ENTRY)), this));
menu->addAction(addEntryAction.data());
addFilesAction.reset(new QAction(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_ADD_FILES)), this));
menu->addAction(addFilesAction.data());
addFolderAction.reset(new QAction(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_ADD_FOLDER)), this));
menu->addAction(addFolderAction.data());
editAction.reset(new QAction(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_EDIT)), this));
deleteAction.reset(new QAction(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_DELETE)), this));
if (!contentHash.isEmpty())
{
menu->addAction(editAction.data());
menu->addAction(deleteAction.data());
}
actionsAdded = true;
}
if (actionsAdded)
selectedAction = menu->exec(cursorPos);
if (!selectedAction)
return;
if (!specialPlaylist)
{
if (selectedAction == downloadThumbnailAction.data())
{
QHash<QString, QString> hash = getCurrentContentHash();
QString system = QFileInfo(getCurrentPlaylistPath()).completeBaseName();
QString title = hash.value("label");
if (!title.isEmpty())
{
if (m_pendingThumbnailDownloadTypes.isEmpty())
{
m_pendingThumbnailDownloadTypes.append(THUMBNAIL_BOXART);
m_pendingThumbnailDownloadTypes.append(THUMBNAIL_SCREENSHOT);
m_pendingThumbnailDownloadTypes.append(THUMBNAIL_TITLE);
downloadThumbnail(system, title);
}
else
{
showMessageBox(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_DOWNLOAD_ALREADY_IN_PROGRESS), MainWindow::MSGBOX_TYPE_ERROR, Qt::ApplicationModal, false);
}
}
}
}
if (!allPlaylist)
{
if (selectedAction == addFilesAction.data())
{
QStringList filePaths = QFileDialog::getOpenFileNames(
this,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_SELECT_FILES));
if (!filePaths.isEmpty())
addFilesToPlaylist(filePaths);
}
else if (selectedAction == addEntryAction.data())
addFilesToPlaylist(QStringList());
else if (selectedAction == addFolderAction.data())
{
QString dirPath = QFileDialog::getExistingDirectory(
this,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_SELECT_FOLDER),
QString(), QFileDialog::ShowDirsOnly);
if (!dirPath.isEmpty())
addFilesToPlaylist(QStringList() << dirPath);
}
else if (selectedAction == editAction.data())
{
QString selectedDatabase;
QString selectedName;
QString selectedPath;
QHash<QString, QString> selectedCore;
PlaylistEntryDialog *playlistDialog = playlistEntryDialog();
QString currentPlaylistPath = getCurrentPlaylistPath();
if (!playlistDialog->showDialog(contentHash))
return;
selectedName = m_playlistEntryDialog->getSelectedName();
selectedPath = m_playlistEntryDialog->getSelectedPath();
selectedCore = m_playlistEntryDialog->getSelectedCore();
selectedDatabase = m_playlistEntryDialog->getSelectedDatabase();
if (selectedCore.isEmpty())
{
selectedCore["core_name"] = "DETECT";
selectedCore["core_path"] = "DETECT";
}
if (selectedDatabase.isEmpty())
selectedDatabase = QFileInfo(currentPlaylistPath).fileName().remove(".lpl");
contentHash["label"] = selectedName;
contentHash["path"] = selectedPath;
contentHash["core_name"] = selectedCore.value("core_name");
contentHash["core_path"] = selectedCore.value("core_path");
contentHash["db_name"] = selectedDatabase;
if (!updateCurrentPlaylistEntry(contentHash))
{
showMessageBox(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_COULD_NOT_UPDATE_PLAYLIST_ENTRY), MainWindow::MSGBOX_TYPE_ERROR, Qt::ApplicationModal, false);
return;
}
}
else if (selectedAction == deleteAction.data())
deleteCurrentPlaylistItem();
}
}