summaryrefslogtreecommitdiffabout
path: root/kaddressbook/phoneeditwidget.cpp
Unidiff
Diffstat (limited to 'kaddressbook/phoneeditwidget.cpp') (more/less context) (show whitespace changes)
-rw-r--r--kaddressbook/phoneeditwidget.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/kaddressbook/phoneeditwidget.cpp b/kaddressbook/phoneeditwidget.cpp
index 5639aa2..df3b551 100644
--- a/kaddressbook/phoneeditwidget.cpp
+++ b/kaddressbook/phoneeditwidget.cpp
@@ -1,167 +1,170 @@
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 <kmessagebox.h>
43#include <klineedit.h> 44#include <klineedit.h>
44#include <kcombobox.h> 45#include <kcombobox.h>
45#include <klocale.h> 46#include <klocale.h>
46#include <kdebug.h> 47#include <kdebug.h>
47#include <kglobal.h> 48#include <kglobal.h>
48#include <kiconloader.h> 49#include <kiconloader.h>
49 50
50#include <kabc/phonenumber.h> 51#include <kabc/phonenumber.h>
51 52
52#include "typecombo.h" 53#include "typecombo.h"
53 54
54#include "phoneeditwidget.h" 55#include "phoneeditwidget.h"
55 56
56PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name ) 57PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name )
57 : QWidget(parent,name) 58 : QWidget(parent,name)
58{ 59{
59 QGridLayout* gridLayout = new QGridLayout ( this, 2,2 ); 60 QGridLayout* gridLayout = new QGridLayout ( this, 2,2 );
60 61
61 QLabel *temp = new QLabel( "", this ); 62 QLabel *temp = new QLabel( "", this );
62 temp->setAlignment( Qt::AlignCenter ); 63 temp->setAlignment( Qt::AlignCenter );
63 temp->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) ); 64 temp->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) );
64 QPushButton *addBut = new QPushButton ( "add", this ); 65 QPushButton *addBut = new QPushButton ( "add", this );
65 addBut->setPixmap ( SmallIcon("plus")); 66 addBut->setPixmap ( SmallIcon("plus"));
66 addBut->setMaximumSize( addBut->sizeHint().height(),addBut->sizeHint().height() ); 67 addBut->setMaximumSize( addBut->sizeHint().height(),addBut->sizeHint().height() );
67 connect(addBut,SIGNAL(clicked ()),SLOT(addNumber())); 68 connect(addBut,SIGNAL(clicked ()),SLOT(addNumber()));
68 69
69 sv = new QScrollView( this ); 70 sv = new QScrollView( this );
70 sv->setFrameStyle ( QFrame::Plain ); 71 sv->setFrameStyle ( QFrame::Plain );
71 sv->setLineWidth ( 0 ); 72 sv->setLineWidth ( 0 );
72 sv->setMidLineWidth ( 0 ); 73 sv->setMidLineWidth ( 0 );
73 mw = new QWidget ( sv->viewport() ); 74 mw = new QWidget ( sv->viewport() );
74 sv->addChild(mw); 75 sv->addChild(mw);
75 sv->setResizePolicy( QScrollView::AutoOneFit ); 76 sv->setResizePolicy( QScrollView::AutoOneFit );
76 mainLayout = new QVBoxLayout ( mw ); 77 mainLayout = new QVBoxLayout ( mw );
77 mainLayout->setMargin( 0 ); 78 mainLayout->setMargin( 0 );
78 mainLayout->setSpacing( 0 ); 79 mainLayout->setSpacing( 0 );
79 gridLayout->setMargin( 2 ); 80 gridLayout->setMargin( 2 );
80 gridLayout->setSpacing( 4 ); 81 gridLayout->setSpacing( 4 );
81 if ( QApplication::desktop()->width() == 240 || QApplication::desktop()->width() == 480 ) { 82 if ( QApplication::desktop()->width() == 240 || QApplication::desktop()->width() == 480 ) {
82 gridLayout->addWidget( addBut, 0, 0 ); 83 gridLayout->addWidget( addBut, 0, 0 );
83 gridLayout->addWidget( temp, 0, 1 ); 84 gridLayout->addWidget( temp, 0, 1 );
84 gridLayout->addMultiCellWidget( sv, 1,1 , 0,1 ); 85 gridLayout->addMultiCellWidget( sv, 1,1 , 0,1 );
85 } else { 86 } else {
86 gridLayout->addWidget( temp, 1, 0 ); 87 gridLayout->addWidget( temp, 1, 0 );
87 gridLayout->addWidget( addBut, 0, 0 ); 88 gridLayout->addWidget( addBut, 0, 0 );
88 gridLayout->addMultiCellWidget( sv, 0, 1, 1,1 ); 89 gridLayout->addMultiCellWidget( sv, 0, 1, 1,1 );
89 } 90 }
90 setDefaults(); 91 setDefaults();
91 mTypeNumberEditList.setAutoDelete( true ); 92 mTypeNumberEditList.setAutoDelete( true );
92 mPopup = new QPopupMenu( this ); 93 mPopup = new QPopupMenu( this );
93 QStringList list = PhoneNumber::supportedTypeListNames(); 94 QStringList list = PhoneNumber::supportedTypeListNames();
94 mPopupCount = list.count(); 95 mPopupCount = list.count();
95 int i = 0; 96 int i = 0;
96 while ( i < mPopupCount ) { 97 while ( i < mPopupCount ) {
97 mPopup->insertItem( list[ i ], i ); 98 mPopup->insertItem( list[ i ], i );
98 ++i; 99 ++i;
99 } 100 }
100 connect(mPopup,SIGNAL(activated(int)),this,SLOT(addNumberInt( int))); 101 connect(mPopup,SIGNAL(activated(int)),this,SLOT(addNumberInt( int)));
101 102
102} 103}
103 104
104PhoneEditWidget::~PhoneEditWidget() 105PhoneEditWidget::~PhoneEditWidget()
105{ 106{
106} 107}
107void PhoneEditWidget::setDefaults() 108void PhoneEditWidget::setDefaults()
108{ 109{
109 mTypeNumberEditList.clear(); 110 mTypeNumberEditList.clear();
110 PhoneTypeNumberEdit* edit = appendEditCombo(); 111 PhoneTypeNumberEdit* edit = appendEditCombo();
111 KABC::PhoneNumber phoneNumber; 112 KABC::PhoneNumber phoneNumber;
112 phoneNumber.setType( KABC::PhoneNumber::Home | KABC::PhoneNumber::Pref ); 113 phoneNumber.setType( KABC::PhoneNumber::Home | KABC::PhoneNumber::Pref );
113 edit->setPhoneNumber( phoneNumber ); 114 edit->setPhoneNumber( phoneNumber );
114 edit = appendEditCombo(); 115 edit = appendEditCombo();
115 phoneNumber.setType( KABC::PhoneNumber::Work | KABC::PhoneNumber::Pref ); 116 KABC::PhoneNumber phoneNumber2;
116 edit->setPhoneNumber( phoneNumber ); 117 phoneNumber2.setType( KABC::PhoneNumber::Work | KABC::PhoneNumber::Pref );
118 edit->setPhoneNumber( phoneNumber2 );
117 edit = appendEditCombo(); 119 edit = appendEditCombo();
118 phoneNumber.setType( KABC::PhoneNumber::Cell ); 120 KABC::PhoneNumber phoneNumber3;
119 edit->setPhoneNumber( phoneNumber ); 121 phoneNumber3.setType( KABC::PhoneNumber::Cell );
122 edit->setPhoneNumber( phoneNumber3 );
120 123
121} 124}
122void PhoneEditWidget::addNumberInt( int index ) 125void PhoneEditWidget::addNumberInt( int index )
123{ 126{
124 PhoneTypeNumberEdit* edit = appendEditCombo(); 127 PhoneTypeNumberEdit* edit = appendEditCombo();
125 KABC::PhoneNumber phoneNumber; 128 KABC::PhoneNumber phoneNumber;
126 phoneNumber.setType( PhoneNumber::supportedTypeList()[index] ); 129 phoneNumber.setType( PhoneNumber::supportedTypeList()[index] );
127 edit->setPhoneNumber( phoneNumber ); 130 edit->setPhoneNumber( phoneNumber );
128 //verticalScrollBar()->setValue( 1024); 131 //verticalScrollBar()->setValue( 1024);
129 QTimer::singleShot( 0, this, SLOT ( bottomVisible() ) ); 132 QTimer::singleShot( 0, this, SLOT ( bottomVisible() ) );
130} 133}
131void PhoneEditWidget::bottomVisible() 134void PhoneEditWidget::bottomVisible()
132{ 135{
133 sv->setContentsPos ( 0, 1024 ); 136 sv->setContentsPos ( 0, 1024 );
134} 137}
135void PhoneEditWidget::addNumber() 138void PhoneEditWidget::addNumber()
136{ 139{
137 int i = 0; 140 int i = 0;
138 while ( i < mPopupCount ) { 141 while ( i < mPopupCount ) {
139 mPopup->setItemEnabled( i, true ); 142 mPopup->setItemEnabled( i, true );
140 ++i; 143 ++i;
141 } 144 }
142 PhoneTypeNumberEdit* edit = mTypeNumberEditList.first(); 145 PhoneTypeNumberEdit* edit = mTypeNumberEditList.first();
143 while ( edit ) { 146 while ( edit ) {
144 if ( edit->currentType() < mPopupCount -1 ) 147 if ( edit->currentType() < mPopupCount -1 )
145 mPopup->setItemEnabled( edit->currentType(), false ); 148 mPopup->setItemEnabled( edit->currentType(), false );
146 edit = mTypeNumberEditList.next(); 149 edit = mTypeNumberEditList.next();
147 } 150 }
148 mPopup->popup( QCursor::pos() ); 151 mPopup->popup( QCursor::pos() );
149} 152}
150PhoneTypeNumberEdit* PhoneEditWidget::appendEditCombo() 153PhoneTypeNumberEdit* PhoneEditWidget::appendEditCombo()
151{ 154{
152 PhoneTypeNumberEdit* edit = new PhoneTypeNumberEdit( mw ); 155 PhoneTypeNumberEdit* edit = new PhoneTypeNumberEdit( mw );
153 connect ( edit, SIGNAL ( typeChange( int , int) ), this, SIGNAL ( typeChange( int , int)) ); 156 connect ( edit, SIGNAL ( typeChange( int , int) ), this, SIGNAL ( typeChange( int , int)) );
154 connect ( edit, SIGNAL ( modified() ), this, SIGNAL ( modified() ) ); 157 connect ( edit, SIGNAL ( modified() ), this, SIGNAL ( modified() ) );
155 connect ( edit, SIGNAL ( deleteMe( PhoneTypeNumberEdit* ) ), this, SLOT ( deleteEdit( PhoneTypeNumberEdit*) ) ); 158 connect ( edit, SIGNAL ( deleteMe( PhoneTypeNumberEdit* ) ), this, SLOT ( deleteEdit( PhoneTypeNumberEdit*) ) );
156 connect ( this, SIGNAL ( typeChange( int , int)), edit, SLOT ( typeExternalChanged( int, int)) ); 159 connect ( this, SIGNAL ( typeChange( int , int)), edit, SLOT ( typeExternalChanged( int, int)) );
157 160
158 mainLayout->add( edit ); 161 mainLayout->add( edit );
159 mTypeNumberEditList.append( edit ); 162 mTypeNumberEditList.append( edit );
160 return edit; 163 return edit;
161} 164}
162 165
163void PhoneEditWidget::deleteEdit( PhoneTypeNumberEdit* ew ) 166void PhoneEditWidget::deleteEdit( PhoneTypeNumberEdit* ew )
164{ 167{
165 mPendingDelete = ew; 168 mPendingDelete = ew;
166 QTimer::singleShot( 0, this, SLOT ( pendingDelete() ) ); 169 QTimer::singleShot( 0, this, SLOT ( pendingDelete() ) );
167} 170}