blob: 5a34e53e2bd7311d55c68043eea4af1618bf85dc [file] [log] [blame]
Andreas Traczykb8b13ba2018-08-21 16:30:16 -04001/***************************************************************************
2 * Copyright (C) 2018 by Savoir-faire Linux *
3 * 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
32void ConversationsFilterWidget::resizeEvent(QResizeEvent * event)
33{
34 using namespace lrc::api::profile;
35 updateNotifier(Type::RING);
36 updateNotifier(Type::PENDING);
37}
38
39void
40ConversationsFilterWidget::updateNotifier(lrc::api::profile::Type typeFilter)
41{
42 using namespace lrc::api::profile;
43 handleNotifierOverlay((typeFilter == Type::RING) ? "btnConversations" : "btnInvites",
44 (typeFilter == Type::RING) ? unreadMessagesNotifier_ : pendingInvitesNotifier_,
45 typeFilter);
46}
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040047
48static inline const QRect
49getNotifierRect(const QRect& buttonRect)
50{
51 qreal radius = 8;
52 QPointF ellipseCenter(buttonRect.right() - radius * 2, buttonRect.top());
53 return QRect(ellipseCenter.x() - radius, ellipseCenter.y() - radius, radius * 2, radius * 2);
54}
55
56void
57ConversationsFilterWidget::handleNotifierOverlay(const QString& buttonName,
Andreas Traczyk43c08232018-10-31 13:42:09 -040058 SmartlistSelectorButtonNotifier*& notifier,
59 lrc::api::profile::Type filter)
Andreas Traczykb8b13ba2018-08-21 16:30:16 -040060{
61 auto button = this->findChild<QPushButton*>(buttonName);
62 if (!button) {
63 return;
64 }
65 if (!notifier) {
66 notifier = new SmartlistSelectorButtonNotifier(this);
67 button->stackUnder(notifier);
68 notifier->setTypeFilter(filter);
69 notifier->hide();
70 QObject::connect(notifier, SIGNAL(clicked()), button, SLOT(click()));
71 } else {
72 notifier->setGeometry(getNotifierRect(button->frameGeometry()));
73 notifier->show();
74 }
Andreas Traczyk43c08232018-10-31 13:42:09 -040075}