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

LineEdit class uses a new layouting strategy for support RTL direction. theme changed for fulfillment this strategy.

This commit is contained in:
S. Razi Alavizadeh 2012-08-11 15:43:37 +04:30 committed by nowrep
parent 45d8cbae22
commit 341739cf59
19 changed files with 94 additions and 76 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 645 B

View File

@ -126,7 +126,8 @@ IconProvider
border-image: url(images/lineedit-bg.png);
border-width:4;
color:black;
padding-left: 28px;
padding-right: 0px;
padding-left: 0px;
padding-top: -2px;
qproperty-fixedheight: 27;
}
@ -204,7 +205,8 @@ IconProvider
border-image: url(images/lineedit-bg.png);
border-width:4;
color:black;
padding-left: 35px;
padding-right: 0px;
padding-left: 0px;
padding-top: -2px;
qproperty-fixedheight: 27;
}

View File

@ -7,8 +7,3 @@
{
qproperty-multiIcon: url(images/navigation-forward.png);
}
#locationbar-goicon
{
qproperty-pixmap: url(images/gotoaddress_rtl.png);
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 645 B

View File

@ -136,7 +136,8 @@ IconProvider
border-image: url(images/lineedit-bg.png);
border-width:4;
color:black;
padding-left: 33px;
padding-right: -2px;
padding-left: -2px;
qproperty-fixedheight: 25;
}
@ -187,13 +188,15 @@ IconProvider
border-image: url(images/lineedit-bg.png);
border-width:4;
color:black;
padding-left: 33px;
padding-right: -2px;
padding-left: -2px;
qproperty-fixedheight: 25;
}
#websearchbar-searchbutton
{
margin-bottom:2px;
/* margin-bottom:2px; */
margin-left: 2px;
qproperty-pixmap: url(images/search.png);
}

View File

@ -7,8 +7,3 @@
{
qproperty-icon: url(images/navigation-forward.png);
}
#locationbar-goicon
{
qproperty-pixmap: url(images/gotoaddress_rtl.png);
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 645 B

View File

@ -116,7 +116,8 @@ IconProvider
#locationbar
{
border-width:4;
padding-left: 22px;
padding-right: -4px;
padding-left: -4px;
padding-top: -2px;
qproperty-fixedheight: 27;
}
@ -187,7 +188,8 @@ IconProvider
#websearchbar
{
border-width:4;
padding-left: 30px;
padding-right: -4px;
padding-left: -4px;
padding-top: -2px;
qproperty-fixedheight: 27;
}

View File

@ -10,7 +10,3 @@
qproperty-fallbackIcon: url(images/go-next.png);
}
#locationbar-goicon
{
qproperty-pixmap: url(images/gotoaddress_rtl.png);
}

View File

@ -121,7 +121,8 @@ IconProvider
border-image: url(images/lineedit-bg.png);
border-width:4;
color:black;
padding-left: 35px;
padding-right: -5px;
padding-left: -5px;
padding-top: -2px;
qproperty-fixedheight: 23;
}
@ -197,7 +198,8 @@ IconProvider
background: transparent;
border-image: url(images/lineedit-bg.png);
border-width: 4;
padding-left: 35px;
padding-right: -4px;
padding-left: -4px;
padding-top: -2px;
color:black;
qproperty-fixedheight: 23;

View File

@ -12,8 +12,3 @@
{
qproperty-multiIcon: url(images/tabs-list-button_rtl.png);
}
#locationbar-goicon
{
qproperty-pixmap: url(images/gotoaddress_rtl.png);
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 645 B

View File

@ -131,7 +131,8 @@ IconProvider
border-image: url(images/lineedit-bg.png);
border-width:4;
color:black;
padding-left: 28px;
padding-right: -4px;
padding-left: -4px;
qproperty-fixedheight: 22;
}
@ -208,7 +209,8 @@ IconProvider
border-image: url(images/lineedit-bg.png);
border-width:4;
color:black;
padding-left: 30px;
padding-right: -4px;
padding-left: -4px;
qproperty-fixedheight: 22;
}

View File

@ -17,8 +17,3 @@
{
qproperty-multiIcon: url(images/tabbar-addtab_rtl.png);
}
#locationbar-goicon
{
qproperty-pixmap: url(images/gotoaddress_rtl.png);
}

View File

