various: ensure qt 5 compatibility

This commit is contained in:
itsmattkc
2022-10-31 18:18:49 -07:00
parent e94580c369
commit c5a86af181
6 changed files with 37 additions and 21 deletions
+5 -1
View File
@@ -106,7 +106,11 @@ set(QT_LIBRARIES
if (UNIX AND NOT APPLE) if (UNIX AND NOT APPLE)
list(APPEND QT_LIBRARIES DBus) list(APPEND QT_LIBRARIES DBus)
endif() endif()
find_package(QT NAMES Qt6 Qt5 REQUIRED find_package(QT
NAMES
Qt6
Qt5
REQUIRED
COMPONENTS COMPONENTS
${QT_LIBRARIES} ${QT_LIBRARIES}
OPTIONAL_COMPONENTS OPTIONAL_COMPONENTS
+7 -1
View File
@@ -56,7 +56,13 @@ void TaskDialog::showEvent(QShowEvent *e)
this, &TaskDialog::TaskFinished, Qt::QueuedConnection); this, &TaskDialog::TaskFinished, Qt::QueuedConnection);
// Run task in another thread with QtConcurrent // Run task in another thread with QtConcurrent
task_watcher->setFuture(QtConcurrent::run(&Task::Start, task_)); task_watcher->setFuture(
#if QT_VERSION_MAJOR >= 6
QtConcurrent::run(&Task::Start, task_)
#else
QtConcurrent::run(task_, &Task::Start)
#endif
);
already_shown_ = true; already_shown_ = true;
} }
+7 -1
View File
@@ -93,7 +93,13 @@ void TaskManager::AddTask(Task* t)
tasks_.insert(watcher, t); tasks_.insert(watcher, t);
// Run task concurrently // Run task concurrently
watcher->setFuture(QtConcurrent::run(&Task::Start, t)); watcher->setFuture(
#if QT_VERSION_MAJOR >= 6
QtConcurrent::run(&Task::Start, t)
#else
QtConcurrent::run(t, &Task::Start)
#endif
);
// Emit signal that a Task was added // Emit signal that a Task was added
emit TaskAdded(t); emit TaskAdded(t);
@@ -61,7 +61,7 @@ bool HandMovableView::HandPress(QMouseEvent *event)
// Transform mouse event to act like the left button is pressed // Transform mouse event to act like the left button is pressed
QMouseEvent transformed(event->type(), QMouseEvent transformed(event->type(),
event->localPos(), event->pos(),
Qt::LeftButton, Qt::LeftButton,
Qt::LeftButton, Qt::LeftButton,
event->modifiers()); event->modifiers());
@@ -83,15 +83,15 @@ bool HandMovableView::HandMove(QMouseEvent *event)
QPoint adjustment(0, 0); QPoint adjustment(0, 0);
QMouseEvent transformed(event->type(), QMouseEvent transformed(event->type(),
event->localPos() - transformed_pos_, event->pos() - transformed_pos_,
Qt::LeftButton, Qt::LeftButton,
Qt::LeftButton, Qt::LeftButton,
event->modifiers()); event->modifiers());
if (event->localPos().x() < 0) { if (event->pos().x() < 0) {
transformed_pos_.setX(transformed_pos_.x() + width()); transformed_pos_.setX(transformed_pos_.x() + width());
adjustment.setX(width()); adjustment.setX(width());
} else if (event->localPos().x() >= width()) { } else if (event->pos().x() >= width()) {
transformed_pos_.setX(transformed_pos_.x() - width()); transformed_pos_.setX(transformed_pos_.x() - width());
adjustment.setX(-width()); adjustment.setX(-width());
} }
@@ -118,14 +118,13 @@ bool HandMovableView::HandRelease(QMouseEvent *event)
if (dragging_hand_) { if (dragging_hand_) {
// Transform mouse event to act like the left button is pressed // Transform mouse event to act like the left button is pressed
QMouseEvent transformed(event->type(), QMouseEvent transformed(event->type(),
event->position(), event->localPos(),
event->scenePosition(), event->windowPos(),
event->globalPosition(), event->screenPos(),
Qt::LeftButton, Qt::LeftButton,
Qt::LeftButton, Qt::LeftButton,
event->modifiers(), event->modifiers(),
event->source(), event->source());
event->pointingDevice());
super::mouseReleaseEvent(&transformed); super::mouseReleaseEvent(&transformed);
+6 -5
View File
@@ -1129,11 +1129,12 @@ void ViewerDisplayWidget::ForwardDragEventToTextEdit(T *e)
if constexpr (std::is_same_v<T, QDragLeaveEvent>) { if constexpr (std::is_same_v<T, QDragLeaveEvent>) {
text_edit_->dragLeaveEvent(e); text_edit_->dragLeaveEvent(e);
} else { } else {
T relay(AdjustPosByVAlign(GetVirtualPosForTextEdit(e->position())).toPoint(),
T relay(AdjustPosByVAlign(GetVirtualPosForTextEdit(e->pos())).toPoint(),
e->possibleActions(), e->possibleActions(),
e->mimeData(), e->mimeData(),
e->buttons(), e->mouseButtons(),
e->modifiers()); e->keyboardModifiers());
if (e->type() == QEvent::DragEnter) { if (e->type() == QEvent::DragEnter) {
text_edit_->dragEnterEvent(static_cast<QDragEnterEvent*>(&relay)); text_edit_->dragEnterEvent(static_cast<QDragEnterEvent*>(&relay));
@@ -1152,7 +1153,7 @@ void ViewerDisplayWidget::ForwardDragEventToTextEdit(T *e)
bool ViewerDisplayWidget::ForwardMouseEventToTextEdit(QMouseEvent *event, bool check_if_outside) bool ViewerDisplayWidget::ForwardMouseEventToTextEdit(QMouseEvent *event, bool check_if_outside)
{ {
// Transform screen mouse coords to world mouse coords // Transform screen mouse coords to world mouse coords
QPointF local_pos = GetVirtualPosForTextEdit(event->position()); QPointF local_pos = GetVirtualPosForTextEdit(event->pos());
if (check_if_outside) { if (check_if_outside) {
if (local_pos.x() < 0 || local_pos.x() >= text_edit_->width() || local_pos.y() < 0 || local_pos.y() >= text_edit_->height()) { if (local_pos.x() < 0 || local_pos.x() >= text_edit_->width() || local_pos.y() < 0 || local_pos.y() >= text_edit_->height()) {
@@ -1163,7 +1164,7 @@ bool ViewerDisplayWidget::ForwardMouseEventToTextEdit(QMouseEvent *event, bool c
local_pos = AdjustPosByVAlign(local_pos); local_pos = AdjustPosByVAlign(local_pos);
QMouseEvent derived(event->type(), local_pos, event->scenePosition(), event->globalPosition(), event->button(), event->buttons(), event->modifiers(), event->source(), event->pointingDevice()); QMouseEvent derived(event->type(), local_pos, event->windowPos(), event->screenPos(), event->button(), event->buttons(), event->modifiers(), event->source());
return ForwardEventToTextEdit(&derived); return ForwardEventToTextEdit(&derived);
} }
+4 -4
View File
@@ -160,7 +160,7 @@ void ViewerTextEditor::UpdateToolBar(ViewerTextEditorToolBar *toolbar, const QTe
} }
QString style = f.fontStyleName().toString(); QString style = f.fontStyleName().toString();
QStringList styles = QFontDatabase::styles(family); QStringList styles = QFontDatabase().styles(family);
if (!styles.isEmpty() && (style.isEmpty() || !styles.contains(style))) { if (!styles.isEmpty() && (style.isEmpty() || !styles.contains(style))) {
// There seems to be no better way to find the "regular" style outside of this heuristic. // There seems to be no better way to find the "regular" style outside of this heuristic.
// Feel free to add more if a font isn't working right. // Feel free to add more if a font isn't working right.
@@ -267,8 +267,8 @@ void ViewerTextEditor::ApplyStyle(QTextCharFormat *format, const QString &family
{ {
// NOTE: Windows appears to require setting weight and italic manually, while macOS and Linux are // NOTE: Windows appears to require setting weight and italic manually, while macOS and Linux are
// perfectly fine with just the style name // perfectly fine with just the style name
format->setFontWeight(QFontDatabase::weight(family, style)); format->setFontWeight(QFontDatabase().weight(family, style));
format->setFontItalic(QFontDatabase::italic(family, style)); format->setFontItalic(QFontDatabase().italic(family, style));
format->setFontStyleName(style); format->setFontStyleName(style);
} }
@@ -536,7 +536,7 @@ void ViewerTextEditorToolBar::UpdateFontStyleList(const QString &family)
style_combo_->blockSignals(true); style_combo_->blockSignals(true);
style_combo_->clear(); style_combo_->clear();
QStringList l = QFontDatabase::styles(family); QStringList l = QFontDatabase().styles(family);
foreach (const QString &style, l) { foreach (const QString &style, l) {
style_combo_->addItem(style); style_combo_->addItem(style);
} }