From ac715f44428f36347328c0d78284fcc885c7059a Mon Sep 17 00:00:00 2001 From: arcan1s Date: Thu, 4 Sep 2014 21:16:41 +0400 Subject: [PATCH] add more conversion functions --- fontdialog.cpp | 82 ++++++++++++++++++++++++++++++-------------------- fontdialog.h | 9 +++++- 2 files changed, 58 insertions(+), 33 deletions(-) diff --git a/fontdialog.cpp b/fontdialog.cpp index e20e64a..0d372a9 100644 --- a/fontdialog.cpp +++ b/fontdialog.cpp @@ -33,43 +33,13 @@ QColor CFont::color() } -int CFont::htmlWeight() -{ - int htmlWeight = 400; - switch(weight()) { - case 16: - htmlWeight = 100; - break; - case 25: - htmlWeight = 300; - break; - case 50: - htmlWeight = 400; - break; - case 63: - htmlWeight = 600; - break; - case 75: - htmlWeight = 800; - break; - case 87: - htmlWeight = 900; - break; - default: - break; - } - - return htmlWeight; -} - - void CFont::setCurrentColor(const QColor color) { currentColor = color; } -void CFont::setHtmlWeight(const int htmlWeight) +void CFont::html2QFont(const int htmlWeight) { int weight = 16; switch(htmlWeight) { @@ -98,7 +68,55 @@ void CFont::setHtmlWeight(const int htmlWeight) break; } - setWeight(weight); + return weight; +} + + +int CFont::qFont2html(const int weight) +{ + int htmlWeight = 400; + switch(weight) { + case 16: + htmlWeight = 100; + break; + case 25: + htmlWeight = 300; + break; + case 50: + htmlWeight = 400; + break; + case 63: + htmlWeight = 600; + break; + case 75: + htmlWeight = 800; + break; + case 87: + htmlWeight = 900; + break; + default: + break; + } + + return htmlWeight; +} + + +int CFont::htmlWeight() +{ + return qFont2html(weight()); +} + + +void CFont::setHtmlWeight(const int htmlWeight) +{ + setWeight(html2QFont(htmlWeight)); +} + + +CFont CFont::fromQFont(const QFont font, const QColor color) +{ + return CFont(font.family(), font.pointSize(), font.weight(), font.italic(), color); } diff --git a/fontdialog.h b/fontdialog.h index d74b777..93eddf7 100644 --- a/fontdialog.h +++ b/fontdialog.h @@ -31,10 +31,17 @@ public: explicit CFont(const QString family, int pointSize = -1, int weight = -1, bool italic = false, QColor color = QColor(QString("#000000"))); + // color properties QColor color(); - int htmlWeight(); void setCurrentColor(const QColor color); + // html weight properties + static html2QFont(const int htmlWeight); + static qFont2html(const int weight); + int htmlWeight(); void setHtmlWeight(const int htmlWeight); + // conversion to QFont + static CFont fromQFont(const QFont font, + const QColor color = QColor(QString("#000000"))); QFont toQFont(); private: