1
0
forked from blue/squawk
squawk/ui/widgets/conversation.h

164 lines
4.7 KiB
C
Raw Normal View History

2019-04-09 00:40:49 +03:00
/*
* Squawk messenger.
2019-04-09 00:40:49 +03: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/>.
*/
#pragma once
2019-04-09 00:40:49 +03:00
#include <QWidget>
#include <QObject>
2019-04-09 00:40:49 +03:00
#include <QScopedPointer>
#include <QMap>
#include <QMimeData>
#include <QFileInfo>
#include <QGraphicsOpacityEffect>
#include <QMenu>
#include <QAction>
#include <QDesktopServices>
#include <vector>
#include "shared/message.h"
#include "ui/models/account.h"
2020-04-11 23:00:15 +03: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-09 00:40:49 +03:00
2023-11-04 22:12:15 -03:00
namespace Ui {
2019-04-09 00:40:49 +03:00
class Conversation;
}
2023-11-04 22:12:15 -03:00
class KeyEnterReceiver : public QObject {
2019-04-10 01:01:25 +03:00
Q_OBJECT
2019-04-10 18:22:52 +03:00
public:
KeyEnterReceiver(QObject* parent = 0);
2019-04-10 01:01:25 +03:00
protected:
2019-04-10 18:22:52 +03:00
bool ownEvent;
2019-04-10 01:01:25 +03:00
bool eventFilter(QObject* obj, QEvent* event);
signals:
void enterPressed();
2021-10-06 23:09:18 +08:00
void imagePasted();
2019-04-10 01:01:25 +03:00
};
2023-11-04 22:12:15 -03:00
class Conversation : public QWidget {
2019-04-09 00:40:49 +03:00
Q_OBJECT
2019-04-09 18:04:08 +03:00
public:
2020-08-12 19:55:01 +03:00
Conversation(bool muc, Models::Account* acc, Models::Element* el, const QString pJid, const QString pRes, QWidget* parent = 0);
2019-04-09 18:04:08 +03:00
~Conversation();
QString getJid() const;
QString getAccount() const;
2019-04-12 18:22:10 +03:00
QString getPalResource() const;
2020-04-11 23:00:15 +03:00
Models::Roster::ElId getId() const;
2019-04-09 18:04:08 +03:00
2019-04-12 18:22:10 +03:00
void setPalResource(const QString& res);
2019-12-23 09:28:23 +03:00
virtual void setAvatar(const QString& path);
2020-04-11 23:00:15 +03:00
void setFeedFrames(bool top, bool right, bool bottom, bool left);
2021-10-06 23:09:18 +08:00
static bool checkClipboardImage();
2019-04-12 18:22:10 +03:00
2019-04-10 23:53:42 +03:00
signals:
void sendMessage(const Shared::Message& message);
2022-03-28 23:25:33 +03: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);
2023-11-04 22:12:15 -03:00
void setEncryption(Shared::EncryptionProtocol value);
2019-04-10 23:53:42 +03:00
2019-04-09 18:04:08 +03:00
protected:
2019-08-28 14:40:55 +03:00
virtual void setName(const QString& name);
2020-04-15 16:48:49 +03:00
virtual Shared::Message createMessage() const;
void setStatus(const QString& status);
void addAttachedFile(const QString& path);
void removeAttachedFile(const QString& id);
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;
void createFeed();
void createUI();
void subscribeEvents();
2019-04-09 18:04:08 +03:00
protected slots:
2022-03-28 23:25:33 +03:00
void initiateMessageSending();
void initiateMessageSending(const Shared::Message& msg);
2021-10-06 23:09:18 +08:00
void onImagePasted();
void onAttach();
void onFileSelected();
void onBadgeClose();
2022-03-28 23:25:33 +03:00
void clear();
void onTextEditDocSizeChanged(const QSizeF& size);
2020-08-08 02:33:03 +03: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);
virtual void onEncryptionButtonClicked();
2019-04-09 18:04:08 +03:00
public:
const bool isMuc;
protected:
enum class CurrentAction {
none,
edit
};
Models::Account* account;
2020-08-12 19:55:01 +03:00
Models::Element* element;
QString palJid;
QString activePalResource;
Ui::Conversation* m_ui;
2019-04-10 01:01:25 +03:00
KeyEnterReceiver ker;
2019-04-12 18:22:10 +03:00
QString thread;
QLabel* statusIcon;
QLabel* statusLabel;
FlowLayout* filesLayout;
QWidget* overlay;
std::vector<Badge*> filesToAttach;
FeedView* feed;
2020-08-21 00:32:30 +03:00
MessageDelegate* delegate;
bool manualSliderChange;
bool tsb; //transient scroll bars
2021-10-06 23:09:18 +08:00
QAction* pasteImageAction;
ShadowOverlay shadow;
QMenu* contextMenu;
CurrentAction currentAction;
2022-03-28 23:25:33 +03:00
QString currentMessageId;
private:
static bool painterInitialized;
static QPainterPath* avatarMask;
static QPixmap* avatarPixmap;
static QPainter* avatarPainter;
2019-04-09 00:40:49 +03:00
};