kivio

kivio_zoomaction.cpp
1/*
2 * Kivio - Visual Modelling and Flowcharting
3 * Copyright (C) 2000-2001 theKompany.com & Dave Marotti
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19#include "kivio_zoomaction.h"
20#include "tkcombobox.h"
21#include <tqregexp.h>
22
23#include <tdelocale.h>
24
25using namespace Kivio;
26
27ZoomAction::ZoomAction(TQObject* parent, const char* name)
28: TTDESelectAction(parent,name)
29{
30 setEditable(true);
31 TQStringList lst;
32 lst << i18n("%1%").arg("33");
33 lst << i18n("%1%").arg("50");
34 lst << i18n("%1%").arg("75");
35 lst << i18n("%1%").arg("100");
36 lst << i18n("%1%").arg("125");
37 lst << i18n("%1%").arg("150");
38 lst << i18n("%1%").arg("200");
39 lst << i18n("%1%").arg("250");
40 lst << i18n("%1%").arg("350");
41 lst << i18n("%1%").arg("400");
42 lst << i18n("%1%").arg("450");
43 lst << i18n("%1%").arg("500");
44 setItems(lst);
45}
46
47ZoomAction::~ZoomAction()
48{
49}
50
51void ZoomAction::slotActivated( const TQString& text )
52{
53 TQRegExp regexp("(\\d+)"); // "Captured" non-empty sequence of digits
54 regexp.search(text);
55 bool ok=false;
56 // Use templates, not macro to avoid to call the functiosn many times.
57 const int zoom=kMin(10000,kMax(10,regexp.cap(1).toInt(&ok)));
58 insertItem(zoom);
59
60 emit zoomActivated(zoom);
61}
62
63void ZoomAction::insertItem( int zoom )
64{
65 // This code is taken from KWords changeZoomMenu
66 TQValueList<int> list;
67 bool ok;
68 const TQStringList itemsList(items());
69 TQRegExp regexp("(\\d+)"); // "Captured" non-empty sequence of digits
70
71 for (TQStringList::ConstIterator it = itemsList.begin() ; it != itemsList.end() ; ++it) {
72 regexp.search(*it);
73 const int val=regexp.cap(1).toInt(&ok);
74 //zoom : limit inferior=10
75 if(ok && val>9 && list.contains(val)==0)
76 list.append( val );
77 }
78 //necessary at the beginning when we read config
79 //this value is not in combo list
80 if(list.contains(zoom)==0)
81 list.append( zoom );
82
83 qHeapSort( list );
84
85 TQStringList lst;
86 for (TQValueList<int>::Iterator it = list.begin() ; it != list.end() ; ++it)
87 lst.append( i18n("%1%").arg(*it) );
88 setItems(lst);
89 setCurrentItem(lst.findIndex(i18n("%1%").arg(zoom)));
90}
91
92void ZoomAction::setEditZoom( int zoom )
93{
94 const TQString zt(i18n("%1%").arg(zoom));
95 setEditText(zt);
96}
97#include "kivio_zoomaction.moc"