mainwindow.h 4.8 KB

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