Skip to content

Commit

Permalink
various: ensure qt 5 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmattkc committed Nov 1, 2022
1 parent e94580c commit c5a86af
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 21 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ set(QT_LIBRARIES
if (UNIX AND NOT APPLE)
list(APPEND QT_LIBRARIES DBus)
endif()
find_package(QT NAMES Qt6 Qt5 REQUIRED
find_package(QT
NAMES
Qt6
Qt5
REQUIRED
COMPONENTS
${QT_LIBRARIES}
OPTIONAL_COMPONENTS
Expand Down
8 changes: 7 additions & 1 deletion app/dialog/task/task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ void TaskDialog::showEvent(QShowEvent *e)
this, &TaskDialog::TaskFinished, Qt::QueuedConnection);

// 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;
}
Expand Down
8 changes: 7 additions & 1 deletion app/task/taskmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ void TaskManager::AddTask(Task* t)
tasks_.insert(watcher, t);

// 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 TaskAdded(t);
Expand Down
17 changes: 8 additions & 9 deletions app/widget/handmovableview/handmovableview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ bool HandMovableView::HandPress(QMouseEvent *event)

// Transform mouse event to act like the left button is pressed
QMouseEvent transformed(event->type(),
event->localPos(),
event->pos(),
Qt::LeftButton,
Qt::LeftButton,
event->modifiers());
Expand All @@ -83,15 +83,15 @@ bool HandMovableView::HandMove(QMouseEvent *event)
QPoint adjustment(0, 0);

QMouseEvent transformed(event->type(),
event->localPos() - transformed_pos_,
event->pos() - transformed_pos_,
Qt::LeftButton,
Qt::LeftButton,
event->modifiers());

if (event->localPos().x() < 0) {
if (event->pos().x() < 0) {
transformed_pos_.setX(transformed_pos_.x() + width());
adjustment.setX(width());
} else if (event->localPos().x() >= width()) {
} else if (event->pos().x() >= width()) {
transformed_pos_.setX(transformed_pos_.x() - width());
adjustment.setX(-width());
}
Expand All @@ -118,14 +118,13 @@ bool HandMovableView::HandRelease(QMouseEvent *event)
if (dragging_hand_) {
// Transform mouse event to act like the left button is pressed
QMouseEvent transformed(event->type(),
event->position(),
event->scenePosition(),
event->globalPosition(),
event->localPos(),
event->windowPos(),
event->screenPos(),
Qt::LeftButton,
Qt::LeftButton,
event->modifiers(),
event->source(),
event->pointingDevice());
event->source());

super::mouseReleaseEvent(&transformed);

Expand Down
11 changes: 6 additions & 5 deletions app/widget/viewer/viewerdisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1129,11 +1129,12 @@ void ViewerDisplayWidget::ForwardDragEventToTextEdit(T *e)
if constexpr (std::is_same_v<T, QDragLeaveEvent>) {
text_edit_->dragLeaveEvent(e);
} else {
T relay(AdjustPosByVAlign(GetVirtualPosForTextEdit(e->position())).toPoint(),

T relay(AdjustPosByVAlign(GetVirtualPosForTextEdit(e->pos())).toPoint(),
e->possibleActions(),
e->mimeData(),
e->buttons(),
e->modifiers());
e->mouseButtons(),
e->keyboardModifiers());

if (e->type() == QEvent::DragEnter) {
text_edit_->dragEnterEvent(static_cast<QDragEnterEvent*>(&relay));
Expand All @@ -1152,7 +1153,7 @@ void ViewerDisplayWidget::ForwardDragEventToTextEdit(T *e)
bool ViewerDisplayWidget::ForwardMouseEventToTextEdit(QMouseEvent *event, bool check_if_outside)
{
// 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 (local_pos.x() < 0 || local_pos.x() >= text_edit_->width() || local_pos.y() < 0 || local_pos.y() >= text_edit_->height()) {
Expand All @@ -1163,7 +1164,7 @@ bool ViewerDisplayWidget::ForwardMouseEventToTextEdit(QMouseEvent *event, bool c

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);
}

Expand Down
8 changes: 4 additions & 4 deletions app/widget/viewer/viewertexteditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void ViewerTextEditor::UpdateToolBar(ViewerTextEditorToolBar *toolbar, const QTe
}

QString style = f.fontStyleName().toString();
QStringList styles = QFontDatabase::styles(family);
QStringList styles = QFontDatabase().styles(family);
if (!styles.isEmpty() && (style.isEmpty() || !styles.contains(style))) {
// 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.
Expand Down Expand Up @@ -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
// perfectly fine with just the style name
format->setFontWeight(QFontDatabase::weight(family, style));
format->setFontItalic(QFontDatabase::italic(family, style));
format->setFontWeight(QFontDatabase().weight(family, style));
format->setFontItalic(QFontDatabase().italic(family, style));

format->setFontStyleName(style);
}
Expand Down Expand Up @@ -536,7 +536,7 @@ void ViewerTextEditorToolBar::UpdateFontStyleList(const QString &family)

style_combo_->blockSignals(true);
style_combo_->clear();
QStringList l = QFontDatabase::styles(family);
QStringList l = QFontDatabase().styles(family);
foreach (const QString &style, l) {
style_combo_->addItem(style);
}
Expand Down

0 comments on commit c5a86af

Please sign in to comment.