-rw-r--r-- | kaddressbook/phoneeditwidget.h | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/kaddressbook/phoneeditwidget.h b/kaddressbook/phoneeditwidget.h index f61087b..5bb4226 100644 --- a/kaddressbook/phoneeditwidget.h +++ b/kaddressbook/phoneeditwidget.h | |||
@@ -1,185 +1,186 @@ | |||
1 | #ifndef PHONEEDITWIDGET_H | 1 | #ifndef PHONEEDITWIDGET_H |
2 | #define PHONEEDITWIDGET_H | 2 | #define PHONEEDITWIDGET_H |
3 | /* | 3 | /* |
4 | This file is part of KAddressBook. | 4 | This file is part of KAddressBook. |
5 | Copyright (c) 2002 Mike Pilone <mpilone@slac.com> | 5 | Copyright (c) 2002 Mike Pilone <mpilone@slac.com> |
6 | 6 | ||
7 | This program is free software; you can redistribute it and/or modify | 7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | 8 | it under the terms of the GNU General Public License as published by |
9 | the Free Software Foundation; either version 2 of the License, or | 9 | the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. | 10 | (at your option) any later version. |
11 | 11 | ||
12 | This program is distributed in the hope that it will be useful, | 12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. | 15 | GNU General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU General Public License | 17 | You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software | 18 | along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
20 | 20 | ||
21 | As a special exception, permission is given to link this program | 21 | As a special exception, permission is given to link this program |
22 | with any edition of Qt, and distribute the resulting executable, | 22 | with any edition of Qt, and distribute the resulting executable, |
23 | without including the source code for Qt in the source distribution. | 23 | without including the source code for Qt in the source distribution. |
24 | */ | 24 | */ |
25 | 25 | ||
26 | #include <kdialogbase.h> | 26 | #include <kdialogbase.h> |
27 | #include <kiconloader.h> | 27 | #include <kiconloader.h> |
28 | #include <qpushbutton.h> | 28 | #include <qpushbutton.h> |
29 | #include <qlayout.h> | 29 | #include <qlayout.h> |
30 | #include <qpopupmenu.h> | 30 | #include <qpopupmenu.h> |
31 | #include <qapplication.h> | ||
31 | 32 | ||
32 | #include <qptrlist.h> | 33 | #include <qptrlist.h> |
33 | #include <qscrollview.h> | 34 | #include <qscrollview.h> |
34 | 35 | ||
35 | #include "addresseeconfig.h" | 36 | #include "addresseeconfig.h" |
36 | #include "typecombo.h" | 37 | #include "typecombo.h" |
37 | 38 | ||
38 | class QButtonGroup; | 39 | class QButtonGroup; |
39 | class QCheckBox; | 40 | class QCheckBox; |
40 | class PhoneTypeNumberEdit; | 41 | class PhoneTypeNumberEdit; |
41 | 42 | ||
42 | #include <klineedit.h> | 43 | #include <klineedit.h> |
43 | #include <kcombobox.h> | 44 | #include <kcombobox.h> |
44 | #include <kabc/phonenumber.h> | 45 | #include <kabc/phonenumber.h> |
45 | 46 | ||
46 | typedef TypeCombo<KABC::PhoneNumber> PhoneTypeCombo; | 47 | typedef TypeCombo<KABC::PhoneNumber> PhoneTypeCombo; |
47 | 48 | ||
48 | /** | 49 | /** |
49 | Widget for editing phone numbers. | 50 | Widget for editing phone numbers. |
50 | */ | 51 | */ |
51 | class PhoneEditWidget : public QWidget | 52 | class PhoneEditWidget : public QWidget |
52 | { | 53 | { |
53 | Q_OBJECT | 54 | Q_OBJECT |
54 | 55 | ||
55 | public: | 56 | public: |
56 | PhoneEditWidget( QWidget *parent, const char *name = 0 ); | 57 | PhoneEditWidget( QWidget *parent, const char *name = 0 ); |
57 | ~PhoneEditWidget(); | 58 | ~PhoneEditWidget(); |
58 | 59 | ||
59 | void setPhoneNumbers( const KABC::PhoneNumber::List &list ); | 60 | void setPhoneNumbers( const KABC::PhoneNumber::List &list ); |
60 | KABC::PhoneNumber::List phoneNumbers(); | 61 | KABC::PhoneNumber::List phoneNumbers(); |
61 | 62 | ||
62 | // void updateTypeCombo( const KABC::PhoneNumber::List&, KComboBox* ); | 63 | // void updateTypeCombo( const KABC::PhoneNumber::List&, KComboBox* ); |
63 | //KABC::PhoneNumber currentPhoneNumber( KComboBox*, int ); | 64 | //KABC::PhoneNumber currentPhoneNumber( KComboBox*, int ); |
64 | 65 | ||
65 | signals: | 66 | signals: |
66 | void modified(); | 67 | void modified(); |
67 | void typeChange( int oldType, int newType ); | 68 | void typeChange( int oldType, int newType ); |
68 | 69 | ||
69 | private slots: | 70 | private slots: |
70 | void bottomVisible(); | 71 | void bottomVisible(); |
71 | void addNumberInt( int ); | 72 | void addNumberInt( int ); |
72 | void deleteEdit( PhoneTypeNumberEdit* ew ); | 73 | void deleteEdit( PhoneTypeNumberEdit* ew ); |
73 | void addNumber(); | 74 | void addNumber(); |
74 | void pendingDelete(); | 75 | void pendingDelete(); |
75 | protected: | 76 | protected: |
76 | 77 | ||
77 | private: | 78 | private: |
78 | QScrollView* sv; | 79 | QScrollView* sv; |
79 | QPopupMenu *mPopup; | 80 | QPopupMenu *mPopup; |
80 | int mPopupCount; | 81 | int mPopupCount; |
81 | PhoneTypeNumberEdit* mPendingDelete; | 82 | PhoneTypeNumberEdit* mPendingDelete; |
82 | void setDefaults(); | 83 | void setDefaults(); |
83 | PhoneTypeNumberEdit* appendEditCombo(); | 84 | PhoneTypeNumberEdit* appendEditCombo(); |
84 | QWidget* mw; | 85 | QWidget* mw; |
85 | QVBoxLayout* mainLayout; | 86 | QVBoxLayout* mainLayout; |
86 | QPtrList <PhoneTypeNumberEdit> mTypeNumberEditList; | 87 | QPtrList <PhoneTypeNumberEdit> mTypeNumberEditList; |
87 | 88 | ||
88 | }; | 89 | }; |
89 | 90 | ||
90 | 91 | ||
91 | class PhoneTypeNumberEdit : public QWidget | 92 | class PhoneTypeNumberEdit : public QWidget |
92 | { | 93 | { |
93 | Q_OBJECT | 94 | Q_OBJECT |
94 | public: | 95 | public: |
95 | PhoneTypeNumberEdit( QWidget *parent, const char *name = 0 ) :QWidget( parent ) | 96 | PhoneTypeNumberEdit( QWidget *parent, const char *name = 0 ) :QWidget( parent ) |
96 | { | 97 | { |
97 | QHBoxLayout * lay = new QHBoxLayout( this ); | 98 | QHBoxLayout * lay = new QHBoxLayout( this ); |
98 | lay->setSpacing( 2 ); | 99 | lay->setSpacing( 2 ); |
99 | lay->setMargin( 0 ); | 100 | lay->setMargin( 0 ); |
100 | mMinusButton = new QPushButton ( this ); | 101 | mMinusButton = new QPushButton ( this ); |
101 | mMinusButton->setPixmap ( SmallIcon("minus")); | 102 | mMinusButton->setPixmap ( SmallIcon("minus")); |
102 | mCombo = new KComboBox( this ); | 103 | mCombo = new KComboBox( this ); |
103 | if ( QApplication::desktop()->width() <= 640 ) | 104 | if ( QApplication::desktop()->width() <= 640 ) |
104 | mCombo->setSizeLimit ( 6 ); | 105 | mCombo->setSizeLimit ( 6 ); |
105 | mNumber = new KLineEdit( this ); | 106 | mNumber = new KLineEdit( this ); |
106 | mMinusButton->setMaximumHeight( mNumber->sizeHint().height() + 6); | 107 | mMinusButton->setMaximumHeight( mNumber->sizeHint().height() + 6); |
107 | lay->addWidget( mMinusButton ); | 108 | lay->addWidget( mMinusButton ); |
108 | lay->addWidget( mCombo ); | 109 | lay->addWidget( mCombo ); |
109 | lay->addWidget( mNumber ); | 110 | lay->addWidget( mNumber ); |
110 | connect( mMinusButton , SIGNAL ( clicked() ), this, SLOT ( deleteNumber() ) ); | 111 | connect( mMinusButton , SIGNAL ( clicked() ), this, SLOT ( deleteNumber() ) ); |
111 | connect( mCombo , SIGNAL ( activated ( int ) ), this, SLOT ( comboTypeChange( int ) ) ); | 112 | connect( mCombo , SIGNAL ( activated ( int ) ), this, SLOT ( comboTypeChange( int ) ) ); |
112 | connect( mNumber , SIGNAL ( textChanged ( const QString & ) ), | 113 | connect( mNumber , SIGNAL ( textChanged ( const QString & ) ), |
113 | this, SLOT ( textChanged ( const QString & ) ) ); | 114 | this, SLOT ( textChanged ( const QString & ) ) ); |
114 | mCombo->insertStringList( PhoneNumber::supportedTypeListNames() ); | 115 | mCombo->insertStringList( PhoneNumber::supportedTypeListNames() ); |
115 | } | 116 | } |
116 | ~PhoneTypeNumberEdit() { | 117 | ~PhoneTypeNumberEdit() { |
117 | // qDebug("~PhoneTypeNumberEdit() "); | 118 | // qDebug("~PhoneTypeNumberEdit() "); |
118 | } | 119 | } |
119 | void setPhoneNumber( const KABC::PhoneNumber &phoneNumber ) | 120 | void setPhoneNumber( const KABC::PhoneNumber &phoneNumber ) |
120 | { | 121 | { |
121 | mPhoneNumber = phoneNumber; | 122 | mPhoneNumber = phoneNumber; |
122 | int index = PhoneNumber::typeListIndex4Type( mPhoneNumber.type() ); | 123 | int index = PhoneNumber::typeListIndex4Type( mPhoneNumber.type() ); |
123 | mCombo->setCurrentItem( index ); | 124 | mCombo->setCurrentItem( index ); |
124 | mNumber->setText( mPhoneNumber.number() ); | 125 | mNumber->setText( mPhoneNumber.number() ); |
125 | show(); | 126 | show(); |
126 | mNumber->setFocus(); | 127 | mNumber->setFocus(); |
127 | } | 128 | } |
128 | KABC::PhoneNumber phoneNumber() | 129 | KABC::PhoneNumber phoneNumber() |
129 | { | 130 | { |
130 | mPhoneNumber.setNumber( mNumber->text() ); | 131 | mPhoneNumber.setNumber( mNumber->text() ); |
131 | int index = mCombo->currentItem(); | 132 | int index = mCombo->currentItem(); |
132 | mPhoneNumber.setType( PhoneNumber::supportedTypeList()[index] ); | 133 | mPhoneNumber.setType( PhoneNumber::supportedTypeList()[index] ); |
133 | return mPhoneNumber; | 134 | return mPhoneNumber; |
134 | } | 135 | } |
135 | bool isValid() | 136 | bool isValid() |
136 | { | 137 | { |
137 | if ( mNumber->text().isEmpty() )return false; | 138 | if ( mNumber->text().isEmpty() )return false; |
138 | return true; | 139 | return true; |
139 | } | 140 | } |
140 | int currentType() | 141 | int currentType() |
141 | { | 142 | { |
142 | return mCombo->currentItem(); | 143 | return mCombo->currentItem(); |
143 | } | 144 | } |
144 | private slots: | 145 | private slots: |
145 | void typeExternalChanged( int oldType, int newType ) | 146 | void typeExternalChanged( int oldType, int newType ) |
146 | { | 147 | { |
147 | if ( mPhoneNumber.type() == newType ) { | 148 | if ( mPhoneNumber.type() == newType ) { |
148 | mPhoneNumber.setType(oldType); | 149 | mPhoneNumber.setType(oldType); |
149 | int index = PhoneNumber::typeListIndex4Type( mPhoneNumber.type() ); | 150 | int index = PhoneNumber::typeListIndex4Type( mPhoneNumber.type() ); |
150 | mCombo->setCurrentItem( index ); | 151 | mCombo->setCurrentItem( index ); |
151 | } | 152 | } |
152 | } | 153 | } |
153 | void deleteNumber() | 154 | void deleteNumber() |
154 | { | 155 | { |
155 | emit deleteMe( this ); | 156 | emit deleteMe( this ); |
156 | } | 157 | } |
157 | void comboTypeChange( int index ) | 158 | void comboTypeChange( int index ) |
158 | { | 159 | { |
159 | int old = mPhoneNumber.type(); | 160 | int old = mPhoneNumber.type(); |
160 | int newT = PhoneNumber::supportedTypeList()[index]; | 161 | int newT = PhoneNumber::supportedTypeList()[index]; |
161 | if ( old != newT ) { | 162 | if ( old != newT ) { |
162 | emit modified(); | 163 | emit modified(); |
163 | if ( newT != PhoneNumber::Voice ) | 164 | if ( newT != PhoneNumber::Voice ) |
164 | emit typeChange ( old, newT ); | 165 | emit typeChange ( old, newT ); |
165 | mPhoneNumber.setType(newT ); | 166 | mPhoneNumber.setType(newT ); |
166 | } | 167 | } |
167 | 168 | ||
168 | } | 169 | } |
169 | void textChanged ( const QString & ) | 170 | void textChanged ( const QString & ) |
170 | { | 171 | { |
171 | emit modified(); | 172 | emit modified(); |
172 | } | 173 | } |
173 | signals: | 174 | signals: |
174 | void typeChange( int oldType, int newType ); | 175 | void typeChange( int oldType, int newType ); |
175 | void modified(); | 176 | void modified(); |
176 | void deleteMe( PhoneTypeNumberEdit* ); | 177 | void deleteMe( PhoneTypeNumberEdit* ); |
177 | 178 | ||
178 | private: | 179 | private: |
179 | KABC::PhoneNumber mPhoneNumber; | 180 | KABC::PhoneNumber mPhoneNumber; |
180 | QPushButton* mMinusButton; | 181 | QPushButton* mMinusButton; |
181 | KComboBox *mCombo; | 182 | KComboBox *mCombo; |
182 | KLineEdit *mNumber; | 183 | KLineEdit *mNumber; |
183 | }; | 184 | }; |
184 | 185 | ||
185 | #endif | 186 | #endif |