blob: 45b97aca4435f14a62d47bbad024cada733fb9ce [file] [log] [blame]
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001/***************************************************************************
Sébastien Blin68abac92019-01-02 17:41:31 -05002 * Copyright (C) 2019-2019 by Savoir-faire Linux *
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04003 * Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17 **************************************************************************/
18
19#include "conversationsfilterwidget.h"
20
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040021#include <QPainter>
Andreas Traczyk43c08232018-10-31 13:42:09 -040022#include <QDebug>
23
24#include "ringthemeutils.h"
25#include "lrcinstance.h"
26
27ConversationsFilterWidget::ConversationsFilterWidget(QWidget *parent)
28 : QWidget(parent)
29{
30}
31
Andreas Traczyk1d8159a2018-12-13 15:48:24 -050032void ConversationsFilterWidget::updateBadges()
Andreas Traczyk43c08232018-10-31 13:42:09 -040033{
34 using namespace lrc::api::profile;
35 updateNotifier(Type::RING);
36 updateNotifier(Type::PENDING);
37}
38
Andreas Traczyk14c3e862018-12-26 14:02:30 -050039void
40ConversationsFilterWidget::resizeEvent(QResizeEvent* event)
Andreas Traczyk1d8159a2018-12-13 15:48:24 -050041{
Andreas Traczyk14c3e862018-12-26 14:02:30 -050042 Q_UNUSED(event);
Andreas Traczyk1d8159a2018-12-13 15:48:24 -050043 updateBadges();
44}
45
Andreas Traczyk43c08232018-10-31 13:42:09 -040046void
47ConversationsFilterWidget::updateNotifier(lrc::api::profile::Type typeFilter)
48{
49 using namespace lrc::api::profile;
50 handleNotifierOverlay((typeFilter == Type::RING) ? "btnConversations" : "btnInvites",
51 (typeFilter == Type::RING) ? unreadMessagesNotifier_ : pendingInvitesNotifier_,
52 typeFilter);
53}
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040054
55static inline const QRect
56getNotifierRect(const QRect& buttonRect)
57{
58 qreal radius = 8;
59 QPointF ellipseCenter(buttonRect.right() - radius * 2, buttonRect.top());
60 return QRect(ellipseCenter.x() - radius, ellipseCenter.y() - radius, radius * 2, radius * 2);
61}
62
63void
64ConversationsFilterWidget::handleNotifierOverlay(const QString& buttonName,
Andreas Traczyk43c08232018-10-31 13:42:09 -040065 SmartlistSelectorButtonNotifier*& notifier,
66 lrc::api::profile::Type filter)
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040067{
68 auto button = this->findChild<QPushButton*>(buttonName);
69 if (!button) {
70 return;
71 }
72 if (!notifier) {
73 notifier = new SmartlistSelectorButtonNotifier(this);
74 button->stackUnder(notifier);
75 notifier->setTypeFilter(filter);
76 notifier->hide();
77 QObject::connect(notifier, SIGNAL(clicked()), button, SLOT(click()));
78 } else {
79 notifier->setGeometry(getNotifierRect(button->frameGeometry()));
80 notifier->show();
81 }
Andreas Traczyk43c08232018-10-31 13:42:09 -040082}