5 #include "textwidget.h"
12 #include <QPlainTextEdit>
13 #include <QTextCursor>
20 #include <QJsonDocument>
21 #include <QJsonObject>
43 //class SocketConnection;
48 class EditorWidget : public QWidget
52 EditorWidget(Settings *settings, Service *service, QWidget *parent = 0);
54 void attach(SocketConnection *socket);
55 void detach(SocketConnection *connection);
57 void set_http_port(quint16 http_port);
60 void set_link_mode(bool mode);
62 void set_link_mode_disabled(bool disable);
64 int source_language();
65 int target_language();
67 void set_segment(TextSegment::pointer segment);
68 void save_sentence(TextSentence::pointer text_sentence);
69 void remove_sentence(TextSentence::pointer text_sentence);
71 void do_panel_entered(SourcePanel *panel);
72 void do_panel_leaved(SourcePanel *panel);
75 //void editModeChanged(bool mode_);
76 void linkModeChanged(bool mode_);
77 void sourceLanguageChanged();
78 void targetLanguageChanged();
81 void onLanguageLoaded(int code, QString name, QIcon icon);
82 void onEditModeTriggered(bool);
83 void onLinkModeTriggered(bool checked);
84 void onSourceLanguageTriggered(bool);
85 void onTargetLanguageTriggered(bool);
86 void onBrowserTriggered(bool);
92 SocketConnection *m_socket;
103 class EditorPanel : public TextPanel
107 enum : int { Word = QTextFormat::UserProperty };
110 explicit EditorPanel(QWidget *parent);
112 Editor* parent_editor();
113 void set_parent_editor(Editor *editor);
115 virtual Text::pointer sentence() = 0;
116 virtual void ensure_sentence();
118 bool is_empty() const;
120 QTextCursor select_cursor(Text::pointer word);
121 Text::pointer select_word(QPoint const &pos);
122 void highlight(Text::pointer word, QColor color);
123 void highlight(WordLink::storage_type *link, QColor color);
124 void clear_highlight();
126 QColor color(int index) const;
133 Editor *m_parent_editor;
136 class SourcePanel : public EditorPanel
140 explicit SourcePanel(QWidget *parent);
143 void set_index(int index);
145 Text::pointer sentence();
146 Text::pointer source_sentence();
147 Text::pointer target_sentence();
148 void set_target_sentence(Text::pointer sentence);
150 TextSentence::pointer text_sentence();
151 void set_text_sentence(TextSentence::pointer text_sentence);
153 TargetPanel* target_panel();
154 void set_target_panel(TargetPanel *target);
157 WordLinker* linker();
159 void ensure_highlight();
162 bool canInsertFromMimeData(QMimeData const *source) const;
163 void insertFromMimeData(QMimeData const *source);
165 void inputMethodEvent(QInputMethodEvent *ev);
166 void keyPressEvent(QKeyEvent *ev);
168 void do_click(QPoint const &pos);
169 void do_click_in_link_mode(QPoint const &pos);
172 int m_index; /*!< Editor上での位置を示す索引 */
173 TargetPanel *m_target_panel;
174 TextSentence::pointer m_text_sentence;
177 class TargetPanel: public EditorPanel
181 explicit TargetPanel(QWidget *parent);
183 SourcePanel* source_panel();
184 void set_source_panel(SourcePanel *source);
186 Text::pointer sentence();
187 void save_sentence();
188 void ensure_sentence();
190 bool is_text_saved() const;
191 void set_text_saved(bool saved);
193 bool is_text_dirty() const;
194 void set_text_dirty(bool dirty);
197 bool canInsertFromMimeData(QMimeData const *source) const;
198 void insertFromMimeData(QMimeData const *source);
200 void inputMethodEvent(QInputMethodEvent *ev);
201 void keyPressEvent(QKeyEvent *ev);
203 void do_click(QPoint const &pos);
204 void do_click_in_link_mode(QPoint const &pos);
206 void do_key_press_in_link_mode(QKeyEvent *ev);
209 SourcePanel *m_source_panel;
210 bool m_text_dirty; /*!< 内容の変更を示すフラグ */
211 bool m_text_saved; /*!< データベース登録の必要性を示すフラグ */
214 class Editor : public TextWidget
218 Editor(Settings *settings, Service *service, QWidget *parent);
221 void set_segment(TextSegment::pointer segment);
223 bool edit_mode() const;
224 void set_edit_mode(bool mode_);
225 bool link_mode() const;
226 void set_link_mode(bool mode_);
228 bool can_link_mode() const;
230 EditorWidget* parent_editor_widget();
232 TargetPanel* current_target_panel();
233 TargetPanel const* current_target_panel() const;
236 void onFocusInChild(TextPanel *new_, TextPanel *old_);
239 SourcePanel* find_source_panel(TextPanel *panel);
241 void do_panel_enter(SourcePanel *panel);
242 void do_panel_leave(SourcePanel *panel);
243 void do_link_mode_enter(SourcePanel *panel);
244 void do_link_mode_leave(SourcePanel *panel);
247 void divide_target_sentence(SourcePanel *source_panel);
250 Settings *m_settings;
254 bool m_edit_mode; /*!< 編集モードのときtrue */
255 bool m_link_mode; /*!< リンクモードのときtrue */
257 SourcePanel *m_current_source_panel;