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