Changeset View
Changeset View
Standalone View
Standalone View
commands/tools/selection/kpToolSelectionCreateCommand.cpp
Show First 20 Lines • Show All 96 Lines • ▼ Show 20 Line(s) | 96 | { | |||
---|---|---|---|---|---|
97 | qCDebug(kpLogCommands) << "kpToolSelectionCreateCommand::execute()"; | 97 | qCDebug(kpLogCommands) << "kpToolSelectionCreateCommand::execute()"; | ||
98 | 98 | | |||
99 | kpDocument *doc = document (); | 99 | kpDocument *doc = document (); | ||
100 | Q_ASSERT (doc); | 100 | Q_ASSERT (doc); | ||
101 | 101 | | |||
102 | if (m_fromSelection) | 102 | if (m_fromSelection) | ||
103 | { | 103 | { | ||
104 | qCDebug(kpLogCommands) << "\tusing fromSelection"; | 104 | qCDebug(kpLogCommands) << "\tusing fromSelection"; | ||
105 | qCDebug(kpLogCommands) << "\t\thave sel=" << doc->selection () | 105 | qCDebug(kpLogCommands) << "\t\thave sel=" << doc->selection (); | ||
106 | << endl; | 106 | auto *imageSel = dynamic_cast <kpAbstractImageSelection *> (m_fromSelection); | ||
107 | kpAbstractImageSelection *imageSel = | 107 | auto *textSel = dynamic_cast <kpTextSelection *> (m_fromSelection); | ||
108 | dynamic_cast <kpAbstractImageSelection *> (m_fromSelection); | 108 | | ||
109 | kpTextSelection *textSel = | | |||
110 | dynamic_cast <kpTextSelection *> (m_fromSelection); | | |||
111 | if (imageSel) | 109 | if (imageSel) | ||
112 | { | 110 | { | ||
113 | if (imageSel->transparency () != environ ()->imageSelectionTransparency ()) | 111 | if (imageSel->transparency () != environ ()->imageSelectionTransparency ()) { | ||
114 | environ ()->setImageSelectionTransparency (imageSel->transparency ()); | 112 | environ ()->setImageSelectionTransparency (imageSel->transparency ()); | ||
115 | } | 113 | } | ||
114 | } | ||||
116 | else if (textSel) | 115 | else if (textSel) | ||
117 | { | 116 | { | ||
118 | if (textSel->textStyle () != environ ()->textStyle ()) | 117 | if (textSel->textStyle () != environ ()->textStyle ()) { | ||
119 | environ ()->setTextStyle (textSel->textStyle ()); | 118 | environ ()->setTextStyle (textSel->textStyle ()); | ||
120 | } | 119 | } | ||
121 | else | 120 | } | ||
121 | else { | ||||
122 | Q_ASSERT (!"Unknown selection type"); | 122 | Q_ASSERT (!"Unknown selection type"); | ||
123 | } | ||||
123 | 124 | | |||
124 | viewManager ()->setTextCursorPosition (m_textRow, m_textCol); | 125 | viewManager ()->setTextCursorPosition (m_textRow, m_textCol); | ||
125 | doc->setSelection (*m_fromSelection); | 126 | doc->setSelection (*m_fromSelection); | ||
126 | 127 | | |||
127 | environ ()->somethingBelowTheCursorChanged (); | 128 | environ ()->somethingBelowTheCursorChanged (); | ||
128 | } | 129 | } | ||
129 | } | 130 | } | ||
130 | 131 | | |||
131 | // public virtual [base kpCommand] | 132 | // public virtual [base kpCommand] | ||
132 | void kpToolSelectionCreateCommand::unexecute () | 133 | void kpToolSelectionCreateCommand::unexecute () | ||
133 | { | 134 | { | ||
134 | kpDocument *doc = document (); | 135 | kpDocument *doc = document (); | ||
135 | Q_ASSERT (doc); | 136 | Q_ASSERT (doc); | ||
136 | 137 | | |||
137 | if (!doc->selection ()) | 138 | if (!doc->selection ()) | ||
138 | { | 139 | { | ||
139 | // Was just a border that got deselected? | 140 | // Was just a border that got deselected? | ||
140 | if (m_fromSelection && !m_fromSelection->hasContent ()) | 141 | if (m_fromSelection && !m_fromSelection->hasContent ()) { | ||
141 | return; | 142 | return; | ||
143 | } | ||||
142 | 144 | | |||
143 | Q_ASSERT (!"kpToolSelectionCreateCommand::unexecute() without sel region"); | 145 | Q_ASSERT (!"kpToolSelectionCreateCommand::unexecute() without sel region"); | ||
144 | return; | 146 | return; | ||
145 | } | 147 | } | ||
146 | 148 | | |||
147 | m_textRow = viewManager ()->textCursorRow (); | 149 | m_textRow = viewManager ()->textCursorRow (); | ||
148 | m_textCol = viewManager ()->textCursorCol (); | 150 | m_textCol = viewManager ()->textCursorCol (); | ||
149 | 151 | | |||
150 | doc->selectionDelete (); | 152 | doc->selectionDelete (); | ||
151 | 153 | | |||
152 | environ ()->somethingBelowTheCursorChanged (); | 154 | environ ()->somethingBelowTheCursorChanged (); | ||
153 | } | 155 | } | ||
154 | 156 | |