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

Compact settings and minor circle widget cleanup

This commit is contained in:
Daniel Hrabovcak 2015-05-30 15:10:43 -04:00 committed by tux3
parent 8f02d6c14c
commit 27237e6164
10 changed files with 210 additions and 83 deletions

View File

@ -287,6 +287,7 @@ void Settings::loadPersonnal(Profile* profile)
friendLst.clear();
ps.beginGroup("Friends");
int size = ps.beginReadArray("Friend");
friendLst.reserve(size);
for (int i = 0; i < size; i ++)
{
ps.setArrayIndex(i);
@ -294,6 +295,7 @@ void Settings::loadPersonnal(Profile* profile)
fp.addr = ps.value("addr").toString();
fp.alias = ps.value("alias").toString();
fp.autoAcceptDir = ps.value("autoAcceptDir").toString();
fp.circleIndex = ps.value("circle", -1).toInt();
friendLst[ToxId(fp.addr).publicKey] = fp;
}
ps.endArray();
@ -303,6 +305,17 @@ void Settings::loadPersonnal(Profile* profile)
compactLayout = ps.value("compactLayout", false).toBool();
ps.endGroup();
ps.beginGroup("Circles");
size = ps.beginReadArray("Circle");
circleLst.reserve(size);
for (int i = 0; i < size; i ++)
{
ps.setArrayIndex(i);
circleLst.push_back(ps.value("name").toString());
}
ps.endArray();
ps.endGroup();
ps.beginGroup("Privacy");
typingNotification = ps.value("typingNotification", false).toBool();
enableLogging = ps.value("enableLogging", false).toBool();
@ -450,6 +463,7 @@ void Settings::savePersonal(QString profileName, QString password)
ps.setValue("addr", frnd.addr);
ps.setValue("alias", frnd.alias);
ps.setValue("autoAcceptDir", frnd.autoAcceptDir);
ps.setValue("circle", frnd.circleIndex);
index++;
}
ps.endArray();
@ -459,6 +473,18 @@ void Settings::savePersonal(QString profileName, QString password)
ps.setValue("compactLayout", compactLayout);
ps.endGroup();
ps.beginGroup("Circles");
ps.beginWriteArray("Circle", circleLst.size());
index = 0;
for (auto& circle : circleLst)
{
ps.setArrayIndex(index);
ps.setValue("name", circle);
index++;
}
ps.endArray();
ps.endGroup();
ps.beginGroup("Privacy");
ps.setValue("typingNotification", typingNotification);
ps.setValue("enableLogging", enableLogging);
@ -1255,6 +1281,16 @@ void Settings::setFriendAlias(const ToxId &id, const QString &alias)
}
}
int Settings::getFriendCircleIndex(const ToxId &id) const
{
QString key = id.publicKey;
auto it = friendLst.find(key);
if (it != friendLst.end())
return it->circleIndex;
return -1;
}
void Settings::removeFriendSettings(const ToxId &id)
{
QMutexLocker locker{&bigLock};
@ -1298,6 +1334,16 @@ void Settings::setGroupchatPosition(bool value)
groupchatPosition = value;
}
int Settings::getCircleCount() const
{
return circleLst.size();
}
QString Settings::getCircleName(int index) const
{
return circleLst[index];
}
int Settings::getThemeColor() const
{
QMutexLocker locker{&bigLock};

View File

@ -228,6 +228,9 @@ public:
QString getFriendAlias(const ToxId &id) const;
void setFriendAlias(const ToxId &id, const QString &alias);
int getFriendCircleIndex(const ToxId &id) const;
void setFriendCircleIndex(const ToxId &id, int index);
void removeFriendSettings(const ToxId &id);
bool getFauxOfflineMessaging() const;
@ -242,6 +245,11 @@ public:
bool getAutoLogin() const;
void setAutoLogin(bool state);
int getCircleCount() const;
void addCircle(const QString &name);
QString getCircleName(int index) const;
void setCircleName(int index);
// Assume all widgets have unique names
// Don't use it to save every single thing you want to save, use it
// for some general purpose widgets, such as MainWindows or Splitters,
@ -357,10 +365,13 @@ private:
QString alias;
QString addr;
QString autoAcceptDir;
int circleIndex;
};
QHash<QString, friendProp> friendLst;
QVector<QString> circleLst;
int themeColor;
static QMutex bigLock;

View File

