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

Merge branch 'pr1371'

This commit is contained in:
Dubslow 2015-03-25 11:22:12 -05:00
commit 2a730d5e22
No known key found for this signature in database
GPG Key ID: 3DB8E05315C220AA
11 changed files with 119 additions and 25 deletions

View File

@ -58,6 +58,8 @@ void Friend::setName(QString name)
if (widget->isActive())
GUI::setWindowTitle(name);
emit displayedNameChanged(getFriendWidget(), getStatus(), hasNewEvents);
}
}
@ -71,6 +73,8 @@ void Friend::setAlias(QString name)
if (widget->isActive())
GUI::setWindowTitle(dispName);
emit displayedNameChanged(getFriendWidget(), getStatus(), hasNewEvents);
}
void Friend::setStatusMessage(QString message)

View File

@ -17,14 +17,16 @@
#ifndef FRIEND_H
#define FRIEND_H
#include <QObject>
#include <QString>
#include "corestructs.h"
struct FriendWidget;
class ChatForm;
struct Friend
struct Friend : QObject
{
Q_OBJECT
public:
Friend(int FriendId, const ToxID &UserId);
Friend(const Friend& other)=delete;
@ -49,6 +51,9 @@ public:
ChatForm *getChatForm();
FriendWidget *getFriendWidget();
signals:
void displayedNameChanged(FriendWidget* widget, Status s, int hasNewEvents);
private:
QString userAlias, userName;
ToxID userID;

View File

@ -217,6 +217,7 @@ void Settings::load()
QStandardPaths::locate(QStandardPaths::HomeLocation, QString(), QStandardPaths::LocateDirectory)
).toString();
compactLayout = s.value("compactLayout", false).toBool();
groupchatPosition = s.value("groupchatPosition", true).toBool();
s.endGroup();
s.beginGroup("Advanced");
@ -385,6 +386,7 @@ void Settings::saveGlobal(QString path)
s.setValue("groupAlwaysNotify", groupAlwaysNotify);
s.setValue("fauxOfflineMessaging", fauxOfflineMessaging);
s.setValue("compactLayout", compactLayout);
s.setValue("groupchatPosition", groupchatPosition);
s.setValue("autoSaveEnabled", autoSaveEnabled);
s.setValue("globalAutoAcceptDir", globalAutoAcceptDir);
s.endGroup();
@ -1174,6 +1176,16 @@ void Settings::setCompactLayout(bool value)
emit compactLayoutChanged();
}
bool Settings::getGroupchatPosition() const
{
return groupchatPosition;
}
void Settings::setGroupchatPosition(bool value)
{
groupchatPosition = value;
}
int Settings::getThemeColor() const
{
return themeColor;

View File

@ -245,6 +245,9 @@ public:
bool getCompactLayout() const;
void setCompactLayout(bool compact);
bool getGroupchatPosition() const;
void setGroupchatPosition(bool value);
public:
void save(bool writePersonal = true);
void save(QString path, bool writePersonal = true);
@ -272,6 +275,7 @@ private:
bool fauxOfflineMessaging;
bool compactLayout;
bool groupchatPosition;
bool enableIPv6;
QString translation;
static bool makeToxPortable;

View File

@ -77,6 +77,7 @@ GeneralForm::GeneralForm(SettingsWidget *myParent) :
bodyUI->groupAlwaysNotify->setChecked(Settings::getInstance().getGroupAlwaysNotify());
bodyUI->cbFauxOfflineMessaging->setChecked(Settings::getInstance().getFauxOfflineMessaging());
bodyUI->cbCompactLayout->setChecked(Settings::getInstance().getCompactLayout());
bodyUI->cbGroupchatPosition->setChecked(Settings::getInstance().getGroupchatPosition());
for (auto entry : SmileyPack::listSmileyPacks())
{
@ -154,7 +155,8 @@ GeneralForm::GeneralForm(SettingsWidget *myParent) :
connect(bodyUI->reconnectButton, &QPushButton::clicked, this, &GeneralForm::onReconnectClicked);
connect(bodyUI->cbFauxOfflineMessaging, &QCheckBox::stateChanged, this, &GeneralForm::onFauxOfflineMessaging);
connect(bodyUI->cbCompactLayout, &QCheckBox::stateChanged, this, &GeneralForm::onCompactLayout);
connect(bodyUI->cbGroupchatPosition, &QCheckBox::stateChanged, this, &GeneralForm::onGroupchatPositionChanged);
// prevent stealing mouse whell scroll
// scrolling event won't be transmitted to comboboxes or qspinboxes when scrolling
// you can scroll through general settings without accidentially chaning theme/skin/icons etc.
@ -394,6 +396,12 @@ void GeneralForm::onCompactLayout()
emit parent->compactToggled(bodyUI->cbCompactLayout->isChecked());
}
void GeneralForm::onGroupchatPositionChanged()
{
Settings::getInstance().setGroupchatPosition(bodyUI->cbGroupchatPosition->isChecked());
emit parent->groupchatPositionToggled(bodyUI->cbGroupchatPosition->isChecked());
}
void GeneralForm::onThemeColorChanged(int)
{
int index = bodyUI->themeColorCBox->currentIndex();

View File

@ -60,6 +60,7 @@ private slots:
void onSetGroupAlwaysNotify();
void onFauxOfflineMessaging();
void onCompactLayout();
void onGroupchatPositionChanged();
void onThemeColorChanged(int);
private:

View File

@ -374,7 +374,7 @@ instead of system taskbar.</string>
<widget class="QCheckBox" name="cbFauxOfflineMessaging">
<property name="toolTip">
<string comment="toolTip for Faux offline messaging setting">Messages you are trying to send to your friends when they are not online
will be sent to them when they will appear online to you.</string>
will be sent to them when they appear online to you.</string>
</property>
<property name="text">
<string>Faux offline messaging</string>
@ -391,6 +391,16 @@ will be sent to them when they will appear online to you.</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QCheckBox" name="cbGroupchatPosition">
<property name="toolTip">
<string comment="toolTip for groupchat positioning">If checked, groupchats will be placed at the top of the friends list, otherwise, they'll be placed below online friends.</string>
</property>
<property name="text">
<string>Place groupchats at top of friend list</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View File

@ -44,6 +44,7 @@ public:
signals:
void setShowSystemTray(bool newValue);
void compactToggled(bool compact);
void groupchatPositionToggled(bool groupchatPosition);
private slots:
void onTabChanged(int);

View File

@ -16,8 +16,11 @@
#include "friendlistwidget.h"
#include <QDebug>
#include <QGridLayout>
#include "src/friend.h"
#include "src/friendlist.h"
#include "src/widget/friendwidget.h"
FriendListWidget::FriendListWidget(QWidget *parent) :
FriendListWidget::FriendListWidget(QWidget *parent, bool groupchatPosition) :
QWidget(parent)
{
mainLayout = new QGridLayout();
@ -30,7 +33,7 @@ FriendListWidget::FriendListWidget(QWidget *parent) :
groupLayout->setSpacing(0);
groupLayout->setMargin(0);
for (Status s : {Status::Online, Status::Away, Status::Busy, Status::Offline})
for (Status s : {Status::Online, Status::Offline})
{
QVBoxLayout *l = new QVBoxLayout();
l->setSpacing(0);
@ -39,11 +42,18 @@ FriendListWidget::FriendListWidget(QWidget *parent) :
layouts[static_cast<int>(s)] = l;
}
mainLayout->addLayout(layouts[static_cast<int>(Status::Online)], 0, 0);
mainLayout->addLayout(groupLayout, 1, 0);
mainLayout->addLayout(layouts[static_cast<int>(Status::Away)], 2, 0);
mainLayout->addLayout(layouts[static_cast<int>(Status::Busy)], 3, 0);
mainLayout->addLayout(layouts[static_cast<int>(Status::Offline)], 4, 0);
if(groupchatPosition)
{
mainLayout->addLayout(groupLayout, 0, 0);
mainLayout->addLayout(layouts[static_cast<int>(Status::Online)], 1, 0);
mainLayout->addLayout(layouts[static_cast<int>(Status::Offline)], 2, 0);
}
else
{
mainLayout->addLayout(layouts[static_cast<int>(Status::Online)], 0, 0);
mainLayout->addLayout(groupLayout, 1, 0);
mainLayout->addLayout(layouts[static_cast<int>(Status::Offline)], 2, 0);
}
}
QVBoxLayout* FriendListWidget::getGroupLayout()
@ -57,15 +67,43 @@ QVBoxLayout* FriendListWidget::getFriendLayout(Status s)
if (res != layouts.end())
return res.value();
qDebug() << "Friend Status: " << static_cast<int>(s) << " not found!";
//qDebug() << "Friend Status: " << static_cast<int>(s) << " not found!";
return layouts[static_cast<int>(Status::Online)];
}
void FriendListWidget::onGroupchatPositionChanged(bool top)
{
mainLayout->removeItem(groupLayout);
mainLayout->removeItem(getFriendLayout(Status::Online));
if(top)
{
mainLayout->addLayout(groupLayout, 0, 0);
mainLayout->addLayout(layouts[static_cast<int>(Status::Online)], 1, 0);
}
else
{
mainLayout->addLayout(layouts[static_cast<int>(Status::Online)], 0, 0);
mainLayout->addLayout(groupLayout, 1, 0);
}
}
void FriendListWidget::moveWidget(QWidget *w, Status s, int hasNewEvents)
{
mainLayout->removeWidget(w);
if (hasNewEvents == 0)
getFriendLayout(s)->addWidget(w);
else
getFriendLayout(s)->insertWidget(0, w);
QVBoxLayout* l = getFriendLayout(s);
l->removeWidget(w);
Friend* g = FriendList::findFriend(dynamic_cast<FriendWidget*>(w)->friendId);
for(int i = 0; i < l->count(); i++)
{
FriendWidget* w1 = dynamic_cast<FriendWidget*>(l->itemAt(i)->widget());
if(w1 != NULL)
{
Friend* f = FriendList::findFriend(w1->friendId);
if(f->getDisplayedName().localeAwareCompare(g->getDisplayedName()) > 0)
{
l->insertWidget(i,w);
return;
}
}
}
l->addWidget(w);
}

View File

@ -29,15 +29,15 @@ class FriendListWidget : public QWidget
{
Q_OBJECT
public:
explicit FriendListWidget(QWidget *parent = 0);
explicit FriendListWidget(QWidget *parent = 0, bool groupchatPosition = true);
QVBoxLayout* getGroupLayout();
QVBoxLayout* getFriendLayout(Status s);
void moveWidget(QWidget *w, Status s, int hasNewEvents);
signals:
public slots:
void onGroupchatPositionChanged(bool top);
void moveWidget(QWidget *w, Status s, int hasNewEvents);
private:
QHash<int, QVBoxLayout*> layouts;

View File

@ -144,7 +144,7 @@ void Widget::init()
ui->statusHead->setStyleSheet(Style::getStylesheet(":/ui/window/statusPanel.css"));
contactListWidget = new FriendListWidget();
contactListWidget = new FriendListWidget(0, Settings::getInstance().getGroupchatPosition());
ui->friendList->setWidget(contactListWidget);
ui->friendList->setLayoutDirection(Qt::RightToLeft);
@ -197,6 +197,7 @@ void Widget::init()
addFriendForm->show(*ui);
connect(settingsWidget, &SettingsWidget::groupchatPositionToggled, contactListWidget, &FriendListWidget::onGroupchatPositionChanged);
#if (AUTOUPDATE_ENABLED)
if (Settings::getInstance().getCheckUpdates())
AutoUpdater::checkUpdatesAsyncInteractive();
@ -561,10 +562,10 @@ void Widget::addFriend(int friendId, const QString &userId)
//qDebug() << "Widget: Adding friend with id" << userId;
ToxID userToxId = ToxID::fromString(userId);
Friend* newfriend = FriendList::addFriend(friendId, userToxId);
QLayout* layout = contactListWidget->getFriendLayout(Status::Offline);
layout->addWidget(newfriend->getFriendWidget());
contactListWidget->moveWidget(newfriend->getFriendWidget(),Status::Offline,0);
Core* core = Nexus::getCore();
connect(newfriend, &Friend::displayedNameChanged, contactListWidget, &FriendListWidget::moveWidget);
connect(settingsWidget, &SettingsWidget::compactToggled, newfriend->getFriendWidget(), &GenericChatroomWidget::onCompactChanged);
connect(newfriend->getFriendWidget(), SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), this, SLOT(onChatroomWidgetClicked(GenericChatroomWidget*)));
connect(newfriend->getFriendWidget(), SIGNAL(removeFriend(int)), this, SLOT(removeFriend(int)));
@ -625,11 +626,21 @@ void Widget::onFriendStatusChanged(int friendId, Status status)
Friend* f = FriendList::findFriend(friendId);
if (!f)
return;
contactListWidget->moveWidget(f->getFriendWidget(), status, f->getEventFlag());
bool isActualChange = f->getStatus() != status;
if(isActualChange)
{
if(f->getStatus() == Status::Offline)
{
contactListWidget->moveWidget(f->getFriendWidget(), Status::Online, f->getEventFlag());
}
else if(status == Status::Offline)
{
contactListWidget->moveWidget(f->getFriendWidget(), Status::Offline, f->getEventFlag());
}
}
f->setStatus(status);
f->getFriendWidget()->updateStatusLight();