Changeset View
Changeset View
Standalone View
Standalone View
src/canvas.cpp
Show First 20 Lines • Show All 104 Lines • ▼ Show 20 Line(s) | |||||
105 | void Canvas::resizeEvent(QResizeEvent* event) | 105 | void Canvas::resizeEvent(QResizeEvent* event) | ||
106 | { | 106 | { | ||
107 | fitInView(_scene->sceneRect().adjusted(kCanvasMargin*-1,kCanvasMargin*-1,kCanvasMargin,kCanvasMargin), Qt::KeepAspectRatio); | 107 | fitInView(_scene->sceneRect().adjusted(kCanvasMargin*-1,kCanvasMargin*-1,kCanvasMargin,kCanvasMargin), Qt::KeepAspectRatio); | ||
108 | event->accept(); | 108 | event->accept(); | ||
109 | } | 109 | } | ||
110 | 110 | | |||
111 | QColor Canvas::rgbDoublesToColor(double r, double g, double b) | 111 | QColor Canvas::rgbDoublesToColor(double r, double g, double b) | ||
112 | { | 112 | { | ||
113 | return QColor(qMin(qMax((int)r, 0), 255), | 113 | return QColor(qMin(qMax(static_cast<int>(r), 0), 255), | ||
114 | qMin(qMax((int)g, 0), 255), | 114 | qMin(qMax(static_cast<int>(g), 0), 255), | ||
115 | qMin(qMax((int)b, 0), 255)); | 115 | qMin(qMax(static_cast<int>(b), 0), 255)); | ||
tcanabrava: This was using space and she changed to tabs, I'll allow this pass. | |||||
116 | } | 116 | } | ||
117 | 117 | | |||
118 | void Canvas::drawLine(double x1, double y1, double x2, double y2) | 118 | void Canvas::drawLine(double x1, double y1, double x2, double y2) | ||
119 | { | 119 | { | ||
120 | if (penWidthIsZero) return; | 120 | if (penWidthIsZero) return; | ||
121 | QGraphicsLineItem* line = new QGraphicsLineItem(QLineF(x1, y1, x2, y2), nullptr); | 121 | QGraphicsLineItem* line = new QGraphicsLineItem(QLineF(x1, y1, x2, y2), nullptr); | ||
122 | _scene->addItem(line); | 122 | _scene->addItem(line); | ||
123 | line->setPen(*pen); | 123 | line->setPen(*pen); | ||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | 165 | } else { | |||
169 | else | 169 | else | ||
170 | pen->setWidthF(width); | 170 | pen->setWidthF(width); | ||
171 | } | 171 | } | ||
172 | } | 172 | } | ||
173 | 173 | | |||
174 | void Canvas::slotPenColor(double r, double g, double b) | 174 | void Canvas::slotPenColor(double r, double g, double b) | ||
175 | { | 175 | { | ||
176 | pen->setColor(rgbDoublesToColor(r, g, b)); | 176 | pen->setColor(rgbDoublesToColor(r, g, b)); | ||
177 | textColor.setRgb((int)r, (int)g, (int)b); | 177 | textColor.setRgb(static_cast<int>(r), static_cast<int>(g), static_cast<int>(b)); | ||
178 | } | 178 | } | ||
179 | 179 | | |||
180 | void Canvas::slotCanvasColor(double r, double g, double b) | 180 | void Canvas::slotCanvasColor(double r, double g, double b) | ||
181 | { | 181 | { | ||
182 | //_scene->setBackgroundBrush(QBrush(rgbDoublesToColor(r, g, b))); | 182 | //_scene->setBackgroundBrush(QBrush(rgbDoublesToColor(r, g, b))); | ||
183 | canvasFrame->setBrush(QBrush(rgbDoublesToColor(r, g, b))); | 183 | canvasFrame->setBrush(QBrush(rgbDoublesToColor(r, g, b))); | ||
184 | } | 184 | } | ||
185 | 185 | | |||
Show All 28 Lines | |||||
214 | void Canvas::slotReset() | 214 | void Canvas::slotReset() | ||
215 | { | 215 | { | ||
216 | slotClear(); | 216 | slotClear(); | ||
217 | initValues(); | 217 | initValues(); | ||
218 | } | 218 | } | ||
219 | 219 | | |||
220 | void Canvas::wheelEvent(QWheelEvent *event) | 220 | void Canvas::wheelEvent(QWheelEvent *event) | ||
221 | { | 221 | { | ||
222 | scaleView(std::pow((double)2.0, -event->delta() / 240.0)); | 222 | scaleView(std::pow(static_cast<double>(2.0), -event->delta() / 240.0)); | ||
223 | } | 223 | } | ||
224 | 224 | | |||
225 | void Canvas::scaleView(double scaleFactor) | 225 | void Canvas::scaleView(double scaleFactor) | ||
226 | { | 226 | { | ||
227 | qreal factor = matrix().scale(scaleFactor, scaleFactor).mapRect(QRectF(0, 0, 1, 1)).width(); | 227 | qreal factor = matrix().scale(scaleFactor, scaleFactor).mapRect(QRectF(0, 0, 1, 1)).width(); | ||
228 | if (factor < 0.07 || factor > 100) return; | 228 | if (factor < 0.07 || factor > 100) return; | ||
229 | scale(scaleFactor, scaleFactor); | 229 | scale(scaleFactor, scaleFactor); | ||
230 | } | 230 | } | ||
▲ Show 20 Lines • Show All 51 Lines • Show Last 20 Lines |
This was using space and she changed to tabs, I'll allow this pass.