File indexing completed on 2024-04-28 05:38:13

0001 /***************************************************************************
0002  *   Copyright (C) 2009 by Renaud Guezennec                                *
0003  *   http://www.rolisteam.org/contact                   *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
0019  ***************************************************************************/
0020 
0021 #ifndef CHARACTERSHEETWINDOW_H
0022 #define CHARACTERSHEETWINDOW_H
0023 #include <QHBoxLayout>
0024 #include <QPushButton>
0025 #include <QQmlEngine>
0026 #include <QTreeView>
0027 #include <QVBoxLayout>
0028 #include <memory>
0029 
0030 //#include "charactersheetmodel.h"
0031 #include "charactersheet/rolisteamimageprovider.h"
0032 #include "data/character.h"
0033 #include "mediacontainers/mediacontainer.h"
0034 #include "rwidgets_global.h"
0035 /**
0036  * @page characterSheet CharacterSheet System
0037  *
0038  * @section Introduction Introduction
0039  * The characterSheet system is dedicated to manage charactersheet.
0040  * It provides a way to display the charactersheet into a graphical user interface.
0041  * This GUI is designed in QML and to create it, rolisteam comes with Rolisteam CharacterSheet Editor.
0042  * The interface displays data from data model stored in rolisteam. Those data are also read by the Dice System.
0043  * The GUI provides different kinds of items to display data: Textfield, TextArea, TextLine, Combobox and dice button.
0044  * So, it is possible to send dice command from the graphical sheet.
0045  * It is possible to use formula in the charactersheet.
0046  *
0047  *
0048  */
0049 
0050 namespace Ui
0051 {
0052 class CharacterSheetWindow;
0053 }
0054 
0055 /**
0056  * @brief herits from SubMdiWindows. It displays and manages all classes required to deal with the character sheet MVC
0057  * architrecture.
0058  */
0059 class SheetWidget;
0060 class Player;
0061 class CharacterSheetController;
0062 class CharacterSheet;
0063 class TreeSheetItem;
0064 class RWIDGET_EXPORT CharacterSheetWindow : public MediaContainer
0065 {
0066     Q_OBJECT
0067 public:
0068     CharacterSheetWindow(CharacterSheetController* ctrl, QWidget* parent= nullptr);
0069     virtual ~CharacterSheetWindow();
0070     QJsonDocument saveFile();
0071     void addCharacterSheetSlot(CharacterSheet*);
0072     bool hasCharacterSheet(QString id);
0073 signals:
0074     void addWidgetToMdiArea(QWidget*, QString str);
0075     void rollDiceCmd(QString str, QString label, bool withAlias);
0076     void showText(QString str);
0077     void errorOccurs(QString error);
0078 
0079 public slots:
0080     void openQML();
0081     void contextMenuForTabs(const QPoint pos);
0082     void detachTab();
0083     void rollDice(QString cmd, bool alias= true);
0084     void removeConnection(Player*);
0085     void readErrorFromQML(QList<QQmlError> errors);
0086     void exportPDF();
0087 protected slots:
0088     void addTabWithSheetView(CharacterSheet* chSheet, Character* character);
0089     void addLine();
0090     void addSection();
0091     void addCharacterSheet();
0092     void displayCustomMenu(const QPoint& pos);
0093     void affectSheetToCharacter(const QString& uuid);
0094     void displayError(const QList<QQmlError>& warnings);
0095     void setReadOnlyOnSelection();
0096     void stopSharing();
0097     virtual void updateTitle();
0098     void copyTab();
0099 
0100 protected:
0101     virtual void closeEvent(QCloseEvent* event);
0102     void addSharingMenu(QMenu* share, int pos);
0103     void checkAlreadyShare(CharacterSheet* sheet);
0104     bool eventFilter(QObject* object, QEvent* event);
0105 
0106 private:
0107     QPointer<CharacterSheetController> m_sheetCtrl;
0108     Ui::CharacterSheetWindow* m_ui;
0109     QString m_qmlUri;
0110 
0111     // QMap<SheetWidget*,CharacterSheet*> m_characterSheetlist;
0112     CharacterSheet* m_currentCharacterSheet;
0113     QQmlComponent* m_sheetComponent;
0114 
0115     QJsonObject m_data;
0116     QList<QQmlError> m_errorList;
0117 
0118     // Translation optimisation
0119     const QString m_shareTo= tr("Share To");
0120     const QString m_filterString= tr("Character Sheet Data files (*.rcs)");
0121 };
0122 
0123 #endif // CHARACTERSHEETWINDOW_H