mirror of
https://github.com/arcan1s/qtadds-fontdialog.git
synced 2025-04-24 16:47:17 +00:00
add more conversion functions
This commit is contained in:
parent
5c645f972c
commit
ac715f4442
@ -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)
|
void CFont::setCurrentColor(const QColor color)
|
||||||
{
|
{
|
||||||
currentColor = color;
|
currentColor = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CFont::setHtmlWeight(const int htmlWeight)
|
void CFont::html2QFont(const int htmlWeight)
|
||||||
{
|
{
|
||||||
int weight = 16;
|
int weight = 16;
|
||||||
switch(htmlWeight) {
|
switch(htmlWeight) {
|
||||||
@ -98,7 +68,55 @@ void CFont::setHtmlWeight(const int htmlWeight)
|
|||||||
break;
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,10 +31,17 @@ public:
|
|||||||
explicit CFont(const QString family, int pointSize = -1,
|
explicit CFont(const QString family, int pointSize = -1,
|
||||||
int weight = -1, bool italic = false,
|
int weight = -1, bool italic = false,
|
||||||
QColor color = QColor(QString("#000000")));
|
QColor color = QColor(QString("#000000")));
|
||||||
|
// color properties
|
||||||
QColor color();
|
QColor color();
|
||||||
int htmlWeight();
|
|
||||||
void setCurrentColor(const QColor color);
|
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);
|
void setHtmlWeight(const int htmlWeight);
|
||||||
|
// conversion to QFont
|
||||||
|
static CFont fromQFont(const QFont font,
|
||||||
|
const QColor color = QColor(QString("#000000")));
|
||||||
QFont toQFont();
|
QFont toQFont();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
Reference in New Issue
Block a user