conversationsfilterwidget.cpp 3.03 KB
Newer Older
1
/***************************************************************************
2
 * Copyright (C) 2019-2019 by Savoir-faire Linux                                *
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 * Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>          *
 *                                                                         *
 * This program is free software; you can redistribute it and/or modify    *
 * it under the terms of the GNU General Public License as published by    *
 * the Free Software Foundation; either version 3 of the License, or       *
 * (at your option) any later version.                                     *
 *                                                                         *
 * This program is distributed in the hope that it will be useful,         *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
 * GNU General Public License for more details.                            *
 *                                                                         *
 * You should have received a copy of the GNU General Public License       *
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.   *
 **************************************************************************/

#include "conversationsfilterwidget.h"

21 22 23
#include <QPainter>
#include <QDebug>

24
#include "ringthemeutils.h"
25
#include "lrcinstance.h"
26

27 28 29 30 31
ConversationsFilterWidget::ConversationsFilterWidget(QWidget *parent)
    : QWidget(parent)
{
}

32
void ConversationsFilterWidget::updateBadges()
33 34 35 36 37 38
{
    using namespace lrc::api::profile;
    updateNotifier(Type::RING);
    updateNotifier(Type::PENDING);
}

39 40
void
ConversationsFilterWidget::resizeEvent(QResizeEvent* event)
41
{
42
    Q_UNUSED(event);
43 44 45
    updateBadges();
}

46 47 48 49 50 51 52 53
void
ConversationsFilterWidget::updateNotifier(lrc::api::profile::Type typeFilter)
{
    using namespace lrc::api::profile;
    handleNotifierOverlay((typeFilter == Type::RING) ? "btnConversations" : "btnInvites",
                          (typeFilter == Type::RING) ? unreadMessagesNotifier_ : pendingInvitesNotifier_,
                          typeFilter);
}
54 55 56 57

static inline const QRect
getNotifierRect(const QRect& buttonRect)
{
58
    qreal radius = 9;
59 60 61 62 63 64
    QPointF ellipseCenter(buttonRect.right() - radius * 2, buttonRect.top());
    return QRect(ellipseCenter.x() - radius, ellipseCenter.y() - radius, radius * 2, radius * 2);
}

void
ConversationsFilterWidget::handleNotifierOverlay(const QString& buttonName,
65 66
    SmartlistSelectorButtonNotifier*& notifier,
    lrc::api::profile::Type filter)
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
{
    auto button = this->findChild<QPushButton*>(buttonName);
    if (!button) {
        return;
    }
    if (!notifier) {
        notifier = new SmartlistSelectorButtonNotifier(this);
        button->stackUnder(notifier);
        notifier->setTypeFilter(filter);
        notifier->hide();
        QObject::connect(notifier, SIGNAL(clicked()), button, SLOT(click()));
    } else {
        notifier->setGeometry(getNotifierRect(button->frameGeometry()));
        notifier->show();
    }
82
}