/*
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:
*
*/
#include "letterwidget.h"
#include <QRect>
#include <QPainter>
#include <QPainterPath>
#include <QPolygon>
#include <hbgridview.h>
#include <QStandardItemModel>
#include <HbScrollArea>
#include <QPalette>
letterwidget::letterwidget(QGraphicsItem *parent)
: HbWidget(parent)
{
HbWidget* widget = new HbWidget;
HbScrollArea* scrollArea = new HbScrollArea;
mItalic = new HbPushButton("Italic");
mBold = new HbPushButton("Bold");
mUnderline = new HbPushButton("Underline");
mRed = new HbPushButton("Red");
mGreen = new HbPushButton("Green");
mBlue = new HbPushButton("Blue");
mSave = new HbPushButton("Save");
mDelete = new HbPushButton("Delete");
mVisibilityLabel = new HbLabel("Visibility");
mVisibilityCombo = new HbComboBox();
mVisibilityCombo->addItem("none");
mVisibilityCombo->addItem("true");
mVisibilityCombo->addItem("false");
mPersistentLabel = new HbLabel("Persistence");
mPersistentCombo = new HbComboBox();
mPersistentCombo->addItem("none");
mPersistentCombo->addItem("true");
mPersistentCombo->addItem("false");
mNameLabel = new HbLabel("Name");
mNameCombo = new HbComboBox();
mNameCombo->addItem("none");
mStatusLabel = new HbLabel("Status");
mResultLabel = new HbLabel;
mSaveDekCheckBox = new HbCheckBox("Delete before Save");
mSaveDekCheckBox->setCheckState(Qt::Checked);
mBackgroundLabel = new HbLabel("Background");
mBackgroundStatusLabel = new HbLabel();
mGridLayout = new QGraphicsGridLayout();
mGridLayout->addItem(mStatusLabel, 0, 0, 1, 1);
mGridLayout->addItem(mResultLabel, 0, 1, 1, 2);
mGridLayout->addItem(mRed, 2, 0, 1, 1);
mGridLayout->addItem(mGreen, 2, 1, 1, 1);
mGridLayout->addItem(mBlue, 2, 2, 1, 1);
mGridLayout->addItem(mSave, 3, 0, 1, 1);
mGridLayout->addItem(mDelete, 3, 1, 1, 1);
mGridLayout->addItem(mVisibilityLabel, 4, 0, 1, 1);
mGridLayout->addItem(mVisibilityCombo, 4, 1, 1, 2);
mGridLayout->addItem(mPersistentLabel, 5, 0, 1, 1);
mGridLayout->addItem(mPersistentCombo, 5, 1, 1, 2);
mGridLayout->addItem(mNameLabel, 6, 0, 1, 1);
mGridLayout->addItem(mNameCombo, 6, 1, 1, 2);
mGridLayout->addItem(mSaveDekCheckBox, 7, 0, 1, 3);
mGridLayout->addItem(mBackgroundLabel, 8, 0, 1, 2);
mGridLayout->addItem(mBackgroundStatusLabel, 8, 2, 1, 1);
widget->setLayout(mGridLayout);
scrollArea->setContentWidget(widget);
scrollArea->setScrollDirections(Qt::Vertical);
scrollArea->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff);
connect(mRed, SIGNAL(released()), this, SLOT(red()));
connect(mGreen, SIGNAL(released()), this, SLOT(green()));
connect(mBlue, SIGNAL(released()), this, SLOT(blue()));
connect(mItalic, SIGNAL(released()), this, SIGNAL(toitalic()));
connect(mBold, SIGNAL(released()), this, SIGNAL(tobold()));
connect(mUnderline, SIGNAL(released()), this, SIGNAL(tounderline()));
connect(mSave, SIGNAL(released()), this, SIGNAL(save()));
connect(mDelete, SIGNAL(released()), this, SIGNAL(del()));
QGraphicsGridLayout* mainLayout = new QGraphicsGridLayout;
mainLayout->addItem(scrollArea, 1, 0, 1, 6);
mainLayout->setRowFixedHeight(0, 200);
setLayout(mainLayout);
setStatus(true);
}
void letterwidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
HbWidget::paint(painter, option, widget);
if (mColor == "red") {
painter->setPen(Qt::red);
} else if (mColor == "green") {
painter->setPen(Qt::green);
} else if (mColor == "blue") {
painter->setPen(Qt::blue);
} else {
Q_ASSERT(false);
}
}
letterwidget::~letterwidget()
{
}
void letterwidget::red()
{
mColor = "red";
update();
}
void letterwidget::green()
{
mColor = "green";
update();
}
void letterwidget::blue()
{
mColor = "blue";
update();
}
void letterwidget::setcolor(const QString &color)
{
mColor = color;
}
QString letterwidget::color()
{
return mColor;
}
QString letterwidget::visibility()
{
return mVisibilityCombo->currentText();
}
QString letterwidget::persistent()
{
return mPersistentCombo->currentText();
}
QString letterwidget::name()
{
return mNameCombo->currentText();
}
void letterwidget::setStatus(bool status)
{
if(status) {
mResultLabel->setTextColor(Qt::green);
mResultLabel->setPlainText("Ok");
} else {
mResultLabel->setTextColor(Qt::red);
mResultLabel->setPlainText("Fail");
}
}
bool letterwidget::delBeforeSave()
{
if (mSaveDekCheckBox->checkState() == Qt::Checked) {
return true;
}
return false;
}
void letterwidget::setBackgroundFlag(bool background)
{
QString mess = "";
if (background) {
mess = "true";
}
mBackgroundStatusLabel->setPlainText(mess);
}