Fixed QMouseEvent::globalPos() warning

This commit is contained in:
Uwe Kindler 2021-01-02 20:29:59 +01:00
parent fe1d9a493f
commit 8d14068df7
4 changed files with 22 additions and 17 deletions

View File

@ -35,9 +35,11 @@ void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QS
int main(int argc, char *argv[])
{
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
#if QT_VERSION >= 0x050600
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
#endif
std::shared_ptr<int> b;
QApplication a(argc, argv);

View File

@ -26,17 +26,6 @@
using namespace ads;
/**
* Helper function to create an SVG icon
*/
static QIcon svgIcon(const QString& File)
{
// This is a workaround, because in item views SVG icons are not
// properly scaled and look blurry or pixelate
QIcon SvgIcon(File);
SvgIcon.addPixmap(SvgIcon.pixmap(92));
return SvgIcon;
}
CMainWindow::CMainWindow(QWidget *parent)
: QMainWindow(parent)

View File

@ -259,7 +259,7 @@ void DockWidgetTabPrivate::createLayout()
void DockWidgetTabPrivate::moveTab(QMouseEvent* ev)
{
ev->accept();
QPoint Distance = ev->globalPos() - GlobalDragStartMousePosition;
QPoint Distance = internal::globalPositionOf(ev) - GlobalDragStartMousePosition;
Distance.setY(0);
auto TargetPos = Distance + TabDragStartPosition;
TargetPos.rx() = qMax(TargetPos.x(), 0);
@ -351,7 +351,7 @@ void CDockWidgetTab::mousePressEvent(QMouseEvent* ev)
if (ev->button() == Qt::LeftButton)
{
ev->accept();
d->saveDragStartMousePosition(ev->globalPos());
d->saveDragStartMousePosition(internal::globalPositionOf(ev));
d->DragState = DraggingMousePressed;
emit clicked();
return;
@ -377,7 +377,7 @@ void CDockWidgetTab::mouseReleaseEvent(QMouseEvent* ev)
// End of tab moving, emit signal
if (d->DockArea)
{
emit moved(ev->globalPos());
emit moved(internal::globalPositionOf(ev));
}
break;
@ -422,7 +422,7 @@ void CDockWidgetTab::mouseMoveEvent(QMouseEvent* ev)
auto MappedPos = mapToParent(ev->pos());
bool MouseOutsideBar = (MappedPos.x() < 0) || (MappedPos.x() > parentWidget()->rect().right());
// Maybe a fixed drag distance is better here ?
int DragDistanceY = qAbs(d->GlobalDragStartMousePosition.y() - ev->globalPos().y());
int DragDistanceY = qAbs(d->GlobalDragStartMousePosition.y() - internal::globalPositionOf(ev).y());
if (DragDistanceY >= CDockManager::startDragDistance() || MouseOutsideBar)
{
// If this is the last dock area in a dock container with only
@ -454,7 +454,7 @@ void CDockWidgetTab::mouseMoveEvent(QMouseEvent* ev)
return;
}
else if (d->DockArea->openDockWidgetsCount() > 1
&& (ev->globalPos() - d->GlobalDragStartMousePosition).manhattanLength() >= QApplication::startDragDistance()) // Wait a few pixels before start moving
&& (internal::globalPositionOf(ev) - d->GlobalDragStartMousePosition).manhattanLength() >= QApplication::startDragDistance()) // Wait a few pixels before start moving
{
// If we start dragging the tab, we save its inital position to
// restore it later
@ -618,7 +618,7 @@ void CDockWidgetTab::mouseDoubleClickEvent(QMouseEvent *event)
if ((!d->DockArea->dockContainer()->isFloating() || d->DockArea->dockWidgetsCount() > 1)
&& d->DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable))
{
d->saveDragStartMousePosition(event->globalPos());
d->saveDragStartMousePosition(internal::globalPositionOf(event));
d->startFloating(DraggingInactive);
}

View File

@ -36,6 +36,7 @@
#include <QWidget>
#include <QDebug>
#include <QStyle>
#include <QMouseEvent>
#ifdef Q_OS_LINUX
#include <xcb/xcb.h>
@ -260,6 +261,19 @@ void setToolTip(QObjectPtr obj, const QString &tip)
}
/**
* Helper function for access to mouse event global position in Qt5 and
*/
inline QPoint globalPositionOf(QMouseEvent* ev)
{
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
return ev->globalPosition().toPoint();
#else
return ev->globalPos();
#endif
}
/**
* Helper function to set the icon of a certain button.
* Use this function to set the icons for the dock area and dock widget buttons.