@ -42,66 +42,44 @@ CircleWidget::CircleWidget(FriendListWidget *parent)
container = new QWidget(this);
container->setObjectName("circleWidgetContainer");
container->setProperty("active", false);
mainLayout = new QVBoxLayout(this);
listLayout = new FriendListLayout();
QHBoxLayout *layout = new QHBoxLayout();
QVBoxLayout *midLayout = new QVBoxLayout;
QHBoxLayout *topLayout = new QHBoxLayout;
container->setLayoutDirection(Qt::LeftToRight);
this->layout()->setSpacing(0);
this->layout()->setMargin(0);
container->setFixedHeight(55);
setLayoutDirection(Qt::LeftToRight);
// status text
statusLabel = new QLabel("0 / 0", this);
statusLabel->setObjectName("status");
statusLabel->setTextFormat(Qt::PlainText);
midLayout->addStretch();
arrowLabel = new QLabel(">", container);
arrowLabel->setPixmap(QPixmap(":/ui/chatArea/scrollBarRightArrow.svg"));
arrowLabel->setStyleSheet("color: white;");
topLayout->addWidget(arrowLabel);
topLayout->addSpacing(5);
nameLabel = new QLabel("Circle", container);
// name text
nameLabel = new QLabel(this);
nameLabel->setObjectName("name");
topLayout->addWidget(nameLabel);
QFrame *lineFrame = new QFrame(container);
nameLabel->setTextFormat(Qt::PlainText);
nameLabel->setText("Circle");
arrowLabel = new QLabel(this);
arrowLabel->setPixmap(QPixmap(":/ui/chatArea/scrollBarRightArrow.svg"));
fullLayout = new QVBoxLayout(this);
fullLayout->setSpacing(0);
fullLayout->setMargin(0);
fullLayout->addWidget(container);
lineFrame = new QFrame(container);
lineFrame->setObjectName("line");
lineFrame->setFrameShape(QFrame::HLine);
midLayout->addLayout(topLayout);
midLayout->addWidget(lineFrame);
midLayout->addStretch();
QHBoxLayout *statusLayout = new QHBoxLayout();
onlineLabel = new QLabel("0", container);
onlineLabel->setObjectName("status");
statusLayout->addWidget(onlineLabel);
topLayout->addStretch();
topLayout->addLayout(statusLayout);
midLayout->addStretch();
layout->addSpacing(10);
layout->addLayout(midLayout);
layout->addSpacing(10);
container->setLayout(layout);
mainLayout->addWidget(container);
listLayout = new FriendListLayout();
setAcceptDrops(true);
onCompactChanged(isCompact());
//renameCircle();
}
void CircleWidget::addFriendWidget(FriendWidget *w, Status s)
{
listLayout->addFriendWidget(w, s);
//if (s == Status::Offline)
updateOffline();
//else
updateOnline();
updateStatus();
}
void CircleWidget::expand()
@ -116,12 +94,12 @@ void CircleWidget::toggle()
expanded = !expanded;
if (expanded)
{
mainLayout->addLayout(listLayout);
fullLayout->addLayout(listLayout);
arrowLabel->setPixmap(QPixmap(":/ui/chatArea/scrollBarDownArrow.svg"));
}
else
{
mainLayout->removeItem(listLayout);
fullLayout->removeItem(listLayout);
arrowLabel->setPixmap(QPixmap(":/ui/chatArea/scrollBarRightArrow.svg"));
}
}
@ -136,29 +114,92 @@ QString CircleWidget::getName() const
return nameLabel->text();
}
void CircleWidget::setName(const QString &name)
{
nameLabel->setText(name);
}
void CircleWidget::renameCircle()
{
qDebug() << nameLabel->parentWidget()->layout();
QLineEdit *lineEdit = new QLineEdit(nameLabel->text());
lineEdit->show();
topLayout->removeWidget(nameLabel);
topLayout->insertWidget(3, lineEdit);
nameLabel->setVisible(false);
//topLayout->replaceWidget(nameLabel, lineEdit);
//nameLabel->parentWidget()->layout()
//static_cast<QBoxLayout*>(nameLabel->parentWidget()->layout())->insertWidget(nameLabel->parentWidget()->layout()->indexOf(nameLabel) - 1, lineEdit);
//nameLabel->parentWidget()->layout()->replaceWidget(nameLabel, lineEdit);
nameLabel->setVisible(false);
//nameLabel->setVisible(false);
lineEdit->selectAll();
lineEdit->setFocus();
connect(lineEdit, &QLineEdit::editingFinished, [this, lineEdit]()
{
nameLabel->setVisible(true);
this->topLayout->removeWidget(lineEdit);
this->topLayout->insertWidget(3, nameLabel);
//this->topLayout->replaceWidget(lineEdit, nameLabel);
//this->nameLabel->setVisible(true);
//lineEdit->parentWidget()->layout()->replaceWidget(lineEdit, nameLabel);
nameLabel->setText(lineEdit->text());
this->nameLabel->setText(lineEdit->text());
nameLabel->setVisible(true);
lineEdit->deleteLater();
});
}
void CircleWidget::onCompactChanged(bool compact)
void CircleWidget::onCompactChanged(bool _compact)
{
delete topLayout;
delete mainLayout;
topLayout = new QHBoxLayout;
topLayout->setSpacing(0);
topLayout->setMargin(0);
setProperty("compact", _compact);
if (property("compact").toBool())
{
mainLayout = nullptr;
container->setFixedHeight(25);
container->setLayout(topLayout);
topLayout->addSpacing(18);
topLayout->addWidget(arrowLabel);
topLayout->addSpacing(5);
topLayout->addWidget(nameLabel);
topLayout->addSpacing(5);
topLayout->addWidget(lineFrame, 1);
topLayout->addSpacing(5);
topLayout->addWidget(statusLabel);
topLayout->addSpacing(5);
topLayout->activate();
}
else
{
qDebug() << "LTSE";
mainLayout = new QVBoxLayout();
mainLayout->setSpacing(0);
mainLayout->setContentsMargins(20, 0, 20, 0);
container->setFixedHeight(55);
container->setLayout(mainLayout);
topLayout->addWidget(arrowLabel);
topLayout->addSpacing(10);
topLayout->addWidget(nameLabel);
topLayout->addStretch();
topLayout->addWidget(statusLabel);
topLayout->activate();
mainLayout->addStretch();
mainLayout->addLayout(topLayout);
mainLayout->addWidget(lineFrame);
mainLayout->addStretch();
mainLayout->activate();
}
Style::repolish(this);
}
void CircleWidget::contextMenuEvent(QContextMenuEvent *event)
@ -236,8 +277,7 @@ void CircleWidget::dropEvent(QDropEvent *event)
if (circleWidget != nullptr)
{
// In case the status was changed while moving, update both.
circleWidget->updateOffline();
circleWidget->updateOnline();
circleWidget->updateStatus();
}
container->setAttribute(Qt::WA_UnderMouse, false);
@ -245,12 +285,7 @@ void CircleWidget::dropEvent(QDropEvent *event)
}
}
void CircleWidget::updateOnline()
void CircleWidget::updateStatus()
{
onlineLabel->setText(QString::number(listLayout->friendOnlineCount()) + QStringLiteral(" / ") + QString::number(listLayout->friendOfflineCount()));
}
void CircleWidget::updateOffline()
{
//offlineLabel->setText(QString::number(listLayout->friendOfflineCount()));
statusLabel->setText(QString::number(listLayout->friendOnlineCount()) + QStringLiteral(" / ") + QString::number(listLayout->friendTotalCount()));
}

