ginebra2/ContentToolbarChromeItem.cpp
author hgs
Fri, 06 Aug 2010 17:23:08 -0400
changeset 9 b39122337a00
parent 3 0954f5dd2cd0
child 16 3c88a81ff781
permissions -rw-r--r--
201031
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     1
/*
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     2
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     3
* All rights reserved.
3
hgs
parents: 0
diff changeset
     4
*
hgs
parents: 0
diff changeset
     5
* This program is free software: you can redistribute it and/or modify
hgs
parents: 0
diff changeset
     6
* it under the terms of the GNU Lesser General Public License as published by
hgs
parents: 0
diff changeset
     7
* the Free Software Foundation, version 2.1 of the License.
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     8
*
3
hgs
parents: 0
diff changeset
     9
* This program is distributed in the hope that it will be useful,
hgs
parents: 0
diff changeset
    10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
hgs
parents: 0
diff changeset
    11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
hgs
parents: 0
diff changeset
    12
* GNU Lesser General Public License for more details.
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    13
*
3
hgs
parents: 0
diff changeset
    14
* You should have received a copy of the GNU Lesser General Public License
hgs
parents: 0
diff changeset
    15
* along with this program.  If not,
hgs
parents: 0
diff changeset
    16
* see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    17
*
3
hgs
parents: 0
diff changeset
    18
* Description:
hgs
parents: 0
diff changeset
    19
* This class extends ToolbarChromeItem. It paints the toolbar background
hgs
parents: 0
diff changeset
    20
* and controls toolbar visibility in the content view.
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    21
*
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    22
*/
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    23
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    24
#include "ContentToolbarChromeItem.h"
3
hgs
parents: 0
diff changeset
    25
#include "ChromeItem.h"
hgs
parents: 0
diff changeset
    26
#include "WebChromeContainerSnippet.h"
hgs
parents: 0
diff changeset
    27
#include "ContentToolbarSnippet.h"
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    28
#include "GWebContentView.h"
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    29
#include "mostvisitedsnippet.h"
3
hgs
parents: 0
diff changeset
    30
#include "webpagecontroller.h"
hgs
parents: 0
diff changeset
    31
#include "ViewController.h"
hgs
parents: 0
diff changeset
    32
#include "ChromeEffect.h"
hgs
parents: 0
diff changeset
    33
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    34
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    35
#include <QTimeLine>
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    36
#include <QDebug>
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    37
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    38
#define TOOLBAR_MARGIN 4
3
hgs
parents: 0
diff changeset
    39
#define TOOLBAR_ANIMATION_DURATION 200
hgs
parents: 0
diff changeset
    40
#define TOOLBAR_INACTIVITY_DURATION 5000
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    41
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    42
namespace GVA {
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    43
3
hgs
parents: 0
diff changeset
    44
  ToolbarFadeAnimator::ToolbarFadeAnimator(): m_timeLine(NULL)
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    45
  {
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    46
  }
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    47
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    48
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    49
  ToolbarFadeAnimator::~ToolbarFadeAnimator() {
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    50
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    51
    if (m_timeLine)
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    52
      delete m_timeLine;
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    53
  }
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    54
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    55
  void ToolbarFadeAnimator::start(bool visible) {
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    56
    //qDebug() << __PRETTY_FUNCTION__ << visible;
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    57
    if (!m_timeLine) {
3
hgs
parents: 0
diff changeset
    58
      m_timeLine = new QTimeLine(TOOLBAR_ANIMATION_DURATION);
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    59
      connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(valueChange(qreal)));
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    60
      connect(m_timeLine, SIGNAL(finished()), this, SIGNAL(finished()));
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    61
    }
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    62
    else {
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    63
      m_timeLine->stop();
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    64
    }
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    65
    if (!visible) {
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    66
      m_timeLine->setDirection(QTimeLine::Forward);
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    67
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    68
    }
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    69
    else {
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    70
      m_timeLine->setDirection(QTimeLine::Backward);
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    71
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    72
    }
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    73
    m_timeLine->start();
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    74
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    75
  }
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    76
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    77
  void ToolbarFadeAnimator::stop() {
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    78
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    79
    //qDebug() << __PRETTY_FUNCTION__ ;
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    80
    m_timeLine->stop();
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    81
  }
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    82
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    83
  void ToolbarFadeAnimator::valueChange(qreal step) {
3
hgs
parents: 0
diff changeset
    84
    emit  updateVisibility(step);
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    85
  }
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    86
3
hgs
parents: 0
diff changeset
    87
  ContentToolbarChromeItem::ContentToolbarChromeItem(ChromeSnippet* snippet, QGraphicsItem* parent)
