Add functions for positioning
This commit is contained in:
parent
9e61cf8e18
commit
3ea0e47a53
|
@ -7,6 +7,11 @@
|
||||||
# include <QPalette>
|
# include <QPalette>
|
||||||
# include <QWidget>
|
# include <QWidget>
|
||||||
# include <QStyle>
|
# include <QStyle>
|
||||||
|
# ifdef GUI_QTWIDGETS
|
||||||
|
# include <QApplication>
|
||||||
|
# include <QDesktopWidget>
|
||||||
|
# include <QCursor>
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
@ -84,6 +89,43 @@ const QString &dialogStyle()
|
||||||
|
|
||||||
# ifdef GUI_QTWIDGETS
|
# ifdef GUI_QTWIDGETS
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Moves the specified \a widget in the middle of the (available) screen area. If there are multiple
|
||||||
|
* screens available, the screen where the cursor currently is located is chosen.
|
||||||
|
*/
|
||||||
|
void centerWidget(QWidget *widget)
|
||||||
|
{
|
||||||
|
widget->setGeometry(
|
||||||
|
QStyle::alignedRect(
|
||||||
|
Qt::LeftToRight,
|
||||||
|
Qt::AlignCenter,
|
||||||
|
widget->size(),
|
||||||
|
QApplication::desktop()->availableGeometry(QCursor::pos())
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Moves the specified \a widget to the corner which is closest to the current cursor position.
|
||||||
|
* If there are multiple screens available, the screen where the cursor currently is located is chosen.
|
||||||
|
*/
|
||||||
|
void cornerWidget(QWidget *widget)
|
||||||
|
{
|
||||||
|
const QPoint cursorPos(QCursor::pos());
|
||||||
|
const QRect availableGeometry(QApplication::desktop()->availableGeometry(cursorPos));
|
||||||
|
Qt::Alignment alignment = 0;
|
||||||
|
alignment |= (cursorPos.x() - availableGeometry.left() < availableGeometry.right() - cursorPos.x() ? Qt::AlignLeft : Qt::AlignRight);
|
||||||
|
alignment |= (cursorPos.y() - availableGeometry.top() < availableGeometry.bottom() - cursorPos.y() ? Qt::AlignTop : Qt::AlignBottom);
|
||||||
|
widget->setGeometry(
|
||||||
|
QStyle::alignedRect(
|
||||||
|
Qt::LeftToRight,
|
||||||
|
alignment,
|
||||||
|
widget->size(),
|
||||||
|
availableGeometry
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Makes \a widget a heading.
|
* \brief Makes \a widget a heading.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -29,6 +29,8 @@ QColor LIB_EXPORT instructionTextColor();
|
||||||
# endif
|
# endif
|
||||||
const QString LIB_EXPORT &dialogStyle();
|
const QString LIB_EXPORT &dialogStyle();
|
||||||
# ifdef GUI_QTWIDGETS
|
# ifdef GUI_QTWIDGETS
|
||||||
|
void LIB_EXPORT centerWidget(QWidget *widget);
|
||||||
|
void LIB_EXPORT cornerWidget(QWidget *widget);
|
||||||
void LIB_EXPORT makeHeading(QWidget *widget);
|
void LIB_EXPORT makeHeading(QWidget *widget);
|
||||||
void LIB_EXPORT updateStyle(QWidget *widget);
|
void LIB_EXPORT updateStyle(QWidget *widget);
|
||||||
# endif
|
# endif
|
||||||
|
|
Loading…
Reference in New Issue