karbon

vzoomtool.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2002, The Karbon Developers
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 
00019 */
00020 
00021 #include <qcursor.h>
00022 #include <qevent.h>
00023 
00024 #include <klocale.h>
00025 
00026 #include "vzoomtool.h"
00027 #include <karbon_part.h>
00028 #include <karbon_part.h>
00029 #include <karbon_view.h>
00030 #include <karbon_view.h>
00031 #include <render/vpainter.h>
00032 #include <render/vpainterfactory.h>
00033 #include <core/vcursor.h>
00034 
00035 VZoomTool::VZoomTool(KarbonView *view ): VTool( view, "tool_zoom_plugin" )
00036 {
00037     m_plusCursor = new QCursor( VCursor::createCursor( VCursor::ZoomPlus ) );
00038 
00039     registerTool( this );
00040 }
00041 
00042 VZoomTool::~VZoomTool()
00043 {
00044     delete m_plusCursor;
00045 }
00046 
00047 QString
00048 VZoomTool::contextHelp()
00049 {
00050     QString s = i18n( "<qt><b>Zoom tool:</b><br>" );
00051     s += i18n( "<i>Click and drag</i> to zoom into a rectangular area.<br>" );
00052     s += i18n( "<i>Right click</i> to zoom out of canvas.<br>" );
00053     s += i18n( "<i>Pressing +/- keys</i><br>to zoom into/out of canvas." );
00054     return s;
00055 }
00056 
00057 void
00058 VZoomTool::activate()
00059 {
00060     VTool::activate();
00061     view()->setCursor( *m_plusCursor );
00062 }
00063 
00064 QString
00065 VZoomTool::statusText()
00066 {
00067     return i18n( "Zoom Tool" );
00068 }
00069 
00070 void
00071 VZoomTool::deactivate()
00072 {
00073 }
00074 
00075 void
00076 VZoomTool::draw()
00077 {
00078     VPainter *painter = view()->painterFactory()->editpainter();
00079     painter->setRasterOp( Qt::NotROP );
00080 
00081     if( isDragging() )
00082     {
00083         painter->setPen( Qt::DotLine );
00084         painter->newPath();
00085         painter->moveTo( KoPoint( first().x(), first().y() ) );
00086         painter->lineTo( KoPoint( m_current.x(), first().y() ) );
00087         painter->lineTo( KoPoint( m_current.x(), m_current.y() ) );
00088         painter->lineTo( KoPoint( first().x(), m_current.y() ) );
00089         painter->lineTo( KoPoint( first().x(), first().y() ) );
00090         painter->strokePath();
00091     }
00092 }
00093 
00094 void
00095 VZoomTool::mouseButtonPress()
00096 {
00097     m_current = first();
00098 
00099     recalc();
00100 
00101     draw();
00102 }
00103 
00104 void 
00105 VZoomTool::rightMouseButtonRelease()
00106 {
00107     view()->setZoomAt( view()->zoom() * 0.75, last() );
00108 }
00109 
00110 void
00111 VZoomTool::mouseButtonRelease()
00112 {
00113     view()->setZoomAt( view()->zoom() * 1.5, last() );
00114 }
00115 
00116 void
00117 VZoomTool::mouseDrag()
00118 {
00119     draw();
00120 
00121     recalc();
00122 
00123     draw();
00124 }
00125 
00126 void
00127 VZoomTool::mouseDragRelease()
00128 {
00129     KoRect rect( first().x(), first().y(), last().x() - first().x(), last().y() - first().y() );
00130     rect = rect.normalize();
00131     view()->setViewportRect( rect );
00132 }
00133 
00134 bool
00135 VZoomTool::keyReleased( Qt::Key key )
00136 {
00137     double zoomChange = 0;
00138     if( key == Qt::Key_Minus )
00139         zoomChange = 0.75;
00140     else if( key == Qt::Key_Plus )
00141         zoomChange = 1.50;
00142 
00143     if( zoomChange != 0 )
00144     {
00145         view()->setZoomAt( view()->zoom() * zoomChange );
00146         return true;
00147     }
00148     return false;
00149 }
00150 
00151 void
00152 VZoomTool::recalc()
00153 {
00154     m_current = last();
00155 }
00156 
00157 void
00158 VZoomTool::setup( KActionCollection *collection )
00159 {
00160     m_action = static_cast<KRadioAction *>(collection -> action( name() ) );
00161 
00162     if( m_action == 0 )
00163     {
00164         m_action = new KRadioAction( i18n( "Zoom Tool" ), "14_zoom", Qt::SHIFT+Qt::Key_H, this, SLOT( activate() ), collection, name() );
00165         m_action->setToolTip( i18n( "Zoom" ) );
00166         m_action->setExclusiveGroup( "misc" );
00167         //m_ownAction = true;
00168     }
00169 }
00170 
KDE Home | KDE Accessibility Home | Description of Access Keys