Newer
Older
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "CustomLineHeightTextEdit.h"
CustomLineHeightTextEdit::CustomLineHeightTextEdit(QWidget *a_parent)
:QTextEdit (a_parent)
{
}
void CustomLineHeightTextEdit::setPlaceholderText(const QString &placeholderText)
{
setProperty("state",STATE_DEFAULT);
style()->unpolish(this);
style()->polish(this);
update();
m_placeholderText = placeholderText;
QTextEdit::setText(textToHtml(placeholderText));
//setReadOnly(true);
}
void CustomLineHeightTextEdit::mousePressEvent(QMouseEvent *e)
{
if(property("state").toString()==STATE_DEFAULT)
{
setProperty("state",STATE_HOVER);
style()->unpolish(this);
style()->polish(this);
update();
QString htmlText = QString("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0//EN' 'http://www.w3.org/TR/REC-html40/strict.dtd'>"
"<html><head><meta name='qrichtext' content='1' /><style type='text/css'>"
"p, li { white-space: pre-wrap; }"
"</style></head><body>"
"<p style='line-height:%1;'></p></body></html>").arg(m_lineHeight);
QTextEdit::setText(htmlText);
}
QTextEdit::mousePressEvent(e);
}
void CustomLineHeightTextEdit::focusOutEvent(QFocusEvent *e)
{
if(toPlainText().isEmpty())
{
setProperty("state",STATE_DEFAULT);
style()->unpolish(this);
style()->polish(this);
update();
QTextEdit::setText(textToHtml(m_placeholderText));
}
QTextEdit::focusOutEvent(e);
}
QString CustomLineHeightTextEdit::toPlainText() const
{
if(property("state").toString()==STATE_DEFAULT)
return QString("");
return QTextEdit::toPlainText();
}
void CustomLineHeightTextEdit::setObjectName(const QString &name)
{
QObject::setObjectName(name);
updateStyleSheets();
}
void CustomLineHeightTextEdit::updateStyleSheets()
{
StyleSheatSearchPar searchPar;
searchPar.widgetName = "#" + this->objectName();
QString stylesheet = AppStyleSheetHandler::getWidgetStyleSheet(searchPar);
m_lineHeight = AppStyleSheetHandler::getValueFromStylesheet(stylesheet, "line-height");
}
QString CustomLineHeightTextEdit::textToHtml(const QString &text)
{
if(m_lineHeight.isEmpty())m_lineHeight = "100";
return QString("<p style = 'line-height:%1;'> %2 </p>").arg(m_lineHeight).arg(text);
}