jamulus/src/chatdlg.cpp

114 lines
3.9 KiB
C++
Raw Normal View History

2013-01-23 11:41:13 +01:00
/******************************************************************************\
2020-01-01 15:41:43 +01:00
* Copyright (c) 2004-2020
2013-01-23 11:41:13 +01:00
*
* Author(s):
* Volker Fischer
*
******************************************************************************
*
* 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 2 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, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
2013-01-23 11:41:13 +01:00
*
\******************************************************************************/
#include "chatdlg.h"
/* Implementation *************************************************************/
CChatDlg::CChatDlg ( QWidget* parent, Qt::WindowFlags f ) :
QDialog ( parent, f )
{
setupUi ( this );
// Add help text to controls -----------------------------------------------
// chat window
txvChatWindow->setWhatsThis ( "<b>" + tr ( "Chat Window" ) + ":</b> " + tr (
"The chat window shows a history of all chat messages." ) );
2013-01-23 11:41:13 +01:00
txvChatWindow->setAccessibleName ( tr ( "Chat history" ) );
// input message text
edtLocalInputText->setWhatsThis ( "<b>" + tr ( "Input Message Text" ) + ":</b> " + tr (
"Enter the chat message text in the edit box and press enter to send the "
2013-01-23 11:41:13 +01:00
"message to the server which distributes the message to all connected "
"clients. Your message will then show up in the chat window." ) );
edtLocalInputText->setAccessibleName ( tr ( "New chat text edit box" ) );
// clear chat window and edit line
txvChatWindow->clear();
edtLocalInputText->clear();
2020-06-21 14:45:11 +02:00
// we do not want to show a curser in the chat history
txvChatWindow->setCursorWidth ( 0 );
// set a placeholder text to make sure where to type the message in (#384)
edtLocalInputText->setPlaceholderText ( tr ( "Type a message here" ) );
2013-01-23 11:41:13 +01:00
2020-06-21 14:45:11 +02:00
// Menu -------------------------------------------------------------------
QMenuBar* pMenu = new QMenuBar ( this );
QMenu* pEditMenu = new QMenu ( tr ( "&Edit" ), this );
pEditMenu->addAction ( tr ( "Cl&ear Chat History" ), this,
SLOT ( OnClearChatHistory() ), QKeySequence ( Qt::CTRL + Qt::Key_E ) );
pMenu->addMenu ( pEditMenu );
// Now tell the layout about the menu
layout()->setMenuBar ( pMenu );
2013-01-23 11:41:13 +01:00
// Connections -------------------------------------------------------------
QObject::connect ( edtLocalInputText, &QLineEdit::textChanged,
this, &CChatDlg::OnLocalInputTextTextChanged );
2013-01-23 11:41:13 +01:00
2020-06-21 14:45:11 +02:00
QObject::connect ( butSend, &QPushButton::clicked,
this, &CChatDlg::OnSendText );
2013-01-23 11:41:13 +01:00
}
void CChatDlg::OnLocalInputTextTextChanged ( const QString& strNewText )
{
// check and correct length
if ( strNewText.length() > MAX_LEN_CHAT_TEXT )
{
// text is too long, update control with shortend text
edtLocalInputText->setText ( strNewText.left ( MAX_LEN_CHAT_TEXT ) );
}
}
2020-06-21 14:45:11 +02:00
void CChatDlg::OnSendText()
2013-01-23 11:41:13 +01:00
{
// send new text and clear line afterwards
emit NewLocalInputText ( edtLocalInputText->text() );
edtLocalInputText->clear();
}
2020-06-21 14:45:11 +02:00
void CChatDlg::OnClearChatHistory()
2013-01-23 11:41:13 +01:00
{
// clear chat window
txvChatWindow->clear();
}
void CChatDlg::AddChatText ( QString strChatText )
{
// add new text in chat window
txvChatWindow->append ( strChatText );
// notify accessibility plugin that text has changed
2020-05-14 21:12:06 +02:00
QAccessible::updateAccessibility ( new QAccessibleValueChangeEvent ( txvChatWindow, strChatText ) );
2013-01-23 11:41:13 +01:00
}