summaryrefslogtreecommitdiffabout
path: root/kaddressbook/phoneeditwidget.cpp
authorzautrix <zautrix>2005-10-28 23:31:46 (UTC)
committer zautrix <zautrix>2005-10-28 23:31:46 (UTC)
commit7a90e619147e06e5f4d4facef98364f78a4a04ef (patch) (unidiff)
treef1b11d0ca9c123d42f9b632bae1cc6608ee5e740 /kaddressbook/phoneeditwidget.cpp
parent85d2ea5c17a2b2c7a4ae4dd954bc635a56239b57 (diff)
downloadkdepimpi-7a90e619147e06e5f4d4facef98364f78a4a04ef.zip
kdepimpi-7a90e619147e06e5f4d4facef98364f78a4a04ef.tar.gz
kdepimpi-7a90e619147e06e5f4d4facef98364f78a4a04ef.tar.bz2
fixx
Diffstat (limited to 'kaddressbook/phoneeditwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/phoneeditwidget.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/kaddressbook/phoneeditwidget.cpp b/kaddressbook/phoneeditwidget.cpp
index 7e2aec1..5639aa2 100644
--- a/kaddressbook/phoneeditwidget.cpp
+++ b/kaddressbook/phoneeditwidget.cpp
@@ -1,206 +1,208 @@
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#include <qcursor.h>
35#include <qtimer.h> 35#include <qtimer.h>
36#include <qapplication.h> 36#include <qapplication.h>
37 37
38#include <kbuttonbox.h> 38#include <kbuttonbox.h>
39#include <klistview.h> 39#include <klistview.h>
40#include <kapplication.h> 40#include <kapplication.h>
41#include <qapplication.h> 41#include <qapplication.h>
42#include <kconfig.h> 42#include <kconfig.h>
43#include <klineedit.h> 43#include <klineedit.h>
44#include <kcombobox.h> 44#include <kcombobox.h>
45#include <klocale.h> 45#include <klocale.h>
46#include <kdebug.h> 46#include <kdebug.h>
47#include <kglobal.h> 47#include <kglobal.h>
48#include <kiconloader.h> 48#include <kiconloader.h>
49 49
50#include <kabc/phonenumber.h> 50#include <kabc/phonenumber.h>
51 51
52#include "typecombo.h" 52#include "typecombo.h"
53 53
54#include "phoneeditwidget.h" 54#include "phoneeditwidget.h"
55 55
56PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name ) 56PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name )
57 : QWidget(parent,name) 57 : QWidget(parent,name)
58{ 58{
59 QGridLayout* gridLayout = new QGridLayout ( this, 2,2 ); 59 QGridLayout* gridLayout = new QGridLayout ( this, 2,2 );
60 60
61 QLabel *temp = new QLabel( "", this ); 61 QLabel *temp = new QLabel( "", this );
62 temp->setAlignment( Qt::AlignCenter ); 62 temp->setAlignment( Qt::AlignCenter );
63 temp->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) ); 63 temp->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) );
64 QPushButton *addBut = new QPushButton ( "add", this ); 64 QPushButton *addBut = new QPushButton ( "add", this );
65 addBut->setPixmap ( SmallIcon("plus")); 65 addBut->setPixmap ( SmallIcon("plus"));
66 addBut->setMaximumSize( addBut->sizeHint().height(),addBut->sizeHint().height() ); 66 addBut->setMaximumSize( addBut->sizeHint().height(),addBut->sizeHint().height() );
67 connect(addBut,SIGNAL(clicked ()),SLOT(addNumber())); 67 connect(addBut,SIGNAL(clicked ()),SLOT(addNumber()));
68 68
69 sv = new QScrollView( this ); 69 sv = new QScrollView( this );
70 sv->setFrameStyle ( QFrame::Panel | QFrame::Plain ); 70 sv->setFrameStyle ( QFrame::Plain );
71 sv->setLineWidth ( 1 ); 71 sv->setLineWidth ( 0 );
72 sv->setMidLineWidth ( 1 ); 72 sv->setMidLineWidth ( 0 );
73 mw = new QWidget ( sv->viewport() ); 73 mw = new QWidget ( sv->viewport() );
74 sv->addChild(mw); 74 sv->addChild(mw);
75 sv->setResizePolicy( QScrollView::AutoOneFit ); 75 sv->setResizePolicy( QScrollView::AutoOneFit );
76 mainLayout = new QVBoxLayout ( mw ); 76 mainLayout = new QVBoxLayout ( mw );
77 mainLayout->setMargin( 0 ); 77 mainLayout->setMargin( 0 );
78 mainLayout->setSpacing( 0 ); 78 mainLayout->setSpacing( 0 );
79 gridLayout->setMargin( 2 );
80 gridLayout->setSpacing( 4 );
79 if ( QApplication::desktop()->width() == 240 || QApplication::desktop()->width() == 480 ) { 81 if ( QApplication::desktop()->width() == 240 || QApplication::desktop()->width() == 480 ) {
80 gridLayout->addWidget( addBut, 0, 0 ); 82 gridLayout->addWidget( addBut, 0, 0 );
81 gridLayout->addWidget( temp, 0, 1 ); 83 gridLayout->addWidget( temp, 0, 1 );
82 gridLayout->addMultiCellWidget( sv, 1,1 , 0,1 ); 84 gridLayout->addMultiCellWidget( sv, 1,1 , 0,1 );
83 } else { 85 } else {
84 gridLayout->addWidget( temp, 1, 0 ); 86 gridLayout->addWidget( temp, 1, 0 );
85 gridLayout->addWidget( addBut, 0, 0 ); 87 gridLayout->addWidget( addBut, 0, 0 );
86 gridLayout->addMultiCellWidget( sv, 0, 1, 1,1 ); 88 gridLayout->addMultiCellWidget( sv, 0, 1, 1,1 );
87 } 89 }
88 setDefaults(); 90 setDefaults();
89 mTypeNumberEditList.setAutoDelete( true ); 91 mTypeNumberEditList.setAutoDelete( true );
90 mPopup = new QPopupMenu( this ); 92 mPopup = new QPopupMenu( this );
91 QStringList list = PhoneNumber::supportedTypeListNames(); 93 QStringList list = PhoneNumber::supportedTypeListNames();
92 mPopupCount = list.count(); 94 mPopupCount = list.count();
93 int i = 0; 95 int i = 0;
94 while ( i < mPopupCount ) { 96 while ( i < mPopupCount ) {
95 mPopup->insertItem( list[ i ], i ); 97 mPopup->insertItem( list[ i ], i );
96 ++i; 98 ++i;
97 } 99 }
98 connect(mPopup,SIGNAL(activated(int)),this,SLOT(addNumberInt( int))); 100 connect(mPopup,SIGNAL(activated(int)),this,SLOT(addNumberInt( int)));
99 101
100} 102}
101 103
102PhoneEditWidget::~PhoneEditWidget() 104PhoneEditWidget::~PhoneEditWidget()
103{ 105{
104} 106}
105void PhoneEditWidget::setDefaults() 107void PhoneEditWidget::setDefaults()
106{ 108{
107 mTypeNumberEditList.clear(); 109 mTypeNumberEditList.clear();
108 PhoneTypeNumberEdit* edit = appendEditCombo(); 110 PhoneTypeNumberEdit* edit = appendEditCombo();
109 KABC::PhoneNumber phoneNumber; 111 KABC::PhoneNumber phoneNumber;
110 phoneNumber.setType( KABC::PhoneNumber::Home | KABC::PhoneNumber::Pref ); 112 phoneNumber.setType( KABC::PhoneNumber::Home | KABC::PhoneNumber::Pref );
111 edit->setPhoneNumber( phoneNumber ); 113 edit->setPhoneNumber( phoneNumber );
112 edit = appendEditCombo(); 114 edit = appendEditCombo();
113 phoneNumber.setType( KABC::PhoneNumber::Work | KABC::PhoneNumber::Pref ); 115 phoneNumber.setType( KABC::PhoneNumber::Work | KABC::PhoneNumber::Pref );
114 edit->setPhoneNumber( phoneNumber ); 116 edit->setPhoneNumber( phoneNumber );
115 edit = appendEditCombo(); 117 edit = appendEditCombo();
116 phoneNumber.setType( KABC::PhoneNumber::Cell ); 118 phoneNumber.setType( KABC::PhoneNumber::Cell );
117 edit->setPhoneNumber( phoneNumber ); 119 edit->setPhoneNumber( phoneNumber );
118 120
119} 121}
120void PhoneEditWidget::addNumberInt( int index ) 122void PhoneEditWidget::addNumberInt( int index )
121{ 123{
122 PhoneTypeNumberEdit* edit = appendEditCombo(); 124 PhoneTypeNumberEdit* edit = appendEditCombo();
123 KABC::PhoneNumber phoneNumber; 125 KABC::PhoneNumber phoneNumber;
124 phoneNumber.setType( PhoneNumber::supportedTypeList()[index] ); 126 phoneNumber.setType( PhoneNumber::supportedTypeList()[index] );
125 edit->setPhoneNumber( phoneNumber ); 127 edit->setPhoneNumber( phoneNumber );
126 //verticalScrollBar()->setValue( 1024); 128 //verticalScrollBar()->setValue( 1024);
127 QTimer::singleShot( 0, this, SLOT ( bottomVisible() ) ); 129 QTimer::singleShot( 0, this, SLOT ( bottomVisible() ) );
128} 130}
129void PhoneEditWidget::bottomVisible() 131void PhoneEditWidget::bottomVisible()
130{ 132{
131 sv->setContentsPos ( 0, 1024 ); 133 sv->setContentsPos ( 0, 1024 );
132} 134}
133void PhoneEditWidget::addNumber() 135void PhoneEditWidget::addNumber()
134{ 136{
135 int i = 0; 137 int i = 0;
136 while ( i < mPopupCount ) { 138 while ( i < mPopupCount ) {
137 mPopup->setItemEnabled( i, true ); 139 mPopup->setItemEnabled( i, true );
138 ++i; 140 ++i;
139 } 141 }
140 PhoneTypeNumberEdit* edit = mTypeNumberEditList.first(); 142 PhoneTypeNumberEdit* edit = mTypeNumberEditList.first();
141 while ( edit ) { 143 while ( edit ) {
142 if ( edit->currentType() < mPopupCount -1 ) 144 if ( edit->currentType() < mPopupCount -1 )
143 mPopup->setItemEnabled( edit->currentType(), false ); 145 mPopup->setItemEnabled( edit->currentType(), false );
144 edit = mTypeNumberEditList.next(); 146 edit = mTypeNumberEditList.next();
145 } 147 }
146 mPopup->popup( QCursor::pos() ); 148 mPopup->popup( QCursor::pos() );
147} 149}
148PhoneTypeNumberEdit* PhoneEditWidget::appendEditCombo() 150PhoneTypeNumberEdit* PhoneEditWidget::appendEditCombo()
149{ 151{
150 PhoneTypeNumberEdit* edit = new PhoneTypeNumberEdit( mw ); 152 PhoneTypeNumberEdit* edit = new PhoneTypeNumberEdit( mw );
151 connect ( edit, SIGNAL ( typeChange( int , int) ), this, SIGNAL ( typeChange( int , int)) ); 153 connect ( edit, SIGNAL ( typeChange( int , int) ), this, SIGNAL ( typeChange( int , int)) );
152 connect ( edit, SIGNAL ( modified() ), this, SIGNAL ( modified() ) ); 154 connect ( edit, SIGNAL ( modified() ), this, SIGNAL ( modified() ) );
153 connect ( edit, SIGNAL ( deleteMe( PhoneTypeNumberEdit* ) ), this, SLOT ( deleteEdit( PhoneTypeNumberEdit*) ) ); 155 connect ( edit, SIGNAL ( deleteMe( PhoneTypeNumberEdit* ) ), this, SLOT ( deleteEdit( PhoneTypeNumberEdit*) ) );
154 connect ( this, SIGNAL ( typeChange( int , int)), edit, SLOT ( typeExternalChanged( int, int)) ); 156 connect ( this, SIGNAL ( typeChange( int , int)), edit, SLOT ( typeExternalChanged( int, int)) );
155 157
156 mainLayout->add( edit ); 158 mainLayout->add( edit );
157 mTypeNumberEditList.append( edit ); 159 mTypeNumberEditList.append( edit );
158 return edit; 160 return edit;
159} 161}
160 162
161void PhoneEditWidget::deleteEdit( PhoneTypeNumberEdit* ew ) 163void PhoneEditWidget::deleteEdit( PhoneTypeNumberEdit* ew )
162{ 164{
163 mPendingDelete = ew; 165 mPendingDelete = ew;
164 QTimer::singleShot( 0, this, SLOT ( pendingDelete() ) ); 166 QTimer::singleShot( 0, this, SLOT ( pendingDelete() ) );
165} 167}
166void PhoneEditWidget::pendingDelete() 168void PhoneEditWidget::pendingDelete()
167{ 169{
168 mTypeNumberEditList.removeRef( mPendingDelete ); 170 mTypeNumberEditList.removeRef( mPendingDelete );
169 emit modified(); 171 emit modified();
170} 172}
171 173
172void PhoneEditWidget::setPhoneNumbers( const KABC::PhoneNumber::List &li ) 174void PhoneEditWidget::setPhoneNumbers( const KABC::PhoneNumber::List &li )
173{ 175{
174 if ( li.isEmpty() ) { 176 if ( li.isEmpty() ) {
175 setDefaults(); 177 setDefaults();
176 return; 178 return;
177 } 179 }
178 mTypeNumberEditList.clear(); 180 mTypeNumberEditList.clear();
179 KABC::PhoneNumber::List::Iterator it; 181 KABC::PhoneNumber::List::Iterator it;
180 KABC::PhoneNumber::List list2 = li; 182 KABC::PhoneNumber::List list2 = li;
181 KABC::PhoneNumber::List list ; 183 KABC::PhoneNumber::List list ;
182 184
183 PhoneNumber::TypeList tList = PhoneNumber::supportedTypeList(); 185 PhoneNumber::TypeList tList = PhoneNumber::supportedTypeList();
184 int i = 0; 186 int i = 0;
185 int max = tList.count(); 187 int max = tList.count();
186 while ( i < max-1 ) { 188 while ( i < max-1 ) {
187 for ( it = list2.begin(); it != list2.end(); ++it ) { 189 for ( it = list2.begin(); it != list2.end(); ++it ) {
188 if ( (*it).type() == tList[i] ) { 190 if ( (*it).type() == tList[i] ) {
189 list.append( (*it ) ); 191 list.append( (*it ) );
190 break; 192 break;
191 } 193 }
192 } 194 }
193 ++i; 195 ++i;
194 } 196 }
195 for ( it = list2.begin(); it != list2.end(); ++it ) { 197 for ( it = list2.begin(); it != list2.end(); ++it ) {
196 if ( (*it).type() == tList[ max-1 ] ) 198 if ( (*it).type() == tList[ max-1 ] )
197 list.append( (*it ) ); 199 list.append( (*it ) );
198 } 200 }
199 for ( it = list.begin(); it != list.end(); ++it ) { 201 for ( it = list.begin(); it != list.end(); ++it ) {
200 PhoneTypeNumberEdit* editNew = appendEditCombo(); 202 PhoneTypeNumberEdit* editNew = appendEditCombo();
201 editNew->setPhoneNumber( (*it ) ); 203 editNew->setPhoneNumber( (*it ) );
202 } 204 }
203 205
204} 206}
205KABC::PhoneNumber::List PhoneEditWidget::phoneNumbers() 207KABC::PhoneNumber::List PhoneEditWidget::phoneNumbers()
206{ 208{