feat: create text particles in a stream
This commit is contained in:
+44
-1
@@ -6,23 +6,28 @@
|
||||
#include "authdialog.h"
|
||||
#include "authmanager.h"
|
||||
#include "settingsdialog.h"
|
||||
#include "textinputdialog.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include <QApplication>
|
||||
#include <QHeaderView>
|
||||
#include <QItemSelectionModel>
|
||||
#include <QLabel>
|
||||
#include <QMenu>
|
||||
#include <QKeyEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <QRandomGenerator>
|
||||
#include <QToolButton>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QTimer>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent), m_trayIcon(nullptr), m_authManager(new AuthManager(this)), m_settingsDialog(nullptr),
|
||||
m_authDialog(nullptr), m_store(nullptr), m_networkStreamModel(nullptr), m_particleListModel(nullptr),
|
||||
m_selectedParticleRow(-1), m_isDragging(false)
|
||||
m_selectedParticleRow(-1), m_isDragging(false), m_textInputDialog(nullptr)
|
||||
{
|
||||
m_authDialog = new AuthDialog(this);
|
||||
m_textInputDialog = new TextInputDialog(this);
|
||||
connect(m_textInputDialog, &TextInputDialog::textSubmitted, this, &MainWindow::onTextMessageSubmitted);
|
||||
|
||||
ui = new Ui::MainWindow;
|
||||
ui->setupUi(this);
|
||||
@@ -102,6 +107,9 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
ui->topLevelParticlesView->expandAll();
|
||||
});
|
||||
|
||||
// DocumentSend toolbar button opens text input dialog
|
||||
connect(ui->toolButton_3, &QToolButton::clicked, this, &MainWindow::showTextInputDialog);
|
||||
|
||||
m_authManager->tryRestoreSession();
|
||||
|
||||
setupTrayIcon();
|
||||
@@ -181,6 +189,9 @@ void MainWindow::setupModels()
|
||||
connect(ui->particlesView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
|
||||
&MainWindow::onParticleSelectionChanged);
|
||||
|
||||
// Install event filter to capture key presses from child views
|
||||
ui->topLevelParticlesView->installEventFilter(this);
|
||||
ui->particlesView->installEventFilter(this);
|
||||
}
|
||||
|
||||
void MainWindow::onTreeSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
|
||||
@@ -376,6 +387,38 @@ void MainWindow::updatePingIndicator()
|
||||
m_pingLabel->setText("connected " + QString::number(currentPing) + "ms");
|
||||
}
|
||||
|
||||
void MainWindow::showTextInputDialog()
|
||||
{
|
||||
if (m_selectedStreamId.isEmpty())
|
||||
return;
|
||||
|
||||
m_textInputDialog->show();
|
||||
m_textInputDialog->raise();
|
||||
m_textInputDialog->activateWindow();
|
||||
}
|
||||
|
||||
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::KeyPress)
|
||||
{
|
||||
auto *keyEvent = static_cast<QKeyEvent *>(event);
|
||||
if (keyEvent->key() == Qt::Key_T && keyEvent->modifiers() == Qt::NoModifier && !m_selectedStreamId.isEmpty())
|
||||
{
|
||||
showTextInputDialog();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return QMainWindow::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
void MainWindow::onTextMessageSubmitted(const QString &text)
|
||||
{
|
||||
if (m_selectedStreamId.isEmpty())
|
||||
return;
|
||||
|
||||
m_store->createParticle(m_selectedStreamId, "text", {{"content", text}});
|
||||
}
|
||||
|
||||
void MainWindow::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton)
|
||||
|
||||
Reference in New Issue
Block a user