ui/views/fullscreenview/src/glxzoomslider.cpp
changeset 33 1ee2af37811f
parent 29 2c833fc9e98f
child 36 6481344a6d67
equal deleted inserted replaced
29:2c833fc9e98f 33:1ee2af37811f
     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:   ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 #include "glxzoomslider.h"
       
    19 #include <hbslider.h>
       
    20 #include <glxmediamodel.h>
       
    21 #include <QAbstractItemModel>
       
    22 #include <QGraphicsItem>
       
    23 #include <QtDebug>
       
    24 #include "glxmodelparm.h"
       
    25 #include <QDebug>
       
    26 
       
    27 GlxZoomSlider::GlxZoomSlider(QGraphicsItem *parent)
       
    28 {
       
    29 	mZoomSlider = new HbSlider(Qt::Horizontal,parent);
       
    30 	mZoomSlider->hide();
       
    31 	mZoomSlider->setRange(0, 400);
       
    32 	mZoomSlider->setSingleStep(25);
       
    33 	mZoomSlider->setSliderPosition(100);
       
    34 	mZoomSlider->setZValue(7);
       
    35 	mZoomSlider->setPos(50,100);
       
    36     mZoomSlider->resize(300.0, 0.0 );
       
    37 	isSliderVisible = false;
       
    38 	mSliderThumbPressed = false;
       
    39 	connect(mZoomSlider, SIGNAL(valueChanged(int)), this, SLOT(filterandEmitSliderValueChanges(int)));
       
    40 	connect(mZoomSlider, SIGNAL(sliderPressed()), this, SLOT(sliderThumbPressed()));
       
    41 	connect(mZoomSlider, SIGNAL(sliderReleased()), this, SLOT(sliderThumbReleased()));
       
    42 }
       
    43 
       
    44 GlxZoomSlider::~GlxZoomSlider()
       
    45 {
       
    46 	disconnect(mZoomSlider, SIGNAL(valueChanged(int)), this, SLOT(filterandEmitSliderValueChanges(int)));
       
    47 	disconnect(mZoomSlider, SIGNAL(sliderPressed()), this, SLOT(sliderThumbPressed()));
       
    48 	disconnect(mZoomSlider, SIGNAL(sliderReleased()), this, SLOT(sliderThumbReleased()));
       
    49 	delete mZoomSlider;
       
    50 	isSliderVisible = false;
       
    51 }
       
    52 
       
    53 void GlxZoomSlider::setModel (QAbstractItemModel *model)
       
    54 {
       
    55 	GlxMediaModel *glxModel = dynamic_cast<GlxMediaModel *>(model);
       
    56     if ( glxModel ==NULL ||  glxModel == mModel) {
       
    57         return ;
       
    58     }
       
    59 	mModel = glxModel;
       
    60 
       
    61 }
       
    62 
       
    63 void GlxZoomSlider::indexChanged (int index)
       
    64 {
       
    65 	Q_UNUSED(index);
       
    66 	mZoomSlider->hide();
       
    67 	isSliderVisible = false;
       
    68 }
       
    69 
       
    70 void GlxZoomSlider::toggleSliderVisibility()
       
    71 {
       
    72 	if(isSliderVisible) {
       
    73 		mZoomSlider->hide();
       
    74 		isSliderVisible = false;
       
    75 	}
       
    76 	else {
       
    77 		calculateAndInitializeFSZoomFactor();
       
    78 		mZoomSlider->show();
       
    79 		isSliderVisible = true;
       
    80 	}
       
    81 }
       
    82 
       
    83 void GlxZoomSlider::retrieveActualAndDisplayedSize(QSize& itemSize, QSize& displayedSize)
       
    84 {
       
    85 	itemSize = (mModel->data(mModel->index(mModel->data(mModel->index(0,0),GlxFocusIndexRole).value<int>(),0),GlxDimensionsRole)).value<QSize>();
       
    86 	qDebug()<<"GlxZoomSlider::retrieveActualAndDisplayedSize"<<itemSize.width()<<itemSize.height();
       
    87 	 QVariant variant = mModel->data(mModel->index(mModel->data(mModel->index(0,0),GlxFocusIndexRole).value<int>(),0),GlxFsImageRole);
       
    88 	 if ( variant.isValid() &&  variant.canConvert<HbIcon> () ) {
       
    89 		 QIcon itemIcon = variant.value<HbIcon>().qicon();
       
    90 		 QSize windowSize(360,640);
       
    91 		 QSize itemSize = itemIcon.actualSize(windowSize);
       
    92 		 QPixmap itemPixmap = itemIcon.pixmap(itemSize);
       
    93 		 displayedSize = itemPixmap.size();
       
    94 		 qDebug()<<"GlxZoomSlider::retrieveActualAndDisplayedSize Display"<<displayedSize.width()<<displayedSize.height();
       
    95 		 }
       
    96 
       
    97 }
       
    98 int GlxZoomSlider::calculateZoomFactor(QSize& itemSize, QSize& displayedSize)
       
    99 {
       
   100 	int zoomFactor = 100 * (displayedSize.width())/(itemSize.width());
       
   101 	return zoomFactor;
       
   102 }
       
   103 
       
   104 void GlxZoomSlider::calculateAndInitializeFSZoomFactor()
       
   105 {
       
   106 	QSize itemSize,displaySize;
       
   107 	retrieveActualAndDisplayedSize(itemSize, displaySize);
       
   108 	int sliderPosition = calculateZoomFactor(itemSize,displaySize);
       
   109 	emit initialZoomFactor(sliderPosition);
       
   110 	mZoomSlider->setSliderPosition(sliderPosition);
       
   111 }
       
   112 
       
   113 void GlxZoomSlider::filterandEmitSliderValueChanges(int newValue)
       
   114 {
       
   115 	if (mSliderThumbPressed){
       
   116 		emit valueChanged(newValue);
       
   117 	}
       
   118 	//else {
       
   119 		qDebug()<<"GlxZoomSlider::filterandEmitSliderValueChanges stray signal"<<newValue;
       
   120 	//}
       
   121 }
       
   122 
       
   123 void GlxZoomSlider::sliderThumbPressed()
       
   124 {
       
   125 	qDebug()<<"GlxZoomSlider::sliderThumbPressed";
       
   126 	mSliderThumbPressed = true;
       
   127 }
       
   128 
       
   129 void GlxZoomSlider::sliderThumbReleased()
       
   130 {
       
   131 	qDebug()<<"GlxZoomSlider::sliderThumbReleased";
       
   132 	mSliderThumbPressed = false;
       
   133 }