screengrabber/src/mainview.cpp
changeset 55 2d9cac8919d3
parent 53 819e59dfc032
child 56 392f7045e621
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 <hbview.h>
       
    19 #include <hbmainwindow.h>
       
    20 #include <hbapplication.h>
       
    21 #include <hblabel.h>
       
    22 #include <hbmenu.h>
       
    23 #include <hbaction.h>
       
    24 #include <hbtextedit.h>
       
    25 #include <hbmessagebox.h>
       
    26 #include <qgraphicslinearlayout.h>
       
    27 #include "enginewrapper.h"
       
    28 #include "settingsview.h"
       
    29 #include "mainview.h"
       
    30 #include "notifications.h"
       
    31 #include "hbtoolbar.h"
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 
       
    35 MainView::MainView(HbMainWindow &mainWindow, EngineWrapper &engineWrapper):
       
    36     mMainWindow(mainWindow),
       
    37     mSettingsView(0),
       
    38     mEngineWrapper(engineWrapper)
       
    39 {
       
    40 }
       
    41 
       
    42 // ---------------------------------------------------------------------------
       
    43 
       
    44 MainView::~MainView()
       
    45 {
       
    46 }
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 
       
    50 void MainView::init(HbApplication &app)
       
    51 {
       
    52     this->setTitle("Screen Grabber");
       
    53     createMenu(app);
       
    54     createInfoText();
       
    55     createToolbar();
       
    56 
       
    57 }
       
    58 
       
    59 void MainView::createMenu(HbApplication& app)
       
    60 {
       
    61     
       
    62     HbMenu* menu = this->menu();
       
    63    
       
    64     if (menu != NULL) {
       
    65     
       
    66         actionSendToBg = menu->addAction("Send to background");
       
    67         connect(actionSendToBg, SIGNAL( triggered() ), this, SLOT( sendToBackground() ) );
       
    68         
       
    69         actionSettings = menu->addAction("Settings");
       
    70         connect(actionSettings, SIGNAL( triggered() ), this, SLOT( showSettings() ) );
       
    71     
       
    72         actionAbout = menu->addAction("About");
       
    73         connect(actionAbout, SIGNAL( triggered() ), this, SLOT( showAboutPopup() ) );
       
    74     
       
    75         actionExit = menu->addAction("Exit");
       
    76         connect(actionExit, SIGNAL(triggered()), this, SLOT( my_quit() ) );
       
    77 
       
    78 		HbAction *mDefaultNavigationAction = new HbAction(Hb::QuitNaviAction, this);
       
    79 		connect(mDefaultNavigationAction,SIGNAL(triggered()), this, SLOT(my_quit()));
       
    80 		setNavigationAction(mDefaultNavigationAction);
       
    81         
       
    82     	//setNavigationAction(actionExit);
       
    83     }
       
    84 }
       
    85 
       
    86 
       
    87 void MainView::quitYesNoQuestionClosed(HbAction* action)
       
    88     {
       
    89     HbMessageBox *dlg = static_cast<HbMessageBox*>(sender());
       
    90     if(action == dlg->primaryAction())
       
    91         {
       
    92         qApp->quit(); 
       
    93         }
       
    94     }
       
    95 
       
    96 void MainView::my_quit()
       
    97     {
       
    98 	HbMessageBox::question("Do you really want to exit the Screen Grabber application?", 
       
    99 	    this, //receiver
       
   100 	    SLOT(quitYesNoQuestionClosed(HbAction *)), //member
       
   101 	    tr("Yes"), //primaryButtonText
       
   102 	    tr("No"), //secondaryButtonText
       
   103 	    new HbLabel("Exit Screen grabber confirm", this)
       
   104         );
       
   105 	}
       
   106 
       
   107 // ---------------------------------------------------------------------------
       
   108 
       
   109 void MainView::createInfoText()
       
   110 {
       
   111     QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Vertical, this);
       
   112     if (layout != NULL) {
       
   113         HbTextEdit* edit = new HbTextEdit(this);
       
   114         if(edit != NULL) {
       
   115             edit->setPlainText("Please use the settings screen to define the "
       
   116                                "capture mode and any other related settings "
       
   117                                "such as capture hotkey and saving format. "
       
   118                                "Using the PNG format for screen shots is "
       
   119                                "recommended, since it is compressed but "
       
   120                                "lossless. The captures can be managed with "
       
   121                                "the Media Gallery application.\n\nYou may "
       
   122                                "start taking screenshots or capturing video "
       
   123                                "now. Please press the Applications key to go back "
       
   124                                "to the Application menu or send this application "
       
   125                                "to the background via the Options menu. To be "
       
   126                                "able to take screenshots or capture video, this "
       
   127                                "application needs to stay running in the "
       
   128                                "background.");
       
   129             edit->setReadOnly(true);
       
   130             //TODO edit->setCursorHidden(true);
       
   131             //TODO edit->setAttribute(Qt::WA_InputMethodEnabled, false);
       
   132             layout->addItem(edit);
       
   133             layout->setContentsMargins(5, 5, 5, 5);
       
   134             this->setLayout(layout);
       
   135         }
       
   136         
       
   137     }
       
   138     
       
   139 }
       
   140 
       
   141 // ---------------------------------------------------------------------------
       
   142 
       
   143 void MainView::showSettings()
       
   144 {
       
   145     mEngineWrapper.EnableRcpOfFoc(ETrue);
       
   146 	mEngineWrapper.LoadSettings();	
       
   147 	mSettingsView->loadSettings();
       
   148 	mMainWindow.setCurrentView(mSettingsView);
       
   149 }
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 
       
   153 void MainView::createToolbar()
       
   154 {
       
   155     HbToolBar *toolbar = new HbToolBar(this); // main view takes the ownership
       
   156     toolbar->addAction(actionSettings);
       
   157     toolbar->addAction(actionSendToBg);
       
   158     setToolBar(toolbar);
       
   159 }
       
   160 
       
   161 // ---------------------------------------------------------------------------
       
   162 
       
   163 void MainView::showAboutPopup()
       
   164 {
       
   165     Notifications::about();
       
   166 }
       
   167 
       
   168 // ---------------------------------------------------------------------------
       
   169 
       
   170 void MainView::sendToBackground()
       
   171     {
       
   172     mEngineWrapper.sendUIToBackground();
       
   173     }
       
   174 
       
   175