added drop support, latest changes from gta5sync
This commit is contained in:
parent
e041c576cd
commit
8ddd79d667
12 changed files with 288 additions and 102 deletions
|
@ -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<QPushButton*> pbBtn = pbDialog.findChildren<QPushButton*>();
|
||||
pbBtn.at(0)->setDisabled(true);
|
||||
QList<QProgressBar*> pbBar = pbDialog.findChildren<QProgressBar*>();
|
||||
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<QPushButton*> pbBtn = pbDialog.findChildren<QPushButton*>();
|
||||
pbBtn.at(0)->setDisabled(true);
|
||||
QList<QProgressBar*> pbBar = pbDialog.findChildren<QProgressBar*>();
|
||||
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<QUrl> 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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue