From a97f90531826b33cd5b7a2bc6cbef079b8ebaac2 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sun, 1 Nov 2020 20:01:00 +0200 Subject: Initial commit --- src/main.cpp | 23 ++++++++++++++++++ src/mainwindow.cpp | 29 ++++++++++++++++++++++ src/mainwindow.h | 24 ++++++++++++++++++ src/mainwindow.ui | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 147 insertions(+) create mode 100644 src/main.cpp create mode 100644 src/mainwindow.cpp create mode 100644 src/mainwindow.h create mode 100644 src/mainwindow.ui (limited to 'src') 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