1
0
forked from blue/squawk

separating chat from conversation in ui

This commit is contained in:
Blue 2019-08-23 12:51:33 +03:00
parent 828d14c908
commit e2cc1bae2e
10 changed files with 150 additions and 65 deletions

View File

@ -22,8 +22,9 @@ set(squawkUI_SRC
models/presence.cpp models/presence.cpp
models/group.cpp models/group.cpp
models/room.cpp models/room.cpp
conversation.cpp widgets/conversation.cpp
messageline.cpp widgets/chat.cpp
widgets/messageline.cpp
newcontact.cpp newcontact.cpp
) )

View File

@ -241,7 +241,7 @@ void Squawk::onRosterItemDoubleClicked(const QModelIndex& item)
itr->second->setPalResource(res); itr->second->setPalResource(res);
} }
} else { } else {
Conversation* conv = new Conversation(contact); Chat* conv = new Chat(contact);
conv->setAttribute(Qt::WA_DeleteOnClose); conv->setAttribute(Qt::WA_DeleteOnClose);
connect(conv, SIGNAL(destroyed(QObject*)), this, SLOT(onConversationClosed(QObject*))); connect(conv, SIGNAL(destroyed(QObject*)), this, SLOT(onConversationClosed(QObject*)));

View File

@ -28,7 +28,7 @@
#include <list> #include <list>
#include "accounts.h" #include "accounts.h"
#include "conversation.h" #include "widgets/chat.h"
#include "models/roster.h" #include "models/roster.h"
#include "newcontact.h" #include "newcontact.h"

72
ui/widgets/chat.cpp Normal file
View File

@ -0,0 +1,72 @@
/*
* Squawk messenger.
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
*
* 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
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "chat.h"
Chat::Chat(Models::Contact* p_contact, QWidget* parent):
Conversation(p_contact->getAccountJid(), p_contact->getAccountResource(), p_contact->getJid(), "", p_contact->getAccountName(), parent),
contact(p_contact)
{
setName(p_contact->getContactName());
updateState();
setStatus(p_contact->getStatus());
connect(contact, SIGNAL(childChanged(Models::Item*, int, int)), this, SLOT(onContactChanged(Models::Item*, int, int)));
line->setMyName(p_contact->getAccountName());
Models::Contact::Messages deque;
contact->getMessages(deque);
for (Models::Contact::Messages::const_iterator itr = deque.begin(), end = deque.end(); itr != end; ++itr) {
addMessage(*itr);
}
}
Chat::~Chat()
{
}
void Chat::onContactChanged(Models::Item* item, int row, int col)
{
if (item == contact) {
switch (col) {
case 0:
setName(contact->getContactName());
break;
case 3:
updateState();
break;
case 5:
setStatus(contact->getStatus());
break;
}
}
}
void Chat::updateState()
{
Shared::Availability av = contact->getAvailability();
statusIcon->setPixmap(Shared::availabilityIcon(av, true).pixmap(40));
statusIcon->setToolTip(Shared::availabilityNames[av]);
}
void Chat::setStatus(const QString& status)
{
statusLabel->setText(status);
}

47
ui/widgets/chat.h Normal file
View File

@ -0,0 +1,47 @@
/*
* Squawk messenger.
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
*
* 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
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CHAT_H
#define CHAT_H
#include "conversation.h"
#include "../models/contact.h"
namespace Ui
{
class Chat;
}
class Chat : public Conversation
{
Q_OBJECT
public:
Chat(Models::Contact* p_contact, QWidget* parent = 0);
~Chat();
protected slots:
void onContactChanged(Models::Item* item, int row, int col);
private:
void updateState();
void setStatus(const QString& status);
private:
Models::Contact* contact;
};
#endif // CHAT_H

View File

@ -24,14 +24,19 @@
#include <QGraphicsDropShadowEffect> #include <QGraphicsDropShadowEffect>
#include <QFileDialog> #include <QFileDialog>
Conversation::Conversation(Models::Contact* p_contact, QWidget* parent): Conversation::Conversation(const QString& mJid, const QString mRes, const QString pJid, const QString pRes, const QString& acc, QWidget* parent):
QWidget(parent), QWidget(parent),
contact(p_contact), myJid(mJid),
myResource(mRes),
palJid(pJid),
activePalResource(pRes),
account(acc),
line(new MessageLine()), line(new MessageLine()),
m_ui(new Ui::Conversation()), m_ui(new Ui::Conversation()),
ker(), ker(),
activePalResource(),
thread(), thread(),
statusIcon(0),
statusLabel(0),
scroll(down), scroll(down),
manualSliderChange(false), manualSliderChange(false),
requestingHistory(false), requestingHistory(false),
@ -41,26 +46,15 @@ Conversation::Conversation(Models::Contact* p_contact, QWidget* parent):
m_ui->splitter->setSizes({300, 0}); m_ui->splitter->setSizes({300, 0});
m_ui->splitter->setStretchFactor(1, 0); m_ui->splitter->setStretchFactor(1, 0);
setName(p_contact->getContactName()); statusIcon = m_ui->statusIcon;
updateState(); statusLabel = m_ui->statusLabel;
setStatus(p_contact->getStatus());
connect(contact, SIGNAL(childChanged(Models::Item*, int, int)), this, SLOT(onContactChanged(Models::Item*, int, int)));
connect(&ker, SIGNAL(enterPressed()), this, SLOT(onEnterPressed())); connect(&ker, SIGNAL(enterPressed()), this, SLOT(onEnterPressed()));
connect(m_ui->sendButton, SIGNAL(clicked(bool)), this, SLOT(onEnterPressed())); connect(m_ui->sendButton, SIGNAL(clicked(bool)), this, SLOT(onEnterPressed()));
connect(line, SIGNAL(resize(int)), this, SLOT(onMessagesResize(int)));
//connect(m_ui->attachButton, SIGNAL(clicked(bool)), this, SLOT(onAttach())); //connect(m_ui->attachButton, SIGNAL(clicked(bool)), this, SLOT(onAttach()));
m_ui->messageEditor->installEventFilter(&ker); m_ui->messageEditor->installEventFilter(&ker);
line->setMyName(p_contact->getAccountName());
Models::Contact::Messages deque;
contact->getMessages(deque);
for (Models::Contact::Messages::const_iterator itr = deque.begin(), end = deque.end(); itr != end; ++itr) {
addMessage(*itr);
}
connect(line, SIGNAL(resize(int)), this, SLOT(onMessagesResize(int)));
QScrollBar* vs = m_ui->scrollArea->verticalScrollBar(); QScrollBar* vs = m_ui->scrollArea->verticalScrollBar();
m_ui->scrollArea->setWidget(line); m_ui->scrollArea->setWidget(line);
@ -106,43 +100,14 @@ void Conversation::setName(const QString& name)
line->setPalName(getJid(), name); line->setPalName(getJid(), name);
} }
void Conversation::updateState()
{
Shared::Availability av = contact->getAvailability();
m_ui->statusIcon->setPixmap(Shared::availabilityIcon(av, true).pixmap(40));
m_ui->statusIcon->setToolTip(Shared::availabilityNames[av]);
}
void Conversation::setStatus(const QString& status)
{
m_ui->statusLabel->setText(status);
}
QString Conversation::getAccount() const QString Conversation::getAccount() const
{ {
return contact->getAccountName(); return account;
} }
QString Conversation::getJid() const QString Conversation::getJid() const
{ {
return contact->getJid(); return palJid;
}
void Conversation::onContactChanged(Models::Item* item, int row, int col)
{
if (item == contact) {
switch (col) {
case 0:
setName(contact->getContactName());
break;
case 3:
updateState();
break;
case 5:
setStatus(contact->getStatus());
break;
}
}
} }
void Conversation::addMessage(const Shared::Message& data) void Conversation::addMessage(const Shared::Message& data)
@ -207,12 +172,11 @@ void Conversation::onEnterPressed()
QString body(m_ui->messageEditor->toPlainText()); QString body(m_ui->messageEditor->toPlainText());
if (body.size() > 0) { if (body.size() > 0) {
const QString& aJid = contact->getAccountJid();
m_ui->messageEditor->clear(); m_ui->messageEditor->clear();
Shared::Message msg(Shared::Message::chat); Shared::Message msg(Shared::Message::chat);
msg.setFromJid(aJid); msg.setFromJid(myJid);
msg.setFromResource(contact->getAccountResource()); msg.setFromResource(myResource);
msg.setToJid(contact->getJid()); msg.setToJid(palJid);
msg.setToResource(activePalResource); msg.setToResource(activePalResource);
msg.setBody(body); msg.setBody(body);
msg.setOutgoing(true); msg.setOutgoing(true);

View File

@ -21,8 +21,7 @@
#include <QWidget> #include <QWidget>
#include <QScopedPointer> #include <QScopedPointer>
#include "../global.h" #include "../../global.h"
#include "models/contact.h"
#include "messageline.h" #include "messageline.h"
namespace Ui namespace Ui
@ -47,7 +46,7 @@ class Conversation : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
Conversation(Models::Contact* p_contact, QWidget* parent = 0); Conversation(const QString& mJid, const QString mRes, const QString pJid, const QString pRes, const QString& acc, QWidget* parent = 0);
~Conversation(); ~Conversation();
QString getJid() const; QString getJid() const;
@ -65,31 +64,33 @@ signals:
void shown(); void shown();
protected: protected:
void updateState();
void setStatus(const QString& status);
void setName(const QString& name); void setName(const QString& name);
void applyVisualEffects(); void applyVisualEffects();
protected slots: protected slots:
void onContactChanged(Models::Item* item, int row, int col);
void onEnterPressed(); void onEnterPressed();
void onMessagesResize(int amount); void onMessagesResize(int amount);
void onSliderValueChanged(int value); void onSliderValueChanged(int value);
void onAttach(); void onAttach();
void onFileSelected(); void onFileSelected();
private: protected:
enum Scroll { enum Scroll {
nothing, nothing,
keep, keep,
down down
}; };
Models::Contact* contact; QString myJid;
QString myResource;
QString palJid;
QString activePalResource;
QString account;
MessageLine* line; MessageLine* line;
QScopedPointer<Ui::Conversation> m_ui; QScopedPointer<Ui::Conversation> m_ui;
KeyEnterReceiver ker; KeyEnterReceiver ker;
QString activePalResource;
QString thread; QString thread;
QLabel* statusIcon;
QLabel* statusLabel;
Scroll scroll; Scroll scroll;
bool manualSliderChange; bool manualSliderChange;
bool requestingHistory; bool requestingHistory;