From a97f90531826b33cd5b7a2bc6cbef079b8ebaac2 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sun, 1 Nov 2020 20:01:00 +0200 Subject: Initial commit --- .gitignore | 1 + meson.build | 32 ++++++++++++++++++++++++ src/main.cpp | 23 ++++++++++++++++++ src/mainwindow.cpp | 29 ++++++++++++++++++++++ src/mainwindow.h | 24 ++++++++++++++++++ src/mainwindow.ui | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 180 insertions(+) create mode 100644 .gitignore create mode 100644 meson.build create mode 100644 src/main.cpp create mode 100644 src/mainwindow.cpp create mode 100644 src/mainwindow.h create mode 100644 src/mainwindow.ui diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..378eac2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..7c3aac3 --- /dev/null +++ b/meson.build @@ -0,0 +1,32 @@ +project('qimv', 'cpp', + version : '0.1', + default_options : ['warning_level=3', 'cpp_std=c++14']) + +summary({ + 'prefix': get_option('prefix'), + 'bindir': get_option('bindir'), + 'libdir': get_option('libdir'), + 'datadir': get_option('datadir') +}, section: 'Install locations') + +cxx = meson.get_compiler('cpp') +summary({ + 'id': cxx.get_id(), + 'version': cxx.version(), + 'linker': cxx.get_linker_id(), +}, section: 'Compiler') + +mod_qt5 = import('qt5') +dep_qt5 = dependency('qt5', modules: [ 'Core', 'Widgets' ], include_type: 'system') + +moc = mod_qt5.preprocess( + moc_headers: [ 'src/mainwindow.h' ], + ui_files: [ 'src/mainwindow.ui' ], + dependencies: dep_qt5 +) + +exe = executable('qimv', + sources: [ 'src/main.cpp', 'src/mainwindow.cpp', moc ], + dependencies: dep_qt5, + install: true) + diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..441a2c5 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,23 @@ +#include "mainwindow.h" +#include +#include + +#define PROJECT_NAME "qimv" + +int main(int argc, char **argv) { + QApplication app(argc, argv); + app.setApplicationName("qimv"); + app.setApplicationVersion("0.1.0"); + + QCommandLineParser parser; + parser.setApplicationDescription("Quick image viewer"); + parser.addHelpOption(); + parser.addVersionOption(); + parser.addPositionalArgument("image", "Image to show."); + + parser.process(app); + + MainWindow wnd(parser.positionalArguments()); + wnd.show(); + return app.exec(); +} diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp new file mode 100644 index 0000000..9eba572 --- /dev/null +++ b/src/mainwindow.cpp @@ -0,0 +1,29 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include +#include +#include + +MainWindow::MainWindow(const QStringList &filePaths, QWidget *parent) + : QMainWindow(parent), ui(new Ui::MainWindow) { + ui->setupUi(this); + + connect(ui->actionQuit, &QAction::triggered, qApp, &QApplication::quit); + + if (!filePaths.isEmpty()) { + current.load(filePaths.first()); + setWindowTitle(title_format.arg(filePaths.first())); + ui->label->setPixmap(current); + } +} + +MainWindow::~MainWindow() { delete ui; } + +void MainWindow::resizeEvent(QResizeEvent *event) { + const auto width = ui->label->width(); + const auto height = ui->label->height(); + + ui->label->setPixmap(current.scaled(width, height, Qt::KeepAspectRatio)); + + QMainWindow::resizeEvent(event); +} diff --git a/src/mainwindow.h b/src/mainwindow.h new file mode 100644 index 0000000..a270fd8 --- /dev/null +++ b/src/mainwindow.h @@ -0,0 +1,24 @@ +#pragma once + +#include +#include + +namespace Ui { +class MainWindow; +} + +class MainWindow final : public QMainWindow { + Q_OBJECT + +public: + explicit MainWindow(const QStringList &filePaths, QWidget *parent = nullptr); + ~MainWindow() override; + +protected: + void resizeEvent(QResizeEvent *event) override; + +private: + Ui::MainWindow *ui; + QPixmap current; + const QString title_format{"qimv [%1]"}; +}; diff --git a/src/mainwindow.ui b/src/mainwindow.ui new file mode 100644 index 0000000..5ea19df --- /dev/null +++ b/src/mainwindow.ui @@ -0,0 +1,71 @@ + + + MainWindow + + + + 0 + 0 + 800 + 600 + + + + qimv + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + [ no data ] + + + Qt::AlignCenter + + + + + + + + + 0 + 0 + 800 + 20 + + + + + qimv + + + + + + + + + Quit + + + Ctrl+Q + + + + + + -- cgit v1.2.1