From 4dd1fea962bfc062fc7af1a9cc8ec99e972fe10a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ll?= Date: Mon, 30 Sep 2013 11:09:27 +0200 Subject: [PATCH 1/6] Implement new friend request display --- projectfiles/QtCreator/TOX-Qt-GUI.pro | 6 +- resources/icons/accept.png | Bin 0 -> 712 bytes resources/icons/cancel.png | Bin 0 -> 727 bytes resources/resources.qrc | 2 + src/friendrequestwidget.cpp | 113 ++++++++++++++++++++++++++ src/friendrequestwidget.h | 43 ++++++++++ src/mainwindow.cpp | 9 +- src/mainwindow.hpp | 3 + 8 files changed, 172 insertions(+), 4 deletions(-) create mode 100644 resources/icons/accept.png create mode 100644 resources/icons/cancel.png create mode 100644 src/friendrequestwidget.cpp create mode 100644 src/friendrequestwidget.h diff --git a/projectfiles/QtCreator/TOX-Qt-GUI.pro b/projectfiles/QtCreator/TOX-Qt-GUI.pro index 1dda0d3..397d417 100644 --- a/projectfiles/QtCreator/TOX-Qt-GUI.pro +++ b/projectfiles/QtCreator/TOX-Qt-GUI.pro @@ -86,7 +86,8 @@ SOURCES += \ ../../src/messagedisplaywidget.cpp \ ../../src/opacitywidget.cpp \ ../../src/customhintwidget.cpp \ - ../../src/Settings/guisettingspage.cpp + ../../src/Settings/guisettingspage.cpp \ + ../../src/friendrequestwidget.cpp HEADERS += \ ../../src/mainwindow.hpp \ @@ -123,7 +124,8 @@ HEADERS += \ ../../src/messagedisplaywidget.hpp \ ../../src/opacitywidget.hpp \ ../../src/customhintwidget.hpp \ - ../../src/Settings/guisettingspage.h + ../../src/Settings/guisettingspage.h \ + ../../src/friendrequestwidget.h SOURCES += \ ../../submodules/ProjectTox-Core/toxcore/DHT.c \ diff --git a/resources/icons/accept.png b/resources/icons/accept.png new file mode 100644 index 0000000000000000000000000000000000000000..719e39151bbdcb581c0e096459bfc964fdc202c1 GIT binary patch literal 712 zcmV;(0yq7MP)MdTBwyf}j+nP!zm~`LUW((b!ll z*3{7aHg?nOpYwK;O|{+}n0@eOzHh#rna2#n!2g)YKa4T^;`BIrR1IUgjsZ^1BZ2_5 z2$(0oHam($BbOIv=BG|@>K5(=y#CAQj$K6e!9!4#3X1YNeim1eTzQY!@)Bx_HZvQ> z*f|m*5Ea>nSII@lHT^y*8MX-qBdo{glHzwR zOylLJVdN|8rfgFeYsj^{P;5gim4{}a_xXsC5O`2gaeMIa5Eg$tK#n8})EU-dIVeM= zL)L&xAp;Iq9_;}@*Dww%Y}$!n`vENHUYN3L42hrE4a=5=aYSCd%1dZtn));~EudF4xZlgyGY*OWLs0p5U%OHw& zTbcv{-Q>y{IEg(HZ-%cQZGs~)2KOEU6GGD&8mnUxXxoT>$)urITj6n0@;mm&wnY*a z*x>|91%}Nn>P;04Q#CJj+e2M(yOvfh^cPgwXz8ToK*qYmADARTU literal 0 HcmV?d00001 diff --git a/resources/icons/cancel.png b/resources/icons/cancel.png new file mode 100644 index 0000000000000000000000000000000000000000..33c876b23a8a3940476e354ffe81f9fe93ac9170 GIT binary patch literal 727 zcmV;|0x127P)S&XCR(-5a9UMJ?X+Da1x7myH-=OMF``hLXxS=>7G@dFfQu*#s*%bW zXB=i6^}W|QcY2Sp=)mROd+zyu@7#0G6{xYP|!6}_b(_u zpM(emNGU1GfxEtr$eA8EyY?XcU<_~^4bgz9u6Qq{n2hyZhWhpy8=0?w3Sf2iH9>+T zUPHL;7+|l%Xxa_Cc`wpq_xSILuBo|kygYKy%|ChM7DsNni`^}*XW4=C?&8V)`s*3* za~#LBjx&%BrN~x!@eIne{DL+NKSn6ps=uBobBm5+b99ja$(6DwJ!zUyk$PlLMSa1x z(Wm~L{VGyNaTd%%u3A|Qki^LTf((SAf&{VZu+pEXy|D-K;SC5nmw98v7Zy*){W<%2U(xl-Vhuph z5lTcfLUe>s$QP8)o`BlftiOH{Y2Tnx$`|MaRe-n?-*>&Ev3{s6dH|-OV6T>{9Y#lj zQgr_|^+H9rvkF@%Z`hcf|A3inVX%Mh<1NNC4#!*i4mZ@_?ubWWnjvaF>OO8#ua$X4 znU>2H%%tY=CRez2HMKCt?c%)!4e2CE=b=^vBUbetc}7ud#S*69zQ^<*G2iT_$HWji z&XxA9){t(JzW{s#@A9R=fz+o_7XR}aJqV2!{NENlu?P4qzyNNT8~9r=WRd^?002ov JPDHLkV1fmNR7L;* literal 0 HcmV?d00001 diff --git a/resources/resources.qrc b/resources/resources.qrc index df0e0be..7002b18 100644 --- a/resources/resources.qrc +++ b/resources/resources.qrc @@ -35,5 +35,7 @@ icons/paste_plain.png icons/arrow_redo.png icons/arrow_undo.png + icons/accept.png + icons/cancel.png diff --git a/src/friendrequestwidget.cpp b/src/friendrequestwidget.cpp new file mode 100644 index 0000000..344bc65 --- /dev/null +++ b/src/friendrequestwidget.cpp @@ -0,0 +1,113 @@ +#include "friendrequestwidget.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "elidelabel.hpp" + +FriendRequestWidget::FriendRequestWidget(QWidget *parent) : + QWidget(parent), + it(requests) +{ + button = new QToolButton(this); + button->setPopupMode(QToolButton::InstantPopup); + button->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); + + menu = new QMenu( this); + QWidgetAction *action = new QWidgetAction(this); + actionDefaultWidget = new QWidget(this); + QVBoxLayout *menulayout = new QVBoxLayout(actionDefaultWidget); + menulayout->setContentsMargins(2,2,2,2); + menulayout->setSpacing(2); + action->setDefaultWidget(actionDefaultWidget); + menu->addAction(action); + + clientId = new ElideLabel(actionDefaultWidget); + clientId->setTextElide(true); + clientId->setTextElideMode(Qt::ElideRight); + + message = new QLabel(actionDefaultWidget); + message->setWordWrap(true); + + accaptButton = new QPushButton(actionDefaultWidget); + accaptButton->setIcon(QIcon("://icons/accept.png")); + + rejectButton = new QPushButton(actionDefaultWidget); + rejectButton->setIcon(QIcon("://icons/cancel.png")); + + connect(accaptButton, &QPushButton::clicked, this, &FriendRequestWidget::acceptUser); + connect(rejectButton, &QPushButton::clicked, this, &FriendRequestWidget::rejectUser); + + QHBoxLayout *buttonLayout = new QHBoxLayout; + buttonLayout->addWidget(accaptButton); + buttonLayout->addWidget(rejectButton); + buttonLayout->setContentsMargins(0,0,0,0); + + menulayout->addWidget(clientId); + menulayout->addWidget(message); + menulayout->addLayout(buttonLayout); + + QVBoxLayout *layout = new QVBoxLayout(this); + layout->addWidget(button); + layout->setContentsMargins(0,0,0,0); + layout->setSpacing(0); + + updateGui(); +} + +void FriendRequestWidget::addFriendRequest(const QString &userId, const QString &msg) +{ + requests.insert(userId, msg); + updateGui(); +} + +void FriendRequestWidget::acceptUser() +{ + emit userAccepted(it.key()); + it.remove(); + button->menu()->close(); + updateGui(); +} + +void FriendRequestWidget::rejectUser() +{ + it.remove(); + button->menu()->close(); + updateGui(); +} + +void FriendRequestWidget::updateGui() +{ + button->setText(tr("%n friend request(s)","", requests.count())); + //qDebug() << requests; + if(requests.count() > 0) { + button->setMenu(menu); + button->setVisible(true); + it.toFront(); + it.next(); + + clientId->setText(tr("Client ID: %1").arg(it.key())); + clientId->setToolTip(it.key()); + message->setText(QString("\"%1\"").arg(it.value())); + } + else { + button->setMenu(NULL); + button->setVisible(false); + clientId->clear(); + message->clear(); + } + + // Recalculate popup size + if (button->menu()) { + actionDefaultWidget->setFixedWidth(button->sizeHint().width()); + actionDefaultWidget->setFixedHeight(message->sizeHint().height()+clientId->sizeHint().height()+accaptButton->sizeHint().height()+4+2*2); + button->menu()->setFixedWidth(button->sizeHint().width()); + button->menu()->setFixedHeight(message->sizeHint().height()+clientId->sizeHint().height()+accaptButton->sizeHint().height()+4+2*2); + } +} diff --git a/src/friendrequestwidget.h b/src/friendrequestwidget.h new file mode 100644 index 0000000..ab3fcd5 --- /dev/null +++ b/src/friendrequestwidget.h @@ -0,0 +1,43 @@ +#ifndef FRIENDREQUESTLABEL_H +#define FRIENDREQUESTLABEL_H + +#include + +class QLabel; +class ElideLabel; +class QPushButton; +class QToolButton; +class QMenu; + +class FriendRequestWidget : public QWidget +{ + Q_OBJECT +public: + explicit FriendRequestWidget(QWidget *parent = 0); + +signals: + void userAccepted(QString); + +public slots: + void addFriendRequest(const QString &userId, const QString &msg); + +private slots: + void acceptUser(); + void rejectUser(); + +private: + QToolButton *button; + QMenu *menu; + QWidget *actionDefaultWidget; + ElideLabel *clientId; + QLabel *message; + QPushButton *accaptButton; + QPushButton *rejectButton; + + QHash requests; + QMutableHashIterator it; + + void updateGui(); +}; + +#endif // FRIENDREQUESTLABEL_H diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index c3031c7..8f10c9f 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -22,6 +22,7 @@ #include "pageswidget.hpp" #include "Settings/settings.hpp" #include "closeapplicationdialog.hpp" +#include "friendrequestwidget.h" #include #include @@ -62,6 +63,7 @@ MainWindow::MainWindow(QWidget* parent) friendDock->setWidget(friendDockWidget); ourUserItem = new OurUserItemWidget(this); + friendRequestWidget = new FriendRequestWidget(this); friendsWidget = new FriendsWidget(friendDockWidget); // Create toolbar @@ -96,6 +98,7 @@ MainWindow::MainWindow(QWidget* parent) // Create toolbar end layout->addWidget(ourUserItem); + layout->addWidget(friendRequestWidget); layout->addWidget(friendsWidget); layout->addWidget(toolBar); @@ -116,7 +119,8 @@ MainWindow::MainWindow(QWidget* parent) connect(core, &Core::connected, this, &MainWindow::onConnected); connect(core, &Core::disconnected, this, &MainWindow::onDisconnected); - connect(core, &Core::friendRequestRecieved, this, &MainWindow::onFriendRequestRecieved); + //connect(core, &Core::friendRequestRecieved, this, &MainWindow::onFriendRequestRecieved); + connect(core, &Core::friendRequestRecieved, friendRequestWidget, &FriendRequestWidget::addFriendRequest); connect(core, SIGNAL(friendStatusChanged(int, Status)), friendsWidget, SLOT(setStatus(int, Status))); connect(core, &Core::friendAddressGenerated, ourUserItem, &OurUserItemWidget::setFriendAddress); connect(core, &Core::friendAdded, friendsWidget, &FriendsWidget::addFriend); @@ -131,7 +135,8 @@ MainWindow::MainWindow(QWidget* parent) coreThread->start(/*QThread::IdlePriority*/); - connect(this, &MainWindow::friendRequestAccepted, core, &Core::acceptFriendRequest); + //connect(this, &MainWindow::friendRequestAccepted, core, &Core::acceptFriendRequest); + connect(friendRequestWidget, &FriendRequestWidget::userAccepted, core, &Core::acceptFriendRequest); connect(ourUserItem, &OurUserItemWidget::usernameChanged, core, &Core::setUsername); connect(core, &Core::usernameSet, ourUserItem, &OurUserItemWidget::setUsername); diff --git a/src/mainwindow.hpp b/src/mainwindow.hpp index f5b2dc4..31ef3c2 100644 --- a/src/mainwindow.hpp +++ b/src/mainwindow.hpp @@ -27,6 +27,8 @@ #include #include +class FriendRequestWidget; + class MainWindow : public QMainWindow { Q_OBJECT @@ -43,6 +45,7 @@ class MainWindow : public QMainWindow QThread* coreThread; FriendsWidget* friendsWidget; OurUserItemWidget* ourUserItem; + FriendRequestWidget* friendRequestWidget; private slots: void onConnected(); From ad0a1eacc8df471788fb4859f682c6bbda53f039 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ll?= Date: Tue, 1 Oct 2013 11:05:24 +0200 Subject: [PATCH 2/6] remove old dialog --- projectfiles/QtCreator/TOX-Qt-GUI.pro | 2 - src/friendrequestdialog.cpp | 61 --------------------------- src/friendrequestdialog.hpp | 30 ------------- src/friendrequestwidget.cpp | 18 +++++++- src/friendrequestwidget.h | 16 +++++++ src/mainwindow.cpp | 12 ------ src/mainwindow.hpp | 1 - 7 files changed, 32 insertions(+), 108 deletions(-) delete mode 100644 src/friendrequestdialog.cpp delete mode 100644 src/friendrequestdialog.hpp diff --git a/projectfiles/QtCreator/TOX-Qt-GUI.pro b/projectfiles/QtCreator/TOX-Qt-GUI.pro index 397d417..cc71626 100644 --- a/projectfiles/QtCreator/TOX-Qt-GUI.pro +++ b/projectfiles/QtCreator/TOX-Qt-GUI.pro @@ -66,7 +66,6 @@ SOURCES += \ ../../src/ouruseritemwidget.cpp \ ../../src/renameeditwidget.cpp \ ../../src/status.cpp \ - ../../src/friendrequestdialog.cpp \ ../../src/customhinttextedit.cpp \ ../../src/elidelabel.cpp \ ../../src/core.cpp \ @@ -103,7 +102,6 @@ HEADERS += \ ../../src/frienditemwidget.hpp \ ../../src/ouruseritemwidget.hpp \ ../../src/renameeditwidget.hpp \ - ../../src/friendrequestdialog.hpp \ ../../src/customhinttextedit.hpp \ ../../src/elidelabel.hpp \ ../../src/core.hpp \ diff --git a/src/friendrequestdialog.cpp b/src/friendrequestdialog.cpp deleted file mode 100644 index 4836824..0000000 --- a/src/friendrequestdialog.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* - Copyright (C) 2013 by Maxim Biro - - This file is part of Tox Qt GUI. - - 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 COPYING file for more details. -*/ - -#include "friendrequestdialog.hpp" - -#include -#include -#include -#include -#include -#include - -FriendRequestDialog::FriendRequestDialog(QWidget *parent, const QString &userId, const QString &message) : - QDialog(parent) -{ - setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); - setWindowTitle("Friend request"); - - QLabel *friendsLabel = new QLabel("Someone wants to make friends with you.", this); - QLabel *userIdLabel = new QLabel("User ID:", this); - QLineEdit *userIdEdit = new QLineEdit(userId, this); - userIdEdit->setCursorPosition(0); - userIdEdit->setReadOnly(true); - QLabel *messageLabel = new QLabel("Friend request message:", this); - QPlainTextEdit *messageEdit = new QPlainTextEdit(message, this); - messageEdit->setReadOnly(true); - - - QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Horizontal, this); - - buttonBox->addButton("Accept", QDialogButtonBox::AcceptRole); - buttonBox->addButton("Reject", QDialogButtonBox::RejectRole); - - connect(buttonBox, &QDialogButtonBox::accepted, this, &FriendRequestDialog::accept); - connect(buttonBox, &QDialogButtonBox::rejected, this, &FriendRequestDialog::reject); - - QVBoxLayout *layout = new QVBoxLayout(this); - - layout->addWidget(friendsLabel); - layout->addSpacing(12); - layout->addWidget(userIdLabel); - layout->addWidget(userIdEdit); - layout->addWidget(messageLabel); - layout->addWidget(messageEdit); - layout->addWidget(buttonBox); - - resize(300, 200); -} diff --git a/src/friendrequestdialog.hpp b/src/friendrequestdialog.hpp deleted file mode 100644 index dc6640c..0000000 --- a/src/friendrequestdialog.hpp +++ /dev/null @@ -1,30 +0,0 @@ -/* - Copyright (C) 2013 by Maxim Biro - - This file is part of Tox Qt GUI. - - 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 COPYING file for more details. -*/ - -#ifndef FRIENDREQUESTDIALOG_HPP -#define FRIENDREQUESTDIALOG_HPP - -#include - -class FriendRequestDialog : public QDialog -{ - Q_OBJECT -public: - explicit FriendRequestDialog(QWidget *parent, const QString &userId, const QString &message); - -}; - -#endif // FRIENDREQUESTDIALOG_HPP diff --git a/src/friendrequestwidget.cpp b/src/friendrequestwidget.cpp index 344bc65..e4d819f 100644 --- a/src/friendrequestwidget.cpp +++ b/src/friendrequestwidget.cpp @@ -1,3 +1,19 @@ +/* + Copyright (C) 2013 by Martin Kröll + + This file is part of Tox Qt GUI. + + 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 COPYING file for more details. +*/ + #include "friendrequestwidget.h" #include @@ -7,7 +23,6 @@ #include #include #include -#include #include "elidelabel.hpp" @@ -85,7 +100,6 @@ void FriendRequestWidget::rejectUser() void FriendRequestWidget::updateGui() { button->setText(tr("%n friend request(s)","", requests.count())); - //qDebug() << requests; if(requests.count() > 0) { button->setMenu(menu); button->setVisible(true); diff --git a/src/friendrequestwidget.h b/src/friendrequestwidget.h index ab3fcd5..5b4f14f 100644 --- a/src/friendrequestwidget.h +++ b/src/friendrequestwidget.h @@ -1,3 +1,19 @@ +/* + Copyright (C) 2013 by Martin Kröll + + This file is part of Tox Qt GUI. + + 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 COPYING file for more details. +*/ + #ifndef FRIENDREQUESTLABEL_H #define FRIENDREQUESTLABEL_H diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 8f10c9f..e4dc879 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -18,7 +18,6 @@ #include "aboutdialog.hpp" #include "appinfo.hpp" -#include "friendrequestdialog.hpp" #include "pageswidget.hpp" #include "Settings/settings.hpp" #include "closeapplicationdialog.hpp" @@ -119,7 +118,6 @@ MainWindow::MainWindow(QWidget* parent) connect(core, &Core::connected, this, &MainWindow::onConnected); connect(core, &Core::disconnected, this, &MainWindow::onDisconnected); - //connect(core, &Core::friendRequestRecieved, this, &MainWindow::onFriendRequestRecieved); connect(core, &Core::friendRequestRecieved, friendRequestWidget, &FriendRequestWidget::addFriendRequest); connect(core, SIGNAL(friendStatusChanged(int, Status)), friendsWidget, SLOT(setStatus(int, Status))); connect(core, &Core::friendAddressGenerated, ourUserItem, &OurUserItemWidget::setFriendAddress); @@ -135,7 +133,6 @@ MainWindow::MainWindow(QWidget* parent) coreThread->start(/*QThread::IdlePriority*/); - //connect(this, &MainWindow::friendRequestAccepted, core, &Core::acceptFriendRequest); connect(friendRequestWidget, &FriendRequestWidget::userAccepted, core, &Core::acceptFriendRequest); connect(ourUserItem, &OurUserItemWidget::usernameChanged, core, &Core::setUsername); @@ -166,15 +163,6 @@ void MainWindow::closeEvent(QCloseEvent *event) QMainWindow::closeEvent(event); } -void MainWindow::onFriendRequestRecieved(const QString& userId, const QString& message) -{ - FriendRequestDialog dialog(this, userId, message); - - if (dialog.exec() == QDialog::Accepted) { - emit friendRequestAccepted(userId); - } -} - void MainWindow::onConnected() { ourUserItem->setStatus(Status::Online); diff --git a/src/mainwindow.hpp b/src/mainwindow.hpp index 31ef3c2..a950dc1 100644 --- a/src/mainwindow.hpp +++ b/src/mainwindow.hpp @@ -50,7 +50,6 @@ class MainWindow : public QMainWindow private slots: void onConnected(); void onDisconnected(); - void onFriendRequestRecieved(const QString &userId, const QString &message); void onFailedToRemoveFriend(int friendId); void onFailedToAddFriend(const QString& userId); void onSettingsActionTriggered(); From 2192507755d6a0b48e189f4460781a9ad61f8ff6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ll?= Date: Tue, 1 Oct 2013 13:31:27 +0200 Subject: [PATCH 3/6] correct FriendRequestWidget popup size calculation --- src/friendrequestwidget.cpp | 12 +++++++++--- src/friendrequestwidget.h | 3 +++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/friendrequestwidget.cpp b/src/friendrequestwidget.cpp index e4d819f..6ac9ef7 100644 --- a/src/friendrequestwidget.cpp +++ b/src/friendrequestwidget.cpp @@ -82,6 +82,12 @@ void FriendRequestWidget::addFriendRequest(const QString &userId, const QString updateGui(); } +void FriendRequestWidget::resizeEvent(QResizeEvent *e) +{ + QWidget::resizeEvent(e); + updateGui(); +} + void FriendRequestWidget::acceptUser() { emit userAccepted(it.key()); @@ -119,9 +125,9 @@ void FriendRequestWidget::updateGui() // Recalculate popup size if (button->menu()) { - actionDefaultWidget->setFixedWidth(button->sizeHint().width()); + button->menu()->setFixedWidth(button->width()); + actionDefaultWidget->setFixedWidth(button->menu()->width() - 4); actionDefaultWidget->setFixedHeight(message->sizeHint().height()+clientId->sizeHint().height()+accaptButton->sizeHint().height()+4+2*2); - button->menu()->setFixedWidth(button->sizeHint().width()); - button->menu()->setFixedHeight(message->sizeHint().height()+clientId->sizeHint().height()+accaptButton->sizeHint().height()+4+2*2); + button->menu()->setFixedHeight(message->sizeHint().height()+clientId->sizeHint().height()+accaptButton->sizeHint().height()+4+2*2+4); } } diff --git a/src/friendrequestwidget.h b/src/friendrequestwidget.h index 5b4f14f..afbb5d8 100644 --- a/src/friendrequestwidget.h +++ b/src/friendrequestwidget.h @@ -37,6 +37,9 @@ class FriendRequestWidget : public QWidget public slots: void addFriendRequest(const QString &userId, const QString &msg); +protected: + void resizeEvent(QResizeEvent *e); + private slots: void acceptUser(); void rejectUser(); From c85445a60f7fecfb1013da7a9ed0764cd7fd4018 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ll?= Date: Fri, 11 Oct 2013 16:09:12 +0200 Subject: [PATCH 4/6] New friend request widget --- resources/icons/resultset_next.png | Bin 0 -> 380 bytes resources/resources.qrc | 1 + src/friendrequestwidget.cpp | 154 ++++++++++++++++++++--------- src/friendrequestwidget.h | 27 +++-- 4 files changed, 131 insertions(+), 51 deletions(-) create mode 100644 resources/icons/resultset_next.png diff --git a/resources/icons/resultset_next.png b/resources/icons/resultset_next.png new file mode 100644 index 0000000000000000000000000000000000000000..59b58a43633f828fbca5ebb29eb72ccea9491545 GIT binary patch literal 380 zcmV-?0fYXDP)`fLq({ zP0p>m{xdQ%GN5Ck4EXc+pKoKN5rb{R_WxwL;2%)i`)_|3^8EA|>>CLif+Y<8GkpL3 zpP_rtU50F59R>#ihF}-~^6Ia@j10V-91OFLJ!eRA)BNMmxC5slEEom=@%O*~8Mrvv z!G`U<|BWTeUgNgRt7ameugdk zE->uJqZvmmFflN*b2Dt)b{MbCI1K;_eA&Bw4?&yZ7NX}yV8|N)DQ0Y%vE^JwO0zRS afB^uQ@L<icons/arrow_undo.png icons/accept.png icons/cancel.png + icons/resultset_next.png diff --git a/src/friendrequestwidget.cpp b/src/friendrequestwidget.cpp index 6ac9ef7..b72e077 100644 --- a/src/friendrequestwidget.cpp +++ b/src/friendrequestwidget.cpp @@ -20,86 +20,146 @@ #include #include #include -#include -#include -#include +#include +#include #include "elidelabel.hpp" +#include "Settings/settings.hpp" FriendRequestWidget::FriendRequestWidget(QWidget *parent) : QWidget(parent), it(requests) { - button = new QToolButton(this); - button->setPopupMode(QToolButton::InstantPopup); - button->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); - - menu = new QMenu( this); - QWidgetAction *action = new QWidgetAction(this); - actionDefaultWidget = new QWidget(this); - QVBoxLayout *menulayout = new QVBoxLayout(actionDefaultWidget); - menulayout->setContentsMargins(2,2,2,2); - menulayout->setSpacing(2); - action->setDefaultWidget(actionDefaultWidget); - menu->addAction(action); - - clientId = new ElideLabel(actionDefaultWidget); + setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); + + button = new QPushButton(this); + button->setCheckable(true); + button->setProperty("class", "frqButton"); // for CSS styling + + detailsWidget = new QFrame(this); + detailsWidget->setFrameShape(QFrame::StyledPanel); + detailsWidget->setProperty("class", "frqDetails"); // for CSS styling + + clientId = new ElideLabel(detailsWidget); clientId->setTextElide(true); clientId->setTextElideMode(Qt::ElideRight); + clientId->setFixedWidth(100); - message = new QLabel(actionDefaultWidget); + message = new QLabel(detailsWidget); message->setWordWrap(true); - accaptButton = new QPushButton(actionDefaultWidget); - accaptButton->setIcon(QIcon("://icons/accept.png")); + acceptButton = new QPushButton(detailsWidget); + acceptButton->setIcon(QIcon("://icons/accept.png")); + acceptButton->setToolTip(tr("Accept request")); - rejectButton = new QPushButton(actionDefaultWidget); + rejectButton = new QPushButton(detailsWidget); rejectButton->setIcon(QIcon("://icons/cancel.png")); + rejectButton->setToolTip(tr("Reject request")); - connect(accaptButton, &QPushButton::clicked, this, &FriendRequestWidget::acceptUser); - connect(rejectButton, &QPushButton::clicked, this, &FriendRequestWidget::rejectUser); + nextButton = new QPushButton(detailsWidget); + nextButton->setIcon(QIcon("://icons/resultset_next.png")); + nextButton->setToolTip(tr("Next request")); QHBoxLayout *buttonLayout = new QHBoxLayout; - buttonLayout->addWidget(accaptButton); + buttonLayout->addWidget(acceptButton); buttonLayout->addWidget(rejectButton); + buttonLayout->addWidget(nextButton); buttonLayout->setContentsMargins(0,0,0,0); - menulayout->addWidget(clientId); - menulayout->addWidget(message); - menulayout->addLayout(buttonLayout); + QVBoxLayout *detailsLayout = new QVBoxLayout(detailsWidget); + detailsLayout->setContentsMargins(0,0,0,0); + detailsLayout->setSpacing(2); + detailsLayout->addWidget(clientId); + detailsLayout->addWidget(message); + detailsLayout->addLayout(buttonLayout); QVBoxLayout *layout = new QVBoxLayout(this); layout->addWidget(button); - layout->setContentsMargins(0,0,0,0); + layout->addWidget(detailsWidget); + layout->setContentsMargins(2,2,2,2); layout->setSpacing(0); + connect(button, &QPushButton::toggled, this, &FriendRequestWidget::showDetails); + connect(acceptButton, &QPushButton::clicked, this, &FriendRequestWidget::acceptUser); + connect(rejectButton, &QPushButton::clicked, this, &FriendRequestWidget::rejectUser); + connect(nextButton, &QPushButton::clicked, this, &FriendRequestWidget::nextRequest); + + animation = new QPropertyAnimation(detailsWidget, "maximumHeight"); + animation->setDuration(200); + animation->setLoopCount(1); + + if(Settings::getInstance().isAnimationEnabled()) { + detailsWidget->setMaximumHeight(0); + } else { + detailsWidget->hide(); + } + updateGui(); } void FriendRequestWidget::addFriendRequest(const QString &userId, const QString &msg) { requests.insert(userId, msg); + goFirst(); + updateGui(); } void FriendRequestWidget::resizeEvent(QResizeEvent *e) { QWidget::resizeEvent(e); - updateGui(); + clientId->setMaximumWidth(width()); } void FriendRequestWidget::acceptUser() { emit userAccepted(it.key()); it.remove(); - button->menu()->close(); + goFirst(); + updateGui(); } void FriendRequestWidget::rejectUser() { it.remove(); - button->menu()->close(); + goFirst(); + + updateGui(); +} + +void FriendRequestWidget::showDetails(bool show) +{ + if(show) { + goFirst(); + + detailsWidget->show(); + if(Settings::getInstance().isAnimationEnabled()) { + animation->setKeyValueAt(0, 0); + animation->setKeyValueAt(1, detailsWidget->sizeHint().height()); + animation->start(); + } else { + detailsWidget->setMaximumHeight(detailsWidget->sizeHint().height()); + } + } + else { + if(Settings::getInstance().isAnimationEnabled()) { + animation->setKeyValueAt(0, detailsWidget->sizeHint().height()); + animation->setKeyValueAt(1, 0); + animation->start(); + } else { + detailsWidget->hide(); + } + } +} + +void FriendRequestWidget::nextRequest() +{ + if(it.hasNext()) { + it.next(); + } else { + goFirst(); + } updateGui(); } @@ -107,27 +167,31 @@ void FriendRequestWidget::updateGui() { button->setText(tr("%n friend request(s)","", requests.count())); if(requests.count() > 0) { - button->setMenu(menu); - button->setVisible(true); - it.toFront(); - it.next(); - + setVisible(true); clientId->setText(tr("Client ID: %1").arg(it.key())); clientId->setToolTip(it.key()); - message->setText(QString("\"%1\"").arg(it.value())); + message->setText(QString("\"%1\"").arg(it.value())); + + // Hide next button + if(requests.count() == 1) { + nextButton->hide(); + } else { + nextButton->show(); + } } else { - button->setMenu(NULL); - button->setVisible(false); + button->setChecked(false); + setVisible(false); clientId->clear(); message->clear(); } +} - // Recalculate popup size - if (button->menu()) { - button->menu()->setFixedWidth(button->width()); - actionDefaultWidget->setFixedWidth(button->menu()->width() - 4); - actionDefaultWidget->setFixedHeight(message->sizeHint().height()+clientId->sizeHint().height()+accaptButton->sizeHint().height()+4+2*2); - button->menu()->setFixedHeight(message->sizeHint().height()+clientId->sizeHint().height()+accaptButton->sizeHint().height()+4+2*2+4); +/*! Go to firsr friend request */ +void FriendRequestWidget::goFirst() +{ + it.toFront(); + if(it.hasNext()) { + it.next(); } } diff --git a/src/friendrequestwidget.h b/src/friendrequestwidget.h index afbb5d8..00ea332 100644 --- a/src/friendrequestwidget.h +++ b/src/friendrequestwidget.h @@ -19,12 +19,22 @@ #include +class QFrame; class QLabel; class ElideLabel; class QPushButton; -class QToolButton; -class QMenu; +class QPropertyAnimation; +/*! FriendRequestWidget shows incoming friend requests. + * + * CSS classes for styling + * ----------------------- + * + * Object | Qt class | CSS class + * ---------------|--------------------|-------------- + * Button | QPushButton | frqButton + * Details widget | QFrame | frqDetails + */ class FriendRequestWidget : public QWidget { Q_OBJECT @@ -43,20 +53,25 @@ public slots: private slots: void acceptUser(); void rejectUser(); + void showDetails(bool show); + void nextRequest(); private: - QToolButton *button; - QMenu *menu; - QWidget *actionDefaultWidget; + QPushButton *button; + QFrame *detailsWidget; ElideLabel *clientId; QLabel *message; - QPushButton *accaptButton; + QPushButton *acceptButton; QPushButton *rejectButton; + QPushButton *nextButton; + + QPropertyAnimation *animation; QHash requests; QMutableHashIterator it; void updateGui(); + void goFirst(); }; #endif // FRIENDREQUESTLABEL_H From 11037384f8c1ad2829f9d6807695a8596fdb7270 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ll?= Date: Fri, 11 Oct 2013 17:22:05 +0200 Subject: [PATCH 5/6] fix typo --- src/friendrequestwidget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/friendrequestwidget.cpp b/src/friendrequestwidget.cpp index b72e077..d2b9ac3 100644 --- a/src/friendrequestwidget.cpp +++ b/src/friendrequestwidget.cpp @@ -187,7 +187,7 @@ void FriendRequestWidget::updateGui() } } -/*! Go to firsr friend request */ +/*! Go to first friend request */ void FriendRequestWidget::goFirst() { it.toFront(); From dbd0f2597ab3b945cfd03ede523c7c01edf85d5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ll?= Date: Wed, 23 Oct 2013 23:08:07 +0200 Subject: [PATCH 6/6] Make graphical design of friend requests more "friendly". There is still a problem with the heigth of the request message on too small app windows. --- src/friendrequestwidget.cpp | 16 ++++++++++------ src/friendrequestwidget.h | 7 ++++--- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/friendrequestwidget.cpp b/src/friendrequestwidget.cpp index d2b9ac3..d74bba2 100644 --- a/src/friendrequestwidget.cpp +++ b/src/friendrequestwidget.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -48,17 +49,20 @@ FriendRequestWidget::FriendRequestWidget(QWidget *parent) : message = new QLabel(detailsWidget); message->setWordWrap(true); - acceptButton = new QPushButton(detailsWidget); + acceptButton = new QToolButton(detailsWidget); acceptButton->setIcon(QIcon("://icons/accept.png")); acceptButton->setToolTip(tr("Accept request")); + acceptButton->setAutoRaise(true); - rejectButton = new QPushButton(detailsWidget); + rejectButton = new QToolButton(detailsWidget); rejectButton->setIcon(QIcon("://icons/cancel.png")); rejectButton->setToolTip(tr("Reject request")); + rejectButton->setAutoRaise(true); - nextButton = new QPushButton(detailsWidget); + nextButton = new QToolButton(detailsWidget); nextButton->setIcon(QIcon("://icons/resultset_next.png")); nextButton->setToolTip(tr("Next request")); + nextButton->setAutoRaise(true); QHBoxLayout *buttonLayout = new QHBoxLayout; buttonLayout->addWidget(acceptButton); @@ -67,7 +71,7 @@ FriendRequestWidget::FriendRequestWidget(QWidget *parent) : buttonLayout->setContentsMargins(0,0,0,0); QVBoxLayout *detailsLayout = new QVBoxLayout(detailsWidget); - detailsLayout->setContentsMargins(0,0,0,0); + detailsLayout->setContentsMargins(2,2,2,2); detailsLayout->setSpacing(2); detailsLayout->addWidget(clientId); detailsLayout->addWidget(message); @@ -76,7 +80,7 @@ FriendRequestWidget::FriendRequestWidget(QWidget *parent) : QVBoxLayout *layout = new QVBoxLayout(this); layout->addWidget(button); layout->addWidget(detailsWidget); - layout->setContentsMargins(2,2,2,2); + layout->setContentsMargins(4,4,4,4); layout->setSpacing(0); connect(button, &QPushButton::toggled, this, &FriendRequestWidget::showDetails); @@ -108,7 +112,7 @@ void FriendRequestWidget::addFriendRequest(const QString &userId, const QString void FriendRequestWidget::resizeEvent(QResizeEvent *e) { QWidget::resizeEvent(e); - clientId->setMaximumWidth(width()); + clientId->setMaximumWidth(detailsWidget->width()); } void FriendRequestWidget::acceptUser() diff --git a/src/friendrequestwidget.h b/src/friendrequestwidget.h index 00ea332..ef94462 100644 --- a/src/friendrequestwidget.h +++ b/src/friendrequestwidget.h @@ -23,6 +23,7 @@ class QFrame; class QLabel; class ElideLabel; class QPushButton; +class QToolButton; class QPropertyAnimation; /*! FriendRequestWidget shows incoming friend requests. @@ -61,9 +62,9 @@ private slots: QFrame *detailsWidget; ElideLabel *clientId; QLabel *message; - QPushButton *acceptButton; - QPushButton *rejectButton; - QPushButton *nextButton; + QToolButton *acceptButton; + QToolButton *rejectButton; + QToolButton *nextButton; QPropertyAnimation *animation;