|
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, 1, 0, 1, 1); |
|
27 mGridLayout->addItem(mCircle, 1, 1, 1, 1); |
|
28 |
|
29 mColor = "green"; |
|
30 mNameCombo->addItem("Triangle"); |
|
31 |
|
32 delete mTriangle; |
|
33 mTriangle = NULL; |
|
34 } |
|
35 |
|
36 trianglewidget::~trianglewidget() |
|
37 { |
|
38 |
|
39 } |
|
40 |
|
41 void trianglewidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
42 { |
|
43 QPolygon polygon; |
|
44 polygon.putPoints(0, 3, 10,300, 150,10, 300,300); |
|
45 painter->setPen(Qt::black); |
|
46 if (mColor == "red") { |
|
47 painter->setBrush(Qt::red); |
|
48 } else if (mColor == "green") { |
|
49 painter->setBrush(Qt::green); |
|
50 } else if (mColor == "blue") { |
|
51 painter->setBrush(Qt::blue); |
|
52 } else { |
|
53 Q_ASSERT(false); |
|
54 } |
|
55 |
|
56 painter->drawPolygon(polygon, Qt::WindingFill); |
|
57 |
|
58 figurewidget::paint(painter, option, widget); |
|
59 } |