Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <QApplication>
#include <QCloseEvent>
#include <QDesktopServices>
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QElapsedTimer>
Expand Down Expand Up @@ -269,6 +270,19 @@ void MainWindow::SetupUi() {
[this](int, int) { SyncSplitterWidths(false); });

QMenu* helpMenu = menuBar()->addMenu("Help");
QAction* shortcutsAct = helpMenu->addAction("Keyboard Shortcuts");
connect(shortcutsAct, &QAction::triggered, this, &MainWindow::ShowShortcuts);
QAction* docsAct = helpMenu->addAction("Documentation");
connect(docsAct, &QAction::triggered, this, []() {
QDesktopServices::openUrl(
QUrl("https://github.com/blocksmith314/DigitalImageAnalyzer#readme"));
});
QAction* issueAct = helpMenu->addAction("Report an Issue");
connect(issueAct, &QAction::triggered, this, []() {
QDesktopServices::openUrl(
QUrl("https://github.com/blocksmith314/DigitalImageAnalyzer/issues"));
});
helpMenu->addSeparator();
QAction* aboutAct = helpMenu->addAction("About Digital Image Analyzer");
connect(aboutAct, &QAction::triggered, this, &MainWindow::ShowAbout);

Expand Down Expand Up @@ -299,6 +313,36 @@ void MainWindow::OpenFile() {
}
}

void MainWindow::ShowShortcuts() {
const auto key = [](QKeySequence::StandardKey standard) {
return QKeySequence(standard).toString(QKeySequence::NativeText);
};
const auto keyOf = [](int key_value) {
return QKeySequence(key_value).toString(QKeySequence::NativeText);
};
const auto keyCombo = [](Qt::Key key_value) {
return QKeySequence(QKeyCombination(Qt::CTRL, key_value))
.toString(QKeySequence::NativeText);
};

const QString text =
QString(
"<h3>Keyboard Shortcuts</h3>"
"<table cellspacing='4'>"
"<tr><td>Open file</td><td><b>%1</b></td></tr>"
"<tr><td>Recent files</td><td><b>%2</b></td></tr>"
"<tr><td>Play / pause</td><td><b>%3</b></td></tr>"
"<tr><td>Previous / next frame</td><td><b>%4 / %5</b></td></tr>"
"<tr><td>Leave fullscreen</td><td><b>%6</b></td></tr>"
"<tr><td>Quit</td><td><b>%7</b></td></tr>"
"</table>")
.arg(key(QKeySequence::Open),
keyCombo(Qt::Key_1) + " ... " + keyCombo(Qt::Key_9),
keyOf(Qt::Key_Space), keyOf(Qt::Key_Left), keyOf(Qt::Key_Right),
keyOf(Qt::Key_Escape), key(QKeySequence::Quit));
QMessageBox::information(this, "Keyboard Shortcuts", text);
}

void MainWindow::ShowAbout() {
QMessageBox::about(this, "About Digital Image Analyzer",
QString("<h3>Digital Image Analyzer %1</h3>"
Expand Down
1 change: 1 addition & 0 deletions mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class MainWindow : public QMainWindow {
void OnPlayerTick();
void OnSpeedChanged(int index);
void ShowAbout();
void ShowShortcuts();

private:
static constexpr int MAX_RECENT_FILES = 10;
Expand Down
19 changes: 19 additions & 0 deletions test/test_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QLabel>
#include <QMenu>
#include <QMenuBar>
#include <QMimeData>
#include <QPushButton>
Expand Down Expand Up @@ -193,6 +194,24 @@ TEST(MainWindowTest, HasHelpMenu) {
EXPECT_TRUE(has_help);
}

TEST(MainWindowTest, HelpMenuHasEntries) {
MainWindow window;
QMenu* help = nullptr;
for (QAction* action : window.menuBar()->actions()) {
if (action->text().contains("Help")) {
help = action->menu();
}
}
ASSERT_NE(help, nullptr);
QStringList entries;
for (QAction* action : help->actions()) {
entries << action->text();
}
EXPECT_TRUE(entries.contains("Keyboard Shortcuts"));
EXPECT_TRUE(entries.contains("Documentation"));
EXPECT_TRUE(entries.contains("Report an Issue"));
}

TEST(MainWindowTest, OpensFileByDrop) {
if (!exists(data_path("output.h264"))) {
GTEST_SKIP() << "H.264 fixture missing";
Expand Down
Loading