qTox
Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
|
Go to the documentation of this file.
24 #include <QCloseEvent>
25 #include <QDragEnterEvent>
26 #include <QGuiApplication>
49 static const int minWidget = 220;
50 static const int minHeight = 220;
51 static const QSize minSize(minHeight, minWidget);
52 static const QSize defaultSize(720, 400);
56 , splitter{
new QSplitter(
this)}
58 , activeChatroomWidget(
nullptr)
59 , videoSurfaceSize(QSize())
64 friendLayout->setMargin(0);
65 friendLayout->setSpacing(0);
67 layouts = {friendLayout->getLayoutOnline(), groupLayout.getLayout(),
68 friendLayout->getLayoutOffline()};
71 #if (QT_VERSION >= QT_VERSION_CHECK(5, 13, 0))
72 layouts.swapItemsAt(0, 1);
78 QWidget* friendWidget =
new QWidget();
79 friendWidget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
80 friendWidget->setAutoFillBackground(
true);
81 friendWidget->setLayout(friendLayout);
85 friendScroll =
new QScrollArea(
this);
86 friendScroll->setMinimumWidth(minWidget);
87 friendScroll->setFrameStyle(QFrame::NoFrame);
88 friendScroll->setLayoutDirection(Qt::RightToLeft);
89 friendScroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
90 friendScroll->setWidgetResizable(
true);
91 friendScroll->setWidget(friendWidget);
93 QWidget* contentWidget =
new QWidget(
this);
94 contentWidget->setAutoFillBackground(
true);
97 contentLayout->setMargin(0);
98 contentLayout->setSpacing(0);
100 splitter->addWidget(friendScroll);
101 splitter->addWidget(contentWidget);
102 splitter->setStretchFactor(1, 1);
103 splitter->setCollapsible(1,
false);
105 QVBoxLayout* boxLayout =
new QVBoxLayout(
this);
106 boxLayout->setMargin(0);
107 boxLayout->setSpacing(0);
108 boxLayout->addWidget(splitter);
110 setMinimumSize(minSize);
111 setAttribute(Qt::WA_DeleteOnClose);
112 setObjectName(
"detached");
116 if (!geometry.isNull()) {
117 restoreGeometry(geometry);
125 username = core.getUsername();
127 setAcceptDrops(
true);
131 new QShortcut(Qt::CTRL + Qt::Key_Q,
this, SLOT(close()));
132 new QShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_Tab,
this, SLOT(previousContact()));
133 new QShortcut(Qt::CTRL + Qt::Key_Tab,
this, SLOT(nextContact()));
134 new QShortcut(Qt::CTRL + Qt::Key_PageUp,
this, SLOT(previousContact()));
135 new QShortcut(Qt::CTRL + Qt::Key_PageDown,
this, SLOT(nextContact()));
157 auto frnd = chatroom->getFriend();
158 const auto& friendPk = frnd->getPublicKey();
159 auto friendWidget =
new FriendWidget(chatroom, compact);
171 emit friendWidget->chatroomWidgetClicked(friendWidget);
178 const auto g = chatroom->
getGroup();
181 auto groupWidget =
new GroupWidget(chatroom, compact);
189 emit groupWidget->chatroomWidgetClicked(groupWidget);
196 auto chatroomWidget = qobject_cast<FriendWidget*>(
contactWidgets[friendPk]);
208 chatroomWidget->deleteLater();
225 auto chatroomWidget = qobject_cast<GroupWidget*>(
contactWidgets[groupId]);
232 chatroomWidget->deleteLater();
306 QLayout* currentLayout;
308 if (!currentLayout || index == -1) {
312 if (!inverse && index == currentLayout->count() - 1) {
320 bool nextIsEmpty = (isCurOnline && offlineEmpty && (groupsEmpty || groupsOnTop))
321 || (isCurGroup && offlineEmpty && (onlineEmpty || !groupsOnTop))
329 index += forward ? 1 : -1;
332 while (index < 0 || index >= currentLayout->count()) {
333 int oldCount = currentLayout->count();
334 currentLayout =
nextLayout(currentLayout, forward);
335 int newCount = currentLayout->count();
337 index = newCount - 1;
338 }
else if (index >= oldCount) {
343 QWidget* widget = currentLayout->itemAt(index)->widget();
359 QSize minSize = minimumSize();
370 QSize minSize = minimumSize();
390 setWindowIcon(QIcon(
":/img/group.svg"));
405 if (newGroupOnTop != oldGroupOnTop) {
407 #if (QT_VERSION >= QT_VERSION_CHECK(5, 13, 0))
446 switch (
event->type()) {
447 case QEvent::WindowActivate:
474 QObject* o =
event->source();
476 GroupWidget* group = qobject_cast<GroupWidget*>(o);
478 assert(
event->mimeData()->hasFormat(
"toxPk"));
479 ToxPk toxPk{
event->mimeData()->data(
"toxPk")};
485 ToxPk friendId = contact->getPublicKey();
489 event->acceptProposedAction();
492 assert(
event->mimeData()->hasFormat(
"groupId"));
500 event->acceptProposedAction();
507 QObject* o =
event->source();
509 GroupWidget* group = qobject_cast<GroupWidget*>(o);
511 assert(
event->mimeData()->hasFormat(
"toxPk"));
512 const ToxPk toxId(
event->mimeData()->data(
"toxPk"));
521 assert(
event->mimeData()->hasFormat(
"groupId"));
522 const GroupId groupId(
event->mimeData()->data(
"groupId"));
535 QWidget::changeEvent(
event);
536 if (
event->type() == QEvent::ActivationChange) {
537 if (isActiveWindow()) {
546 QDialog::resizeEvent(
event);
552 QDialog::moveEvent(
event);
558 if (
event->key() != Qt::Key_Escape) {
559 QDialog::keyPressEvent(
event);
570 auto it = list.find(
id);
571 if (it == list.end()) {
607 auto widget = qobject_cast<FriendWidget*>(
contactWidgets.value(friendPk));
614 if (widget !=
nullptr) {
615 widget->updateStatusLight();
622 if (widget ==
nullptr) {
626 return widget->isActive();
633 if (widget !=
nullptr) {
701 int index =
layouts.indexOf(layout);
706 int next = forward ? index + 1 : index - 1;
708 next = (next + size) % size;
QLayout * nextLayout(QLayout *layout, bool forward) const
Find the next or previous layout in layout list.
void updateContactStatusLight(const ContactId &contactId)
void saveSplitterState()
Save state of splitter between dialog and dialog list.
void nextContact()
Enable next contact.
bool isContactActive(const ContactId &contactId) const override
void removeSortedWidget(GenericChatItemWidget *widget)
void dropEvent(QDropEvent *event) final
QList< QLayout * > layouts
void onVideoShow(QSize size)
void addFriendWidget(FriendWidget *widget, Status::Status s)
int friendTotalCount() const
void removeGroup(const GroupId &groupId) override
void resizeEvent(QResizeEvent *event) override
int chatroomCount() const override
static void unregister(void *owner)
Unregisters all handlers of an owner.
QByteArray getDialogSplitterState() const
void removeFriendWidget(FriendWidget *widget, Status::Status s)
QString getIconPath(Status status, bool event)
void changeEvent(QEvent *event) override
int indexOfFriendWidget(GenericChatItemWidget *widget, bool online) const
void updateFriendStatus(const ToxPk &friendPk, Status::Status status)
static Friend * findFriend(const ToxPk &friendPk)
QLayout * getLayout() const
void addFriendWidget(FriendWidget *widget, Status::Status status)
void reorderLayouts(bool newGroupOnTop)
Update layouts order according to settings.
Status::Status getStatus() const
GenericChatroomWidget * activeChatroomWidget
FriendListLayout * friendLayout
void retranslateUi()
Retranslate all elements in the form.
void ensureSplitterVisible()
void setDialogGeometry(const QByteArray &value)
void friendDialogShown(const Friend *f)
void statusMessageChanged(const ToxPk &friendId, const QString &message)
bool isActiveWidget(GenericChatroomWidget *widget)
void setUsername(const QString &newName)
Update username to show in the title.
void aliasChanged(const ToxPk &friendId, QString alias)
void updateTitleAndStatusIcon()
Update window title and icon.
QByteArray getDialogGeometry() const
bool getGroupchatPosition() const
This class represents a Tox Public Key, which is a part of Tox ID.
QLayout * getLayoutOnline() const
void reloadTheme() override
int getCurrentLayout(QLayout *&layout)
Get current layout and index of current wiget in it. Current layout – layout contains activated widge...
void moveEvent(QMoveEvent *event) override
void keyPressEvent(QKeyEvent *event) override
void addFriendDialog(Friend *frnd, ContentDialog *contentDialog)
void updateFriendWidget(const ToxPk &friendPk, QString alias)
Update friend widget name and position.
void onGroupchatPositionChanged(bool top)
Handler of groupchatPositionChanged action. Move group layout on the top or on the buttom.
const GroupId & getPersistentId() const override
void connectFriendWidget(FriendWidget &friendWidget)
void cycleContacts(bool forward, bool loop=true)
Activate next/previous contact.
void focusContact(const ContactId &friendPk)
static void registerHandler(const std::function< void()> &, void *owner)
Register a function to be called when the UI needs to be retranslated.
void setStatusMessage(const ToxPk &friendPk, const QString &message)
QScrollArea * friendScroll
static Settings & getInstance()
Returns the singleton instance.
void dragEnterEvent(QDragEnterEvent *event) final
GenericChatItemLayout groupLayout
ContentLayout * contentLayout
This class represents a long term persistent group identifier.
GroupWidget * addGroup(std::shared_ptr< GroupChatroom > chatroom, GenericChatForm *form)
QLayout * getLayoutOffline() const
void groupchatPositionChanged(bool enabled)
void groupDialogShown(Group *g)
QHash< const ContactId &, GenericChatroomWidget * > contactWidgets
QHash< const ContactId &, GenericChatForm * > contactChatForms
void closeEvent(QCloseEvent *event) override
static const QString getStylesheet(const QString &filename, const QFont &baseFont=QFont())
bool event(QEvent *event) override
void removeFriend(const ToxPk &friendPk) override
void focusCommon(const ContactId &id, QHash< const ContactId &, GenericChatroomWidget * > list)
static Group * findGroup(const GroupId &groupId)
bool event(QEvent *event) final
~ContentDialog() override
void addGroupDialog(Group *group, ContentDialog *contentDialog)
void activate(GenericChatroomWidget *widget)
Show ContentDialog, activate chatroom widget.
void setDialogSplitterState(const QByteArray &value)
FriendWidget * addFriend(std::shared_ptr< FriendChatroom > chatroom, GenericChatForm *form)
Restore splitter from saved state and reset to default.
void saveDialogGeometry()
Save size of dialog window.
int indexOfSortedWidget(GenericChatItemWidget *widget) const
void addSortedWidget(GenericChatItemWidget *widget, int stretch=0, Qt::Alignment alignment=Qt::Alignment())
bool hasContact(const ContactId &contactId) const override
ContentDialog(const Core &core, QWidget *parent=nullptr)