1 Star 0 Fork 0

fuchaow/Property-Editor

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
CFontProperty.cpp 2.81 KB
一键复制 编辑 原始数据 按行查看 历史
Shujaat 提交于 2019-10-27 19:22 . Add files via upload
#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();
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/fuchaow/Property-Editor.git
git@gitee.com:fuchaow/Property-Editor.git
fuchaow
Property-Editor
Property-Editor
master

搜索帮助