mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-28 00:49:28 -05:00
Merge pull request #98 from PhenomRetroShare/AddMinimumFontSizeInChat
Add minimum font size in chat.
This commit is contained in:
commit
bd94fcd08e
@ -870,6 +870,7 @@ void ChatWidget::addChatMsg(bool incoming, const QString &name, const QDateTime
|
||||
if (!Settings->valueFromGroup("Chat", "EnableCustomFontSize", true).toBool()) {
|
||||
formatTextFlag |= RSHTML_FORMATTEXT_REMOVE_FONT_SIZE;
|
||||
}
|
||||
int desiredMinimumFontSize = Settings->valueFromGroup("Chat", "MinimumFontSize", 10).toInt();
|
||||
if (!Settings->valueFromGroup("Chat", "EnableBold", true).toBool()) {
|
||||
formatTextFlag |= RSHTML_FORMATTEXT_REMOVE_FONT_WEIGHT;
|
||||
}
|
||||
@ -893,7 +894,7 @@ void ChatWidget::addChatMsg(bool incoming, const QString &name, const QDateTime
|
||||
formatFlag |= CHAT_FORMATMSG_SYSTEM;
|
||||
}
|
||||
|
||||
QString formattedMessage = RsHtml().formatText(ui->textBrowser->document(), message, formatTextFlag, backgroundColor, desiredContrast);
|
||||
QString formattedMessage = RsHtml().formatText(ui->textBrowser->document(), message, formatTextFlag, backgroundColor, desiredContrast, desiredMinimumFontSize);
|
||||
QDateTime dtTimestamp=incoming ? sendTime : recvTime;
|
||||
QString formatMsg = chatStyle.formatMessage(type, name, dtTimestamp, formattedMessage, formatFlag);
|
||||
QString timeStamp = dtTimestamp.toString(Qt::ISODate);
|
||||
|
@ -115,6 +115,7 @@ ChatPage::save(QString &/*errmsg*/)
|
||||
Settings->setValue("Emoteicons_GroupChat", ui.checkBox_emotegroupchat->isChecked());
|
||||
Settings->setValue("EnableCustomFonts", ui.checkBox_enableCustomFonts->isChecked());
|
||||
Settings->setValue("EnableCustomFontSize", ui.checkBox_enableCustomFontSize->isChecked());
|
||||
Settings->setValue("MinimumFontSize", ui.minimumFontSize->value());
|
||||
Settings->setValue("EnableBold", ui.checkBox_enableBold->isChecked());
|
||||
Settings->setValue("EnableItalics", ui.checkBox_enableItalics->isChecked());
|
||||
Settings->setValue("MinimumContrast", ui.minimumContrast->value());
|
||||
@ -219,6 +220,7 @@ ChatPage::load()
|
||||
ui.checkBox_emotegroupchat->setChecked(Settings->value("Emoteicons_GroupChat", true).toBool());
|
||||
ui.checkBox_enableCustomFonts->setChecked(Settings->value("EnableCustomFonts", true).toBool());
|
||||
ui.checkBox_enableCustomFontSize->setChecked(Settings->value("EnableCustomFontSize", true).toBool());
|
||||
ui.minimumFontSize->setValue(Settings->value("MinimumFontSize", 10).toInt());
|
||||
ui.checkBox_enableBold->setChecked(Settings->value("EnableBold", true).toBool());
|
||||
ui.checkBox_enableItalics->setChecked(Settings->value("EnableItalics", true).toBool());
|
||||
ui.minimumContrast->setValue(Settings->value("MinimumContrast", 4.5).toDouble());
|
||||
|
@ -75,6 +75,43 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="hl_minimumFontSize">
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="minimumFontSizeLabel">
|
||||
<property name="text">
|
||||
<string>Minimum font size</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="hs_minimumFontSize">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="minimumFontSize">
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>64</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_enableBold">
|
||||
<property name="text">
|
||||
|
@ -376,7 +376,7 @@ static QString saveSpace(const QString text)
|
||||
return savedSpaceText;
|
||||
}
|
||||
|
||||
QString RsHtml::formatText(QTextDocument *textDocument, const QString &text, ulong flag, const QColor &backgroundColor, qreal desiredContrast)
|
||||
QString RsHtml::formatText(QTextDocument *textDocument, const QString &text, ulong flag, const QColor &backgroundColor, qreal desiredContrast, int desiredMinimumFontSize)
|
||||
{
|
||||
if (flag == 0 || text.isEmpty()) {
|
||||
// nothing to do
|
||||
@ -416,7 +416,7 @@ QString RsHtml::formatText(QTextDocument *textDocument, const QString &text, ulo
|
||||
formattedText = doc.toString(-1); // -1 removes any annoying carriage return misinterpreted by QTextEdit
|
||||
|
||||
if (flag & RSHTML_OPTIMIZEHTML_MASK) {
|
||||
optimizeHtml(formattedText, flag, backgroundColor, desiredContrast);
|
||||
optimizeHtml(formattedText, flag, backgroundColor, desiredContrast, desiredMinimumFontSize);
|
||||
}
|
||||
|
||||
return formattedText;
|
||||
@ -734,12 +734,14 @@ static void optimizeHtml(QDomDocument& doc
|
||||
* is passed inside flag.
|
||||
* @param desiredContrast: Minimum contrast between text and background color,
|
||||
* between 1 and 21.
|
||||
* @param desiredMinimumFontSize: Minimum font size.
|
||||
*/
|
||||
static void styleCreate(QDomDocument& doc
|
||||
, QHash<QString, QStringList*> stylesList
|
||||
, unsigned int flag
|
||||
, qreal bglum
|
||||
, qreal desiredContrast)
|
||||
, qreal desiredContrast
|
||||
, int desiredMinimumFontSize)
|
||||
{
|
||||
QDomElement styleElem;
|
||||
do{
|
||||
@ -792,6 +794,15 @@ static void styleCreate(QDomDocument& doc
|
||||
QString key = keyvalue.at(0).trimmed();
|
||||
QString val = keyvalue.at(1).trimmed();
|
||||
|
||||
if (key == "font-size") {
|
||||
QRegExp re("(\\d+)(\\D*)");
|
||||
if (re.indexIn(val) != -1) {
|
||||
bool ok; int iVal = re.cap(1).toInt(&ok);
|
||||
if (ok && (iVal < desiredMinimumFontSize)) {
|
||||
val = QString::number(desiredMinimumFontSize) + re.cap(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((flag & RSHTML_FORMATTEXT_REMOVE_FONT_FAMILY && key == "font-family") ||
|
||||
(flag & RSHTML_FORMATTEXT_REMOVE_FONT_SIZE && key == "font-size") ||
|
||||
(flag & RSHTML_FORMATTEXT_REMOVE_FONT_WEIGHT && key == "font-weight") ||
|
||||
@ -864,9 +875,12 @@ void RsHtml::optimizeHtml(QTextEdit *textEdit, QString &text, unsigned int flag
|
||||
* is passed inside flag.
|
||||
* @param desiredContrast Minimum contrast between text and background color,
|
||||
* between 1 and 21.
|
||||
* @param desiredMinimumFontSize Minimum font size.
|
||||
*/
|
||||
void RsHtml::optimizeHtml(QString &text, unsigned int flag /*= 0*/
|
||||
, const QColor &backgroundColor /*= Qt::white*/, qreal desiredContrast /*= 1.0*/
|
||||
, const QColor &backgroundColor /*= Qt::white*/
|
||||
, qreal desiredContrast /*= 1.0*/
|
||||
, int desiredMinimumFontSize /*=10*/
|
||||
)
|
||||
{
|
||||
|
||||
@ -888,7 +902,7 @@ void RsHtml::optimizeHtml(QString &text, unsigned int flag /*= 0*/
|
||||
QHash<QString, QString> knownStyle;
|
||||
|
||||
::optimizeHtml(doc, body, stylesList, knownStyle);
|
||||
::styleCreate(doc, stylesList, flag, ::getRelativeLuminance(backgroundColor), desiredContrast);
|
||||
::styleCreate(doc, stylesList, flag, ::getRelativeLuminance(backgroundColor), desiredContrast, desiredMinimumFontSize);
|
||||
text = doc.toString(-1);
|
||||
|
||||
// std::cerr << "Optimized text to " << text.length() << " bytes , instead of " << originalLength << std::endl;
|
||||
|
@ -59,11 +59,11 @@ public:
|
||||
|
||||
static void initEmoticons(const QHash< QString, QString >& hash);
|
||||
|
||||
QString formatText(QTextDocument *textDocument, const QString &text, ulong flag, const QColor &backgroundColor = Qt::white, qreal desiredContrast = 1.0);
|
||||
QString formatText(QTextDocument *textDocument, const QString &text, ulong flag, const QColor &backgroundColor = Qt::white, qreal desiredContrast = 1.0, int desiredMinimumFontSize = 10);
|
||||
static bool findAnchors(const QString &text, QStringList& urls);
|
||||
|
||||
static void optimizeHtml(QTextEdit *textEdit, QString &text, unsigned int flag = 0);
|
||||
static void optimizeHtml(QString &text, unsigned int flag = 0, const QColor &backgroundColor = Qt::white, qreal desiredContrast = 1.0);
|
||||
static void optimizeHtml(QString &text, unsigned int flag = 0, const QColor &backgroundColor = Qt::white, qreal desiredContrast = 1.0, int desiredMinimumFontSize = 10);
|
||||
static QString toHtml(QString text, bool realHtml = true);
|
||||
|
||||
static bool makeEmbeddedImage(const QString &fileName, QString &embeddedImage, const int maxPixels);
|
||||
|
Loading…
Reference in New Issue
Block a user