6 changed files with 103 additions and 9 deletions
@ -0,0 +1,39 @@
|
||||
#include "selectionrectangle.hpp" |
||||
|
||||
#include <QDebug> |
||||
#include <QGraphicsScene> |
||||
#include <QGraphicsSceneMouseEvent> |
||||
#include <QGraphicsView> |
||||
|
||||
SelectionRectangle::SelectionRectangle() { |
||||
} |
||||
|
||||
SelectionRectangle::SelectionRectangle(qreal x, qreal y, qreal w, qreal h, QGraphicsItem *parent) |
||||
: QGraphicsRectItem(x, y, w, h, parent) { |
||||
} |
||||
|
||||
void SelectionRectangle::paint(QPainter *painter, const QStyleOptionGraphicsItem *options, QWidget *widget) { |
||||
QRect rect = this->rect().toRect(); |
||||
if (rect.height() > 30 && rect.width() > 30) { |
||||
painter->setPen(Qt::NoPen); |
||||
painter->setBrush(pen().color()); |
||||
|
||||
// Before you panick, the <angle> * 16 things are needed because here angles are 1/16th of their value
|
||||
// The <x/y> - 10 is accounting for sizes.
|
||||
// Trail and error ftw
|
||||
|
||||
// Bottom left
|
||||
painter->drawPie(rect.left() - 10, rect.bottom() - 10, 20, 20, 0, 90 * 16); |
||||
// Top right
|
||||
painter->drawPie(rect.right() - 10, rect.bottom() - 10, 20, 20, 90 * 16, 90 * 16); |
||||
|
||||
|
||||
// Top left
|
||||
painter->drawPie(rect.left() - 10, rect.top() - 10, 20, 20, 270 * 16, 90 * 16); |
||||
// Top right
|
||||
painter->drawPie(rect.right() - 10, rect.top() - 10, 20, 20, 180 * 16, 90 * 16); |
||||
} |
||||
painter->setBrush(brush()); |
||||
painter->setPen(pen()); |
||||
QGraphicsRectItem::paint(painter, options, widget); |
||||
} |
@ -0,0 +1,16 @@
|
||||
#ifndef SELECTIONRECTANGLE_HPP |
||||
#define SELECTIONRECTANGLE_HPP |
||||
|
||||
#include <QGraphicsRectItem> |
||||
#include <QPainter> |
||||
|
||||
class SelectionRectangle : public QGraphicsRectItem { |
||||
public: |
||||
SelectionRectangle(); |
||||
explicit SelectionRectangle(qreal x, qreal y, qreal w, qreal h, QGraphicsItem *parent = nullptr); |
||||
|
||||
protected: |
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *options, QWidget *widget) override; |
||||
}; |
||||
|
||||
#endif // SELECTIONRECTANGLE_HPP
|
Loading…
Reference in new issue