stifui/qt/src/dlgrepeatrun.cpp
branchRCL_3
changeset 43 48060abbbeaf
parent 42 d40e813b23c0
child 45 b3cee849fa46
equal deleted inserted replaced
42:d40e813b23c0 43:48060abbbeaf
     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: QT C++ based Class.
       
    15  * 
       
    16  */
       
    17 
       
    18 #include "dlgrepeatrun.h"
       
    19 #include <QtGui>
       
    20 
       
    21 DlgRepeatRun::DlgRepeatRun(QWidget *parent)
       
    22     : QDialog(parent),
       
    23       loopTimes(0),
       
    24       isInfinite(true)
       
    25     {
       
    26     SetupUI();
       
    27     }
       
    28 
       
    29 void DlgRepeatRun::SetupUI()
       
    30     {
       
    31     this->setContextMenuPolicy(Qt::NoContextMenu);
       
    32     QGridLayout *mainLayout = new QGridLayout(this);
       
    33     this->setLayout(mainLayout);
       
    34     
       
    35     //nullWidget is just place holder for better looking.
       
    36     QWidget *nullWidget = new QWidget(this);
       
    37     nullWidget->setMinimumHeight(30);
       
    38     mainLayout->addWidget(nullWidget, 0, 0);
       
    39     
       
    40     // check box LoopInfinitely
       
    41     rdoLoopInfinitely = new QRadioButton(this);
       
    42     rdoLoopInfinitely->setMinimumHeight(40);
       
    43     rdoLoopInfinitely->setText(tr("Repeat infinitely."));
       
    44     rdoLoopInfinitely->setChecked(Qt::Checked);
       
    45     QObject::connect(rdoLoopInfinitely, SIGNAL(clicked(bool)), this,
       
    46                 SLOT(on_rdoLoopInfinitely_stateChanged(bool)));
       
    47     
       
    48 
       
    49     // check box LoopTime
       
    50     rdoGiveLoopTimes = new QRadioButton(this);
       
    51     rdoGiveLoopTimes->setMinimumHeight(40);
       
    52     rdoGiveLoopTimes->setText(tr("Give loop times:"));
       
    53     rdoGiveLoopTimes->setChecked(Qt::Unchecked);
       
    54     QObject::connect(rdoGiveLoopTimes, SIGNAL(clicked(bool)), this,
       
    55                 SLOT(on_rdoGiveLoopTimes_stateChanged(bool)));
       
    56     
       
    57     // lineEdit, 
       
    58     QValidator *validator = new QIntValidator(1, 999999, this); 
       
    59     lineEdit = new QLineEdit(this);
       
    60     lineEdit->setValidator(validator);
       
    61     lineEdit->setMinimumHeight(40);
       
    62     lineEdit->setMaxLength(6);
       
    63     lineEdit->setMaximumWidth(60);
       
    64     lineEdit->setEchoMode(QLineEdit::NoEcho);
       
    65     lineEdit->setReadOnly(true);
       
    66     
       
    67     // add check box and lineEdit to layout. 
       
    68     QWidget *toolWidgetForLoopTimes = new QWidget(this);
       
    69     QGridLayout *toolLayoutForLoopTimes = new QGridLayout(this);
       
    70     toolWidgetForLoopTimes->setLayout(toolLayoutForLoopTimes);
       
    71     toolLayoutForLoopTimes->addWidget(rdoLoopInfinitely, 0, 0);
       
    72     toolLayoutForLoopTimes->addWidget(rdoGiveLoopTimes, 1, 0);
       
    73     toolLayoutForLoopTimes->addWidget(lineEdit, 1, 1);
       
    74     mainLayout->addWidget(toolWidgetForLoopTimes, 1, 0);
       
    75     
       
    76     // add button
       
    77     QWidget *toolWidgetForButtons = new QWidget(this);
       
    78     QGridLayout *toolLayoutForButtons = new QGridLayout(this);
       
    79     toolWidgetForButtons->setLayout(toolLayoutForButtons);
       
    80     btnOk = new QPushButton(tr("Ok"), toolWidgetForButtons);
       
    81     QObject::connect(btnOk, SIGNAL(clicked()), this,
       
    82             SLOT(on_btnOk_clicked()));
       
    83     btnCancel = new QPushButton(tr("Cancel"), toolWidgetForButtons);
       
    84     QObject::connect(btnCancel, SIGNAL(clicked()), this,
       
    85             SLOT(on_btnCancel_clicked()));
       
    86     toolLayoutForButtons->addWidget(btnOk, 0, 0);
       
    87     toolLayoutForButtons->addWidget(btnCancel, 0, 1);
       
    88     mainLayout->addWidget(toolWidgetForButtons, 2, 0);
       
    89     }
       
    90 
       
    91 void DlgRepeatRun::on_btnOk_clicked()
       
    92     {
       
    93     if(!isRepeatInfinitely())
       
    94         {
       
    95         loopTimes = lineEdit->text().toInt();
       
    96         if (loopTimes < 0)
       
    97             {
       
    98             loopTimes = 0;
       
    99             }
       
   100         }
       
   101     else
       
   102         {
       
   103         loopTimes = 0;
       
   104         }
       
   105     this->accept();
       
   106     }
       
   107 
       
   108 void DlgRepeatRun::on_btnCancel_clicked()
       
   109     {
       
   110     this->reject();    
       
   111     }
       
   112 
       
   113 void DlgRepeatRun::on_rdoLoopInfinitely_stateChanged(bool checked)
       
   114     {
       
   115     if(checked)
       
   116         {
       
   117         isInfinite = true;
       
   118         lineEdit->setEchoMode(QLineEdit::NoEcho);
       
   119         lineEdit->setReadOnly(true);
       
   120         }
       
   121     }
       
   122 
       
   123 void DlgRepeatRun::on_rdoGiveLoopTimes_stateChanged(bool checked)
       
   124     {
       
   125     if(checked)
       
   126         {
       
   127         isInfinite = false;
       
   128         lineEdit->setEchoMode(QLineEdit::Normal); 
       
   129         lineEdit->setReadOnly(false);
       
   130         }
       
   131     }
       
   132 
       
   133 // End of File