• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

okteta

  • sources
  • kde-4.12
  • kdesdk
  • okteta
  • libs
  • kasten
  • controllers
  • view
  • zoom
zoomcontroller.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Kasten Framework, made within the KDE community.
3 
4  Copyright 2006-2008 Friedrich W. H. Kossebau <kossebau@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) version 3, or any
10  later version accepted by the membership of KDE e.V. (or its
11  successor approved by the membership of KDE e.V.), which shall
12  act as a proxy defined in Section 6 of version 3 of the license.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #include "zoomcontroller.h"
24 
25 // Kasten gui
26 #include <zoomable.h>
27 // Kasten core
28 #include <abstractmodel.h>
29 // KDE
30 #include <KXMLGUIClient>
31 #include <KLocale>
32 #include <KAction>
33 #include <KActionCollection>
34 #include <KStandardAction>
35 
36 
37 namespace Kasten2
38 {
39 
40 ZoomController::ZoomController( KXMLGUIClient* guiClient )
41  : mModel( 0 ), mZoomControl( 0 )
42 {
43  KActionCollection* actionCollection = guiClient->actionCollection();
44 
45  mZoomInAction = KStandardAction::zoomIn( this, SLOT(zoomIn()), actionCollection );
46  mZoomOutAction = KStandardAction::zoomOut( this, SLOT(zoomOut()), actionCollection );
47 
48 #if 0
49  ZoomToAction = new KSelectAction( i18n("Zoom"), "viewmag", 0, ActionCollection, "zoomTo" );
50  ZoomToAction->setEditable( true );
51  QList<double> mags = DisplayOptions::normalMagnificationValues();
52  QStringList translated;
53  int idx = 0;
54  int cur = 0;
55  for ( QList<double>::iterator first = mags.begin(), last = mags.end();
56  first != last;
57  ++first ) {
58  translated << i18nc( "zoom-factor (percentage)", "%1%", *first * 100.0 );
59  if ( *first == 1.0 ) idx = cur;
60  ++cur;
61  }
62  ZoomToAction->setItems( translated );
63  ZoomToAction->setCurrentItem( idx );
64  connect( ZoomToAction, SIGNAL(triggered(QString) ), SLOT(zoomTo(QString) ) );
65 
66  // TODO: name size relative to object or view? name object(variable) or view?
67  // TODO: is this a sticking parameter?
68  FitToWidthAction = new KAction( i18n( "&Fit to Width" ), ActionCollection, "fit_to_width" );
69  connect( FitWidthAction, SIGNAL(triggered(bool) ), SLOT(fitToWidth()));
70  FitToHeightAction = new KAction( i18n( "&Fit to Height" ), ActionCollection, "fit_to_height" );
71  connect( FitWidthAction, SIGNAL(triggered(bool) ), SLOT(fitToHeight()));
72  FitToSizeAction = new KAction( i18n( "&Fit to Size" ), ActionCollection, "fit_to_size" );
73  connect( FitToSizeAction, SIGNAL(triggered(bool) ), SLOT(fitToSize()));
74 #endif
75  setTargetModel( 0 );
76 }
77 
78 void ZoomController::setTargetModel( AbstractModel* model )
79 {
80  if( mModel ) mModel->disconnect( this );
81 
82  mModel = model ? model->findBaseModelWithInterface<If::Zoomable*>() : 0;
83  mZoomControl = mModel ? qobject_cast<If::Zoomable *>( mModel ) : 0;
84 
85  if( mZoomControl )
86  {
87  mZoomLevel = mZoomControl->zoomLevel();
88  connect( mModel, SIGNAL(zoomLevelChanged(double)), SLOT(onZoomLevelChange(double)) );
89  }
90 
91  const bool hasView = ( mZoomControl != 0 );
92  mZoomInAction->setEnabled( hasView );
93  mZoomOutAction->setEnabled( hasView );
94 }
95 
96 
97 void ZoomController::zoomIn()
98 {
99  mZoomControl->setZoomLevel( mZoomLevel * 1.10 );
100 }
101 
102 void ZoomController::zoomOut()
103 {
104  mZoomControl->setZoomLevel( mZoomLevel / 1.10 );
105 }
106 #if 0
107 void ZoomController::zoomTo( const QString& nz )
108 {
109  QString z = nz;
110  double zoom;
111  z.remove( z.indexOf( '%' ), 1 );
112  zoom = KGlobal::locale()->readNumber( z ) / 100;
113  kDebug( 4500 ) << "ZOOM = " << nz << ", setting zoom = " << zoom << endl;
114 
115  DisplayOptions options = miniWidget()->displayOptions();
116  options.setMagnification( zoom );
117  miniWidget()->setDisplayOptions( options );
118  miniWidget()->redisplay();
119  _mainWidget->setFocus();
120  updateZoomActions();
121 }
122 
123 void ZoomController::fitToWidth()
124 {
125  if( pageView()->page() )
126  miniWidget()->fitWidth( pageView()->viewport()->width() - 16 );
127  // We subtract 16 pixels because of the page decoration.
128  updateZoomActions();
129 }
130 
131 void ZoomController::fitToSize()
132 {
133  if( pageView()->page() )
134  miniWidget()->fitWidthHeight( pageView()->viewport()->width() - 16,
135  pageView()->viewport()->height() - 16 );
136  updateZoomActions();
137 }
138 #endif
139 void ZoomController::onZoomLevelChange( double level )
140 {
141  mZoomLevel = level;
142 }
143 
144 }
abstractmodel.h
zoomable.h
Kasten2::AbstractModel::findBaseModelWithInterface
AbstractModel * findBaseModelWithInterface() const
returns the first baseModel which is of type T, or null if none is found.
Definition: abstractmodel.h:109
Kasten2::If::Zoomable::setZoomLevel
virtual void setZoomLevel(double Level)=0
Kasten2::ZoomController::ZoomController
ZoomController(KXMLGUIClient *guiClient)
Definition: zoomcontroller.cpp:40
Kasten2::If::Zoomable
Definition: zoomable.h:37
Kasten2::If::Zoomable::zoomLevel
virtual double zoomLevel() const =0
Kasten2::ZoomController::setTargetModel
virtual void setTargetModel(AbstractModel *model)
Definition: zoomcontroller.cpp:78
zoomcontroller.h
Kasten2::AbstractModel
Definition: abstractmodel.h:40
QList
Definition: bookmarkable.h:29
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:09 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

okteta

Skip menu "okteta"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal