Permalink
Browse files

Intial import

found on disk my very old project, it's ugly, needs to be rewritten.
  • Loading branch information...
vookimedlo committed Sep 15, 2017
1 parent 90b741d commit a8c9d295d97e28507cbc192fa357a0396beeafb7
Showing with 1,244 additions and 0 deletions.
  1. +38 −0 .gitignore
  2. +674 −0 LICENSE
  3. +30 −0 build/qmake/project.pro
  4. +11 −0 src/main.cpp
  5. +88 −0 src/ui/ImageArea.cpp
  6. +35 −0 src/ui/ImageArea.h
  7. +85 −0 src/ui/MainWindow.cpp
  8. +39 −0 src/ui/MainWindow.h
  9. +244 −0 src/ui/forms/MainWindow.ui
@@ -0,0 +1,38 @@
# Backups
*~
# Build dirs
build/build*
# User settings
*.user
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
674 LICENSE

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,30 @@
#-------------------------------------------------
#
# Project created by QtCreator 2017-01-02T20:42:10
#
#-------------------------------------------------
QT += core gui widgets
greaterThan(QT_MAJOR_VERSION, 5): QT += widgets
TARGET = VookiImageViever
TEMPLATE = app
# std::make_unique is part of c++14
#
CONFIG += c++14
SOURCES += \
../../src/main.cpp \
../../src/ui/MainWindow.cpp \
../../src/ui/ImageArea.cpp
HEADERS += \
../../src/ui/MainWindow.h \
../../src/ui/ImageArea.h
FORMS += \
../../src/ui/forms/MainWindow.ui
@@ -0,0 +1,11 @@
#include "ui/MainWindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
@@ -0,0 +1,88 @@
#include "ImageArea.h"
#include <QColor>
#include <QImage>
#include <QPainter>
#include <QRect>
#include <QPaintEvent>
ImageArea::ImageArea(QWidget *parent): isFitToWindow(false), scaleFactor(1.0), originalImage(), scaledImage(), finalImage(), QWidget(parent)
{
originalImage.fill(qRgb(0, 0, 0));
scaledImage.fill(qRgb(0, 0, 0));
finalImage.fill(qRgb(0, 0, 0));
}
bool ImageArea::showImage(const QString &fileName)
{
if (!originalImage.load(fileName))
return false;
scaleFactor = 1;
scaleImage();
update();
return true;
}
void ImageArea::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
QRect dirtyRect = event->rect();
painter.drawImage(dirtyRect, finalImage, dirtyRect);
}
void ImageArea::resizeEvent(QResizeEvent *event)
{
scaleImage();
update();
QWidget::resizeEvent(event);
}
void ImageArea::scaleImage()
{
if(isFitToWindow)
{
//QSize newSize = originalImage.size().expandedTo(size());
if(originalImage.width() < originalImage.height())
scaledImage = originalImage.scaledToHeight(height());
else
scaledImage = originalImage.scaledToWidth(width());
}
else
scaledImage = originalImage.scaledToWidth(originalImage.width() * scaleFactor);
QSize newSize = scaledImage.size().expandedTo(size());
QImage newImage(newSize, QImage::Format_RGB32);
newImage.fill(qRgb(0, 0, 0));
QPainter painterImage(&newImage);
painterImage.drawImage(QPoint(newSize.width() / 2 - scaledImage.size().width() / 2, newSize.height() / 2 - scaledImage.size().height() / 2), scaledImage);
finalImage = newImage;
}
void ImageArea::setFitToWindow(bool enabled)
{
isFitToWindow = enabled;
scaleImage();
update();
}
void ImageArea::zoomImageIn(double factor)
{
double newScaleFactor = factor + scaleFactor;
if(newScaleFactor > 3.0)
return;
scaleFactor = newScaleFactor;
scaleImage();
update();
}
void ImageArea::zoomImageOut(double factor)
{
double newScaleFactor = -1 * factor + scaleFactor;
if(newScaleFactor < 0.2)
return;
scaleFactor = newScaleFactor;
scaleImage();
update();
}
@@ -0,0 +1,35 @@
#ifndef IMAGEAREA_H
#define IMAGEAREA_H
#include <QWidget>
class ImageArea : public QWidget
{
Q_OBJECT
private:
bool isFitToWindow;
double scaleFactor;
QImage originalImage;
QImage scaledImage;
QImage finalImage;
public:
ImageArea(QWidget *parent = 0);
void setFitToWindow(bool enabled);
bool showImage(const QString &fileName);
void zoomImageIn(double factor);
void zoomImageOut(double factor);
public slots:
protected:
void paintEvent(QPaintEvent *event);
void resizeEvent(QResizeEvent *event);
private:
void scaleImage();
};
#endif // IMAGEAREA_H
@@ -0,0 +1,85 @@
#include "MainWindow.h"
#include "ui_MainWindow.h"
#include <QFileSystemModel>
#include <QPainter>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
fileSystemModel(new QFileSystemModel())
{
ui->setupUi(this);
fileSystemModel->setRootPath(QDir::currentPath());
ui->treeView->setModel(fileSystemModel);
for(int i = 1; i < fileSystemModel->columnCount(); i++)
ui->treeView->setColumnHidden(i, true);
QStringList filters;
filters << "*.JPG";
filters << "*.BMP";
filters << "*.GIF";
filters << "*.JPEG";
filters << "*.PNG";
filters << "*.PBM";
filters << "*.PGM";
filters << "*.PPM";
filters << "*.XBM";
filters << "*.XPM";
fileSystemModel->setNameFilters(filters);
fileSystemModel->setNameFilterDisables(false);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_action_Quit_triggered()
{
close();
}
void MainWindow::on_action_FullScreen_triggered()
{
if(isFullScreen())
{
showNormal();
ui->toolBar->show();
ui->mainToolBar->show();
ui->dockWidget->show();
ui->statusBar->show();
}
else
{
ui->toolBar->hide();
ui->mainToolBar->hide();
ui->dockWidget->hide();
ui->statusBar->hide();
showFullScreen();
}
}
void MainWindow::on_treeView_doubleClicked(const QModelIndex &index)
{
QString filePath = fileSystemModel->filePath(index);
ui->imageAreaWidget->showImage(filePath);
}
void MainWindow::on_actionZoom_In_triggered()
{
ui->imageAreaWidget->zoomImageIn(0.10);
}
void MainWindow::on_actionZoom_Out_triggered()
{
ui->imageAreaWidget->zoomImageOut(0.10);
}
void MainWindow::on_actionFi_t_to_Window_toggled(bool checked)
{
ui->imageAreaWidget->setFitToWindow(checked);
}
@@ -0,0 +1,39 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui>
#include <QtCore>
#include <QtWidgets>
namespace Ui {
class MainWindow;
}
class QFileSystemModel;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_action_Quit_triggered();
void on_treeView_doubleClicked(const QModelIndex &index);
void on_actionZoom_In_triggered();
void on_actionZoom_Out_triggered();
void on_actionFi_t_to_Window_toggled(bool arg1);
void on_action_FullScreen_triggered();
private:
Ui::MainWindow *ui;
QFileSystemModel *fileSystemModel;
};
#endif // MAINWINDOW_H
Oops, something went wrong.

0 comments on commit a8c9d29

Please sign in to comment.