-
Notifications
You must be signed in to change notification settings - Fork 18
/
CFontProperty.cpp
126 lines (90 loc) · 2.81 KB
/
CFontProperty.cpp
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "CFontProperty.h"
#include <QFontDialog>
CFontProperty::CFontProperty(const QByteArray &id, const QString &name, const QFont &font,
const QFontComboBox::FontFilters filters, const QFontDatabase::WritingSystem writeSystem):
CBaseProperty(id, name),
m_font(font),
m_filters(filters),
m_writeSystem(writeSystem)
{
init();
}
CFontProperty::CFontProperty(CBaseProperty *top, const QByteArray &id, const QString &name, const QFont &font,
const QFontComboBox::FontFilters filters, const QFontDatabase::WritingSystem writeSystem):
CBaseProperty(top, id, name),
m_font(font),
m_filters(filters),
m_writeSystem(writeSystem)
{
init();
}
void CFontProperty::init()
{
setFont(m_font);
}
void CFontProperty::setFont(const QFont &font)
{
m_font = font;
CBaseProperty::setValue();
}
const QFont& CFontProperty::getFont() const
{
return m_font;
}
QVariant CFontProperty::getVariantValue() const
{
return getFont();
}
void CFontProperty::displayValue()
{
if (treeWidget())
treeWidget()->blockSignals(true);
QString fontString = QString("%1, %2pt")
.arg(m_font.family())
.arg(m_font.pointSizeF());
if (m_font.bold()) fontString += ", bold";
if (m_font.italic()) fontString += ", italic";
if (m_font.underline()) fontString += ", underline";
setText(1, fontString);
setToolTip(1, fontString);
QFont showFont(m_font);
showFont.setPointSize(font(0).pointSize());
QTreeWidgetItem::setFont(1, showFont);
if (treeWidget())
treeWidget()->blockSignals(false);
}
QWidget* CFontProperty::createEditor() const
{
m_fontCombo.setWritingSystem(m_writeSystem);
m_fontCombo.setFontFilters(m_filters);
CFontButtonEditor* hostEditor = new CFontButtonEditor(&m_fontCombo, const_cast<CFontProperty*>(this));
return hostEditor;
}
void CFontProperty::valueToEditor()
{
if (m_fontCombo.isVisible())
m_fontCombo.setCurrentFont(m_font);
}
void CFontProperty::valueFromEditor()
{
if (m_fontCombo.currentFont() != m_font)
{
setFont(m_fontCombo.currentFont());
emitValueChanged();
}
}
// CFontButtonEditor
CFontProperty::CFontButtonEditor::CFontButtonEditor(QFontComboBox *fontComboEditor, CFontProperty *property)
: TButtonBasedEditor<QFontComboBox>(fontComboEditor),
m_property(property)
{
}
void CFontProperty::CFontButtonEditor::onEditButtonActivated()
{
QFontDialog fontDialog(getEditor()->currentFont());
if (fontDialog.exec() == QDialog::Accepted)
{
getEditor()->setCurrentFont(fontDialog.currentFont());
m_property->finishEdit();
}
}