Changeset View
Changeset View
Standalone View
Standalone View
commands/tools/selection/text/kpToolTextInsertCommand.cpp
Show All 32 Lines | |||||
33 | #include "layers/selections/text/kpTextSelection.h" | 33 | #include "layers/selections/text/kpTextSelection.h" | ||
34 | #include "views/manager/kpViewManager.h" | 34 | #include "views/manager/kpViewManager.h" | ||
35 | 35 | | |||
36 | #include <QList> | 36 | #include <QList> | ||
37 | 37 | | |||
38 | //--------------------------------------------------------------------- | 38 | //--------------------------------------------------------------------- | ||
39 | 39 | | |||
40 | kpToolTextInsertCommand::kpToolTextInsertCommand (const QString &name, | 40 | kpToolTextInsertCommand::kpToolTextInsertCommand (const QString &name, | ||
41 | int row, int col, QString newText, | 41 | int row, int col, const QString& newText, | ||
42 | kpCommandEnvironment *environ) | 42 | kpCommandEnvironment *environ) | ||
43 | : kpNamedCommand (name, environ), | 43 | : kpNamedCommand (name, environ), | ||
44 | m_row (row), m_col (col) | 44 | m_row (row), m_col (col) | ||
45 | { | 45 | { | ||
46 | viewManager ()->setTextCursorPosition (m_row, m_col); | 46 | viewManager ()->setTextCursorPosition (m_row, m_col); | ||
47 | addText (newText); | 47 | addText (newText); | ||
48 | } | 48 | } | ||
49 | 49 | | |||
50 | //--------------------------------------------------------------------- | 50 | //--------------------------------------------------------------------- | ||
51 | 51 | | |||
52 | // public | 52 | // public | ||
53 | void kpToolTextInsertCommand::addText (const QString &moreText) | 53 | void kpToolTextInsertCommand::addText (const QString &moreText) | ||
54 | { | 54 | { | ||
55 | if (moreText.isEmpty ()) | 55 | if (moreText.isEmpty ()) { | ||
56 | return; | 56 | return; | ||
57 | } | ||||
57 | 58 | | |||
58 | QList <QString> textLines = textSelection ()->textLines (); | 59 | QList <QString> textLines = textSelection ()->textLines (); | ||
59 | const QString leftHalf = textLines [m_row].left (m_col); | 60 | const QString leftHalf = textLines [m_row].left (m_col); | ||
60 | const QString rightHalf = textLines [m_row].mid (m_col); | 61 | const QString rightHalf = textLines [m_row].mid (m_col); | ||
61 | textLines [m_row] = leftHalf + moreText + rightHalf; | 62 | textLines [m_row] = leftHalf + moreText + rightHalf; | ||
62 | textSelection ()->setTextLines (textLines); | 63 | textSelection ()->setTextLines (textLines); | ||
63 | 64 | | |||
64 | m_newText += moreText; | 65 | m_newText += moreText; | ||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |