102 lines
2.9 KiB
C++
Executable File
102 lines
2.9 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Philipp Last, NLSE, 2018-01-11
|
|
*/
|
|
#include "ui_evl_new_comment_dialog.h"
|
|
#include "evl_new_comment_dialog.h"
|
|
|
|
#include <Evaluations/logger.h>
|
|
#include <LtsUtilsSettings/settings.h>
|
|
|
|
namespace Evaluations
|
|
{
|
|
EvlNewCommentDialog::EvlNewCommentDialog(const std::shared_ptr<OperatorManagement::Interface::Dtc> &opmDtc,
|
|
QWidget *parent)
|
|
: QDialog(parent),
|
|
m_ui(new Ui::EvlNewCommentDialog),
|
|
m_logger(getLogger("EvlComments::EvlNewCommentDialog"))
|
|
{
|
|
m_ui->setupUi(this);
|
|
setWindowFlags(Qt::Tool);
|
|
m_ui->m_ltsComboBox_ReceiverOperator->addItem(tr("All (Default)"), 0);
|
|
|
|
auto cbUser = [this](const OperatorManagement::User &user)
|
|
{
|
|
m_ui->m_ltsComboBox_ReceiverOperator->addItem(QString::fromStdString(user.name()), user.id());
|
|
};
|
|
opmDtc->users(cbUser);
|
|
|
|
connect(m_ui->m_pushButton_AddComment, &QPushButton::clicked, this, &QDialog::accept);
|
|
connect(m_ui->m_pushButton_Cancel, &QPushButton::clicked, this, &QDialog::reject);
|
|
connect(m_ui->m_plainTextEdit_Comment, &QPlainTextEdit::textChanged, this, &EvlNewCommentDialog::onTextChanged);
|
|
|
|
m_ui->m_checkBox_SendComment->setChecked(LtsUtils::OperatorSettings::getInstance()->value(QStringLiteral("Evaluations"), QStringLiteral("setAutoSendComments"), false).toBool());
|
|
|
|
onTextChanged();
|
|
}
|
|
|
|
|
|
EvlNewCommentDialog::~EvlNewCommentDialog()
|
|
{
|
|
LtsUtils::OperatorSettings::getInstance()->setValue(QStringLiteral("Evaluations"), QStringLiteral("setAutoSendComments"), m_ui->m_checkBox_SendComment->isChecked());
|
|
delete m_ui;
|
|
}
|
|
|
|
|
|
void EvlNewCommentDialog::onTextChanged()
|
|
{
|
|
QString plainText(m_ui->m_plainTextEdit_Comment->toPlainText());
|
|
int currentUsedChars = plainText.toUtf8().size();
|
|
bool bNeedSetNew = false;
|
|
|
|
while (currentUsedChars > m_maxChars)
|
|
{
|
|
plainText.chop(1);
|
|
currentUsedChars = plainText.toUtf8().size();
|
|
bNeedSetNew = true; // do not set text directly, results in recursion
|
|
}
|
|
|
|
// if text longer than allowed
|
|
if (bNeedSetNew)
|
|
{
|
|
m_ui->m_plainTextEdit_Comment->setPlainText(plainText);
|
|
m_ui->m_plainTextEdit_Comment->moveCursor(QTextCursor::End);
|
|
}
|
|
|
|
m_ui->m_label_CharsLeft->setText(tr("Characters left: %1").arg(m_maxChars - currentUsedChars));
|
|
}
|
|
|
|
|
|
bool EvlNewCommentDialog::autoSend() const
|
|
{
|
|
return m_ui->m_checkBox_SendComment->isChecked();
|
|
}
|
|
|
|
|
|
QString EvlNewCommentDialog::comment() const
|
|
{
|
|
return m_ui->m_plainTextEdit_Comment->toPlainText();
|
|
}
|
|
|
|
|
|
int EvlNewCommentDialog::selectedReceiverId() const
|
|
{
|
|
return m_ui->m_ltsComboBox_ReceiverOperator->currentData().toInt();
|
|
}
|
|
|
|
void EvlNewCommentDialog::setAsEditComment(const QString &text)
|
|
{
|
|
m_ui->m_plainTextEdit_Comment->setPlainText(text);
|
|
m_ui->m_label_CharsLeft->hide();
|
|
m_ui->label->hide();
|
|
m_ui->m_ltsComboBox_ReceiverOperator->hide();
|
|
m_ui->m_checkBox_SendComment->hide();
|
|
|
|
m_ui->m_pushButton_AddComment->setText(tr("Edit Comment"));
|
|
}
|
|
}
|
|
|