Example #1
0
	SearchModel::SearchModel(QObject *parent)
		: AbstractSearchModel(parent)
		, SearchRequested_(false)
	{
		connect(Ui::GetDispatcher(), SIGNAL(searchResult(QStringList)), this, SLOT(searchResult(QStringList)), Qt::QueuedConnection);
        connect(GetAvatarStorage(), SIGNAL(avatarChanged(QString)), this, SLOT(avatarLoaded(QString)), Qt::QueuedConnection);
        connect(Ui::GetDispatcher(), SIGNAL(contactRemoved(QString)), this, SLOT(contactRemoved(QString)), Qt::QueuedConnection);
	}
    void UnknownItemDelegate::paint(QPainter* _painter, const QStyleOptionViewItem& _option, const Data::DlgState& _dlg, bool _fromAlert, bool _dragOverlay) const
    {
        if (_dlg.AimId_ == ql1s("~delete_all~"))
        {
            _painter->save();
            _painter->setRenderHint(QPainter::Antialiasing);
            _painter->setRenderHint(QPainter::TextAntialiasing);
            _painter->setRenderHint(QPainter::SmoothPixmapTransform);
            _painter->translate(_option.rect.topLeft());

            const bool hasMouseOver = (platform::is_apple() ? Logic::getUnknownsModel()->customFlagIsSet(Logic::CustomAbstractListModelFlags::HasMouseOver) : true);
            const bool isSelected_ = (_option.state & QStyle::State_Selected) && !stateBlocked_;
            const bool isHovered_ = (_option.state & QStyle::State_MouseOver) && !stateBlocked_ && !isSelected_ && hasMouseOver;

            ContactList::RenderDeleteAllItem(* _painter, QT_TRANSLATE_NOOP("contact_list", "Close All"), isHovered_, viewParams_);

            _painter->restore();
            return;
        }

        const auto isMultichat = Logic::getContactListModel()->isChat(_dlg.AimId_);
        const auto state = isMultichat ? QString() : Logic::getContactListModel()->getState(_dlg.AimId_);

        bool isDefault = false;

        const auto avatar = *GetAvatarStorage()->GetRounded(
            _dlg.AimId_,
            QString(),
            Utils::scale_bitmap(ContactList::GetRecentsParams(viewParams_.regim_).getAvatarSize()),
            state,
            isDefault,
            false,
            ContactList::GetRecentsParams(viewParams_.regim_).isCL()
        );

        const bool hasMouseOver = (platform::is_apple() ? Logic::getUnknownsModel()->customFlagIsSet(Logic::CustomAbstractListModelFlags::HasMouseOver) : true);
        const bool isSelected_ = (_option.state & QStyle::State_Selected) && !stateBlocked_;
        const bool isHovered_ = (_option.state & QStyle::State_MouseOver) && !stateBlocked_ && !isSelected_ && hasMouseOver;

        const auto displayName = Logic::getContactListModel()->getDisplayName(_dlg.AimId_);

        auto message = _dlg.GetText();

        bool isOfficial = _dlg.Official_ || Logic::getContactListModel()->isOfficial(_dlg.AimId_);

        bool isDrawLastRead = false;

        QPixmap lastReadAvatar;

        bool isOutgoing = _dlg.Outgoing_;
        bool isLastRead = (_dlg.LastMsgId_ >= 0 && _dlg.TheirsLastRead_ > 0 && _dlg.LastMsgId_ <= _dlg.TheirsLastRead_);

        if (!isMultichat && isOutgoing && isLastRead && !Logic::GetMessagesModel()->hasPending(_dlg.AimId_))
        {
            lastReadAvatar = *GetAvatarStorage()->GetRounded(
                _dlg.AimId_, QString(),
                Utils::scale_bitmap(ContactList::GetRecentsParams(viewParams_.regim_).getLastReadAvatarSize()),
                QString(), isDefault, false, ContactList::GetRecentsParams(viewParams_.regim_).isCL());
            isDrawLastRead = true;
        }

        ContactList::RecentItemVisualData visData(
            _dlg.AimId_,
            avatar,
            state,
            message,
            isHovered_,
            isSelected_,
            displayName.isEmpty() ? _dlg.AimId_ : displayName,
            true /* hasLastSeen */,
            QDateTime::fromTime_t(_dlg.Time_),
            (int)_dlg.UnreadCount_,
            Logic::getContactListModel()->isMuted(_dlg.AimId_),
            _dlg.senderNick_,
            isOfficial,
            isDrawLastRead,
            lastReadAvatar,
            false /* isTyping */);

        _painter->save();
        _painter->setRenderHint(QPainter::Antialiasing);
        _painter->setRenderHint(QPainter::TextAntialiasing);
        _painter->setRenderHint(QPainter::SmoothPixmapTransform);
        _painter->translate(_option.rect.topLeft());

        ContactList::RenderRecentsItem(*_painter, visData, viewParams_, _option.rect);

        if (_dragOverlay)
            ContactList::RenderRecentsDragOverlay(*_painter, viewParams_);

        _painter->restore();
    }