|
10 | 10 | namespace { |
11 | 11 | #define PADDING_VALUE 2 |
12 | 12 | #define THICKNESS_OFFSET 15 |
| 13 | +int const MIN_COUNTER = 1; |
| 14 | +int const MAX_COUNTER = 999; |
13 | 15 | } |
14 | 16 |
|
15 | 17 | CircleCountTool::CircleCountTool(QObject* parent) |
@@ -180,21 +182,50 @@ void CircleCountTool::paintMousePreview(QPainter& painter, |
180 | 182 |
|
181 | 183 | // Thickness for pen is *2 to range from radius to diameter to match the |
182 | 184 | // ellipse draw function |
183 | | - auto orig_pen = painter.pen(); |
184 | | - auto orig_opacity = painter.opacity(); |
| 185 | + auto const previewWidth = (size() + THICKNESS_OFFSET) * 2; |
| 186 | + painter.save(); |
185 | 187 | painter.setOpacity(0.35); |
186 | | - painter.setPen(QPen(context.color, |
187 | | - (size() + THICKNESS_OFFSET) * 2, |
188 | | - Qt::SolidLine, |
189 | | - Qt::RoundCap)); |
| 188 | + painter.setPen( |
| 189 | + QPen(context.color, previewWidth, Qt::SolidLine, Qt::RoundCap)); |
190 | 190 | painter.drawLine(context.mousePos, |
191 | 191 | { context.mousePos.x() + 1, context.mousePos.y() + 1 }); |
192 | | - painter.setOpacity(orig_opacity); |
193 | | - painter.setPen(orig_pen); |
| 192 | + |
| 193 | + auto font = painter.font(); |
| 194 | + font.setPixelSize(previewWidth / 2); |
| 195 | + font.setBold(true); |
| 196 | + painter.setFont(font); |
| 197 | + |
| 198 | + painter.setPen(QPen("white")); |
| 199 | + painter.drawText(QRect{ context.mousePos.x() - previewWidth / 2, |
| 200 | + context.mousePos.y() - previewWidth / 2, |
| 201 | + previewWidth, |
| 202 | + previewWidth }, |
| 203 | + Qt::AlignCenter, |
| 204 | + QString::number(context.circleCount)); |
| 205 | + |
| 206 | + painter.restore(); |
| 207 | +} |
| 208 | + |
| 209 | +bool CircleCountTool::handleMouseWheelEvent(int delta, |
| 210 | + bool adjustmentButtonPressed, |
| 211 | + CaptureContext& ctx) |
| 212 | +{ |
| 213 | + if (adjustmentButtonPressed) { |
| 214 | + ctx.circleCount = |
| 215 | + qBound(MIN_COUNTER, ctx.circleCount + delta, MAX_COUNTER); |
| 216 | + } |
| 217 | + return adjustmentButtonPressed; |
194 | 218 | } |
195 | 219 |
|
196 | 220 | void CircleCountTool::drawStart(const CaptureContext& context) |
197 | 221 | { |
| 222 | + setCount(context.circleCount); |
| 223 | + // ------------------------------------------------------------------ |
| 224 | + // Temporary solution until the circle count variable removed from |
| 225 | + // the context altogether and made part of Circle count tool |
| 226 | + CaptureContext& ctx = const_cast<CaptureContext&>(context); |
| 227 | + ctx.circleCount = qBound(MIN_COUNTER, ctx.circleCount + 1, MAX_COUNTER); |
| 228 | + // ------------------------------------------------------------------ |
198 | 229 | AbstractTwoPointTool::drawStart(context); |
199 | 230 | m_valid = true; |
200 | 231 | } |
|
0 commit comments