-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdot.cpp
91 lines (85 loc) · 3.02 KB
/
dot.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/***************************************************************************
* Copyright (C) 2011 by Daniel 'gordonc64' Gorazdowski *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "dot.h"
#include <QGraphicsScene>
#include <QGraphicsSceneMouseEvent>
#include <QPainter>
dot::dot()
{
setFlags ( ItemIsMovable | ItemIsSelectable );
setZValue ( 1 );
flaga = 0;
}
dot::~dot()
{
}
QRectF dot::boundingRect() const
{
qreal adjust = 5;
return QRectF ( -2 - adjust, -2 - adjust,
6 + adjust, 6 + adjust );
}
void dot::movable()
{
}
void dot::paint ( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget )
{
Q_UNUSED ( widget );
painter->setPen ( Qt::NoPen );
painter->setBrush ( Qt::darkGray );
painter->drawEllipse ( -1, -1, 5, 5 );
QRadialGradient gradient ( -3, -3, 10 );
if( this->isSelected() )
{
if ( option->state & QStyle::State_Sunken )
{
gradient.setCenter ( 3, 3 );
gradient.setFocalPoint ( 3, 3 );
gradient.setColorAt ( 1, QColor ( Qt::green ).light ( 100 ) );
gradient.setColorAt ( 0, QColor ( Qt::darkGreen ).light ( 100 ) );
}
else
{
gradient.setColorAt ( 0, Qt::green );
gradient.setColorAt ( 1, Qt::darkGreen );
}
}
else
{
if ( option->state & QStyle::State_Sunken )
{
gradient.setCenter ( 3, 3 );
gradient.setFocalPoint ( 3, 3 );
gradient.setColorAt ( 1, QColor ( Qt::yellow ).light ( 100 ) );
gradient.setColorAt ( 0, QColor ( Qt::darkYellow ).light ( 100 ) );
}
else
{
gradient.setColorAt ( 0, Qt::yellow );
gradient.setColorAt ( 1, Qt::darkYellow );
}
}
painter->setBrush ( gradient );
painter->setPen ( QPen ( Qt::black, 0 ) );
painter->drawEllipse ( -2, -2, 6, 6 );
painter->scale ( 1.0,-1.0 );
painter->setFont(QFont("Arial", 14));
painter->drawText(0,10,message);
}