1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Circle context menus

This commit is contained in:
Daniel Hrabovcak 2015-05-29 09:26:43 -04:00 committed by tux3
parent ff37812a53
commit 8f02d6c14c
5 changed files with 84 additions and 40 deletions

View File

@ -67,8 +67,6 @@ CircleWidget::CircleWidget(FriendListWidget *parent)
QFrame *lineFrame = new QFrame(container); QFrame *lineFrame = new QFrame(container);
lineFrame->setObjectName("line"); lineFrame->setObjectName("line");
lineFrame->setFrameShape(QFrame::HLine); lineFrame->setFrameShape(QFrame::HLine);
//topLayout->addSpacing(5);
//topLayout->addWidget(lineFrame, 1);
midLayout->addLayout(topLayout); midLayout->addLayout(topLayout);
midLayout->addWidget(lineFrame); midLayout->addWidget(lineFrame);
@ -77,38 +75,11 @@ CircleWidget::CircleWidget(FriendListWidget *parent)
QHBoxLayout *statusLayout = new QHBoxLayout(); QHBoxLayout *statusLayout = new QHBoxLayout();
//QLabel *onlineIconLabel = new QLabel(container);
//onlineIconLabel->setAlignment(Qt::AlignCenter);
//onlineIconLabel->setPixmap(QPixmap(":img/status/dot_online.svg"));
onlineLabel = new QLabel("0", container); onlineLabel = new QLabel("0", container);
onlineLabel->setObjectName("status"); onlineLabel->setObjectName("status");
/*QLabel *awayIconLabel = new QLabel(container);
awayIconLabel->setAlignment(Qt::AlignCenter);
awayIconLabel->setPixmap(QPixmap(":img/status/dot_away.svg"));
QLabel *awayLabel = new QLabel("0", container);
awayLabel->setObjectName("status");*/
//QLabel *offlineIconLabel = new QLabel(container);
//offlineIconLabel->setAlignment(Qt::AlignCenter);
//offlineIconLabel->setPixmap(QPixmap(":img/status/dot_offline.svg"));
//offlineLabel = new QLabel("0", container);
//offlineLabel->setObjectName("status");
//statusLayout->addWidget(onlineIconLabel);
//statusLayout->addSpacing(2);
statusLayout->addWidget(onlineLabel); statusLayout->addWidget(onlineLabel);
//statusLayout->addSpacing(10);
//statusLayout->addWidget(awayIconLabel);
//statusLayout->addSpacing(5);
//statusLayout->addWidget(awayLabel);
//statusLayout->addSpacing(10);
//statusLayout->addWidget(offlineIconLabel);
//statusLayout->addSpacing(2);
//statusLayout->addWidget(offlineLabel);
//statusLayout->addStretch();
//midLayout->addLayout(statusLayout);
topLayout->addStretch(); topLayout->addStretch();
topLayout->addLayout(statusLayout); topLayout->addLayout(statusLayout);
@ -133,6 +104,13 @@ void CircleWidget::addFriendWidget(FriendWidget *w, Status s)
updateOnline(); updateOnline();
} }
void CircleWidget::expand()
{
if (expanded)
return;
toggle();
}
void CircleWidget::toggle() void CircleWidget::toggle()
{ {
expanded = !expanded; expanded = !expanded;
@ -153,6 +131,11 @@ void CircleWidget::searchChatrooms(const QString &searchString, bool hideOnline,
listLayout->searchChatrooms(searchString, hideOnline, hideOffline, hideGroups); listLayout->searchChatrooms(searchString, hideOnline, hideOffline, hideGroups);
} }
QString CircleWidget::getName() const
{
return nameLabel->text();
}
void CircleWidget::renameCircle() void CircleWidget::renameCircle()
{ {
qDebug() << nameLabel->parentWidget()->layout(); qDebug() << nameLabel->parentWidget()->layout();
@ -173,6 +156,11 @@ void CircleWidget::renameCircle()
}); });
} }
void CircleWidget::onCompactChanged(bool compact)
{
}
void CircleWidget::contextMenuEvent(QContextMenuEvent *event) void CircleWidget::contextMenuEvent(QContextMenuEvent *event)
{ {
QMenu menu; QMenu menu;
@ -188,21 +176,17 @@ void CircleWidget::contextMenuEvent(QContextMenuEvent *event)
while (listLayout->friendLayouts[Online]->count() != 0) while (listLayout->friendLayouts[Online]->count() != 0)
{ {
QWidget *getWidget = listLayout->friendLayouts[Online]->takeAt(0)->widget(); QWidget *getWidget = listLayout->friendLayouts[Online]->takeAt(0)->widget();
qDebug() << getWidget;
assert(getWidget != nullptr); assert(getWidget != nullptr);
FriendWidget *friendWidget = dynamic_cast<FriendWidget*>(getWidget); FriendWidget *friendWidget = dynamic_cast<FriendWidget*>(getWidget);
qDebug() << friendWidget;
friendList->moveWidget(friendWidget, FriendList::findFriend(friendWidget->friendId)->getStatus(), true); friendList->moveWidget(friendWidget, FriendList::findFriend(friendWidget->friendId)->getStatus(), true);
} }
while (listLayout->friendLayouts[Offline]->count() != 0) while (listLayout->friendLayouts[Offline]->count() != 0)
{ {
QWidget *getWidget = listLayout->friendLayouts[Offline]->takeAt(0)->widget(); QWidget *getWidget = listLayout->friendLayouts[Offline]->takeAt(0)->widget();
qDebug() << getWidget; assert(getWidget != nullptr);
assert(getWidget != nullptr);
FriendWidget *friendWidget = dynamic_cast<FriendWidget*>(getWidget); FriendWidget *friendWidget = dynamic_cast<FriendWidget*>(getWidget);
qDebug() << friendWidget;
friendList->moveWidget(friendWidget, FriendList::findFriend(friendWidget->friendId)->getStatus(), true); friendList->moveWidget(friendWidget, FriendList::findFriend(friendWidget->friendId)->getStatus(), true);
} }

View File

@ -36,13 +36,18 @@ public:
void searchChatrooms(const QString &searchString, bool hideOnline = false, bool hideOffline = false, bool hideGroups = false); void searchChatrooms(const QString &searchString, bool hideOnline = false, bool hideOffline = false, bool hideGroups = false);
void expand();
void toggle(); void toggle();
void updateOnline(); void updateOnline();
void updateOffline(); void updateOffline();
QString getName() const;
void renameCircle(); void renameCircle();
public slots:
void onCompactChanged(bool compact);
protected: protected:
void contextMenuEvent(QContextMenuEvent *event); void contextMenuEvent(QContextMenuEvent *event);
@ -64,7 +69,6 @@ private:
QVBoxLayout *mainLayout; QVBoxLayout *mainLayout;
QLabel *arrowLabel; QLabel *arrowLabel;
QLabel *onlineLabel; QLabel *onlineLabel;
QLabel *offlineLabel;
QWidget *container; QWidget *container;
QLabel *nameLabel; QLabel *nameLabel;
}; };