View File

@ -39,10 +39,10 @@ public:
void expand();
void toggle();
void updateOnline();
void updateOffline();
void updateStatus();
QString getName() const;
void setName(const QString &name);
void renameCircle();
public slots:
@ -65,12 +65,15 @@ private:
Offline = 1
};
bool expanded = false;
FriendListLayout *listLayout;
QVBoxLayout *mainLayout;
QLabel *arrowLabel;
QLabel *onlineLabel;
QWidget *container;
QLabel *nameLabel;
FriendListLayout* listLayout;
QVBoxLayout* fullLayout;
QVBoxLayout* mainLayout = nullptr;
QLabel* arrowLabel;
QLabel* nameLabel;
QLabel* statusLabel;
QFrame* lineFrame;
QWidget* container;
QHBoxLayout* topLayout = nullptr;
};
#endif // CIRCLEWIDGET_H

View File

@ -88,7 +88,7 @@ int FriendListLayout::friendOnlineCount() const
return friendLayouts[Online]->count();
}
int FriendListLayout::friendOfflineCount() const
int FriendListLayout::friendTotalCount() const
{
return friendLayouts[Offline]->count() + friendOnlineCount();
}

View File

@ -31,7 +31,7 @@ public:
void addGroupWidget(GroupWidget *widget);
void addFriendWidget(FriendWidget *widget, Status s);
int friendOnlineCount() const;
int friendOfflineCount() const;
int friendTotalCount() const;
void searchChatrooms(const QString &searchString, bool hideOnline = false, bool hideOffline = false, bool hideGroups = false);
bool hasChatrooms() const;

View File

