1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
/*
* Copyright 2010, Robert Bieber
* Licensed under the LGPLv2.1, see the COPYING file for more information
*/
#include <QPushButton>
#include <QTextEdit>
#include <QPlainTextEdit>
#include "varianteditor.h"
VariantEditor::VariantEditor(QPlainTextEdit *plainTextEdit)
: plainTextEdit(plainTextEdit), textEdit(0), type(Plain)
{
}
VariantEditor::VariantEditor(QTextEdit *textEdit)
: plainTextEdit(0), textEdit(textEdit), type(Rich)
{
}
void VariantEditor::connectToSetEnabled(QPushButton *button)
{
if(type == Rich)
QObject::connect(textEdit, SIGNAL(copyAvailable(bool)),
button, SLOT(setEnabled(bool)));
else
QObject::connect(plainTextEdit, SIGNAL(copyAvailable(bool)),
button, SLOT(setEnabled(bool)));
}
QTextDocument* VariantEditor::document()
{
return type == Rich ? textEdit->document() : plainTextEdit->document();
}
void VariantEditor::setTextCursor(const QTextCursor& cursor)
{
if(type == Rich)
textEdit->setTextCursor(cursor);
else
plainTextEdit->setTextCursor(cursor);
}
bool VariantEditor::find(const QString& exp, QTextDocument::FindFlags flags)
{
return type == Rich ? textEdit->find(exp, flags) : plainTextEdit->find(exp, flags);
}
QTextCursor VariantEditor::textCursor() const
{
return type == Rich ? textEdit->textCursor() : plainTextEdit->textCursor();
}
|