hgs
parents: 0
diff changeset
    88
      : ToolbarChromeItem(snippet, parent),
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    89
      m_background(NULL),
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    90
      m_state(CONTENT_TOOLBAR_STATE_FULL),
3
hgs
parents: 0
diff changeset
    91
      m_autoHideToolbar(true),
hgs
parents: 0
diff changeset
    92
      m_timerState(CONTENT_TOOLBAR_TIMER_STATE_ALLOW)
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    93
  {
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    94
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    95
    m_inactivityTimer = new QTimer(this);
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    96
    connect(m_inactivityTimer, SIGNAL(timeout()), this, SLOT(onInactivityTimer()));
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    97
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    98
    m_animator = new ToolbarFadeAnimator();
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    99
    connect(m_animator, SIGNAL(updateVisibility(qreal)), this, SLOT(onUpdateVisibility(qreal)));
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   100
    connect(m_animator, SIGNAL(finished()), this, SLOT(onAnimFinished()));
3
hgs
parents: 0
diff changeset
   101
    
hgs
parents: 0
diff changeset
   102
    m_maxOpacity = m_bgopacity = opacity();   
hgs
parents: 0
diff changeset
   103
    if (m_autoHideToolbar ) {
hgs
parents: 0
diff changeset
   104
       connect(m_snippet->chrome(), SIGNAL(chromeComplete()), this, SLOT(onChromeComplete()));
hgs
parents: 0
diff changeset
   105
    }
hgs
parents: 0
diff changeset
   106
    
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   107
    setFlags(QGraphicsItem::ItemDoesntPropagateOpacityToChildren);
3
hgs
parents: 0
diff changeset
   108
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   109
  }
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   110
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   111
  ContentToolbarChromeItem::~ContentToolbarChromeItem()
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   112
  {
3
hgs
parents: 0
diff changeset
   113
    if (m_background )
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   114
        delete m_background;
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   115
    delete m_inactivityTimer;
3
hgs
parents: 0
diff changeset
   116
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   117
    delete m_animator;
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   118
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   119
  }
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   120
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   121
  void ContentToolbarChromeItem::resizeEvent(QGraphicsSceneResizeEvent * ev)
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   122
  {
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   123
    //qDebug() << __PRETTY_FUNCTION__ << boundingRect();
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   124
    ToolbarChromeItem::resizeEvent(ev);
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   125
    addFullBackground();
3
hgs
parents: 0
diff changeset
   126
hgs
parents: 0
diff changeset
   127
  }
hgs
parents: 0
diff changeset
   128
hgs
parents: 0
diff changeset
   129
  void ContentToolbarChromeItem::mousePressEvent(QGraphicsSceneMouseEvent * ev)
hgs
parents: 0
diff changeset
   130
  {
hgs
parents: 0
diff changeset
   131
      // If we are not in full state, ignore the event. Once igonre, none of the
hgs
parents: 0
diff changeset
   132
      // other mouse events are received until the next mouse press
hgs
parents: 0
diff changeset
   133
      if (m_state == CONTENT_TOOLBAR_STATE_PARTIAL ) {
hgs
parents: 0
diff changeset
   134
          ev->ignore();
hgs
parents: 0
diff changeset
   135
      }
hgs
parents: 0
diff changeset
   136
      else {
hgs
parents: 0
diff changeset
   137
          ChromeSnippet * mv = m_snippet->chrome()->getSnippet("MostVisitedViewId");
hgs
parents: 0
diff changeset
   138
          // Let mostvisited snippet handle the key press if it is visible
hgs
parents: 0
diff changeset
   139
          if (mv && mv->isVisible() ){
hgs
parents: 0
diff changeset
   140
              ev->ignore();
hgs
parents: 0
diff changeset
   141
          }
hgs
parents: 0
diff changeset
   142
      }
hgs
parents: 0
diff changeset
   143
  }
hgs
parents: 0
diff changeset
   144
