summaryrefslogtreecommitdiffstats
path: root/tools/linguist
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>2009-05-28 16:38:38 (GMT)
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>2009-06-15 18:17:24 (GMT)
commita6d9cf91c34092d5056d9da96de08aece15615b2 (patch)
treee9ef743327018e9cd43d406f156f6cc97806daac /tools/linguist
parent9ed7ec89e11a3badd59f8cfa130c2ee810164944 (diff)
downloadQt-a6d9cf91c34092d5056d9da96de08aece15615b2.zip
Qt-a6d9cf91c34092d5056d9da96de08aece15615b2.tar.gz
Qt-a6d9cf91c34092d5056d9da96de08aece15615b2.tar.bz2
make the focus tracking insensitive to loss of actual window focus
Diffstat (limited to 'tools/linguist')
-rw-r--r--tools/linguist/linguist/messageeditor.cpp64
-rw-r--r--tools/linguist/linguist/messageeditor.h7
-rw-r--r--tools/linguist/linguist/messageeditorwidgets.cpp7
-rw-r--r--tools/linguist/linguist/messageeditorwidgets.h3
4 files changed, 55 insertions, 26 deletions
diff --git a/tools/linguist/linguist/messageeditor.cpp b/tools/linguist/linguist/messageeditor.cpp
index 64264db..aacf482 100644
--- a/tools/linguist/linguist/messageeditor.cpp
+++ b/tools/linguist/linguist/messageeditor.cpp
@@ -91,7 +91,8 @@ MessageEditor::MessageEditor(MultiDataModel *dataModel, QMainWindow *parent)
m_redoAvail(false),
m_cutAvail(false),
m_copyAvail(false),
- m_selectionHolder(0)
+ m_selectionHolder(0),
+ m_focusWidget(0)
{
setObjectName(QLatin1String("scroll area"));
@@ -218,8 +219,9 @@ void MessageEditor::messageModelAppended()
ed.transCommentText->getEditor()->installEventFilter(this);
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(textChanged(QTextEdit *)),
+ SLOT(emitTranslatorCommentChanged(QTextEdit *)));
+ connect(ed.transCommentText, SIGNAL(textChanged(QTextEdit *)), SLOT(resetHoverSelection()));
connect(ed.transCommentText, SIGNAL(cursorPositionChanged()), SLOT(resetHoverSelection()));
QBoxLayout *box = new QVBoxLayout(ed.container);
box->setMargin(5);
@@ -280,8 +282,9 @@ void MessageEditor::addPluralForm(int model, const QString &label, bool writable
transEditor->getEditor()->installEventFilter(this);
connect(transEditor, SIGNAL(selectionChanged(QTextEdit *)),
SLOT(selectionChanged(QTextEdit *)));
- connect(transEditor, SIGNAL(textChanged()), SLOT(emitTranslationChanged()));
- connect(transEditor, SIGNAL(textChanged()), SLOT(resetHoverSelection()));
+ connect(transEditor, SIGNAL(textChanged(QTextEdit *)),
+ SLOT(emitTranslationChanged(QTextEdit *)));
+ connect(transEditor, SIGNAL(textChanged(QTextEdit *)), SLOT(resetHoverSelection()));
connect(transEditor, SIGNAL(cursorPositionChanged()), SLOT(resetHoverSelection()));
m_editors[model].transTexts << transEditor;
@@ -342,12 +345,12 @@ void MessageEditor::activeModelAndNumerus(int *model, int *numerus) const
{
for (int j = 0; j < m_editors.count(); ++j) {
for (int i = 0; i < m_editors[j].transTexts.count(); ++i)
- if (m_editors[j].transTexts[i]->getEditor()->hasFocus()) {
+ if (m_focusWidget == m_editors[j].transTexts[i]->getEditor()) {
*model = j;
*numerus = i;
return;
}
- if (m_editors[j].transCommentText->getEditor()->hasFocus()) {
+ if (m_focusWidget == m_editors[j].transCommentText->getEditor()) {
*model = j;
*numerus = -1;
return;
@@ -513,22 +516,39 @@ bool MessageEditor::eventFilter(QObject *o, QEvent *e)
return decFont(modelForWidget(o));
}
} else if (e->type() == QEvent::FocusIn) {
- int model, numerus;
- activeModelAndNumerus(&model, &numerus);
- if (model != m_currentModel || numerus != m_currentNumerus) {
- resetSelection();
- m_currentModel = model;
- m_currentNumerus = numerus;
- emit activeModelChanged(activeModel());
- updateBeginFromSource();
- updateUndoRedo();
- updateCanPaste();
- }
+ QWidget *widget = static_cast<QWidget *>(o);
+ if (widget != m_focusWidget)
+ trackFocus(widget);
}
return QScrollArea::eventFilter(o, e);
}
+void MessageEditor::grabFocus(QWidget *widget)
+{
+ if (widget != m_focusWidget) {
+ widget->setFocus();
+ trackFocus(widget);
+ }
+}
+
+void MessageEditor::trackFocus(QWidget *widget)
+{
+ m_focusWidget = widget;
+
+ int model, numerus;
+ activeModelAndNumerus(&model, &numerus);
+ if (model != m_currentModel || numerus != m_currentNumerus) {
+ resetSelection();
+ m_currentModel = model;
+ m_currentNumerus = numerus;
+ emit activeModelChanged(activeModel());
+ updateBeginFromSource();
+ updateUndoRedo();
+ updateCanPaste();
+ }
+}
+
void MessageEditor::showNothing()
{
m_source->clearTranslation();
@@ -747,17 +767,17 @@ void MessageEditor::selectAll()
te->selectAll();
}
-void MessageEditor::emitTranslationChanged()
+void MessageEditor::emitTranslationChanged(QTextEdit *widget)
{
- static_cast<FormWidget *>(sender())->getEditor()->setFocus(); // DND proofness
+ grabFocus(widget); // DND proofness
updateBeginFromSource();
updateUndoRedo();
emit translationChanged(translations(m_currentModel));
}
-void MessageEditor::emitTranslatorCommentChanged()
+void MessageEditor::emitTranslatorCommentChanged(QTextEdit *widget)
{
- static_cast<FormWidget *>(sender())->getEditor()->setFocus(); // DND proofness
+ grabFocus(widget); // DND proofness
updateUndoRedo();
emit translatorCommentChanged(m_editors[m_currentModel].transCommentText->getTranslation());
}
diff --git a/tools/linguist/linguist/messageeditor.h b/tools/linguist/linguist/messageeditor.h
index fa78540..9dd26f9 100644
--- a/tools/linguist/linguist/messageeditor.h
+++ b/tools/linguist/linguist/messageeditor.h
@@ -112,8 +112,8 @@ public slots:
private slots:
void selectionChanged(QTextEdit *);
void resetHoverSelection();
- void emitTranslationChanged();
- void emitTranslatorCommentChanged();
+ void emitTranslationChanged(QTextEdit *);
+ void emitTranslatorCommentChanged(QTextEdit *);
void updateCanPaste();
void clipboardChanged();
void messageModelAppended();
@@ -126,6 +126,8 @@ private:
void setEditingEnabled(int model, bool enabled);
bool focusNextUnfinished(int start);
void resetSelection();
+ void grabFocus(QWidget *widget);
+ void trackFocus(QWidget *widget);
void activeModelAndNumerus(int *model, int *numerus) const;
QTextEdit *activeTranslation() const;
QTextEdit *activeOr1stTranslation() const;
@@ -155,6 +157,7 @@ private:
bool m_clipboardEmpty;
QTextEdit *m_selectionHolder;
+ QWidget *m_focusWidget;
QBoxLayout *m_layout;
FormWidget *m_source;
FormWidget *m_pluralSource;
diff --git a/tools/linguist/linguist/messageeditorwidgets.cpp b/tools/linguist/linguist/messageeditorwidgets.cpp
index 4f3e6d5..5270c0d 100644
--- a/tools/linguist/linguist/messageeditorwidgets.cpp
+++ b/tools/linguist/linguist/messageeditorwidgets.cpp
@@ -178,7 +178,7 @@ FormWidget::FormWidget(const QString &label, bool isEditable, QWidget *parent)
setLayout(layout);
- connect(m_editor->document(), SIGNAL(contentsChanged()), SIGNAL(textChanged()));
+ connect(m_editor->document(), SIGNAL(contentsChanged()), SLOT(slotTextChanged()));
connect(m_editor, SIGNAL(selectionChanged()), SLOT(slotSelectionChanged()));
connect(m_editor, SIGNAL(cursorPositionChanged()), SIGNAL(cursorPositionChanged()));
}
@@ -188,6 +188,11 @@ void FormWidget::slotSelectionChanged()
emit selectionChanged(m_editor);
}
+void FormWidget::slotTextChanged()
+{
+ emit textChanged(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 09566dc..fa65f3b 100644
--- a/tools/linguist/linguist/messageeditorwidgets.h
+++ b/tools/linguist/linguist/messageeditorwidgets.h
@@ -115,12 +115,13 @@ public:
FormatTextEdit *getEditor() { return m_editor; }
signals:
- void textChanged();
+ void textChanged(QTextEdit *);
void selectionChanged(QTextEdit *);
void cursorPositionChanged();
private slots:
void slotSelectionChanged();
+ void slotTextChanged();
private:
QLabel *m_label;