View File

@ -51,10 +51,15 @@ void FriendListWidget::addGroupWidget(GroupWidget *widget)
listLayout->groupLayout->addWidget(widget); listLayout->groupLayout->addWidget(widget);
} }
void FriendListWidget::addCircleWidget() void FriendListWidget::addCircleWidget(FriendWidget *friendWidget)
{ {
CircleWidget *circleWidget = new CircleWidget(this); CircleWidget *circleWidget = new CircleWidget(this);
circleLayout->addWidget(circleWidget); circleLayout->addWidget(circleWidget);
if (friendWidget != nullptr)
{
circleWidget->addFriendWidget(friendWidget, FriendList::findFriend(friendWidget->friendId)->getStatus());
circleWidget->toggle();
}
circleWidget->show(); // Avoid flickering. circleWidget->show(); // Avoid flickering.
} }
@ -62,7 +67,7 @@ void FriendListWidget::removeCircleWidget(CircleWidget *widget)
{ {
//setUpdatesEnabled(false); //setUpdatesEnabled(false);
//widget->setVisible(false); //widget->setVisible(false);
//circleLayout->removeWidget(widget); circleLayout->removeWidget(widget);
widget->deleteLater(); widget->deleteLater();
//setUpdatesEnabled(true); //setUpdatesEnabled(true);
//widget->deleteLater(); //widget->deleteLater();
@ -127,6 +132,17 @@ QList<GenericChatroomWidget*> FriendListWidget::getAllFriends()
return friends; return friends;
} }
QVector<CircleWidget*> FriendListWidget::getAllCircles()
{
QVector<CircleWidget*> vec;
vec.reserve(circleLayout->count());
for (int i = 0; i < circleLayout->count(); ++i)
{
vec.push_back(dynamic_cast<CircleWidget*>(circleLayout->itemAt(i)->widget()));
}
return vec;
}
void FriendListWidget::dragEnterEvent(QDragEnterEvent *event) void FriendListWidget::dragEnterEvent(QDragEnterEvent *event)
{ {
if (event->mimeData()->hasFormat("friend")) if (event->mimeData()->hasFormat("friend"))

View File

@ -23,6 +23,7 @@
#include <QWidget> #include <QWidget>
#include <QHash> #include <QHash>
#include <QList> #include <QList>
#include <QVector>
#include "src/core/corestructs.h" #include "src/core/corestructs.h"
#include "src/widget/genericchatroomwidget.h" #include "src/widget/genericchatroomwidget.h"
@ -43,12 +44,13 @@ public:
void addGroupWidget(GroupWidget *widget); void addGroupWidget(GroupWidget *widget);
void addCircleWidget(); void addCircleWidget(FriendWidget *widget = nullptr);
void removeCircleWidget(CircleWidget *widget); void removeCircleWidget(CircleWidget *widget);
void searchChatrooms(const QString &searchString, bool hideOnline = false, bool hideOffline = false, bool hideGroups = false); void searchChatrooms(const QString &searchString, bool hideOnline = false, bool hideOffline = false, bool hideGroups = false);
QList<GenericChatroomWidget*> getAllFriends(); QList<GenericChatroomWidget*> getAllFriends();
QVector<CircleWidget*> getAllCircles();
void reDraw(); void reDraw();

View File

@ -38,6 +38,10 @@
#include <QDebug> #include <QDebug>
#include <QInputDialog> #include <QInputDialog>
#include "circlewidget.h"
#include "friendlistwidget.h"
#include <cassert>
FriendWidget::FriendWidget(int FriendId, QString id) FriendWidget::FriendWidget(int FriendId, QString id)
: friendId(FriendId) : friendId(FriendId)
, isDefaultAvatar{true} , isDefaultAvatar{true}
@ -71,10 +75,30 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
if (groupActions.isEmpty()) if (groupActions.isEmpty())
inviteMenu->setEnabled(false); inviteMenu->setEnabled(false);
circleMenu->addAction(tr("To new circle")); CircleWidget *circleWidget = dynamic_cast<CircleWidget*>(parentWidget());
circleMenu->addAction(tr("Remove from this circle"));
QAction* newCircleAction = circleMenu->addAction(tr("To new circle"));
QAction *removeCircleAction;
if (circleWidget != nullptr)
removeCircleAction = circleMenu->addAction(tr("Remove from this circle"));
circleMenu->addSeparator(); circleMenu->addSeparator();
FriendListWidget *friendList;
if (circleWidget == nullptr)
friendList = dynamic_cast<FriendListWidget*>(parentWidget());
else
friendList = dynamic_cast<FriendListWidget*>(circleWidget->parentWidget());
assert(friendList != nullptr);
QVector<CircleWidget*> circleVec = friendList->getAllCircles();
QMap<QAction*, CircleWidget*> circleActions;
for (CircleWidget* circle : circleVec)
{
QAction* circleAction = circleMenu->addAction(tr("Add to circle \"%1\"").arg(circle->getName()));
circleActions[circleAction] = circle;
}
QAction* setAlias = menu.addAction(tr("Set alias...")); QAction* setAlias = menu.addAction(tr("Set alias..."));
menu.addSeparator(); menu.addSeparator();
@ -119,11 +143,25 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
Settings::getInstance().setAutoAcceptDir(id, dir); Settings::getInstance().setAutoAcceptDir(id, dir);
} }
} }
else if (selectedItem == newCircleAction)
{
friendList->addCircleWidget(this);
}
else if (groupActions.contains(selectedItem)) else if (groupActions.contains(selectedItem))
{ {
Group* group = groupActions[selectedItem]; Group* group = groupActions[selectedItem];
Core::getInstance()->groupInviteFriend(friendId, group->getGroupId()); Core::getInstance()->groupInviteFriend(friendId, group->getGroupId());
} }
else if (removeCircleAction != nullptr && selectedItem == removeCircleAction)
{
friendList->moveWidget(this, FriendList::findFriend(friendId)->getStatus(), true);
}
else if (circleActions.contains(selectedItem))
{
CircleWidget* circle = circleActions[selectedItem];
circle->addFriendWidget(this, FriendList::findFriend(friendId)->getStatus());
circle->expand();
}
} }
} }