hgs
parents: 0
diff changeset
   145
  void ContentToolbarChromeItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * ev)
hgs
parents: 0
diff changeset
   146
  {
hgs
parents: 0
diff changeset
   147
      Q_UNUSED(ev);
hgs
parents: 0
diff changeset
   148
      // Do nothing - prevent the event from trickling down
hgs
parents: 0
diff changeset
   149
      
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   150
  }
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   151
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   152
  void ContentToolbarChromeItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* opt, QWidget* widget)
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   153
  {
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   154
    Q_UNUSED(opt)
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   155
    Q_UNUSED(widget)
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   156
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   157
//    qDebug() << __PRETTY_FUNCTION__ << m_state;
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   158
    painter->save();
3
hgs
parents: 0
diff changeset
   159
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   160
    painter->setRenderHint(QPainter::Antialiasing);
3
hgs
parents: 0
diff changeset
   161
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   162
    painter->setPen(pen());
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   163
    painter->setOpacity(m_bgopacity);
3
hgs
parents: 0
diff changeset
   164
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   165
    switch (m_state) {
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   166
        case CONTENT_TOOLBAR_STATE_PARTIAL:
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   167
          ToolbarChromeItem::paint(painter, opt, widget);
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   168
          break;
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   169
        case CONTENT_TOOLBAR_STATE_ANIM_TO_FULL:
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   170
        case CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL:
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   171
          ToolbarChromeItem::paint(painter, opt, widget);
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   172
        case CONTENT_TOOLBAR_STATE_FULL:
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   173
          // fill path with color
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   174
          painter->fillPath(*m_background,QBrush(grad()));
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   175
          painter->drawPath(*m_background);
3
hgs
parents: 0
diff changeset
   176
          if(m_state == CONTENT_TOOLBAR_STATE_FULL && !isEnabled()) {
hgs
parents: 0
diff changeset
   177
              // Disabled, apply whitewash.
hgs
parents: 0
diff changeset
   178
              ChromeEffect::paintDisabledRect(painter, opt->exposedRect);
hgs
parents: 0
diff changeset
   179
          }
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   180
          break;
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   181
        default:
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   182
          qDebug() << "ContentToolbarChromeItem::paint invalid state" ;
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   183
          break;
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   184
    }
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   185
    // restore painter
3
hgs
parents: 0
diff changeset
   186
    painter->restore();
hgs
parents: 0
diff changeset
   187
hgs
parents: 0
diff changeset
   188
  }
hgs
parents: 0
diff changeset
   189
hgs
parents: 0
diff changeset
   190
hgs
parents: 0
diff changeset
   191
  void ContentToolbarChromeItem::setSnippet(ChromeSnippet* snippet) {
hgs
parents: 0
diff changeset
   192
    ToolbarChromeItem::setSnippet(snippet);
hgs
parents: 0
diff changeset
   193
    m_maxOpacity = m_bgopacity = opacity();
hgs
parents: 0
diff changeset
   194
    
hgs
parents: 0
diff changeset
   195
    if (m_autoHideToolbar ) {
hgs
parents: 0
diff changeset
   196
        connect(snippet->chrome(), SIGNAL(chromeComplete()), this, SLOT(onChromeComplete()));
hgs
parents: 0
diff changeset
   197
    }
hgs
parents: 0
diff changeset
   198
hgs
parents: 0
diff changeset
   199
  }
hgs
parents: 0
diff changeset
   200
hgs
parents: 0
diff changeset
   201
  void ContentToolbarChromeItem::onChromeComplete() {
hgs
parents: 0
diff changeset
   202
hgs
parents: 0
diff changeset
   203
    GWebContentView* webView  = static_cast<GWebContentView*> (m_snippet->chrome()->getView("WebView"));
hgs
parents: 0
diff changeset
   204
    //qDebug() << __PRETTY_FUNCTION__ << webView;
hgs
parents: 0
diff changeset
   205
    if (webView ) {
hgs
parents: 0
diff changeset
   206
        connect(webView, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool)));
hgs
parents: 0
diff changeset
   207
        connect(webView, SIGNAL(loadStarted()), this, SLOT(onLoadStarted()));
hgs
parents: 0
diff changeset
   208
