author | zautrix <zautrix> | 2005-01-19 14:35:53 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-01-19 14:35:53 (UTC) |
commit | a9f8ad6916ea1a849a43fe49c4085f6c44b5c47b (patch) (unidiff) | |
tree | a649fbc1c07e2c199833da1a23cf326d68406d4b /kaddressbook | |
parent | 0d878a0144644499ead17b2532cc94abb545bcdb (diff) | |
download | kdepimpi-a9f8ad6916ea1a849a43fe49c4085f6c44b5c47b.zip kdepimpi-a9f8ad6916ea1a849a43fe49c4085f6c44b5c47b.tar.gz kdepimpi-a9f8ad6916ea1a849a43fe49c4085f6c44b5c47b.tar.bz2 |
dislog size fixes
-rw-r--r-- | kaddressbook/jumpbuttonbar.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/kaddressbook/jumpbuttonbar.cpp b/kaddressbook/jumpbuttonbar.cpp index ee5b44e..184d516 100644 --- a/kaddressbook/jumpbuttonbar.cpp +++ b/kaddressbook/jumpbuttonbar.cpp | |||
@@ -1,232 +1,233 @@ | |||
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 | ||
40 | class JumpButton : public QPushButton | 40 | class 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 | ||
53 | JumpButton::JumpButton( const QString &text, QWidget *parent, | 53 | JumpButton::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 | ||
60 | void JumpButton::setCharacter( const QString &character ) | 60 | void 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 | ||
66 | QString JumpButton::character() const | 66 | QString JumpButton::character() const |
67 | { | 67 | { |
68 | return mCharacter; | 68 | return mCharacter; |
69 | } | 69 | } |
70 | 70 | ||
71 | JumpButtonBar::JumpButtonBar( KABCore *core, QWidget *parent, const char *name ) | 71 | JumpButtonBar::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 | ||
84 | JumpButtonBar::~JumpButtonBar() | 84 | JumpButtonBar::~JumpButtonBar() |
85 | { | 85 | { |
86 | } | 86 | } |
87 | 87 | ||
88 | QSizePolicy JumpButtonBar::sizePolicy() const | 88 | QSizePolicy 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 | ||
98 | void JumpButtonBar::letterClicked() | 98 | void 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.isNull() ) | 102 | if ( !character.isNull() ) |
103 | emit jumpToLetter( character ); | 103 | emit jumpToLetter( character ); |
104 | } | 104 | } |
105 | 105 | ||
106 | void JumpButtonBar::recreateButtons() | 106 | void JumpButtonBar::recreateButtons() |
107 | { | 107 | { |
108 | // the easiest way to remove all buttons ;) | 108 | // the easiest way to remove all buttons ;) |
109 | //mButtons.setAutoDelete( true ); | 109 | //mButtons.setAutoDelete( true ); |
110 | //mButtons.clear(); | 110 | //mButtons.clear(); |
111 | //mButtons.setAutoDelete( false ); | 111 | //mButtons.setAutoDelete( false ); |
112 | mCharacters.clear(); | 112 | mCharacters.clear(); |
113 | 113 | ||
114 | QString character; | 114 | QString character; |
115 | 115 | ||
116 | KABC::AddressBook *ab = mCore->addressBook(); | 116 | KABC::AddressBook *ab = mCore->addressBook(); |
117 | KABC::AddressBook::Iterator it; | 117 | KABC::AddressBook::Iterator it; |
118 | KABC::Field *field = mCore->currentSearchField(); | 118 | KABC::Field *field = mCore->currentSearchField(); |
119 | if ( field ) { | 119 | if ( field ) { |
120 | setEnabled( true ); | 120 | setEnabled( true ); |
121 | } else { | 121 | } else { |
122 | setEnabled( false ); | 122 | setEnabled( false ); |
123 | return; | 123 | return; |
124 | } | 124 | } |
125 | for ( it = ab->begin(); it != ab->end(); ++it ) { | 125 | for ( it = ab->begin(); it != ab->end(); ++it ) { |
126 | if ( !field->value( *it ).isEmpty() ) | 126 | if ( !field->value( *it ).isEmpty() ) |
127 | character = field->value( *it )[ 0 ].lower(); | 127 | character = field->value( *it )[ 0 ].lower(); |
128 | if ( !character.isEmpty() && !mCharacters.contains( character ) ) | 128 | if ( character != "!" ) |
129 | if ( !character.isEmpty() && !mCharacters.contains( character ) ) | ||
129 | mCharacters.append( character ); | 130 | mCharacters.append( character ); |
130 | } | 131 | } |
131 | if ( mCharacters.count() == 0 ) { | 132 | if ( mCharacters.count() == 0 ) { |
132 | setEnabled( false ); | 133 | setEnabled( false ); |
133 | return; | 134 | return; |
134 | } | 135 | } |
135 | 136 | ||
136 | int maxRows = mCharacters.count() / 2; // we use 2 columns | 137 | int maxRows = mCharacters.count() / 2; // we use 2 columns |
137 | if ( mCharacters.count() % 2 ) | 138 | if ( mCharacters.count() % 2 ) |
138 | maxRows++; | 139 | maxRows++; |
139 | int fixwid = 20; | 140 | int fixwid = 20; |
140 | sortListLocaleAware( mCharacters ); | 141 | sortListLocaleAware( mCharacters ); |
141 | bool skip2 = false; | 142 | bool skip2 = false; |
142 | int skipcount = 0; | 143 | int skipcount = 0; |
143 | int maxHei = 25; | 144 | int maxHei = 25; |
144 | if ( QApplication::desktop()->width() < 480 && mCharacters.count() > 13) { | 145 | if ( QApplication::desktop()->width() < 480 && mCharacters.count() > 13) { |
145 | skipcount = mCharacters.count()-13; | 146 | skipcount = mCharacters.count()-13; |
146 | maxHei = (QApplication::desktop()->height()-65)/13; | 147 | maxHei = (QApplication::desktop()->height()-65)/13; |
147 | } | 148 | } |
148 | else { | 149 | else { |
149 | fixwid = 30; | 150 | fixwid = 30; |
150 | if ( mCharacters.count() > 20 ) | 151 | if ( mCharacters.count() > 20 ) |
151 | skipcount = mCharacters.count()- 20; | 152 | skipcount = mCharacters.count()- 20; |
152 | maxHei = (QApplication::desktop()->height()-120)/(mCharacters.count()-skipcount); | 153 | maxHei = (QApplication::desktop()->height()-120)/(mCharacters.count()-skipcount); |
153 | 154 | ||
154 | } | 155 | } |
155 | maxRows = 28; | 156 | maxRows = 28; |
156 | bool skipcurrent = false; | 157 | bool skipcurrent = false; |
157 | bool state = isUpdatesEnabled(); | 158 | bool state = isUpdatesEnabled(); |
158 | setUpdatesEnabled( false ); | 159 | setUpdatesEnabled( false ); |
159 | //qDebug("cc %d ",mCharacters.count() ); | 160 | //qDebug("cc %d ",mCharacters.count() ); |
160 | JumpButton *button; | 161 | JumpButton *button; |
161 | int row = 0, col = 0; | 162 | int row = 0, col = 0; |
162 | JumpButton* cur = mButtons.first(); | 163 | JumpButton* cur = mButtons.first(); |
163 | for ( uint i = 0; i < mCharacters.count(); ++i ) { | 164 | for ( uint i = 0; i < mCharacters.count(); ++i ) { |
164 | if ( skipcount > 0 && skipcurrent ) { | 165 | if ( skipcount > 0 && skipcurrent ) { |
165 | --skipcount; | 166 | --skipcount; |
166 | } else { | 167 | } else { |
167 | if ( cur ) { | 168 | if ( cur ) { |
168 | button = cur ; | 169 | button = cur ; |
169 | cur = mButtons.next(); | 170 | cur = mButtons.next(); |
170 | button->setCharacter(mCharacters[ i ]); | 171 | button->setCharacter(mCharacters[ i ]); |
171 | } else { | 172 | } else { |
172 | button = new JumpButton( mCharacters[ i ].upper(), this, mCharacters[ i ] ); | 173 | button = new JumpButton( mCharacters[ i ].upper(), this, mCharacters[ i ] ); |
173 | button->setFixedWidth( fixwid ); | 174 | button->setFixedWidth( fixwid ); |
174 | mButtons.append( button ); | 175 | mButtons.append( button ); |
175 | connect( button, SIGNAL( clicked() ), this, SLOT( letterClicked() ) ); | 176 | connect( button, SIGNAL( clicked() ), this, SLOT( letterClicked() ) ); |
176 | mButtonLayout->addWidget( button, row, col ); | 177 | mButtonLayout->addWidget( button, row, col ); |
177 | } | 178 | } |
178 | button->setMaximumHeight( maxHei ); | 179 | button->setMaximumHeight( maxHei ); |
179 | button->show(); | 180 | button->show(); |
180 | 181 | ||
181 | if ( col == maxRows ) { | 182 | if ( col == maxRows ) { |
182 | row = 0; | 183 | row = 0; |
183 | col++; | 184 | col++; |
184 | } else | 185 | } else |
185 | row++; | 186 | row++; |
186 | } | 187 | } |
187 | 188 | ||
188 | skipcurrent = !skipcurrent; | 189 | skipcurrent = !skipcurrent; |
189 | } | 190 | } |
190 | while ( cur ) { | 191 | while ( cur ) { |
191 | cur->hide(); | 192 | cur->hide(); |
192 | cur = mButtons.next(); | 193 | cur = mButtons.next(); |
193 | } | 194 | } |
194 | 195 | ||
195 | mButtonLayout->activate(); | 196 | mButtonLayout->activate(); |
196 | setUpdatesEnabled( state ); | 197 | setUpdatesEnabled( state ); |
197 | update(); | 198 | update(); |
198 | } | 199 | } |
199 | 200 | ||
200 | void JumpButtonBar::sortListLocaleAware( QStringList &list ) | 201 | void JumpButtonBar::sortListLocaleAware( QStringList &list ) |
201 | { | 202 | { |
202 | QStringList::Iterator beginIt = list.begin(); | 203 | QStringList::Iterator beginIt = list.begin(); |
203 | QStringList::Iterator endIt = list.end(); | 204 | QStringList::Iterator endIt = list.end(); |
204 | 205 | ||
205 | --endIt; | 206 | --endIt; |
206 | if ( beginIt == endIt ) // don't need sorting | 207 | if ( beginIt == endIt ) // don't need sorting |
207 | return; | 208 | return; |
208 | 209 | ||
209 | QStringList::Iterator walkBackIt = endIt; | 210 | QStringList::Iterator walkBackIt = endIt; |
210 | while ( beginIt != endIt ) { | 211 | while ( beginIt != endIt ) { |
211 | QStringList::Iterator j1 = list.begin(); | 212 | QStringList::Iterator j1 = list.begin(); |
212 | QStringList::Iterator j2 = j1; | 213 | QStringList::Iterator j2 = j1; |
213 | ++j2; | 214 | ++j2; |
214 | while ( j1 != walkBackIt ) { | 215 | while ( j1 != walkBackIt ) { |
215 | #ifndef KAB_EMBEDDED | 216 | #ifndef KAB_EMBEDDED |
216 | if ( QString::localeAwareCompare( *j2, *j1 ) < 0 ) | 217 | if ( QString::localeAwareCompare( *j2, *j1 ) < 0 ) |
217 | #else //KAB_EMBEDDED | 218 | #else //KAB_EMBEDDED |
218 | if ( QString::compare( *j2, *j1 ) < 0 ) | 219 | if ( QString::compare( *j2, *j1 ) < 0 ) |
219 | #endif //KAB_EMBEDDED | 220 | #endif //KAB_EMBEDDED |
220 | qSwap( *j1, *j2 ); | 221 | qSwap( *j1, *j2 ); |
221 | 222 | ||
222 | ++j1; | 223 | ++j1; |
223 | ++j2; | 224 | ++j2; |
224 | } | 225 | } |
225 | ++beginIt; | 226 | ++beginIt; |
226 | --walkBackIt; | 227 | --walkBackIt; |
227 | } | 228 | } |
228 | } | 229 | } |
229 | 230 | ||
230 | #ifndef KAB_EMBEDDED | 231 | #ifndef KAB_EMBEDDED |
231 | #include "jumpbuttonbar.moc" | 232 | #include "jumpbuttonbar.moc" |
232 | #endif //KAB_EMBEDDED | 233 | #endif //KAB_EMBEDDED |