diff options
Diffstat (limited to 'tools/linguist')
-rw-r--r-- | tools/linguist/linguist/globals.cpp | 55 | ||||
-rw-r--r-- | tools/linguist/linguist/globals.h | 50 | ||||
-rw-r--r-- | tools/linguist/linguist/linguist.pro | 2 | ||||
-rw-r--r-- | tools/linguist/linguist/main.cpp | 5 | ||||
-rw-r--r-- | tools/linguist/linguist/mainwindow.cpp | 46 | ||||
-rw-r--r-- | tools/linguist/linguist/mainwindow.h | 2 | ||||
-rw-r--r-- | tools/linguist/linguist/messageeditor.cpp | 216 | ||||
-rw-r--r-- | tools/linguist/linguist/messageeditor.h | 27 | ||||
-rw-r--r-- | tools/linguist/linguist/messageeditorwidgets.cpp | 19 | ||||
-rw-r--r-- | tools/linguist/linguist/messageeditorwidgets.h | 8 | ||||
-rw-r--r-- | tools/linguist/linguist/phraseview.cpp | 3 | ||||
-rw-r--r-- | tools/linguist/linguist/recentfiles.cpp | 5 | ||||
-rw-r--r-- | tools/linguist/lupdate/cpp.cpp | 4 | ||||
-rw-r--r-- | tools/linguist/shared/qph.cpp | 22 |
14 files changed, 273 insertions, 191 deletions
diff --git a/tools/linguist/linguist/globals.cpp b/tools/linguist/linguist/globals.cpp new file mode 100644 index 0000000..697b28b --- /dev/null +++ b/tools/linguist/linguist/globals.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the Qt Linguist of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "globals.h" + +const QString &settingsPrefix() +{ + static QString prefix = QString(QLatin1String("%1.%2/")) + .arg((QT_VERSION >> 16) & 0xff) + .arg((QT_VERSION >> 8) & 0xff); + return prefix; +} + +QString settingPath(const char *path) +{ + return settingsPrefix() + QLatin1String(path); +} diff --git a/tools/linguist/linguist/globals.h b/tools/linguist/linguist/globals.h new file mode 100644 index 0000000..6b7293f --- /dev/null +++ b/tools/linguist/linguist/globals.h @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the Qt Linguist of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef GLOBALS_H +#define GLOBALS_H + +#include <QString> + +const QString &settingsPrefix(); +QString settingPath(const char *path); + +#endif // GLOBALS_H diff --git a/tools/linguist/linguist/linguist.pro b/tools/linguist/linguist/linguist.pro index 968293a..234b0b1 100644 --- a/tools/linguist/linguist/linguist.pro +++ b/tools/linguist/linguist/linguist.pro @@ -26,6 +26,7 @@ SOURCES += \ errorsview.cpp \ finddialog.cpp \ formpreviewview.cpp \ + globals.cpp \ main.cpp \ mainwindow.cpp \ messageeditor.cpp \ @@ -49,6 +50,7 @@ HEADERS += \ errorsview.h \ finddialog.h \ formpreviewview.h \ + globals.h \ mainwindow.h \ messageeditor.h \ messageeditorwidgets.h \ diff --git a/tools/linguist/linguist/main.cpp b/tools/linguist/linguist/main.cpp index a6a0d27..98cd876 100644 --- a/tools/linguist/linguist/main.cpp +++ b/tools/linguist/linguist/main.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include "mainwindow.h" +#include "globals.h" #include <QtCore/QFile> #include <QtCore/QLibraryInfo> @@ -92,13 +93,11 @@ int main(int argc, char **argv) app.setOrganizationName(QLatin1String("Trolltech")); app.setApplicationName(QLatin1String("Linguist")); - QString keybase(QString::number( (QT_VERSION >> 16) & 0xff ) + - QLatin1Char('.') + QString::number( (QT_VERSION >> 8) & 0xff ) + QLatin1Char('/') ); QSettings config; QWidget tmp; - tmp.restoreGeometry(config.value(keybase + QLatin1String("Geometry/WindowGeometry")).toByteArray()); + tmp.restoreGeometry(config.value(settingPath("Geometry/WindowGeometry")).toByteArray()); QSplashScreen *splash = 0; int screenId = QApplication::desktop()->screenNumber(tmp.geometry().center()); diff --git a/tools/linguist/linguist/mainwindow.cpp b/tools/linguist/linguist/mainwindow.cpp index f91175d..783587c 100644 --- a/tools/linguist/linguist/mainwindow.cpp +++ b/tools/linguist/linguist/mainwindow.cpp @@ -50,6 +50,7 @@ #include "errorsview.h" #include "finddialog.h" #include "formpreviewview.h" +#include "globals.h" #include "messageeditor.h" #include "messagemodel.h" #include "phrasebookbox.h" @@ -96,14 +97,6 @@ QT_BEGIN_NAMESPACE static const int MessageMS = 2500; -const QString &settingsPrefix() -{ - static QString prefix = QString(QLatin1String("%1.%2/")) - .arg((QT_VERSION >> 16) & 0xff) - .arg((QT_VERSION >> 8) & 0xff); - return prefix; -} - enum Ending { End_None, End_FullStop, @@ -121,11 +114,10 @@ static bool hasFormPreview(const QString &fileName) static Ending ending(QString str, QLocale::Language lang) { str = str.simplified(); - int ch = 0; - if (!str.isEmpty()) - ch = str.right(1)[0].unicode(); + if (str.isEmpty()) + return End_None; - switch (ch) { + switch (str.at(str.length() - 1).unicode()) { case 0x002e: // full stop if (str.endsWith(QLatin1String("..."))) return End_Ellipsis; @@ -2494,25 +2486,24 @@ void MainWindow::updateDanger(const MultiDataIndex &index, bool verbose) void MainWindow::readConfig() { - QString keybase = settingsPrefix(); QSettings config; QRect r(pos(), size()); - restoreGeometry(config.value(keybase + QLatin1String("Geometry/WindowGeometry")).toByteArray()); - restoreState(config.value(keybase + QLatin1String("MainWindowState")).toByteArray()); + restoreGeometry(config.value(settingPath("Geometry/WindowGeometry")).toByteArray()); + restoreState(config.value(settingPath("MainWindowState")).toByteArray()); m_ui.actionAccelerators->setChecked( - config.value(keybase + QLatin1String("Validators/Accelerator"), true).toBool()); + config.value(settingPath("Validators/Accelerator"), true).toBool()); m_ui.actionEndingPunctuation->setChecked( - config.value(keybase + QLatin1String("Validators/EndingPunctuation"), true).toBool()); + config.value(settingPath("Validators/EndingPunctuation"), true).toBool()); m_ui.actionPhraseMatches->setChecked( - config.value(keybase + QLatin1String("Validators/PhraseMatch"), true).toBool()); + config.value(settingPath("Validators/PhraseMatch"), true).toBool()); m_ui.actionPlaceMarkerMatches->setChecked( - config.value(keybase + QLatin1String("Validators/PlaceMarkers"), true).toBool()); + config.value(settingPath("Validators/PlaceMarkers"), true).toBool()); recentFiles().readConfig(); - int size = config.beginReadArray(keybase + QLatin1String("OpenedPhraseBooks")); + int size = config.beginReadArray(settingPath("OpenedPhraseBooks")); for (int i = 0; i < size; ++i) { config.setArrayIndex(i); openPhraseBook(config.value(QLatin1String("FileName")).toString()); @@ -2522,23 +2513,22 @@ void MainWindow::readConfig() void MainWindow::writeConfig() { - QString keybase = settingsPrefix(); QSettings config; - config.setValue(keybase + QLatin1String("Geometry/WindowGeometry"), + config.setValue(settingPath("Geometry/WindowGeometry"), saveGeometry()); - config.setValue(keybase + QLatin1String("Validators/Accelerator"), + config.setValue(settingPath("Validators/Accelerator"), m_ui.actionAccelerators->isChecked()); - config.setValue(keybase + QLatin1String("Validators/EndingPunctuation"), + config.setValue(settingPath("Validators/EndingPunctuation"), m_ui.actionEndingPunctuation->isChecked()); - config.setValue(keybase + QLatin1String("Validators/PhraseMatch"), + config.setValue(settingPath("Validators/PhraseMatch"), m_ui.actionPhraseMatches->isChecked()); - config.setValue(keybase + QLatin1String("Validators/PlaceMarkers"), + config.setValue(settingPath("Validators/PlaceMarkers"), m_ui.actionPlaceMarkerMatches->isChecked()); - config.setValue(keybase + QLatin1String("MainWindowState"), + config.setValue(settingPath("MainWindowState"), saveState()); recentFiles().writeConfig(); - config.beginWriteArray(keybase + QLatin1String("OpenedPhraseBooks"), + config.beginWriteArray(settingPath("OpenedPhraseBooks"), m_phraseBooks.size()); for (int i = 0; i < m_phraseBooks.size(); ++i) { config.setArrayIndex(i); diff --git a/tools/linguist/linguist/mainwindow.h b/tools/linguist/linguist/mainwindow.h index 9f6b4d9..6eed8ac 100644 --- a/tools/linguist/linguist/mainwindow.h +++ b/tools/linguist/linguist/mainwindow.h @@ -79,8 +79,6 @@ class Statistics; class TranslateDialog; class TranslationSettingsDialog; -const QString &settingsPrefix(); - class MainWindow : public QMainWindow { Q_OBJECT diff --git a/tools/linguist/linguist/messageeditor.cpp b/tools/linguist/linguist/messageeditor.cpp index 6351577..aacf482 100644 --- a/tools/linguist/linguist/messageeditor.cpp +++ b/tools/linguist/linguist/messageeditor.cpp @@ -91,9 +91,8 @@ 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), + m_focusWidget(0) { setObjectName(QLatin1String("scroll area")); @@ -144,12 +143,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,9 +217,11 @@ 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(textChanged()), SLOT(emitTranslatorCommentChanged())); - connect(ed.transCommentText, SIGNAL(textChanged()), SLOT(resetHoverSelection())); + connect(ed.transCommentText, SIGNAL(selectionChanged(QTextEdit *)), + SLOT(selectionChanged(QTextEdit *))); + 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); @@ -250,7 +253,7 @@ void MessageEditor::messageModelDeleted(int model) if (m_currentModel >= 0) { if (m_currentNumerus >= m_editors[m_currentModel].transTexts.size()) m_currentNumerus = m_editors[m_currentModel].transTexts.size() - 1; - activeEditor()->getEditor()->setFocus(); + activeEditor()->setFocus(); } else { m_currentNumerus = -1; } @@ -277,9 +280,11 @@ 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(textChanged()), SLOT(emitTranslationChanged())); - connect(transEditor, SIGNAL(textChanged()), SLOT(resetHoverSelection())); + connect(transEditor, SIGNAL(selectionChanged(QTextEdit *)), + SLOT(selectionChanged(QTextEdit *))); + 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; @@ -300,69 +305,52 @@ 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 { 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; @@ -372,43 +360,43 @@ void MessageEditor::activeModelAndNumerus(int *model, int *numerus) const *numerus = -1; } -FormWidget *MessageEditor::activeTranslation() const +QTextEdit *MessageEditor::activeTranslation() const { if (m_currentNumerus < 0) return 0; - return m_editors[m_currentModel].transTexts[m_currentNumerus]; + return m_editors[m_currentModel].transTexts[m_currentNumerus]->getEditor(); } -FormWidget *MessageEditor::activeOr1stTranslation() const +QTextEdit *MessageEditor::activeOr1stTranslation() const { if (m_currentNumerus < 0) { for (int i = 0; i < m_editors.size(); ++i) if (m_editors[i].container->isVisible() && !m_editors[i].transTexts[0]->getEditor()->isReadOnly()) - return m_editors[i].transTexts[0]; + return m_editors[i].transTexts[0]->getEditor(); return 0; } - return m_editors[m_currentModel].transTexts[m_currentNumerus]; + return m_editors[m_currentModel].transTexts[m_currentNumerus]->getEditor(); } -FormWidget *MessageEditor::activeTransComment() const +QTextEdit *MessageEditor::activeTransComment() const { if (m_currentModel < 0 || m_currentNumerus >= 0) return 0; - return m_editors[m_currentModel].transCommentText; + return m_editors[m_currentModel].transCommentText->getEditor(); } -FormWidget *MessageEditor::activeEditor() const +QTextEdit *MessageEditor::activeEditor() const { - if (FormWidget *fw = activeTransComment()) - return fw; + if (QTextEdit *te = activeTransComment()) + return te; return activeTranslation(); } -FormWidget *MessageEditor::activeOr1stEditor() const +QTextEdit *MessageEditor::activeOr1stEditor() const { - if (FormWidget *fw = activeTransComment()) - return fw; + if (QTextEdit *te = activeTransComment()) + return te; return activeOr1stTranslation(); } @@ -528,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(); @@ -672,20 +677,20 @@ void MessageEditor::setEditingEnabled(int model, bool enabled) void MessageEditor::undo() { - activeEditor()->getEditor()->document()->undo(); + activeEditor()->document()->undo(); } void MessageEditor::redo() { - activeEditor()->getEditor()->document()->redo(); + activeEditor()->document()->redo(); } void MessageEditor::updateUndoRedo() { bool newUndoAvail = false; bool newRedoAvail = false; - if (FormWidget *fw = activeEditor()) { - QTextDocument *doc = fw->getEditor()->document(); + if (QTextEdit *te = activeEditor()) { + QTextDocument *doc = te->document(); newUndoAvail = doc->isUndoAvailable(); newRedoAvail = doc->isRedoAvailable(); } @@ -703,18 +708,12 @@ void MessageEditor::updateUndoRedo() void MessageEditor::cut() { - QTextEdit *editor = activeEditor()->getEditor(); - 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()->getEditor())->textCursor().hasSelection()) - te->copy(); + m_selectionHolder->copy(); } void MessageEditor::updateCanCutCopy() @@ -722,19 +721,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 (FormWidget *fw = activeEditor()) { - QTextEdit *te = fw->getEditor(); - if (te->textCursor().hasSelection()) { - m_currentSelected = true; - newCopyState = true; - newCutState = !te->isReadOnly(); - } + newCutState = !m_selectionHolder->isReadOnly(); } if (newCopyState != m_copyAvail) { @@ -750,14 +739,14 @@ void MessageEditor::updateCanCutCopy() void MessageEditor::paste() { - activeEditor()->getEditor()->paste(); + activeEditor()->paste(); } void MessageEditor::updateCanPaste() { - FormWidget *fw; + QTextEdit *te; emit pasteAvailable(!m_clipboardEmpty - && (fw = activeEditor()) && !fw->getEditor()->isReadOnly()); + && (te = activeEditor()) && !te->isReadOnly()); } void MessageEditor::clipboardChanged() @@ -772,24 +761,23 @@ void MessageEditor::selectAll() // make sure we don't select the selection of a translator textedit, // if we really want the source text editor to be selected. QTextEdit *te; - FormWidget *fw; if ((te = m_source->getEditor())->underMouse() || (te = m_pluralSource->getEditor())->underMouse() - || ((fw = activeEditor()) && (te = fw->getEditor())->hasFocus())) + || ((te = activeEditor()) && te->hasFocus())) 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()); } @@ -797,11 +785,9 @@ void MessageEditor::emitTranslatorCommentChanged() void MessageEditor::updateBeginFromSource() { bool overwrite = false; - if (FormWidget *transForm = activeTranslation()) { - QTextEdit *activeEditor = transForm->getEditor(); + if (QTextEdit *activeEditor = activeTranslation()) overwrite = !activeEditor->isReadOnly() && activeEditor->toPlainText().trimmed().isEmpty(); - } emit beginFromSourceAvailable(overwrite); } @@ -816,8 +802,8 @@ void MessageEditor::beginFromSource() void MessageEditor::setEditorFocus() { if (!widget()->hasFocus()) - if (FormWidget *transForm = activeOr1stEditor()) - transForm->getEditor()->setFocus(); + if (QTextEdit *activeEditor = activeOr1stEditor()) + activeEditor->setFocus(); } void MessageEditor::setEditorFocus(int model) diff --git a/tools/linguist/linguist/messageeditor.h b/tools/linguist/linguist/messageeditor.h index de563ec..9dd26f9 100644 --- a/tools/linguist/linguist/messageeditor.h +++ b/tools/linguist/linguist/messageeditor.h @@ -110,10 +110,10 @@ public slots: void setTranslation(int latestModel, const QString &translation); private slots: - void selectionChanged(); - bool resetHoverSelection(FormWidget *fw = 0); - void emitTranslationChanged(); - void emitTranslatorCommentChanged(); + void selectionChanged(QTextEdit *); + void resetHoverSelection(); + void emitTranslationChanged(QTextEdit *); + void emitTranslatorCommentChanged(QTextEdit *); void updateCanPaste(); void clipboardChanged(); void messageModelAppended(); @@ -125,13 +125,15 @@ private: void setupEditorPage(); void setEditingEnabled(int model, bool enabled); bool focusNextUnfinished(int start); - bool resetSelection(FormWidget *fw = 0); + void resetSelection(); + void grabFocus(QWidget *widget); + void trackFocus(QWidget *widget); void activeModelAndNumerus(int *model, int *numerus) const; - FormWidget *activeTranslation() const; - FormWidget *activeOr1stTranslation() const; - FormWidget *activeTransComment() const; - FormWidget *activeEditor() const; - FormWidget *activeOr1stEditor() const; + QTextEdit *activeTranslation() const; + QTextEdit *activeOr1stTranslation() const; + QTextEdit *activeTransComment() const; + QTextEdit *activeEditor() const; + QTextEdit *activeOr1stEditor() const; MessageEditorData *modelForWidget(const QObject *o); int activeTranslationNumerus() const; QStringList translations(int model) const; @@ -151,12 +153,11 @@ 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; + 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 7412571..d23d42e 100644 --- a/tools/linguist/linguist/messageeditorwidgets.cpp +++ b/tools/linguist/linguist/messageeditorwidgets.cpp @@ -145,16 +145,15 @@ void FormatTextEdit::setEditable(bool editable) void FormatTextEdit::setPlainText(const QString &text, bool userAction) { - bool oldBlockState = false; if (!userAction) { // Prevent contentsChanged signal - oldBlockState = document()->blockSignals(true); + bool oldBlockState = blockSignals(true); document()->setUndoRedoEnabled(false); ExpandingTextEdit::setPlainText(text); // highlighter is out of sync because of blocked signals m_highlighter->rehighlight(); document()->setUndoRedoEnabled(true); - document()->blockSignals(oldBlockState); + blockSignals(oldBlockState); } else { ExpandingTextEdit::setPlainText(text); } @@ -178,11 +177,21 @@ 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(textChanged()), SLOT(slotTextChanged())); + connect(m_editor, SIGNAL(selectionChanged()), SLOT(slotSelectionChanged())); connect(m_editor, SIGNAL(cursorPositionChanged()), SIGNAL(cursorPositionChanged())); } +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 b1609e5..fa65f3b 100644 --- a/tools/linguist/linguist/messageeditorwidgets.h +++ b/tools/linguist/linguist/messageeditorwidgets.h @@ -115,10 +115,14 @@ public: FormatTextEdit *getEditor() { return m_editor; } signals: - void textChanged(); - void selectionChanged(); + void textChanged(QTextEdit *); + void selectionChanged(QTextEdit *); void cursorPositionChanged(); +private slots: + void slotSelectionChanged(); + void slotTextChanged(); + private: QLabel *m_label; FormatTextEdit *m_editor; diff --git a/tools/linguist/linguist/phraseview.cpp b/tools/linguist/linguist/phraseview.cpp index 72c27dc..e5c3508 100644 --- a/tools/linguist/linguist/phraseview.cpp +++ b/tools/linguist/linguist/phraseview.cpp @@ -39,6 +39,7 @@ ** ****************************************************************************/ +#include "globals.h" #include "mainwindow.h" #include "messagemodel.h" #include "phrase.h" @@ -61,7 +62,7 @@ static const int MaxCandidates = 5; static QString phraseViewHeaderKey() { - return settingsPrefix() + QLatin1String("PhraseViewHeader"); + return settingPath("PhraseViewHeader"); } PhraseView::PhraseView(MultiDataModel *model, QList<QHash<QString, QList<Phrase *> > > *phraseDict, QWidget *parent) diff --git a/tools/linguist/linguist/recentfiles.cpp b/tools/linguist/linguist/recentfiles.cpp index 6fc72f7..568f5c2 100644 --- a/tools/linguist/linguist/recentfiles.cpp +++ b/tools/linguist/linguist/recentfiles.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include "recentfiles.h" +#include "globals.h" #include <QtCore/QDebug> #include <QtCore/QFileInfo> @@ -49,11 +50,9 @@ QT_BEGIN_NAMESPACE -const QString &settingsPrefix(); - static QString configKey() { - return settingsPrefix() + QLatin1String("RecentlyOpenedFiles"); + return settingPath("RecentlyOpenedFiles"); } diff --git a/tools/linguist/lupdate/cpp.cpp b/tools/linguist/lupdate/cpp.cpp index b9e8406..7f52c53 100644 --- a/tools/linguist/lupdate/cpp.cpp +++ b/tools/linguist/lupdate/cpp.cpp @@ -1153,7 +1153,9 @@ bool CppParser::matchString(QString *s) s->clear(); while (yyTok == Tok_String) { *s += yyString; - yyTok = getToken(); + do { + yyTok = getToken(); + } while (yyTok == Tok_Comment); } return matches; } diff --git a/tools/linguist/shared/qph.cpp b/tools/linguist/shared/qph.cpp index 799bf7d..77e74ef 100644 --- a/tools/linguist/shared/qph.cpp +++ b/tools/linguist/shared/qph.cpp @@ -54,33 +54,19 @@ QT_BEGIN_NAMESPACE class QPHReader : public QXmlStreamReader { public: - QPHReader(QIODevice &dev, ConversionData &cd) - : QXmlStreamReader(&dev), m_cd(cd) + QPHReader(QIODevice &dev) + : QXmlStreamReader(&dev) {} // the "real thing" bool read(Translator &translator); private: - bool elementStarts(const QString &str) const - { - return isStartElement() && name() == str; - } - bool isWhiteSpace() const { return isCharacters() && text().toString().trimmed().isEmpty(); } - // needed to expand <byte ... /> - QString readContents(); - // needed to join <lengthvariant>s - QString readTransContents(); - - void handleError(); - - ConversionData &m_cd; - enum DataField { NoField, SourceField, TargetField, DefinitionField }; DataField m_currentField; QString m_currentSource; @@ -126,10 +112,10 @@ bool QPHReader::read(Translator &translator) return true; } -static bool loadQPH(Translator &translator, QIODevice &dev, ConversionData &cd) +static bool loadQPH(Translator &translator, QIODevice &dev, ConversionData &) { translator.setLocationsType(Translator::NoLocations); - QPHReader reader(dev, cd); + QPHReader reader(dev); return reader.read(translator); } |