kivio

kivio_zoomaction.cpp

00001 /*
00002  * Kivio - Visual Modelling and Flowcharting
00003  * Copyright (C) 2000-2001 theKompany.com & Dave Marotti
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00018  */
00019 #include "kivio_zoomaction.h"
00020 #include "tkcombobox.h"
00021 #include <qregexp.h>
00022 
00023 #include <klocale.h>
00024 
00025 using namespace Kivio;
00026 
00027 ZoomAction::ZoomAction(QObject* parent, const char* name)
00028 : TKSelectAction(parent,name)
00029 {
00030   setEditable(true);
00031   QStringList lst;
00032   lst << i18n("%1%").arg("33");
00033   lst << i18n("%1%").arg("50");
00034   lst << i18n("%1%").arg("75");
00035   lst << i18n("%1%").arg("100");
00036   lst << i18n("%1%").arg("125");
00037   lst << i18n("%1%").arg("150");
00038   lst << i18n("%1%").arg("200");
00039   lst << i18n("%1%").arg("250");
00040   lst << i18n("%1%").arg("350");
00041   lst << i18n("%1%").arg("400");
00042   lst << i18n("%1%").arg("450");
00043   lst << i18n("%1%").arg("500");
00044   setItems(lst);
00045 }
00046 
00047 ZoomAction::~ZoomAction()
00048 {
00049 }
00050 
00051 void ZoomAction::slotActivated( const QString& text )
00052 {
00053   QRegExp regexp("(\\d+)"); // "Captured" non-empty sequence of digits
00054   regexp.search(text);
00055   bool ok=false;
00056   // Use templates, not macro to avoid to call the functiosn many times.
00057   const int zoom=kMin(10000,kMax(10,regexp.cap(1).toInt(&ok)));
00058   insertItem(zoom);
00059 
00060   emit zoomActivated(zoom);
00061 }
00062 
00063 void ZoomAction::insertItem( int zoom )
00064 {
00065   // This code is taken from KWords changeZoomMenu
00066   QValueList<int> list;
00067   bool ok;
00068   const QStringList itemsList(items());
00069   QRegExp regexp("(\\d+)"); // "Captured" non-empty sequence of digits
00070 
00071   for (QStringList::ConstIterator it = itemsList.begin() ; it != itemsList.end() ; ++it) {
00072     regexp.search(*it);
00073     const int val=regexp.cap(1).toInt(&ok);
00074     //zoom : limit inferior=10
00075     if(ok && val>9 && list.contains(val)==0)
00076       list.append( val );
00077   }
00078   //necessary at the beginning when we read config
00079   //this value is not in combo list
00080   if(list.contains(zoom)==0)
00081     list.append( zoom );
00082 
00083   qHeapSort( list );
00084 
00085   QStringList lst;
00086   for (QValueList<int>::Iterator it = list.begin() ; it != list.end() ; ++it)
00087     lst.append( i18n("%1%").arg(*it) );
00088   setItems(lst);
00089   setCurrentItem(lst.findIndex(i18n("%1%").arg(zoom)));
00090 }
00091 
00092 void ZoomAction::setEditZoom( int zoom )
00093 {
00094   const QString zt(i18n("%1%").arg(zoom));
00095   setEditText(zt);
00096 }
00097 #include "kivio_zoomaction.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys