perfmon/ui/hb/app/src/mainview.cpp
branchRCL_3
changeset 20 fad26422216a
parent 19 b3cee849fa46
child 21 f8280f3bfeb7
equal deleted inserted replaced
19:b3cee849fa46 20:fad26422216a
     1 /*
       
     2 * Copyright (c) 2010 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 
       
    18 #include <QActionGroup>
       
    19 #include <HbApplication>
       
    20 #include <HbMenu>
       
    21 #include <HbToolBar>
       
    22 #include <HbAction>
       
    23 #include <HbMessageBox>
       
    24 #include <HbLabel>
       
    25 
       
    26 #include "mainview.h"
       
    27 #include "enginewrapper.h"
       
    28 
       
    29 
       
    30 // ---------------------------------------------------------------------------
       
    31 
       
    32 MainView::MainView(EngineWrapper &engine) :
       
    33     mEngine(engine),
       
    34     mValueDataContainer(0),
       
    35     mGraphDataContainer(0)
       
    36 {
       
    37     setTitle(tr("Perf. Monitor"));
       
    38     mValueDataContainer = new ValueDataContainer(mEngine, this); 
       
    39     mGraphDataContainer = new GraphDataContainer(mEngine, this);
       
    40     createMenu();
       
    41     showValues();
       
    42 }
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 
       
    46 MainView::~MainView()
       
    47 {
       
    48 }
       
    49 
       
    50 // ---------------------------------------------------------------------------
       
    51 
       
    52 void MainView::createMenu()
       
    53 {
       
    54     HbMenu *menu = this->menu();
       
    55     HbToolBar *toolbar = this->toolBar();
       
    56 
       
    57     if (menu && toolbar) {
       
    58         mSwitchViewAction = new HbAction(toolbar);
       
    59         toolbar->addAction(mSwitchViewAction);
       
    60 
       
    61         QActionGroup *viewGroup = new QActionGroup(this);
       
    62         HbMenu *viewSubmenu = menu->addMenu(tr("View"));
       
    63         mValuesAction = viewSubmenu->addAction(tr("Values"), this, SLOT(showValues()));
       
    64         mValuesAction->setCheckable(true);
       
    65         mValuesAction->setChecked(true);
       
    66         viewGroup->addAction(mValuesAction);
       
    67 
       
    68         mGraphAction = viewSubmenu->addAction(tr("Graphs"), this, SLOT(showGraphs()));
       
    69         mGraphAction->setCheckable(true);
       
    70         viewGroup->addAction(mGraphAction);
       
    71 
       
    72         mLoggingAction = menu->addAction(QString(), this, SLOT(toggleLogging()));
       
    73         toolbar->addAction(mLoggingAction);
       
    74         updateLoggingAction();
       
    75 
       
    76         menu->addAction(tr("Settings..."), this, SIGNAL(settingsCommandInvoked()));
       
    77         menu->addAction(tr("About..."), this, SLOT(showAbout()));
       
    78         menu->addAction(tr("Exit"), qApp, SLOT(quit()));
       
    79 
       
    80     }
       
    81 }
       
    82 
       
    83 void MainView::showValues()
       
    84 {
       
    85     // remove old widget & take ownership
       
    86     takeWidget();
       
    87     mGraphDataContainer->hideContainer();
       
    88     mValueDataContainer->showContainer(); 
       
    89     // set new widget
       
    90     this->setWidget(mValueDataContainer);
       
    91     
       
    92     mValuesAction->setChecked(true);
       
    93 
       
    94     mSwitchViewAction->setText(tr("View Graphs"));
       
    95     disconnect(mSwitchViewAction, SIGNAL(triggered(bool)), this, SLOT(showValues()));
       
    96     connect(mSwitchViewAction, SIGNAL(triggered(bool)), this, SLOT(showGraphs()));
       
    97 }
       
    98 
       
    99 void MainView::showGraphs()
       
   100 {
       
   101     // remove old widget & take ownership
       
   102     takeWidget();
       
   103     mValueDataContainer->hideContainer();    
       
   104     mGraphDataContainer->showContainer();
       
   105     // set new widget
       
   106     this->setWidget(mGraphDataContainer);
       
   107 
       
   108     mGraphAction->setChecked(true);
       
   109 
       
   110     mSwitchViewAction->setText(tr("View Values"));
       
   111     disconnect(mSwitchViewAction, SIGNAL(triggered(bool)), this, SLOT(showGraphs()));
       
   112     connect(mSwitchViewAction, SIGNAL(triggered(bool)), this, SLOT(showValues()));
       
   113 }
       
   114 
       
   115 void MainView::updateLoggingAction()
       
   116 {
       
   117     mLoggingAction->setText(mEngine.settings().loggingEnabled() ?
       
   118                             tr("Stop Logging") :
       
   119                             tr("Start Logging"));
       
   120 }
       
   121 
       
   122 void MainView::toggleLogging()
       
   123 {
       
   124     mEngine.setLoggingEnabled(!mEngine.settings().loggingEnabled());
       
   125     updateLoggingAction();
       
   126 }
       
   127 
       
   128 void MainView::showAbout()
       
   129 {
       
   130     HbMessageBox *messageBox = new HbMessageBox(HbMessageBox::MessageTypeInformation);
       
   131     messageBox->setText("Version 1.1.1 - 21st May 2010. Copyright © 2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. Licensed under Eclipse Public License v1.0.");
       
   132     HbLabel *header = new HbLabel("About PerfMon", messageBox);
       
   133     messageBox->setHeadingWidget(header);
       
   134     messageBox->setAttribute(Qt::WA_DeleteOnClose);
       
   135     messageBox->setTimeout(HbPopup::NoTimeout);
       
   136     messageBox->open();
       
   137 }