Changeset 6148
- Timestamp:
- 04/13/08 23:18:08 (8 months ago)
- Location:
- trunk/qt4-gui/src
- Files:
-
- 13 modified
-
contactlist/contactgroup.cpp (modified) (2 diffs)
-
contactlist/contactgroup.h (modified) (1 diff)
-
contactlist/contactitem.cpp (modified) (1 diff)
-
contactlist/contactitem.h (modified) (1 diff)
-
contactlist/contactlist.cpp (modified) (2 diffs)
-
contactlist/contactlist.h (modified) (1 diff)
-
contactlist/contactuser.cpp (modified) (1 diff)
-
contactlist/contactuser.h (modified) (1 diff)
-
contactlist/contactuserdata.cpp (modified) (4 diffs)
-
contactlist/contactuserdata.h (modified) (2 diffs)
-
views/contactdelegate.cpp (modified) (2 diffs)
-
views/contactdelegate.h (modified) (1 diff)
-
views/userviewbase.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/qt4-gui/src/contactlist/contactgroup.cpp
r5885 r6148 161 161 break; 162 162 163 case Qt::EditRole: 164 return myName; 165 163 166 case ContactListModel::ItemTypeRole: 164 167 return ContactListModel::GroupItem; … … 185 188 return QVariant(); 186 189 } 190 191 bool ContactGroup::setData(const QVariant& value, int role) 192 { 193 if (role != Qt::EditRole || !value.isValid()) 194 return false; 195 196 // Don't allow system groups or "Other users" to be renamed this way 197 if (myGroupId == 0 || myGroupId >= ContactListModel::SystemGroupOffset) 198 return false; 199 200 if (value.toString() == myName) 201 return true; 202 203 myName = value.toString(); 204 gUserManager.RenameGroup(myGroupId, myName.toLocal8Bit()); 205 206 // Daemon doesn't signal when groups change so trigger update from here 207 emit dataChanged(this); 208 209 return true; 210 } -
trunk/qt4-gui/src/contactlist/contactgroup.h
r5885 r6148 143 143 QVariant data(int column, int role) const; 144 144 145 /** 146 * Set data for this group 147 * 148 * @param value New value to set 149 * @param role Role to set 150 * @return True if any data was changed 151 */ 152 virtual bool setData(const QVariant& value, int role = Qt::EditRole); 153 145 154 signals: 146 155 /** -
trunk/qt4-gui/src/contactlist/contactitem.cpp
r5837 r6148 27 27 { 28 28 } 29 30 bool ContactItem::setData(const QVariant& /* value */, int /* role */) 31 { 32 return false; 33 } -
trunk/qt4-gui/src/contactlist/contactitem.h
r5837 r6148 66 66 virtual QVariant data(int column, int role) const = 0; 67 67 68 /** 69 * Set data for this item 70 * 71 * @param value New value to set 72 * @param role Role to set 73 * @return True if any data was changed 74 */ 75 virtual bool setData(const QVariant& value, int role = Qt::EditRole); 76 68 77 private: 69 78 ContactListModel::ItemType myItemType; -
trunk/qt4-gui/src/contactlist/contactlist.cpp
r5892 r6148 402 402 return Qt::ItemIsEnabled; 403 403 404 return Qt::ItemIsEnabled | Qt::ItemIsSelectable; 404 Qt::ItemFlags f = Qt::ItemIsEnabled | Qt::ItemIsSelectable; 405 406 ItemType itemType = static_cast<ContactItem*>(index.internalPointer())->itemType(); 407 408 // Only editing of alias for contacts 409 if (itemType == UserItem && Config::ContactList::instance()->columnFormat(index.column()) == "%a") 410 f |= Qt::ItemIsEditable; 411 412 // Group names are editable in first column unless it's a system group 413 if (itemType == GroupItem && index.column() == 0 && index.row() != 0 && index.row() < myUserGroups.size()) 414 f |= Qt::ItemIsEditable; 415 416 return f; 405 417 } 406 418 … … 449 461 return QModelIndex(); 450 462 } 463 464 bool ContactListModel::setData(const QModelIndex& index, const QVariant& value, int role) 465 { 466 return static_cast<ContactItem*>(index.internalPointer())->setData(value, role); 467 } -
trunk/qt4-gui/src/contactlist/contactlist.h
r5885 r6148 291 291 292 292 /** 293 * Set item data 294 * 295 * @param index Index for the item to update 296 * @param value Value to set 297 * @param role Role to update 298 */ 299 virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); 300 301 /** 293 302 * Get index for a specific user 294 303 * -
trunk/qt4-gui/src/contactlist/contactuser.cpp
r5837 r6148 52 52 return myUserData->data(column, role); 53 53 } 54 55 bool ContactUser::setData(const QVariant& value, int role) 56 { 57 return myUserData->setData(value, role); 58 } -
trunk/qt4-gui/src/contactlist/contactuser.h
r5885 r6148 99 99 QVariant data(int column, int role) const; 100 100 101 /** 102 * Set data for this user 103 * 104 * @param value New value to set 105 * @param role Role to set 106 * @return True if any data was changed 107 */ 108 virtual bool setData(const QVariant& value, int role = Qt::EditRole); 109 101 110 private: 102 111 ContactUserData* myUserData; -
trunk/qt4-gui/src/contactlist/contactuserdata.cpp
r6132 r6148 400 400 bool hasChanged = false; 401 401 402 myAlias = QString::fromUtf8(licqUser->GetAlias()); 403 402 404 for (unsigned short i = 0; i < Config::ContactList::instance()->columnCount(); i++) 403 405 { … … 410 412 free(temp); 411 413 412 temp = licqUser->usprintf("%a"); 413 QString alias = QString::fromUtf8(temp); 414 free(temp); 415 416 newStr.replace("@_USER_ALIAS_@", alias); 414 newStr.replace("@_USER_ALIAS_@", myAlias); 417 415 418 416 if (newStr != myText[i]) … … 471 469 } 472 470 471 bool ContactUserData::setData(const QVariant& value, int role) 472 { 473 if (role != Qt::EditRole || !value.isValid()) 474 return false; 475 476 if (value.toString() == myAlias) 477 return true; 478 479 ICQUser* u = gUserManager.FetchUser(myId.toLatin1(), myPpid, LOCK_R); 480 if (u == NULL) 481 return false; 482 483 myAlias = value.toString(); 484 u->SetAlias(myAlias.toUtf8()); 485 u->SetKeepAliasOnUpdate(true); 486 487 // Daemon dosen't send signal when alias is changed so trigger update from here 488 updateText(u); 489 updateSorting(); 490 491 gUserManager.DropUser(u); 492 493 emit dataChanged(this); 494 return true; 495 } 496 473 497 void ContactUserData::refresh() 474 498 { … … 558 582 return myText[column]; 559 583 break; 584 585 case Qt::EditRole: 586 return myAlias; 560 587 561 588 case Qt::ToolTipRole: -
trunk/qt4-gui/src/contactlist/contactuserdata.h
r5955 r6148 148 148 */ 149 149 QVariant data(int column, int role) const; 150 151 /** 152 * Set data for this user 153 * Currently only alias may be change this way 154 * 155 * @param value New value to set 156 * @param role Must be Qt::EditRole 157 * @return True if alias was changed 158 */ 159 virtual bool setData(const QVariant& value, int role = Qt::EditRole); 150 160 151 161 signals: … … 241 251 bool myUrgent; 242 252 QString myText[4]; 253 QString myAlias; 243 254 QList<ContactUser*> myUserInstances; 244 255 -
trunk/qt4-gui/src/views/contactdelegate.cpp
r6008 r6148 23 23 #include "contactdelegate.h" 24 24 25 #include <QApplication> 26 #include <QKeyEvent> 27 #include <QLineEdit> 25 28 #include <QPainter> 26 29 … … 495 498 #undef EXTICON 496 499 } 500 501 QWidget* ContactDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& /* option */, const QModelIndex& /* index */) const 502 { 503 QLineEdit* editor = new QLineEdit(parent); 504 505 // Don't use the view's skinned palette 506 editor->setPalette(QApplication::palette()); 507 508 return editor; 509 } 510 511 void ContactDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const 512 { 513 QString value = index.model()->data(index, Qt::EditRole).toString(); 514 515 QLineEdit* lineedit = dynamic_cast<QLineEdit*>(editor); 516 lineedit->setText(value); 517 } 518 519 void ContactDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const 520 { 521 QLineEdit* lineedit = dynamic_cast<QLineEdit*>(editor); 522 model->setData(index, lineedit->text(), Qt::EditRole); 523 } 524 525 void ContactDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const 526 { 527 QRect r = option.rect; 528 529 // Leave space for icon in first column 530 if (index.column() == 0) 531 r.setLeft(r.left() + 18); 532 533 editor->setGeometry(r); 534 } 535 536 bool ContactDelegate::eventFilter(QObject* object, QEvent* event) 537 { 538 QWidget* editor = qobject_cast<QWidget*>(object); 539 if (editor == NULL) 540 return false; 541 542 if (event->type() == QEvent::KeyPress) 543 { 544 switch (static_cast<QKeyEvent*>(event)->key()) 545 { 546 case Qt::Key_Enter: 547 case Qt::Key_Return: 548 emit commitData(editor); 549 emit closeEditor(editor, QAbstractItemDelegate::SubmitModelCache); 550 return true; 551 case Qt::Key_Escape: 552 // don't commit data 553 emit closeEditor(editor, QAbstractItemDelegate::RevertModelCache); 554 return true; 555 } 556 } 557 else if (event->type() == QEvent::FocusOut) 558 { 559 emit commitData(editor); 560 emit closeEditor(editor, NoHint); 561 } 562 563 return QAbstractItemDelegate::eventFilter(object, event); 564 } 565 -
trunk/qt4-gui/src/views/contactdelegate.h
r5930 r6148 72 72 virtual void paint(QPainter* p, const QStyleOptionViewItem& option, const QModelIndex& index) const; 73 73 74 /** 75 * Create widget that can be used for editing data in an item 76 * 77 * @param parent Parent widget for the editor 78 * @param option Style options 79 * @param index Item to edit 80 * @return An editor widget 81 */ 82 virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const; 83 84 /** 85 * Set data for an editor widget 86 * 87 * @param editor Existing editor widget to update with data 88 * @param index Item to get data from 89 */ 90 virtual void setEditorData(QWidget* editor, const QModelIndex& index) const; 91 92 /** 93 * Get data from editor widget and update model 94 * 95 * @param editor Existing editor widget with data 96 * @param model Model to write data to 97 * @param index Index of item to update 98 */ 99 virtual void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const; 100 101 /** 102 * Update geometry of an editor widget 103 * 104 * @param editor Existing editor widget to update geometry for 105 * @param option Style options, including new rect for editor 106 * @param index Index of item being edited 107 */ 108 virtual void updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const; 109 110 /** 111 * Catch events for other objects. Used to get events for editor widget 112 * 113 * @param object Object the event happened for 114 * @param event Event for that object 115 * @return True if event should not be forwarded to object 116 */ 117 virtual bool eventFilter(QObject* object, QEvent* event); 118 74 119 private: 75 120 /** -
trunk/qt4-gui/src/views/userviewbase.cpp
r6100 r6148 50 50 { 51 51 setItemDelegate(new ContactDelegate(this, this)); 52 setEditTriggers(EditKeyPressed); 52 53 53 54 // Look'n'Feel
