Fix pasting into Type Tool edit box
This commit is contained in:
parent
1e87ca33b0
commit
dc44edb301
1 changed files with 21 additions and 3 deletions
|
@ -35,6 +35,9 @@
|
|||
|
||||
// For Qt translation support
|
||||
#include <QCoreApplication>
|
||||
#include <QClipboard>
|
||||
#include <QApplication>
|
||||
#include <QMimeData>
|
||||
|
||||
//#include "tw/message.h"
|
||||
|
||||
|
@ -1511,6 +1514,20 @@ void TypeTool::deleteKey() {
|
|||
bool TypeTool::keyDown(QKeyEvent *event) {
|
||||
QString text = event->text();
|
||||
if ((event->modifiers() & Qt::ShiftModifier)) text.toUpper();
|
||||
|
||||
std::string keyStr =
|
||||
QKeySequence(event->key() + event->modifiers()).toString().toStdString();
|
||||
QAction *action = CommandManager::instance()->getActionFromShortcut(keyStr);
|
||||
if (action) {
|
||||
std::string actionId = CommandManager::instance()->getIdFromAction(action);
|
||||
if (actionId == "MI_Paste") {
|
||||
QClipboard *clipboard = QApplication::clipboard();
|
||||
const QMimeData *mimeData = clipboard->mimeData();
|
||||
if (!mimeData->hasText()) return true;
|
||||
text = mimeData->text().replace('\n', '\r');
|
||||
}
|
||||
}
|
||||
|
||||
std::wstring unicodeChar = text.toStdWString();
|
||||
|
||||
// per sicurezza
|
||||
|
@ -1618,9 +1635,10 @@ bool TypeTool::keyDown(QKeyEvent *event) {
|
|||
default:
|
||||
if (unicodeChar.empty()) return false;
|
||||
replaceText(unicodeChar, m_cursorIndex, m_cursorIndex);
|
||||
m_cursorIndex++;
|
||||
m_preeditRange = std::make_pair(m_cursorIndex, m_cursorIndex);
|
||||
updateCharPositions(m_cursorIndex - 1);
|
||||
int startIndex = m_cursorIndex + 1;
|
||||
m_cursorIndex += unicodeChar.size();
|
||||
m_preeditRange = std::make_pair(startIndex, m_cursorIndex);
|
||||
updateCharPositions(startIndex - 1);
|
||||
}
|
||||
|
||||
invalidate();
|
||||
|
|
Loading…
Reference in a new issue