-
Notifications
You must be signed in to change notification settings - Fork 0
/
cornergrabber.cpp
57 lines (43 loc) · 1.46 KB
/
cornergrabber.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* The MIT License (MIT)
* Copyright (c) 2017-2018 Kirill Lebedev
**/
#include "cornergrabber.h"
#include <QPainter>
CornerGrabber::CornerGrabber(QGraphicsItem *parent, int corner) : QGraphicsItem(parent), _outterborderColor(Qt::black), _outterborderPen(), _corner(corner) {
setParentItem(parent);
_outterborderPen.setWidth(2);
_outterborderPen.setColor(_outterborderColor);
this->setAcceptHoverEvents(true);
}
void CornerGrabber::setMouseState(KMouse s) {
_mouseButtonState = s;
}
CornerGrabber::KMouse CornerGrabber::getMouseState() const {
return _mouseButtonState;
}
int CornerGrabber::getCorner() const {
return _corner;
}
void CornerGrabber::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
_outterborderColor = Qt::black;
this->update(0, 0, _width, _height);
}
void CornerGrabber::hoverEnterEvent(QGraphicsSceneHoverEvent *) {
_outterborderColor = Qt::red;
this->update(0, 0, _width, _height);
}
QRectF CornerGrabber::boundingRect() const {
return QRectF(0, 0, _width, _height);
}
void CornerGrabber::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) {
_outterborderPen.setCapStyle(Qt::SquareCap);
_outterborderPen.setStyle(Qt::SolidLine);
painter->setPen(_outterborderPen);
QPointF topLeft(0, 0);
QPointF bottomRight(_width, _height);
QRectF rect(topLeft, bottomRight);
QBrush brush(Qt::SolidPattern);
brush.setColor(_outterborderColor);
painter->fillRect(rect, brush);
}