summaryrefslogtreecommitdiffabout
path: root/kaddressbook/phoneeditwidget.cpp
Unidiff
Diffstat (limited to 'kaddressbook/phoneeditwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/phoneeditwidget.cpp80
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
@@ -10,117 +10,153 @@
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
53PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name ) 54PhoneEditWidget::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
82PhoneEditWidget::~PhoneEditWidget() 94PhoneEditWidget::~PhoneEditWidget()
83{ 95{
84} 96}
85void PhoneEditWidget::setDefaults() 97void 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}
112void 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}
121void PhoneEditWidget::bottomVisible()
122{
123 sv->setContentsPos ( 0, 1024 );
124}
100void PhoneEditWidget::addNumber() 125void 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}
104PhoneTypeNumberEdit* PhoneEditWidget::appendEditCombo() 140PhoneTypeNumberEdit* 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
117void PhoneEditWidget::deleteEdit( PhoneTypeNumberEdit* ew ) 153void 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}
122void PhoneEditWidget::pendingDelete() 158void PhoneEditWidget::pendingDelete()
123{ 159{
124 mTypeNumberEditList.removeRef( mPendingDelete ); 160 mTypeNumberEditList.removeRef( mPendingDelete );
125 emit modified(); 161 emit modified();
126} 162}