author | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
commit | a08aff328d4393031d5ba7d622c2b05705a89d73 (patch) (unidiff) | |
tree | 8ee90d686081c52e7c69b5ce946e9b1a7d690001 /microkde/keditlistbox.cpp | |
parent | 11edc920afe4f274c0964436633aa632c8288a40 (diff) | |
download | kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.zip kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.gz kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.bz2 |
initial public commit of qt4 portp1
-rw-r--r-- | microkde/keditlistbox.cpp | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/microkde/keditlistbox.cpp b/microkde/keditlistbox.cpp index 55b7784..257a44a 100644 --- a/microkde/keditlistbox.cpp +++ b/microkde/keditlistbox.cpp | |||
@@ -8,121 +8,124 @@ | |||
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library 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 GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <qstringlist.h> | 21 | #include <qstringlist.h> |
22 | #include <qpushbutton.h> | 22 | #include <qpushbutton.h> |
23 | #include <qlayout.h> | 23 | #include <qlayout.h> |
24 | #include <qgroupbox.h> | 24 | #include <q3groupbox.h> |
25 | #include <qlistbox.h> | 25 | #include <q3listbox.h> |
26 | #include <qwhatsthis.h> | 26 | #include <q3whatsthis.h> |
27 | #include <qlabel.h> | 27 | #include <qlabel.h> |
28 | //Added by qt3to4: | ||
29 | #include <Q3GridLayout> | ||
30 | #include <Q3StrList> | ||
28 | 31 | ||
29 | #include <kcombobox.h> | 32 | #include <kcombobox.h> |
30 | #include <kdebug.h> | 33 | #include <kdebug.h> |
31 | #include <kdialog.h> | 34 | #include <kdialog.h> |
32 | #include <klineedit.h> | 35 | #include <klineedit.h> |
33 | #include <klocale.h> | 36 | #include <klocale.h> |
34 | #include <kapplication.h> | 37 | #include <kapplication.h> |
35 | #include <knotifyclient.h> | 38 | #include <knotifyclient.h> |
36 | 39 | ||
37 | #include "keditlistbox.h" | 40 | #include "keditlistbox.h" |
38 | 41 | ||
39 | #include <assert.h> | 42 | #include <assert.h> |
40 | 43 | ||
41 | class KEditListBoxPrivate | 44 | class KEditListBoxPrivate |
42 | { | 45 | { |
43 | public: | 46 | public: |
44 | bool m_checkAtEntering; | 47 | bool m_checkAtEntering; |
45 | int buttons; | 48 | int buttons; |
46 | }; | 49 | }; |
47 | 50 | ||
48 | KEditListBox::KEditListBox(QWidget *parent, const char *name, | 51 | KEditListBox::KEditListBox(QWidget *parent, const char *name, |
49 | bool checkAtEntering, int buttons ) | 52 | bool checkAtEntering, int buttons ) |
50 | :QGroupBox(parent, name ) | 53 | :Q3GroupBox(parent, name ) |
51 | { | 54 | { |
52 | init( checkAtEntering, buttons ); | 55 | init( checkAtEntering, buttons ); |
53 | } | 56 | } |
54 | 57 | ||
55 | KEditListBox::KEditListBox(const QString& title, QWidget *parent, | 58 | KEditListBox::KEditListBox(const QString& title, QWidget *parent, |
56 | const char *name, bool checkAtEntering, int buttons) | 59 | const char *name, bool checkAtEntering, int buttons) |
57 | :QGroupBox(title, parent, name ) | 60 | :Q3GroupBox(title, parent, name ) |
58 | { | 61 | { |
59 | init( checkAtEntering, buttons ); | 62 | init( checkAtEntering, buttons ); |
60 | } | 63 | } |
61 | 64 | ||
62 | KEditListBox::KEditListBox(const QString& title, const CustomEditor& custom, | 65 | KEditListBox::KEditListBox(const QString& title, const CustomEditor& custom, |
63 | QWidget *parent, const char *name, | 66 | QWidget *parent, const char *name, |
64 | bool checkAtEntering, int buttons) | 67 | bool checkAtEntering, int buttons) |
65 | :QGroupBox(title, parent, name ) | 68 | :Q3GroupBox(title, parent, name ) |
66 | { | 69 | { |
67 | m_lineEdit = custom.lineEdit(); | 70 | m_lineEdit = custom.lineEdit(); |
68 | init( checkAtEntering, buttons, custom.representationWidget() ); | 71 | init( checkAtEntering, buttons, custom.representationWidget() ); |
69 | } | 72 | } |
70 | 73 | ||
71 | KEditListBox::~KEditListBox() | 74 | KEditListBox::~KEditListBox() |
72 | { | 75 | { |
73 | delete d; | 76 | delete d; |
74 | d=0; | 77 | d=0; |
75 | } | 78 | } |
76 | 79 | ||
77 | void KEditListBox::init( bool checkAtEntering, int buttons, | 80 | void KEditListBox::init( bool checkAtEntering, int buttons, |
78 | QWidget *representationWidget ) | 81 | QWidget *representationWidget ) |
79 | { | 82 | { |
80 | d=new KEditListBoxPrivate; | 83 | d=new KEditListBoxPrivate; |
81 | d->m_checkAtEntering=checkAtEntering; | 84 | d->m_checkAtEntering=checkAtEntering; |
82 | d->buttons = buttons; | 85 | d->buttons = buttons; |
83 | 86 | ||
84 | int lostButtons = 0; | 87 | int lostButtons = 0; |
85 | if ( (buttons & Add) == 0 ) | 88 | if ( (buttons & Add) == 0 ) |
86 | lostButtons++; | 89 | lostButtons++; |
87 | if ( (buttons & Remove) == 0 ) | 90 | if ( (buttons & Remove) == 0 ) |
88 | lostButtons++; | 91 | lostButtons++; |
89 | if ( (buttons & UpDown) == 0 ) | 92 | if ( (buttons & UpDown) == 0 ) |
90 | lostButtons += 2; | 93 | lostButtons += 2; |
91 | 94 | ||
92 | 95 | ||
93 | servNewButton = servRemoveButton = servUpButton = servDownButton = 0L; | 96 | servNewButton = servRemoveButton = servUpButton = servDownButton = 0L; |
94 | setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, | 97 | setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, |
95 | QSizePolicy::MinimumExpanding)); | 98 | QSizePolicy::MinimumExpanding)); |
96 | 99 | ||
97 | QWidget * gb = this; | 100 | QWidget * gb = this; |
98 | QGridLayout * grid = new QGridLayout(gb, 7 - lostButtons, 2, | 101 | Q3GridLayout * grid = new Q3GridLayout(gb, 7 - lostButtons, 2, |
99 | KDialog::marginHint(), | 102 | KDialog::marginHint(), |
100 | KDialog::spacingHint()); | 103 | KDialog::spacingHint()); |
101 | grid->addRowSpacing(0, fontMetrics().lineSpacing()); | 104 | grid->addRowSpacing(0, fontMetrics().lineSpacing()); |
102 | for ( int i = 1; i < 7 - lostButtons; i++ ) | 105 | for ( int i = 1; i < 7 - lostButtons; i++ ) |
103 | grid->setRowStretch(i, 1); | 106 | grid->setRowStretch(i, 1); |
104 | 107 | ||
105 | grid->setMargin(15); | 108 | grid->setMargin(15); |
106 | 109 | ||
107 | if ( representationWidget ) | 110 | if ( representationWidget ) |
108 | representationWidget->reparent( gb, QPoint(0,0) ); | 111 | representationWidget->reparent( gb, QPoint(0,0) ); |
109 | else | 112 | else |
110 | m_lineEdit=new KLineEdit(gb); | 113 | m_lineEdit=new KLineEdit(gb); |
111 | 114 | ||
112 | m_listBox = new QListBox(gb); | 115 | m_listBox = new Q3ListBox(gb); |
113 | 116 | ||
114 | QWidget *editingWidget = representationWidget ? | 117 | QWidget *editingWidget = representationWidget ? |
115 | representationWidget : m_lineEdit; | 118 | representationWidget : m_lineEdit; |
116 | grid->addMultiCellWidget(editingWidget,1,1,0,1); | 119 | grid->addMultiCellWidget(editingWidget,1,1,0,1); |
117 | grid->addMultiCellWidget(m_listBox, 2, 6 - lostButtons, 0, 0); | 120 | grid->addMultiCellWidget(m_listBox, 2, 6 - lostButtons, 0, 0); |
118 | int row = 2; | 121 | int row = 2; |
119 | if ( buttons & Add ) { | 122 | if ( buttons & Add ) { |
120 | servNewButton = new QPushButton(i18n("&Add"), gb); | 123 | servNewButton = new QPushButton(i18n("&Add"), gb); |
121 | servNewButton->setEnabled(false); | 124 | servNewButton->setEnabled(false); |
122 | connect(servNewButton, SIGNAL(clicked()), SLOT(addItem())); | 125 | connect(servNewButton, SIGNAL(clicked()), SLOT(addItem())); |
123 | 126 | ||
124 | grid->addWidget(servNewButton, row++, 1); | 127 | grid->addWidget(servNewButton, row++, 1); |
125 | } | 128 | } |
126 | 129 | ||
127 | if ( buttons & Remove ) { | 130 | if ( buttons & Remove ) { |
128 | servRemoveButton = new QPushButton(i18n("&Remove"), gb); | 131 | servRemoveButton = new QPushButton(i18n("&Remove"), gb); |
@@ -191,56 +194,56 @@ void KEditListBox::typedSomething(const QString& text) | |||
191 | 194 | ||
192 | void KEditListBox::moveItemUp() | 195 | void KEditListBox::moveItemUp() |
193 | { | 196 | { |
194 | if (!m_listBox->isEnabled()) | 197 | if (!m_listBox->isEnabled()) |
195 | { | 198 | { |
196 | KNotifyClient::beep(); | 199 | KNotifyClient::beep(); |
197 | return; | 200 | return; |
198 | } | 201 | } |
199 | 202 | ||
200 | unsigned int selIndex = m_listBox->currentItem(); | 203 | unsigned int selIndex = m_listBox->currentItem(); |
201 | if (selIndex == 0) | 204 | if (selIndex == 0) |
202 | { | 205 | { |
203 | KNotifyClient::beep(); | 206 | KNotifyClient::beep(); |
204 | return; | 207 | return; |
205 | } | 208 | } |
206 | 209 | ||
207 | QListBoxItem *selItem = m_listBox->item(selIndex); | 210 | Q3ListBoxItem *selItem = m_listBox->item(selIndex); |
208 | m_listBox->takeItem(selItem); | 211 | m_listBox->takeItem(selItem); |
209 | m_listBox->insertItem(selItem, selIndex-1); | 212 | m_listBox->insertItem(selItem, selIndex-1); |
210 | m_listBox->setCurrentItem(selIndex - 1); | 213 | m_listBox->setCurrentItem(selIndex - 1); |
211 | 214 | ||
212 | emit changed(); | 215 | emit changed(); |
213 | } | 216 | } |
214 | 217 | ||
215 | void KEditListBox::moveItemDown() | 218 | void KEditListBox::moveItemDown() |
216 | { | 219 | { |
217 | if (!m_listBox->isEnabled()) | 220 | if (!m_listBox->isEnabled()) |
218 | { | 221 | { |
219 | KNotifyClient::beep(); | 222 | KNotifyClient::beep(); |
220 | return; | 223 | return; |
221 | } | 224 | } |
222 | 225 | ||
223 | unsigned int selIndex = m_listBox->currentItem(); | 226 | unsigned int selIndex = m_listBox->currentItem(); |
224 | if (selIndex == m_listBox->count() - 1) | 227 | if (selIndex == m_listBox->count() - 1) |
225 | { | 228 | { |
226 | KNotifyClient::beep(); | 229 | KNotifyClient::beep(); |
227 | return; | 230 | return; |
228 | } | 231 | } |
229 | 232 | ||
230 | QListBoxItem *selItem = m_listBox->item(selIndex); | 233 | Q3ListBoxItem *selItem = m_listBox->item(selIndex); |
231 | m_listBox->takeItem(selItem); | 234 | m_listBox->takeItem(selItem); |
232 | m_listBox->insertItem(selItem, selIndex+1); | 235 | m_listBox->insertItem(selItem, selIndex+1); |
233 | m_listBox->setCurrentItem(selIndex + 1); | 236 | m_listBox->setCurrentItem(selIndex + 1); |
234 | 237 | ||
235 | emit changed(); | 238 | emit changed(); |
236 | } | 239 | } |
237 | 240 | ||
238 | void KEditListBox::addItem() | 241 | void KEditListBox::addItem() |
239 | { | 242 | { |
240 | // when m_checkAtEntering is true, the add-button is disabled, but this | 243 | // when m_checkAtEntering is true, the add-button is disabled, but this |
241 | // slot can still be called through Key_Return/Key_Enter. So we guard | 244 | // slot can still be called through Key_Return/Key_Enter. So we guard |
242 | // against this. | 245 | // against this. |
243 | if ( !servNewButton || !servNewButton->isEnabled() ) | 246 | if ( !servNewButton || !servNewButton->isEnabled() ) |
244 | return; | 247 | return; |
245 | 248 | ||
246 | const QString& currentTextLE=m_lineEdit->text(); | 249 | const QString& currentTextLE=m_lineEdit->text(); |
@@ -336,40 +339,42 @@ void KEditListBox::enableMoveButtons(int index) | |||
336 | if ( servRemoveButton ) | 339 | if ( servRemoveButton ) |
337 | servRemoveButton->setEnabled(true); | 340 | servRemoveButton->setEnabled(true); |
338 | } | 341 | } |
339 | 342 | ||
340 | void KEditListBox::clear() | 343 | void KEditListBox::clear() |
341 | { | 344 | { |
342 | m_lineEdit->clear(); | 345 | m_lineEdit->clear(); |
343 | m_listBox->clear(); | 346 | m_listBox->clear(); |
344 | emit changed(); | 347 | emit changed(); |
345 | } | 348 | } |
346 | 349 | ||
347 | void KEditListBox::insertStringList(const QStringList& list, int index) | 350 | void KEditListBox::insertStringList(const QStringList& list, int index) |
348 | { | 351 | { |
349 | m_listBox->insertStringList(list,index); | 352 | m_listBox->insertStringList(list,index); |
350 | } | 353 | } |
351 | 354 | ||
352 | void KEditListBox::insertStrList(const QStrList* list, int index) | 355 | void KEditListBox::insertStrList(const Q3StrList* list, int index) |
353 | { | 356 | { |
354 | m_listBox->insertStrList(list,index); | 357 | for(Q3StrList::const_iterator i=list->begin();i!=list->end();++i) |
358 | m_listBox->insertItem(*i,index++); | ||
355 | } | 359 | } |
356 | 360 | ||
357 | void KEditListBox::insertStrList(const QStrList& list, int index) | 361 | void KEditListBox::insertStrList(const Q3StrList& list, int index) |
358 | { | 362 | { |
359 | m_listBox->insertStrList(list,index); | 363 | for(Q3StrList::const_iterator i=list.begin();i!=list.end();++i) |
364 | m_listBox->insertItem(*i,index++); | ||
360 | } | 365 | } |
361 | 366 | ||
362 | void KEditListBox::insertStrList(const char ** list, int numStrings, int index) | 367 | void KEditListBox::insertStrList(const char ** list, int numStrings, int index) |
363 | { | 368 | { |
364 | m_listBox->insertStrList(list,numStrings,index); | 369 | m_listBox->insertStrList(list,numStrings,index); |
365 | } | 370 | } |
366 | 371 | ||
367 | QStringList KEditListBox::items() const | 372 | QStringList KEditListBox::items() const |
368 | { | 373 | { |
369 | QStringList list; | 374 | QStringList list; |
370 | for ( uint i = 0; i < m_listBox->count(); i++ ) | 375 | for ( uint i = 0; i < m_listBox->count(); i++ ) |
371 | list.append( m_listBox->text( i )); | 376 | list.append( m_listBox->text( i )); |
372 | 377 | ||
373 | return list; | 378 | return list; |
374 | } | 379 | } |
375 | 380 | ||