squawk/ui/widgets/conversation.h

166 lines
4.7 KiB
C
Raw Normal View History

2019-04-08 21:40:49 +00:00
/*
* Squawk messenger.
2019-04-08 21:40:49 +00:00
* 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 CONVERSATION_H
#define CONVERSATION_H
#include <QWidget>
#include <QScopedPointer>
#include <QMap>
#include <QMimeData>
#include <QFileInfo>
#include <QGraphicsOpacityEffect>
#include <QMenu>
#include <QAction>
#include <QDesktopServices>
#include "shared/message.h"
2021-05-11 17:29:08 +00:00
#include "shared/order.h"
#include "shared/icons.h"
#include "shared/utils.h"
#include "shared/pathcheck.h"
2023-08-15 15:28:25 +00:00
#include "shared/defines.h"
#include "ui/models/account.h"
2020-04-11 20:00:15 +00:00
#include "ui/models/roster.h"
#include "ui/utils/flowlayout.h"
#include "ui/utils/badge.h"
#include "ui/utils/shadowoverlay.h"
#include "ui/widgets/messageline/feedview.h"
#include "ui/widgets/messageline/messagedelegate.h"
2019-04-08 21:40:49 +00:00
namespace Ui
{
class Conversation;
}
2019-04-09 22:01:25 +00:00
class KeyEnterReceiver : public QObject
{
Q_OBJECT
2019-04-10 15:22:52 +00:00
public:
KeyEnterReceiver(QObject* parent = 0);
2019-04-09 22:01:25 +00:00
protected:
2019-04-10 15:22:52 +00:00
bool ownEvent;
2019-04-09 22:01:25 +00:00
bool eventFilter(QObject* obj, QEvent* event);
signals:
void enterPressed();
2021-10-06 15:09:18 +00:00
void imagePasted();
2019-04-09 22:01:25 +00:00
};
2019-04-08 21:40:49 +00:00
class Conversation : public QWidget
{
Q_OBJECT
2019-04-09 15:04:08 +00:00
public:
2020-08-12 16:55:01 +00:00
Conversation(bool muc, Models::Account* acc, Models::Element* el, const QString pJid, const QString pRes, QWidget* parent = 0);
2019-04-09 15:04:08 +00:00
~Conversation();
QString getJid() const;
QString getAccount() const;
2019-04-12 15:22:10 +00:00
QString getPalResource() const;
2020-04-11 20:00:15 +00:00
Models::Roster::ElId getId() const;
2019-04-09 15:04:08 +00:00
2019-04-12 15:22:10 +00:00
void setPalResource(const QString& res);
2019-12-23 06:28:23 +00:00
virtual void setAvatar(const QString& path);
2020-04-11 20:00:15 +00:00
void setFeedFrames(bool top, bool right, bool bottom, bool left);
2021-10-06 15:09:18 +00:00
static bool checkClipboardImage();
2019-04-12 15:22:10 +00:00
2019-04-10 20:53:42 +00:00
signals:
void sendMessage(const Shared::Message& message);
2022-03-28 20:25:33 +00:00
void replaceMessage(const QString& originalId, const Shared::Message& message);
void resendMessage(const QString& id);
void requestArchive(const QString& before);
void shown();
void requestLocalFile(const QString& messageId, const QString& url);
void downloadFile(const QString& messageId, const QString& url);
void notifyableMessage(const QString& account, const Shared::Message& msg);
2019-04-10 20:53:42 +00:00
2019-04-09 15:04:08 +00:00
protected:
2019-08-28 11:40:55 +00:00
virtual void setName(const QString& name);
2020-04-15 13:48:49 +00:00
virtual Shared::Message createMessage() const;
void setStatus(const QString& status);
void addAttachedFile(const QString& path);
void removeAttachedFile(Badge* badge);
void clearAttachedFiles();
void dragEnterEvent(QDragEnterEvent* event) override;
void dragLeaveEvent(QDragLeaveEvent* event) override;
void dropEvent(QDropEvent* event) override;
void initializeOverlay();
virtual void onMessage(const Shared::Message& msg);
virtual void showEvent(QShowEvent * event) override;
2019-04-09 15:04:08 +00:00
protected slots:
2022-03-28 20:25:33 +00:00
void initiateMessageSending();
void initiateMessageSending(const Shared::Message& msg);
2021-10-06 15:09:18 +00:00
void onImagePasted();
void onAttach();
void onFileSelected();
void onBadgeClose();
2022-03-28 20:25:33 +00:00
void clear();
void onTextEditDocSizeChanged(const QSizeF& size);
2020-08-07 23:33:03 +00:00
void onAccountChanged(Models::Item* item, int row, int col);
void onFeedMessage(const Shared::Message& msg);
void positionShadow();
void onFeedContext(const QPoint &pos);
void onMessageEditorContext(const QPoint &pos);
void onMessageEditRequested(const QString& id);
2019-04-09 15:04:08 +00:00
public:
const bool isMuc;
protected:
enum class CurrentAction {
none,
edit
};
Models::Account* account;
2020-08-12 16:55:01 +00:00
Models::Element* element;
QString palJid;
QString activePalResource;
2019-04-08 21:40:49 +00:00
QScopedPointer<Ui::Conversation> m_ui;
2019-04-09 22:01:25 +00:00
KeyEnterReceiver ker;
2019-04-12 15:22:10 +00:00
QString thread;
QLabel* statusIcon;
QLabel* statusLabel;
FlowLayout* filesLayout;
QWidget* overlay;
W::Order<Badge*, Badge::Comparator> filesToAttach;
FeedView* feed;
2020-08-20 21:32:30 +00:00
MessageDelegate* delegate;
bool manualSliderChange;
bool tsb; //transient scroll bars
2021-10-06 15:09:18 +00:00
QAction* pasteImageAction;
ShadowOverlay shadow;
QMenu* contextMenu;
CurrentAction currentAction;
2022-03-28 20:25:33 +00:00
QString currentMessageId;
private:
static bool painterInitialized;
static QPainterPath* avatarMask;
static QPixmap* avatarPixmap;
static QPainter* avatarPainter;
2019-04-08 21:40:49 +00:00
};
#endif // CONVERSATION_H