diff --git a/misc/dialogutils.cpp b/misc/dialogutils.cpp index 2b4edc3..e9b261d 100644 --- a/misc/dialogutils.cpp +++ b/misc/dialogutils.cpp @@ -116,25 +116,25 @@ QRect availableScreenGeometryAtPoint(const QPoint &point) * \brief Moves the specified \a widget in the middle of the (available) screen * area or \a parent if specified. * - * If there are multiple screens available, the screen where the cursor currently - * is located is chosen. + * The screen containing the current cursor position is used unless \a position + * is specified. */ -void centerWidget(QWidget *widget, const QWidget *parent) +void centerWidget(QWidget *widget, const QWidget *parent, const QPoint *position) { - widget->setGeometry(QStyle::alignedRect( - Qt::LeftToRight, Qt::AlignCenter, widget->size(), parent ? parent->geometry() : availableScreenGeometryAtPoint(QCursor::pos()))); + widget->setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, widget->size(), + parent ? parent->geometry() : availableScreenGeometryAtPoint(position ? *position : QCursor::pos()))); } /*! * \brief Moves the specified \a widget to the corner which is closest to the - * current cursor position. + * current cursor position or \a position if specified. * * If there are multiple screens available, the screen where the cursor currently * is located is chosen. */ -void cornerWidget(QWidget *widget) +void cornerWidget(QWidget *widget, const QPoint *position) { - const QPoint cursorPos(QCursor::pos()); + const QPoint cursorPos(position ? *position : QCursor::pos()); const QRect availableGeometry(availableScreenGeometryAtPoint(cursorPos)); Qt::Alignment alignment = nullptr; alignment |= (cursorPos.x() - availableGeometry.left() < availableGeometry.right() - cursorPos.x() ? Qt::AlignLeft : Qt::AlignRight); diff --git a/misc/dialogutils.h b/misc/dialogutils.h index c80df57..99c2d20 100644 --- a/misc/dialogutils.h +++ b/misc/dialogutils.h @@ -36,8 +36,8 @@ QColor QT_UTILITIES_EXPORT instructionTextColor(); const QString QT_UTILITIES_EXPORT &dialogStyle(); #ifdef QT_UTILITIES_GUI_QTWIDGETS QRect QT_UTILITIES_EXPORT availableScreenGeometryAtPoint(const QPoint &point); -void QT_UTILITIES_EXPORT centerWidget(QWidget *widget, const QWidget *parent = nullptr); -void QT_UTILITIES_EXPORT cornerWidget(QWidget *widget); +void QT_UTILITIES_EXPORT centerWidget(QWidget *widget, const QWidget *parent = nullptr, const QPoint *position = nullptr); +void QT_UTILITIES_EXPORT cornerWidget(QWidget *widget, const QPoint *position = nullptr); void QT_UTILITIES_EXPORT makeHeading(QWidget *widget); void QT_UTILITIES_EXPORT updateStyle(QWidget *widget); #endif