Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 1 | /*************************************************************************** |
Sébastien Blin | 68abac9 | 2019-01-02 17:41:31 -0500 | [diff] [blame] | 2 | * Copyright (C) 2019-2019 by Savoir-faire Linux * |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 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 Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 21 | #include <QPainter> |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 22 | #include <QDebug> |
| 23 | |
| 24 | #include "ringthemeutils.h" |
| 25 | #include "lrcinstance.h" |
| 26 | |
| 27 | ConversationsFilterWidget::ConversationsFilterWidget(QWidget *parent) |
| 28 | : QWidget(parent) |
| 29 | { |
| 30 | } |
| 31 | |
Andreas Traczyk | 1d8159a | 2018-12-13 15:48:24 -0500 | [diff] [blame] | 32 | void ConversationsFilterWidget::updateBadges() |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 33 | { |
| 34 | using namespace lrc::api::profile; |
| 35 | updateNotifier(Type::RING); |
| 36 | updateNotifier(Type::PENDING); |
| 37 | } |
| 38 | |
Andreas Traczyk | 14c3e86 | 2018-12-26 14:02:30 -0500 | [diff] [blame] | 39 | void |
| 40 | ConversationsFilterWidget::resizeEvent(QResizeEvent* event) |
Andreas Traczyk | 1d8159a | 2018-12-13 15:48:24 -0500 | [diff] [blame] | 41 | { |
Andreas Traczyk | 14c3e86 | 2018-12-26 14:02:30 -0500 | [diff] [blame] | 42 | Q_UNUSED(event); |
Andreas Traczyk | 1d8159a | 2018-12-13 15:48:24 -0500 | [diff] [blame] | 43 | updateBadges(); |
| 44 | } |
| 45 | |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 46 | void |
| 47 | ConversationsFilterWidget::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 Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 54 | |
| 55 | static inline const QRect |
| 56 | getNotifierRect(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 | |
| 63 | void |
| 64 | ConversationsFilterWidget::handleNotifierOverlay(const QString& buttonName, |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 65 | SmartlistSelectorButtonNotifier*& notifier, |
| 66 | lrc::api::profile::Type filter) |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 67 | { |
| 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 Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 82 | } |