browsercore/appfw/Api/Views/ThumbnailView.cpp
branchGCC_SURGE
changeset 8 2e16851ffecd
parent 2 bf4420e9fa4d
parent 6 1c3b8676e58c
equal deleted inserted replaced
2:bf4420e9fa4d 8:2e16851ffecd
     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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "WrtPageManager.h"
       
    21 #include "ThumbnailView_p.h"
       
    22 #include "ThumbnailView.h"
       
    23 #include "TnEngineHandler.h"
       
    24 #include "TnEngineView.h"
       
    25 #include "wrtbrowsercontainer.h"
       
    26 
       
    27 #include <QDebug>
       
    28 
       
    29 namespace WRT {
       
    30 ThumbnailViewPrivate::ThumbnailViewPrivate(WrtPageManager * mgr, QWidget* parent) :
       
    31     m_widgetParent(parent),
       
    32     m_graphicsWidgetParent(0),
       
    33     m_pageManager(mgr),
       
    34     m_activePage(0),
       
    35     m_tnEngineHandler(0),
       
    36     m_tnEngineView(0),
       
    37     m_isActive(false)
       
    38 {
       
    39     Q_ASSERT(m_pageManager);
       
    40     init();
       
    41 }
       
    42 
       
    43 ThumbnailViewPrivate::ThumbnailViewPrivate(WrtPageManager * mgr, QGraphicsWidget* parent) :
       
    44     m_widgetParent(0),
       
    45     m_graphicsWidgetParent(parent),
       
    46     m_pageManager(mgr),
       
    47     m_activePage(0),
       
    48     m_tnEngineHandler(0),
       
    49     m_tnEngineView(0),
       
    50     m_isActive(false)
       
    51 {
       
    52     Q_ASSERT(m_pageManager);    
       
    53     init();
       
    54 }
       
    55 
       
    56 ThumbnailViewPrivate::~ThumbnailViewPrivate()
       
    57 {
       
    58 }
       
    59 
       
    60 void ThumbnailViewPrivate::init()
       
    61 {
       
    62     // create the view's actions
       
    63     m_actionOK = new QAction("OK",m_widgetParent);
       
    64     m_actionOK->setObjectName("OK");
       
    65     m_actionCancel = new QAction("Cancel",m_widgetParent);
       
    66     m_actionCancel->setObjectName("Cancel");    
       
    67 }
       
    68 
       
    69 /*!
       
    70  * \class ThumbnailView
       
    71  *
       
    72  * \brief The Thumbnail View
       
    73  *
       
    74  * This class provides an overview of the current page, allows the user to scroll to 
       
    75  * a different part of the page
       
    76  */
       
    77 
       
    78 /*!
       
    79   Basic ThumbnailView constructor requires a PageManager to manage the pages
       
    80   and a parent QWidget
       
    81 */
       
    82 ThumbnailView::ThumbnailView(WrtPageManager * pageMgr, QWidget* parent) :
       
    83     d(new ThumbnailViewPrivate(pageMgr, parent))
       
    84 {
       
    85 }
       
    86 
       
    87 /*!
       
    88   Basic ThumbnailView constructor requires a PageManager to manage the pages
       
    89   and a parent QGraphicsWidget
       
    90 */
       
    91 ThumbnailView::ThumbnailView(WrtPageManager * pageMgr, QGraphicsWidget* parent) :
       
    92     d(new ThumbnailViewPrivate(pageMgr, parent))
       
    93 {    
       
    94 }
       
    95 
       
    96 
       
    97 ThumbnailView::~ThumbnailView()
       
    98 {
       
    99     if(d->m_isActive)
       
   100         deactivate();
       
   101 
       
   102     if(d->m_tnEngineHandler)
       
   103         delete(d->m_tnEngineHandler);
       
   104 
       
   105     if(d->m_tnEngineView)
       
   106         delete(d->m_tnEngineView);
       
   107 
       
   108     delete d;
       
   109 }
       
   110 
       
   111 /*!
       
   112   Retrieve the WrtPageManager assigned to this view
       
   113 */
       
   114 WrtPageManager* ThumbnailView::wrtPageManager()
       
   115 {
       
   116     return d->m_pageManager;
       
   117 }
       
   118 
       
   119 /*!
       
   120   Return the view's OK QAction
       
   121   For invoking the view's OK
       
   122 */
       
   123 QAction * ThumbnailView::getActionOK()
       
   124 {
       
   125     return d->m_actionOK;
       
   126 }
       
   127 
       
   128 /*!
       
   129   Return the view's Cancel QAction
       
   130   For invoking the view's Cancel
       
   131 */
       
   132 QAction * ThumbnailView::getActionCancel()
       
   133 {
       
   134     return d->m_actionCancel;
       
   135 }
       
   136 
       
   137 /*!
       
   138   Return the widget handle of this view
       
   139 */
       
   140 QWidget* ThumbnailView::qWidget() const
       
   141 {
       
   142     return d->m_tnEngineHandler->widget();
       
   143 }
       
   144 
       
   145 /*!
       
   146   Return the title of this view for display
       
   147 */
       
   148 QString ThumbnailView::title()
       
   149 {
       
   150     return QString("ThumbnailView");
       
   151 }
       
   152 
       
   153 /*!
       
   154   Return whether this view is active or not
       
   155 */
       
   156 bool ThumbnailView::isActive()
       
   157 {
       
   158     return d->m_isActive;
       
   159 }
       
   160 
       
   161 
       
   162 /*! 
       
   163   Return the list of public QActions most relevant to the view's current context
       
   164   (most approptiate for contextual menus, etc.
       
   165 */
       
   166 QList<QAction*> ThumbnailView::getContext()
       
   167 {
       
   168     // for now, all actions valid at all times
       
   169     // but there may be some logic here to determine context
       
   170     QList<QAction*> contextList;
       
   171     contextList <<
       
   172         d->m_actionOK <<
       
   173         d->m_actionCancel;
       
   174     return contextList;
       
   175 }
       
   176 
       
   177 /*!
       
   178   activate the view's resources. Could be connected by client to view visibility
       
   179 */
       
   180 void ThumbnailView::activate()
       
   181 {
       
   182     Q_ASSERT(!d->m_isActive);
       
   183 
       
   184     d->m_tnEngineHandler = new TnEngineHandler(d->m_pageManager, d->m_widgetParent);
       
   185     Q_ASSERT(d->m_tnEngineHandler);
       
   186     d->m_tnEngineView = d->m_tnEngineHandler->tnEngineView();
       
   187     Q_ASSERT(d->m_tnEngineView);
       
   188 
       
   189     // connect/forward signals as appropriate
       
   190     connect(d->m_tnEngineView,SIGNAL(scrollStarted()),this,SIGNAL(scrollStarted()));
       
   191     connect(d->m_tnEngineView,SIGNAL(scrollBy(int,int)),this,SIGNAL(scrollBy(int,int)));
       
   192     connect(d->m_tnEngineView,SIGNAL(scrollEnded()),this,SIGNAL(scrollEnded()));
       
   193     connect(d->m_tnEngineHandler,SIGNAL(ok(int,int)),this,SIGNAL(ok(int,int)));
       
   194     connect(d->m_tnEngineView,SIGNAL(cancel()),this,SIGNAL(cancel()));
       
   195 
       
   196     //d->m_tnEngineHandler->show();
       
   197     d->m_isActive = true;
       
   198 
       
   199 }
       
   200     
       
   201 /*! 
       
   202   deactivate the view's resources. Could be connected by client to view visibility
       
   203 */
       
   204 void ThumbnailView::deactivate()
       
   205 {
       
   206     Q_ASSERT(d->m_isActive);
       
   207 
       
   208     Q_ASSERT(d->m_tnEngineHandler);
       
   209     Q_ASSERT(d->m_tnEngineView);
       
   210 
       
   211     // connect/forward signals as appropriate
       
   212     disconnect(d->m_tnEngineView,SIGNAL(scrollStarted()),this,SIGNAL(scrollStarted()));
       
   213     disconnect(d->m_tnEngineView,SIGNAL(scrollBy(int,int)),this,SIGNAL(scrollBy(int,int)));
       
   214     disconnect(d->m_tnEngineView,SIGNAL(scrollEnded()),this,SIGNAL(scrollEnded()));
       
   215     disconnect(d->m_tnEngineHandler,SIGNAL(ok(int,int)),this,SIGNAL(ok(int,int)));
       
   216     disconnect(d->m_tnEngineView,SIGNAL(cancel()),this,SIGNAL(cancel()));
       
   217 
       
   218     m_proxyWidget->setWidget(0);
       
   219     delete m_proxyWidget;
       
   220     m_proxyWidget = 0;
       
   221     delete(d->m_tnEngineHandler);
       
   222     d->m_tnEngineHandler = NULL;
       
   223     d->m_tnEngineView = NULL;
       
   224 
       
   225     d->m_isActive = false;
       
   226 }
       
   227 
       
   228 /*!
       
   229   scroll the ThumbnailView by the amount given the doc coordinates
       
   230 */
       
   231 void ThumbnailView::scrollViewBy(int /*x*/, int /*y*/)
       
   232 {
       
   233     Q_ASSERT(d->m_tnEngineHandler);
       
   234     Q_ASSERT(d->m_tnEngineView);
       
   235     d->m_tnEngineHandler->updateNow();
       
   236     d->m_tnEngineView->update();
       
   237 }
       
   238     
       
   239 /*!
       
   240   \fn void ThumbnailView::scrollStarted();
       
   241   emitted when scrolling on the ThumbnailView has started
       
   242 */
       
   243 
       
   244 /*!
       
   245   \fn void ThumbnailView::scrollTo(int x, int y);
       
   246   emitted during a scrolling event
       
   247 */  
       
   248 
       
   249 /*!  
       
   250   \fn void ThumbnailView::scrollEnded();
       
   251   emitted when scrolling has ended();
       
   252 */   
       
   253  
       
   254 /*!
       
   255   \fn void ThumbnailView::ok(int x, int y);
       
   256   emitted when the ok action has occured, and the position the 
       
   257   view has currently scrolled to
       
   258 */
       
   259 
       
   260 /*!
       
   261   \fn void ThumbnailView::cancel();
       
   262   emitted when the cancel action has occured
       
   263 */
       
   264 
       
   265 } // namespace WRT