Open Source Snapmatic picture and Savegame viewer/editor for GTA V https://gta5view.syping.de/

SavegameDialog.cpp 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*****************************************************************************
  2. * gta5view Grand Theft Auto V Profile Viewer
  3. * Copyright (C) 2016-2018 Syping
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *****************************************************************************/
  18. #include "SavegameDialog.h"
  19. #include "ui_SavegameDialog.h"
  20. #include "SavegameCopy.h"
  21. #include "AppEnv.h"
  22. #include <QMessageBox>
  23. #include <QDebug>
  24. SavegameDialog::SavegameDialog(QWidget *parent) :
  25. QDialog(parent),
  26. ui(new Ui::SavegameDialog)
  27. {
  28. // Set Window Flags
  29. setWindowFlags(windowFlags()^Qt::WindowContextHelpButtonHint);
  30. // Setup User Interface
  31. ui->setupUi(this);
  32. ui->cmdClose->setFocus();
  33. savegameLabStr = ui->labSavegameText->text();
  34. // Set Icon for Close Button
  35. if (QIcon::hasThemeIcon("dialog-close"))
  36. {
  37. ui->cmdClose->setIcon(QIcon::fromTheme("dialog-close"));
  38. }
  39. else if (QIcon::hasThemeIcon("gtk-close"))
  40. {
  41. ui->cmdClose->setIcon(QIcon::fromTheme("gtk-close"));
  42. }
  43. // Set Icon for Export Button
  44. if (QIcon::hasThemeIcon("document-export"))
  45. {
  46. ui->cmdCopy->setIcon(QIcon::fromTheme("document-export"));
  47. }
  48. else if (QIcon::hasThemeIcon("document-save"))
  49. {
  50. ui->cmdCopy->setIcon(QIcon::fromTheme("document-save"));
  51. }
  52. refreshWindowSize();
  53. }
  54. SavegameDialog::~SavegameDialog()
  55. {
  56. delete ui;
  57. }
  58. void SavegameDialog::refreshWindowSize()
  59. {
  60. // DPI calculation
  61. qreal screenRatio = AppEnv::screenRatio();
  62. int dpiWindowWidth = 400 * screenRatio;
  63. int dpiWindowHeight = 105 * screenRatio;
  64. if (dpiWindowHeight < heightForWidth(dpiWindowWidth))
  65. {
  66. dpiWindowHeight = heightForWidth(dpiWindowWidth);
  67. }
  68. resize(dpiWindowWidth, dpiWindowHeight);
  69. }
  70. void SavegameDialog::setSavegameData(SavegameData *savegame, QString savegamePath, bool readOk)
  71. {
  72. // Showing error if reading error
  73. if (!readOk)
  74. {
  75. QMessageBox::warning(this,tr("Savegame Viewer"),tr("Failed at %1").arg(savegame->getLastStep()));
  76. return;
  77. }
  78. sgdPath = savegamePath;
  79. ui->labSavegameText->setText(savegameLabStr.arg(savegame->getSavegameStr()));
  80. refreshWindowSize();
  81. }
  82. void SavegameDialog::on_cmdClose_clicked()
  83. {
  84. this->close();
  85. }
  86. void SavegameDialog::on_cmdCopy_clicked()
  87. {
  88. SavegameCopy::copySavegame(this, sgdPath);
  89. }