Skip to content

Commit 46af3a8

Browse files
fix: use double click to launch actions
1 parent 3cbe993 commit 46af3a8

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ add_executable(${PROJECT_TARGET_NAME} WIN32
137137
"${CMAKE_CURRENT_SOURCE_DIR}/src/Config.h"
138138
"${CMAKE_CURRENT_SOURCE_DIR}/src/GameConfig.cpp"
139139
"${CMAKE_CURRENT_SOURCE_DIR}/src/GameConfig.h"
140+
"${CMAKE_CURRENT_SOURCE_DIR}/src/LaunchButton.h"
140141
"${CMAKE_CURRENT_SOURCE_DIR}/src/Main.cpp"
141142
"${CMAKE_CURRENT_SOURCE_DIR}/src/NewModDialog.cpp"
142143
"${CMAKE_CURRENT_SOURCE_DIR}/src/NewModDialog.h"

src/LaunchButton.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#pragma once
2+
3+
#include <QToolButton>
4+
5+
class QMouseEvent;
6+
7+
class LaunchButton : public QToolButton {
8+
Q_OBJECT;
9+
10+
public:
11+
using QToolButton::QToolButton;
12+
13+
protected:
14+
// Actually incredible Qt doesn't expose this already
15+
void mouseDoubleClickEvent(QMouseEvent*) override {
16+
emit this->doubleClicked();
17+
}
18+
19+
signals:
20+
void doubleClicked();
21+
};

src/Window.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "Config.h"
2020
#include "GameConfig.h"
21+
#include "LaunchButton.h"
2122
#include "NewModDialog.h"
2223

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

266267
for (auto& entry : section.entries) {
267-
auto* button = new QToolButton(this->main);
268+
auto* button = new LaunchButton(this->main);
268269
button->setStyleSheet(
269-
"QToolButton { background-color: rgba( 0, 0, 0, 0); border: none; }\n"
270-
"QToolButton::pressed { background-color: rgba(220, 220, 0, 32); border: none; }\n"
271-
"QToolButton::hover { background-color: rgba(220, 220, 0, 32); border: none; }");
270+
"LaunchButton { background-color: rgba( 0, 0, 0, 0); border: none; }\n"
271+
"LaunchButton::pressed { background-color: rgba(220, 220, 0, 32); border: none; }\n"
272+
"LaunchButton::hover { background-color: rgba(220, 220, 0, 32); border: none; }");
272273
button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
273274
button->setText(entry.name);
274275
button->setIconSize({16, 16});
@@ -303,7 +304,7 @@ void Window::loadGameConfig(const QString& path) {
303304
#endif
304305
}
305306
button->setToolTip(action + " " + entry.arguments.join(" "));
306-
QObject::connect(button, &QToolButton::clicked, this, [this, action, args=entry.arguments, cwd=rootPath] {
307+
QObject::connect(button, &LaunchButton::doubleClicked, this, [this, action, args=entry.arguments, cwd=rootPath] {
307308
auto* process = new QProcess;
308309
QObject::connect(process, &QProcess::errorOccurred, this, [this](QProcess::ProcessError code) {
309310
QString error;
@@ -337,7 +338,7 @@ void Window::loadGameConfig(const QString& path) {
337338
button->setIcon(this->style()->standardIcon(QStyle::SP_MessageBoxInformation));
338339
}
339340
button->setToolTip(action);
340-
QObject::connect(button, &QToolButton::clicked, this, [action] {
341+
QObject::connect(button, &LaunchButton::doubleClicked, this, [action] {
341342
QDesktopServices::openUrl({action});
342343
});
343344
break;
@@ -346,7 +347,7 @@ void Window::loadGameConfig(const QString& path) {
346347
button->setIcon(this->style()->standardIcon(QStyle::SP_DirLinkIcon));
347348
}
348349
button->setToolTip(action);
349-
QObject::connect(button, &QToolButton::clicked, this, [action] {
350+
QObject::connect(button, &LaunchButton::doubleClicked, this, [action] {
350351
QDesktopServices::openUrl({QString("file:///") + action});
351352
});
352353
break;

0 commit comments

Comments
 (0)