Skip to content

Commit

Permalink
fix: use double click to launch actions
Browse files Browse the repository at this point in the history
  • Loading branch information
craftablescience committed Oct 13, 2024
1 parent 3cbe993 commit 46af3a8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ add_executable(${PROJECT_TARGET_NAME} WIN32
"${CMAKE_CURRENT_SOURCE_DIR}/src/Config.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/GameConfig.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/GameConfig.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/LaunchButton.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Main.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/NewModDialog.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/NewModDialog.h"
Expand Down
21 changes: 21 additions & 0 deletions src/LaunchButton.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include <QToolButton>

class QMouseEvent;

class LaunchButton : public QToolButton {
Q_OBJECT;

public:
using QToolButton::QToolButton;

protected:
// Actually incredible Qt doesn't expose this already
void mouseDoubleClickEvent(QMouseEvent*) override {
emit this->doubleClicked();
}

signals:
void doubleClicked();
};
15 changes: 8 additions & 7 deletions src/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "Config.h"
#include "GameConfig.h"
#include "LaunchButton.h"
#include "NewModDialog.h"

#ifdef _WIN32
Expand Down Expand Up @@ -264,11 +265,11 @@ void Window::loadGameConfig(const QString& path) {
layout->addWidget(line);

for (auto& entry : section.entries) {
auto* button = new QToolButton(this->main);
auto* button = new LaunchButton(this->main);
button->setStyleSheet(
"QToolButton { background-color: rgba( 0, 0, 0, 0); border: none; }\n"
"QToolButton::pressed { background-color: rgba(220, 220, 0, 32); border: none; }\n"
"QToolButton::hover { background-color: rgba(220, 220, 0, 32); border: none; }");
"LaunchButton { background-color: rgba( 0, 0, 0, 0); border: none; }\n"
"LaunchButton::pressed { background-color: rgba(220, 220, 0, 32); border: none; }\n"
"LaunchButton::hover { background-color: rgba(220, 220, 0, 32); border: none; }");
button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
button->setText(entry.name);
button->setIconSize({16, 16});
Expand Down Expand Up @@ -303,7 +304,7 @@ void Window::loadGameConfig(const QString& path) {
#endif
}
button->setToolTip(action + " " + entry.arguments.join(" "));
QObject::connect(button, &QToolButton::clicked, this, [this, action, args=entry.arguments, cwd=rootPath] {
QObject::connect(button, &LaunchButton::doubleClicked, this, [this, action, args=entry.arguments, cwd=rootPath] {
auto* process = new QProcess;
QObject::connect(process, &QProcess::errorOccurred, this, [this](QProcess::ProcessError code) {
QString error;
Expand Down Expand Up @@ -337,7 +338,7 @@ void Window::loadGameConfig(const QString& path) {
button->setIcon(this->style()->standardIcon(QStyle::SP_MessageBoxInformation));
}
button->setToolTip(action);
QObject::connect(button, &QToolButton::clicked, this, [action] {
QObject::connect(button, &LaunchButton::doubleClicked, this, [action] {
QDesktopServices::openUrl({action});
});
break;
Expand All @@ -346,7 +347,7 @@ void Window::loadGameConfig(const QString& path) {
button->setIcon(this->style()->standardIcon(QStyle::SP_DirLinkIcon));
}
button->setToolTip(action);
QObject::connect(button, &QToolButton::clicked, this, [action] {
QObject::connect(button, &LaunchButton::doubleClicked, this, [action] {
QDesktopServices::openUrl({QString("file:///") + action});
});
break;
Expand Down

0 comments on commit 46af3a8

Please sign in to comment.