X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=proxy%2Ftmwidget.cpp;h=26e6f02c47fb2061607f049644f09dfd071cc9d2;hb=edc65c7afadf9ae97f729588f07bf971d524a6f8;hp=258ced406f3c088a3ab8d2dd6a4ef2f26219b3bb;hpb=eae89ca820562929d9c8d6e902a564d572c7eac0;p=wordring-tm%2Fwordring-tm.git 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"; }