From edc65c7afadf9ae97f729588f07bf971d524a6f8 Mon Sep 17 00:00:00 2001 From: wordring Date: Thu, 6 Aug 2015 17:34:17 +0900 Subject: [PATCH] =?utf8?q?=E5=8D=98=E8=AA=9E=E9=96=93=E3=81=AE=E3=83=AA?= =?utf8?q?=E3=83=B3=E3=82=AF=E3=81=AB=E3=81=A4=E3=81=84=E3=81=A6UI?= =?utf8?q?=E9=83=A8=E5=88=86=E3=81=AE=E3=81=BF=E5=AE=9F=E8=A3=85=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- proxy/main.cpp | 2 +- proxy/textwidget.cpp | 6 +++++ proxy/textwidget.h | 1 + proxy/tmtext.cpp | 6 +++++ proxy/tmtext.h | 2 ++ proxy/tmwidget.cpp | 64 ++++++++++++++++++++++++++++++++++------------------ proxy/tmwidget.h | 5 ++-- 7 files changed, 61 insertions(+), 25 deletions(-) diff --git a/proxy/main.cpp b/proxy/main.cpp index 85a6831..4d789d6 100644 --- a/proxy/main.cpp +++ b/proxy/main.cpp @@ -27,7 +27,7 @@ int main(int argc, char *argv[]) QString path = QStandardPaths::writableLocation( QStandardPaths::ConfigLocation) + "/settings.ini"; QSettings settings(path, QSettings::IniFormat); - QString apppath = QCoreApplication::applicationDirPath(); + //QString apppath = QCoreApplication::applicationDirPath(); settings.setValue("language/japanese/mecabdic", "C:/Users/Kouichi/Documents/mecab ipadic"); diff --git a/proxy/textwidget.cpp b/proxy/textwidget.cpp index 6cc7c5d..cd0066e 100644 --- a/proxy/textwidget.cpp +++ b/proxy/textwidget.cpp @@ -144,6 +144,12 @@ QVariant TextPanel::inputMethodQuery(Qt::InputMethodQuery property) const return QPlainTextEdit::inputMethodQuery(property); } +void TextPanel::insertFromMimeData(QMimeData const *source) +{ + QPlainTextEdit::insertFromMimeData(source); + parent_text_area()->perform_resize(); +} + /*! * \brief キーボードメッセージに対する処理を行います。 * diff --git a/proxy/textwidget.h b/proxy/textwidget.h index 5172288..a587975 100644 --- a/proxy/textwidget.h +++ b/proxy/textwidget.h @@ -60,6 +60,7 @@ protected: void hideEvent(QHideEvent *ev); void inputMethodEvent(QInputMethodEvent *ev); QVariant inputMethodQuery(Qt::InputMethodQuery property) const; + void insertFromMimeData(QMimeData const *source); void keyPressEvent(QKeyEvent *ev); void mousePressEvent(QMouseEvent *ev); void mouseReleaseEvent(QMouseEvent *ev); diff --git a/proxy/tmtext.cpp b/proxy/tmtext.cpp index dfedf54..ad224a4 100644 --- a/proxy/tmtext.cpp +++ b/proxy/tmtext.cpp @@ -85,6 +85,12 @@ TM::WordLink::pointer TM::WordLink::create(int place, Text::pointer word) // WordLinker ----------------------------------------------------------------- +void TM::WordLinker::clear() +{ + m_current_link.reset(); + m_links.clear(); +} + /*! * \brief リンクの編集を開始します。 */ diff --git a/proxy/tmtext.h b/proxy/tmtext.h index 2ac7ae2..f53d22a 100644 --- a/proxy/tmtext.h +++ b/proxy/tmtext.h @@ -70,6 +70,8 @@ public: typedef storage_type::const_iterator const_iterator; public: + void clear(); + void start(); void commit(); void append(int place, Text::pointer word); diff --git a/proxy/tmwidget.cpp b/proxy/tmwidget.cpp index 258ced4..26e6f02 100644 --- a/proxy/tmwidget.cpp +++ b/proxy/tmwidget.cpp @@ -131,7 +131,12 @@ bool TM::Widget::link_mode() return m_link->isChecked(); } -void TM::Widget::disable_link_mode(bool disable) +/*! + * \brief リンクボタンをグレーアウトします。 + * + * + */ +void TM::Widget::set_link_mode_disabled(bool disable) { QMutexLocker lock(&m_mutex); m_link->setDisabled(disable); @@ -458,7 +463,11 @@ void TM::TargetPanel::set_sentence(Text::pointer sentence) bool TM::TargetPanel::is_text_dirty() const { return m_text_dirty; } -void TM::TargetPanel::set_text_dirty(bool dirty) { m_text_dirty = dirty; } +void TM::TargetPanel::set_text_dirty(bool dirty) +{ + m_text_dirty = dirty; + if(dirty) m_editor->parent_widget()->set_link_mode_disabled(false); +} bool TM::TargetPanel::canInsertFromMimeData(QMimeData const *source) const { @@ -466,6 +475,12 @@ bool TM::TargetPanel::canInsertFromMimeData(QMimeData const *source) const return false; } +void TM::TargetPanel::insertFromMimeData(QMimeData const *source) +{ + TextPanel::insertFromMimeData(source); + set_text_dirty(true); +} + void TM::TargetPanel::inputMethodEvent(QInputMethodEvent *ev) { if(m_editor->link_mode()) ev->setCommitString(""); @@ -473,10 +488,14 @@ void TM::TargetPanel::inputMethodEvent(QInputMethodEvent *ev) QPlainTextEdit::inputMethodEvent(ev); } -void TM::TargetPanel::keyPressEvent_(QKeyEvent *ev) +void TM::TargetPanel::keyPressEvent(QKeyEvent *ev) { if(m_editor->link_mode()) do_key_press_in_link_mode(ev); - else QPlainTextEdit::keyPressEvent(ev); + else + { + TextPanel::keyPressEvent(ev); + if(!ev->text().isEmpty()) set_text_dirty(true); + } } void TM::TargetPanel::do_click(QPoint const &pos) @@ -512,10 +531,15 @@ void TM::TargetPanel::do_key_press_in_link_mode(QKeyEvent *ev) { case Qt::Key_Enter: case Qt::Key_Return: - if(m_editor->link_mode()) m_editor->set_link_mode(false); + m_editor->set_link_mode(false); + break; + case Qt::Key_Left: + case Qt::Key_Right: + case Qt::Key_Up: + case Qt::Key_Down: + TextPanel::keyPressEvent(ev); break; } - } // Editor --------------------------------------------------------------------- @@ -539,6 +563,7 @@ void TM::Editor::clear() TextArea *ta = text_area(); ta->clear(); set_link_mode(false); + parent_widget()->set_link_mode_disabled(true); } void TM::Editor::set_sentences(Text::pointer sentences) @@ -604,17 +629,7 @@ TM::TargetPanel const* TM::Editor::current_target_panel() const { return const_cast(this)->current_target_panel(); } -/* -bool TM::Editor::is_panel_changed(TextPanel *new_) const -{ - SourcePanel *sp = qobject_cast(new_); - if(sp) return sp != m_current_source_panel; - TargetPanel *tp = qobject_cast(new_); - if(tp) return tp->source_panel() != m_current_source_panel; - assert(false); - return false; -} -*/ + void TM::Editor::onFocusInChild(TextPanel *new_, TextPanel *) { SourcePanel *old_panel = m_current_source_panel; @@ -643,7 +658,7 @@ void TM::Editor::do_panel_enter(SourcePanel *panel) TargetPanel *tp = panel->target_panel(); assert(tp); tp->show(); - if(can_link_mode()) parent_widget()->disable_link_mode(false); + if(can_link_mode()) parent_widget()->set_link_mode_disabled(false); } /*! @@ -656,9 +671,12 @@ void TM::Editor::do_panel_leave(SourcePanel *panel) tp->hide(); set_link_mode(false); - parent_widget()->disable_link_mode(true); + parent_widget()->set_link_mode_disabled(true); } +/*! + * \brief リンクモードに入るとき呼び出されます。 + */ void TM::Editor::do_link_mode_enter(SourcePanel *panel) { assert(panel); @@ -666,9 +684,9 @@ void TM::Editor::do_link_mode_enter(SourcePanel *panel) assert(tp); int tcode = parent_widget()->target_language(); - if(tp && tp->is_text_dirty()) + if(tp->is_text_dirty()) { - qDebug() << "dirty"; + panel->linker()->clear(); QString string = tp->toPlainText(); Text::pointer sentences = m_service->divide_into_sentences(tcode, string); if(sentences->size()) @@ -681,12 +699,14 @@ void TM::Editor::do_link_mode_enter(SourcePanel *panel) panel->ensure_highlight(); } +/*! + * \brief リンクモードから出るとき呼び出されます。 + */ void TM::Editor::do_link_mode_leave(SourcePanel *panel) { assert(panel); panel->commit_link(); panel->clear_highlight(); - qDebug() << "do_link_mode_leave"; } diff --git a/proxy/tmwidget.h b/proxy/tmwidget.h index d0fee62..5e2d71d 100644 --- a/proxy/tmwidget.h +++ b/proxy/tmwidget.h @@ -51,7 +51,7 @@ public: bool edit_mode(); void set_link_mode(bool mode); bool link_mode(); - void disable_link_mode(bool disable); + void set_link_mode_disabled(bool disable); int source_language(); int target_language(); @@ -162,9 +162,10 @@ public: protected: bool canInsertFromMimeData(QMimeData const *source) const; + void insertFromMimeData(QMimeData const *source); void inputMethodEvent(QInputMethodEvent *ev); - void keyPressEvent_(QKeyEvent *ev); + void keyPressEvent(QKeyEvent *ev); //void do_enter(); void do_click(QPoint const &pos); -- 2.11.0