merged with master
This commit is contained in:
+54
-8
@@ -20,6 +20,7 @@
|
||||
|
||||
#include "texteditex.h"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
#include <QDebug>
|
||||
|
||||
#include "dialogs/texteditdialog.h"
|
||||
@@ -27,13 +28,58 @@
|
||||
#include "mainwindow.h"
|
||||
|
||||
TextEditEx::TextEditEx(QWidget *parent, bool enable_rich_text) :
|
||||
QTextEdit(parent),
|
||||
QWidget(parent),
|
||||
enable_rich_text_(enable_rich_text)
|
||||
{
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(text_edit_menu()));
|
||||
QVBoxLayout* layout = new QVBoxLayout(this);
|
||||
|
||||
connect(this, SIGNAL(textChanged()), this, SLOT(queue_text_modified()));
|
||||
text_editor_ = new QTextEdit();
|
||||
connect(text_editor_, SIGNAL(textChanged()), this, SLOT(queue_text_modified()));
|
||||
layout->addWidget(text_editor_);
|
||||
|
||||
QPushButton* edit_button = new QPushButton(tr("Edit Text"));
|
||||
layout->addWidget(edit_button);
|
||||
connect(edit_button, SIGNAL(clicked(bool)), this, SLOT(open_text_edit()));
|
||||
|
||||
/*
|
||||
text_editor_->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(text_editor_, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(text_edit_menu()));
|
||||
*/
|
||||
}
|
||||
|
||||
void TextEditEx::setUndoRedoEnabled(bool e)
|
||||
{
|
||||
text_editor_->setUndoRedoEnabled(e);
|
||||
}
|
||||
|
||||
QTextDocument *TextEditEx::document()
|
||||
{
|
||||
return text_editor_->document();
|
||||
}
|
||||
|
||||
QTextCursor TextEditEx::textCursor()
|
||||
{
|
||||
return text_editor_->textCursor();
|
||||
}
|
||||
|
||||
void TextEditEx::setTextCursor(const QTextCursor &cursor)
|
||||
{
|
||||
text_editor_->setTextCursor(cursor);
|
||||
}
|
||||
|
||||
void TextEditEx::setTextHeight(int h)
|
||||
{
|
||||
text_editor_->setFixedHeight(h);
|
||||
}
|
||||
|
||||
void TextEditEx::setHtml(const QString &text)
|
||||
{
|
||||
text_editor_->setHtml(text);
|
||||
}
|
||||
|
||||
void TextEditEx::setPlainText(const QString &text)
|
||||
{
|
||||
text_editor_->setPlainText(text);
|
||||
}
|
||||
|
||||
void TextEditEx::text_edit_menu() {
|
||||
@@ -45,21 +91,21 @@ void TextEditEx::text_edit_menu() {
|
||||
}
|
||||
|
||||
void TextEditEx::open_text_edit() {
|
||||
const QString& current_text = (enable_rich_text_) ? toHtml() : toPlainText();
|
||||
const QString& current_text = (enable_rich_text_) ? text_editor_->toHtml() : text_editor_->toPlainText();
|
||||
|
||||
TextEditDialog ted(olive::MainWindow, current_text, enable_rich_text_);
|
||||
ted.exec();
|
||||
QString result = ted.get_string();
|
||||
if (!result.isEmpty()) {
|
||||
if (enable_rich_text_) {
|
||||
setHtml(result);
|
||||
text_editor_->setHtml(result);
|
||||
} else {
|
||||
setPlainText(result);
|
||||
text_editor_->setPlainText(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TextEditEx::queue_text_modified()
|
||||
{
|
||||
emit textModified(enable_rich_text_ ? toHtml() : toPlainText());
|
||||
emit textModified(enable_rich_text_ ? text_editor_->toHtml() : text_editor_->toPlainText());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user