mainwindow.h 4.5 KB

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