blob: eb97f3a930e27107b4e635cc47e2928e3a7c3217 [file] [log] [blame]
Isa Nanic6e4a39a2018-12-04 14:26:02 -05001/**************************************************************************
2* Copyright (C) 2018 by Savoir-faire Linux *
3* Author: Isa Nanic <isa.nanic@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 <https://www.gnu.org/licenses/>. *
17**************************************************************************/
18
19#include "avatargraphicsview.h"
20
21AvatarGraphicsView::AvatarGraphicsView(QWidget* parent)
22 : QGraphicsView(parent)
23{
24 setDragMode(QGraphicsView::ScrollHandDrag);
25}
26
27void
28AvatarGraphicsView::wheelEvent(QWheelEvent* event)
29{
30 QPoint numSteps = event->angleDelta() / (8*15);
31
32 if (!numSteps.isNull()) {
33 zoomImage(numSteps);
34 }
35 event->accept();
36}
37
38void
39AvatarGraphicsView::zoomImage(const QPoint& steps)
40{
41 steps.y() == 1 ? scale(zoomIncrement_, zoomIncrement_) : scale(1 / zoomIncrement_, 1 / zoomIncrement_);
42}
43
44void
45AvatarGraphicsView::paintEvent(QPaintEvent* e)
46{
47 QGraphicsView::paintEvent(e);
48 QPainter painter(viewport());
49
50 QPainterPath square;
51 QPainterPath circle;
52
53 square.addRect(0, 0, width(), height());
54 circle.addEllipse(QPoint(width() / 2 - 0.5, height() / 2 - 0.5), circleSize_ + 1, circleSize_ + 1);
55
56 painter.setOpacity(0.3);
57
58 painter.fillPath(square.subtracted(circle), QBrush(QColor(Qt::black)));
59}