Changeset View
Changeset View
Standalone View
Standalone View
environments/document/kpDocumentEnvironment.cpp
Show First 20 Lines • Show All 85 Lines • ▼ Show 20 Line(s) | |||||
86 | 86 | | |||
87 | // public | 87 | // public | ||
88 | void kpDocumentEnvironment::switchToCompatibleTool (const kpAbstractSelection &selection, | 88 | void kpDocumentEnvironment::switchToCompatibleTool (const kpAbstractSelection &selection, | ||
89 | bool *isTextChanged) const | 89 | bool *isTextChanged) const | ||
90 | { | 90 | { | ||
91 | qCDebug(kpLogEnvironments) << "kpDocumentEnvironment::switchToCompatibleTool(" | 91 | qCDebug(kpLogEnvironments) << "kpDocumentEnvironment::switchToCompatibleTool(" | ||
92 | << &selection << ")" | 92 | << &selection << ")" | ||
93 | << " mainwindow.tool=" | 93 | << " mainwindow.tool=" | ||
94 | << (mainWindow ()->tool () ? mainWindow ()->tool ()->objectName () : 0) | 94 | << (mainWindow ()->tool () ? mainWindow ()->tool ()->objectName () : nullptr) | ||
95 | << " mainWindow.toolIsTextTool=" << mainWindow ()->toolIsTextTool () | 95 | << " mainWindow.toolIsTextTool=" << mainWindow ()->toolIsTextTool () | ||
96 | << " current selection=" | 96 | << " current selection=" | ||
97 | << document ()->selection () | 97 | << document ()->selection () | ||
98 | << " new selection is text=" | 98 | << " new selection is text=" | ||
99 | << dynamic_cast <const kpTextSelection *> (&selection) | 99 | << dynamic_cast <const kpTextSelection *> (&selection); | ||
100 | << endl; | | |||
101 | 100 | | |||
102 | 101 | | |||
103 | *isTextChanged = (mainWindow ()->toolIsTextTool () != | 102 | *isTextChanged = (mainWindow ()->toolIsTextTool () != | ||
104 | (dynamic_cast <const kpTextSelection *> (&selection) != nullptr)); | 103 | (dynamic_cast <const kpTextSelection *> (&selection) != nullptr)); | ||
105 | 104 | | |||
106 | // We don't change the Selection Tool if the new selection's | 105 | // We don't change the Selection Tool if the new selection's | ||
107 | // shape is merely different to the current tool's (e.g. rectangular | 106 | // shape is merely different to the current tool's (e.g. rectangular | ||
108 | // vs elliptical) because: | 107 | // vs elliptical) because: | ||
Show All 29 Lines | 136 | { | |||
138 | qCDebug(kpLogEnvironments) << "\tswitch to free form selection tool"; | 137 | qCDebug(kpLogEnvironments) << "\tswitch to free form selection tool"; | ||
139 | mainWindow ()->slotToolFreeFormSelection (); | 138 | mainWindow ()->slotToolFreeFormSelection (); | ||
140 | } | 139 | } | ||
141 | else if (dynamic_cast <const kpTextSelection *> (&selection)) | 140 | else if (dynamic_cast <const kpTextSelection *> (&selection)) | ||
142 | { | 141 | { | ||
143 | qCDebug(kpLogEnvironments) << "\tswitch to text selection tool"; | 142 | qCDebug(kpLogEnvironments) << "\tswitch to text selection tool"; | ||
144 | mainWindow ()->slotToolText (); | 143 | mainWindow ()->slotToolText (); | ||
145 | } | 144 | } | ||
146 | else | 145 | else { | ||
147 | Q_ASSERT (!"Unknown selection type"); | 146 | Q_ASSERT (!"Unknown selection type"); | ||
148 | } | 147 | } | ||
148 | } | ||||
149 | 149 | | |||
150 | qCDebug(kpLogEnvironments) << "kpDocumentEnvironment::switchToCompatibleTool(" << &selection << ") finished"; | 150 | qCDebug(kpLogEnvironments) << "kpDocumentEnvironment::switchToCompatibleTool(" << &selection << ") finished"; | ||
151 | } | 151 | } | ||
152 | 152 | | |||
153 | //--------------------------------------------------------------------- | 153 | //--------------------------------------------------------------------- | ||
154 | 154 | | |||
155 | // public | 155 | // public | ||
156 | void kpDocumentEnvironment::assertMatchingUIState (const kpAbstractSelection &selection) const | 156 | void kpDocumentEnvironment::assertMatchingUIState (const kpAbstractSelection &selection) const | ||
157 | { | 157 | { | ||
158 | // Trap and try to recover from bugs. | 158 | // Trap and try to recover from bugs. | ||
159 | // TODO: See kpDocument::setSelection() API comment and determine best fix. | 159 | // TODO: See kpDocument::setSelection() API comment and determine best fix. | ||
160 | const kpAbstractImageSelection *imageSelection = | 160 | const auto *imageSelection = dynamic_cast <const kpAbstractImageSelection *> (&selection); | ||
161 | dynamic_cast <const kpAbstractImageSelection *> (&selection); | 161 | const auto *textSelection = dynamic_cast <const kpTextSelection *> (&selection); | ||
162 | const kpTextSelection *textSelection = | 162 | | ||
163 | dynamic_cast <const kpTextSelection *> (&selection); | | |||
164 | if (imageSelection) | 163 | if (imageSelection) | ||
165 | { | 164 | { | ||
166 | if (imageSelection->transparency () != mainWindow ()->imageSelectionTransparency ()) | 165 | if (imageSelection->transparency () != mainWindow ()->imageSelectionTransparency ()) | ||
167 | { | 166 | { | ||
168 | qCCritical(kpLogEnvironments) << "kpDocument::setSelection() sel's transparency differs " | 167 | qCCritical(kpLogEnvironments) << "kpDocument::setSelection() sel's transparency differs " | ||
169 | "from mainWindow's transparency - setting mainWindow's transparency " | 168 | "from mainWindow's transparency - setting mainWindow's transparency " | ||
170 | "to sel" | 169 | "to sel"; | ||
171 | << endl; | 170 | | ||
172 | qCCritical(kpLogEnvironments) << "\tisOpaque: sel=" << imageSelection->transparency ().isOpaque () | 171 | qCCritical(kpLogEnvironments) << "\tisOpaque: sel=" << imageSelection->transparency ().isOpaque () | ||
173 | << " mainWindow=" << mainWindow ()->imageSelectionTransparency ().isOpaque () | 172 | << " mainWindow=" << mainWindow ()->imageSelectionTransparency ().isOpaque (); | ||
174 | << endl; | 173 | | ||
175 | mainWindow ()->setImageSelectionTransparency (imageSelection->transparency ()); | 174 | mainWindow ()->setImageSelectionTransparency (imageSelection->transparency ()); | ||
176 | } | 175 | } | ||
177 | } | 176 | } | ||
178 | else if (textSelection) | 177 | else if (textSelection) | ||
179 | { | 178 | { | ||
180 | if (textSelection->textStyle () != mainWindow ()->textStyle ()) | 179 | if (textSelection->textStyle () != mainWindow ()->textStyle ()) | ||
181 | { | 180 | { | ||
182 | qCCritical(kpLogEnvironments) << "kpDocument::setSelection() sel's textStyle differs " | 181 | qCCritical(kpLogEnvironments) << "kpDocument::setSelection() sel's textStyle differs " | ||
183 | "from mainWindow's textStyle - setting mainWindow's textStyle " | 182 | "from mainWindow's textStyle - setting mainWindow's textStyle " | ||
184 | "to sel" | 183 | "to sel"; | ||
185 | << endl; | 184 | | ||
186 | mainWindow ()->setTextStyle (textSelection->textStyle ()); | 185 | mainWindow ()->setTextStyle (textSelection->textStyle ()); | ||
187 | } | 186 | } | ||
188 | } | 187 | } | ||
189 | else | 188 | else | ||
190 | { | 189 | { | ||
191 | Q_ASSERT (!"Unknown selection type"); | 190 | Q_ASSERT (!"Unknown selection type"); | ||
192 | } | 191 | } | ||
193 | } | 192 | } | ||
194 | 193 | | |||
195 | 194 | |