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