#ifdef BEDROCK_TILED_BACKING_STORE
hgs
parents: 0
diff changeset
   209
        connect(webView, SIGNAL(contextEvent(::WebViewEventContext *)), this, SLOT(resetTimer()));
hgs
parents: 0
diff changeset
   210
#else
hgs
parents: 0
diff changeset
   211
        connect(webView->widget(), SIGNAL(contextEvent(::WebViewEventContext *)), this, SLOT(resetTimer()));
hgs
parents: 0
diff changeset
   212
#endif
hgs
parents: 0
diff changeset
   213
    }
hgs
parents: 0
diff changeset
   214
hgs
parents: 0
diff changeset
   215
  }
hgs
parents: 0
diff changeset
   216
hgs
parents: 0
diff changeset
   217
  void ContentToolbarChromeItem::onLoadStarted() {
hgs
parents: 0
diff changeset
   218
hgs
parents: 0
diff changeset
   219
      m_timerState = CONTENT_TOOLBAR_TIMER_STATE_ALLOW;
hgs
parents: 0
diff changeset
   220
      stopInactivityTimer();
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   221
  }
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   222
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   223
3
hgs
parents: 0
diff changeset
   224
  void ContentToolbarChromeItem::onLoadFinished(bool ok) {
hgs
parents: 0
diff changeset
   225
hgs
parents: 0
diff changeset
   226
    Q_UNUSED(ok);
hgs
parents: 0
diff changeset
   227
    //qDebug() << __PRETTY_FUNCTION__ << m_state << "Timer Allowed" << m_timerState;
hgs
parents: 0
diff changeset
   228
hgs
parents: 0
diff changeset
   229
    if (m_autoHideToolbar  && m_timerState == CONTENT_TOOLBAR_TIMER_STATE_ALLOW) {
hgs
parents: 0
diff changeset
   230
        ControllableViewBase* curView = m_snippet->chrome()->viewController()->currentView();
hgs
parents: 0
diff changeset
   231
        if (curView && curView->type() == "webView") {
hgs
parents: 0
diff changeset
   232
            GWebContentView * gView = qobject_cast<GWebContentView*> (curView);
hgs
parents: 0
diff changeset
   233
            bool isSuperPage = gView ? gView->currentPageIsSuperPage() : false;
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   234
3
hgs
parents: 0
diff changeset
   235
        // Start inactivity timer if full toolbar is visible 
hgs
parents: 0
diff changeset
   236
        if (!isSuperPage && m_state ==  CONTENT_TOOLBAR_STATE_FULL ) 
hgs
parents: 0
diff changeset
   237
            m_inactivityTimer->start(TOOLBAR_INACTIVITY_DURATION);
hgs
parents: 0
diff changeset
   238
        }
hgs
parents: 0
diff changeset
   239
    }
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   240
3
hgs
parents: 0
diff changeset
   241
  }
hgs
parents: 0
diff changeset
   242
  void ContentToolbarChromeItem::resetTimer() {
hgs
parents: 0
diff changeset
   243
      
hgs
parents: 0
diff changeset
   244
      m_timerState = CONTENT_TOOLBAR_TIMER_STATE_NONE;
hgs
parents: 0
diff changeset
   245
      stopInactivityTimer();
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   246
  }
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   247
3
hgs
parents: 0
diff changeset
   248
  void ContentToolbarChromeItem::stopInactivityTimer() {
hgs
parents: 0
diff changeset
   249
hgs
parents: 0
diff changeset
   250
    //qDebug() << __PRETTY_FUNCTION__<< m_state << " Timer Active: " << m_inactivityTimer->isActive(); 
hgs
parents: 0
diff changeset
   251
    // Stop inactivity timer 
hgs
parents: 0
diff changeset
   252
    if (m_inactivityTimer->isActive() )
hgs
parents: 0
diff changeset
   253
        m_inactivityTimer->stop();
hgs
parents: 0
diff changeset
   254
hgs
parents: 0
diff changeset
   255
  }
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   256
3
hgs
parents: 0
diff changeset
   257
  void ContentToolbarChromeItem::onInactivityTimer() {
hgs
parents: 0
diff changeset
   258
hgs
parents: 0
diff changeset
   259
    //qDebug() << __PRETTY_FUNCTION__ << m_state;
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   260
3
hgs
parents: 0
diff changeset
   261
    //We are here because inactivity timer timed out. So we have to be in full toolbar state with no
hgs
parents: 0
diff changeset
   262
    // popups. So change fade to Partial state after stopping inactivity timer
hgs
parents: 0
diff changeset
   263
    m_inactivityTimer->stop();
hgs
parents: 0
diff changeset
   264
    changeState(CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL, true);
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   265
  }
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   266
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   267
  void ContentToolbarChromeItem::onSnippetMouseEvent( QEvent::Type type) {
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   268
3
hgs
parents: 0
diff changeset
   269
    //qDebug() << __PRETTY_FUNCTION__ << type ;
hgs
parents: 0
diff changeset
   270
hgs
parents: 0
diff changeset
   271
    if (type == QEvent::MouseButtonPress || type ==  QEvent::GraphicsSceneMousePress) {
hgs
parents: 0
diff changeset
   272
        resetTimer();
hgs
parents: 0
diff changeset
   273
    } 
hgs
parents: 0
diff changeset
   274
  }
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   275
3
hgs
parents: 0
diff changeset
   276
  void ContentToolbarChromeItem::addLinkedChild(ChromeSnippet * s) {
hgs
parents: 0
diff changeset
   277
      m_linkedChildren.append(s);
hgs
parents: 0
diff changeset
   278
  }
