1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

Better RTL support for LocationCompleter and add direction property to dirlist.html

This commit is contained in:
S. Razi Alavizadeh 2013-02-04 15:14:56 +03:30
parent 9f02eecc21
commit e3db93740b
4 changed files with 20 additions and 8 deletions

View File

@ -4,7 +4,7 @@
<style>
html {background: #eeeeee;font: 13px/22px "Helvetica Neue", Helvetica, Arial, sans-serif;color: #525c66;}
html * {font-size: 100%;line-height: 1.6;}
#box {max-width:650px;min-width:400px;overflow:auto;margin: 25px auto 10px auto;padding: 10px 40px;border-width: 20px;-webkit-border-image: url(%BOX-BORDER%) 25;text-align: %LEFT_STR%;}
#box {max-width:650px;min-width:400px;overflow:auto;margin: 25px auto 10px auto;padding: 10px 40px;border-width: 20px;-webkit-border-image: url(%BOX-BORDER%) 25;text-align: %LEFT_STR%;direction: %DIRECTION%;}
h1 {color:#1a4ba4;font-size:120%;margin-bottom:0px;word-wrap:break-word;}
a{text-decoration:none;}
a:hover{text-decoration:underline;}

View File

@ -137,7 +137,7 @@ static bool sizeBiggerThan(const QString &s1, const QString &s2)
return s1.size() > s2.size();
}
void LocationCompleterDelegate::drawHighlightedTextLine(const QRect &rect, QString text, const QString &searchText,
void LocationCompleterDelegate::drawHighlightedTextLine(const QRect &rect, const QString &text, const QString &searchText,
QPainter* painter, const QStyle* style, const QStyleOptionViewItemV4 &option,
const QPalette::ColorRole &role) const
{
@ -204,9 +204,12 @@ void LocationCompleterDelegate::drawHighlightedTextLine(const QRect &rect, QStri
if (!normalPart.isEmpty()) {
int width = normalMetrics.width(normalPart);
const QRect &nRect = adjustRect(rect, QRect(lastRectPos, rect.top(), width, rect.height()));
QRect nRect = adjustRect(rect, QRect(lastRectPos, rect.top(), width, rect.height()));
if (nRect.width() > 0) {
if (text.isRightToLeft()) {
nRect = style->visualRect(Qt::RightToLeft, rect, nRect);
}
painter->setFont(normalFont);
drawTextLine(nRect, normalPart, painter, style, option, role);
@ -216,15 +219,19 @@ void LocationCompleterDelegate::drawHighlightedTextLine(const QRect &rect, QStri
if (!boldPart.isEmpty()) {
int width = boldMetrics.width(boldPart);
const QRect &bRect = adjustRect(rect, QRect(lastRectPos, rect.top(), width, rect.height()));
QRect bRect = adjustRect(rect, QRect(lastRectPos, rect.top(), width, rect.height()));
if (bRect.width() > 0) {
if (text.isRightToLeft()) {
bRect = style->visualRect(Qt::RightToLeft, rect, bRect);
}
painter->setFont(boldFont);
drawTextLine(bRect, boldPart, painter, style, option, role);
// Paint manually line under text instead of using QFont::underline
QRect underlineRect(bRect.left(), bRect.top() + boldMetrics.ascent() + 1,
bRect.width(), boldFont.pointSize() > 8 ? 2 : 1);
painter->fillRect(underlineRect, option.palette.color(role));
lastRectPos += bRect.width();
@ -235,10 +242,12 @@ void LocationCompleterDelegate::drawHighlightedTextLine(const QRect &rect, QStri
const QString &lastText = text.mid(lastEndPos);
int width = normalMetrics.width(lastText);
QRect nRect(lastRectPos, rect.top(), width, rect.height());
QRect nRect = adjustRect(rect, QRect(lastRectPos, rect.top(), width, rect.height()));
if (text.isRightToLeft()) {
nRect = style->visualRect(Qt::RightToLeft, rect, nRect);
}
painter->setFont(normalFont);
drawTextLine(adjustRect(rect, nRect), lastText, painter, style, option, role);
drawTextLine(nRect, lastText, painter, style, option, role);
}
}
}

View File

@ -35,7 +35,7 @@ public:
void drawSwitchToTab(bool enable);
private:
void drawHighlightedTextLine(const QRect &rect, QString text, const QString &searchText,
void drawHighlightedTextLine(const QRect &rect, const QString &text, const QString &searchText,
QPainter* painter, const QStyle* style, const QStyleOptionViewItemV4 &option,
const QPalette::ColorRole &role) const;

View File

@ -614,6 +614,9 @@ void LocationBar::paintEvent(QPaintEvent* event)
QPainter p(this);
QRect cursorRect(cursorXpos, cursorYpos, cursorWidth, cursorHeight);
if (isRightToLeft()) {
cursorRect = style()->visualRect(Qt::RightToLeft, contentsRect, cursorRect);
}
p.fillRect(cursorRect, option.palette.text().color());
return;
}