activityfw/testapplications/newtestappset/acttestletter/letterwidget.cpp
changeset 117 c63ee96dbe5f
equal deleted inserted replaced
115:3ab5c078b490 117:c63ee96dbe5f
       
     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 "letterwidget.h"
       
    18 #include <QRect>
       
    19 #include <QPainter>
       
    20 #include <QPainterPath>
       
    21 #include <QPolygon>
       
    22 #include <hbgridview.h>
       
    23 #include <QStandardItemModel>
       
    24 #include <HbScrollArea>
       
    25 #include <QPalette>
       
    26 
       
    27 letterwidget::letterwidget(QGraphicsItem *parent)
       
    28     : HbWidget(parent)
       
    29 {
       
    30     HbWidget* widget = new HbWidget;
       
    31     HbScrollArea* scrollArea = new HbScrollArea; 
       
    32     
       
    33     mItalic = new HbPushButton("Italic");
       
    34     mBold = new HbPushButton("Bold");
       
    35     mUnderline = new HbPushButton("Underline");
       
    36     mRed = new HbPushButton("Red");
       
    37     mGreen = new HbPushButton("Green");
       
    38     mBlue = new HbPushButton("Blue");
       
    39     mSave = new HbPushButton("Save");
       
    40     mDelete = new HbPushButton("Delete");
       
    41     
       
    42     mVisibilityLabel = new HbLabel("Visibility");
       
    43     mVisibilityCombo = new HbComboBox();
       
    44     mVisibilityCombo->addItem("none");
       
    45     mVisibilityCombo->addItem("true");
       
    46     mVisibilityCombo->addItem("false");
       
    47     
       
    48     mPersistentLabel = new HbLabel("Persistence");
       
    49     mPersistentCombo = new HbComboBox();
       
    50     mPersistentCombo->addItem("none");
       
    51     mPersistentCombo->addItem("true");
       
    52     mPersistentCombo->addItem("false");
       
    53     
       
    54     mNameLabel = new HbLabel("Name");
       
    55     mNameCombo = new HbComboBox();
       
    56     mNameCombo->addItem("none");    
       
    57     
       
    58     mStatusLabel = new HbLabel("Status");
       
    59     mResultLabel = new HbLabel;
       
    60     
       
    61     mSaveDekCheckBox = new HbCheckBox("Delete before Save");
       
    62     mSaveDekCheckBox->setCheckState(Qt::Checked);
       
    63     
       
    64     mBackgroundLabel = new HbLabel("Background");
       
    65     mBackgroundStatusLabel = new HbLabel();
       
    66     
       
    67     mGridLayout = new QGraphicsGridLayout();
       
    68     mGridLayout->addItem(mStatusLabel, 0, 0, 1, 1);
       
    69     mGridLayout->addItem(mResultLabel, 0, 1, 1, 2);
       
    70     mGridLayout->addItem(mRed, 2, 0, 1, 1);
       
    71     mGridLayout->addItem(mGreen, 2, 1, 1, 1);
       
    72     mGridLayout->addItem(mBlue, 2, 2, 1, 1);
       
    73     mGridLayout->addItem(mSave, 3, 0, 1, 1);
       
    74     mGridLayout->addItem(mDelete, 3, 1, 1, 1);
       
    75     mGridLayout->addItem(mVisibilityLabel, 4, 0, 1, 1);
       
    76     mGridLayout->addItem(mVisibilityCombo, 4, 1, 1, 2);
       
    77     mGridLayout->addItem(mPersistentLabel, 5, 0, 1, 1);
       
    78     mGridLayout->addItem(mPersistentCombo, 5, 1, 1, 2);
       
    79     mGridLayout->addItem(mNameLabel, 6, 0, 1, 1);
       
    80     mGridLayout->addItem(mNameCombo, 6, 1, 1, 2);
       
    81     mGridLayout->addItem(mSaveDekCheckBox, 7, 0, 1, 3);
       
    82     mGridLayout->addItem(mBackgroundLabel, 8, 0, 1, 2);
       
    83     mGridLayout->addItem(mBackgroundStatusLabel, 8, 2, 1, 1);
       
    84     
       
    85     widget->setLayout(mGridLayout);
       
    86     
       
    87     scrollArea->setContentWidget(widget);
       
    88     scrollArea->setScrollDirections(Qt::Vertical);
       
    89     scrollArea->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff);
       
    90 
       
    91     connect(mRed, SIGNAL(released()), this, SLOT(red()));
       
    92     connect(mGreen, SIGNAL(released()), this, SLOT(green()));
       
    93     connect(mBlue, SIGNAL(released()), this, SLOT(blue()));
       
    94 
       
    95     connect(mItalic, SIGNAL(released()), this, SIGNAL(toitalic()));
       
    96     connect(mBold, SIGNAL(released()), this, SIGNAL(tobold()));
       
    97     connect(mUnderline, SIGNAL(released()), this, SIGNAL(tounderline()));
       
    98 
       
    99     connect(mSave, SIGNAL(released()), this, SIGNAL(save()));
       
   100     connect(mDelete, SIGNAL(released()), this, SIGNAL(del()));
       
   101     
       
   102     QGraphicsGridLayout* mainLayout = new QGraphicsGridLayout;
       
   103     mainLayout->addItem(scrollArea, 1, 0, 1, 6);
       
   104     mainLayout->setRowFixedHeight(0, 200);
       
   105     setLayout(mainLayout);
       
   106     
       
   107     setStatus(true);
       
   108     
       
   109 }
       
   110 
       
   111 void letterwidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
       
   112 {
       
   113     HbWidget::paint(painter, option, widget);
       
   114 
       
   115     if (mColor == "red") {
       
   116         painter->setPen(Qt::red);
       
   117     } else if (mColor == "green") {
       
   118         painter->setPen(Qt::green);
       
   119     } else if (mColor == "blue") {
       
   120         painter->setPen(Qt::blue);
       
   121     } else {
       
   122         Q_ASSERT(false);
       
   123     }
       
   124 }
       
   125 
       
   126 letterwidget::~letterwidget()
       
   127 {
       
   128 }
       
   129 
       
   130 
       
   131 void letterwidget::red()
       
   132 {
       
   133     mColor = "red";
       
   134     update();
       
   135 }
       
   136 
       
   137 void letterwidget::green()
       
   138 {
       
   139     mColor = "green";
       
   140     update();
       
   141 }
       
   142 
       
   143 void letterwidget::blue()
       
   144 {
       
   145     mColor = "blue";
       
   146     update();
       
   147 }
       
   148 
       
   149 void letterwidget::setcolor(const QString &color)
       
   150 {
       
   151     mColor = color;
       
   152 }
       
   153 
       
   154 QString letterwidget::color()
       
   155 {
       
   156     return mColor;
       
   157 }
       
   158 
       
   159 QString letterwidget::visibility()
       
   160 {
       
   161     return mVisibilityCombo->currentText();
       
   162 }
       
   163 
       
   164 QString letterwidget::persistent()
       
   165 {
       
   166 	return mPersistentCombo->currentText();
       
   167 }
       
   168 
       
   169 QString letterwidget::name()
       
   170 {
       
   171     return mNameCombo->currentText();
       
   172 }
       
   173 
       
   174 void letterwidget::setStatus(bool status)
       
   175 {    
       
   176     if(status) {        
       
   177         mResultLabel->setTextColor(Qt::green);
       
   178         mResultLabel->setPlainText("Ok");
       
   179     } else {
       
   180         mResultLabel->setTextColor(Qt::red);
       
   181         mResultLabel->setPlainText("Fail");
       
   182     }
       
   183     
       
   184 }
       
   185 
       
   186 bool letterwidget::delBeforeSave()
       
   187 {
       
   188     if (mSaveDekCheckBox->checkState() == Qt::Checked) {
       
   189         return true;
       
   190     }
       
   191     return false;
       
   192 }
       
   193 
       
   194 void letterwidget::setBackgroundFlag(bool background)
       
   195 {
       
   196     QString mess = "";
       
   197     if (background) {
       
   198         mess = "true";
       
   199     }    
       
   200     mBackgroundStatusLabel->setPlainText(mess);
       
   201 }