hgs
parents: 0
diff changeset
   279
hgs
parents: 0
diff changeset
   280
  void ContentToolbarChromeItem::toggleMiddleSnippet() {
hgs
parents: 0
diff changeset
   281
      //qDebug() << "TOGGLE MIDDLE : " << m_state;
hgs
parents: 0
diff changeset
   282
      switch (m_state) {
hgs
parents: 0
diff changeset
   283
         case CONTENT_TOOLBAR_STATE_PARTIAL:
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   284
            changeState(CONTENT_TOOLBAR_STATE_ANIM_TO_FULL);
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   285
            break;
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   286
          case CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL:
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   287
            // Stop animation and change to full immediately
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   288
            m_animator->stop();
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   289
            changeState(CONTENT_TOOLBAR_STATE_FULL, false);
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   290
            break;
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   291
          case CONTENT_TOOLBAR_STATE_ANIM_TO_FULL:
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   292
            // Do nothing here - will reset inactivity timer when
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   293
            // animation completes
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   294
            break;
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   295
          case CONTENT_TOOLBAR_STATE_FULL:
3
hgs
parents: 0
diff changeset
   296
            // if MV is active then wait for it to hide before changing the toolbar state
hgs
parents: 0
diff changeset
   297
            if (mvSnippetVisible()) {
hgs
parents: 0
diff changeset
   298
                changeState(CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL, false);
hgs
parents: 0
diff changeset
   299
            }
hgs
parents: 0
diff changeset
   300
            else {
hgs
parents: 0
diff changeset
   301
                changeState(CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL, true);
hgs
parents: 0
diff changeset
   302
            }
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   303
            break;
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   304
          default:
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   305
            break;
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   306
        }
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   307
  }
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   308
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   309
  void ContentToolbarChromeItem::onMVCloseComplete() {
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   310
3
hgs
parents: 0
diff changeset
   311
//    qDebug() << __PRETTY_FUNCTION__;
hgs
parents: 0
diff changeset
   312
    ChromeSnippet * mv = m_snippet->chrome()->getSnippet("MostVisitedViewId");
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   313
    disconnect(mv, SIGNAL(mostVisitedSnippetCloseComplete()) , this, SLOT(onMVCloseComplete()));
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   314
    // MostVisitedSnippet animation complete, so let's do toolbar animation
3
hgs
parents: 0
diff changeset
   315
    if (m_state == CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL)
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   316
      changeState(CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL, true);
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   317
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   318
  }
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   319
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   320
  void ContentToolbarChromeItem::onUpdateVisibility(qreal step) {
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   321
3
hgs
parents: 0
diff changeset
   322
    //qDebug() << __PRETTY_FUNCTION__ << step << m_bgopacity << opacity();
hgs
parents: 0
diff changeset
   323
    // Value we get is 1.0 based, adjust it based on our max opacity
hgs
parents: 0
diff changeset
   324
    qreal value = step - (1.0 - m_maxOpacity);
hgs
parents: 0
diff changeset
   325
    value =  (value > 0)? value: 0.0;
hgs
parents: 0
diff changeset
   326
hgs
parents: 0
diff changeset
   327
    if (m_bgopacity != value ) {
hgs
parents: 0
diff changeset
   328
      m_bgopacity = value;
hgs
parents: 0
diff changeset
   329
      setOpacity(m_maxOpacity - value);
hgs
parents: 0
diff changeset
   330
      ContentToolbarSnippet * s = static_cast<ContentToolbarSnippet*>(m_snippet);
hgs
parents: 0
diff changeset
   331
      s->middleSnippet()->widget()->setOpacity(value);
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   332
      update();
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   333
    }
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   334
  }
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   335
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   336
  void ContentToolbarChromeItem::onAnimFinished() {
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   337
3
hgs
parents: 0
diff changeset
   338
    ContentToolbarState state = CONTENT_TOOLBAR_STATE_INVALID;
hgs
parents: 0
diff changeset
   339
    bool animate = false;
hgs
parents: 0
diff changeset
   340
    //qDebug() << __PRETTY_FUNCTION__ << m_state;
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   341
    switch (m_state) {
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   342
        case CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL:
3
hgs
parents: 0
diff changeset
   343
          state = CONTENT_TOOLBAR_STATE_PARTIAL; 
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   344
          break;
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   345
        case CONTENT_TOOLBAR_STATE_ANIM_TO_FULL:
3
hgs
parents: 0
diff changeset
   346
          state = CONTENT_TOOLBAR_STATE_FULL; 
hgs
parents: 0
diff changeset
   347
          animate = true;
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   348
          break;
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   349
        default:
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   350
          break;
3
hgs
parents: 0
diff changeset
   351
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   352
    }
3
hgs
parents: 0
diff changeset
   353
  
hgs
parents: 0
diff changeset
   354
    ContentToolbarSnippet * s = static_cast<ContentToolbarSnippet*>(m_snippet);
hgs
parents: 0
diff changeset
   355
    s->handleToolbarStateChange(state);
hgs
parents: 0
diff changeset
   356
    changeState(state, animate);
hgs
parents: 0
diff changeset
   357
    //qDebug() << __PRETTY_FUNCTION__ << m_state;
hgs
parents: 0
diff changeset
   358
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   359
  }
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   360
  void ContentToolbarChromeItem::addFullBackground() {
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   361
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   362
    //qDebug() << __PRETTY_FUNCTION__ ;
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   363
    qreal roundness((boundingRect().height() -TOOLBAR_MARGIN)/2);
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   364
    QRectF r(1, 1, boundingRect().width()-TOOLBAR_MARGIN, boundingRect().height()-TOOLBAR_MARGIN);
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   365
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   366
    if (m_background ) {
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   367
        delete m_background;
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   368
        m_background = NULL;
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   369
    }
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   370
    m_background = new QPainterPath();
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   371
    m_background->addRoundedRect(r, roundness, roundness);
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   372
  }
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   373
3
hgs
parents: 0
diff changeset
   374
  void ContentToolbarChromeItem::stateEnterFull(bool animate) {
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   375
3
hgs
parents: 0
diff changeset
   376
    //qDebug() <<__PRETTY_FUNCTION__ ;
hgs
parents: 0
diff changeset
   377
    ContentToolbarSnippet * s = static_cast<ContentToolbarSnippet*>(m_snippet);
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   378
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   379
    // Show the middle snippet and reset the opacity if we are here directly with no aniamtion
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   380
    if (!animate) {
3
hgs
parents: 0
diff changeset
   381
      m_bgopacity = 0.75;
hgs
parents: 0
diff changeset
   382
      s->middleSnippet()->show();
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   383
    }
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   384
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   385
    m_state = CONTENT_TOOLBAR_STATE_FULL;
3
hgs
parents: 0
diff changeset
   386
    s->middleSnippet()->widget()->setOpacity(1.0);
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   387
    // TODO: specify the rect to be updated to avoid full repaint
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   388
    update();
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   389
  }
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   390
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   391
  void ContentToolbarChromeItem::stateEnterPartial(bool animate) {
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   392
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   393
    //qDebug() <<__PRETTY_FUNCTION__ ;
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   394
    Q_UNUSED(animate);
3
hgs
parents: 0
diff changeset
   395
    ContentToolbarSnippet * s = static_cast<ContentToolbarSnippet*>(m_snippet);
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   396
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   397
    // Explicity hide the linked snippets so that toggle button javascript gets the right
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   398
    // signals that it is expecting
3
hgs
parents: 0
diff changeset
   399
    hideLinkedChildren();
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   400
3
hgs
parents: 0
diff changeset
   401
    s->middleSnippet()->hide();
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   402
    m_state = CONTENT_TOOLBAR_STATE_PARTIAL;
3
hgs
parents: 0
diff changeset
   403
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   404
  }
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   405
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   406
  void ContentToolbarChromeItem::stateEnterAnimToFull(bool animate) {
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   407
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   408
    //qDebug() <<__PRETTY_FUNCTION__ ;
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   409
    Q_UNUSED(animate);
3
hgs
parents: 0
diff changeset
   410
    ContentToolbarSnippet * s = static_cast<ContentToolbarSnippet*>(m_snippet);
hgs
parents: 0
diff changeset
   411
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   412
    m_state = CONTENT_TOOLBAR_STATE_ANIM_TO_FULL;
3
hgs
parents: 0
diff changeset
   413
    s->middleSnippet()->show();
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   414
    m_animator->start(false);
3
hgs
parents: 0
diff changeset
   415
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   416
  }
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   417
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   418
  void ContentToolbarChromeItem::stateEnterAnimToPartial(bool animate) {
3
hgs
parents: 0
diff changeset
   419
    m_state = CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL;
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   420
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   421
    if (animate ) {
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   422
      m_animator->start(true);
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   423
    }
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   424
    else {
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   425
3
hgs
parents: 0
diff changeset
   426
      MostVisitedSnippet * mv = static_cast<MostVisitedSnippet *>(m_snippet->chrome()->getSnippet("MostVisitedViewId"));
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   427
      connect(mv, SIGNAL(mostVisitedSnippetCloseComplete()) , this, SLOT(onMVCloseComplete()));
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   428
      mv->close();
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   429
    }
3
hgs
parents: 0
diff changeset
   430
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   431
  }
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   432
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   433
  void ContentToolbarChromeItem::changeState( ContentToolbarState state, bool animate){
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   434
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   435
    onStateEntry(state, animate);
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   436
  }
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   437
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   438
  void ContentToolbarChromeItem::onStateEntry(ContentToolbarState state, bool animate){
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   439
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   440
   //qDebug() << __PRETTY_FUNCTION__ ;
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   441
   switch (state) {
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   442
        case CONTENT_TOOLBAR_STATE_PARTIAL:
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   443
          stateEnterPartial(animate);
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   444
          break;
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   445
        case CONTENT_TOOLBAR_STATE_ANIM_TO_FULL:
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   446
          stateEnterAnimToFull(animate);
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   447
          break;
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   448
        case CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL:
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   449
          stateEnterAnimToPartial(animate);
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   450
          break;
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   451
        case CONTENT_TOOLBAR_STATE_FULL:
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   452
          stateEnterFull(animate);
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   453
          break;
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   454
        default:
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   455
          qDebug() << "ContentToolbarChromeItem::onStateEntry -  invalid state" ;
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   456
          break;
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   457
    }
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   458
  }
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   459
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   460
  bool ContentToolbarChromeItem::mvSnippetVisible() {
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   461
3
hgs
parents: 0
diff changeset
   462
    ChromeSnippet * mv = m_snippet->chrome()->getSnippet("MostVisitedViewId");
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   463
    bool result = false;
3
hgs
parents: 0
diff changeset
   464
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   465
    if (mv && mv->isVisible() ) {
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   466
      result = true;
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   467
    }
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   468
    return result;
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   469
  }
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   470
3
hgs
parents: 0
diff changeset
   471
  void ContentToolbarChromeItem::hideLinkedChildren() {
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   472
3
hgs
parents: 0
diff changeset
   473
    for (int i=0; i < m_linkedChildren.count() ; i++) {
hgs
parents: 0
diff changeset
   474
hgs
parents: 0
diff changeset
   475
      m_linkedChildren.at(i)->hide();
0
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   476
    }
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   477
  }
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   478
} // end of namespace GVA
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   479
1450b09d0cfd Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   480