1 /* 2 Drawpile - a collaborative drawing program. 3 4 Copyright (C) 2006-2017 Calle Laakkonen 5 6 Drawpile is free software: you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 Drawpile is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with Drawpile. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 #ifndef MAINWINDOW_H 20 #define MAINWINDOW_H 21 22 #include <QMainWindow> 23 #include <QElapsedTimer> 24 #include <QUrl> 25 26 #include "tools/tool.h" 27 #include "canvas/features.h" 28 29 class QActionGroup; 30 class QMessageBox; 31 class QUrl; 32 class QLabel; 33 class QSplitter; 34 class QTimer; 35 class QToolButton; 36 class QListView; 37 38 class Document; 39 class ActionBuilder; 40 41 namespace widgets { 42 class CanvasView; 43 class NetStatus; 44 class ChatBox; 45 class UserItemDelegate; 46 class ViewStatus; 47 } 48 namespace docks { 49 class ToolSettings; 50 class BrushPalette; 51 class InputSettings; 52 class LayerList; 53 class PaletteBox; 54 class ColorBox; 55 class Navigator; 56 } 57 namespace dialogs { 58 class PlaybackDialog; 59 class HostDialog; 60 class SessionSettingsDialog; 61 class ServerLogDialog; 62 } 63 namespace drawingboard { 64 class CanvasScene; 65 } 66 namespace canvas { 67 class CanvasModel; 68 class SessionLoader; 69 } 70 71 namespace net { 72 class Client; 73 class LoginHandler; 74 } 75 76 namespace recording { 77 class Writer; 78 class Reader; 79 } 80 81 namespace tools { 82 class ToolController; 83 } 84 85 class ShortcutDetector; 86 87 //! The application main window 88 class MainWindow : public QMainWindow { 89 Q_OBJECT 90 public: 91 MainWindow(bool restoreWindowPosition=true); 92 ~MainWindow(); 93 94 MainWindow *loadDocument(canvas::SessionLoader &loader); 95 MainWindow *loadRecording(recording::Reader *reader); 96 97 //! Host a session using the settings from the given dialog 98 void hostSession(dialogs::HostDialog *dlg); 99 100 //! Connect to a host and join a session if full URL is provided. 101 void joinSession(const QUrl& url, const QString &autoRecordFilename=QString()); 102 103 //! Check if the current board can be replaced 104 bool canReplace() const; 105 106 //! Save settings and exit 107 void exit(); 108 109 public slots: 110 // Triggerable actions 111 void showNew(); 112 void open(); 113 void open(const QUrl &url); 114 void save(); 115 void saveas(); 116 void exportAnimation(); 117 void exportTemplate(); 118 void showFlipbook(); 119 120 static void showSettings(); 121 void reportAbuse(); 122 void tryToGainOp(); 123 void resetSession(); 124 void terminateSession(); 125 126 void host(); 127 void join(const QUrl &defaultUrl=QUrl()); 128 void leave(); 129 130 void toggleFullscreen(); 131 void setShowAnnotations(bool show); 132 void setShowLaserTrails(bool show); 133 134 void selectTool(QAction *tool); 135 136 static void about(); 137 static void homepage(); 138 139 //! Create a blank new document 140 void newDocument(const QSize &size, const QColor &background); 141 142 private slots: 143 void toggleRecording(); 144 145 void onOperatorModeChange(bool op); 146 void onFeatureAccessChange(canvas::Feature feature, bool canUse); 147 148 void onServerConnected(); 149 void onServerLogin(); 150 void onServerDisconnected(const QString &message, const QString &errorcode, bool localDisconnect); 151 void onNsfmChanged(bool nsfm); 152 153 void updateLockWidget(); 154 void setRecorderStatus(bool on); 155 156 void loadShortcuts(); 157 void updateSettings(); 158 159 void updateLayerViewMode(); 160 161 void copyText(); 162 void paste(); 163 void pasteFile(); 164 void pasteFile(const QUrl &url); 165 void pasteImage(const QImage &image, const QPoint *point=nullptr); 166 void dropUrl(const QUrl &url); 167 168 void clearOrDelete(); 169 170 void resizeCanvas(); 171 void changeCanvasBackground(); 172 void markSpotForRecording(); 173 174 void toolChanged(tools::Tool::Type tool); 175 176 void selectionRemoved(); 177 178 void hotBorderMenubar(bool show); 179 180 void setFreezeDocks(bool freeze); 181 void setDocksHidden(bool hidden); 182 183 void updateTitle(); 184 185 void onCanvasChanged(canvas::CanvasModel *canvas); 186 void onCanvasSaveStarted(); 187 void onCanvasSaved(const QString &errorMessage); 188 189 protected: 190 void closeEvent(QCloseEvent *event); 191 bool event(QEvent *event); 192 193 private: 194 //! Confirm saving of image in a format that doesn't support all required features 195 bool confirmFlatten(QString& file) const; 196 197 ActionBuilder makeAction(const char *name, const QString &text); 198 QAction *getAction(const QString &name); 199 200 //! Add a new entry to recent files list 201 void addRecentFile(const QString& file); 202 203 //! Enable or disable drawing tools 204 void setDrawingToolsEnabled(bool enable); 205 206 //! Display an error message 207 void showErrorMessage(const QString& message, const QString& details=QString()); 208 209 void readSettings(bool windowpos=true); 210 void writeSettings(); 211 212 void createDocks(); 213 void setupActions(); 214 215 QSplitter *m_splitter; 216 217 docks::ToolSettings *m_dockToolSettings; 218 docks::BrushPalette *m_dockBrushPalette; 219 docks::InputSettings *m_dockInput; 220 docks::LayerList *m_dockLayers; 221 docks::ColorBox *m_dockColors; 222 docks::Navigator *m_dockNavigator; 223 widgets::ChatBox *m_chatbox; 224 225 widgets::CanvasView *m_view; 226 227 QStatusBar *m_viewStatusBar; 228 QLabel *m_lockstatus; 229 widgets::NetStatus *m_netstatus; 230 widgets::ViewStatus *m_viewstatus; 231 QToolButton *m_statusChatButton; 232 233 dialogs::PlaybackDialog *m_playbackDialog; 234 dialogs::SessionSettingsDialog *m_sessionSettings; 235 dialogs::ServerLogDialog *m_serverLogDialog; 236 237 drawingboard::CanvasScene *m_canvasscene; 238 239 QMenu *m_recentMenu; 240 241 QActionGroup *m_currentdoctools; // general tools that require no special permissions 242 QActionGroup *m_admintools; // session operator actions 243 QActionGroup *m_modtools; // session moderator tools 244 QActionGroup *m_canvasbgtools; // tools related to canvas background feature 245 QActionGroup *m_resizetools; // tools related to canvas resizing feature 246 QActionGroup *m_putimagetools; // Cut&Paste related tools 247 QActionGroup *m_undotools; // undo&redo related tools 248 QActionGroup *m_drawingtools; // drawing tool selection 249 QActionGroup *m_brushSlots; // tool slot shortcuts 250 251 int m_lastToolBeforePaste; // Last selected tool before Paste was used 252 253 QMetaObject::Connection m_textCopyConnection; 254 255 // Remember window state to return from fullscreen mode 256 QRect m_fullscreenOldGeometry; 257 bool m_fullscreenOldMaximized; 258 259 QElapsedTimer m_toolChangeTime; // how long the user has held down the tool change button 260 ShortcutDetector *m_tempToolSwitchShortcut; 261 262 Document *m_doc; 263 bool m_exitAfterSave; 264 }; 265 266 #endif 267 268