Handle plain text in clipboard
This does not word-wrap single lines of text at all, it assumes the plain text is in a neat block with newlines at the end of each line. We can't yet handle non-ASCII Unicode characters as that will need further work on the keymapping tables.
This commit is contained in:
@@ -26,6 +26,7 @@
|
|||||||
#include "levelonecommands.h"
|
#include "levelonecommands.h"
|
||||||
|
|
||||||
#include "document.h"
|
#include "document.h"
|
||||||
|
#include "keymap.h"
|
||||||
|
|
||||||
LevelOneCommand::LevelOneCommand(TeletextDocument *teletextDocument, QUndoCommand *parent) : QUndoCommand(parent)
|
LevelOneCommand::LevelOneCommand(TeletextDocument *teletextDocument, QUndoCommand *parent) : QUndoCommand(parent)
|
||||||
{
|
{
|
||||||
@@ -417,6 +418,7 @@ PasteCommand::PasteCommand(TeletextDocument *teletextDocument, QUndoCommand *par
|
|||||||
m_clipboardDataHeight = m_clipboardDataWidth = 0;
|
m_clipboardDataHeight = m_clipboardDataWidth = 0;
|
||||||
|
|
||||||
// Try to get something from the clipboard
|
// Try to get something from the clipboard
|
||||||
|
// FIXME is this a correct "custom" mime type? Or should we use vnd?
|
||||||
nativeData = mimeData->data("application/x-teletext");
|
nativeData = mimeData->data("application/x-teletext");
|
||||||
if (nativeData.size() > 2) {
|
if (nativeData.size() > 2) {
|
||||||
// Native clipboard data: we put it there ourselves
|
// Native clipboard data: we put it there ourselves
|
||||||
@@ -430,9 +432,26 @@ PasteCommand::PasteCommand(TeletextDocument *teletextDocument, QUndoCommand *par
|
|||||||
else
|
else
|
||||||
// Invalidate
|
// Invalidate
|
||||||
m_clipboardDataHeight = m_clipboardDataWidth = 0;
|
m_clipboardDataHeight = m_clipboardDataWidth = 0;
|
||||||
|
} else if (mimeData->hasText()) {
|
||||||
|
// Plain text
|
||||||
|
QStringList plainTextData = mimeData->text().split(QRegExp("\n|\r\n|\r"));
|
||||||
|
|
||||||
|
m_clipboardDataHeight = plainTextData.size();
|
||||||
|
m_clipboardDataWidth = 0;
|
||||||
|
|
||||||
|
for (int r=0; r<m_clipboardDataHeight; r++) {
|
||||||
|
m_pastingCharacters.append(QByteArray());
|
||||||
|
for (int c=0; c<plainTextData.at(r).size(); c++)
|
||||||
|
// TODO deal with Unicode properly
|
||||||
|
m_pastingCharacters[r].append(keymapping[12].value(plainTextData.at(r).at(c), *qPrintable(plainTextData.at(r).at(c))));
|
||||||
|
m_clipboardDataWidth = qMax(m_pastingCharacters.at(r).size(), m_clipboardDataWidth);
|
||||||
|
}
|
||||||
|
// Pad short lines with spaces to make a box
|
||||||
|
for (int r=0; r<m_clipboardDataHeight; r++)
|
||||||
|
m_pastingCharacters[r] = m_pastingCharacters.at(r).leftJustified(m_clipboardDataWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_clipboardDataWidth == 0)
|
if (m_clipboardDataWidth == 0 || m_clipboardDataHeight == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (m_selectionActive) {
|
if (m_selectionActive) {
|
||||||
@@ -468,7 +487,7 @@ PasteCommand::PasteCommand(TeletextDocument *teletextDocument, QUndoCommand *par
|
|||||||
|
|
||||||
void PasteCommand::redo()
|
void PasteCommand::redo()
|
||||||
{
|
{
|
||||||
if (m_clipboardDataWidth == 0)
|
if (m_clipboardDataWidth == 0 || m_clipboardDataHeight == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
|
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
|
||||||
@@ -508,7 +527,7 @@ void PasteCommand::redo()
|
|||||||
|
|
||||||
void PasteCommand::undo()
|
void PasteCommand::undo()
|
||||||
{
|
{
|
||||||
if (m_clipboardDataWidth == 0)
|
if (m_clipboardDataWidth == 0 || m_clipboardDataHeight == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
|
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
|
||||||
@@ -528,6 +547,9 @@ void PasteCommand::undo()
|
|||||||
|
|
||||||
arrayR++;
|
arrayR++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!m_selectionActive)
|
||||||
|
m_teletextDocument->moveCursor(m_row, m_column);
|
||||||
}
|
}
|
||||||
#endif // !QT_NO_CLIPBOARD
|
#endif // !QT_NO_CLIPBOARD
|
||||||
|
|
||||||
|
|||||||
@@ -394,20 +394,33 @@ void TeletextWidget::toggleCharacterBit(unsigned char bitToToggle)
|
|||||||
void TeletextWidget::selectionToClipboard()
|
void TeletextWidget::selectionToClipboard()
|
||||||
{
|
{
|
||||||
QByteArray nativeData;
|
QByteArray nativeData;
|
||||||
|
QString plainTextData;
|
||||||
QClipboard *clipboard = QApplication::clipboard();
|
QClipboard *clipboard = QApplication::clipboard();
|
||||||
|
|
||||||
nativeData.resize(2 + m_teletextDocument->selectionWidth() * m_teletextDocument->selectionHeight());
|
nativeData.resize(2 + m_teletextDocument->selectionWidth() * m_teletextDocument->selectionHeight());
|
||||||
nativeData[0] = m_teletextDocument->selectionHeight();
|
nativeData[0] = m_teletextDocument->selectionHeight();
|
||||||
nativeData[1] = m_teletextDocument->selectionWidth();
|
nativeData[1] = m_teletextDocument->selectionWidth();
|
||||||
|
|
||||||
|
plainTextData.reserve((m_teletextDocument->selectionWidth()+1) * m_teletextDocument->selectionHeight() - 1);
|
||||||
|
|
||||||
int i=2;
|
int i=2;
|
||||||
|
|
||||||
for (int r=m_teletextDocument->selectionTopRow(); r<=m_teletextDocument->selectionBottomRow(); r++)
|
for (int r=m_teletextDocument->selectionTopRow(); r<=m_teletextDocument->selectionBottomRow(); r++) {
|
||||||
for (int c=m_teletextDocument->selectionLeftColumn(); c<=m_teletextDocument->selectionRightColumn(); c++)
|
for (int c=m_teletextDocument->selectionLeftColumn(); c<=m_teletextDocument->selectionRightColumn(); c++) {
|
||||||
nativeData[i++] = m_teletextDocument->currentSubPage()->character(r, c);
|
nativeData[i++] = m_teletextDocument->currentSubPage()->character(r, c);
|
||||||
|
|
||||||
|
if (m_teletextDocument->currentSubPage()->character(r, c) >= 0x20)
|
||||||
|
plainTextData.append(keymapping[m_pageRender.level1CharSet(r, c)].key(m_teletextDocument->currentSubPage()->character(r, c), m_teletextDocument->currentSubPage()->character(r, c)));
|
||||||
|
else
|
||||||
|
plainTextData.append(' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
plainTextData.append('\n');
|
||||||
|
}
|
||||||
|
|
||||||
QMimeData *mimeData = new QMimeData();
|
QMimeData *mimeData = new QMimeData();
|
||||||
mimeData->setData("application/x-teletext", nativeData);
|
mimeData->setData("application/x-teletext", nativeData);
|
||||||
|
mimeData->setText(plainTextData);
|
||||||
clipboard->setMimeData(mimeData);
|
clipboard->setMimeData(mimeData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user