• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kviewshell

zoom.cpp

Go to the documentation of this file.
00001 // zoom.cpp
00002 //
00003 // Part of KVIEWSHELL - A framework for multipage text/gfx viewers
00004 //
00005 // (C) 2002 Stefan Kebekus
00006 // Distributed under the GPL
00007 
00008 // Add header files alphabetically
00009 
00010 #include <config.h>
00011 
00012 #include <math.h>
00013 #include <qstringlist.h>
00014 
00015 #include <klocale.h>
00016 
00017 #include "zoom.h"
00018 #include "zoomlimits.h"
00019 
00020 float zoomVals[] = {0.20, 0.33, 0.50, 0.75, 1.00, 1.25, 1.50, 2.00, 2.50, 0};
00021 
00022 Zoom::Zoom()
00023 {
00024   valueNames << i18n("Fit to Page Width");
00025   valueNames << i18n("Fit to Page Height");
00026   valueNames << i18n("Fit to Page");
00027 
00028   _zoomValue = 1.0;
00029   valNo      = 6; // 1.0 is 6rd entry in the list
00030   for(int i=0; zoomVals[i] != 0; i++) 
00031     valueNames << QString("%1%").arg(zoomVals[i]);
00032 }
00033 
00034 
00035 void Zoom::setZoomValue(const QString &cval)
00036 {
00037   float fval;
00038 
00039   // Remove a trailing '%', if any
00040   QString val = cval.stripWhiteSpace();
00041   if (val.right(1) == "%")
00042     val = val.left(val.length()-1).stripWhiteSpace();
00043 
00044   bool ok;
00045   fval = val.toFloat(&ok)/100.0;
00046 
00047   if (ok == true)
00048     setZoomValue(fval);
00049   else {
00050     emit(zoomNamesChanged(valueNames));
00051     emit(valNoChanged(valNo));
00052     emit(zoomNameChanged(QString("%1%").arg((int)(_zoomValue*100.0+0.5))));
00053   }
00054 }
00055 
00056 void Zoom::setZoomFitWidth(float zoom)
00057 {
00058   // Make sure _zoomValue is in the permissible range!
00059   if (zoom < ZoomLimits::MinZoom/1000.0)
00060     zoom = ZoomLimits::MinZoom/1000.0;
00061   if (zoom > ZoomLimits::MaxZoom/1000.0)
00062     zoom = ZoomLimits::MaxZoom/1000.0;
00063   _zoomValue = zoom;
00064 
00065   valNo = 0;
00066   emit(valNoChanged(valNo));
00067   emit(zoomNameChanged(QString("%1%").arg((int)(_zoomValue*100.0+0.5))));
00068 }
00069 
00070 void Zoom::setZoomFitHeight(float zoom)
00071 {
00072   // Make sure _zoomValue is in the permissible range!
00073   if (zoom < ZoomLimits::MinZoom/1000.0)
00074     zoom = ZoomLimits::MinZoom/1000.0;
00075   if (zoom > ZoomLimits::MaxZoom/1000.0)
00076     zoom = ZoomLimits::MaxZoom/1000.0;
00077   _zoomValue = zoom;
00078 
00079   valNo = 1;
00080   emit(valNoChanged(valNo));
00081   emit(zoomNameChanged(QString("%1%").arg((int)(_zoomValue*100.0+0.5))));
00082 }
00083 
00084 void Zoom::setZoomFitPage(float zoom)
00085 {
00086   // Make sure _zoomValue is in the permissible range!
00087   if (zoom < ZoomLimits::MinZoom/1000.0)
00088     zoom = ZoomLimits::MinZoom/1000.0;
00089   if (zoom > ZoomLimits::MaxZoom/1000.0)
00090     zoom = ZoomLimits::MaxZoom/1000.0;
00091   _zoomValue = zoom;
00092 
00093   valNo = 2;
00094   emit(valNoChanged(valNo));
00095   emit(zoomNameChanged(QString("%1%").arg((int)(_zoomValue*100.0+0.5))));
00096 }
00097 
00098 void Zoom::setZoomValue(float f)
00099 {
00100   // Make sure _zoomValue is in the permissible range!
00101   if (f < ZoomLimits::MinZoom/1000.0)
00102     f = ZoomLimits::MinZoom/1000.0;
00103   if (f > ZoomLimits::MaxZoom/1000.0)
00104     f = ZoomLimits::MaxZoom/1000.0;
00105   _zoomValue = f;
00106 
00107 
00108   valueNames.clear();
00109 
00110   valueNames << i18n("Fit to Page Width");
00111   valueNames << i18n("Fit to Page Height");
00112   valueNames << i18n("Fit to Page");
00113 
00114   bool flag = false;
00115   for(int i = 0; zoomVals[i] != 0; i++) {
00116     if ((_zoomValue <= zoomVals[i]) && (flag == false)) {
00117       flag  = true;
00118       valNo = i + 3;
00119       if (fabs(_zoomValue-zoomVals[i]) > 0.01)
00120         valueNames << QString("%1%").arg((int)(_zoomValue*100.0+0.5));
00121     }
00122     valueNames << QString("%1%").arg((int)(zoomVals[i]*100.0+0.5));
00123   }
00124 
00125   if (flag == false) {
00126     valNo = valueNames.size();
00127     valueNames << QString("%1%").arg((int)(_zoomValue*100.0+0.5));
00128   }
00129 
00130   emit(zoomNamesChanged(valueNames));
00131   emit(valNoChanged(valNo));
00132   emit(zoomNameChanged(QString("%1%").arg((int)(_zoomValue*100.0+0.5))));
00133 }
00134 
00135 float Zoom::zoomIn()
00136 {
00137   int i;
00138   for(i=0; zoomVals[i] != 0; i++) 
00139     if (zoomVals[i] > _zoomValue)
00140       return zoomVals[i];
00141 
00142   return zoomVals[i-1];
00143 }
00144 
00145 float Zoom::zoomOut()
00146 {
00147   float result = zoomVals[0];
00148 
00149   for(int i=0; zoomVals[i] != 0; i++) 
00150     if (_zoomValue > zoomVals[i])
00151       result = zoomVals[i];
00152 
00153   return result;
00154 }
00155 
00156 #include "zoom.moc"

kviewshell

Skip menu "kviewshell"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • kviewshell
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal