Commit 265de2a8 authored by David Jarvie's avatar David Jarvie
Browse files

Layout fixes for right-to-left direction

parent 17461471
Pipeline #71287 failed with stage
in 4 minutes and 25 seconds
KAlarm Change Log
=== Version 3.3.0 (KDE Applications 21.08) --- 16 July 2021 ===
=== Version 3.3.0 (KDE Applications 21.08) --- 21 July 2021 ===
* Add date selector option to enable alarm list view to be filtered.
* Show hamburger menu when menu bar is hidden, to allow access to all options.
* Fix crash when context menu is requested after toolbar has been edited.
* Fix crash when alarm message is shown on a multiple screen system using Wayland [KDE Bug 439853]
* Fixes to dialogue layouts when using right-to-left languages.
=== Version 3.2.2 (KDE Applications 21.04.2) --- 26 May 2021 ===
* In audio alarm edit dialogue, don't show file name in encoded format [KDE Bug 437676]
......
/*
* latecancel.cpp - widget to specify cancellation if late
* Program: kalarm
* SPDX-FileCopyrightText: 2004-2020 David Jarvie <djarvie@kde.org>
* SPDX-FileCopyrightText: 2004-2021 David Jarvie <djarvie@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
......@@ -64,7 +64,11 @@ LateCancelSelector::LateCancelSelector(bool allowHourMinute, QWidget* parent)
hlayout->addWidget(mTimeSelector, 0, Qt::AlignLeft);
hlayout = new QHBoxLayout();
hlayout->setContentsMargins(CheckBox::textIndent(mCheckbox), 0, 0, 0);
const int indent = CheckBox::textIndent(mCheckbox);
if (layoutDirection() == Qt::LeftToRight)
hlayout->setContentsMargins(indent, 0, 0, 0);
else
hlayout->setContentsMargins(0, 0, indent, 0);
topLayout->addLayout(hlayout);
mAutoClose = new CheckBox(i18n_chk_AutoCloseWin(), this);
connect(mAutoClose, &CheckBox::toggled, this, &LateCancelSelector::changed);
......
/*
* checkbox.cpp - check box with read-only option
* Program: kalarm
* SPDX-FileCopyrightText: 2002-2005, 2020 David Jarvie <djarvie@kde.org>
* SPDX-FileCopyrightText: 2002-2021 David Jarvie <djarvie@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "checkbox.h"
#include "kalarm_debug.h"
#include <QMouseEvent>
#include <QKeyEvent>
#include <QStyleOptionButton>
......@@ -70,7 +72,8 @@ int CheckBox::textIndent(QWidget* widget)
opt.initFrom(&cb);
style = cb.style();
}
return style->subElementRect(QStyle::SE_CheckBoxContents, &opt).left();
const QRect contents = style->subElementRect(QStyle::SE_CheckBoxContents, &opt);
return (widget->layoutDirection() == Qt::LeftToRight) ? contents.left() : opt.rect.right() - contents.right();
}
/******************************************************************************
......
/*
* packedlayout.cpp - layout to pack items into rows
* Program: kalarm
* SPDX-FileCopyrightText: 2007-2020 David Jarvie <djarvie@kde.org>
* SPDX-FileCopyrightText: 2007-2021 David Jarvie <djarvie@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "packedlayout.h"
#include "kalarm_debug.h"
#include <QWidget>
PackedLayout::PackedLayout(QWidget* parent, Qt::Alignment alignment)
: QLayout(parent)
......@@ -48,8 +51,8 @@ int PackedLayout::verticalSpacing() const
}
/******************************************************************************
* Inserts a button into the group.
*/
* Inserts a button into the group.
*/
void PackedLayout::addItem(QLayoutItem* item)
{
mWidthCached = 0;
......@@ -130,7 +133,7 @@ int PackedLayout::arrange(const QRect& rect, bool set) const
// Left aligned: no position adjustment needed
// Set the positions of all the layout items
for (int i = 0; i < count; ++i)
items[i]->setGeometry(posn[i]);
items[i]->setGeometry(alignRect(rect, posn[i]));
}
else
{
......@@ -148,13 +151,13 @@ int PackedLayout::arrange(const QRect& rect, bool set) const
case Qt::AlignJustify:
if (n == 1)
{
items[i]->setGeometry(posn[i]);
items[i]->setGeometry(alignRect(rect, posn[i]));
++i;
}
else if (n > 1)
{
for (int j = 0; i < last; ++j, ++i)
items[i]->setGeometry(QRect(QPoint(posn[i].x() + (free * j)/(n - 1), y), posn[i].size()));
items[i]->setGeometry(alignRect(rect, QRect(QPoint(posn[i].x() + (free * j)/(n - 1), y), posn[i].size())));
}
break;
case Qt::AlignHCenter:
......@@ -163,7 +166,7 @@ int PackedLayout::arrange(const QRect& rect, bool set) const
Q_FALLTHROUGH();
case Qt::AlignRight:
for ( ; i < last; ++i)
items[i]->setGeometry(QRect(QPoint(posn[i].x() + free, y), posn[i].size()));
items[i]->setGeometry(alignRect(rect, QRect(QPoint(posn[i].x() + free, y), posn[i].size())));
break;
default:
break;
......@@ -174,4 +177,15 @@ int PackedLayout::arrange(const QRect& rect, bool set) const
return y + yrow - rect.y();
}
/******************************************************************************
* Adjust an item's geometry if using right-to-left alignment.
*/
QRect PackedLayout::alignRect(const QRect& rect, const QRect& itemRect) const
{
QRect result(itemRect);
if (parentWidget()->layoutDirection() == Qt::RightToLeft)
result.moveRight(rect.right() - (itemRect.left() - rect.left()));
return result;
}
// vim: et sw=4:
/*
* packedlayout.h - layout to pack items into rows
* Program: kalarm
* SPDX-FileCopyrightText: 2007, 2020 David Jarvie <djarvie@kde.org>
* SPDX-FileCopyrightText: 2007-2021 David Jarvie <djarvie@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
......@@ -47,6 +47,8 @@ public:
private:
int arrange(const QRect&, bool set) const;
QRect alignRect(const QRect& rect, const QRect& itemRect) const;
QList<QLayoutItem*> mItems;
Qt::Alignment mAlignment;
......
......@@ -1282,7 +1282,8 @@ EditPrefTab::EditPrefTab(StackedScrollGroup* scrollGroup)
auto vbox = new QVBoxLayout(febBox);
vbox->setContentsMargins(0, 0, 0, 0);
label = new QLabel(i18nc("@label", "In non-leap years, repeat yearly February 29th alarms on:"));
label->setAlignment(Qt::AlignLeft);
// *** Workaround for the bug that QLabel doesn't align correctly in right-to-left mode. ***
label->setAlignment((layoutDirection() == Qt::LeftToRight ? Qt::AlignLeft : Qt::AlignRight) | Qt::AlignAbsolute);
label->setWordWrap(true);
vbox->addWidget(label);
box = new QHBoxLayout();
......
/*
* reminder.cpp - reminder setting widget
* Program: kalarm
* SPDX-FileCopyrightText: 2003-2020 David Jarvie <djarvie@kde.org>
* SPDX-FileCopyrightText: 2003-2021 David Jarvie <djarvie@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
......@@ -58,7 +58,11 @@ Reminder::Reminder(const QString& reminderWhatsThis, const QString& valueWhatsTh
{
auto layout = new QHBoxLayout();
layout->setContentsMargins(0, 0, 0, 0);
layout->setContentsMargins(CheckBox::textIndent(mTime), 0, 0, 0);
const int indent = CheckBox::textIndent(mTime);
if (layoutDirection() == Qt::LeftToRight)
layout->setContentsMargins(indent, 0, 0, 0);
else
layout->setContentsMargins(0, 0, indent, 0);
topLayout->addLayout(layout);
mOnceOnly = new CheckBox(i18n_chk_FirstRecurrenceOnly(), this);
mOnceOnly->setFixedSize(mOnceOnly->sizeHint());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment