author | zautrix <zautrix> | 2005-10-28 13:24:38 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-10-28 13:24:38 (UTC) |
commit | 61a52cfdb0eda075dabde46984cf05b37856bbc2 (patch) (unidiff) | |
tree | cd587a374d62fa9b50143305f762c0ed995bd50c /kaddressbook/phoneeditwidget.cpp | |
parent | cee83f70d8e4a6945f4456c55ab1b280d3425f0f (diff) | |
download | kdepimpi-61a52cfdb0eda075dabde46984cf05b37856bbc2.zip kdepimpi-61a52cfdb0eda075dabde46984cf05b37856bbc2.tar.gz kdepimpi-61a52cfdb0eda075dabde46984cf05b37856bbc2.tar.bz2 |
commit
Diffstat (limited to 'kaddressbook/phoneeditwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kaddressbook/phoneeditwidget.cpp | 80 |
1 files changed, 58 insertions, 22 deletions
diff --git a/kaddressbook/phoneeditwidget.cpp b/kaddressbook/phoneeditwidget.cpp index 997fc05..9e7e221 100644 --- a/kaddressbook/phoneeditwidget.cpp +++ b/kaddressbook/phoneeditwidget.cpp | |||
@@ -1,198 +1,234 @@ | |||
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 <qlayout.h> | 24 | #include <qlayout.h> |
25 | #include <qlabel.h> | 25 | #include <qlabel.h> |
26 | #include <qtooltip.h> | 26 | #include <qtooltip.h> |
27 | #include <qpushbutton.h> | 27 | #include <qpushbutton.h> |
28 | #include <qcheckbox.h> | 28 | #include <qcheckbox.h> |
29 | #include <qstring.h> | 29 | #include <qstring.h> |
30 | #include <qlistbox.h> | 30 | #include <qlistbox.h> |
31 | #include <qlistview.h> | 31 | #include <qlistview.h> |
32 | #include <qbuttongroup.h> | 32 | #include <qbuttongroup.h> |
33 | #include <qhbox.h> | 33 | #include <qhbox.h> |
34 | #include <qcursor.h> | ||
34 | 35 | ||
35 | #include <kbuttonbox.h> | 36 | #include <kbuttonbox.h> |
36 | #include <klistview.h> | 37 | #include <klistview.h> |
37 | #include <kapplication.h> | 38 | #include <kapplication.h> |
38 | #include <qapplication.h> | 39 | #include <qapplication.h> |
39 | #include <kconfig.h> | 40 | #include <kconfig.h> |
40 | #include <klineedit.h> | 41 | #include <klineedit.h> |
41 | #include <kcombobox.h> | 42 | #include <kcombobox.h> |
42 | #include <klocale.h> | 43 | #include <klocale.h> |
43 | #include <kdebug.h> | 44 | #include <kdebug.h> |
44 | #include <kglobal.h> | 45 | #include <kglobal.h> |
45 | #include <kiconloader.h> | 46 | #include <kiconloader.h> |
46 | 47 | ||
47 | #include <kabc/phonenumber.h> | 48 | #include <kabc/phonenumber.h> |
48 | 49 | ||
49 | #include "typecombo.h" | 50 | #include "typecombo.h" |
50 | 51 | ||
51 | #include "phoneeditwidget.h" | 52 | #include "phoneeditwidget.h" |
52 | 53 | ||
53 | PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name ) | 54 | PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name ) |
54 | : QScrollView(parent,name) | 55 | : QWidget(parent,name) |
55 | { | 56 | { |
56 | setFrameStyle ( QFrame::Panel | QFrame::Plain ); | 57 | QGridLayout* gridLayout = new QGridLayout ( this, 2,2 ); |
57 | setLineWidth ( 1 ); | 58 | |
58 | setMidLineWidth ( 1 ); | 59 | QLabel *temp = new QLabel( "", this ); |
59 | mw = new QWidget ( viewport() ); | 60 | temp->setAlignment( Qt::AlignCenter ); |
60 | addChild(mw); | 61 | temp->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) ); |
61 | setResizePolicy( AutoOneFit ); | 62 | gridLayout->addWidget( temp, 1, 0 ); |
63 | QPushButton *addBut = new QPushButton ( "add", this ); | ||
64 | addBut->setPixmap ( SmallIcon("plus")); | ||
65 | addBut->setMaximumSize( addBut->sizeHint().height(),addBut->sizeHint().height() ); | ||
66 | connect(addBut,SIGNAL(clicked ()),SLOT(addNumber())); | ||
67 | gridLayout->addWidget( addBut, 0, 0 ); | ||
68 | |||
69 | sv = new QScrollView( this ); | ||
70 | sv->setFrameStyle ( QFrame::Panel | QFrame::Plain ); | ||
71 | sv->setLineWidth ( 1 ); | ||
72 | sv->setMidLineWidth ( 1 ); | ||
73 | mw = new QWidget ( sv->viewport() ); | ||
74 | sv->addChild(mw); | ||
75 | sv->setResizePolicy( QScrollView::AutoOneFit ); | ||
62 | mainLayout = new QVBoxLayout ( mw ); | 76 | mainLayout = new QVBoxLayout ( mw ); |
63 | mainLayout->setMargin( 2 ); | 77 | mainLayout->setMargin( 2 ); |
64 | mainLayout->setSpacing( 2 ); | 78 | mainLayout->setSpacing( 2 ); |
65 | QWidget* hb = new QWidget ( mw ); | 79 | gridLayout->addMultiCellWidget( sv, 0, 1, 1,1 ); |
66 | mainLayout->add( hb ); | ||
67 | QHBoxLayout* hbLayout = new QHBoxLayout ( hb ); | ||
68 | QPushButton *addBut = new QPushButton ( "add", hb ); | ||
69 | hbLayout->add( addBut ); | ||
70 | addBut->setPixmap ( SmallIcon("plus")); | ||
71 | addBut->setMaximumSize( addBut->sizeHint().height(),addBut->sizeHint().height() ); | ||
72 | connect(addBut,SIGNAL(clicked()),SLOT(addNumber())); | ||
73 | //QLabel * temp = new QLabel( i18n("Phone Type"), hb ); | ||
74 | QLabel *temp = new QLabel( i18n("Phone Number"),hb ); | ||
75 | temp->setAlignment( Qt::AlignCenter ); | ||
76 | temp->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) ); | ||
77 | hbLayout->add( temp ); | ||
78 | setDefaults(); | 80 | setDefaults(); |
79 | mTypeNumberEditList.setAutoDelete( true ); | 81 | mTypeNumberEditList.setAutoDelete( true ); |
82 | mPopup = new QPopupMenu( this ); | ||
83 | QStringList list = PhoneNumber::supportedTypeListNames(); | ||
84 | mPopupCount = list.count(); | ||
85 | int i = 0; | ||
86 | while ( i < mPopupCount ) { | ||
87 | mPopup->insertItem( list[ i ], i ); | ||
88 | ++i; | ||
89 | } | ||
90 | connect(mPopup,SIGNAL(activated(int)),this,SLOT(addNumberInt( int))); | ||
91 | |||
80 | } | 92 | } |
81 | 93 | ||
82 | PhoneEditWidget::~PhoneEditWidget() | 94 | PhoneEditWidget::~PhoneEditWidget() |
83 | { | 95 | { |
84 | } | 96 | } |
85 | void PhoneEditWidget::setDefaults() | 97 | void PhoneEditWidget::setDefaults() |
86 | { | 98 | { |
87 | mTypeNumberEditList.clear(); | 99 | mTypeNumberEditList.clear(); |
88 | PhoneTypeNumberEdit* edit = appendEditCombo(); | 100 | PhoneTypeNumberEdit* edit = appendEditCombo(); |
89 | KABC::PhoneNumber phoneNumber; | 101 | KABC::PhoneNumber phoneNumber; |
90 | phoneNumber.setType( KABC::PhoneNumber::Home | KABC::PhoneNumber::Pref ); | 102 | phoneNumber.setType( KABC::PhoneNumber::Home | KABC::PhoneNumber::Pref ); |
91 | edit->setPhoneNumber( phoneNumber ); | 103 | edit->setPhoneNumber( phoneNumber ); |
92 | edit = appendEditCombo(); | 104 | edit = appendEditCombo(); |
93 | phoneNumber.setType( KABC::PhoneNumber::Work | KABC::PhoneNumber::Pref ); | 105 | phoneNumber.setType( KABC::PhoneNumber::Work | KABC::PhoneNumber::Pref ); |
94 | edit->setPhoneNumber( phoneNumber ); | 106 | edit->setPhoneNumber( phoneNumber ); |
95 | edit = appendEditCombo(); | 107 | edit = appendEditCombo(); |
96 | phoneNumber.setType( KABC::PhoneNumber::Cell ); | 108 | phoneNumber.setType( KABC::PhoneNumber::Cell ); |
97 | edit->setPhoneNumber( phoneNumber ); | 109 | edit->setPhoneNumber( phoneNumber ); |
98 | 110 | ||
99 | } | 111 | } |
112 | void PhoneEditWidget::addNumberInt( int index ) | ||
113 | { | ||
114 | PhoneTypeNumberEdit* edit = appendEditCombo(); | ||
115 | KABC::PhoneNumber phoneNumber; | ||
116 | phoneNumber.setType( PhoneNumber::supportedTypeList()[index] ); | ||
117 | edit->setPhoneNumber( phoneNumber ); | ||
118 | //verticalScrollBar()->setValue( 1024); | ||
119 | QTimer::singleShot( 0, this, SLOT ( bottomVisible() ) ); | ||
120 | } | ||
121 | void PhoneEditWidget::bottomVisible() | ||
122 | { | ||
123 | sv->setContentsPos ( 0, 1024 ); | ||
124 | } | ||
100 | void PhoneEditWidget::addNumber() | 125 | void PhoneEditWidget::addNumber() |
101 | { | 126 | { |
102 | 127 | int i = 0; | |
128 | while ( i < mPopupCount ) { | ||
129 | mPopup->setItemEnabled( i, true ); | ||
130 | ++i; | ||
131 | } | ||
132 | PhoneTypeNumberEdit* edit = mTypeNumberEditList.first(); | ||
133 | while ( edit ) { | ||
134 | if ( edit->currentType() < mPopupCount -1 ) | ||
135 | mPopup->setItemEnabled( edit->currentType(), false ); | ||
136 | edit = mTypeNumberEditList.next(); | ||
137 | } | ||
138 | mPopup->popup( QCursor::pos() ); | ||
103 | } | 139 | } |
104 | PhoneTypeNumberEdit* PhoneEditWidget::appendEditCombo() | 140 | PhoneTypeNumberEdit* PhoneEditWidget::appendEditCombo() |
105 | { | 141 | { |
106 | PhoneTypeNumberEdit* edit = new PhoneTypeNumberEdit( mw ); | 142 | PhoneTypeNumberEdit* edit = new PhoneTypeNumberEdit( mw ); |
107 | connect ( edit, SIGNAL ( typeChange( int , int) ), this, SIGNAL ( typeChange( int , int)) ); | 143 | connect ( edit, SIGNAL ( typeChange( int , int) ), this, SIGNAL ( typeChange( int , int)) ); |
108 | connect ( edit, SIGNAL ( modified() ), this, SIGNAL ( modified() ) ); | 144 | connect ( edit, SIGNAL ( modified() ), this, SIGNAL ( modified() ) ); |
109 | connect ( edit, SIGNAL ( deleteMe( PhoneTypeNumberEdit* ) ), this, SLOT ( deleteEdit( PhoneTypeNumberEdit*) ) ); | 145 | connect ( edit, SIGNAL ( deleteMe( PhoneTypeNumberEdit* ) ), this, SLOT ( deleteEdit( PhoneTypeNumberEdit*) ) ); |
110 | connect ( this, SIGNAL ( typeChange( int , int)), edit, SLOT ( typeExternalChanged( int, int)) ); | 146 | connect ( this, SIGNAL ( typeChange( int , int)), edit, SLOT ( typeExternalChanged( int, int)) ); |
111 | 147 | ||
112 | mainLayout->add( edit ); | 148 | mainLayout->add( edit ); |
113 | mTypeNumberEditList.append( edit ); | 149 | mTypeNumberEditList.append( edit ); |
114 | return edit; | 150 | return edit; |
115 | } | 151 | } |
116 | 152 | ||
117 | void PhoneEditWidget::deleteEdit( PhoneTypeNumberEdit* ew ) | 153 | void PhoneEditWidget::deleteEdit( PhoneTypeNumberEdit* ew ) |
118 | { | 154 | { |
119 | mPendingDelete = ew; | 155 | mPendingDelete = ew; |
120 | QTimer::singleShot( 0, this, SLOT ( pendingDelete() ) ); | 156 | QTimer::singleShot( 0, this, SLOT ( pendingDelete() ) ); |
121 | } | 157 | } |
122 | void PhoneEditWidget::pendingDelete() | 158 | void PhoneEditWidget::pendingDelete() |
123 | { | 159 | { |
124 | mTypeNumberEditList.removeRef( mPendingDelete ); | 160 | mTypeNumberEditList.removeRef( mPendingDelete ); |
125 | emit modified(); | 161 | emit modified(); |
126 | } | 162 | } |
127 | 163 | ||
128 | void PhoneEditWidget::setPhoneNumbers( const KABC::PhoneNumber::List &li ) | 164 | void PhoneEditWidget::setPhoneNumbers( const KABC::PhoneNumber::List &li ) |
129 | { | 165 | { |
130 | if ( li.isEmpty() ) { | 166 | if ( li.isEmpty() ) { |
131 | setDefaults(); | 167 | setDefaults(); |
132 | return; | 168 | return; |
133 | } | 169 | } |
134 | mTypeNumberEditList.clear(); | 170 | mTypeNumberEditList.clear(); |
135 | KABC::PhoneNumber::List::Iterator it; | 171 | KABC::PhoneNumber::List::Iterator it; |
136 | KABC::PhoneNumber::List list = li; | 172 | KABC::PhoneNumber::List list = li; |
137 | PhoneTypeNumberEdit* edit = 0;//mTypeNumberEditList.first(); | 173 | PhoneTypeNumberEdit* edit = 0;//mTypeNumberEditList.first(); |
138 | for ( it = list.begin(); it != list.end(); ++it ) { | 174 | for ( it = list.begin(); it != list.end(); ++it ) { |
139 | if ( edit ) { | 175 | if ( edit ) { |
140 | edit->setPhoneNumber( (*it ) ); | 176 | edit->setPhoneNumber( (*it ) ); |
141 | edit = mTypeNumberEditList.next(); | 177 | edit = mTypeNumberEditList.next(); |
142 | } else { | 178 | } else { |
143 | PhoneTypeNumberEdit* editNew = appendEditCombo(); | 179 | PhoneTypeNumberEdit* editNew = appendEditCombo(); |
144 | editNew->setPhoneNumber( (*it ) ); | 180 | editNew->setPhoneNumber( (*it ) ); |
145 | } | 181 | } |
146 | } | 182 | } |
147 | while ( edit ) { | 183 | while ( edit ) { |
148 | edit->hide(); | 184 | edit->hide(); |
149 | edit = mTypeNumberEditList.next(); | 185 | edit = mTypeNumberEditList.next(); |
150 | } | 186 | } |
151 | } | 187 | } |
152 | KABC::PhoneNumber::List PhoneEditWidget::phoneNumbers() | 188 | KABC::PhoneNumber::List PhoneEditWidget::phoneNumbers() |
153 | { | 189 | { |
154 | KABC::PhoneNumber::List retList; | 190 | KABC::PhoneNumber::List retList; |
155 | 191 | ||
156 | PhoneTypeNumberEdit* edit = mTypeNumberEditList.first(); | 192 | PhoneTypeNumberEdit* edit = mTypeNumberEditList.first(); |
157 | while ( edit ) { | 193 | while ( edit ) { |
158 | if ( edit->isValid() ) { | 194 | if ( edit->isValid() ) { |
159 | retList.append( edit->phoneNumber()); | 195 | retList.append( edit->phoneNumber()); |
160 | } | 196 | } |
161 | edit = mTypeNumberEditList.next(); | 197 | edit = mTypeNumberEditList.next(); |
162 | 198 | ||
163 | } | 199 | } |
164 | return retList; | 200 | return retList; |
165 | } | 201 | } |
166 | 202 | ||
167 | #if 0 | 203 | #if 0 |
168 | PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name ) | 204 | PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name ) |
169 | : QWidget( parent, name ) | 205 | : QWidget( parent, name ) |
170 | { | 206 | { |
171 | QGridLayout *layout = new QGridLayout( this, 4, 1 ); | 207 | QGridLayout *layout = new QGridLayout( this, 4, 1 ); |
172 | //US layout->setSpacing( KDialog::spacingHint() ); | 208 | //US layout->setSpacing( KDialog::spacingHint() ); |
173 | layout->setSpacing( KDialogBase::spacingHintSmall() ); | 209 | layout->setSpacing( KDialogBase::spacingHintSmall() ); |
174 | 210 | ||
175 | 211 | ||
176 | 212 | ||
177 | QLabel* label = new QLabel( this ); | 213 | QLabel* label = new QLabel( this ); |
178 | //US loadIcon call is ambiguous. Add one more parameter | 214 | //US loadIcon call is ambiguous. Add one more parameter |
179 | //US label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop ) ); | 215 | //US label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop ) ); |
180 | label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) ); | 216 | label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) ); |
181 | label->setAlignment( AlignCenter ); | 217 | label->setAlignment( AlignCenter ); |
182 | //US layout->addMultiCellWidget( label, 0, 1, 3, 3 ); | 218 | //US layout->addMultiCellWidget( label, 0, 1, 3, 3 ); |
183 | layout->addWidget( label, 0, 0 ); | 219 | layout->addWidget( label, 0, 0 ); |
184 | 220 | ||
185 | QPushButton *editButton = new QPushButton( i18n( "Edit Phone Numbers..." ), | 221 | QPushButton *editButton = new QPushButton( i18n( "Edit Phone Numbers..." ), |
186 | this ); | 222 | this ); |
187 | if ( QApplication::desktop()->width() < 640 ) | 223 | if ( QApplication::desktop()->width() < 640 ) |
188 | layout->addWidget( editButton, 0, 1 ); | 224 | layout->addWidget( editButton, 0, 1 ); |
189 | else | 225 | else |
190 | layout->addMultiCellWidget( editButton, 0, 0, 1, 3); | 226 | layout->addMultiCellWidget( editButton, 0, 0, 1, 3); |
191 | 227 | ||
192 | mPrefCombo = new PhoneTypeCombo( mPhoneList, this ); | 228 | mPrefCombo = new PhoneTypeCombo( mPhoneList, this ); |
193 | mPrefEdit = new KLineEdit( this ); | 229 | mPrefEdit = new KLineEdit( this ); |
194 | //mPrefEdit->setMinimumWidth( int(mPrefEdit->sizeHint().width() * 1.5) ); | 230 | //mPrefEdit->setMinimumWidth( int(mPrefEdit->sizeHint().width() * 1.5) ); |
195 | mPrefCombo->setLineEdit( mPrefEdit ); | 231 | mPrefCombo->setLineEdit( mPrefEdit ); |
196 | layout->addWidget( mPrefCombo, 1, 0 ); | 232 | layout->addWidget( mPrefCombo, 1, 0 ); |
197 | layout->addWidget( mPrefEdit, 1, 1 ); | 233 | layout->addWidget( mPrefEdit, 1, 1 ); |
198 | int x = 1, y = 2; | 234 | int x = 1, y = 2; |