1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the linguist application of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
31
This is the right panel of the main window.
38
#include "messagemodel.h"
39
#include "phrasemodel.h"
43
#include <qapplication.h>
44
#include <qclipboard.h>
47
#include <qtextedit.h>
51
#include <qscrollbar.h>
52
#include <qheaderview.h>
53
#include <qshortcut.h>
55
#include <qdockwidget.h>
57
#include <qtreeview.h>
58
#include <qscrollarea.h>
59
#include <qtextdocumentfragment.h>
60
#include <qtextcursor.h>
62
#include <QAbstractTextDocumentLayout>
64
static const int MaxCandidates = 5;
66
const char MessageEditor::backTab[] = "\a\b\f\n\r\t";
67
const char * const MessageEditor::friendlyBackTab[] = {
68
QT_TRANSLATE_NOOP("MessageEditor", "bell"),
69
QT_TRANSLATE_NOOP("MessageEditor", "backspace"),
70
QT_TRANSLATE_NOOP("MessageEditor", "new page"),
71
QT_TRANSLATE_NOOP("MessageEditor", "new line"),
72
QT_TRANSLATE_NOOP("MessageEditor", "carriage return"),
73
QT_TRANSLATE_NOOP("MessageEditor", "tab")
76
void MessageEditor::visualizeBackTabs(const QString &text, QTextEdit *te)
79
QTextCursor tc(te->textCursor());
80
QTextCharFormat blueFormat = defFormat;
81
blueFormat.setForeground(QBrush(Qt::blue));
82
blueFormat.setFontItalic(true);
83
blueFormat.setProperty(QTextFormat::UserProperty, -1);
86
for (int i = 0; i < (int) text.length(); ++i)
88
int ch = text[i].unicode();
91
if (!plainText.isEmpty())
93
tc.insertText(plainText, defFormat);
96
const char *p = strchr(backTab, ch);
97
// store the character in the user format property
98
// in the first '(' in the phrase
99
blueFormat.setProperty(QTextFormat::UserProperty, ch);
100
tc.insertText(QString("("), blueFormat);
101
blueFormat.setProperty(QTextFormat::UserProperty, -1);
104
tc.insertText(QString::number(ch, 16) + ")", blueFormat);
108
tc.insertText(MessageEditor::tr(friendlyBackTab[p - backTab]) + ")",
110
if (backTab[p - backTab] == '\n')
114
// if a space is by itself, at the end, or beside other spaces
117
if (i == 0 || i == text.length() - 1 || text[i - 1].isSpace() ||
118
text[i + 1].isSpace())
120
blueFormat.setProperty(QTextFormat::UserProperty, ch);
121
tc.insertText(QString("("), blueFormat);
122
blueFormat.setProperty(QTextFormat::UserProperty, -1);
123
tc.insertText(MessageEditor::tr("sp)"), blueFormat);
132
plainText += QString(ch);
135
tc.insertText(plainText, defFormat);
138
SourceTextEdit::SourceTextEdit(QWidget *parent) : QTextEdit(parent)
141
actCopy = new QAction(tr("&Copy"), this);
142
actCopy->setShortcut(QKeySequence(tr("Ctrl+C")));
143
actSelect = new QAction(tr("Select &All"), this);
144
actSelect->setShortcut(QKeySequence(tr("Ctrl+A")));
145
connect(actCopy, SIGNAL(triggered()), this, SLOT(copySelection()));
146
connect(actSelect, SIGNAL(triggered()), this, SLOT(selectAll()));
149
void SourceTextEdit::copySelection()
151
QTextDocumentFragment tdf = textCursor().selection();
154
tc.insertFragment(tdf);
157
tc.movePosition(QTextCursor::Start);
160
tc.movePosition(QTextCursor::NextCharacter);
161
ch = tc.charFormat().intProperty(QTextFormat::UserProperty);
162
if (ch != 0) // if wrong format
165
tc.deletePreviousChar();
166
if (ch != -1) // insert backtab
167
tc.insertText(QString(ch));
171
QApplication::clipboard()->setText(td.toPlainText());
174
void SourceTextEdit::contextMenuEvent(QContextMenuEvent *e)
178
srcmenu = new QMenu(this);
179
srcmenu->addAction(actCopy);
180
srcmenu->addAction(actSelect);
183
actCopy->setEnabled(textCursor().hasSelection());
184
actSelect->setEnabled(!document()->isEmpty());
186
srcmenu->popup(e->globalPos());
190
ShadowWidget class impl.
192
Used to create a shadow like effect for a widget
194
ShadowWidget::ShadowWidget(QWidget *parent)
195
: QWidget(parent), sWidth(10), wMargin(3), childWgt(0)
200
ShadowWidget::ShadowWidget(QWidget *child, QWidget *parent)
201
: QWidget(parent), sWidth(10), wMargin(3), childWgt(0)
206
void ShadowWidget::setWidget(QWidget *child)
209
if (childWgt && childWgt->parent() != this) {
210
childWgt->setParent(this);
216
void ShadowWidget::resizeEvent(QResizeEvent *)
219
childWgt->move(wMargin, wMargin);
220
childWgt->resize(width() - sWidth - wMargin, height() - sWidth -
225
void ShadowWidget::paintEvent(QPaintEvent *e)
228
int w = width() - sWidth;
229
int h = height() - sWidth;
232
if (!((w > 0) && (h > 0)))
236
p.setPen(palette().color(QPalette::Shadow));
238
p.drawPoint(w + 5, 6);
239
p.drawLine(w + 3, 6, w + 5, 8);
240
p.drawLine(w + 1, 6, w + 5, 10);
242
for (i=7; i < h; i += 2)
243
p.drawLine( w, i, w + 5, i + 5);
244
for (i = w - i + h; i > 6; i -= 2)
245
p.drawLine( i, h, i + 5, h + 5);
246
for (; i > 0 ; i -= 2)
247
p.drawLine( 6, h + 6 - i, i + 5, h + 5);
251
QWidget::paintEvent(e);
255
EditorPage class impl.
257
A frame that contains the source text, translated text and any
258
source code comments and hints.
260
EditorPage::EditorPage(MessageEditor *parent, const char *name)
265
setFrameStyle(QFrame::Box | QFrame::Plain);
267
// Use white explicitly as the background color for the editor page.
268
QPalette p = palette();
269
p.setColor(QPalette::Active, QPalette::Base, QColor(Qt::white));
270
p.setColor(QPalette::Inactive, QPalette::Base, QColor(Qt::white));
271
p.setColor(QPalette::Disabled, QPalette::Base, QColor(Qt::white));
272
p.setColor(QPalette::Active, QPalette::Background,
273
p.color(QPalette::Active, QPalette::Base));
274
p.setColor(QPalette::Inactive, QPalette::Background,
275
p.color(QPalette::Inactive, QPalette::Base));
276
p.setColor(QPalette::Disabled, QPalette::Background,
277
p.color(QPalette::Disabled, QPalette::Base));
279
parent->setPalette(p);
281
srcTextLbl = new QLabel(tr("Source text"), this);
282
transLbl = new QLabel(tr("Translation"), this);
286
srcTextLbl->setFont(fnt);
287
transLbl->setFont(fnt);
289
srcText = new SourceTextEdit(this);
290
srcText->setFrameStyle(QFrame::NoFrame);
291
srcText->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding,
292
QSizePolicy::Minimum));
293
srcText->setAutoFormatting(QTextEdit::AutoNone);
294
srcText->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
295
srcText->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
296
p = srcText->palette();
297
p.setColor(QPalette::Disabled, QPalette::Base, p.color(QPalette::Active, QPalette::Base));
298
srcText->setPalette( p );
299
srcText->setReadOnly(true);
300
connect(srcText->document(), SIGNAL(contentsChanged()), SLOT(handleSourceChanges()));
302
cmtText = new QTextEdit(this);
303
cmtText->setObjectName("comment/context view");
304
cmtText->setFrameStyle( QFrame::NoFrame );
305
cmtText->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding,
306
QSizePolicy::Minimum ) );
307
cmtText->setAutoFormatting(QTextEdit::AutoNone);
308
cmtText->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
309
cmtText->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
310
p = cmtText->palette();
311
p.setColor(QPalette::Active, QPalette::Base, QColor(236,245,255));
312
p.setColor(QPalette::Inactive, QPalette::Base, QColor(236,245,255));
313
cmtText->setPalette(p);
314
cmtText->setReadOnly(true);
315
connect(cmtText->document(), SIGNAL(contentsChanged()), SLOT(handleCommentChanges()));
317
transText = new QTextEdit(this);
318
transText->setObjectName("translation editor");
319
transText->setFrameStyle(QFrame::NoFrame);
320
transText->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding,
321
QSizePolicy::MinimumExpanding));
322
transText->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
323
transText->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
324
transText->setAutoFormatting(QTextEdit::AutoNone);
325
transText->setLineWrapMode(QTextEdit::WidgetWidth);
326
p = transText->palette();
327
p.setColor(QPalette::Disabled, QPalette::Base, p.color(QPalette::Active, QPalette::Base));
328
transText->setPalette(p);
329
connect(transText->document(), SIGNAL(contentsChanged()),
330
SLOT(handleTranslationChanges()));
332
pageCurl = new PageCurl(this);
335
setFocusPolicy(Qt::StrongFocus);
336
parent->setFocusProxy(transText);
337
transLbl->setFocusProxy(transText);
338
srcTextLbl->setFocusProxy(transText);
339
srcText->setFocusProxy(transText);
340
cmtText->setFocusProxy(transText);
341
setFocusProxy(transText);
343
updateCommentField();
347
Don't show the comment field if there are no comments.
349
void EditorPage::updateCommentField()
351
if(cmtText->toPlainText().isEmpty())
360
Handle the widget layout manually
362
void EditorPage::layoutWidgets()
368
pageCurl->move(width() - pageCurl->width(), 0);
370
QFontMetrics fm(srcTextLbl->font());
371
srcTextLbl->move(margin, margin);
372
srcTextLbl->resize(fm.width(srcTextLbl->text()), srcTextLbl->height());
374
srcText->move(margin, srcTextLbl->y() + srcTextLbl->height() + space);
375
srcText->resize(w - margin*2, srcText->height());
377
cmtText->move(margin, srcText->y() + srcText->height() + space);
378
cmtText->resize(w - margin*2, cmtText->height());
380
if (cmtText->isHidden())
381
transLbl->move(margin, srcText->y() + srcText->height() + space);
383
transLbl->move(margin, cmtText->y() + cmtText->height() + space);
384
transLbl->resize( w - margin*2, transLbl->height() );
386
transText->move(margin, transLbl->y() + transLbl->height() + space);
387
transText->resize(w - margin*2, transText->height());
389
// Calculate the total height for the editor page - emit a signal
390
// if the actual page size is larger/smaller
391
int totHeight = margin + srcTextLbl->height() +
392
srcText->height() + space +
393
transLbl->height() + space +
394
transText->height() + space +
395
frameWidth()*lineWidth()*2 + space * 3;
397
if (!cmtText->isHidden())
398
totHeight += cmtText->height() + space;
400
if (height() != totHeight)
401
emit pageHeightUpdated(totHeight);
404
void EditorPage::resizeEvent(QResizeEvent *)
406
handleTranslationChanges();
407
handleSourceChanges();
408
handleCommentChanges();
412
void EditorPage::handleTranslationChanges()
414
calculateFieldHeight(transText);
417
void EditorPage::handleSourceChanges()
419
calculateFieldHeight(srcText);
422
void EditorPage::handleCommentChanges()
424
calculateFieldHeight(cmtText);
428
Check if the translation text field is big enough to show all text
429
that has been entered. If it isn't, resize it.
431
void EditorPage::calculateFieldHeight(QTextEdit *field)
433
int contentsHeight = qRound(field->document()->documentLayout()->documentSize().height());
435
if (contentsHeight != field->height()) {
436
int oldHeight = field->height();
437
if(contentsHeight < 30)
439
field->resize(field->width(), contentsHeight);
440
emit pageHeightUpdated(height() + (field->height() - oldHeight));
444
void EditorPage::fontChange(const QFont &)
446
//keep the labels bold...
450
QFontMetrics fm(fnt);
451
srcTextLbl->setFont(fnt);
452
srcTextLbl->resize(fm.width(srcTextLbl->text()), srcTextLbl->height());
453
transLbl->setFont(fnt);
454
transLbl->resize(fm.width(transLbl->text()), transLbl->height());
459
MessageEditor class impl.
461
Handle layout of dock windows and the editor page.
463
MessageEditor::MessageEditor(MetaTranslator *t, QMainWindow *parent)
464
: QScrollArea(parent), tor(t)
468
topDockWnd = new QDockWidget(parent);
469
topDockWnd->setAllowedAreas(Qt::AllDockWidgetAreas);
470
topDockWnd->setFeatures(QDockWidget::AllDockWidgetFeatures);
471
topDockWnd->setWindowTitle(tr("Source text"));
473
srcTextView = new QTreeView(topDockWnd);
474
srcMdl = new MessageModel(topDockWnd);
475
srcTextView->setModel(srcMdl);
476
srcTextView->setAlternatingRowColors(true);
477
srcTextView->setSelectionBehavior(QAbstractItemView::SelectRows);
478
srcTextView->setSelectionMode(QAbstractItemView::SingleSelection);
479
srcTextView->setRootIsDecorated(false);
480
srcTextView->setUniformRowHeights(true);
481
QPalette pal = srcTextView->palette();
482
pal.setColor(QPalette::AlternateBase, TREEVIEW_ODD_COLOR);
483
srcTextView->setPalette(pal);
485
QFontMetrics fm(font());
486
srcTextView->header()->setResizeMode(1, QHeaderView::Stretch);
487
srcTextView->header()->resizeSection(0, fm.width(MessageModel::tr("Done")) + 20);
488
srcTextView->header()->resizeSection(2, 300);
489
srcTextView->header()->setClickable(true);
491
topDockWnd->setWidget(srcTextView);
492
parent->addDockWidget(Qt::TopDockWidgetArea, topDockWnd);
494
bottomDockWnd = new QDockWidget(parent);
495
bottomDockWnd->setAllowedAreas(Qt::AllDockWidgetAreas);
496
bottomDockWnd->setFeatures(QDockWidget::AllDockWidgetFeatures);
497
bottomDockWnd->setWindowTitle(tr("Phrases"));
499
QWidget *w = new QWidget(bottomDockWnd);
500
w->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
501
QVBoxLayout *vl = new QVBoxLayout(w);
504
phraseLbl = new QLabel( tr("Phrases and guesses:"), w );
506
phraseTv = new QTreeView(w);
507
phraseTv->setObjectName("phrase list view");
508
phrMdl = new PhraseModel(w);
509
phraseTv->setModel(phrMdl);
510
phraseTv->setAlternatingRowColors(true);
511
phraseTv->setSelectionBehavior(QAbstractItemView::SelectRows);
512
phraseTv->setSelectionMode(QAbstractItemView::SingleSelection);
513
phraseTv->setRootIsDecorated(false);
514
pal = phraseTv->palette();
515
pal.setColor(QPalette::AlternateBase, TREEVIEW_ODD_COLOR);
516
phraseTv->setPalette(pal);
518
phraseTv->header()->setResizeMode(QHeaderView::Stretch);
519
phraseTv->header()->setClickable(true);
521
vl->addWidget(phraseLbl);
522
vl->addWidget(phraseTv);
524
for (int i = 0; i < 9; ++i) {
525
(void) new GuessShortcut(i, this, SLOT(guessActivated(int)));
528
bottomDockWnd->setWidget(w);
529
parent->addDockWidget(Qt::BottomDockWidgetArea, bottomDockWnd);
531
setObjectName("scroll area");
532
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
533
setFrameStyle(QFrame::NoFrame);
535
editorPage = new EditorPage(this, "editor page");
536
connect(editorPage, SIGNAL(pageHeightUpdated(int)),
537
SLOT(updatePageHeight(int)));
539
sw = new ShadowWidget(editorPage, this);
540
sw->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
541
sw->setMinimumSize(QSize(100, 150));
544
defFormat = editorPage->srcText->currentCharFormat();
545
editorPage->transText->installEventFilter(this);
548
connect(editorPage->pageCurl, SIGNAL(nextPage()),
549
SIGNAL(nextUnfinished()));
550
connect(editorPage->pageCurl, SIGNAL(prevPage()),
551
SIGNAL(prevUnfinished()));
553
connect(editorPage->transText->document(), SIGNAL(contentsChanged()),
554
this, SLOT(emitTranslationChanged()));
555
connect(editorPage->transText->document(), SIGNAL(contentsChanged()),
556
this, SLOT(updateButtons()));
557
connect(editorPage->transText->document(), SIGNAL(undoAvailable(bool)),
558
this, SIGNAL(undoAvailable(bool)));
559
connect(editorPage->transText->document(), SIGNAL(redoAvailable(bool)),
560
this, SIGNAL(redoAvailable(bool)));
561
connect(editorPage->transText, SIGNAL(copyAvailable(bool)),
562
this, SIGNAL(cutAvailable(bool)));
563
connect(editorPage->transText, SIGNAL(copyAvailable(bool)),
564
this, SIGNAL(copyAvailable(bool)));
565
connect(qApp->clipboard(), SIGNAL(dataChanged()),
566
this, SLOT(updateCanPaste()));
567
connect(phraseTv, SIGNAL(doubleClicked(QModelIndex)),
568
this, SLOT(insertPhraseInTranslation(QModelIndex)));
570
phraseTv->installEventFilter(this);
572
connect(srcTextView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
573
parent, SLOT(showNewCurrent(QModelIndex,QModelIndex)));
576
this->setWhatsThis(tr("This whole panel allows you to view and edit "
577
"the translation of some source text.") );
578
editorPage->srcText->setWhatsThis(tr("This area shows the source text.") );
579
editorPage->cmtText->setWhatsThis(tr("This area shows a comment that"
580
" may guide you, and the context in which the text"
582
editorPage->transText->setWhatsThis(tr("This is where you can enter or modify"
583
" the translation of some source text.") );
588
bool MessageEditor::eventFilter(QObject *o, QEvent *e)
590
// handle copying from the source
591
if ((e->type() == QEvent::KeyPress) ||
592
(e->type() == QEvent::ShortcutOverride))
594
QKeyEvent *ke = static_cast<QKeyEvent *>(e);
596
// handle return key in phrase list
598
&& e->type() == QEvent::KeyPress
599
&& ke->modifiers() == Qt::NoModifier
600
&& ke->key() == Qt::Key_Return
601
&& phraseTv->currentIndex().isValid())
603
insertPhraseInTranslationAndLeave(phraseTv->currentIndex());
607
if (ke->modifiers() & Qt::ControlModifier)
609
if ((ke->key() == Qt::Key_A) &&
610
editorPage->srcText->underMouse())
612
editorPage->srcText->selectAll();
615
if ((ke->key() == Qt::Key_C) &&
616
editorPage->srcText->textCursor().hasSelection() &&
617
editorPage->srcText->underMouse())
619
editorPage->srcText->copySelection();
625
return QScrollArea::eventFilter(o, e);
628
void MessageEditor::updatePageHeight(int height)
630
sw->resize(sw->width(), height + sw->margin() + sw->shadowWidth());
633
void MessageEditor::resizeEvent(QResizeEvent *e)
635
sw->resize(viewport()->width(), sw->height());
636
QScrollArea::resizeEvent(e);
639
QTreeView *MessageEditor::sourceTextView() const
644
QTreeView *MessageEditor::phraseView() const
649
void MessageEditor::showNothing()
651
editorPage->srcText->clear();
653
setEditionEnabled(false);
655
editorPage->cmtText->clear();
656
setTranslation(QString(), false);
657
editorPage->handleSourceChanges();
658
editorPage->handleCommentChanges();
659
editorPage->handleTranslationChanges();
660
editorPage->updateCommentField();
663
void MessageEditor::showMessage(const QString &text,
664
const QString &comment,
665
const QString &fullContext,
666
const QString &translation,
667
MetaTranslatorMessage::Type type,
668
const QList<Phrase> &phrases)
670
phraseTv->clearSelection();
672
bool obsolete = (type == MetaTranslatorMessage::Obsolete);
673
setEditionEnabled(!obsolete);
676
visualizeBackTabs(text, editorPage->srcText);
678
if (!fullContext.isEmpty() && !comment.isEmpty())
679
visualizeBackTabs(fullContext.simplified() + "\n" +
680
comment.simplified(), editorPage->cmtText);
681
else if (!fullContext.isEmpty() && comment.isEmpty())
682
visualizeBackTabs(fullContext.simplified(), editorPage->cmtText);
683
else if (fullContext.isEmpty() && !comment.isEmpty())
684
visualizeBackTabs(comment.simplified(), editorPage->cmtText);
686
editorPage->cmtText->clear();
688
setTranslation(translation, false);
689
phrMdl->removePhrases();
691
foreach(Phrase p, phrases) {
692
phrMdl->addPhrase(p);
695
if (doGuesses && !sourceText.isEmpty()) {
696
CandidateList cl = similarTextHeuristicCandidates(tor,
697
sourceText.toLatin1(), MaxCandidates);
699
QList<Candidate>::Iterator it = cl.begin();
700
while (it != cl.end()) {
703
def = tr("Guess (%1)").arg(QString(QKeySequence(Qt::CTRL | (Qt::Key_0 + (n + 1)))));
706
phrMdl->addPhrase(Phrase((*it).source, (*it).target, def, n));
712
editorPage->handleSourceChanges();
713
editorPage->handleCommentChanges();
714
editorPage->handleTranslationChanges();
715
editorPage->updateCommentField();
718
void MessageEditor::setTranslation(const QString &translation, bool emitt)
720
// Block signals so that a signal is not emitted when
721
// for example a new source text item is selected and *not*
722
// the actual translation.
724
editorPage->transText->document()->blockSignals(true);
726
if (translation.isNull())
727
editorPage->transText->clear();
729
editorPage->transText->setPlainText(translation);
733
editorPage->transText->document()->blockSignals(false);
735
//don't undo the change
736
emit undoAvailable(false);
737
emit redoAvailable(false);
740
emit cutAvailable(false);
741
emit copyAvailable(false);
744
void MessageEditor::setEditionEnabled(bool enabled)
746
editorPage->transLbl->setEnabled(enabled);
747
editorPage->transText->setReadOnly(!enabled);
749
phraseLbl->setEnabled(enabled);
750
phraseTv->setEnabled(enabled);
754
void MessageEditor::undo()
756
editorPage->transText->document()->undo();
759
void MessageEditor::redo()
761
editorPage->transText->document()->redo();
764
void MessageEditor::cut()
766
editorPage->transText->cut();
769
void MessageEditor::copy()
771
editorPage->transText->copy();
774
void MessageEditor::paste()
776
editorPage->transText->paste();
779
void MessageEditor::selectAll()
781
editorPage->transText->selectAll();
784
void MessageEditor::emitTranslationChanged()
786
emit translationChanged(editorPage->transText->toPlainText());
789
void MessageEditor::guessActivated(int key)
794
for (int i=0; i<phrMdl->phraseList().count(); ++i) {
795
mi = phrMdl->QAbstractTableModel::index(i, 0);
796
p = phrMdl->phrase(mi);
797
if (p.shortcut() == key) {
798
insertPhraseInTranslation(mi);
804
void MessageEditor::insertPhraseInTranslation(const QModelIndex &index)
806
if (!editorPage->transText->isReadOnly())
808
editorPage->transText->textCursor().insertText(phrMdl->phrase(index).target());
809
emit translationChanged(editorPage->transText->toPlainText());
813
void MessageEditor::insertPhraseInTranslationAndLeave(const QModelIndex &index)
815
if (!editorPage->transText->isReadOnly())
817
editorPage->transText->textCursor().insertText(phrMdl->phrase(index).target());
818
emit translationChanged(editorPage->transText->toPlainText());
819
editorPage->transText->setFocus();
823
void MessageEditor::updateButtons()
825
bool overwrite = (!editorPage->transText->isReadOnly() &&
826
(editorPage->transText->toPlainText().trimmed().isEmpty() ||
827
mayOverwriteTranslation));
828
mayOverwriteTranslation = false;
829
emit updateActions(overwrite);
832
void MessageEditor::beginFromSource()
834
mayOverwriteTranslation = true;
835
setTranslation(sourceText, true);
839
void MessageEditor::setEditorFocus()
841
if (!editorPage->hasFocus())
842
editorPage->setFocus();
845
void MessageEditor::updateCanPaste()
847
bool oldCanPaste = canPaste;
848
canPaste = (!editorPage->transText->isReadOnly() &&
849
!qApp->clipboard()->text().isNull());
850
if (canPaste != oldCanPaste)
851
emit pasteAvailable(canPaste);
854
void MessageEditor::toggleGuessing()
856
doGuesses = !doGuesses;
858
phrMdl->removePhrases();