Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 1 | /*************************************************************************** |
| 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 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 | |
| 32 | void ConversationsFilterWidget::resizeEvent(QResizeEvent * event) |
| 33 | { |
| 34 | using namespace lrc::api::profile; |
| 35 | updateNotifier(Type::RING); |
| 36 | updateNotifier(Type::PENDING); |
| 37 | } |
| 38 | |
| 39 | void |
| 40 | ConversationsFilterWidget::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 Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 47 | |
| 48 | static inline const QRect |
| 49 | getNotifierRect(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 | |
| 56 | void |
| 57 | ConversationsFilterWidget::handleNotifierOverlay(const QString& buttonName, |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 58 | SmartlistSelectorButtonNotifier*& notifier, |
| 59 | lrc::api::profile::Type filter) |
Andreas Traczyk | b8b13ba | 2018-08-21 16:30:16 -0400 | [diff] [blame] | 60 | { |
| 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 Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 75 | } |