utilityapps/launcher/src/outputview.cpp
changeset 55 2d9cac8919d3
parent 26 41ebde60981f
equal deleted inserted replaced
53:819e59dfc032 55:2d9cac8919d3
       
     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 <hbdocumentloader.h>
       
    19 #include <launchermainwindow.h>
       
    20 #include <hbaction.h>
       
    21 #include <hbmenu.h>
       
    22 #include <hbtextedit.h>
       
    23 
       
    24 #include "enginewrapper.h"
       
    25 #include "commonActions.h"
       
    26 #include "outputview.h"
       
    27 
       
    28 // xml definition of view
       
    29 const char *OUTPUTVIEW_XML = ":/xml/outputview.xml";
       
    30 
       
    31 // name of the output view object in the xml file.
       
    32 const char *OUTPUTVIEW = "outputview";
       
    33 const char *ACTIONCLEAR = "actionClearWindow";
       
    34 const char *TEXTOUTPUT = "textEdit";
       
    35 const char *ACTIONOPENAPPLICATIONVIEW = "actionOpenApplicationView";
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 
       
    39 
       
    40 OutputView::OutputView():
       
    41     mActionClear(0),
       
    42     mActionOpenApplicationView(0),
       
    43     mTextOutput(0)
       
    44 {
       
    45 
       
    46 }
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 
       
    50 OutputView::~OutputView()
       
    51 {
       
    52     if(mActionClear)
       
    53         mActionClear->deleteLater();
       
    54     if(mActionOpenApplicationView)
       
    55         mActionOpenApplicationView->deleteLater();
       
    56 }
       
    57 
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 
       
    61 OutputView* OutputView::create(HbDocumentLoader &loader, 
       
    62                         CommonActions *commonActions)
       
    63 {
       
    64     // Load application view from xml-file
       
    65     bool ok = false;
       
    66     loader.load(OUTPUTVIEW_XML, &ok);
       
    67     
       
    68     // Output View:
       
    69     QGraphicsWidget *widget = loader.findWidget(OUTPUTVIEW);
       
    70     Q_ASSERT_X(ok && (widget != 0), "Launcher", "Invalid launcher.xml file");
       
    71     OutputView *outputView = qobject_cast<OutputView *>(widget);
       
    72     
       
    73     // initialize view
       
    74     outputView->init(loader, commonActions);
       
    75     
       
    76     return outputView;
       
    77 }
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 
       
    81 
       
    82 void OutputView::loadItemsFromXml(HbDocumentLoader &loader)
       
    83 {
       
    84 
       
    85     // List widget:
       
    86     QGraphicsWidget *widget = loader.findWidget(TEXTOUTPUT);
       
    87     Q_ASSERT_X((widget != 0), "Launcher", "Invalid launcher.xml file");
       
    88     mTextOutput = qobject_cast<HbTextEdit *>(widget);
       
    89 
       
    90     // clear action:
       
    91     QObject *object= loader.findObject(ACTIONCLEAR);
       
    92     Q_ASSERT_X((object != 0), "Launcher", "Invalid launcher.xml file");
       
    93     mActionClear = qobject_cast<HbAction *>(object);
       
    94     
       
    95     // open output view
       
    96     object= loader.findObject(ACTIONOPENAPPLICATIONVIEW);
       
    97     Q_ASSERT_X((object != 0), "Launcher", "Invalid launcher.xml file");
       
    98     mActionOpenApplicationView = qobject_cast<HbAction *>(object);
       
    99 
       
   100 }
       
   101 
       
   102 // ---------------------------------------------------------------------------
       
   103 
       
   104 
       
   105 void OutputView::init(HbDocumentLoader &loader, CommonActions *commonActions)
       
   106 {
       
   107     loadItemsFromXml(loader);
       
   108     connectSignalsAndSlots();
       
   109 
       
   110     // set text edit components settings
       
   111     mTextOutput->setPlainText("Ready.\n\n");
       
   112     mTextOutput->setReadOnly(true);
       
   113     mTextOutput->setCursorVisibility( Hb::TextCursorHidden );
       
   114     mTextOutput->setAttribute(Qt::WA_InputMethodEnabled, false);
       
   115     
       
   116     // add actions to menu
       
   117     commonActions->addActionsToMenu(menu());
       
   118 
       
   119 }
       
   120 
       
   121 // ---------------------------------------------------------------------------
       
   122 
       
   123 void OutputView::connectSignalsAndSlots()
       
   124 {
       
   125     // Clear action
       
   126     connect(mActionClear, SIGNAL(triggered()), this, SLOT(clearOutput()));
       
   127     connect(mActionOpenApplicationView, SIGNAL(triggered()), this, SLOT(openApplicationView()));
       
   128 }
       
   129 
       
   130 // ---------------------------------------------------------------------------
       
   131 
       
   132 void OutputView::clearOutput()
       
   133 {
       
   134     mTextOutput->setPlainText("");
       
   135 }
       
   136 
       
   137 // ---------------------------------------------------------------------------
       
   138 
       
   139 void OutputView::printText(const QString &text)
       
   140 {
       
   141     QString newText = mTextOutput->toPlainText() + text;
       
   142     mTextOutput->setPlainText(newText);
       
   143     mTextOutput->setCursorPosition(newText.length()-1);
       
   144 }
       
   145 
       
   146 // ---------------------------------------------------------------------------
       
   147 
       
   148 void OutputView::openApplicationView()
       
   149 {
       
   150     qDebug("openApplicationView");
       
   151     LauncherMainWindow *pMainWindow = static_cast< LauncherMainWindow * >( mainWindow() );
       
   152     if( pMainWindow )
       
   153         {
       
   154         pMainWindow->openApplicationView();
       
   155         }
       
   156 }
       
   157 
       
   158 // ---------------------------------------------------------------------------
       
   159