From 3f4f9abb369233a6dbc255ad0a25d8aa4e6ea680 Mon Sep 17 00:00:00 2001 From: Felix Geyer Date: Sun, 27 May 2012 19:43:34 +0200 Subject: [PATCH] Support RTL layout in LineEdit. --- COPYING | 3 + .../actions/edit-clear-locationbar-ltr.png | Bin 0 -> 793 bytes .../actions/edit-clear-locationbar-rtl.png | Bin 0 -> 579 bytes .../actions/edit-clear-locationbar-rtl.png | Bin 750 -> 0 bytes src/gui/LineEdit.cpp | 55 +++++++++++++----- src/gui/LineEdit.h | 26 ++++++--- 6 files changed, 62 insertions(+), 22 deletions(-) create mode 100644 share/icons/application/16x16/actions/edit-clear-locationbar-ltr.png create mode 100644 share/icons/application/16x16/actions/edit-clear-locationbar-rtl.png delete mode 100644 share/icons/application/22x22/actions/edit-clear-locationbar-rtl.png diff --git a/COPYING b/COPYING index c19ee7353..e6c759d82 100644 --- a/COPYING +++ b/COPYING @@ -20,6 +20,7 @@ Source: http://www.keepassx.org/ Copyright: 2010-2012, Felix Geyer 2011-2012, Florian Geyer + 2007, Trolltech ASA License: GPL-2 or GPL-3 Files: share/icons/database/*.png @@ -59,6 +60,8 @@ Files: share/icons/application/*/actions/application-exit.png, share/icons/application/*/actions/document-open.png, share/icons/application/*/actions/document-save.png, share/icons/application/*/actions/document-save-as.png, + share/icons/application/*/actions/edit-clear-locationbar-ltr.png, + share/icons/application/*/actions/edit-clear-locationbar-rtl.png, share/icons/application/*/actions/system-search.png, share/icons/application/*/status/dialog-error.png, share/icons/application/*/status/dialog-information.png, diff --git a/share/icons/application/16x16/actions/edit-clear-locationbar-ltr.png b/share/icons/application/16x16/actions/edit-clear-locationbar-ltr.png new file mode 100644 index 0000000000000000000000000000000000000000..97c8e38a760e11419c1d26730ebcf8709399aef1 GIT binary patch literal 793 zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd4mJh`2Kmqb6B!to9(cMqhE&{Idg-qBXhcL`;a~Rfr!+rKOVEqv!A8hk3QFLw13-6mF17pA|^cOy*y1yQKE8c+2Yr3 zpZGVZNLQ#F2ym{^u_GobZI(YhY^}Y6DzUMX{?k8<@ol$A4{Oa}V zr?&H~_HA6*n4ed7VEY!EC$ry~e`@YOTvK6iM0GL?A0Hos;KN_Mtbal+WSZW+V_<2v zy>S0NyXe&I7CWBI^5J?eCMKRx_U-K3bAJDqTuqbQ8l^k2y7XPg?YCVPbG}`4D8GK> z!w2JFn}4i(?(xa#bug%et1`TOoBN<>_p!fq^1o{AjJ~9BFgG%^IWbG{u(f7+WPwW`=9*usc6zU z_RpV9oqc_K1LETTX?rFHDn7~lv`B3-=l1Q}IfH)x{w>jc^uvb_0S;Nk#lat{_8!UG zo?PblO+@<1_V@7*V+4H{glNUT_*zwBA(N7w%{_DTX5$nyGqaXozpB=(T`OuM$8Q)W z9k?)H4|9X|0S^_S2bFb7+S=WJ6()MH%ydy|Jagg%N7mM;gBd1^4kiekNh@BoV}}Ie z0{IzNu7pfW5n?!JedFfMgNqj{-?@GJ@Z-nHckbRzojP%z;F2KCi6>KLOq%qmF;__9 z*Fm8@OM=~Q*(I)BzqZz`emVd3>(^Pi9)H}SF#R;AZF|zjAG!=351YK!HhuZ>MKjjZ zuE=^qZTawy>(?iSteUdsQ;LNN$IhKQmCA%Q60{Q=!%a=g zFFq}su$IkyY&_T5eEP+&1*^RBLswsYZ){}r ztf;8yS*X@io4aRf(!!q2aa$aDm*iy0y>mRbA=&)Y6tRVBx$G|xUWGgIk@Y*p;R zmnB`RR`=SxZCRXuF2}G~Z1qgzJB9^ev!||KvEoPa)A<=|9HxHFi>zi~U|{fc^>bP0 Hl+XkKk}rSh literal 0 HcmV?d00001 diff --git a/share/icons/application/16x16/actions/edit-clear-locationbar-rtl.png b/share/icons/application/16x16/actions/edit-clear-locationbar-rtl.png new file mode 100644 index 0000000000000000000000000000000000000000..85e31eb30a0ea0da288a4dbb08c22d3a57158c70 GIT binary patch literal 579 zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd4rT@h1`S>QUw+tS{eRP~2eQ9aU+%(G%YnI9wTsRWM*%ZNaK=&}CHcv|0 z_T#e`%U?gfG--39K&1k;;Rn1*{N9J gCGPb1@LKbjA{hy$rawOz7#J8lUHx3vIVCg!0O@?)asU7T literal 0 HcmV?d00001 diff --git a/share/icons/application/22x22/actions/edit-clear-locationbar-rtl.png b/share/icons/application/22x22/actions/edit-clear-locationbar-rtl.png deleted file mode 100644 index 80ff24af5698684b79ba8855d207067337d4347c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 750 zcmeAS@N?(olHy`uVBq!ia0y~yU=Rag4mJh`h9g^YtQi=XwtBiahE&{oJLR;0u%k$O z?!qq<->uSYN?5t=X`uGRYhFR?beBx?;9a?eDNHKY(aTBj(v?GehnSoU5}E(AN{8#* zFnxK*W5QG+A*Mvv1x^*MUk;uxPA@bMS;Z~vYjbk?Z0quO=IPJQoH1pnZ~6adzeCRE zn_nJ3ejLB^xUYu8tj)!j_p6xAK3jJBa9c=yz5TQ2&jtIB3w9qB=yfx+vFYjT!W2cdcW6P%(!st)~N!kxfz+6js_A(-o4W^n#t3z@RWVltXWMbQ=FosrC+Q)Dq4Lu5z@VU_r)9#z@+)R&=!RY{da-fKmX@zy^L=g|xtUO2 z@Zv4^#+d=%rWCTjdi{QL3YVNfm)%UCY3q!y9lV&M9;kok{JcenUpt0>=Pud*=E#NJ zjxFqmDjpRrn)&O34|gYPrSaO^<*${sPrv#)n}JQ4x#O7I2RpyxRVf_#hxdNi|7zL$ z^NyR(JQIID{dMMAd(Ej{A`0%ut3GaD@5`mBxSQ$Z{@RQG8BViY`uItF)&vFy1_n=8 KKbLh*2~7Y`LSNtj diff --git a/src/gui/LineEdit.cpp b/src/gui/LineEdit.cpp index e344899c6..89b420471 100644 --- a/src/gui/LineEdit.cpp +++ b/src/gui/LineEdit.cpp @@ -1,16 +1,26 @@ -/**************************************************************************** -** -** Copyright (c) 2007 Trolltech ASA -** -** Use, modification and distribution is allowed without limitation, -** warranty, liability or support of any kind. -** -****************************************************************************/ +/* + * Copyright (C) 2007 Trolltech ASA + * Copyright (C) 2012 Felix Geyer + * Copyright (C) 2012 Florian Geyer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 or (at your option) + * version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ #include "LineEdit.h" -#include #include +#include #include "core/DataPath.h" @@ -19,7 +29,18 @@ LineEdit::LineEdit(QWidget* parent) { m_clearButton = new QToolButton(this); m_clearButton->setObjectName("clearButton"); - QIcon icon = dataPath()->icon("actions", "edit-clear-locationbar-rtl"); + + QIcon icon; + QString iconNameDirected = QString("edit-clear-locationbar-").append( + (layoutDirection() == Qt::LeftToRight) ? "rtl" : "ltr"); + icon = QIcon::fromTheme(iconNameDirected); + if (icon.isNull()) { + icon = QIcon::fromTheme("edit-clear"); + if (icon.isNull()) { + icon = dataPath()->icon("actions", iconNameDirected, false); + } + } + m_clearButton->setIcon(icon); m_clearButton->setCursor(Qt::ArrowCursor); m_clearButton->setStyleSheet("QToolButton { border: none; padding: 0px; }"); @@ -36,12 +57,18 @@ LineEdit::LineEdit(QWidget* parent) void LineEdit::resizeEvent(QResizeEvent* event) { - Q_UNUSED(event); - QSize sz = m_clearButton->sizeHint(); int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); - m_clearButton->move(rect().right() - frameWidth - sz.width(), - (rect().bottom() + 1 - sz.height())/2); + int y = (rect().bottom() + 1 - sz.height()) / 2; + + if (layoutDirection() == Qt::LeftToRight) { + m_clearButton->move(rect().right() - frameWidth - sz.width(), y); + } + else { + m_clearButton->move(rect().left() + frameWidth, y); + } + + QLineEdit::resizeEvent(event); } void LineEdit::updateCloseButton(const QString& text) diff --git a/src/gui/LineEdit.h b/src/gui/LineEdit.h index 85ddb7c76..802180f12 100644 --- a/src/gui/LineEdit.h +++ b/src/gui/LineEdit.h @@ -1,11 +1,21 @@ -/**************************************************************************** -** -** Copyright (c) 2007 Trolltech ASA -** -** Use, modification and distribution is allowed without limitation, -** warranty, liability or support of any kind. -** -****************************************************************************/ +/* + * Copyright (C) 2007 Trolltech ASA + * Copyright (C) 2012 Felix Geyer + * Copyright (C) 2012 Florian Geyer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 or (at your option) + * version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ #ifndef KEEPASSX_LINEEDIT_H #define KEEPASSX_LINEEDIT_H