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

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 DOCUMENT_H
0020 #define DOCUMENT_H
0021 
0022 #include "codeeditor.h"
0023 #include "enu.h"
0024 #include "findtoolbar.h"
0025 #include "model/participantmodel.h"
0026 #include "network/networkmessagewriter.h"
0027 #include "participantspane.h"
0028 #include "rwidgets_global.h"
0029 #include <QSyntaxHighlighter>
0030 #include <QWidget>
0031 
0032 //#include "client.h"
0033 //#include "server.h"
0034 
0035 namespace Ui
0036 {
0037 class Document;
0038 }
0039 class SharedNoteController;
0040 class RWIDGET_EXPORT Document : public QWidget
0041 {
0042     Q_OBJECT
0043 public:
0044     Document(SharedNoteController* ctrl, QWidget* parent= nullptr);
0045     ~Document();
0046 
0047     // This sets up the document so people can connect to it.
0048     // Hopefully we can do something with Bonjour so you can browse for local documents
0049     // but that's down the road.
0050     void displayParticipantPanel();
0051     void setEditorFont(QFont font);
0052     void setParticipantsFont(QFont font);
0053 
0054     void undo();
0055     void redo();
0056     void cut();
0057     void copy();
0058     void paste();
0059 
0060     // shows/hides the participants pane
0061     void setParticipantsHidden(bool b);
0062     // shifts the current line/selected lines left
0063     void shiftLeft();
0064     // shifts the current line/selected lines right
0065     void shiftRight();
0066     // C++ style (un)commenting
0067     void unCommentSelection();
0068 
0069     // User wants to resynchronize the document with the owner
0070     // void fill(NetworkMessageWriter* msg);
0071     // void readFromMsg(NetworkMessageReader* msg);
0072 
0073     // returns if the editor is undable
0074     bool isUndoable();
0075     // returns if the editor is redoable
0076     bool isRedoable();
0077     // returns if the editor is modified (unsaved since last edit)
0078     bool isModified();
0079     // returns if the chat pane is hidden, used for determining which actions to enable/disable by the main window
0080     bool isChatHidden();
0081     // returns if the participants pane is hidden, used for determining which actions to enable/disable in the MW
0082     bool isParticipantsHidden();
0083 
0084     // Find functions
0085     void findAll();
0086     void findNext(QString searchString, Qt::CaseSensitivity sensitivity, bool wrapAround, Enu::FindMode mode);
0087     void findPrev(QString searchString, Qt::CaseSensitivity sensitivity, bool wrapAround, Enu::FindMode mode);
0088     void replaceAll(QString searchString, QString replaceString, Qt::CaseSensitivity sensitivity, Enu::FindMode mode);
0089     void replace(QString replaceString);
0090     void findReplace(QString searchString, QString replaceString, Qt::CaseSensitivity sensitivity, bool wrapAround,
0091                      Enu::FindMode mode);
0092 
0093     QString getPlainText();
0094     void setPlainText(QString text);
0095 
0096     QTextDocument* getDocument();
0097 
0098     void toggleLineWrap();
0099     void setModified(bool b);
0100     void renderMarkdown();
0101     bool docHasCollaborated();
0102 
0103     void setOwnerName(QString name);
0104 
0105     ParticipantsPane* getParticipantPane() const;
0106     void setParticipantPane(ParticipantsPane* participantPane);
0107 
0108 signals:
0109     void redoAvailable(bool);
0110     void undoAvailable(bool);
0111     void notFound();
0112     void contentChanged();
0113 
0114 private slots:
0115     // triggered by the find toolbar, not the dialog
0116     void findNext(QString string);
0117     void findPrevious(QString string);
0118     void updateHighlighter();
0119 
0120 private:
0121     QPointer<SharedNoteController> m_shareCtrl;
0122     Ui::Document* ui= nullptr;
0123     sharedNotes::CodeEditor* m_editor= nullptr;
0124     QTextEdit* m_previewMarkdown= nullptr;
0125 
0126     bool startedCollaborating;
0127     FindToolBar* findAllToolbar= nullptr;
0128     std::unique_ptr<ParticipantsPane> m_participantPane;
0129     std::unique_ptr<QSyntaxHighlighter> m_highlighter;
0130 };
0131 
0132 #endif // DOCUMENT_H