Changeset View
Changeset View
Standalone View
Standalone View
tools/selection/text/kpToolText_Create.cpp
Show All 19 Lines | 2 | /* | |||
---|---|---|---|---|---|
20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | 20 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 21 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
22 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 22 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
23 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 23 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
25 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | 26 | */ | ||
27 | 27 | | |||
28 | #define DEBUG_KP_TOOL_TEXT 0 | | |||
29 | | ||||
30 | | ||||
31 | #include "tools/selection/text/kpToolText.h" | 28 | #include "tools/selection/text/kpToolText.h" | ||
32 | #include "kpToolTextPrivate.h" | 29 | #include "kpToolTextPrivate.h" | ||
33 | 30 | | |||
34 | #include <QList> | 31 | #include <QList> | ||
35 | 32 | | |||
36 | #include <KLocalizedString> | 33 | #include <KLocalizedString> | ||
37 | #include "kpLogCategories.h" | 34 | #include "kpLogCategories.h" | ||
38 | 35 | | |||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Line(s) | |||||
102 | 99 | | |||
103 | // private | 100 | // private | ||
104 | bool kpToolText::shouldCreate (bool dragAccepted, | 101 | bool kpToolText::shouldCreate (bool dragAccepted, | ||
105 | const QPoint &accidentalDragAdjustedPoint, | 102 | const QPoint &accidentalDragAdjustedPoint, | ||
106 | const kpTextStyle &textStyle, | 103 | const kpTextStyle &textStyle, | ||
107 | int *minimumWidthOut, int *minimumHeightOut, | 104 | int *minimumWidthOut, int *minimumHeightOut, | ||
108 | bool *newDragAccepted) | 105 | bool *newDragAccepted) | ||
109 | { | 106 | { | ||
110 | #if DEBUG_KP_TOOL_TEXT && 1 | | |||
111 | qCDebug(kpLogTools) << "CALL(dragAccepted=" << dragAccepted | 107 | qCDebug(kpLogTools) << "CALL(dragAccepted=" << dragAccepted | ||
112 | << ",accidentalDragAdjustedPoint=" << accidentalDragAdjustedPoint | 108 | << ",accidentalDragAdjustedPoint=" << accidentalDragAdjustedPoint | ||
113 | << ")"; | 109 | << ")"; | ||
114 | #endif | | |||
115 | *newDragAccepted = dragAccepted; | 110 | *newDragAccepted = dragAccepted; | ||
116 | 111 | | |||
117 | // Is the drag so short that we're essentially just clicking? | 112 | // Is the drag so short that we're essentially just clicking? | ||
118 | // Basically, we're trying to prevent unintentional creation of 1-pixel | 113 | // Basically, we're trying to prevent unintentional creation of 1-pixel | ||
119 | // selections. | 114 | // selections. | ||
120 | if (!dragAccepted && accidentalDragAdjustedPoint == startPoint ()) | 115 | if (!dragAccepted && accidentalDragAdjustedPoint == startPoint ()) | ||
121 | { | 116 | { | ||
122 | // We had an existing text box before the click? | 117 | // We had an existing text box before the click? | ||
123 | if (hadSelectionBeforeDraw ()) | 118 | if (hadSelectionBeforeDraw ()) | ||
124 | { | 119 | { | ||
125 | #if DEBUG_KP_TOOL_TEXT && 1 | | |||
126 | qCDebug(kpLogTools) << "\ttext box deselect - NOP - return"; | 120 | qCDebug(kpLogTools) << "\ttext box deselect - NOP - return"; | ||
127 | #endif | | |||
128 | // We must be attempting to deselect the text box. | 121 | // We must be attempting to deselect the text box. | ||
129 | // This deselection has already been done by kpAbstractSelectionTool::beginDraw(). | 122 | // This deselection has already been done by kpAbstractSelectionTool::beginDraw(). | ||
130 | // Therefore, we are not doing a drag. | 123 | // Therefore, we are not doing a drag. | ||
131 | return false; | 124 | return false; | ||
132 | } | 125 | } | ||
133 | // We are probably creating a new box. | 126 | // We are probably creating a new box. | ||
134 | else | 127 | else | ||
135 | { | 128 | { | ||
136 | // This drag is currently a click -- not a drag. | 129 | // This drag is currently a click -- not a drag. | ||
137 | // As a special case, allow user to create a text box, | 130 | // As a special case, allow user to create a text box, | ||
138 | // of reasonable ("preferred minimum") size, using a single | 131 | // of reasonable ("preferred minimum") size, using a single | ||
139 | // click. | 132 | // click. | ||
140 | // | 133 | // | ||
141 | // If the user drags further, the normal drag-to-create-a-textbox | 134 | // If the user drags further, the normal drag-to-create-a-textbox | ||
142 | // branch [x] will execute and the size will be determined based on | 135 | // branch [x] will execute and the size will be determined based on | ||
143 | // the size of the drag instead. | 136 | // the size of the drag instead. | ||
144 | 137 | | |||
145 | #if DEBUG_KP_TOOL_TEXT && 1 | | |||
146 | qCDebug(kpLogTools) << "\tclick creating text box"; | 138 | qCDebug(kpLogTools) << "\tclick creating text box"; | ||
147 | #endif | | |||
148 | 139 | | |||
149 | // (Click creating text box with RMB would not be obvious | 140 | // (Click creating text box with RMB would not be obvious | ||
150 | // since RMB menu most likely hides text box immediately | 141 | // since RMB menu most likely hides text box immediately | ||
151 | // afterwards) | 142 | // afterwards) | ||
152 | // TODO: I suspect this logic is simply too late | 143 | // TODO: I suspect this logic is simply too late | ||
153 | // TODO: We setUserShapePoints() on return but didn't before. | 144 | // TODO: We setUserShapePoints() on return but didn't before. | ||
154 | if (mouseButton () == 1) | 145 | if (mouseButton () == 1) | ||
155 | return false/*do not create text box*/; | 146 | return false/*do not create text box*/; | ||
Show All 25 Lines | |||||
181 | return true/*do create text box*/; | 172 | return true/*do create text box*/; | ||
182 | } | 173 | } | ||
183 | } | 174 | } | ||
184 | // Dragging to create a text box [x]. | 175 | // Dragging to create a text box [x]. | ||
185 | // | 176 | // | ||
186 | // The size will be determined based on the size of the drag. | 177 | // The size will be determined based on the size of the drag. | ||
187 | else | 178 | else | ||
188 | { | 179 | { | ||
189 | #if DEBUG_KP_TOOL_TEXT && 1 | | |||
190 | qCDebug(kpLogTools) << "\tdrag creating text box"; | 180 | qCDebug(kpLogTools) << "\tdrag creating text box"; | ||
191 | #endif | | |||
192 | *minimumWidthOut = kpTextSelection::MinimumWidthForTextStyle (textStyle); | 181 | *minimumWidthOut = kpTextSelection::MinimumWidthForTextStyle (textStyle); | ||
193 | *minimumHeightOut = kpTextSelection::MinimumHeightForTextStyle (textStyle); | 182 | *minimumHeightOut = kpTextSelection::MinimumHeightForTextStyle (textStyle); | ||
194 | 183 | | |||
195 | *newDragAccepted = true; | 184 | *newDragAccepted = true; | ||
196 | return true/*do create text box*/; | 185 | return true/*do create text box*/; | ||
197 | } | 186 | } | ||
198 | 187 | | |||
199 | } | 188 | } | ||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | 195 | { | |||
241 | if (normalizedRect.height () < minimumHeight) | 230 | if (normalizedRect.height () < minimumHeight) | ||
242 | { | 231 | { | ||
243 | if (accidentalDragAdjustedPoint.y () >= startPoint ().y ()) | 232 | if (accidentalDragAdjustedPoint.y () >= startPoint ().y ()) | ||
244 | normalizedRect.setHeight (minimumHeight); | 233 | normalizedRect.setHeight (minimumHeight); | ||
245 | else | 234 | else | ||
246 | normalizedRect.setY (normalizedRect.bottom () - minimumHeight + 1); | 235 | normalizedRect.setY (normalizedRect.bottom () - minimumHeight + 1); | ||
247 | } | 236 | } | ||
248 | 237 | | |||
249 | #if DEBUG_KP_TOOL_TEXT && 1 | | |||
250 | qCDebug(kpLogTools) << "\t\tnormalizedRect=" << normalizedRect | 238 | qCDebug(kpLogTools) << "\t\tnormalizedRect=" << normalizedRect | ||
251 | << " kpTextSelection::preferredMinimumSize=" | 239 | << " kpTextSelection::preferredMinimumSize=" | ||
252 | << QSize (minimumWidth, minimumHeight) | 240 | << QSize (minimumWidth, minimumHeight); | ||
253 | << endl; | | |||
254 | #endif | | |||
255 | 241 | | |||
256 | 242 | | |||
257 | // | 243 | // | ||
258 | // Construct and Deploy Text Box. | 244 | // Construct and Deploy Text Box. | ||
259 | // | 245 | // | ||
260 | 246 | | |||
261 | // Create empty text box. | 247 | // Create empty text box. | ||
262 | QList <QString> textLines; | 248 | QList <QString> textLines; | ||
Show All 26 Lines |