summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-01-27 14:15:50 (UTC)
committer zautrix <zautrix>2005-01-27 14:15:50 (UTC)
commitcd1b9287f2bcd59652ef66186d00dcf5ff8a2a46 (patch) (unidiff)
tree99db53425edb1c68cd880e8221805e0f84ae9a75
parent32ad6c6cc658d952c9dfa1fcf5857662bcf01c22 (diff)
downloadkdepimpi-cd1b9287f2bcd59652ef66186d00dcf5ff8a2a46.zip
kdepimpi-cd1b9287f2bcd59652ef66186d00dcf5ff8a2a46.tar.gz
kdepimpi-cd1b9287f2bcd59652ef66186d00dcf5ff8a2a46.tar.bz2
jump 1
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/jumpbuttonbar.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/kaddressbook/jumpbuttonbar.cpp b/kaddressbook/jumpbuttonbar.cpp
index 184d516..b12d9e7 100644
--- a/kaddressbook/jumpbuttonbar.cpp
+++ b/kaddressbook/jumpbuttonbar.cpp
@@ -1,233 +1,240 @@
1/* 1/*
2 This file is part of KAddressBook. 2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com> 3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 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 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#include <qevent.h> 24#include <qevent.h>
25#include <qlayout.h> 25#include <qlayout.h>
26#include <qpushbutton.h> 26#include <qpushbutton.h>
27#include <qstring.h> 27#include <qstring.h>
28#include <qtl.h> 28#include <qtl.h>
29#include <qapplication.h> 29#include <qapplication.h>
30 30
31#include <kabc/addressbook.h> 31#include <kabc/addressbook.h>
32#include <kabc/field.h> 32#include <kabc/field.h>
33#include <kdebug.h> 33#include <kdebug.h>
34#include <klocale.h> 34#include <klocale.h>
35 35
36#include "kabcore.h" 36#include "kabcore.h"
37 37
38#include "jumpbuttonbar.h" 38#include "jumpbuttonbar.h"
39 39
40class JumpButton : public QPushButton 40class JumpButton : public QPushButton
41{ 41{
42 public: 42 public:
43 JumpButton( const QString &text, QWidget *parent, 43 JumpButton( const QString &text, QWidget *parent,
44 const QString &character ); 44 const QString &character );
45 45
46 void setCharacter( const QString &character ); 46 void setCharacter( const QString &character );
47 QString character() const; 47 QString character() const;
48 48
49 private: 49 private:
50 QString mCharacter; 50 QString mCharacter;
51}; 51};
52 52
53JumpButton::JumpButton( const QString &text, QWidget *parent, 53JumpButton::JumpButton( const QString &text, QWidget *parent,
54 const QString &character ) 54 const QString &character )
55 : QPushButton( text, parent ) 55 : QPushButton( text, parent )
56{ 56{
57 mCharacter = character; 57 mCharacter = character;
58} 58}
59 59
60void JumpButton::setCharacter( const QString &character ) 60void JumpButton::setCharacter( const QString &character )
61{ 61{
62 mCharacter = character; 62 mCharacter = character;
63 setText(mCharacter.upper() ); 63 setText(mCharacter.upper() );
64} 64}
65 65
66QString JumpButton::character() const 66QString JumpButton::character() const
67{ 67{
68 return mCharacter; 68 return mCharacter;
69} 69}
70 70
71JumpButtonBar::JumpButtonBar( KABCore *core, QWidget *parent, const char *name ) 71JumpButtonBar::JumpButtonBar( KABCore *core, QWidget *parent, const char *name )
72 : QWidget( parent, name ), mCore( core ) 72 : QWidget( parent, name ), mCore( core )
73{ 73{
74 if ( QApplication::desktop()->width() < 480 ) 74 if ( QApplication::desktop()->width() < 480 )
75 75
76 mButtonLayout = new QGridLayout( this, 2, 14 ); 76 mButtonLayout = new QGridLayout( this, 2, 14 );
77 else 77 else
78 mButtonLayout = new QGridLayout( this, 1, 28 ); 78 mButtonLayout = new QGridLayout( this, 1, 28 );
79 mButtonLayout->setAlignment( Qt::AlignTop ); 79 mButtonLayout->setAlignment( Qt::AlignTop );
80 80
81 recreateButtons(); 81 recreateButtons();
82} 82}
83 83
84JumpButtonBar::~JumpButtonBar() 84JumpButtonBar::~JumpButtonBar()
85{ 85{
86} 86}
87 87
88QSizePolicy JumpButtonBar::sizePolicy() const 88QSizePolicy JumpButtonBar::sizePolicy() const
89{ 89{
90#ifndef KAB_EMBEDDED 90#ifndef KAB_EMBEDDED
91 return QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Minimum, 91 return QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Minimum,
92 QSizePolicy::Vertically ); 92 QSizePolicy::Vertically );
93#else //KAB_EMBEDDED 93#else //KAB_EMBEDDED
94 return QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Minimum); 94 return QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Minimum);
95#endif //KAB_EMBEDDED 95#endif //KAB_EMBEDDED
96} 96}
97 97
98void JumpButtonBar::letterClicked() 98void JumpButtonBar::letterClicked()
99{ 99{
100 JumpButton *button = (JumpButton*)sender(); 100 JumpButton *button = (JumpButton*)sender();
101 QString character = button->character(); 101 QString character = button->character();
102 if ( character.length() == 2 )
103 character = character.left(1) +"-"+character.right(1);
102 if ( !character.isNull() ) 104 if ( !character.isNull() )
103 emit jumpToLetter( character ); 105 emit jumpToLetter( character );
106 //qDebug("emit *%s* ",character.latin1());
104} 107}
105 108
106void JumpButtonBar::recreateButtons() 109void JumpButtonBar::recreateButtons()
107{ 110{
108 // the easiest way to remove all buttons ;) 111 // the easiest way to remove all buttons ;)
109 //mButtons.setAutoDelete( true ); 112 //mButtons.setAutoDelete( true );
110 //mButtons.clear(); 113 //mButtons.clear();
111 //mButtons.setAutoDelete( false ); 114 //mButtons.setAutoDelete( false );
112 mCharacters.clear(); 115 mCharacters.clear();
113 116
114 QString character; 117 QString character;
115 118
116 KABC::AddressBook *ab = mCore->addressBook(); 119 KABC::AddressBook *ab = mCore->addressBook();
117 KABC::AddressBook::Iterator it; 120 KABC::AddressBook::Iterator it;
118 KABC::Field *field = mCore->currentSearchField(); 121 KABC::Field *field = mCore->currentSearchField();
119 if ( field ) { 122 if ( field ) {
120 setEnabled( true ); 123 setEnabled( true );
121 } else { 124 } else {
122 setEnabled( false ); 125 setEnabled( false );
123 return; 126 return;
124 } 127 }
128 mCharacters.append( "*");
125 for ( it = ab->begin(); it != ab->end(); ++it ) { 129 for ( it = ab->begin(); it != ab->end(); ++it ) {
126 if ( !field->value( *it ).isEmpty() ) 130 if ( !field->value( *it ).isEmpty() )
127 character = field->value( *it )[ 0 ].lower(); 131 character = field->value( *it )[ 0 ].lower();
128 if ( character != "!" ) 132 if ( character != "!" )
129 if ( !character.isEmpty() && !mCharacters.contains( character ) ) 133 if ( !character.isEmpty() && !mCharacters.contains( character ) )
130 mCharacters.append( character ); 134 mCharacters.append( character );
131 } 135 }
132 if ( mCharacters.count() == 0 ) { 136 if ( mCharacters.count() == 0 ) {
133 setEnabled( false ); 137 setEnabled( false );
134 return; 138 return;
135 } 139 }
136 140
137 int maxRows = mCharacters.count() / 2; // we use 2 columns 141 int maxRows = mCharacters.count() / 2; // we use 2 columns
138 if ( mCharacters.count() % 2 ) 142 if ( mCharacters.count() % 2 )
139 maxRows++; 143 maxRows++;
140 int fixwid = 20; 144 int fixwid = 20;
141 sortListLocaleAware( mCharacters ); 145 sortListLocaleAware( mCharacters );
142 bool skip2 = false; 146 bool skip2 = false;
143 int skipcount = 0; 147 int skipcount = 0;
144 int maxHei = 25; 148 int maxHei = 25;
145 if ( QApplication::desktop()->width() < 480 && mCharacters.count() > 13) { 149 if ( QApplication::desktop()->width() < 480 && mCharacters.count() > 13) {
146 skipcount = mCharacters.count()-13; 150 skipcount = mCharacters.count()-13;
147 maxHei = (QApplication::desktop()->height()-65)/13; 151 maxHei = (QApplication::desktop()->height()-65)/13;
148 } 152 }
149 else { 153 else {
150 fixwid = 30; 154 fixwid = 30;
151 if ( mCharacters.count() > 20 ) 155 if ( mCharacters.count() > 20 )
152 skipcount = mCharacters.count()- 20; 156 skipcount = mCharacters.count()- 20;
153 maxHei = (QApplication::desktop()->height()-120)/(mCharacters.count()-skipcount); 157 maxHei = (QApplication::desktop()->height()-120)/(mCharacters.count()-skipcount);
154 158
155 } 159 }
156 maxRows = 28; 160 maxRows = 28;
157 bool skipcurrent = false; 161 bool skipcurrent = false;
158 bool state = isUpdatesEnabled(); 162 bool state = isUpdatesEnabled();
159 setUpdatesEnabled( false ); 163 setUpdatesEnabled( false );
160 //qDebug("cc %d ",mCharacters.count() ); 164 //qDebug("cc %d ",mCharacters.count() );
161 JumpButton *button; 165 JumpButton *button = 0;
162 int row = 0, col = 0; 166 int row = 0, col = 0;
163 JumpButton* cur = mButtons.first(); 167 JumpButton* cur = mButtons.first();
164 for ( uint i = 0; i < mCharacters.count(); ++i ) { 168 for ( uint i = 0; i < mCharacters.count(); ++i ) {
165 if ( skipcount > 0 && skipcurrent ) { 169 if ( skipcount > 0 && skipcurrent ) {
166 --skipcount; 170 --skipcount;
171 if ( button ) {
172 button->setCharacter( button->character() + mCharacters[ i ]);
173 }
167 } else { 174 } else {
168 if ( cur ) { 175 if ( cur ) {
169 button = cur ; 176 button = cur ;
170 cur = mButtons.next(); 177 cur = mButtons.next();
171 button->setCharacter(mCharacters[ i ]); 178 button->setCharacter(mCharacters[ i ]);
172 } else { 179 } else {
173 button = new JumpButton( mCharacters[ i ].upper(), this, mCharacters[ i ] ); 180 button = new JumpButton( mCharacters[ i ].upper(), this, mCharacters[ i ] );
174 button->setFixedWidth( fixwid ); 181 button->setFixedWidth( fixwid );
175 mButtons.append( button ); 182 mButtons.append( button );
176 connect( button, SIGNAL( clicked() ), this, SLOT( letterClicked() ) ); 183 connect( button, SIGNAL( clicked() ), this, SLOT( letterClicked() ) );
177 mButtonLayout->addWidget( button, row, col ); 184 mButtonLayout->addWidget( button, row, col );
178 } 185 }
179 button->setMaximumHeight( maxHei ); 186 button->setMaximumHeight( maxHei );
180 button->show(); 187 button->show();
181 188
182 if ( col == maxRows ) { 189 if ( col == maxRows ) {
183 row = 0; 190 row = 0;
184 col++; 191 col++;
185 } else 192 } else
186 row++; 193 row++;
187 } 194 }
188 195 if ( i > 0 )
189 skipcurrent = !skipcurrent; 196 skipcurrent = !skipcurrent;
190 } 197 }
191 while ( cur ) { 198 while ( cur ) {
192 cur->hide(); 199 cur->hide();
193 cur = mButtons.next(); 200 cur = mButtons.next();
194 } 201 }
195 202
196 mButtonLayout->activate(); 203 mButtonLayout->activate();
197 setUpdatesEnabled( state ); 204 setUpdatesEnabled( state );
198 update(); 205 update();
199} 206}
200 207
201void JumpButtonBar::sortListLocaleAware( QStringList &list ) 208void JumpButtonBar::sortListLocaleAware( QStringList &list )
202{ 209{
203 QStringList::Iterator beginIt = list.begin(); 210 QStringList::Iterator beginIt = list.begin();
204 QStringList::Iterator endIt = list.end(); 211 QStringList::Iterator endIt = list.end();
205 212
206 --endIt; 213 --endIt;
207 if ( beginIt == endIt ) // don't need sorting 214 if ( beginIt == endIt ) // don't need sorting
208 return; 215 return;
209 216
210 QStringList::Iterator walkBackIt = endIt; 217 QStringList::Iterator walkBackIt = endIt;
211 while ( beginIt != endIt ) { 218 while ( beginIt != endIt ) {
212 QStringList::Iterator j1 = list.begin(); 219 QStringList::Iterator j1 = list.begin();
213 QStringList::Iterator j2 = j1; 220 QStringList::Iterator j2 = j1;
214 ++j2; 221 ++j2;
215 while ( j1 != walkBackIt ) { 222 while ( j1 != walkBackIt ) {
216#ifndef KAB_EMBEDDED 223#ifndef KAB_EMBEDDED
217 if ( QString::localeAwareCompare( *j2, *j1 ) < 0 ) 224 if ( QString::localeAwareCompare( *j2, *j1 ) < 0 )
218#else //KAB_EMBEDDED 225#else //KAB_EMBEDDED
219 if ( QString::compare( *j2, *j1 ) < 0 ) 226 if ( QString::compare( *j2, *j1 ) < 0 )
220#endif //KAB_EMBEDDED 227#endif //KAB_EMBEDDED
221 qSwap( *j1, *j2 ); 228 qSwap( *j1, *j2 );
222 229
223 ++j1; 230 ++j1;
224 ++j2; 231 ++j2;
225 } 232 }
226 ++beginIt; 233 ++beginIt;
227 --walkBackIt; 234 --walkBackIt;
228 } 235 }
229} 236}
230 237
231#ifndef KAB_EMBEDDED 238#ifndef KAB_EMBEDDED
232#include "jumpbuttonbar.moc" 239#include "jumpbuttonbar.moc"
233#endif //KAB_EMBEDDED 240#endif //KAB_EMBEDDED