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
30 changes: 29 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.16)

project(DigitalImageAnalyzer VERSION 0.1.1 LANGUAGES CXX)
project(DigitalImageAnalyzer VERSION 0.1.2 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand All @@ -11,6 +11,29 @@ find_package(Qt6 REQUIRED COMPONENTS Widgets Multimedia Test)

qt_standard_project_setup()

# Version metadata for --version and the About dialog. Falls back to
# "unknown" when the sources are built outside a git checkout.
execute_process(
COMMAND git rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE DIA_GIT_COMMIT
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET)
execute_process(
COMMAND git log -1 --format=%cs
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE DIA_GIT_COMMIT_DATE
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET)
if(NOT DIA_GIT_COMMIT)
set(DIA_GIT_COMMIT "unknown")
endif()
if(NOT DIA_GIT_COMMIT_DATE)
set(DIA_GIT_COMMIT_DATE "unknown")
endif()
configure_file(core/version.h.in ${CMAKE_BINARY_DIR}/generated/version.h @ONLY)
include_directories(${CMAKE_BINARY_DIR}/generated)

find_package(PkgConfig REQUIRED)
pkg_check_modules(AVFORMAT REQUIRED IMPORTED_TARGET libavformat)
pkg_check_modules(AVCODEC REQUIRED IMPORTED_TARGET libavcodec)
Expand Down Expand Up @@ -295,4 +318,9 @@ if (BUILD_TEST)
gtest_discover_tests(test_gui PROPERTIES
ENVIRONMENT "QT_QPA_PLATFORM=offscreen")
add_dependencies(all_tests test_gui)

add_test(NAME app_version
COMMAND $<TARGET_FILE:DigitalImageAnalyzer> --version)
set_tests_properties(app_version PROPERTIES
PASS_REGULAR_EXPRESSION "Digital Image Analyzer ${PROJECT_VERSION}")
endif ()
5 changes: 5 additions & 0 deletions core/version.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#define DIA_VERSION "@PROJECT_VERSION@"
#define DIA_GIT_COMMIT "@DIA_GIT_COMMIT@"
#define DIA_GIT_COMMIT_DATE "@DIA_GIT_COMMIT_DATE@"
13 changes: 13 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
#include <QApplication>
#include <QSysInfo>
#include <cstdio>
#include <cstring>

#include "mainwindow.h"
#include "version.h"

int main(int argc, char* argv[]) {
for (int i = 1; i < argc; i++) {
if (std::strcmp(argv[i], "--version") == 0) {
std::printf("Digital Image Analyzer %s\ncommit %s (%s)\nQt %s, %s\n",
DIA_VERSION, DIA_GIT_COMMIT, DIA_GIT_COMMIT_DATE, qVersion(),
QSysInfo::prettyProductName().toUtf8().constData());
return 0;
}
}

QApplication a(argc, argv);

MainWindow w;
Expand Down
15 changes: 15 additions & 0 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <QSplitter>
#include <QStatusBar>
#include <QStyle>
#include <QSysInfo>
#include <QToolBar>
#include <QUrl>
#include <QVBoxLayout>
Expand All @@ -36,6 +37,7 @@
#include "annexb.h"
#include "audio.h"
#include "nallistmodel.h"
#include "version.h"

MainWindow::MainWindow(QWidget* parent)
: QMainWindow(parent), parser_(CodecType::kH264) {
Expand Down Expand Up @@ -266,6 +268,10 @@ void MainWindow::SetupUi() {
connect(bottomSplit, &QSplitter::splitterMoved, this,
[this](int, int) { SyncSplitterWidths(false); });

QMenu* helpMenu = menuBar()->addMenu("Help");
QAction* aboutAct = helpMenu->addAction("About Digital Image Analyzer");
connect(aboutAct, &QAction::triggered, this, &MainWindow::ShowAbout);

setCentralWidget(mainSplit);
top_split_ = topSplit;
bottom_split_ = bottomSplit;
Expand Down Expand Up @@ -293,6 +299,15 @@ void MainWindow::OpenFile() {
}
}

void MainWindow::ShowAbout() {
QMessageBox::about(this, "About Digital Image Analyzer",
QString("<h3>Digital Image Analyzer %1</h3>"
"<p>H.264/H.265 bitstream analyzer.</p>"
"<p>Commit: %2 (%3)<br>Qt: %4<br>OS: %5</p>")
.arg(DIA_VERSION, DIA_GIT_COMMIT, DIA_GIT_COMMIT_DATE,
qVersion(), QSysInfo::prettyProductName()));
}

void MainWindow::dragEnterEvent(QDragEnterEvent* event) {
const QList<QUrl> urls = event->mimeData()->urls();
for (const QUrl& url : urls) {
Expand Down
1 change: 1 addition & 0 deletions mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class MainWindow : public QMainWindow {
void ToggleFullscreen();
void OnPlayerTick();
void OnSpeedChanged(int index);
void ShowAbout();

private:
static constexpr int MAX_RECENT_FILES = 10;
Expand Down
12 changes: 12 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 <QMenuBar>
#include <QMimeData>
#include <QPushButton>
#include <QSignalSpy>
Expand Down Expand Up @@ -181,6 +182,17 @@ TEST(MainWindowTest, LoadsFileAndUpdatesViews) {
EXPECT_TRUE(status_has_nal_count);
}

TEST(MainWindowTest, HasHelpMenu) {
MainWindow window;
bool has_help = false;
for (QAction* action : window.menuBar()->actions()) {
if (action->text().contains("Help")) {
has_help = true;
}
}
EXPECT_TRUE(has_help);
}

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