Pass font/fontsize to RT editor
This commit is contained in:
@@ -250,14 +250,20 @@ void TaskRichAnno::onEditorClicked(bool b)
|
||||
m_textDialog->setWindowTitle(QObject::tr("Rich text editor"));
|
||||
m_textDialog->setMinimumWidth (400);
|
||||
m_textDialog->setMinimumHeight(400);
|
||||
if (m_annoVP != nullptr) {
|
||||
double mmToPts = 2.83;
|
||||
m_rte->setDefFontSize(round(m_annoVP->Fontsize.getValue() * mmToPts ));
|
||||
m_rte->setDefFont(Base::Tools::fromStdString(m_annoVP->Font.getValue()));
|
||||
} else { //no VP yet, use defs
|
||||
m_rte->setDefFontSize(getDefFontSize());
|
||||
m_rte->setDefFont(getDefFont());
|
||||
}
|
||||
|
||||
connect(m_rte, SIGNAL(saveText(QString)),
|
||||
this, SLOT(onSaveAndExit(QString)));
|
||||
connect(m_rte, SIGNAL(editorFinished(void)),
|
||||
this, SLOT(onEditorExit(void)));
|
||||
|
||||
// m_textDialog->setFont(m_annoVP->Font.getValue());
|
||||
// m_textDialog->setFontSize(m_annoVP->FontSize.getValue());
|
||||
m_textDialog->show();
|
||||
}
|
||||
|
||||
@@ -442,6 +448,24 @@ void TaskRichAnno::enableTaskButtons(bool b)
|
||||
m_btnCancel->setEnabled(b);
|
||||
}
|
||||
|
||||
QString TaskRichAnno::getDefFont(void)
|
||||
{
|
||||
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
|
||||
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Labels");
|
||||
std::string fontName = hGrp->GetASCII("LabelFont", "osifont");
|
||||
QString result = Base::Tools::fromStdString(fontName);
|
||||
return result;
|
||||
}
|
||||
|
||||
int TaskRichAnno::getDefFontSize()
|
||||
{
|
||||
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
|
||||
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions");
|
||||
double fontSize = hGrp->GetFloat("FontSize", 5.0); // this is mm, not pts!
|
||||
double mmToPts = 2.83;
|
||||
int ptsSize = round(fontSize * mmToPts);
|
||||
return ptsSize;
|
||||
}
|
||||
//******************************************************************************
|
||||
|
||||
bool TaskRichAnno::accept()
|
||||
@@ -469,7 +493,7 @@ bool TaskRichAnno::accept()
|
||||
|
||||
bool TaskRichAnno::reject()
|
||||
{
|
||||
Base::Console().Message("TRA::reject()\n");
|
||||
// Base::Console().Message("TRA::reject()\n");
|
||||
if (m_inProgressLock) {
|
||||
// Base::Console().Message("TRA::reject - edit in progress!!\n");
|
||||
return false;
|
||||
@@ -481,7 +505,6 @@ bool TaskRichAnno::reject()
|
||||
return false;
|
||||
}
|
||||
|
||||
Base::Console().Message("TRA::reject() - m_mdi: %X\n", m_mdi);
|
||||
if (m_mdi != nullptr) {
|
||||
m_mdi->setContextMenuPolicy(m_saveContextPolicy);
|
||||
}
|
||||
|
||||
@@ -99,6 +99,9 @@ protected:
|
||||
void setUiEdit(void);
|
||||
void enableTextUi(bool b);
|
||||
void enableVPUi(bool b);
|
||||
|
||||
int getDefFontSize(void);
|
||||
QString getDefFont(void);
|
||||
|
||||
private:
|
||||
Ui_TaskRichAnno * ui;
|
||||
|
||||
@@ -50,8 +50,6 @@ public:
|
||||
App::PropertyFont Font;
|
||||
App::PropertyLength Fontsize;
|
||||
App::PropertyColor Color;
|
||||
App::PropertyFloat MaxWidth;
|
||||
App::PropertyBool ShowFrame;
|
||||
|
||||
virtual void attach(App::DocumentObject *);
|
||||
/* virtual void setDisplayMode(const char* ModeName);*/
|
||||
|
||||
@@ -49,6 +49,8 @@ MRichTextEdit::MRichTextEdit(QWidget *parent, QString textIn) : QWidget(parent)
|
||||
m_lastBlockList = 0;
|
||||
f_textedit->setTabStopWidth(40);
|
||||
setText(textIn);
|
||||
m_defFontSize = 12;
|
||||
m_defFont = QString::fromUtf8("Sans");
|
||||
|
||||
connect(f_save, SIGNAL(clicked()),
|
||||
this, SLOT(onSave()));
|
||||
@@ -60,12 +62,13 @@ MRichTextEdit::MRichTextEdit(QWidget *parent, QString textIn) : QWidget(parent)
|
||||
connect(f_textedit, SIGNAL(cursorPositionChanged()),
|
||||
this, SLOT(slotCursorPositionChanged()));
|
||||
|
||||
m_fontsize_h1 = 18;
|
||||
m_fontsize_h2 = 16;
|
||||
m_fontsize_h3 = 14;
|
||||
m_fontsize_h4 = 12;
|
||||
m_fontsize_h1 = m_defFontSize + 8;
|
||||
m_fontsize_h2 = m_defFontSize + 6;
|
||||
m_fontsize_h3 = m_defFontSize + 4;
|
||||
m_fontsize_h4 = m_defFontSize + 2;
|
||||
|
||||
fontChanged(f_textedit->font());
|
||||
// fontChanged(f_textedit->font());
|
||||
fontChanged(getDefFont());
|
||||
bgColorChanged(f_textedit->textColor());
|
||||
|
||||
// paragraph formatting
|
||||
@@ -181,8 +184,9 @@ MRichTextEdit::MRichTextEdit(QWidget *parent, QString textIn) : QWidget(parent)
|
||||
|
||||
connect(f_fontsize, SIGNAL(activated(QString)),
|
||||
this, SLOT(textSize(QString)));
|
||||
f_fontsize->setCurrentIndex(f_fontsize->findText(QString::number(QApplication::font()
|
||||
.pointSize())));
|
||||
// f_fontsize->setCurrentIndex(f_fontsize->findText(QString::number(QApplication::font()
|
||||
// .pointSize())));
|
||||
f_fontsize->setCurrentIndex(f_fontsize->findText(getDefFontSize()));
|
||||
|
||||
// text foreground color
|
||||
|
||||
@@ -227,7 +231,7 @@ void MRichTextEdit::textRemoveFormat() {
|
||||
fmt.setFontUnderline (false);
|
||||
fmt.setFontStrikeOut (false);
|
||||
fmt.setFontItalic (false);
|
||||
fmt.setFontPointSize (9);
|
||||
fmt.setFontPointSize (m_defFontSize);
|
||||
// fmt.setFontFamily ("Helvetica");
|
||||
// fmt.setFontStyleHint (QFont::SansSerif);
|
||||
// fmt.setFontFixedPitch (true);
|
||||
@@ -236,7 +240,7 @@ void MRichTextEdit::textRemoveFormat() {
|
||||
f_underline ->setChecked(false);
|
||||
f_italic ->setChecked(false);
|
||||
f_strikeout ->setChecked(false);
|
||||
f_fontsize ->setCurrentIndex(f_fontsize->findText("9"));
|
||||
f_fontsize ->setCurrentIndex(f_fontsize->findText(getDefFontSize()));
|
||||
|
||||
// QTextBlockFormat bfmt = cursor.blockFormat();
|
||||
// bfmt->setIndent(0);
|
||||
@@ -252,7 +256,7 @@ void MRichTextEdit::textRemoveAllFormat() {
|
||||
f_underline ->setChecked(false);
|
||||
f_italic ->setChecked(false);
|
||||
f_strikeout ->setChecked(false);
|
||||
f_fontsize ->setCurrentIndex(f_fontsize->findText("9"));
|
||||
f_fontsize ->setCurrentIndex(f_fontsize->findText(getDefFontSize()));
|
||||
QString text = f_textedit->toPlainText();
|
||||
f_textedit->setPlainText(text);
|
||||
}
|
||||
@@ -617,5 +621,38 @@ void MRichTextEdit::onExit(void)
|
||||
Q_EMIT editorFinished();
|
||||
}
|
||||
|
||||
void MRichTextEdit::setDefFontSize(int fs)
|
||||
{
|
||||
m_defFontSize = fs;
|
||||
f_fontsize->findText(getDefFontSize());
|
||||
m_fontsize_h1 = m_defFontSize + 8;
|
||||
m_fontsize_h2 = m_defFontSize + 6;
|
||||
m_fontsize_h3 = m_defFontSize + 4;
|
||||
m_fontsize_h4 = m_defFontSize + 2;
|
||||
//have to do something with f_fontSize
|
||||
QString newSize = QString::number(fs);
|
||||
f_fontsize->setCurrentIndex(f_fontsize->findText(newSize));
|
||||
//void MRichTextEdit::fontChanged(const QFont &f) { ???
|
||||
textSize(newSize);
|
||||
}
|
||||
|
||||
QString MRichTextEdit::getDefFontSize(void)
|
||||
{
|
||||
QString result = QString::number(m_defFontSize);
|
||||
return result;
|
||||
}
|
||||
|
||||
void MRichTextEdit::setDefFont(QString f)
|
||||
{
|
||||
m_defFont = f;
|
||||
}
|
||||
|
||||
QFont MRichTextEdit::getDefFont(void)
|
||||
{
|
||||
QFont result;
|
||||
result.setFamily(m_defFont);
|
||||
return result;
|
||||
}
|
||||
|
||||
#include <Mod/TechDraw/Gui/moc_mrichtextedit.cpp>
|
||||
|
||||
|
||||
@@ -41,7 +41,12 @@ class MRichTextEdit : public QWidget, protected Ui::MRichTextEdit {
|
||||
QTextCursor textCursor() const { return f_textedit->textCursor(); }
|
||||
void setTextCursor(const QTextCursor& cursor) { f_textedit->setTextCursor(cursor); }
|
||||
void setMaxWidth(double w);
|
||||
|
||||
/* void setFontSize(double fs);*/
|
||||
void setDefFontSize(int fs);
|
||||
void setDefFont(QString f);
|
||||
QString getDefFontSize(void);
|
||||
QFont getDefFont(void);
|
||||
|
||||
public slots:
|
||||
void setText(const QString &text);
|
||||
|
||||
@@ -98,6 +103,8 @@ Q_SIGNALS:
|
||||
ParagraphMonospace };
|
||||
|
||||
QPointer<QTextList> m_lastBlockList;
|
||||
int m_defFontSize;
|
||||
QString m_defFont;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -650,7 +650,7 @@
|
||||
<tabstop>f_menu</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="Resources/MRichText.qrc"/>
|
||||
<include location="Resources/TechDraw.qrc"/>
|
||||
<include location="Resources/TechDraw.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
|
||||
Reference in New Issue
Block a user