diff options
author | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2009-05-27 11:58:48 (GMT) |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2009-06-15 18:17:23 (GMT) |
commit | 9ed7ec89e11a3badd59f8cfa130c2ee810164944 (patch) | |
tree | 7ed9f40b66834cd478951f40cf7cc5c8c2be1427 /tools/linguist | |
parent | 1e693674d390c50b90d73045019bb269f0c891b0 (diff) | |
download | Qt-9ed7ec89e11a3badd59f8cfa130c2ee810164944.zip Qt-9ed7ec89e11a3badd59f8cfa130c2ee810164944.tar.gz Qt-9ed7ec89e11a3badd59f8cfa130c2ee810164944.tar.bz2 |
greatly simplify exclusive selection handling
Diffstat (limited to 'tools/linguist')
-rw-r--r-- | tools/linguist/linguist/messageeditor.cpp | 100 | ||||
-rw-r--r-- | tools/linguist/linguist/messageeditor.h | 10 | ||||
-rw-r--r-- | tools/linguist/linguist/messageeditorwidgets.cpp | 7 | ||||
-rw-r--r-- | tools/linguist/linguist/messageeditorwidgets.h | 5 |
4 files changed, 49 insertions, 73 deletions
diff --git a/tools/linguist/linguist/messageeditor.cpp b/tools/linguist/linguist/messageeditor.cpp index 1f00c04..64264db 100644 --- a/tools/linguist/linguist/messageeditor.cpp +++ b/tools/linguist/linguist/messageeditor.cpp @@ -91,9 +91,7 @@ MessageEditor::MessageEditor(MultiDataModel *dataModel, QMainWindow *parent) m_redoAvail(false), m_cutAvail(false), m_copyAvail(false), - m_sourceSelected(false), - m_pluralSourceSelected(false), - m_currentSelected(false) + m_selectionHolder(0) { setObjectName(QLatin1String("scroll area")); @@ -144,12 +142,14 @@ void MessageEditor::setupEditorPage() m_source = new FormWidget(tr("Source text"), false); m_source->setHideWhenEmpty(true); m_source->setWhatsThis(tr("This area shows the source text.")); - connect(m_source, SIGNAL(selectionChanged()), SLOT(selectionChanged())); + connect(m_source, SIGNAL(selectionChanged(QTextEdit *)), + SLOT(selectionChanged(QTextEdit *))); m_pluralSource = new FormWidget(tr("Source text (Plural)"), false); m_pluralSource->setHideWhenEmpty(true); m_pluralSource->setWhatsThis(tr("This area shows the plural form of the source text.")); - connect(m_pluralSource, SIGNAL(selectionChanged()), SLOT(selectionChanged())); + connect(m_pluralSource, SIGNAL(selectionChanged(QTextEdit *)), + SLOT(selectionChanged(QTextEdit *))); m_commentText = new FormWidget(tr("Developer comments"), false); m_commentText->setHideWhenEmpty(true); @@ -216,7 +216,8 @@ void MessageEditor::messageModelAppended() ed.transCommentText->setWhatsThis(tr("Here you can enter comments for your own use." " They have no effect on the translated applications.") ); ed.transCommentText->getEditor()->installEventFilter(this); - connect(ed.transCommentText, SIGNAL(selectionChanged()), SLOT(selectionChanged())); + connect(ed.transCommentText, SIGNAL(selectionChanged(QTextEdit *)), + SLOT(selectionChanged(QTextEdit *))); connect(ed.transCommentText, SIGNAL(textChanged()), SLOT(emitTranslatorCommentChanged())); connect(ed.transCommentText, SIGNAL(textChanged()), SLOT(resetHoverSelection())); connect(ed.transCommentText, SIGNAL(cursorPositionChanged()), SLOT(resetHoverSelection())); @@ -277,7 +278,8 @@ void MessageEditor::addPluralForm(int model, const QString &label, bool writable m_editors[model].transTexts.count(), transEditor); transEditor->getEditor()->installEventFilter(this); - connect(transEditor, SIGNAL(selectionChanged()), SLOT(selectionChanged())); + connect(transEditor, SIGNAL(selectionChanged(QTextEdit *)), + SLOT(selectionChanged(QTextEdit *))); connect(transEditor, SIGNAL(textChanged()), SLOT(emitTranslationChanged())); connect(transEditor, SIGNAL(textChanged()), SLOT(resetHoverSelection())); connect(transEditor, SIGNAL(cursorPositionChanged()), SLOT(resetHoverSelection())); @@ -300,57 +302,40 @@ QStringList MessageEditor::translations(int model) const return translations; } -static bool clearFormSelection(FormWidget *fw, FormWidget *te) +static void clearSelection(QTextEdit *t) { - if (fw != te) { - QTextEdit *t = fw->getEditor(); - bool oldBlockState = t->blockSignals(true); - QTextCursor c = t->textCursor(); - c.clearSelection(); - t->setTextCursor(c); - t->blockSignals(oldBlockState); - return true; - } - return false; + bool oldBlockState = t->blockSignals(true); + QTextCursor c = t->textCursor(); + c.clearSelection(); + t->setTextCursor(c); + t->blockSignals(oldBlockState); } -// Clear the selection for all textedits except the sender -void MessageEditor::selectionChanged() +void MessageEditor::selectionChanged(QTextEdit *te) { - if (!resetSelection(qobject_cast<FormWidget *>(sender()))) + if (te != m_selectionHolder) { + if (m_selectionHolder) + clearSelection(m_selectionHolder); + m_selectionHolder = (te->textCursor().hasSelection() ? te : 0); updateCanCutCopy(); + } } -bool MessageEditor::resetHoverSelection(FormWidget *fw) +void MessageEditor::resetHoverSelection() { - if (m_sourceSelected) { - if (clearFormSelection(m_source, fw)) { - updateCanCutCopy(); - return true; - } - } else if (m_pluralSourceSelected) { - if (clearFormSelection(m_pluralSource, fw)) { - updateCanCutCopy(); - return true; - } - } - return false; + if (m_selectionHolder && + (m_selectionHolder == m_source->getEditor() + || m_selectionHolder == m_pluralSource->getEditor())) + resetSelection(); } -bool MessageEditor::resetSelection(FormWidget *fw) +void MessageEditor::resetSelection() { - if (resetHoverSelection(fw)) - return true; - if (m_currentSelected) { - MessageEditorData &ed = m_editors[m_currentModel]; - FormWidget *cfw = (m_currentNumerus < 0) ? ed.transCommentText - : ed.transTexts[m_currentNumerus]; - if (clearFormSelection(cfw, fw)) { - updateCanCutCopy(); - return true; - } + if (m_selectionHolder) { + clearSelection(m_selectionHolder); + m_selectionHolder = 0; + updateCanCutCopy(); } - return false; } void MessageEditor::activeModelAndNumerus(int *model, int *numerus) const @@ -703,18 +688,12 @@ void MessageEditor::updateUndoRedo() void MessageEditor::cut() { - QTextEdit *editor = activeEditor(); - if (editor->textCursor().hasSelection()) - editor->cut(); + m_selectionHolder->cut(); } void MessageEditor::copy() { - QTextEdit *te; - if ((te = m_source->getEditor())->textCursor().hasSelection() - || (te = m_pluralSource->getEditor())->textCursor().hasSelection() - || (te = activeEditor())->textCursor().hasSelection()) - te->copy(); + m_selectionHolder->copy(); } void MessageEditor::updateCanCutCopy() @@ -722,18 +701,9 @@ void MessageEditor::updateCanCutCopy() bool newCopyState = false; bool newCutState = false; - m_sourceSelected = m_source->getEditor()->textCursor().hasSelection(); - m_pluralSourceSelected = m_pluralSource->getEditor()->textCursor().hasSelection(); - m_currentSelected = false; - - if (m_sourceSelected || m_pluralSourceSelected) { + if (m_selectionHolder) { newCopyState = true; - } else if (QTextEdit *te = activeEditor()) { - if (te->textCursor().hasSelection()) { - m_currentSelected = true; - newCopyState = true; - newCutState = !te->isReadOnly(); - } + newCutState = !m_selectionHolder->isReadOnly(); } if (newCopyState != m_copyAvail) { diff --git a/tools/linguist/linguist/messageeditor.h b/tools/linguist/linguist/messageeditor.h index 0a47c0f..fa78540 100644 --- a/tools/linguist/linguist/messageeditor.h +++ b/tools/linguist/linguist/messageeditor.h @@ -110,8 +110,8 @@ public slots: void setTranslation(int latestModel, const QString &translation); private slots: - void selectionChanged(); - bool resetHoverSelection(FormWidget *fw = 0); + void selectionChanged(QTextEdit *); + void resetHoverSelection(); void emitTranslationChanged(); void emitTranslatorCommentChanged(); void updateCanPaste(); @@ -125,7 +125,7 @@ private: void setupEditorPage(); void setEditingEnabled(int model, bool enabled); bool focusNextUnfinished(int start); - bool resetSelection(FormWidget *fw = 0); + void resetSelection(); void activeModelAndNumerus(int *model, int *numerus) const; QTextEdit *activeTranslation() const; QTextEdit *activeOr1stTranslation() const; @@ -151,12 +151,10 @@ private: bool m_redoAvail; bool m_cutAvail; bool m_copyAvail; - bool m_sourceSelected; - bool m_pluralSourceSelected; - bool m_currentSelected; bool m_clipboardEmpty; + QTextEdit *m_selectionHolder; QBoxLayout *m_layout; FormWidget *m_source; FormWidget *m_pluralSource; diff --git a/tools/linguist/linguist/messageeditorwidgets.cpp b/tools/linguist/linguist/messageeditorwidgets.cpp index 7412571..4f3e6d5 100644 --- a/tools/linguist/linguist/messageeditorwidgets.cpp +++ b/tools/linguist/linguist/messageeditorwidgets.cpp @@ -179,10 +179,15 @@ FormWidget::FormWidget(const QString &label, bool isEditable, QWidget *parent) setLayout(layout); connect(m_editor->document(), SIGNAL(contentsChanged()), SIGNAL(textChanged())); - connect(m_editor, SIGNAL(selectionChanged()), SIGNAL(selectionChanged())); + connect(m_editor, SIGNAL(selectionChanged()), SLOT(slotSelectionChanged())); connect(m_editor, SIGNAL(cursorPositionChanged()), SIGNAL(cursorPositionChanged())); } +void FormWidget::slotSelectionChanged() +{ + emit selectionChanged(m_editor); +} + void FormWidget::setTranslation(const QString &text, bool userAction) { m_editor->setPlainText(text, userAction); diff --git a/tools/linguist/linguist/messageeditorwidgets.h b/tools/linguist/linguist/messageeditorwidgets.h index b1609e5..09566dc 100644 --- a/tools/linguist/linguist/messageeditorwidgets.h +++ b/tools/linguist/linguist/messageeditorwidgets.h @@ -116,9 +116,12 @@ public: signals: void textChanged(); - void selectionChanged(); + void selectionChanged(QTextEdit *); void cursorPositionChanged(); +private slots: + void slotSelectionChanged(); + private: QLabel *m_label; FormatTextEdit *m_editor; |