|
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 "figurewidget.h" |
|
18 #include <QRect> |
|
19 #include <QPainter> |
|
20 #include <QPainterPath> |
|
21 #include <QPolygon> |
|
22 #include <HbCheckBox> |
|
23 #include <HbScrollArea> |
|
24 |
|
25 figurewidget::figurewidget(QGraphicsItem *parent) |
|
26 : HbWidget(parent), mFailed(false) |
|
27 { |
|
28 HbWidget* widget = new HbWidget; |
|
29 HbScrollArea* scrollArea = new HbScrollArea; |
|
30 mTriangle = new HbPushButton("Triangle"); |
|
31 mSqure = new HbPushButton("Squre"); |
|
32 mCircle = new HbPushButton("Circle"); |
|
33 mRed = new HbPushButton("Red"); |
|
34 mGreen = new HbPushButton("Green"); |
|
35 mBlue = new HbPushButton("Blue"); |
|
36 mSave = new HbPushButton("Save"); |
|
37 mDelete = new HbPushButton("Delete"); |
|
38 mVisibilityLabel = new HbLabel("Visibility"); |
|
39 mVisibilityCombo = new HbComboBox(); |
|
40 mVisibilityCombo->addItem("none"); |
|
41 mVisibilityCombo->addItem("true"); |
|
42 mVisibilityCombo->addItem("false"); |
|
43 |
|
44 mPersistentLabel = new HbLabel("Persistence"); |
|
45 mPersistentCombo = new HbComboBox(); |
|
46 mPersistentCombo->addItem("none"); |
|
47 mPersistentCombo->addItem("true"); |
|
48 mPersistentCombo->addItem("false"); |
|
49 |
|
50 mNameLabel = new HbLabel("Name"); |
|
51 mNameCombo = new HbComboBox(); |
|
52 mNameCombo->addItem("none"); |
|
53 |
|
54 mSaveDekCheckBox = new HbCheckBox("Delete before Save"); |
|
55 mSaveDekCheckBox->setCheckState(Qt::Unchecked); |
|
56 mGridLayout = new QGraphicsGridLayout(); |
|
57 mGridLayout->addItem(mRed, 0, 0, 1, 1); |
|
58 mGridLayout->addItem(mGreen, 0, 1, 1, 1); |
|
59 mGridLayout->addItem(mBlue, 0, 2, 1, 1); |
|
60 mGridLayout->addItem(mSave, 2, 0, 1, 1); |
|
61 mGridLayout->addItem(mDelete, 2, 2, 1, 1); |
|
62 mGridLayout->addItem(mVisibilityLabel, 3, 0, 1, 1); |
|
63 mGridLayout->addItem(mVisibilityCombo, 3, 1, 1, 2); |
|
64 mGridLayout->addItem(mPersistentLabel, 4, 0, 1, 1); |
|
65 mGridLayout->addItem(mPersistentCombo, 4, 1, 1, 2); |
|
66 mGridLayout->addItem(mNameLabel, 5, 0, 1, 1); |
|
67 mGridLayout->addItem(mNameCombo, 5, 1, 1, 2); |
|
68 mGridLayout->addItem(mSaveDekCheckBox, 6, 0, 1, 3); |
|
69 |
|
70 widget->setLayout(mGridLayout); |
|
71 |
|
72 scrollArea->setContentWidget(widget); |
|
73 scrollArea->setScrollDirections(Qt::Vertical); |
|
74 scrollArea->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff); |
|
75 |
|
76 connect(mRed, SIGNAL(released()), this, SLOT(red())); |
|
77 connect(mGreen, SIGNAL(released()), this, SLOT(green())); |
|
78 connect(mBlue, SIGNAL(released()), this, SLOT(blue())); |
|
79 |
|
80 connect(mTriangle, SIGNAL(released()), this, SIGNAL(totriangle())); |
|
81 connect(mSqure, SIGNAL(released()), this, SIGNAL(tosqure())); |
|
82 connect(mCircle, SIGNAL(released()), this, SIGNAL(tocircle())); |
|
83 |
|
84 connect(mSave, SIGNAL(released()), this, SIGNAL(save())); |
|
85 connect(mDelete, SIGNAL(released()), this, SIGNAL(del())); |
|
86 |
|
87 connect(mRed, SIGNAL(released()), this, SLOT(clearFailedFlag())); |
|
88 connect(mGreen, SIGNAL(released()), this, SLOT(clearFailedFlag())); |
|
89 connect(mBlue, SIGNAL(released()), this, SLOT(clearFailedFlag())); |
|
90 connect(mSqure, SIGNAL(released()), this, SLOT(clearFailedFlag())); |
|
91 connect(mTriangle, SIGNAL(released()), this, SLOT(clearFailedFlag())); |
|
92 |
|
93 QGraphicsGridLayout* mainLayout = new QGraphicsGridLayout; |
|
94 mainLayout->addItem(scrollArea, 1, 0, 1, 6); |
|
95 mainLayout->setRowFixedHeight(0, 250); |
|
96 setLayout(mainLayout); |
|
97 } |
|
98 |
|
99 figurewidget::~figurewidget() |
|
100 { |
|
101 } |
|
102 |
|
103 void figurewidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
104 { |
|
105 HbWidget::paint(painter, option, widget); |
|
106 |
|
107 if ( mFailed ) { |
|
108 painter->setPen(Qt::gray); |
|
109 QFont font; |
|
110 font.setPointSize(38); |
|
111 font.setBold(true); |
|
112 painter->setFont(font); |
|
113 painter->drawText(10, 120, "*FAIL*"); |
|
114 } |
|
115 } |
|
116 |
|
117 |
|
118 void figurewidget::red() |
|
119 { |
|
120 mColor = "red"; |
|
121 update(); |
|
122 } |
|
123 |
|
124 void figurewidget::green() |
|
125 { |
|
126 mColor = "green"; |
|
127 update(); |
|
128 } |
|
129 |
|
130 void figurewidget::blue() |
|
131 { |
|
132 mColor = "blue"; |
|
133 update(); |
|
134 } |
|
135 |
|
136 void figurewidget::setcolor(const QString &color) |
|
137 { |
|
138 mColor = color; |
|
139 } |
|
140 |
|
141 QString figurewidget::color() |
|
142 { |
|
143 return mColor; |
|
144 } |
|
145 |
|
146 void figurewidget::clearFailedFlag() |
|
147 { |
|
148 mFailed = false; |
|
149 update(); |
|
150 } |
|
151 |
|
152 void figurewidget::setFailedFlag() |
|
153 { |
|
154 mFailed = true; |
|
155 update(); |
|
156 } |
|
157 |
|
158 QString figurewidget::visibility() |
|
159 { |
|
160 return mVisibilityCombo->currentText(); |
|
161 } |
|
162 |
|
163 QString figurewidget::persistent() |
|
164 { |
|
165 return mPersistentCombo->currentText(); |
|
166 } |
|
167 |
|
168 QString figurewidget::name() |
|
169 { |
|
170 return mNameCombo->currentText(); |
|
171 } |
|
172 |
|
173 |
|
174 bool figurewidget::delBeforeSave() |
|
175 { |
|
176 if (mSaveDekCheckBox->checkState() == Qt::Checked) { |
|
177 return true; |
|
178 } |
|
179 return false; |
|
180 } |