From 8ddd79d667b27d8431a7737fa0077cb67e2242d1 Mon Sep 17 00:00:00 2001 From: Syping Date: Fri, 28 Jul 2017 19:53:07 +0200 Subject: [PATCH] added drop support, latest changes from gta5sync --- .travis.yml | 6 +- AppEnv.cpp | 4 + PictureDialog.cpp | 4 + PictureDialog.ui | 13 +++ ProfileInterface.cpp | 202 +++++++++++++++++++++++------------------- ProfileInterface.h | 2 + ProfileInterface.ui | 20 ++++- config.h | 2 +- gta5view.pro | 6 +- res/app.rc | 8 +- uimod/UiModWidget.cpp | 76 ++++++++++++++++ uimod/UiModWidget.h | 47 ++++++++++ 12 files changed, 288 insertions(+), 102 deletions(-) create mode 100644 uimod/UiModWidget.cpp create mode 100644 uimod/UiModWidget.h diff --git a/.travis.yml b/.travis.yml index f5e4953..7c7976a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,15 +24,15 @@ before_script: - echo "Grand Theft Auto V Snapmatic and Savegame viewer" > ./description-pak script: - - qmake -qt=5 "DEFINES+=GTA5SYNC_DAILYB=\\\\\\\"$PACKAGE_VERSION-rc1\\\\\\\"" ../gta5view.pro + - qmake -qt=5 "DEFINES+=GTA5SYNC_DAILYB=\\\\\\\"$PACKAGE_VERSION-rc2\\\\\\\"" ../gta5view.pro - make -j 4 - - sudo checkinstall -D --default --nodoc --pkgname=gta5view --pkgversion=$PACKAGE_VERSION --pkgrelease=rc1 --pkggroup=utility --maintainer="Syping on Travis \" --requires=libqt5core5a,libqt5gui5,libqt5network5,libqt5widgets5 --pakdir=../package + - sudo checkinstall -D --default --nodoc --pkgname=gta5view --pkgversion=$PACKAGE_VERSION --pkgrelease=rc2 --pkggroup=utility --maintainer="Syping on Travis \" --requires=libqt5core5a,libqt5gui5,libqt5network5,libqt5widgets5 --pakdir=../package deploy: provider: releases api_key: secure: "o7VneEz1aHfdVwZvOZLfopf6uJWNrFsZaBvunTmXFzpmNFhlNS1qwqgMUkIA2yBRbZ3wIzVs4vfwIHv7W9yE/PqK+AYL+R8+AwKGrwlgT4HqJNuk6VM/LNJ6GwT/qkQuaoOVw29bUjmzzgIRdHmw53SlJv6Hh1VE8HphlTT//aex6nCfcFhUZ0BETdZDWz5FSHwL3NalUoqfKfQrJeky5RXzCyCANQC2tKt0bV46GaWIgWrDo2KCTNqPtRWWf5GDmnkXE5IYRMQ3mXvO9iYh0v5Y2jo4PiXGUiFUU6Z3aAWFAiPdGclrBO697cf3lCTzDMhuCETR153qFYsLShUlFf61ITAmCeHAWETjZDri0lmPONo3GoNB6alGfYEA51qw14kXakrTpICtTJj7gw/gtUYOabW6hrzmieNzMBIy62RikDPjyakFnuwW2qNHRlD65e0jYv+6nCpb6E+OV16Ysh1zhV2vTfpfzVmSuyu2J+ELqXD3OZCXRSPpDIih9UQ8335p8FBji6jHORcgym/TRgdgRmENibh8tLzWp+UjpWHuWfcpvZgOskjfwU0iDMCayMJ7tDpOhXHcAhDRnd6XRIiOJ5YZCzflj2nEwmt3YUd7DwXS/AU+WHOmcNQBjXBxF/FJa35XXcy3HKJM5TTKqtph3medo30us5yXHeG6NNg=" - file: "../package/gta5view_$PACKAGE_VERSION-rc1_amd64.deb" + file: "../package/gta5view_$PACKAGE_VERSION-rc2_amd64.deb" skip_cleanup: true on: tags: true diff --git a/AppEnv.cpp b/AppEnv.cpp index d5b9c08..aad4f73 100755 --- a/AppEnv.cpp +++ b/AppEnv.cpp @@ -142,5 +142,9 @@ qreal AppEnv::screenRatio() #else qreal dpi = qApp->desktop()->logicalDpiX(); #endif +#ifdef Q_OS_MAC + return (dpi / 72); +#else return (dpi / 96); +#endif } diff --git a/PictureDialog.cpp b/PictureDialog.cpp index c1e6a6c..edba768 100755 --- a/PictureDialog.cpp +++ b/PictureDialog.cpp @@ -158,6 +158,10 @@ void PictureDialog::setupPictureDialog(bool withDatabase_) installEventFilter(ui->labPicture); ui->labPicture->setFixedSize(960 * screenRatio, 536 * screenRatio); ui->labPicture->setFocusPolicy(Qt::StrongFocus); + + // Pre-adapt window for DPI + setFixedWidth(960 * screenRatio); + setFixedHeight(536 * screenRatio); } PictureDialog::~PictureDialog() diff --git a/PictureDialog.ui b/PictureDialog.ui index c658d32..44eb828 100755 --- a/PictureDialog.ui +++ b/PictureDialog.ui @@ -51,6 +51,19 @@ + + + + Qt::Vertical + + + + 0 + 0 + + + + diff --git a/ProfileInterface.cpp b/ProfileInterface.cpp index fb6be42..6050840 100755 --- a/ProfileInterface.cpp +++ b/ProfileInterface.cpp @@ -69,6 +69,7 @@ ProfileInterface::ProfileInterface(ProfileDatabase *profileDB, CrewDatabase *cre QColor baseColor = palette.base().color(); ui->labVersion->setText(ui->labVersion->text().arg(GTA5SYNC_APPSTR, GTA5SYNC_APPVER)); ui->saProfile->setStyleSheet(QString("QWidget#saProfileContent{background-color: rgb(%1, %2, %3)}").arg(QString::number(baseColor.red()),QString::number(baseColor.green()),QString::number(baseColor.blue()))); + ui->saProfileContent->setFilesMode(true); if (QIcon::hasThemeIcon("dialog-close")) { @@ -77,8 +78,13 @@ ProfileInterface::ProfileInterface(ProfileDatabase *profileDB, CrewDatabase *cre // DPI calculation qreal screenRatio = AppEnv::screenRatio(); +#ifndef Q_OS_MAC ui->hlButtons->setSpacing(6 * screenRatio); ui->hlButtons->setContentsMargins(9 * screenRatio, 9 * screenRatio, 9 * screenRatio, 9 * screenRatio); +#else + ui->hlButtons->setSpacing(6 * screenRatio); + ui->hlButtons->setContentsMargins(9 * screenRatio, 15 * screenRatio, 15 * screenRatio, 17 * screenRatio); +#endif } ProfileInterface::~ProfileInterface() @@ -415,71 +421,7 @@ fileDialogPreOpen: //Work? } else if (selectedFiles.length() > 1) { - int maximumId = selectedFiles.length(); - int overallId = 1; - int currentId = 0; - QString errorStr; - QStringList failedFiles; - - // Progress dialog - QProgressDialog pbDialog(this); - pbDialog.setWindowFlags(pbDialog.windowFlags()^Qt::WindowContextHelpButtonHint^Qt::WindowCloseButtonHint); - pbDialog.setWindowTitle(tr("Import...")); - pbDialog.setLabelText(tr("Import file %1 of %2 files").arg(QString::number(overallId), QString::number(maximumId))); - pbDialog.setRange(1, maximumId); - pbDialog.setValue(1); - pbDialog.setModal(true); - QList pbBtn = pbDialog.findChildren(); - pbBtn.at(0)->setDisabled(true); - QList pbBar = pbDialog.findChildren(); - pbBar.at(0)->setTextVisible(false); - pbDialog.show(); - - QTime t; - t.start(); - foreach(const QString &selectedFile, selectedFiles) - { - pbDialog.setValue(overallId); - pbDialog.setLabelText(tr("Import file %1 of %2 files").arg(QString::number(overallId), QString::number(maximumId))); - if (currentId == 10) - { - // Break until two seconds are over (this prevent import failures) - int elapsedTime = t.elapsed(); - if (elapsedTime > 2000) - { - } - else if (elapsedTime < 0) - { - QEventLoop loop; - QTimer::singleShot(2000, &loop, SLOT(quit())); - loop.exec(); - } - else - { - QEventLoop loop; - QTimer::singleShot(2000 - elapsedTime, &loop, SLOT(quit())); - loop.exec(); - } - currentId = 0; - t.restart(); - } - if (!importFile(selectedFile, false, currentId)) - { - failedFiles << QFileInfo(selectedFile).fileName(); - } - overallId++; - currentId++; - } - pbDialog.close(); - foreach (const QString &curErrorStr, failedFiles) - { - errorStr.append(", " + curErrorStr); - } - if (errorStr != "") - { - errorStr.remove(0, 2); - QMessageBox::warning(this, tr("Import"), tr("Import failed with...\n\n%1").arg(errorStr)); - } + importFilesProgress(selectedFiles); } else { @@ -494,6 +436,75 @@ fileDialogPreOpen: //Work? settings.endGroup(); } +void ProfileInterface::importFilesProgress(QStringList selectedFiles) +{ + int maximumId = selectedFiles.length(); + int overallId = 1; + int currentId = 0; + QString errorStr; + QStringList failedFiles; + + // Progress dialog + QProgressDialog pbDialog(this); + pbDialog.setWindowFlags(pbDialog.windowFlags()^Qt::WindowContextHelpButtonHint^Qt::WindowCloseButtonHint); + pbDialog.setWindowTitle(tr("Import...")); + pbDialog.setLabelText(tr("Import file %1 of %2 files").arg(QString::number(overallId), QString::number(maximumId))); + pbDialog.setRange(1, maximumId); + pbDialog.setValue(1); + pbDialog.setModal(true); + QList pbBtn = pbDialog.findChildren(); + pbBtn.at(0)->setDisabled(true); + QList pbBar = pbDialog.findChildren(); + pbBar.at(0)->setTextVisible(false); + pbDialog.show(); + + QTime t; + t.start(); + foreach(const QString &selectedFile, selectedFiles) + { + pbDialog.setValue(overallId); + pbDialog.setLabelText(tr("Import file %1 of %2 files").arg(QString::number(overallId), QString::number(maximumId))); + if (currentId == 10) + { + // Break until two seconds are over (this prevent import failures) + int elapsedTime = t.elapsed(); + if (elapsedTime > 2000) + { + } + else if (elapsedTime < 0) + { + QEventLoop loop; + QTimer::singleShot(2000, &loop, SLOT(quit())); + loop.exec(); + } + else + { + QEventLoop loop; + QTimer::singleShot(2000 - elapsedTime, &loop, SLOT(quit())); + loop.exec(); + } + currentId = 0; + t.restart(); + } + if (!importFile(selectedFile, false, currentId)) + { + failedFiles << QFileInfo(selectedFile).fileName(); + } + overallId++; + currentId++; + } + pbDialog.close(); + foreach (const QString &curErrorStr, failedFiles) + { + errorStr.append(", " + curErrorStr); + } + if (errorStr != "") + { + errorStr.remove(0, 2); + QMessageBox::warning(this, tr("Import"), tr("Import failed with...\n\n%1").arg(errorStr)); + } +} + bool ProfileInterface::importFile(QString selectedFile, bool notMultiple, int currentId) { QString selectedFileName = QFileInfo(selectedFile).fileName(); @@ -1097,22 +1108,16 @@ void ProfileInterface::contextMenuTriggeredPIC(QContextMenuEvent *ev) contextMenu.addMenu(&editMenu); contextMenu.addMenu(&exportMenu); contextMenu.addAction(SnapmaticWidget::tr("&Remove"), picWidget, SLOT(on_cmdDelete_clicked())); - if (picWidget->isSelected()) + contextMenu.addSeparator(); + if (!picWidget->isSelected()) { contextMenu.addAction(SnapmaticWidget::tr("&Select"), picWidget, SLOT(pictureSelected())); } + if (picWidget->isSelected()) { contextMenu.addAction(SnapmaticWidget::tr("&Deselect"), picWidget, SLOT(pictureSelected())); } + if (selectedWidgets() != widgets.count()) { - contextMenu.addSeparator(); - if (!picWidget->isSelected()) { contextMenu.addAction(SnapmaticWidget::tr("&Select"), picWidget, SLOT(pictureSelected())); } - if (picWidget->isSelected()) { contextMenu.addAction(SnapmaticWidget::tr("&Deselect"), picWidget, SLOT(pictureSelected())); } contextMenu.addAction(SnapmaticWidget::tr("Select &All"), picWidget, SLOT(selectAllWidgets()), QKeySequence::fromString("Ctrl+A")); - if (selectedWidgets() != 0) - { - contextMenu.addAction(SnapmaticWidget::tr("&Deselect All"), picWidget, SLOT(deselectAllWidgets()), QKeySequence::fromString("Ctrl+D")); - } } - else + if (selectedWidgets() != 0) { - contextMenu.addSeparator(); - contextMenu.addAction(SnapmaticWidget::tr("&Select"), picWidget, SLOT(pictureSelected())); - contextMenu.addAction(SnapmaticWidget::tr("Select &All"), picWidget, SLOT(selectAllWidgets()), QKeySequence::fromString("Ctrl+A")); + contextMenu.addAction(SnapmaticWidget::tr("&Deselect All"), picWidget, SLOT(deselectAllWidgets()), QKeySequence::fromString("Ctrl+D")); } contextMenu.exec(ev->globalPos()); } @@ -1124,22 +1129,41 @@ void ProfileInterface::contextMenuTriggeredSGD(QContextMenuEvent *ev) contextMenu.addAction(SavegameWidget::tr("&View"), sgdWidget, SLOT(on_cmdView_clicked())); contextMenu.addAction(SavegameWidget::tr("&Export"), sgdWidget, SLOT(on_cmdCopy_clicked())); contextMenu.addAction(SavegameWidget::tr("&Remove"), sgdWidget, SLOT(on_cmdDelete_clicked())); - if (sgdWidget->isSelected()) + contextMenu.addSeparator(); + if (!sgdWidget->isSelected()) { contextMenu.addAction(SavegameWidget::tr("&Select"), sgdWidget, SLOT(savegameSelected())); } + if (sgdWidget->isSelected()) { contextMenu.addAction(SavegameWidget::tr("&Deselect"), sgdWidget, SLOT(savegameSelected())); } + if (selectedWidgets() != widgets.count()) { - contextMenu.addSeparator(); - if (!sgdWidget->isSelected()) { contextMenu.addAction(SavegameWidget::tr("&Select"), this, SLOT(savegameSelected())); } - if (sgdWidget->isSelected()) { contextMenu.addAction(SavegameWidget::tr("&Deselect"), this, SLOT(savegameSelected())); } contextMenu.addAction(SavegameWidget::tr("Select &All"), sgdWidget, SLOT(selectAllWidgets()), QKeySequence::fromString("Ctrl+A")); - if (selectedWidgets() != 0) - { - contextMenu.addAction(SavegameWidget::tr("&Deselect All"), sgdWidget, SLOT(deselectAllWidgets()), QKeySequence::fromString("Ctrl+D")); - } } - else + if (selectedWidgets() != 0) { - contextMenu.addSeparator(); - contextMenu.addAction(SavegameWidget::tr("&Select"), sgdWidget, SLOT(savegameSelected())); - contextMenu.addAction(SavegameWidget::tr("Select &All"), sgdWidget, SLOT(selectAllWidgets()), QKeySequence::fromString("Ctrl+A")); + contextMenu.addAction(SavegameWidget::tr("&Deselect All"), sgdWidget, SLOT(deselectAllWidgets()), QKeySequence::fromString("Ctrl+D")); } contextMenu.exec(ev->globalPos()); } + +void ProfileInterface::on_saProfileContent_dropped(const QMimeData *mimeData) +{ + if (!mimeData) return; + QStringList pathList; + QList urlList = mimeData->urls(); + + foreach(const QUrl ¤tUrl, urlList) + { + if (currentUrl.isLocalFile()) + { + pathList.append(currentUrl.toLocalFile()); + } + } + + if (pathList.length() == 1) + { + QString selectedFile = pathList.at(0); + importFile(selectedFile, true, 0); + } + else if (pathList.length() > 1) + { + importFilesProgress(pathList); + } +} diff --git a/ProfileInterface.h b/ProfileInterface.h index 3ae93cc..f9dbc93 100755 --- a/ProfileInterface.h +++ b/ProfileInterface.h @@ -74,6 +74,7 @@ private slots: void profileWidgetDeselected(); void dialogNextPictureRequested(QWidget *dialog); void dialogPreviousPictureRequested(QWidget *dialog); + void on_saProfileContent_dropped(const QMimeData *mimeData); private: ProfileDatabase *profileDB; @@ -94,6 +95,7 @@ private: int contentMode; bool importFile(QString selectedFile, bool notMultiple, int currentId); + void importFilesProgress(QStringList selectedFiles); bool importSnapmaticPicture(SnapmaticPicture *picture, bool warn = true); bool importSavegameData(SavegameData *savegame, QString sgdPath, bool warn = true); void pictureLoaded(SnapmaticPicture *picture, bool inserted); diff --git a/ProfileInterface.ui b/ProfileInterface.ui index 1186939..de37b79 100755 --- a/ProfileInterface.ui +++ b/ProfileInterface.ui @@ -103,15 +103,18 @@ true - + 0 0 - 98 - 28 + 398 + 257 + + true + 0 @@ -225,6 +228,17 @@ + + + UiModWidget + QWidget +
UiModWidget.h
+ 1 + + dropped(QMimeData*) + +
+
diff --git a/config.h b/config.h index 6d9549e..ff4e316 100755 --- a/config.h +++ b/config.h @@ -50,7 +50,7 @@ #ifndef GTA5SYNC_APPVER #ifndef GTA5SYNC_DAILYB -#define GTA5SYNC_APPVER "1.4.0-rc1" +#define GTA5SYNC_APPVER "1.4.0-rc2" #else #define GTA5SYNC_APPVER QString("%1").arg(GTA5SYNC_DAILYB) #endif diff --git a/gta5view.pro b/gta5view.pro index fce9ff1..76c40f3 100755 --- a/gta5view.pro +++ b/gta5view.pro @@ -56,7 +56,8 @@ SOURCES += main.cpp \ StandardPaths.cpp \ StringParser.cpp \ UserInterface.cpp \ - uimod/UiModLabel.cpp + uimod/UiModLabel.cpp \ + uimod/UiModWidget.cpp HEADERS += \ AboutDialog.h \ @@ -87,7 +88,8 @@ HEADERS += \ StandardPaths.h \ StringParser.h \ UserInterface.h \ - uimod/UiModLabel.h + uimod/UiModLabel.h \ + uimod/UiModWidget.h PRECOMPILED_HEADER += config.h diff --git a/res/app.rc b/res/app.rc index 2520178..e662ebc 100755 --- a/res/app.rc +++ b/res/app.rc @@ -7,8 +7,8 @@ CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "gta5view.exe.manifest" #include VS_VERSION_INFO VERSIONINFO -FILEVERSION 1, 4, 0, 5 -PRODUCTVERSION 1, 4, 0, 5 +FILEVERSION 1, 4, 0, 6 +PRODUCTVERSION 1, 4, 0, 6 FILEFLAGSMASK 0x3fL FILEFLAGS 0 FILEOS VOS_NT_WINDOWS32 @@ -25,12 +25,12 @@ BEGIN BEGIN VALUE "CompanyName", "Syping" VALUE "FileDescription", "gta5view\0" - VALUE "FileVersion", "1.4.0-rc1\0" + VALUE "FileVersion", "1.4.0-rc2\0" VALUE "InternalName", "gta5view\0" VALUE "LegalCopyright", "Copyright © 2016-2017 Syping\0" VALUE "OriginalFilename", "gta5view.exe\0" VALUE "ProductName", "gta5view\0" - VALUE "ProductVersion", "1.4.0-rc1\0" + VALUE "ProductVersion", "1.4.0-rc2\0" END END END diff --git a/uimod/UiModWidget.cpp b/uimod/UiModWidget.cpp new file mode 100644 index 0000000..f9dd61f --- /dev/null +++ b/uimod/UiModWidget.cpp @@ -0,0 +1,76 @@ +/***************************************************************************** +* gta5sync GRAND THEFT AUTO V SYNC +* Copyright (C) 2017 Syping +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*****************************************************************************/ + +#include "UiModWidget.h" +#include +#include +#include +#include +#include +#include + +UiModWidget::UiModWidget(QWidget *parent) : QWidget(parent) +{ + filesMode = false; +} + +UiModWidget::~UiModWidget() +{ +} + +void UiModWidget::setFilesMode(bool filesModeEnabled) +{ + filesMode = filesModeEnabled; +} + +void UiModWidget::dragEnterEvent(QDragEnterEvent *dragEnterEvent) +{ + if (filesMode && dragEnterEvent->mimeData()->hasUrls()) + { + QStringList pathList; + QList urlList = dragEnterEvent->mimeData()->urls(); + + foreach(const QUrl ¤tUrl, urlList) + { + if (currentUrl.isLocalFile()) + { + pathList.append(currentUrl.toLocalFile()); + } + } + + if (!pathList.isEmpty()) + { + dragEnterEvent->acceptProposedAction(); + } + } +} + +void UiModWidget::dropEvent(QDropEvent *dropEvent) +{ + dropEvent->acceptProposedAction(); + emit dropped(dropEvent->mimeData()); +} + +void UiModWidget::paintEvent(QPaintEvent *paintEvent) +{ + Q_UNUSED(paintEvent) + QStyleOption opt; + opt.init(this); + QPainter p(this); + style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); +} diff --git a/uimod/UiModWidget.h b/uimod/UiModWidget.h new file mode 100644 index 0000000..3858425 --- /dev/null +++ b/uimod/UiModWidget.h @@ -0,0 +1,47 @@ +/***************************************************************************** +* gta5sync GRAND THEFT AUTO V SYNC +* Copyright (C) 2017 Syping +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*****************************************************************************/ + +#ifndef UIMODWIDGET_H +#define UIMODWIDGET_H + +#include +#include +#include +#include + +class UiModWidget : public QWidget +{ + Q_OBJECT +public: + UiModWidget(QWidget *parent = 0); + void setFilesMode(bool enabled); + ~UiModWidget(); + +protected: + void dragEnterEvent(QDragEnterEvent *dragEnterEvent); + void dropEvent(QDropEvent *dropEvent); + void paintEvent(QPaintEvent *paintEvent); + +private: + bool filesMode; + +signals: + void dropped(const QMimeData *mimeData); +}; + +#endif // UIMODWIDGET_H