add more conversion functions

This commit is contained in:
arcan1s 2014-09-04 21:16:41 +04:00
parent 5c645f972c
commit ac715f4442
2 changed files with 58 additions and 33 deletions

View File

@ -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);
}

View File

@ -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: