5 #include "textwidget.h"
11 #include <QPlainTextEdit>
12 #include <QTextCursor>
19 #include <QJsonDocument>
20 #include <QJsonObject>
43 class SocketConnection;
47 class EditorWidget : public QWidget
51 EditorWidget(Settings *settings, Service *service, QWidget *parent = 0);
53 void attach(SocketConnection *socket);
54 void detach(SocketConnection *socket);
56 void set_http_port(quint16 http_port);
58 void set_edit_mode(bool mode);
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_string(QString source_, QString target_);
68 void append_sentence();
72 void editModeChanged(bool mode_);
73 void linkModeChanged(bool mode_);
75 void contentsEdited();
78 void onLanguageLoaded(int code, QString name, QIcon icon);
79 void onEditModeTriggered(bool);
80 void onLinkModeTriggered(bool checked);
81 void onSourceLanguageTriggered(bool);
82 void onTargetLanguageTriggered(bool);
83 void onBrowserTriggered(bool);
90 SocketConnection *m_socket;
101 class EditorPanel : public TextPanel
105 enum : int { Word = QTextFormat::UserProperty };
108 explicit EditorPanel(QWidget *parent);
109 void set_editor(Editor *editor);
111 Text::pointer sentence();
112 virtual void set_sentence(Text::pointer sentence);
114 bool is_empty() const;
116 QTextCursor select_cursor(Text::pointer word);
117 Text::pointer select_word(QPoint const &pos);
118 void highlight(Text::pointer word, QColor color);
119 void highlight(WordLink::storage_type *link, QColor color);
120 void clear_highlight();
122 QColor color(int index) const;
126 Text::pointer m_sentence;
129 class SourcePanel : public EditorPanel
133 explicit SourcePanel(QWidget *parent);
135 TargetPanel* target_panel();
136 void set_target_panel(TargetPanel *target);
139 WordLinker* linker();
141 void ensure_highlight();
144 bool canInsertFromMimeData(QMimeData const *source) const;
145 void insertFromMimeData(QMimeData const *source);
147 void inputMethodEvent(QInputMethodEvent *ev);
148 void keyPressEvent(QKeyEvent *ev);
151 void do_click(QPoint const &pos);
152 void do_click_in_link_mode(QPoint const &pos);
158 TargetPanel *m_target_panel;
162 class TargetPanel: public EditorPanel
166 explicit TargetPanel(QWidget *parent);
168 SourcePanel* source_panel();
169 void set_source_panel(SourcePanel *source);
171 void set_sentence(Text::pointer sentence);
173 bool is_text_saved() const;
174 void set_text_saved(bool saved);
176 bool is_text_dirty() const;
177 void set_text_dirty(bool dirty);
180 bool canInsertFromMimeData(QMimeData const *source) const;
181 void insertFromMimeData(QMimeData const *source);
183 void inputMethodEvent(QInputMethodEvent *ev);
184 void keyPressEvent(QKeyEvent *ev);
187 void do_click(QPoint const &pos);
188 void do_click_in_link_mode(QPoint const &pos);
193 void do_key_press_in_link_mode(QKeyEvent *ev);
196 SourcePanel *m_source_panel;
197 bool m_text_dirty; /*!< 内容の変更を示すフラグ */
198 bool m_text_saved; /*!< データベース登録の必要性を示すフラグ */
201 class Editor : public TextWidget
205 Editor(Settings *settings, Service *service, QWidget *parent);
208 void set_sentences(Text::pointer sentences);
210 bool edit_mode() const;
211 void set_edit_mode(bool mode_);
212 bool link_mode() const;
213 void set_link_mode(bool mode_);
215 bool can_link_mode() const;
217 EditorWidget* parent_editor_widget();
218 TargetPanel* current_target_panel();
219 TargetPanel const* current_target_panel() const;
221 //bool is_panel_changed(TextPanel *new_) const;
224 void onFocusInChild(TextPanel *new_, TextPanel *old_);
227 SourcePanel* find_source_panel(TextPanel *panel);
229 void do_panel_enter(SourcePanel *panel);
230 void do_panel_leave(SourcePanel *panel);
231 void do_link_mode_enter(SourcePanel *panel);
232 void do_link_mode_leave(SourcePanel *panel);
235 Settings *m_settings;
238 Text::pointer m_sentences;
239 bool m_edit_mode; /*!< 編集モードのときtrue */
240 bool m_link_mode; /*!< リンクモードのときtrue */
242 SourcePanel *m_current_source_panel;