File indexing completed on 2025-02-23 04:09:00

0001 /*
0002  *  SPDX-FileCopyrightText: 2016 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "kis_guides_decoration.h"
0008 
0009 #include <KisDocument.h>
0010 #include "kis_config.h"
0011 #include "kis_guides_config.h"
0012 #include "kis_coordinates_converter.h"
0013 
0014 struct KisGuidesDecoration::Private
0015 {
0016     KisGuidesConfig guidesConfig;
0017 };
0018 
0019 KisGuidesDecoration::KisGuidesDecoration(QPointer<KisView> view)
0020     : KisCanvasDecoration(GUIDES_DECORATION_ID, view),
0021       m_d(new Private)
0022 {
0023     setPriority(90);
0024 }
0025 
0026 KisGuidesDecoration::~KisGuidesDecoration()
0027 {
0028 }
0029 
0030 void KisGuidesDecoration::setGuidesConfig(const KisGuidesConfig &value)
0031 {
0032     m_d->guidesConfig = value;
0033 }
0034 
0035 const KisGuidesConfig& KisGuidesDecoration::guidesConfig() const
0036 {
0037     return m_d->guidesConfig;
0038 }
0039 
0040 
0041 void KisGuidesDecoration::drawDecoration(QPainter &painter, const QRectF& updateArea, const KisCoordinatesConverter *converter, KisCanvas2 *canvas)
0042 {
0043     Q_UNUSED(canvas);
0044 
0045     const qreal borderDelta = 2.0;
0046     const QPen guidesPen(m_d->guidesConfig.guidesPen());
0047 
0048     painter.save();
0049     painter.setPen(guidesPen);
0050     painter.setTransform(QTransform());
0051     painter.setRenderHints(QPainter::Antialiasing, false);
0052     painter.setRenderHints(QPainter::Antialiasing, false);
0053 
0054     Q_FOREACH (qreal guide, m_d->guidesConfig.horizontalGuideLines()) {
0055         if (guide < updateArea.top() - borderDelta ||
0056             guide > updateArea.bottom() + borderDelta) {
0057 
0058             continue;
0059         }
0060 
0061         const QPoint p0 = converter->documentToWidget(QPointF(updateArea.left() - borderDelta, guide)).toPoint();
0062         const QPoint p1 = converter->documentToWidget(QPointF(updateArea.right() + borderDelta, guide)).toPoint();
0063         painter.drawLine(p0, p1);
0064     }
0065 
0066     Q_FOREACH (qreal guide, m_d->guidesConfig.verticalGuideLines()) {
0067         if (guide < updateArea.left() - borderDelta ||
0068             guide > updateArea.right() + borderDelta) {
0069 
0070             continue;
0071         }
0072 
0073         const QPoint p0 = converter->documentToWidget(QPointF(guide, updateArea.top() - borderDelta)).toPoint();
0074         const QPoint p1 = converter->documentToWidget(QPointF(guide, updateArea.bottom() + borderDelta)).toPoint();
0075         painter.drawLine(p0, p1);
0076     }
0077 
0078     painter.restore();
0079 }