@ -47,10 +47,20 @@ void LineEdit::setLeftMargin(int margin)
void LineEdit::init()
{
////we use setTextMargins() instead of padding property, and we should
//// uncomment following line or just update padding property of LineEdit's
//// subclasses in all themes and use same value for padding-left and padding-right,
//// with this new implementation padding-left and padding-right show padding from
//// edges of m_leftWidget and m_rightWidget.
//setStyleSheet(QString("QLineEdit{padding-left: 0; padding-right: 0;}"));
mainLayout = new QHBoxLayout(this);
mainLayout->setContentsMargins(0, 0, 0, 0);
mainLayout->setSpacing(0);
m_leftWidget = new SideWidget(this);
m_leftWidget->resize(0, 0);
m_leftLayout = new QHBoxLayout(m_leftWidget);
m_leftLayout->setContentsMargins(0, 0, 0, 0);
m_leftLayout->setContentsMargins(0, 0, 2, 0);
if (isRightToLeft()) {
m_leftLayout->setDirection(QBoxLayout::RightToLeft);
@ -69,10 +79,15 @@ void LineEdit::init()
else {
m_rightLayout->setDirection(QBoxLayout::LeftToRight);
}
m_rightLayout->setContentsMargins(0, 0, 0, 0);
m_rightLayout->setContentsMargins(0, 0, 2, 0);
QSpacerItem* horizontalSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
m_rightLayout->addItem(horizontalSpacer);
mainLayout->addWidget(m_leftWidget, 0, Qt::AlignVCenter|Qt::AlignLeft);
mainLayout->addItem(horizontalSpacer);
mainLayout->addWidget(m_rightWidget, 0, Qt::AlignVCenter|Qt::AlignRight);
//by this we undo reversing of layout when direction is RTL. //TODO: don't do this and show reversed icon when needed
mainLayout->setDirection(isRightToLeft() ? QBoxLayout::RightToLeft : QBoxLayout::LeftToRight);
setWidgetSpacing(3);
connect(m_leftWidget, SIGNAL(sizeHintChanged()),
@ -84,11 +99,14 @@ void LineEdit::init()
bool LineEdit::event(QEvent* event)
{
if (event->type() == QEvent::LayoutDirectionChange) {
//by this we undo reversing of layout when direction is RTL.
if (isRightToLeft()) {
mainLayout->setDirection(QBoxLayout::RightToLeft);
m_leftLayout->setDirection(QBoxLayout::RightToLeft);
m_rightLayout->setDirection(QBoxLayout::RightToLeft);
}
else {
mainLayout->setDirection(QBoxLayout::LeftToRight);
m_leftLayout->setDirection(QBoxLayout::LeftToRight);
m_rightLayout->setDirection(QBoxLayout::LeftToRight);
}
@ -101,16 +119,11 @@ void LineEdit::addWidget(QWidget* widget, WidgetPosition position)
if (!widget) {
return;
}
bool rtl = isRightToLeft();
if (rtl) {
position = (position == LeftSide) ? RightSide : LeftSide;
}
if (position == LeftSide) {
m_leftLayout->addWidget(widget);
}
else {
m_rightLayout->insertWidget(1, widget);
m_rightLayout->addWidget(widget);
}
}
@ -157,49 +170,49 @@ void LineEdit::updateTextMargins()
{
int left;
if (m_leftMargin == 0) {
left = textMargin(LineEdit::LeftSide);
left = m_leftWidget->sizeHint().width();
}
else {
left = m_leftMargin;
}
int right = textMargin(LineEdit::RightSide) + 3;
int right = m_rightWidget->sizeHint().width();
int top = 0;
int bottom = 0;
setTextMargins(left, top, right, bottom);
updateSideWidgetLocations();
// updateSideWidgetLocations();
}
void LineEdit::updateSideWidgetLocations()
{
QStyleOptionFrameV2 opt;
initStyleOption(&opt);
QRect textRect = style()->subElementRect(QStyle::SE_LineEditContents, &opt, this);
int spacing = m_rightLayout->spacing();
textRect.adjust(spacing, 0, -spacing, 0);
//void LineEdit::updateSideWidgetLocations()
//{
// QStyleOptionFrameV2 opt;
// initStyleOption(&opt);
// QRect textRect = style()->subElementRect(QStyle::SE_LineEditContents, &opt, this);
// int spacing = m_rightLayout->spacing();
// textRect.adjust(spacing, 0, -spacing, 0);
int left = textMargin(LineEdit::LeftSide);
// int left = textMargin(LineEdit::LeftSide);
int midHeight = textRect.center().y() + 1;
// int midHeight = textRect.center().y() + 1;
if (m_leftLayout->count() > 0) {
int leftHeight = midHeight - m_leftWidget->height() / 2;
int leftWidth = m_leftWidget->width();
if (leftWidth == 0) {
leftHeight = midHeight - m_leftWidget->sizeHint().height() / 2;
}
m_leftWidget->move(textRect.x(), leftHeight);
}
textRect.setX(left);
textRect.setY(midHeight - m_rightWidget->sizeHint().height() / 2);
textRect.setHeight(m_rightWidget->sizeHint().height());
m_rightWidget->setGeometry(textRect);
}
// if (m_leftLayout->count() > 0) {
// int leftHeight = midHeight - m_leftWidget->height() / 2;
// int leftWidth = m_leftWidget->width();
// if (leftWidth == 0) {
// leftHeight = midHeight - m_leftWidget->sizeHint().height() / 2;
// }
// m_leftWidget->move(textRect.x(), leftHeight);
// }
// textRect.setX(left);
// textRect.setY(midHeight - m_rightWidget->sizeHint().height() / 2);
// textRect.setHeight(m_rightWidget->sizeHint().height());
// m_rightWidget->setGeometry(textRect);
//}
void LineEdit::resizeEvent(QResizeEvent* event)
{
updateSideWidgetLocations();
QLineEdit::resizeEvent(event);
}
//void LineEdit::resizeEvent(QResizeEvent* event)
//{
// updateSideWidgetLocations();
// QLineEdit::resizeEvent(event);
//}
QString LineEdit::inactiveText() const
{

View File

@ -75,17 +75,18 @@ public slots:
void updateTextMargins();
protected:
void resizeEvent(QResizeEvent* event);
// void resizeEvent(QResizeEvent* event);
bool event(QEvent* event);
private:
void init();
void updateSideWidgetLocations();
// void updateSideWidgetLocations();
SideWidget* m_leftWidget;
SideWidget* m_rightWidget;
QHBoxLayout* m_leftLayout;
QHBoxLayout* m_rightLayout;
QHBoxLayout* mainLayout;
QString m_inactiveText;
int m_leftMargin;
};

View File

@ -276,6 +276,10 @@ void MainApplication::loadSettings()
cssFile.open(QFile::ReadOnly);
QString css = cssFile.readAll();
cssFile.close();
//resetting style sheet
//it seems the css properties of previous theme that was not setted
// in the new theme are applied to new theme! for this we reset all properties here!!
setStyleSheet("");
#ifdef Q_WS_X11
if (QFile(m_activeThemePath + "linux.css").exists()) {
cssFile.setFileName(m_activeThemePath + "linux.css");

View File

@ -59,6 +59,13 @@ LocationBar::LocationBar(QupZilla* mainClass)
m_siteIcon = new SiteIcon(this);
DownIcon* down = new DownIcon(this);
////RTL Support
////if we don't add 'm_siteIcon' by following code, then we should use suitable padding-left value
//// but then, when typing RTL text the layout dynamically changed and within RTL layout direction
//// padding-left is equivalent to padding-right and vice versa, and because style sheet is
//// not changed dynamically this create padding problems.
addWidget(m_siteIcon, LineEdit::LeftSide);
addWidget(down, LineEdit::RightSide);
addWidget(m_bookmarkIcon, LineEdit::RightSide);
addWidget(m_goIcon, LineEdit::RightSide);

View File

@ -64,6 +64,12 @@ WebSearchBar::WebSearchBar(QupZilla* mainClass, QWidget* parent)
m_boxSearchType = new ButtonWithMenu(this);
m_boxSearchType->setObjectName("websearchbar-searchprovider-comobobox");
//RTL Support
////if we don't add 'm_boxSearchType' by following code, then we should use suitable padding-left value
//// but then, when typing RTL text the layout dynamically changed and within RTL layout direction
//// padding-left is equivalent to padding-right and vice versa, and because style sheet is
//// not changed dynamically this create padding problems.
addWidget(m_boxSearchType, LineEdit::LeftSide);
addWidget(m_buttonSearch, LineEdit::RightSide);