Skip to content
Permalink
Browse files

Merge PR #2408: TextMessage, RichTextEditor: accept TextMessage dialo…

…g when Ctrl-Enter is pressed.
  • Loading branch information...
mkrautz committed Jul 9, 2016
2 parents 6a78217 + 7d2e1ef commit c2be406af851ab72050221b5dcd1c901992116dc
Showing with 23 additions and 17 deletions.
  1. +17 −0 src/mumble/RichTextEditor.cpp
  2. +4 −0 src/mumble/RichTextEditor.h
  3. +2 −16 src/mumble/TextMessage.cpp
  4. +0 −1 src/mumble/TextMessage.h
@@ -184,6 +184,9 @@ RichTextEditor::RichTextEditor(QWidget *p) : QTabWidget(p) {
updateActions();

qteRichText->setFocus();

qteRichText->installEventFilter(this);
qptePlainText->installEventFilter(this);
}

bool RichTextEditor::isModified() const {
@@ -615,6 +618,20 @@ QString RichTextEditor::text() {
return qptePlainText->toPlainText();
}

bool RichTextEditor::eventFilter(QObject *obj, QEvent *evt) {
if (obj != qptePlainText && obj != qteRichText)
return false;
if (evt->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(evt);
if (((keyEvent->key() == Qt::Key_Enter) || (keyEvent->key() == Qt::Key_Return)) &&
(keyEvent->modifiers() == Qt::ControlModifier)) {
emit accept();
return true;
}
}
return false;
}

bool RichTextImage::isValidImage(const QByteArray &ba, QByteArray &fmt) {
QBuffer qb;
qb.setData(ba);
@@ -50,10 +50,14 @@ class RichTextEditor : public QTabWidget, Ui::RichTextEditor {
bool bReadOnly;
void richToPlain();
QColor qcColor;
bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE;
public:
RichTextEditor(QWidget *p = NULL);
QString text();
bool isModified() const;
signals:
/// The accept signal is emitted when Ctrl-Enter is pressed inside the RichTextEditor.
void accept();
public slots:
void setText(const QString &text, bool readonly = false);
void updateColor(const QColor &);
@@ -12,8 +12,9 @@ TextMessage::TextMessage(QWidget *p, QString title, bool bChannel) : QDialog(p)
if (!bChannel)
qcbTreeMessage->setHidden(true);
setWindowTitle(title);
rteMessage->installEventFilter(this);
bTreeMessage = false;

QObject::connect(rteMessage, SIGNAL(accept()), this, SLOT(accept()));
}

void TextMessage::on_qcbTreeMessage_stateChanged(int s) {
@@ -60,18 +61,3 @@ QString TextMessage::autoFormat(QString qsPlain) {
QString TextMessage::message() {
return rteMessage->text();
}

bool TextMessage::eventFilter(QObject *obj, QEvent *evt) {
if (obj != rteMessage)
return false;
if (evt->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(evt);
if (((keyEvent->key() == Qt::Key_Enter) || (keyEvent->key() == Qt::Key_Return)) &&
(keyEvent->modifiers() == Qt::NoModifier)) {
accept();
return true;
}
}
return false;
}

@@ -19,7 +19,6 @@ class TextMessage : public QDialog, public Ui::TextMessage {
public:
TextMessage(QWidget *parent = NULL, QString title = tr("Enter text"), bool bChannel = false);
QString message();
bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE;
static QString autoFormat(QString qsPlain);
bool bTreeMessage;
};

0 comments on commit c2be406

Please sign in to comment.
You can’t perform that action at this time.