summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--meson.build32
-rw-r--r--src/main.cpp23
-rw-r--r--src/mainwindow.cpp29
-rw-r--r--src/mainwindow.h24
-rw-r--r--src/mainwindow.ui71
6 files changed, 180 insertions, 0 deletions
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 <QApplication>
+#include <QCommandLineParser>
+
+#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 <QApplication>
+#include <QPixmap>
+#include <QResizeEvent>
+
+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 <QMainWindow>
+#include <QPixmap>
+
+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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>800</width>
+ <height>600</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>qimv</string>
+ </property>
+ <widget class="QWidget" name="centralwidget">
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>[ no data ]</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QMenuBar" name="menubar">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>800</width>
+ <height>20</height>
+ </rect>
+ </property>
+ <widget class="QMenu" name="menuqimv">
+ <property name="title">
+ <string>qimv</string>
+ </property>
+ <addaction name="actionQuit"/>
+ </widget>
+ <addaction name="menuqimv"/>
+ </widget>
+ <widget class="QStatusBar" name="statusbar"/>
+ <action name="actionQuit">
+ <property name="text">
+ <string>Quit</string>
+ </property>
+ <property name="shortcut">
+ <string>Ctrl+Q</string>
+ </property>
+ </action>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>