separating chat from conversation in ui
This commit is contained in:
parent
828d14c908
commit
e2cc1bae2e
@ -22,8 +22,9 @@ set(squawkUI_SRC
|
||||
models/presence.cpp
|
||||
models/group.cpp
|
||||
models/room.cpp
|
||||
conversation.cpp
|
||||
messageline.cpp
|
||||
widgets/conversation.cpp
|
||||
widgets/chat.cpp
|
||||
widgets/messageline.cpp
|
||||
newcontact.cpp
|
||||
)
|
||||
|
||||
|
@ -241,7 +241,7 @@ void Squawk::onRosterItemDoubleClicked(const QModelIndex& item)
|
||||
itr->second->setPalResource(res);
|
||||
}
|
||||
} else {
|
||||
Conversation* conv = new Conversation(contact);
|
||||
Chat* conv = new Chat(contact);
|
||||
|
||||
conv->setAttribute(Qt::WA_DeleteOnClose);
|
||||
connect(conv, SIGNAL(destroyed(QObject*)), this, SLOT(onConversationClosed(QObject*)));
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include <list>
|
||||
|
||||
#include "accounts.h"
|
||||
#include "conversation.h"
|
||||
#include "widgets/chat.h"
|
||||
#include "models/roster.h"
|
||||
#include "newcontact.h"
|
||||
|
||||
|
72
ui/widgets/chat.cpp
Normal file
72
ui/widgets/chat.cpp
Normal 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
47
ui/widgets/chat.h
Normal 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
|
@ -24,14 +24,19 @@
|
||||
#include <QGraphicsDropShadowEffect>
|
||||
#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),
|
||||
contact(p_contact),
|
||||
myJid(mJid),
|
||||
myResource(mRes),
|
||||
palJid(pJid),
|
||||
activePalResource(pRes),
|
||||
account(acc),
|
||||
line(new MessageLine()),
|
||||
m_ui(new Ui::Conversation()),
|
||||
ker(),
|
||||
activePalResource(),
|
||||
thread(),
|
||||
statusIcon(0),
|
||||
statusLabel(0),
|
||||
scroll(down),
|
||||
manualSliderChange(false),
|
||||
requestingHistory(false),
|
||||
@ -41,26 +46,15 @@ Conversation::Conversation(Models::Contact* p_contact, QWidget* parent):
|
||||
m_ui->splitter->setSizes({300, 0});
|
||||
m_ui->splitter->setStretchFactor(1, 0);
|
||||
|
||||
setName(p_contact->getContactName());
|
||||
updateState();
|
||||
setStatus(p_contact->getStatus());
|
||||
statusIcon = m_ui->statusIcon;
|
||||
statusLabel = m_ui->statusLabel;
|
||||
|
||||
connect(contact, SIGNAL(childChanged(Models::Item*, int, int)), this, SLOT(onContactChanged(Models::Item*, int, int)));
|
||||
connect(&ker, SIGNAL(enterPressed()), 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()));
|
||||
|
||||
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();
|
||||
m_ui->scrollArea->setWidget(line);
|
||||
@ -106,43 +100,14 @@ void Conversation::setName(const QString& 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
|
||||
{
|
||||
return contact->getAccountName();
|
||||
return account;
|
||||
}
|
||||
|
||||
QString Conversation::getJid() const
|
||||
{
|
||||
return contact->getJid();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
return palJid;
|
||||
}
|
||||
|
||||
void Conversation::addMessage(const Shared::Message& data)
|
||||
@ -207,12 +172,11 @@ void Conversation::onEnterPressed()
|
||||
QString body(m_ui->messageEditor->toPlainText());
|
||||
|
||||
if (body.size() > 0) {
|
||||
const QString& aJid = contact->getAccountJid();
|
||||
m_ui->messageEditor->clear();
|
||||
Shared::Message msg(Shared::Message::chat);
|
||||
msg.setFromJid(aJid);
|
||||
msg.setFromResource(contact->getAccountResource());
|
||||
msg.setToJid(contact->getJid());
|
||||
msg.setFromJid(myJid);
|
||||
msg.setFromResource(myResource);
|
||||
msg.setToJid(palJid);
|
||||
msg.setToResource(activePalResource);
|
||||
msg.setBody(body);
|
||||
msg.setOutgoing(true);
|
@ -21,8 +21,7 @@
|
||||
|
||||
#include <QWidget>
|
||||
#include <QScopedPointer>
|
||||
#include "../global.h"
|
||||
#include "models/contact.h"
|
||||
#include "../../global.h"
|
||||
#include "messageline.h"
|
||||
|
||||
namespace Ui
|
||||
@ -47,7 +46,7 @@ class Conversation : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
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();
|
||||
|
||||
QString getJid() const;
|
||||
@ -65,31 +64,33 @@ signals:
|
||||
void shown();
|
||||
|
||||
protected:
|
||||
void updateState();
|
||||
void setStatus(const QString& status);
|
||||
void setName(const QString& name);
|
||||
void applyVisualEffects();
|
||||
|
||||
protected slots:
|
||||
void onContactChanged(Models::Item* item, int row, int col);
|
||||
void onEnterPressed();
|
||||
void onMessagesResize(int amount);
|
||||
void onSliderValueChanged(int value);
|
||||
void onAttach();
|
||||
void onFileSelected();
|
||||
|
||||
private:
|
||||
protected:
|
||||
enum Scroll {
|
||||
nothing,
|
||||
keep,
|
||||
down
|
||||
};
|
||||
Models::Contact* contact;
|
||||
QString myJid;
|
||||
QString myResource;
|
||||
QString palJid;
|
||||
QString activePalResource;
|
||||
QString account;
|
||||
MessageLine* line;
|
||||
QScopedPointer<Ui::Conversation> m_ui;
|
||||
KeyEnterReceiver ker;
|
||||
QString activePalResource;
|
||||
QString thread;
|
||||
QLabel* statusIcon;
|
||||
QLabel* statusLabel;
|
||||
Scroll scroll;
|
||||
bool manualSliderChange;
|
||||
bool requestingHistory;
|
Loading…
Reference in New Issue
Block a user