ContactListEdit::ContactListEdit( QWidget* parent ) :QTextEdit(parent) { _completer = nullptr; connect( this, &QTextEdit::textChanged, this, &ContactListEdit::fitHeightToDocument ); setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred ); fitHeightToDocument(); setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); }
ContactListEdit::ContactListEdit(QWidget* parent) : QTextEdit(parent) { _completer = nullptr; _clicked_contact = new bts::addressbook::wallet_contact(); connect(this, &QTextEdit::textChanged, this, &ContactListEdit::fitHeightToDocument); setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); fitHeightToDocument(); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); setTabChangesFocus(true); }
ContactListEdit::ContactListEdit(QWidget* parent) : QTextEdit(parent), _addressBookModel(nullptr), _completerModel(nullptr), _skipCompletion(false) { _completer = nullptr; connect(this, &QTextEdit::textChanged, this, &ContactListEdit::onTextChanged); setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); fitHeightToDocument(); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); setTabChangesFocus(true); }
void ContactListEdit::resizeEvent( QResizeEvent* e ) { fitHeightToDocument(); QTextEdit::resizeEvent(e); }
void ContactListEdit::resizeEvent(QResizeEvent* resize_event) { fitHeightToDocument(); QTextEdit::resizeEvent(resize_event); }
void ContactListEdit::onTextChanged() { /** Remember last changed text range in _activeCursor member. Will be used to replace entered text whith contact entry. */ QString text = textUnderCursor(&_activeCursor); if(_skipCompletion == false && _completer != nullptr && isReadOnly() == false && text.isEmpty() == false) { TAutoSkipCompletion asc(this); std::string textKey = text.toStdString(); bts::addressbook::wallet_contact matchedContact; bool contactFound = false; try { auto aBook = bts::get_profile()->get_addressbook(); auto contact = aBook->get_contact_by_display_name(textKey); contactFound = contact; if(contactFound == false) contact = aBook->get_contact_by_dac_id(textKey); if(contact) { contactFound = true; matchedContact = *contact; } } catch(const fc::exception& e) { wlog( "${e}", ("e",e.to_detail_string()) ); } bool semanticallyValidKey = false; if(contactFound) { /// Delete previously entered text - will be replaced with image control holding contact info deleteEnteredText(); /// Update PK-like text with displayed form text = QString::fromStdString(matchedContact.get_display_name()); /// If text already points to some found contact, just add it addContactEntry(text, matchedContact, false); } else if(public_key_address::is_valid(textKey, &semanticallyValidKey) && semanticallyValidKey) { /// Delete previously entered text - will be replaced with image control holding contact info deleteEnteredText(); public_key_address converter(textKey); fc::ecc::public_key parsedKey = converter.key; if(Utils::matchContact(parsedKey, &matchedContact)) { QString displayText = _completerModel->getDisplayText(Contact(matchedContact)); addContactEntry(displayText, matchedContact, false); QString txt = tr("Known public key has been replaced with matching contact..."); /// Don't pass here parent widget to avoid switching active window when tooltip appears QToolTip::showText(QCursor::pos(), txt, nullptr, QRect(), 3000); } else { QString tooltip = tr("Valid, but <b>unknown</b> public key, cannot be matched to any contact " "present in address book..."); addContactEntry(text, matchedContact, true, &tooltip); } } else { QTextCharFormat fmt; fmt.setFontWeight(QFont::Bold); fmt.setForeground(QColor(Qt::red)); fmt.setToolTip(tr("Unknown contact - can be <b>ignored</b> while sending message")); _activeCursor.mergeCharFormat(fmt); showCompleter(text); } } fitHeightToDocument(); }