kozoomaction.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <kozoomaction.h>
00020
00021 #include <qstring.h>
00022 #include <qstringlist.h>
00023 #include <qregexp.h>
00024 #include <qvaluelist.h>
00025
00026 #include <klocale.h>
00027
00028 KoZoomAction::KoZoomAction( const QString& text, const QIconSet& pix,
00029 const KShortcut& cut, QObject* parent, const char* name ):
00030 KSelectAction( text, pix, cut, parent, name )
00031 {
00032 init();
00033 }
00034
00035 KoZoomAction::KoZoomAction( const QString& text, const QString& pix,
00036 const KShortcut& cut, QObject* parent, const char* name ):
00037 KSelectAction( text, pix, cut, parent, name )
00038 {
00039 init();
00040
00041 }
00042
00043 void KoZoomAction::setZoom( const QString& text )
00044 {
00045 bool ok = false;
00046 QString t = text;
00047 int zoom = t.remove( '%' ).toInt( &ok );
00048
00049
00050 QValueList<int> list;
00051 if( zoom > 10 ) list.append( zoom );
00052
00053
00054 QRegExp regexp("(\\d+)");
00055
00056 const QStringList itemsList( items() );
00057 for( QStringList::ConstIterator it = itemsList.begin(); it != itemsList.end(); ++it )
00058 {
00059 regexp.search( *it );
00060 const int val=regexp.cap(1).toInt( &ok );
00061
00062
00063 if( ok && val>9 && list.contains( val )==0 )
00064 list.append( val );
00065 }
00066
00067 qHeapSort( list );
00068
00069
00070 QStringList values;
00071 for (QValueList<int>::Iterator it = list.begin(); it != list.end(); ++it )
00072 values.append( i18n("%1%").arg(*it) );
00073 setItems( values );
00074
00075 QString zoomStr = i18n("%1%").arg( zoom );
00076 setCurrentItem( values.findIndex( zoomStr ) );
00077 }
00078
00079 void KoZoomAction::setZoom( int zoom )
00080 {
00081 setZoom( QString::number( zoom ) );
00082 }
00083
00084 void KoZoomAction::activated( const QString& text )
00085 {
00086 setZoom( text );
00087 emit zoomChanged( text );
00088 }
00089
00090 void KoZoomAction::init()
00091 {
00092 setEditable( true );
00093
00094 QStringList values;
00095 values << i18n("%1%").arg("33");
00096 values << i18n("%1%").arg("50");
00097 values << i18n("%1%").arg("75");
00098 values << i18n("%1%").arg("100");
00099 values << i18n("%1%").arg("125");
00100 values << i18n("%1%").arg("150");
00101 values << i18n("%1%").arg("200");
00102 values << i18n("%1%").arg("250");
00103 values << i18n("%1%").arg("350");
00104 values << i18n("%1%").arg("400");
00105 values << i18n("%1%").arg("450");
00106 values << i18n("%1%").arg("500");
00107 setItems( values );
00108
00109 setCurrentItem( values.findIndex( i18n("%1%").arg( 100 ) ) );
00110
00111 connect( this, SIGNAL( activated( const QString& ) ),
00112 SLOT( activated( const QString& ) ) );
00113 }
00114
00115 #include "kozoomaction.moc"
This file is part of the documentation for lib Library Version 1.4.2.