summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2018-01-29 20:49:23 +0100
committerLiang Qi <liang.qi@qt.io>2018-01-29 20:49:24 +0100
commit27e8612fa415522b52e03de7430fbe2e8fff02e4 (patch)
tree5b7ede058e8183ba901c504cc8abfad767474abb /src
parent11f6c646967c61e3eac6302a2d4ea8f30a41beff (diff)
parent3adfcbf1ed9b63c3ce41d7417658db3836fd3530 (diff)
Merge remote-tracking branch 'origin/5.9' into 5.10
Diffstat (limited to 'src')
-rw-r--r--src/android/jar/src/org/qtproject/qt5/android/CursorHandle.java27
-rw-r--r--src/gui/kernel/qplatforminputcontext.cpp2
-rw-r--r--src/plugins/platforms/android/qandroidinputcontext.cpp58
-rw-r--r--src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm2
-rw-r--r--src/widgets/itemviews/qheaderview.cpp88
-rw-r--r--src/widgets/itemviews/qheaderview_p.h11
-rw-r--r--src/widgets/itemviews/qtreeview.cpp2
-rw-r--r--src/widgets/util/qsystemtrayicon.cpp7
8 files changed, 146 insertions, 51 deletions
diff --git a/src/android/jar/src/org/qtproject/qt5/android/CursorHandle.java b/src/android/jar/src/org/qtproject/qt5/android/CursorHandle.java
index e6814c202d..4f2c06644d 100644
--- a/src/android/jar/src/org/qtproject/qt5/android/CursorHandle.java
+++ b/src/android/jar/src/org/qtproject/qt5/android/CursorHandle.java
@@ -51,6 +51,7 @@ import android.graphics.drawable.Drawable;
import android.view.MotionEvent;
import android.widget.PopupWindow;
import android.app.Activity;
+import android.util.TypedValue;
import android.view.ViewTreeObserver;
/* This view represents one of the handle (selection or cursor handle) */
@@ -58,8 +59,9 @@ class CursorView extends ImageView
{
private CursorHandle mHandle;
// The coordinare which where clicked
- private int m_offsetX;
- private int m_offsetY;
+ private float m_offsetX;
+ private float m_offsetY;
+ private boolean m_pressed = false;
CursorView (Context context, CursorHandle handle) {
super(context);
@@ -76,21 +78,23 @@ class CursorView extends ImageView
public boolean onTouchEvent(MotionEvent ev) {
switch (ev.getActionMasked()) {
case MotionEvent.ACTION_DOWN: {
- m_offsetX = Math.round(ev.getRawX());
- m_offsetY = Math.round(ev.getRawY());
+ m_offsetX = ev.getRawX();
+ m_offsetY = ev.getRawY() + getHeight() / 2;
+ m_pressed = true;
break;
}
case MotionEvent.ACTION_MOVE: {
- mHandle.updatePosition(Math.round(ev.getRawX()) - m_offsetX,
- Math.round(ev.getRawY()) - m_offsetY);
+ if (!m_pressed)
+ return false;
+ mHandle.updatePosition(Math.round(ev.getRawX() - m_offsetX),
+ Math.round(ev.getRawY() - m_offsetY));
break;
}
case MotionEvent.ACTION_UP:
- break;
-
case MotionEvent.ACTION_CANCEL:
+ m_pressed = false;
break;
}
return true;
@@ -113,6 +117,7 @@ public class CursorHandle implements ViewTreeObserver.OnPreDrawListener
private int m_lastY;
int tolerance;
private boolean m_rtl;
+ int m_yShift;
public CursorHandle(Activity activity, View layout, int id, int attr, boolean rtl) {
m_activity = activity;
@@ -121,7 +126,8 @@ public class CursorHandle implements ViewTreeObserver.OnPreDrawListener
m_layout = layout;
DisplayMetrics metrics = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
- tolerance = Math.round(2 * metrics.density);
+ m_yShift = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM, 1f, metrics);
+ tolerance = Math.min(1, (int)(m_yShift / 2f));
m_lastX = m_lastY = -1 - tolerance;
m_rtl = rtl;
}
@@ -158,7 +164,7 @@ public class CursorHandle implements ViewTreeObserver.OnPreDrawListener
m_layout.getLocationOnScreen(location);
int x2 = x + location[0];
- int y2 = y + location[1];
+ int y2 = y + location[1] + m_yShift;
if (m_id == QtNative.IdCursorHandle) {
x2 -= m_cursorView.getWidth() / 2 ;
@@ -187,6 +193,7 @@ public class CursorHandle implements ViewTreeObserver.OnPreDrawListener
// The handle was dragged by a given relative position
public void updatePosition(int x, int y) {
+ y -= m_yShift;
if (Math.abs(m_lastX - x) > tolerance || Math.abs(m_lastY - y) > tolerance) {
QtNative.handleLocationChanged(m_id, x + m_posX, y + m_posY);
m_lastX = x;
diff --git a/src/gui/kernel/qplatforminputcontext.cpp b/src/gui/kernel/qplatforminputcontext.cpp
index 3f59116e9a..9771e6ba11 100644
--- a/src/gui/kernel/qplatforminputcontext.cpp
+++ b/src/gui/kernel/qplatforminputcontext.cpp
@@ -287,6 +287,8 @@ void QPlatformInputContext::setSelectionOnFocusObject(const QPointF &anchorPos,
if (success) {
int cursor = QInputMethod::queryFocusObject(Qt::ImCursorPosition, cursorPos * mapToLocal).toInt(&success);
if (success) {
+ if (anchor == cursor && anchorPos != cursorPos)
+ return;
QList<QInputMethodEvent::Attribute> imAttributes;
imAttributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::Selection, anchor, cursor - anchor, QVariant()));
QInputMethodEvent event(QString(), imAttributes);
diff --git a/src/plugins/platforms/android/qandroidinputcontext.cpp b/src/plugins/platforms/android/qandroidinputcontext.cpp
index fe4c5be4cb..f548a1fa96 100644
--- a/src/plugins/platforms/android/qandroidinputcontext.cpp
+++ b/src/plugins/platforms/android/qandroidinputcontext.cpp
@@ -438,6 +438,16 @@ QAndroidInputContext::QAndroidInputContext()
QObject::connect(QGuiApplication::inputMethod(), &QInputMethod::cursorRectangleChanged,
this, &QAndroidInputContext::updateSelectionHandles);
+ QObject::connect(QGuiApplication::inputMethod(), &QInputMethod::anchorRectangleChanged,
+ this, &QAndroidInputContext::updateSelectionHandles);
+ QObject::connect(QGuiApplication::inputMethod(), &QInputMethod::inputItemClipRectangleChanged, this, [this]{
+ auto im = qGuiApp->inputMethod();
+ if (!im->inputItemClipRectangle().contains(im->anchorRectangle()) ||
+ !im->inputItemClipRectangle().contains(im->cursorRectangle())) {
+ m_cursorHandleShown = CursorHandleNotShown;
+ updateSelectionHandles();
+ }
+ });
}
QAndroidInputContext::~QAndroidInputContext()
@@ -595,27 +605,63 @@ void QAndroidInputContext::handleLocationChanged(int handleId, int x, int y)
double pixelDensity = window
? QHighDpiScaling::factor(window)
: QHighDpiScaling::factor(QtAndroid::androidPlatformIntegration()->screen());
- QPoint point(x / pixelDensity, y / pixelDensity);
- y -= leftRect.width() / 2;
+ QPointF point(x / pixelDensity, y / pixelDensity);
+ point.setY(point.y() - leftRect.width() / 2);
if (handleId == 1) {
setSelectionOnFocusObject(point, point);
return;
}
- QInputMethodQueryEvent query(Qt::ImCursorPosition | Qt::ImAnchorPosition);
+ QInputMethodQueryEvent query(Qt::ImCursorPosition | Qt::ImAnchorPosition | Qt::ImCurrentSelection);
QCoreApplication::sendEvent(m_focusObject, &query);
int cpos = query.value(Qt::ImCursorPosition).toInt();
int anchor = query.value(Qt::ImAnchorPosition).toInt();
-
+ bool rtl = query.value(Qt::ImCurrentSelection).toString().isRightToLeft();
auto rightRect = im->anchorRectangle();
if (cpos > anchor)
std::swap(leftRect, rightRect);
+ auto checkLeftHandle = [&rightRect](QPointF &handlePos) {
+ if (handlePos.y() > rightRect.center().y())
+ handlePos.setY(rightRect.center().y()); // adjust Y handle pos
+ if (handlePos.y() >= rightRect.y() && handlePos.y() <= rightRect.bottom() && handlePos.x() >= rightRect.x())
+ return false; // same line and wrong X pos ?
+ return true;
+ };
+
+ auto checkRtlRightHandle = [&rightRect](QPointF &handlePos) {
+ if (handlePos.y() > rightRect.center().y())
+ handlePos.setY(rightRect.center().y()); // adjust Y handle pos
+ if (handlePos.y() >= rightRect.y() && handlePos.y() <= rightRect.bottom() && rightRect.x() >= handlePos.x())
+ return false; // same line and wrong X pos ?
+ return true;
+ };
+
+ auto checkRightHandle = [&leftRect](QPointF &handlePos) {
+ if (handlePos.y() < leftRect.center().y())
+ handlePos.setY(leftRect.center().y()); // adjust Y handle pos
+ if (handlePos.y() >= leftRect.y() && handlePos.y() <= leftRect.bottom() && leftRect.x() >= handlePos.x())
+ return false; // same line and wrong X pos ?
+ return true;
+ };
+
+ auto checkRtlLeftHandle = [&leftRect](QPointF &handlePos) {
+ if (handlePos.y() < leftRect.center().y())
+ handlePos.setY(leftRect.center().y()); // adjust Y handle pos
+ if (handlePos.y() >= leftRect.y() && handlePos.y() <= leftRect.bottom() && handlePos.x() >= leftRect.x())
+ return false; // same line and wrong X pos ?
+ return true;
+ };
+
if (handleId == 2) {
- QPoint rightPoint(rightRect.center().toPoint());
+ QPointF rightPoint(rightRect.center());
+ if ((!rtl && !checkLeftHandle(point)) || (rtl && !checkRtlRightHandle(point)))
+ return;
setSelectionOnFocusObject(point, rightPoint);
} else if (handleId == 3) {
- QPoint leftPoint(leftRect.center().toPoint());
+ QPointF leftPoint(leftRect.center());
+ if ((!rtl && !checkRightHandle(point)) || (rtl && !checkRtlLeftHandle(point)))
+ return;
setSelectionOnFocusObject(leftPoint, point);
}
}
diff --git a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm
index e756f0aeb0..f4c968ab57 100644
--- a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm
+++ b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm
@@ -72,8 +72,6 @@
**
****************************************************************************/
-#define QT_MAC_SYSTEMTRAY_USE_GROWL
-
#include "qcocoasystemtrayicon.h"
#ifndef QT_NO_SYSTEMTRAYICON
diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp
index c3c9bdf51c..60457f7254 100644
--- a/src/widgets/itemviews/qheaderview.cpp
+++ b/src/widgets/itemviews/qheaderview.cpp
@@ -351,7 +351,7 @@ void QHeaderView::setModel(QAbstractItemModel *model)
if (model == this->model())
return;
Q_D(QHeaderView);
- d->persistentHiddenSections.clear();
+ d->layoutChangePersistentSections.clear();
if (d->model && d->model != QAbstractItemModelPrivate::staticEmptyModel()) {
if (d->orientation == Qt::Horizontal) {
QObject::disconnect(d->model, SIGNAL(columnsInserted(QModelIndex,int,int)),
@@ -2072,14 +2072,28 @@ void QHeaderViewPrivate::_q_layoutAboutToBeChanged()
|| model->columnCount(root) == 0)
return;
- if (hiddenSectionSize.count() == 0)
- return;
+ layoutChangePersistentSections.clear();
+ layoutChangePersistentSections.reserve(std::min(10, sectionItems.count()));
+ // after layoutChanged another section can be last stretched section
+ if (stretchLastSection) {
+ const int visual = visualIndex(lastSectionLogicalIdx);
+ sectionItems[visual].size = lastSectionSize;
+ }
+ for (int i = 0; i < sectionItems.size(); ++i) {
+ const auto &s = sectionItems.at(i);
+ // only add if the section is not default and not visually moved
+ if (s.size == defaultSectionSize && !s.isHidden && s.resizeMode == globalResizeMode)
+ continue;
- for (int i = 0; i < sectionItems.count(); ++i)
- if (isVisualIndexHidden(i)) // ### note that we are using column or row 0
- persistentHiddenSections.append(orientation == Qt::Horizontal
- ? model->index(0, logicalIndex(i), root)
- : model->index(logicalIndex(i), 0, root));
+ // ### note that we are using column or row 0
+ layoutChangePersistentSections.append({orientation == Qt::Horizontal
+ ? model->index(0, logicalIndex(i), root)
+ : model->index(logicalIndex(i), 0, root),
+ s});
+
+ if (layoutChangePersistentSections.size() > 1000)
+ break;
+ }
}
void QHeaderViewPrivate::_q_layoutChanged()
@@ -2087,25 +2101,57 @@ void QHeaderViewPrivate::_q_layoutChanged()
Q_Q(QHeaderView);
viewport->update();
- const auto hiddenSections = persistentHiddenSections;
- persistentHiddenSections.clear();
-
- clear();
- q->initializeSections();
- invalidateCachedSizeHint();
+ const auto oldPersistentSections = layoutChangePersistentSections;
+ layoutChangePersistentSections.clear();
- if (modelIsEmpty()) {
+ const int newCount = modelSectionCount();
+ const int oldCount = sectionItems.size();
+ if (newCount == 0) {
+ clear();
+ if (oldCount != 0)
+ emit q->sectionCountChanged(oldCount, 0);
return;
}
- for (const auto &index : hiddenSections) {
- if (index.isValid()) {
- const int logical = (orientation == Qt::Horizontal
- ? index.column()
- : index.row());
- q->setSectionHidden(logical, true);
+ // adjust section size
+ if (newCount != oldCount) {
+ const int min = qBound(0, oldCount, newCount - 1);
+ q->initializeSections(min, newCount - 1);
+ }
+ // reset sections
+ sectionItems.fill(SectionItem(defaultSectionSize, globalResizeMode), newCount);
+
+ // all hidden sections are in oldPersistentSections
+ hiddenSectionSize.clear();
+
+ for (const auto &item : oldPersistentSections) {
+ const auto &index = item.index;
+ if (!index.isValid())
+ continue;
+
+ const int newLogicalIndex = (orientation == Qt::Horizontal
+ ? index.column()
+ : index.row());
+ // the new visualIndices are already adjusted / reset by initializeSections()
+ const int newVisualIndex = visualIndex(newLogicalIndex);
+ auto &newSection = sectionItems[newVisualIndex];
+ newSection = item.section;
+
+ if (newSection.isHidden) {
+ // otherwise setSectionHidden will return without doing anything
+ newSection.isHidden = false;
+ q->setSectionHidden(newLogicalIndex, true);
}
}
+
+ recalcSectionStartPos();
+ length = headerLength();
+
+ if (stretchLastSection) {
+ // force rebuild of stretched section later on
+ lastSectionLogicalIdx = -1;
+ maybeRestorePrevLastSectionAndStretchLast();
+ }
}
/*!
diff --git a/src/widgets/itemviews/qheaderview_p.h b/src/widgets/itemviews/qheaderview_p.h
index 8fc8b88aa5..c9c2cf8493 100644
--- a/src/widgets/itemviews/qheaderview_p.h
+++ b/src/widgets/itemviews/qheaderview_p.h
@@ -231,10 +231,6 @@ public:
: model->rowCount(root));
}
- inline bool modelIsEmpty() const {
- return (model->rowCount(root) == 0 || model->columnCount(root) == 0);
- }
-
inline void doDelayedResizeSections() {
if (!delayedResize.isActive())
delayedResize.start(0, q_func());
@@ -304,7 +300,6 @@ public:
QLabel *sectionIndicator;
#endif
QHeaderView::ResizeMode globalResizeMode;
- QList<QPersistentModelIndex> persistentHiddenSections;
mutable bool sectionStartposRecalc;
int resizeContentsPrecision;
// header sections
@@ -335,6 +330,11 @@ public:
};
QVector<SectionItem> sectionItems;
+ struct LayoutChangeItem {
+ QPersistentModelIndex index;
+ SectionItem section;
+ };
+ QVector<LayoutChangeItem> layoutChangePersistentSections;
void createSectionItems(int start, int end, int size, QHeaderView::ResizeMode mode);
void removeSectionsFromSectionItems(int start, int end);
@@ -388,6 +388,7 @@ public:
};
Q_DECLARE_TYPEINFO(QHeaderViewPrivate::SectionItem, Q_PRIMITIVE_TYPE);
+Q_DECLARE_TYPEINFO(QHeaderViewPrivate::LayoutChangeItem, Q_MOVABLE_TYPE);
QT_END_NAMESPACE
diff --git a/src/widgets/itemviews/qtreeview.cpp b/src/widgets/itemviews/qtreeview.cpp
index 7696b75661..6892a5aba1 100644
--- a/src/widgets/itemviews/qtreeview.cpp
+++ b/src/widgets/itemviews/qtreeview.cpp
@@ -987,7 +987,7 @@ void QTreeView::setTreePosition(int index)
{
Q_D(QTreeView);
d->treePosition = index;
- update();
+ d->viewport->update();
}
/*!
diff --git a/src/widgets/util/qsystemtrayicon.cpp b/src/widgets/util/qsystemtrayicon.cpp
index 447c7b2aeb..86c824afdb 100644
--- a/src/widgets/util/qsystemtrayicon.cpp
+++ b/src/widgets/util/qsystemtrayicon.cpp
@@ -111,9 +111,7 @@ static QIcon messageIcon2qIcon(QSystemTrayIcon::MessageIcon icon)
\li All X11 desktop environments that implement the D-Bus
\l{http://www.freedesktop.org/wiki/Specifications/StatusNotifierItem/StatusNotifierItem}
specification, including recent versions of KDE and Unity.
- \li All supported versions of \macos. Note that the Growl
- notification system must be installed for
- QSystemTrayIcon::showMessage() to display messages on \macos prior to 10.8 (Mountain Lion).
+ \li All supported versions of \macos.
\endlist
To check whether a system tray is present on the user's desktop,
@@ -420,9 +418,6 @@ bool QSystemTrayIcon::supportsMessages()
On Windows, the \a millisecondsTimeoutHint is usually ignored by the system
when the application has focus.
- On \macos, the Growl notification system must be installed for this function to
- display messages.
-
Has been turned into a slot in Qt 5.2.
\sa show(), supportsMessages()