Merge remote-tracking branch 'origin/5.9' into 5.10

Change-Id: I6b40ecee4db13e6329e7a0433b57c5bca473c63f
This commit is contained in:
Liang Qi 2018-01-29 20:49:23 +01:00
commit 27e8612fa4
11 changed files with 162 additions and 58 deletions

View File

@ -3,4 +3,8 @@ requires(qtHaveModule(widgets))
TEMPLATE = subdirs TEMPLATE = subdirs
qtConfig(sharedmemory): SUBDIRS = sharedmemory qtConfig(sharedmemory): SUBDIRS = sharedmemory
qtHaveModule(network): SUBDIRS += localfortuneserver localfortuneclient qtHaveModule(network) {
QT_FOR_CONFIG += network
qtConfig(localserver): SUBDIRS += localfortuneserver localfortuneclient
}

View File

@ -64,6 +64,8 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QGuiApplication app(argc, argv);
QSurfaceFormat fmt; QSurfaceFormat fmt;
fmt.setDepthBufferSize(24); fmt.setDepthBufferSize(24);
@ -79,8 +81,6 @@ int main(int argc, char *argv[])
QSurfaceFormat::setDefaultFormat(fmt); QSurfaceFormat::setDefaultFormat(fmt);
QGuiApplication app(argc, argv);
GLWindow glWindow; GLWindow glWindow;
glWindow.showMaximized(); glWindow.showMaximized();

View File

