00001 /**************************************************************************** 00002 00003 This file is part of the GLC-lib library. 00004 Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net) 00005 Version 2.0.0 Beta 1, packaged on April 2010. 00006 00007 http://glc-lib.sourceforge.net 00008 00009 GLC-lib is free software; you can redistribute it and/or modify 00010 it under the terms of the GNU General Public License as published by 00011 the Free Software Foundation; either version 2 of the License, or 00012 (at your option) any later version. 00013 00014 GLC-lib is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU General Public License for more details. 00018 00019 You should have received a copy of the GNU General Public License 00020 along with GLC-lib; if not, write to the Free Software 00021 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00022 00023 *****************************************************************************/ 00024 00025 #include "glc_zoommover.h" 00026 #include "glc_viewport.h" 00027 00028 // Default constructor 00029 GLC_ZoomMover::GLC_ZoomMover(GLC_Viewport* pViewport, const QList<GLC_RepMover*>& repsList) 00030 : GLC_Mover(pViewport, repsList) 00031 , m_MaxZoomFactor(3.0) 00032 { 00033 00034 } 00035 00036 // Copy constructor 00037 GLC_ZoomMover::GLC_ZoomMover(const GLC_ZoomMover& mover) 00038 : GLC_Mover(mover) 00039 , m_MaxZoomFactor(mover.m_MaxZoomFactor) 00040 { 00041 00042 } 00043 00044 GLC_ZoomMover::~GLC_ZoomMover() 00045 { 00046 00047 } 00048 00049 00051 // Get Functions 00053 00054 // Return a clone of the mover 00055 GLC_Mover* GLC_ZoomMover::clone() const 00056 { 00057 return new GLC_ZoomMover(*this); 00058 } 00059 00061 // Set Functions 00063 00064 // Initialized the mover 00065 void GLC_ZoomMover::init(QMouseEvent * e) 00066 { 00067 // Change origine (view center) and cover between -1 and 1 00068 const double vSize= static_cast<double>(m_pViewport->viewVSize()); 00069 m_PreviousVector.setY((vSize / 2.0 - e->y()) / ( vSize / 2.0)); 00070 } 00071 00072 // Move the camera 00073 bool GLC_ZoomMover::move(QMouseEvent * e) 00074 { 00075 // Change origine (View Center) and cover (from -1 to 1) 00076 const double vSize= static_cast<double>(m_pViewport->viewVSize()); 00077 const double Posy= (vSize / 2.0 - e->y()) / ( vSize / 2.0); 00078 00079 // Compute zoom factor between (1 / MAXZOOMFACTOR) and (MAXZOOMFACTOR) 00080 double ZoomFactor= Posy - m_PreviousVector.y(); 00081 00082 if (ZoomFactor > 0) 00083 { 00084 ZoomFactor= (m_MaxZoomFactor - 1.0) * ZoomFactor + 1.0; 00085 } 00086 else 00087 { 00088 ZoomFactor= 1.0 / ( (m_MaxZoomFactor - 1.0) * fabs(ZoomFactor) + 1.0 ); 00089 } 00090 00091 m_pViewport->cameraHandle()->zoom(ZoomFactor); 00092 00093 m_PreviousVector.setY(Posy); 00094 00095 return true; 00096 }