File indexing completed on 2024-05-12 05:39:48
0001 /*************************************************************************** 0002 * Copyright (C) 2019 by Renaud Guezennec * 0003 * http://www.rolisteam.org/contact * 0004 * * 0005 * This software 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 #ifndef CONTENTCONTROLLER_H 0021 #define CONTENTCONTROLLER_H 0022 0023 #include <QClipboard> 0024 #include <QFileSystemModel> 0025 #include <QModelIndexList> 0026 #include <QObject> 0027 #include <QPointer> 0028 #include <map> 0029 #include <memory> 0030 0031 #include "controller/controllerinterface.h" 0032 0033 #include "media/mediatype.h" 0034 #include "network/receiveevent.h" 0035 #include "preferences/preferenceslistener.h" 0036 #include <core_global.h> 0037 0038 #include "model/contentmodel.h" 0039 #include "model/historymodel.h" 0040 0041 namespace campaign 0042 { 0043 class CampaignEditor; 0044 class CampaignManager; 0045 } // namespace campaign 0046 class MediaContainer; 0047 class QAbstractItemModel; 0048 class ResourcesNode; 0049 class PreferencesManager; 0050 class NetworkMessageReader; 0051 class NetworkController; 0052 class MapMediaController; 0053 class CharacterModel; 0054 class PdfMediaController; 0055 class PlayerModel; 0056 class NoteMediaController; 0057 class MediaControllerBase; 0058 class MediaUpdaterInterface; 0059 class DiceRoller; 0060 0061 class CORE_EXPORT ContentController : public AbstractControllerInterface, 0062 public PreferencesListener, 0063 public NetWorkReceiver 0064 { 0065 Q_OBJECT 0066 Q_PROPERTY(QFileSystemModel* sessionModel READ sessionModel CONSTANT) 0067 Q_PROPERTY(ContentModel* contentModel READ contentModel CONSTANT) 0068 Q_PROPERTY(history::HistoryModel* historyModel READ historyModel CONSTANT) 0069 Q_PROPERTY(QString workspaceFilename READ workspaceFilename NOTIFY workspaceFilenameChanged) 0070 Q_PROPERTY(QColor workspaceColor READ workspaceColor NOTIFY workspaceColorChanged) 0071 Q_PROPERTY(int workspacePositioning READ workspacePositioning NOTIFY workspacePositioningChanged) 0072 Q_PROPERTY(bool shortTitleTab READ shortTitleTab NOTIFY shortTitleTabChanged) 0073 Q_PROPERTY(int maxLengthTabName READ maxLengthTabName NOTIFY maxLengthTabNameChanged) 0074 Q_PROPERTY(QString gameMasterId READ gameMasterId WRITE setGameMasterId NOTIFY gameMasterIdChanged) 0075 Q_PROPERTY(QString localId READ localId WRITE setLocalId NOTIFY localIdChanged) 0076 Q_PROPERTY(QColor localColor READ localColor WRITE setLocalColor NOTIFY localColorChanged) 0077 Q_PROPERTY(QString mediaRoot READ mediaRoot WRITE setMediaRoot NOTIFY mediaRootChanged) 0078 Q_PROPERTY(bool canPaste READ canPaste NOTIFY canPasteChanged) 0079 0080 public: 0081 explicit ContentController(campaign::CampaignManager* campaign, PlayerModel* playerModel, 0082 CharacterModel* characterModel, QClipboard* clipboard, QObject* parent= nullptr); 0083 ~ContentController() override; 0084 0085 QFileSystemModel* sessionModel() const; 0086 ContentModel* contentModel() const; 0087 history::HistoryModel* historyModel() const; 0088 int contentCount() const; 0089 0090 int maxLengthTabName() const; 0091 bool shortTitleTab() const; 0092 QString workspaceFilename() const; 0093 QColor workspaceColor() const; 0094 int workspacePositioning() const; 0095 0096 QString gameMasterId() const; 0097 QString currentMediaId() const; 0098 MediaControllerBase* media(const QString& id) const; 0099 QString localId() const; 0100 bool localIsGM() const; 0101 bool canPaste() const; 0102 bool canCopy() const; 0103 QString mediaRoot() const; 0104 0105 void setGameController(GameController*) override; 0106 void preferencesHasChanged(const QString& key) override; 0107 void newMedia(campaign::CampaignEditor* editor, 0108 const std::map<QString, QVariant>& params= std::map<QString, QVariant>()); 0109 void openMedia(const std::map<QString, QVariant>& params= std::map<QString, QVariant>()); 0110 void clear(); 0111 void clearHistory(); 0112 void closeCurrentMedia(); 0113 NetWorkReceiver::SendType processMessage(NetworkMessageReader* msg) override; 0114 0115 const QColor& localColor() const; 0116 void setLocalColor(const QColor& newLocalColor); 0117 0118 signals: 0119 void workspaceFilenameChanged(); 0120 void workspaceColorChanged(); 0121 void workspacePositioningChanged(); 0122 void shortTitleTabChanged(); 0123 void maxLengthTabNameChanged(); 0124 void mediaRootChanged(); 0125 void historyChanged(); 0126 0127 void sessionChanged(bool); 0128 void sessionNameChanged(); 0129 void sessionPathChanged(); 0130 void gameMasterIdChanged(const QString& gameMasterId); 0131 void localIdChanged(const QString& game); 0132 void mediaControllerCreated(MediaControllerBase* base); 0133 void canPasteChanged(bool); 0134 0135 void localColorChanged(); 0136 0137 public slots: 0138 // Session API 0139 void setGameMasterId(const QString& id); 0140 void setLocalId(const QString& id); 0141 void setMediaRoot(const QString& path); 0142 0143 void copyData(); 0144 void pasteData(); 0145 0146 private: 0147 void readMimeData(const QMimeData& data); 0148 0149 private: 0150 std::unique_ptr<QFileSystemModel> m_sessionModel; 0151 std::map<Core::ContentType, std::unique_ptr<MediaUpdaterInterface>> m_mediaUpdaters; 0152 std::unique_ptr<ContentModel> m_contentModel; 0153 std::unique_ptr<history::HistoryModel> m_historyModel; 0154 0155 QPointer<QClipboard> m_clipboard; 0156 0157 PreferencesManager* m_preferences= nullptr; 0158 QString m_gameMasterId; 0159 QString m_localId; 0160 QColor m_localColor; 0161 }; 0162 0163 #endif // CONTENTCONTROLLER_H