Andreas Traczyk | dc17c81 | 2019-01-11 15:35:20 -0500 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * Copyright (C) 2019 by Savoir-faire Linux * |
| 3 | * Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> * |
| 4 | * * |
| 5 | * This program is free software; you can redistribute it and/or modify * |
| 6 | * it under the terms of the GNU General Public License as published by * |
| 7 | * the Free Software Foundation; either version 3 of the License, or * |
| 8 | * (at your option) any later version. * |
| 9 | * * |
| 10 | * This program is distributed in the hope that it will be useful, * |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 13 | * GNU General Public License for more details. * |
| 14 | * * |
| 15 | * You should have received a copy of the GNU General Public License * |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. * |
| 17 | **************************************************************************/ |
| 18 | |
| 19 | #pragma once |
| 20 | |
| 21 | #include "bezierconnectorwidget.h" |
| 22 | |
| 23 | #include <QPainter> |
| 24 | #include <QDebug> |
| 25 | |
| 26 | BezierConnectorWidget::BezierConnectorWidget(QWidget* parent) : QWidget(parent) |
| 27 | { |
| 28 | } |
| 29 | |
| 30 | BezierConnectorWidget::~BezierConnectorWidget() |
| 31 | { |
| 32 | } |
| 33 | |
| 34 | void |
| 35 | BezierConnectorWidget::paintEvent(QPaintEvent* event) |
| 36 | { |
| 37 | Q_UNUSED(event); |
| 38 | QPainter painter(this); |
| 39 | |
| 40 | painter.setRenderHints(QPainter::Antialiasing, true); |
| 41 | |
| 42 | QPen pen(painter.pen()); |
| 43 | pen.setWidth(2.0); |
| 44 | pen.setColor(QColor(240, 240, 240)); |
| 45 | painter.setPen(pen); |
| 46 | |
| 47 | QPainterPath bezierPath; |
| 48 | double c = 0.551915024494; |
| 49 | QPointF p0, p1, p2, p3; |
| 50 | |
| 51 | if (this->objectName().contains("right", Qt::CaseInsensitive)) { |
| 52 | p0 = rect().topLeft(); |
| 53 | p3 = rect().bottomRight(); |
| 54 | p1 = QPointF(p0.x() + c * rect().width(), p0.y()); |
| 55 | p2 = QPointF(p0.x() + rect().width(), p0.y() + rect().height() - (c * rect().height())); |
| 56 | } else if (this->objectName().contains("left", Qt::CaseInsensitive)) { |
| 57 | p0 = rect().bottomLeft(); |
| 58 | p3 = rect().topRight(); |
Andreas Traczyk | dc2703e | 2019-01-17 18:02:31 -0500 | [diff] [blame] | 59 | p1 = QPointF(p0.x(), p3.y() + c * rect().height()); |
| 60 | p2 = QPointF(p0.x() + c * rect().width(), p3.y()); |
Andreas Traczyk | dc17c81 | 2019-01-11 15:35:20 -0500 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | bezierPath.moveTo(p0); |
| 64 | bezierPath.cubicTo(p1, p2, p3); |
| 65 | painter.drawPath(bezierPath); |
| 66 | } |