stifui/qt/src/dlgoutput.cpp
branchRCL_3
changeset 9 404ad6c9bc20
child 12 aefcba28a3e0
equal deleted inserted replaced
8:87e9ebfbe96a 9:404ad6c9bc20
       
     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 #include "dlgoutput.h"
       
    18 #include <QtGui>
       
    19 
       
    20 DlgOutput::DlgOutput(IStfQtUIController* ctl, QWidget *parent) :
       
    21     QDialog(parent), controller(ctl)
       
    22     {
       
    23     QSize btnSize(100,30);
       
    24     QGridLayout *mainLayout = new QGridLayout(this);
       
    25     this->setLayout(mainLayout);
       
    26     this->setContextMenuPolicy(Qt::NoContextMenu);
       
    27 
       
    28     tabMain = new QTabWidget();
       
    29     tabMain->setContextMenuPolicy(Qt::NoContextMenu);
       
    30 
       
    31     QWidget *toolWidget = new QWidget(this);
       
    32     toolWidget->setContextMenuPolicy(Qt::NoContextMenu);
       
    33     QGridLayout *toolLayout = new QGridLayout();
       
    34     toolWidget->setLayout(toolLayout);
       
    35     btnPause = new QPushButton(tr("Pause"), toolWidget);
       
    36     btnPause->setContextMenuPolicy(Qt::NoContextMenu);
       
    37     btnPause->setFixedSize(btnSize);
       
    38     QObject::connect(btnPause, SIGNAL(clicked()), this,
       
    39             SLOT(on_btnPause_clicked()));
       
    40     btnAbort = new QPushButton(tr("Abort"), toolWidget);
       
    41     btnAbort->setContextMenuPolicy(Qt::NoContextMenu);
       
    42     btnAbort->setFixedSize(btnSize);
       
    43     QObject::connect(btnAbort, SIGNAL(clicked()), this,
       
    44             SLOT(on_btnAbort_clicked()));
       
    45     toolLayout->addWidget(btnPause, 0, 0);
       
    46     toolLayout->addWidget(btnAbort, 0, 1);
       
    47 
       
    48     mainLayout->addWidget(toolWidget, 0, 0);
       
    49     mainLayout->addWidget(tabMain, 1, 0);
       
    50     controller->AddStfEventListener(this);
       
    51     }
       
    52 
       
    53 DlgOutput::~DlgOutput()
       
    54     {
       
    55     controller->RemoveStfEventListener(this);
       
    56     }
       
    57 
       
    58 void DlgOutput::CreateItem(QString index, QString item)
       
    59     {
       
    60     QPlainTextEdit* edit = new QPlainTextEdit(this);
       
    61     edit->setContextMenuPolicy(Qt::NoContextMenu);
       
    62     tabMain->addTab(edit, item);
       
    63     tabList.insert(index, edit);
       
    64     }
       
    65 
       
    66 void DlgOutput::CloseItem(QString index)
       
    67     {
       
    68     int u = tabList.keys().indexOf(index);
       
    69     tabList.remove(index);
       
    70     tabMain->removeTab(u);
       
    71     if (tabMain->count() == 0)
       
    72         {
       
    73         this->close();
       
    74         }
       
    75     }
       
    76 
       
    77 void DlgOutput::ShowMessage(QString index, QString msg)
       
    78     {
       
    79     if(tabList.contains(index))
       
    80         {
       
    81         tabList.value(index)->setPlainText(msg);    
       
    82         }
       
    83     }
       
    84 
       
    85 void DlgOutput::on_btnPause_clicked()
       
    86     {
       
    87     if (btnPause->text() == "Pause")
       
    88         {
       
    89         controller->PauseCase();
       
    90         btnPause->setText(tr("Resume"));
       
    91         }
       
    92     else
       
    93         {
       
    94         controller->ResumeCase();
       
    95         btnPause->setText(tr("Pause"));
       
    96         }
       
    97     }
       
    98 
       
    99 void DlgOutput::on_btnAbort_clicked()
       
   100     {
       
   101     controller->AbortCase();
       
   102     }
       
   103 
       
   104 void DlgOutput::OnCaseOutputChanged(const IStfEventListener::CaseOutputCommand& cmd,
       
   105         const QString& index, const QString& msg)
       
   106     {
       
   107     this->showMaximized();
       
   108     switch (cmd)
       
   109         {
       
   110         case IStfEventListener::ECreate:
       
   111             CreateItem(index, msg);
       
   112             break;
       
   113         case IStfEventListener::EClose:
       
   114             CloseItem(index);
       
   115             break;
       
   116         default:
       
   117             ShowMessage(index, msg);
       
   118             break;
       
   119         }
       
   120 
       
   121     }
       
   122