Handle non-Latin characters when pasting plain text
This commit is contained in:
@@ -403,7 +403,7 @@ void CutCommand::undo()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PasteCommand::PasteCommand(TeletextDocument *teletextDocument, QUndoCommand *parent) : LevelOneCommand(teletextDocument, parent)
|
PasteCommand::PasteCommand(TeletextDocument *teletextDocument, int pageCharSet, QUndoCommand *parent) : LevelOneCommand(teletextDocument, parent)
|
||||||
{
|
{
|
||||||
const QClipboard *clipboard = QApplication::clipboard();
|
const QClipboard *clipboard = QApplication::clipboard();
|
||||||
const QMimeData *mimeData = clipboard->mimeData();
|
const QMimeData *mimeData = clipboard->mimeData();
|
||||||
@@ -441,9 +441,26 @@ PasteCommand::PasteCommand(TeletextDocument *teletextDocument, QUndoCommand *par
|
|||||||
|
|
||||||
for (int r=0; r<m_clipboardDataHeight; r++) {
|
for (int r=0; r<m_clipboardDataHeight; r++) {
|
||||||
m_pastingCharacters.append(QByteArray());
|
m_pastingCharacters.append(QByteArray());
|
||||||
for (int c=0; c<plainTextData.at(r).size(); c++)
|
for (int c=0; c<plainTextData.at(r).size(); c++) {
|
||||||
// TODO deal with Unicode properly
|
// Try to map the unicode character to the current Level 1 character set of this page
|
||||||
m_pastingCharacters[r].append(keymapping[12].value(plainTextData.at(r).at(c), *qPrintable(plainTextData.at(r).at(c))));
|
|
||||||
|
char convertedChar;
|
||||||
|
const QChar charToConvert = plainTextData.at(r).at(c);
|
||||||
|
|
||||||
|
if (keymapping[pageCharSet].contains(charToConvert))
|
||||||
|
// Remapped character or non-Latin character converted successfully
|
||||||
|
convertedChar = keymapping[pageCharSet].value(charToConvert);
|
||||||
|
else {
|
||||||
|
// Either a Latin character or non-Latin character that can't be converted
|
||||||
|
// See if it's a Latin character
|
||||||
|
convertedChar = charToConvert.toLatin1();
|
||||||
|
if (convertedChar == 0)
|
||||||
|
// Couldn't convert - make it a block character so it doesn't need to be inserted-between later on
|
||||||
|
convertedChar = 0x7f;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_pastingCharacters[r].append(convertedChar);
|
||||||
|
}
|
||||||
m_clipboardDataWidth = qMax(m_pastingCharacters.at(r).size(), m_clipboardDataWidth);
|
m_clipboardDataWidth = qMax(m_pastingCharacters.at(r).size(), m_clipboardDataWidth);
|
||||||
}
|
}
|
||||||
// Pad short lines with spaces to make a box
|
// Pad short lines with spaces to make a box
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ private:
|
|||||||
class PasteCommand : public LevelOneCommand
|
class PasteCommand : public LevelOneCommand
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PasteCommand(TeletextDocument *, QUndoCommand *parent = 0);
|
PasteCommand(TeletextDocument *, int, QUndoCommand *parent = 0);
|
||||||
|
|
||||||
void redo() override;
|
void redo() override;
|
||||||
void undo() override;
|
void undo() override;
|
||||||
|
|||||||
@@ -443,7 +443,7 @@ void TeletextWidget::copy()
|
|||||||
|
|
||||||
void TeletextWidget::paste()
|
void TeletextWidget::paste()
|
||||||
{
|
{
|
||||||
m_teletextDocument->undoStack()->push(new PasteCommand(m_teletextDocument));
|
m_teletextDocument->undoStack()->push(new PasteCommand(m_teletextDocument, m_pageRender.level1CharSet(m_teletextDocument->cursorRow(), m_teletextDocument->cursorColumn())));
|
||||||
}
|
}
|
||||||
|
|
||||||
QPair<int, int> TeletextWidget::mouseToRowAndColumn(const QPoint &mousePosition)
|
QPair<int, int> TeletextWidget::mouseToRowAndColumn(const QPoint &mousePosition)
|
||||||
|
|||||||
Reference in New Issue
Block a user