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

0001 /*
0002     Cahoots is a crossplatform real-time collaborative text editor.
0003 
0004     Copyright (C) 2010 Chris Dimpfl, Anandi Hira, David Vega
0005 
0006     This program is free software: you can redistribute it and/or modify
0007     it under the terms of the GNU General Public License as published by
0008     the Free Software Foundation, either version 3 of the License, or
0009     (at your option) any later version.
0010 
0011     This program is distributed in the hope that it will be useful,
0012     but WITHOUT ANY WARRANTY; without even the implied warranty of
0013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014     GNU General Public License for more details.
0015 
0016     You should have received a copy of the GNU General Public License
0017     along with this program.  If not, see <http://www.gnu.org/licenses/>.
0018 */
0019 #ifndef MAINWINDOW_H
0020 #define MAINWINDOW_H
0021 
0022 #include "document.h"
0023 #include "finddialog.h"
0024 #include "findtoolbar.h"
0025 #include "rwidgets_global.h"
0026 #include <QMainWindow>
0027 #include <QSettings>
0028 #include <QTextStream>
0029 //#include "preferencesdialog.h"
0030 
0031 class Player;
0032 class NetworkMessageReader;
0033 class NetworkMessageWriter;
0034 class SharedNoteController;
0035 
0036 namespace Ui
0037 {
0038 class SharedNote;
0039 }
0040 
0041 class RWIDGET_EXPORT SharedNote : public QMainWindow
0042 {
0043     Q_OBJECT
0044 
0045 public:
0046     SharedNote(SharedNoteController* ctrl, QWidget* parent= nullptr);
0047     ~SharedNote();
0048 
0049     bool saveFileAsText(QTextStream& out);
0050     bool loadFileAsText(QTextStream& out, bool md);
0051 
0052     bool saveFile(QDataStream& out);
0053     bool loadFile(QDataStream& fileName);
0054 
0055     void setCurrentFile(const QString& fileName);
0056     QString strippedName(const QString& fullFileName);
0057 
0058     void readSettings();
0059     void writeSettings();
0060 
0061     void displaySharingPanel();
0062     void setOwnerId(const QString& id);
0063 
0064     QString id() const;
0065     void setId(const QString& id);
0066 
0067 public slots:
0068     void updateDocumentToAll(NetworkMessageWriter* msg);
0069     void textHasChanged(int pos, int charsRemoved, int charsAdded);
0070 
0071     void playerPermissionsChanged(QString, int);
0072     void populateDocumentForUser(QString id);
0073 
0074 protected:
0075     void closeEvent(QCloseEvent* event);
0076     bool eventFilter(QObject*, QEvent* event);
0077 
0078     void updateWindowTitle();
0079 private slots:
0080     //  bool fileSaveAs();
0081 
0082     void on_actionFile_Print_triggered();
0083 
0084     void on_actionEdit_Undo_triggered();
0085     void on_actionEdit_Redo_triggered();
0086     void on_actionEdit_Cut_triggered();
0087     void on_actionEdit_Copy_triggered();
0088     void on_actionEdit_Paste_triggered();
0089     void on_actionEdit_Find_All_triggered();
0090     void on_actionEdit_Find_triggered();
0091 
0092     void on_actionView_Line_Wrap_triggered();
0093     void on_actionText_Shift_Left_triggered();
0094     void on_actionText_Shift_Right_triggered();
0095     void on_actionText_Comment_Line_triggered();
0096 
0097     void setUndoability(bool b);
0098     void setRedoability(bool b);
0099 
0100     void documentChanged();
0101     void tabCloseClicked();
0102 
0103     void findNextTriggered(QString str, Qt::CaseSensitivity, bool wrapAround, Enu::FindMode mode);
0104     void findPrevTriggered(QString str, Qt::CaseSensitivity, bool wrapAround, Enu::FindMode mode);
0105     void replaceAllTriggered(QString find, QString replace, Qt::CaseSensitivity sensitivity, Enu::FindMode mode);
0106     void replaceTriggered(QString replace);
0107     void findReplaceTriggered(QString find, QString replace, Qt::CaseSensitivity sensitivity, bool wrapAround,
0108                               Enu::FindMode mode);
0109 
0110     void setEditorFont(QFont font);
0111     void setParticipantsFont(QFont font);
0112 
0113     void on_m_markdownPreview_triggered();
0114 
0115 private:
0116     QPointer<SharedNoteController> m_sharedCtrl;
0117     Ui::SharedNote* ui= nullptr;
0118     FindDialog* findDialog= nullptr;
0119     Document* m_document= nullptr;
0120     bool m_networkEditing= false;
0121     QString m_id; // global name used for connecting to documents
0122 };
0123 
0124 #endif // MAINWINDOW_H