|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 #include "trianglewidget.h" |
|
18 #include <QRect> |
|
19 #include <QPainter> |
|
20 #include <QPolygon> |
|
21 |
|
22 |
|
23 trianglewidget::trianglewidget(QGraphicsItem *parent) |
|
24 : figurewidget(parent) |
|
25 { |
|
26 mGridLayout->addItem(mSqure, 2, 0, 1, 1); |
|
27 mGridLayout->addItem(mCircle, 2, 1, 1, 1); |
|
28 |
|
29 mColor = "green"; |
|
30 |
|
31 delete mTriangle; |
|
32 mTriangle = NULL; |
|
33 } |
|
34 |
|
35 trianglewidget::~trianglewidget() |
|
36 { |
|
37 |
|
38 } |
|
39 |
|
40 void trianglewidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
41 { |
|
42 QPolygon polygon; |
|
43 polygon.putPoints(0, 3, 10,300, 150,10, 300,300); |
|
44 painter->setPen(Qt::black); |
|
45 if (mColor == "red") { |
|
46 painter->setBrush(Qt::red); |
|
47 } else if (mColor == "green") { |
|
48 painter->setBrush(Qt::green); |
|
49 } else if (mColor == "blue") { |
|
50 painter->setBrush(Qt::blue); |
|
51 } else { |
|
52 Q_ASSERT(false); |
|
53 } |
|
54 |
|
55 painter->drawPolygon(polygon, Qt::WindingFill); |
|
56 |
|
57 figurewidget::paint(painter, option, widget); |
|
58 } |