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 | |||
@@ -31,6 +31,7 @@ | |||
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> |
@@ -51,32 +52,43 @@ | |||
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() |
@@ -97,9 +109,33 @@ void PhoneEditWidget::setDefaults() | |||
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 | { |