@ -51,6 +51,7 @@ import android.graphics.drawable.Drawable;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.widget.PopupWindow; import android.widget.PopupWindow;
import android.app.Activity; import android.app.Activity;
import android.util.TypedValue;
import android.view.ViewTreeObserver; import android.view.ViewTreeObserver;
/* This view represents one of the handle (selection or cursor handle) */ /* This view represents one of the handle (selection or cursor handle) */
@ -58,8 +59,9 @@ class CursorView extends ImageView
{ {
private CursorHandle mHandle; private CursorHandle mHandle;
// The coordinare which where clicked // The coordinare which where clicked
private int m_offsetX; private float m_offsetX;
private int m_offsetY; private float m_offsetY;
private boolean m_pressed = false;
CursorView (Context context, CursorHandle handle) { CursorView (Context context, CursorHandle handle) {
super(context); super(context);
@ -76,21 +78,23 @@ class CursorView extends ImageView
public boolean onTouchEvent(MotionEvent ev) { public boolean onTouchEvent(MotionEvent ev) {
switch (ev.getActionMasked()) { switch (ev.getActionMasked()) {
case MotionEvent.ACTION_DOWN: { case MotionEvent.ACTION_DOWN: {
m_offsetX = Math.round(ev.getRawX()); m_offsetX = ev.getRawX();
m_offsetY = Math.round(ev.getRawY()); m_offsetY = ev.getRawY() + getHeight() / 2;
m_pressed = true;
break; break;
} }
case MotionEvent.ACTION_MOVE: { case MotionEvent.ACTION_MOVE: {
mHandle.updatePosition(Math.round(ev.getRawX()) - m_offsetX, if (!m_pressed)
Math.round(ev.getRawY()) - m_offsetY); return false;
mHandle.updatePosition(Math.round(ev.getRawX() - m_offsetX),
Math.round(ev.getRawY() - m_offsetY));
break; break;
} }
case MotionEvent.ACTION_UP: case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_CANCEL:
m_pressed = false;
break; break;
} }
return true; return true;
@ -113,6 +117,7 @@ public class CursorHandle implements ViewTreeObserver.OnPreDrawListener
private int m_lastY; private int m_lastY;
int tolerance; int tolerance;
private boolean m_rtl; private boolean m_rtl;
int m_yShift;
public CursorHandle(Activity activity, View layout, int id, int attr, boolean rtl) { public CursorHandle(Activity activity, View layout, int id, int attr, boolean rtl) {
m_activity = activity; m_activity = activity;
@ -121,7 +126,8 @@ public class CursorHandle implements ViewTreeObserver.OnPreDrawListener
m_layout = layout; m_layout = layout;
DisplayMetrics metrics = new DisplayMetrics(); DisplayMetrics metrics = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); 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_lastX = m_lastY = -1 - tolerance;
m_rtl = rtl; m_rtl = rtl;
} }
@ -158,7 +164,7 @@ public class CursorHandle implements ViewTreeObserver.OnPreDrawListener
m_layout.getLocationOnScreen(location); m_layout.getLocationOnScreen(location);
int x2 = x + location[0]; int x2 = x + location[0];
int y2 = y + location[1]; int y2 = y + location[1] + m_yShift;
if (m_id == QtNative.IdCursorHandle) { if (m_id == QtNative.IdCursorHandle) {
x2 -= m_cursorView.getWidth() / 2 ; x2 -= m_cursorView.getWidth() / 2 ;
@ -187,6 +193,7 @@ public class CursorHandle implements ViewTreeObserver.OnPreDrawListener
// The handle was dragged by a given relative position // The handle was dragged by a given relative position
public void updatePosition(int x, int y) { public void updatePosition(int x, int y) {
y -= m_yShift;
if (Math.abs(m_lastX - x) > tolerance || Math.abs(m_lastY - y) > tolerance) { if (Math.abs(m_lastX - x) > tolerance || Math.abs(m_lastY - y) > tolerance) {
QtNative.handleLocationChanged(m_id, x + m_posX, y + m_posY); QtNative.handleLocationChanged(m_id, x + m_posX, y + m_posY);
m_lastX = x; m_lastX = x;

View File

@ -287,6 +287,8 @@ void QPlatformInputContext::setSelectionOnFocusObject(const QPointF &anchorPos,
if (success) { if (success) {
int cursor = QInputMethod::queryFocusObject(Qt::ImCursorPosition, cursorPos * mapToLocal).toInt(&success); int cursor = QInputMethod::queryFocusObject(Qt::ImCursorPosition, cursorPos * mapToLocal).toInt(&success);
if (success) { if (success) {
if (anchor == cursor && anchorPos != cursorPos)
return;
QList<QInputMethodEvent::Attribute> imAttributes; QList<QInputMethodEvent::Attribute> imAttributes;
imAttributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::Selection, anchor, cursor - anchor, QVariant())); imAttributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::Selection, anchor, cursor - anchor, QVariant()));
QInputMethodEvent event(QString(), imAttributes); QInputMethodEvent event(QString(), imAttributes);

View File

@ -438,6 +438,16 @@ QAndroidInputContext::QAndroidInputContext()
QObject::connect(QGuiApplication::inputMethod(), &QInputMethod::cursorRectangleChanged, QObject::connect(QGuiApplication::inputMethod(), &QInputMethod::cursorRectangleChanged,
this, &QAndroidInputContext::updateSelectionHandles); 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() QAndroidInputContext::~QAndroidInputContext()
@ -595,27 +605,63 @@ void QAndroidInputContext::handleLocationChanged(int handleId, int x, int y)
double pixelDensity = window double pixelDensity = window
? QHighDpiScaling::factor(window) ? QHighDpiScaling::factor(window)
: QHighDpiScaling::factor(QtAndroid::androidPlatformIntegration()->screen()); : QHighDpiScaling::factor(QtAndroid::androidPlatformIntegration()->screen());
QPoint point(x / pixelDensity, y / pixelDensity); QPointF point(x / pixelDensity, y / pixelDensity);
y -= leftRect.width() / 2; point.setY(point.y() - leftRect.width() / 2);
if (handleId == 1) { if (handleId == 1) {
setSelectionOnFocusObject(point, point); setSelectionOnFocusObject(point, point);
return; return;
} }
QInputMethodQueryEvent query(Qt::ImCursorPosition | Qt::ImAnchorPosition); QInputMethodQueryEvent query(Qt::ImCursorPosition | Qt::ImAnchorPosition | Qt::ImCurrentSelection);
QCoreApplication::sendEvent(m_focusObject, &query); QCoreApplication::sendEvent(m_focusObject, &query);
int cpos = query.value(Qt::ImCursorPosition).toInt(); int cpos = query.value(Qt::ImCursorPosition).toInt();
int anchor = query.value(Qt::ImAnchorPosition).toInt(); int anchor = query.value(Qt::ImAnchorPosition).toInt();
bool rtl = query.value(Qt::ImCurrentSelection).toString().isRightToLeft();
auto rightRect = im->anchorRectangle(); auto rightRect = im->anchorRectangle();
if (cpos > anchor) if (cpos > anchor)
std::swap(leftRect, rightRect); 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) { if (handleId == 2) {
QPoint rightPoint(rightRect.center().toPoint()); QPointF rightPoint(rightRect.center());
if ((!rtl && !checkLeftHandle(point)) || (rtl && !checkRtlRightHandle(point)))
return;
setSelectionOnFocusObject(point, rightPoint); setSelectionOnFocusObject(point, rightPoint);
} else if (handleId == 3) { } else if (handleId == 3) {
QPoint leftPoint(leftRect.center().toPoint()); QPointF leftPoint(leftRect.center());
if ((!rtl && !checkRightHandle(point)) || (rtl && !checkRtlLeftHandle(point)))
return;
setSelectionOnFocusObject(leftPoint, point); setSelectionOnFocusObject(leftPoint, point);
} }
} }

View File

@ -72,8 +72,6 @@
** **
****************************************************************************/ ****************************************************************************/
#define QT_MAC_SYSTEMTRAY_USE_GROWL
#include "qcocoasystemtrayicon.h" #include "qcocoasystemtrayicon.h"
#ifndef QT_NO_SYSTEMTRAYICON #ifndef QT_NO_SYSTEMTRAYICON

View File

@ -351,7 +351,7 @@ void QHeaderView::setModel(QAbstractItemModel *model)
if (model == this->model()) if (model == this->model())
return; return;
Q_D(QHeaderView); Q_D(QHeaderView);
d->persistentHiddenSections.clear(); d->layoutChangePersistentSections.clear();
if (d->model && d->model != QAbstractItemModelPrivate::staticEmptyModel()) { if (d->model && d->model != QAbstractItemModelPrivate::staticEmptyModel()) {
if (d->orientation == Qt::Horizontal) { if (d->orientation == Qt::Horizontal) {
QObject::disconnect(d->model, SIGNAL(columnsInserted(QModelIndex,int,int)), QObject::disconnect(d->model, SIGNAL(columnsInserted(QModelIndex,int,int)),
@ -2072,14 +2072,28 @@ void QHeaderViewPrivate::_q_layoutAboutToBeChanged()
|| model->columnCount(root) == 0) || model->columnCount(root) == 0)
return; return;
if (hiddenSectionSize.count() == 0) layoutChangePersistentSections.clear();
return; 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) // ### note that we are using column or row 0
if (isVisualIndexHidden(i)) // ### note that we are using column or row 0 layoutChangePersistentSections.append({orientation == Qt::Horizontal
persistentHiddenSections.append(orientation == Qt::Horizontal
? model->index(0, logicalIndex(i), root) ? model->index(0, logicalIndex(i), root)
: model->index(logicalIndex(i), 0, root)); : model->index(logicalIndex(i), 0, root),
s});
if (layoutChangePersistentSections.size() > 1000)
break;
}
} }
void QHeaderViewPrivate::_q_layoutChanged() void QHeaderViewPrivate::_q_layoutChanged()
@ -2087,25 +2101,57 @@ void QHeaderViewPrivate::_q_layoutChanged()
Q_Q(QHeaderView); Q_Q(QHeaderView);
viewport->update(); viewport->update();
const auto hiddenSections = persistentHiddenSections; const auto oldPersistentSections = layoutChangePersistentSections;
persistentHiddenSections.clear(); layoutChangePersistentSections.clear();
const int newCount = modelSectionCount();
const int oldCount = sectionItems.size();
if (newCount == 0) {
clear(); clear();
q->initializeSections(); if (oldCount != 0)
invalidateCachedSizeHint(); emit q->sectionCountChanged(oldCount, 0);
if (modelIsEmpty()) {
return; return;
} }
for (const auto &index : hiddenSections) { // adjust section size
if (index.isValid()) { if (newCount != oldCount) {
const int logical = (orientation == Qt::Horizontal 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.column()
: index.row()); : index.row());
q->setSectionHidden(logical, true); // 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();
}
} }
/*! /*!

View File

@ -231,10 +231,6 @@ public:
: model->rowCount(root)); : model->rowCount(root));
} }
inline bool modelIsEmpty() const {
return (model->rowCount(root) == 0 || model->columnCount(root) == 0);
}
inline void doDelayedResizeSections() { inline void doDelayedResizeSections() {
if (!delayedResize.isActive()) if (!delayedResize.isActive())
delayedResize.start(0, q_func()); delayedResize.start(0, q_func());
@ -304,7 +300,6 @@ public:
QLabel *sectionIndicator; QLabel *sectionIndicator;
#endif #endif
QHeaderView::ResizeMode globalResizeMode; QHeaderView::ResizeMode globalResizeMode;
QList<QPersistentModelIndex> persistentHiddenSections;
mutable bool sectionStartposRecalc; mutable bool sectionStartposRecalc;
int resizeContentsPrecision; int resizeContentsPrecision;
// header sections // header sections
@ -335,6 +330,11 @@ public:
}; };
QVector<SectionItem> sectionItems; QVector<SectionItem> sectionItems;
struct LayoutChangeItem {
QPersistentModelIndex index;
SectionItem section;
};
QVector<LayoutChangeItem> layoutChangePersistentSections;
void createSectionItems(int start, int end, int size, QHeaderView::ResizeMode mode); void createSectionItems(int start, int end, int size, QHeaderView::ResizeMode mode);
void removeSectionsFromSectionItems(int start, int end); void removeSectionsFromSectionItems(int start, int end);
@ -388,6 +388,7 @@ public:
}; };
Q_DECLARE_TYPEINFO(QHeaderViewPrivate::SectionItem, Q_PRIMITIVE_TYPE); Q_DECLARE_TYPEINFO(QHeaderViewPrivate::SectionItem, Q_PRIMITIVE_TYPE);
Q_DECLARE_TYPEINFO(QHeaderViewPrivate::LayoutChangeItem, Q_MOVABLE_TYPE);
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -987,7 +987,7 @@ void QTreeView::setTreePosition(int index)
{ {
Q_D(QTreeView); Q_D(QTreeView);
d->treePosition = index; d->treePosition = index;
update(); d->viewport->update();
} }
/*! /*!

View File

@ -111,9 +111,7 @@ static QIcon messageIcon2qIcon(QSystemTrayIcon::MessageIcon icon)
\li All X11 desktop environments that implement the D-Bus \li All X11 desktop environments that implement the D-Bus
\l{http://www.freedesktop.org/wiki/Specifications/StatusNotifierItem/StatusNotifierItem} \l{http://www.freedesktop.org/wiki/Specifications/StatusNotifierItem/StatusNotifierItem}
specification, including recent versions of KDE and Unity. specification, including recent versions of KDE and Unity.
\li All supported versions of \macos. Note that the Growl \li All supported versions of \macos.
notification system must be installed for
QSystemTrayIcon::showMessage() to display messages on \macos prior to 10.8 (Mountain Lion).
\endlist \endlist
To check whether a system tray is present on the user's desktop, 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 On Windows, the \a millisecondsTimeoutHint is usually ignored by the system
when the application has focus. 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. Has been turned into a slot in Qt 5.2.
\sa show(), supportsMessages() \sa show(), supportsMessages()

View File

@ -2251,10 +2251,6 @@ void tst_QHeaderView::QTBUG6058_reset()
void tst_QHeaderView::QTBUG7833_sectionClicked() void tst_QHeaderView::QTBUG7833_sectionClicked()
{ {
QTableView tv; QTableView tv;
QStandardItemModel *sim = new QStandardItemModel(&tv); QStandardItemModel *sim = new QStandardItemModel(&tv);
QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(&tv); QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(&tv);
@ -2278,11 +2274,20 @@ void tst_QHeaderView::QTBUG7833_sectionClicked()
tv.horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive); tv.horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
tv.setModel(proxyModel); tv.setModel(proxyModel);
const int section4Size = tv.horizontalHeader()->sectionSize(4) + 1;
tv.horizontalHeader()->resizeSection(4, section4Size);
tv.setColumnHidden(5, true); tv.setColumnHidden(5, true);
tv.setColumnHidden(6, true); tv.setColumnHidden(6, true);
tv.horizontalHeader()->swapSections(8, 10); tv.horizontalHeader()->swapSections(8, 10);
tv.sortByColumn(1, Qt::AscendingOrder); tv.sortByColumn(1, Qt::AscendingOrder);
QCOMPARE(tv.isColumnHidden(5), true);
QCOMPARE(tv.isColumnHidden(6), true);
QCOMPARE(tv.horizontalHeader()->sectionsMoved(), true);
QCOMPARE(tv.horizontalHeader()->logicalIndex(8), 10);
QCOMPARE(tv.horizontalHeader()->logicalIndex(10), 8);
QCOMPARE(tv.horizontalHeader()->sectionSize(4), section4Size);
QSignalSpy clickedSpy(tv.horizontalHeader(), SIGNAL(sectionClicked(int))); QSignalSpy clickedSpy(tv.horizontalHeader(), SIGNAL(sectionClicked(int)));
QSignalSpy pressedSpy(tv.horizontalHeader(), SIGNAL(sectionPressed(int))); QSignalSpy pressedSpy(tv.horizontalHeader(), SIGNAL(sectionPressed(int)));