qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
genericchatform.h
Go to the documentation of this file.
1 /*
2  Copyright © 2014-2019 by The qTox Project Contributors
3 
4  This file is part of qTox, a Qt-based graphical interface for Tox.
5 
6  qTox is libre software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  qTox is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with qTox. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
23 #include "src/core/toxpk.h"
24 #include "src/model/ichatlog.h"
25 #include "src/widget/searchtypes.h"
26 
27 #include <QMenu>
28 #include <QWidget>
29 
36 class ChatFormHeader;
37 class ChatWidget;
38 class ChatTextEdit;
39 class Contact;
40 class ContentLayout;
41 class CroppingLabel;
43 class GenericNetCamView;
45 class SearchForm;
46 class Widget;
47 
48 class QLabel;
49 class QPushButton;
50 class QSplitter;
51 class QToolButton;
52 class QVBoxLayout;
53 
54 class IMessageDispatcher;
55 struct Message;
56 
57 namespace Ui {
58 class MainWindow;
59 }
60 
61 #ifdef SPELL_CHECKING
62 namespace Sonnet {
63 class SpellCheckDecorator;
64 }
65 #endif
66 
67 class GenericChatForm : public QWidget
68 {
69  Q_OBJECT
70 public:
71  GenericChatForm(const Core& _core, const Contact* contact, IChatLog& chatLog,
72  IMessageDispatcher& messageDispatcher, QWidget* parent = nullptr);
73  ~GenericChatForm() override;
74 
75  void setName(const QString& newName);
76  virtual void show(ContentLayout* contentLayout);
77 
78  void addSystemInfoMessage(const QDateTime& datetime, SystemMessageType messageType,
79  SystemMessage::Args messageArgs);
80  static QString resolveToxPk(const ToxPk& pk);
81  QDateTime getLatestTime() const;
82 
83 signals:
84  void messageInserted();
85 
86 public slots:
87  void focusInput();
88  void onChatMessageFontChanged(const QFont& font);
89  void setColorizedNames(bool enable);
90  virtual void reloadTheme();
91 
92 protected slots:
93  void onChatContextMenuRequested(QPoint pos);
94  virtual void onScreenshotClicked() = 0;
95  void onSendTriggered();
96  virtual void onAttachClicked() = 0;
97  void onEmoteButtonClicked();
98  void onEmoteInsertRequested(QString str);
99  void onCopyLogClicked();
100  void clearChatArea();
101  void clearChatArea(bool confirm, bool inform);
102  void onSelectAllClicked();
103  void showFileMenu();
104  void hideFileMenu();
105  void quoteSelectedText();
106  void copyLink();
107  void onLoadHistory();
108  void onExportChat();
109  void searchFormShow();
110  void updateShowDateInfo(const ChatLine::Ptr& prevLine, const ChatLine::Ptr& topLine);
111  void goToCurrentDate();
112 
113 private:
114  void retranslateUi();
115  void addSystemDateMessage(const QDate& date);
116  QDateTime getTime(const ChatLine::Ptr& chatLine) const;
117 
118 protected:
119  ChatMessage::Ptr createMessage(const ToxPk& author, const QString& message,
120  const QDateTime& datetime, bool isAction, bool isSent, bool colorizeName = false);
121  void adjustFileMenuPosition();
122  void hideEvent(QHideEvent* event) override;
123  void showEvent(QShowEvent*) override;
124  bool event(QEvent*) final;
125  void resizeEvent(QResizeEvent* event) final;
126  bool eventFilter(QObject* object, QEvent* event) final;
127  bool searchInText(const QString& phrase, const ParameterSearch& parameter, SearchDirection direction);
128  std::pair<int, int> indexForSearchInLine(const QString& txt, const QString& phrase, const ParameterSearch& parameter, SearchDirection direction);
129 
130 protected:
131  const Core& core;
134  int curRow;
135 
136  QAction* clearAction;
137  QAction* quoteAction;
138  QAction* copyLinkAction;
139  QAction* searchAction;
143 
144  QMenu menu;
145 
146  QVBoxLayout* contentLayout;
147  QPushButton* emoteButton;
148  QPushButton* fileButton;
149  QPushButton* screenshotButton;
150  QPushButton* sendButton;
151 
152  QSplitter* bodySplitter;
153 
155 
157  QLabel *dateInfo;
160 #ifdef SPELL_CHECKING
161  Sonnet::SpellCheckDecorator* decorator{nullptr};
162 #endif
165 
168 };
GenericChatForm::quoteSelectedText
void quoteSelectedText()
Definition: genericchatform.cpp:613
GenericChatForm::fileFlyout
FlyoutOverlayWidget * fileFlyout
Definition: genericchatform.h:163
GenericChatForm::audioOutputFlag
bool audioOutputFlag
Definition: genericchatform.h:133
GenericChatForm::showFileMenu
void showFileMenu()
Definition: genericchatform.cpp:288
SearchDirection
SearchDirection
Definition: searchtypes.h:42
GenericChatForm
Parent class for all chatforms. It's provide the minimum required UI elements and methods to work wit...
Definition: genericchatform.h:67
GenericChatForm::onScreenshotClicked
virtual void onScreenshotClicked()=0
GenericChatForm::bodySplitter
QSplitter * bodySplitter
Definition: genericchatform.h:152
GenericChatForm::goToCurrentDateAction
QAction * goToCurrentDateAction
Definition: genericchatform.h:140
GenericChatForm::createMessage
ChatMessage::Ptr createMessage(const ToxPk &author, const QString &message, const QDateTime &datetime, bool isAction, bool isSent, bool colorizeName=false)
ichatlog.h
GenericChatForm::exportChatAction
QAction * exportChatAction
Definition: genericchatform.h:142
GenericChatForm::setName
void setName(const QString &newName)
Definition: genericchatform.cpp:359
GenericChatForm::dateInfo
QLabel * dateInfo
Definition: genericchatform.h:157
SystemMessageType
SystemMessageType
Definition: systemmessage.h:28
GenericChatForm::clearChatArea
void clearChatArea()
Definition: genericchatform.cpp:526
CroppingLabel
Definition: croppinglabel.h:26
GenericChatForm::focusInput
void focusInput()
Definition: genericchatform.cpp:480
GenericChatForm::curRow
int curRow
Definition: genericchatform.h:134
ParameterSearch
Definition: searchtypes.h:47
GenericChatForm::indexForSearchInLine
std::pair< int, int > indexForSearchInLine(const QString &txt, const QString &phrase, const ParameterSearch &parameter, SearchDirection direction)
GenericChatForm::headWidget
ChatFormHeader * headWidget
Definition: genericchatform.h:154
ChatMessage::Ptr
std::shared_ptr< ChatMessage > Ptr
Definition: chatmessage.h:34
GenericChatForm::resolveToxPk
static QString resolveToxPk(const ToxPk &pk)
Searches for name (possibly alias) of someone with specified public key among all of your friends or ...
Definition: genericchatform.cpp:96
searchtypes.h
GenericChatForm::setColorizedNames
void setColorizedNames(bool enable)
Definition: genericchatform.cpp:495
GenericChatForm::chatLog
IChatLog & chatLog
Definition: genericchatform.h:166
ChatWidget
Definition: chatwidget.h:41
GenericChatForm::emoteButton
QPushButton * emoteButton
Definition: genericchatform.h:147
GenericChatForm::onLoadHistory
void onLoadHistory()
Definition: genericchatform.cpp:650
GenericChatForm::searchAction
QAction * searchAction
Definition: genericchatform.h:139
SystemMessage::Args
std::array< QString, 4 > Args
Definition: systemmessage.h:49
toxpk.h
IMessageDispatcher
Definition: imessagedispatcher.h:34
GenericChatForm::clearAction
QAction * clearAction
Definition: genericchatform.h:136
GenericChatForm::getLatestTime
QDateTime getLatestTime() const
Definition: genericchatform.cpp:303
GenericChatForm::onAttachClicked
virtual void onAttachClicked()=0
IChatLog
Definition: ichatlog.h:83
GenericChatForm::onEmoteButtonClicked
void onEmoteButtonClicked()
Definition: genericchatform.cpp:447
GenericChatForm::~GenericChatForm
~GenericChatForm() override
Definition: genericchatform.cpp:275
GenericChatForm::event
bool event(QEvent *) final
Definition: genericchatform.cpp:387
GenericChatForm::screenshotButton
QPushButton * screenshotButton
Definition: genericchatform.h:149
GenericChatForm::showEvent
void showEvent(QShowEvent *) override
Definition: genericchatform.cpp:381
Ui
Definition: filetransferwidget.h:30
HistMessageContentType::message
@ message
MaskablePixmapWidget
Definition: maskablepixmapwidget.h:24
ToxPk
This class represents a Tox Public Key, which is a part of Tox ID.
Definition: toxpk.h:26
GenericChatForm::onSelectAllClicked
void onSelectAllClicked()
Definition: genericchatform.cpp:549
Contact
Definition: contact.h:26
GenericChatForm::onSendTriggered
void onSendTriggered()
Definition: genericchatform.cpp:427
GenericChatForm::parent
Widget * parent
Definition: genericchatform.h:164
GenericChatForm::quoteAction
QAction * quoteAction
Definition: genericchatform.h:137
GenericChatForm::contentLayout
QVBoxLayout * contentLayout
Definition: genericchatform.h:146
GenericChatForm::messageInserted
void messageInserted()
GenericChatForm::hideEvent
void hideEvent(QHideEvent *event) override
Definition: genericchatform.cpp:554
GenericChatForm::searchForm
SearchForm * searchForm
Definition: genericchatform.h:156
GenericChatForm::reloadTheme
virtual void reloadTheme()
Definition: genericchatform.cpp:346
GenericChatForm::loadHistoryAction
QAction * loadHistoryAction
Definition: genericchatform.h:141
GenericChatForm::show
virtual void show(ContentLayout *contentLayout)
Definition: genericchatform.cpp:364
GenericChatForm::goToCurrentDate
void goToCurrentDate()
Definition: genericchatform.cpp:689
GenericChatForm::addSystemDateMessage
void addSystemDateMessage(const QDate &date)
GenericChatForm::onChatContextMenuRequested
void onChatContextMenuRequested(QPoint pos)
Definition: genericchatform.cpp:406
ChatTextEdit
Definition: chattextedit.h:24
GenericChatForm::GenericChatForm
GenericChatForm(const Core &_core, const Contact *contact, IChatLog &chatLog, IMessageDispatcher &messageDispatcher, QWidget *parent=nullptr)
Definition: genericchatform.cpp:137
GenericChatForm::searchInText
bool searchInText(const QString &phrase, const ParameterSearch &parameter, SearchDirection direction)
GenericChatForm::msgEdit
ChatTextEdit * msgEdit
Definition: genericchatform.h:159
GenericChatForm::sendButton
QPushButton * sendButton
Definition: genericchatform.h:150
GenericChatForm::onExportChat
void onExportChat()
Definition: genericchatform.cpp:658
GenericChatForm::updateShowDateInfo
void updateShowDateInfo(const ChatLine::Ptr &prevLine, const ChatLine::Ptr &topLine)
Definition: genericchatform.cpp:694
GenericChatForm::hideFileMenu
void hideFileMenu()
Definition: genericchatform.cpp:297
ContentLayout
Definition: contentlayout.h:25
GenericChatForm::audioInputFlag
bool audioInputFlag
Definition: genericchatform.h:132
GenericChatForm::menu
QMenu menu
Definition: genericchatform.h:144
chatmessage.h
GenericChatForm::resizeEvent
void resizeEvent(QResizeEvent *event) final
Definition: genericchatform.cpp:560
FlyoutOverlayWidget
Definition: flyoutoverlaywidget.h:27
GenericChatForm::adjustFileMenuPosition
void adjustFileMenuPosition()
Definition: genericchatform.cpp:281
GenericChatForm::onChatMessageFontChanged
void onChatMessageFontChanged(const QFont &font)
Definition: genericchatform.cpp:485
GenericChatForm::getTime
QDateTime getTime(const ChatLine::Ptr &chatLine) const
Definition: genericchatform.cpp:510
GenericChatForm::copyLinkAction
QAction * copyLinkAction
Definition: genericchatform.h:138
GenericChatForm::searchFormShow
void searchFormShow()
Definition: genericchatform.cpp:642
ChatFormHeader
Definition: chatformheader.h:38
SearchForm
Definition: searchform.h:31
GenericChatForm::retranslateUi
void retranslateUi()
Definition: genericchatform.cpp:712
GenericChatForm::fileButton
QPushButton * fileButton
Definition: genericchatform.h:148
GenericChatForm::core
const Core & core
Definition: genericchatform.h:131
GenericChatForm::chatWidget
ChatWidget * chatWidget
Definition: genericchatform.h:158
GenericChatForm::messageDispatcher
IMessageDispatcher & messageDispatcher
Definition: genericchatform.h:167
ChatLine::Ptr
std::shared_ptr< ChatLine > Ptr
Definition: chatline.h:68
GenericChatForm::addSystemInfoMessage
void addSystemInfoMessage(const QDateTime &datetime, SystemMessageType messageType, SystemMessage::Args messageArgs)
Definition: genericchatform.cpp:500
Message
Definition: message.h:52
GenericChatForm::onEmoteInsertRequested
void onEmoteInsertRequested(QString str)
Definition: genericchatform.cpp:465
Core
Definition: core.h:59
Widget
Definition: widget.h:87
GenericChatForm::copyLink
void copyLink()
Callback of GenericChatForm::copyLinkAction.
Definition: genericchatform.cpp:636
GenericChatForm::onCopyLogClicked
void onCopyLogClicked()
Definition: genericchatform.cpp:475
GenericChatForm::eventFilter
bool eventFilter(QObject *object, QEvent *event) final
Definition: genericchatform.cpp:566