mainwindow.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. #pragma once
  2. #include <QMainWindow>
  3. #include <QGraphicsScene>
  4. #include <QStandardItemModel>
  5. #include "mapcontroller.h"
  6. #include "resourceExtractor/ResourceConverter.h"
  7. class ObjectBrowser;
  8. class ObjectBrowserProxyModel;
  9. VCMI_LIB_NAMESPACE_BEGIN
  10. class CMap;
  11. class CGObjectInstance;
  12. VCMI_LIB_NAMESPACE_END
  13. namespace Ui
  14. {
  15. class MainWindow;
  16. const QString teamName = "vcmi";
  17. const QString appName = "mapeditor";
  18. }
  19. class MainWindow : public QMainWindow
  20. {
  21. Q_OBJECT
  22. const QString mainWindowSizeSetting = "MainWindow/Size";
  23. const QString mainWindowPositionSetting = "MainWindow/Position";
  24. const QString lastDirectorySetting = "MainWindow/Directory";
  25. #ifdef ENABLE_QT_TRANSLATIONS
  26. QTranslator translator;
  27. #endif
  28. std::unique_ptr<CMap> openMapInternal(const QString &);
  29. public:
  30. explicit MainWindow(QWidget *parent = nullptr);
  31. ~MainWindow();
  32. void initializeMap(bool isNew);
  33. void saveMap();
  34. bool openMap(const QString &);
  35. //MapView * mapView();
  36. void loadObjectsTree();
  37. void setStatusMessage(const QString & status);
  38. int getMapLevel() const {return mapLevel;}
  39. MapController controller;
  40. void loadTranslation();
  41. private slots:
  42. void on_actionOpen_triggered();
  43. void on_actionSave_as_triggered();
  44. void on_actionNew_triggered();
  45. void on_actionLevel_triggered();
  46. void on_actionSave_triggered();
  47. void on_actionErase_triggered();
  48. void on_actionUndo_triggered();
  49. void on_actionRedo_triggered();
  50. void on_actionPass_triggered(bool checked);
  51. void on_actionGrid_triggered(bool checked);
  52. void terrainButtonClicked(TerrainId terrain);
  53. void roadOrRiverButtonClicked(ui8 type, bool isRoad);
  54. void currentCoordinatesChanged(int x, int y);
  55. void on_terrainFilterCombo_currentIndexChanged(int index);
  56. void on_filter_textChanged(const QString &arg1);
  57. void on_actionFill_triggered();
  58. void on_inspectorWidget_itemChanged(QTableWidgetItem *item);
  59. void on_actionMapSettings_triggered();
  60. void on_actionPlayers_settings_triggered();
  61. void on_actionValidate_triggered();
  62. void on_actionUpdate_appearance_triggered();
  63. void on_actionRecreate_obstacles_triggered();
  64. void switchDefaultPlayer(const PlayerColor &);
  65. void on_actionCut_triggered();
  66. void on_actionCopy_triggered();
  67. void on_actionPaste_triggered();
  68. void on_actionExport_triggered();
  69. void on_actionTranslations_triggered();
  70. void on_actionh3m_converter_triggered();
  71. void on_actionLock_triggered();
  72. void on_actionUnlock_triggered();
  73. void on_actionZoom_in_triggered();
  74. void on_actionZoom_out_triggered();
  75. void on_actionZoom_reset_triggered();
  76. void on_toolLine_toggled(bool checked);
  77. void on_toolBrush2_toggled(bool checked);
  78. void on_toolBrush_toggled(bool checked);
  79. void on_toolBrush4_toggled(bool checked);
  80. void on_toolLasso_toggled(bool checked);
  81. void on_toolArea_toggled(bool checked);
  82. void on_toolFill_toggled(bool checked);
  83. void on_toolSelect_toggled(bool checked);
  84. public slots:
  85. void treeViewSelected(const QModelIndex &selected, const QModelIndex &deselected);
  86. void loadInspector(CGObjectInstance * obj, bool switchTab);
  87. void mapChanged();
  88. void enableUndo(bool enable);
  89. void enableRedo(bool enable);
  90. void onSelectionMade(int level, bool anythingSelected);
  91. void onPlayersChanged();
  92. void displayStatus(const QString& message, int timeout = 2000);
  93. private:
  94. void preparePreview(const QModelIndex & index);
  95. void addGroupIntoCatalog(const std::string & groupName, bool staticOnly);
  96. void addGroupIntoCatalog(const std::string & groupName, bool useCustomName, bool staticOnly, int ID);
  97. QAction * getActionPlayer(const PlayerColor &);
  98. void changeBrushState(int idx);
  99. void setTitle();
  100. void closeEvent(QCloseEvent *event) override;
  101. bool getAnswerAboutUnsavedChanges();
  102. void loadUserSettings();
  103. void saveUserSettings();
  104. void parseCommandLine(ExtractionOptions & extractionOptions);
  105. private:
  106. Ui::MainWindow * ui;
  107. ObjectBrowserProxyModel * objectBrowser = nullptr;
  108. QGraphicsScene * scenePreview;
  109. QString filename;
  110. QString lastSavingDir;
  111. bool unsaved = false;
  112. QStandardItemModel objectsModel;
  113. int mapLevel = 0;
  114. QRectF initialScale;
  115. std::set<int> catalog;
  116. // command line options
  117. QString mapFilePath; // FilePath to the H3 or VCMI map to open
  118. };