@ -51,7 +51,30 @@ void FriendListWidget::addGroupWidget(GroupWidget *widget)
listLayout->groupLayout->addWidget(widget);
}
void FriendListWidget::addCircleWidget(FriendWidget *friendWidget)
void FriendListWidget::addFriendWidget(FriendWidget *w, Status s, int circleIndex)
{
CircleWidget *circleWidget = nullptr;
qDebug() << circleIndex;
if (circleIndex >= 0 && circleIndex < circleLayout->count())
circleWidget = dynamic_cast<CircleWidget*>(circleLayout->itemAt(circleIndex)->widget());
if (circleWidget == nullptr)
circleIndex = -1;
if (circleIndex == -1)
moveWidget(w, s, true);
else
circleWidget->addFriendWidget(w, s);
}
void FriendListWidget::addCircleWidget(const QString &name)
{
CircleWidget *circleWidget = new CircleWidget(this);
circleWidget->setName(name);
circleLayout->addWidget(circleWidget);
}
CircleWidget* FriendListWidget::addCircleWidget(FriendWidget *friendWidget)
{
CircleWidget *circleWidget = new CircleWidget(this);
circleLayout->addWidget(circleWidget);
@ -61,6 +84,7 @@ void FriendListWidget::addCircleWidget(FriendWidget *friendWidget)
circleWidget->toggle();
}
circleWidget->show(); // Avoid flickering.
return circleWidget;
}
void FriendListWidget::removeCircleWidget(CircleWidget *widget)
@ -168,8 +192,7 @@ void FriendListWidget::dropEvent(QDropEvent *event)
if (circleWidget != nullptr)
{
// In case the status was changed while moving, update both.
circleWidget->updateOffline();
circleWidget->updateOnline();
circleWidget->updateStatus();
}
}
}

View File

@ -43,8 +43,9 @@ public:
explicit FriendListWidget(QWidget *parent = 0, bool groupsOnTop = true);
void addGroupWidget(GroupWidget *widget);
void addCircleWidget(FriendWidget *widget = nullptr);
void addFriendWidget(FriendWidget *w, Status s, int circleIndex);
void addCircleWidget(const QString &name);
CircleWidget *addCircleWidget(FriendWidget *widget = nullptr);
void removeCircleWidget(CircleWidget *widget);
void searchChatrooms(const QString &searchString, bool hideOnline = false, bool hideOffline = false, bool hideGroups = false);

View File

@ -62,7 +62,7 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
QString dir = Settings::getInstance().getAutoAcceptDir(id);
QMenu menu;
QMenu* inviteMenu = menu.addMenu(tr("Invite to group","Menu to invite a friend to a groupchat"));
QMenu* circleMenu = menu.addMenu(tr("Move to circle", "Menu to move a friend into a different circle"));
QMenu* circleMenu = menu.addMenu(tr("Move to circle...", "Menu to move a friend into a different circle"));
QAction* copyId = menu.addAction(tr("Copy friend ID","Menu to copy the Tox ID of that friend"));
QMap<QAction*, Group*> groupActions;
@ -95,8 +95,11 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
QMap<QAction*, CircleWidget*> circleActions;
for (CircleWidget* circle : circleVec)
{
QAction* circleAction = circleMenu->addAction(tr("Add to circle \"%1\"").arg(circle->getName()));
circleActions[circleAction] = circle;
if (circle != circleWidget)
{
QAction* circleAction = circleMenu->addAction(tr("Move to circle \"%1\"").arg(circle->getName()));
circleActions[circleAction] = circle;
}
}
QAction* setAlias = menu.addAction(tr("Set alias..."));

View File

@ -29,6 +29,7 @@
#include "src/group.h"
#include "groupwidget.h"
#include "form/groupchatform.h"
#include "circlewidget.h"
#include "src/widget/style.h"
#include "friendlistwidget.h"
#include "form/chatform.h"
@ -232,6 +233,9 @@ void Widget::init()
if (!Settings::getInstance().getShowSystemTray())
show();
for (int i = 0; i < Settings::getInstance().getCircleCount(); ++i)
contactListWidget->addCircleWidget(Settings::getInstance().getCircleName(i));
}
bool Widget::eventFilter(QObject *obj, QEvent *event)
@ -577,7 +581,7 @@ void Widget::addFriend(int friendId, const QString &userId)
{
ToxId userToxId = ToxId(userId);
Friend* newfriend = FriendList::addFriend(friendId, userToxId);
contactListWidget->moveWidget(newfriend->getFriendWidget(),Status::Offline);
contactListWidget->addFriendWidget(newfriend->getFriendWidget(),Status::Offline,Settings::getInstance().getFriendCircleIndex(newfriend->getToxId()));
Core* core = Nexus::getCore();
connect(newfriend, &Friend::displayedNameChanged, contactListWidget, &FriendListWidget::moveWidget);
@ -1415,7 +1419,8 @@ void Widget::friendListContextMenu(const QPoint &pos)
if (chosenAction == addCircleAction)
{
contactListWidget->addCircleWidget();
CircleWidget *newcircle = contactListWidget->addCircleWidget();
connect(settingsWidget, &SettingsWidget::compactToggled, newcircle, &CircleWidget::onCompactChanged);
}
}