kivio
kivio_zoomaction.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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+)");
00054 regexp.search(text);
00055 bool ok=false;
00056
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
00066 QValueList<int> list;
00067 bool ok;
00068 const QStringList itemsList(items());
00069 QRegExp regexp("(\\d+)");
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
00075 if(ok && val>9 && list.contains(val)==0)
00076 list.append( val );
00077 }
00078
00079
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"
|