File indexing completed on 2024-05-12 05:39:39

0001 /***************************************************************************
0002  * Copyright (C) 2014 by Renaud Guezennec                                   *
0003  * http://www.rolisteam.org/                                                *
0004  *                                                                          *
0005  *  This file is part of rcse                                               *
0006  *                                                                          *
0007  * rcse is free software; you can redistribute it and/or modify             *
0008  * it under the terms of the GNU General Public License as published by     *
0009  * the Free Software Foundation; either version 2 of the License, or        *
0010  * (at your option) any later version.                                      *
0011  *                                                                          *
0012  * rcse is distributed in the hope that it will be useful,                  *
0013  * but WITHOUT ANY WARRANTY; without even the implied warranty of           *
0014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the             *
0015  * GNU General Public License for more details.                             *
0016  *                                                                          *
0017  * You should have received a copy of the GNU General Public License        *
0018  * along with this program; if not, write to the                            *
0019  * Free Software Foundation, Inc.,                                          *
0020  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.                 *
0021  ***************************************************************************/
0022 #ifndef RCSE_MAINWINDOW_H
0023 #define RCSE_MAINWINDOW_H
0024 
0025 #include <QGraphicsView>
0026 #include <QHash>
0027 #include <QMainWindow>
0028 #include <QPixmap>
0029 #include <QUndoStack>
0030 
0031 #include "canvas.h"
0032 #include "charactersheet/charactersheetmodel.h"
0033 #include "charactersheet/controllers/fieldcontroller.h"
0034 #include "charactersheet/imagemodel.h"
0035 #include "charactersheet/rolisteamimageprovider.h"
0036 #include "controllers/maincontroller.h"
0037 #include "dialog/pdfmanager.h"
0038 #include "dialog/sheetproperties.h"
0039 #include "fieldmodel.h"
0040 #include "itemeditor.h"
0041 #include "preferences/preferencesmanager.h"
0042 
0043 class CodeEditor;
0044 class LogPanel;
0045 namespace Ui
0046 {
0047 class MainWindow;
0048 }
0049 /**
0050  * @brief The MainWindow class displays all components to edit and manage the character sheet.
0051  */
0052 namespace rcse
0053 {
0054 class MainWindow : public QMainWindow
0055 {
0056     Q_OBJECT
0057 public:
0058     enum EDITION_TOOL
0059     {
0060         ADDFIELD,
0061         SELECT,
0062         NONE
0063     };
0064     explicit MainWindow(QWidget* parent= nullptr);
0065     ~MainWindow();
0066 
0067     bool qmlGeneration() const;
0068     void setQmlGeneration(bool qmlGeneration);
0069 
0070     void updatePageSelector();
0071     void readSettings();
0072     void writeSettings();
0073     void cleanData();
0074 
0075 public slots:
0076     void openPDF();
0077 
0078     bool save();
0079     bool saveAs();
0080 
0081     void open();
0082     void openRecentFile();
0083 
0084     void generateAndShowQML();
0085     void showQMLFromCode();
0086 
0087     // void saveQML();
0088     void openQML();
0089 
0090     void addBackgroundImage();
0091     void addPage();
0092     void removePage();
0093 
0094     void openBackgroundImage();
0095     void openImage();
0096     bool mayBeSaved();
0097     void helpOnLine();
0098 
0099     void exportPDF();
0100     bool loadFile(const QString& file);
0101 
0102 protected:
0103     bool eventFilter(QObject*, QEvent*);
0104     bool wheelEventForView(QWheelEvent* event);
0105     void closeEvent(QCloseEvent* event);
0106     void defineItemCode(QModelIndex& index);
0107     void updateRecentFileAction();
0108 
0109     bool saveFile(const QString& filename);
0110 
0111     void setUpActionForImageTab();
0112     void setUpActionForCharacterTab();
0113 protected slots:
0114     void showPreferences();
0115     void showContextMenuForImageTab();
0116     void showContextMenuForCharacterTab();
0117     void updateTitle();
0118 
0119 private:
0120     Ui::MainWindow* ui;
0121     std::unique_ptr<rcse::MainController> m_mainCtrl;
0122     EDITION_TOOL m_currentTool;
0123     QPoint m_startField;
0124     bool m_qmlGeneration;
0125     RolisteamImageProvider* m_imgProvider;
0126     int m_counterZoom;
0127     QString m_pdfPath;
0128 
0129     // Log
0130     LogPanel* m_logPanel= nullptr;
0131 
0132     // Image tab action
0133     QAction* m_copyPath= nullptr;
0134     QAction* m_copyUrl= nullptr;
0135     QAction* m_replaceImage= nullptr;
0136     QAction* m_removeImage= nullptr;
0137     QAction* m_reloadImageFromFile= nullptr;
0138 
0139     // Action for CharacterTab
0140     QAction* m_addCharacter= nullptr;
0141     QAction* m_deleteCharacter= nullptr;
0142     QAction* m_copyCharacter= nullptr;
0143     QAction* m_defineAsTabName= nullptr;
0144     QAction* m_applyValueOnSelectedCharacterLines= nullptr;
0145     QAction* m_applyValueOnAllCharacters= nullptr;
0146 
0147     // Recent file
0148     std::vector<QAction*> m_recentActions;
0149     QStringList m_recentFiles;
0150     int m_maxRecentFile= 5;
0151     QAction* m_separatorAction;
0152 
0153     PreferencesManager* m_preferences;
0154 };
0155 }
0156 #endif // RCSE_MAINWINDOW_H