Load and show image info
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
#include "imageinfo.h"
|
||||
|
||||
ImageInfo::ImageInfo(QWidget *parent) : QTreeWidget(parent)
|
||||
{
|
||||
setColumnCount(2);
|
||||
setHeaderLabels({tr("Property"), tr("Value")});
|
||||
}
|
||||
|
||||
void ImageInfo::setInfo(ImageInfoData info)
|
||||
{
|
||||
clear();
|
||||
QList<QTreeWidgetItem*> items;
|
||||
QTreeWidgetItem *w;
|
||||
int i=0;
|
||||
for(StringPair item : info)
|
||||
{
|
||||
w = new QTreeWidgetItem({item.first, item.second});
|
||||
w->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
||||
|
||||
items.append(w);
|
||||
i++;
|
||||
}
|
||||
insertTopLevelItems(0, items);
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
#ifndef IMAGEINFO_H
|
||||
#define IMAGEINFO_H
|
||||
|
||||
#include <QTreeWidget>
|
||||
|
||||
typedef QPair<QString, QString> StringPair;
|
||||
typedef QVector<StringPair> ImageInfoData;
|
||||
|
||||
Q_DECLARE_METATYPE(ImageInfoData);
|
||||
|
||||
class ImageInfo : public QTreeWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ImageInfo(QWidget *parent);
|
||||
public slots:
|
||||
void setInfo(ImageInfoData info);
|
||||
};
|
||||
|
||||
#endif // IMAGEINFO_H
|
||||
+8
-1
@@ -44,17 +44,23 @@ QPixmap Image::pixmap() const
|
||||
return m_pixmap;
|
||||
}
|
||||
|
||||
ImageInfoData Image::info() const
|
||||
{
|
||||
return m_info;
|
||||
}
|
||||
|
||||
bool Image::isCurrent() const
|
||||
{
|
||||
return !m_released;
|
||||
}
|
||||
|
||||
void Image::imageLoaded(QImage img)
|
||||
void Image::imageLoaded(QImage img, ImageInfoData info)
|
||||
{
|
||||
m_loading = false;
|
||||
if(!m_released)
|
||||
{
|
||||
m_pixmap = QPixmap::fromImage(img);
|
||||
m_info = info;
|
||||
emit pixmapLoaded(this);
|
||||
}
|
||||
}
|
||||
@@ -183,6 +189,7 @@ void ImageRingList::imageLoaded(Image *image)
|
||||
if(image->name() == (*m_currImage)->name())
|
||||
{
|
||||
emit pixmapLoaded(image->pixmap());
|
||||
emit infoLoaded(image->info());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-1
@@ -6,6 +6,7 @@
|
||||
#include <QList>
|
||||
#include <QPixmap>
|
||||
#include <memory>
|
||||
#include "imageinfo.h"
|
||||
|
||||
class Image : public QObject
|
||||
{
|
||||
@@ -15,17 +16,19 @@ class Image : public QObject
|
||||
bool m_current;
|
||||
QPixmap m_pixmap;
|
||||
QString m_name;
|
||||
ImageInfoData m_info;
|
||||
public:
|
||||
explicit Image(const QString name);
|
||||
void load();
|
||||
void release();
|
||||
QString name() const;
|
||||
QPixmap pixmap() const;
|
||||
ImageInfoData info() const;
|
||||
bool isCurrent() const;
|
||||
signals:
|
||||
void pixmapLoaded(Image *ptr);
|
||||
protected slots:
|
||||
void imageLoaded(QImage img);
|
||||
void imageLoaded(QImage img, ImageInfoData info);
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<Image> ImagePtr;
|
||||
@@ -54,6 +57,7 @@ protected:
|
||||
QList<ImagePtr>::iterator decrement(QList<ImagePtr>::iterator iter);
|
||||
signals:
|
||||
void pixmapLoaded(QPixmap pix);
|
||||
void infoLoaded(ImageInfoData info);
|
||||
void currentImageChanged();
|
||||
protected slots:
|
||||
void imageLoaded(Image *image);
|
||||
|
||||
+5
-3
@@ -13,17 +13,19 @@ TEMPLATE = app
|
||||
|
||||
CONFIG += c++11
|
||||
|
||||
LIBS += -lraw
|
||||
LIBS += -lraw -lexif
|
||||
|
||||
SOURCES += main.cpp\
|
||||
mainwindow.cpp \
|
||||
imagescrollarea.cpp \
|
||||
imageringlist.cpp \
|
||||
database.cpp \
|
||||
loadrunable.cpp
|
||||
loadrunable.cpp \
|
||||
imageinfo.cpp
|
||||
|
||||
HEADERS += mainwindow.h \
|
||||
imagescrollarea.h \
|
||||
imageringlist.h \
|
||||
database.h \
|
||||
loadrunable.h
|
||||
loadrunable.h \
|
||||
imageinfo.h
|
||||
|
||||
+22
-2
@@ -1,6 +1,9 @@
|
||||
#include "loadrunable.h"
|
||||
#include "imageringlist.h"
|
||||
#include <libraw/libraw.h>
|
||||
#include "imageinfo.h"
|
||||
#include <QFileInfo>
|
||||
#include <libexif/exif-data.h>
|
||||
|
||||
LoadRunable::LoadRunable(const QString &file, Image *receiver) :
|
||||
m_file(file),
|
||||
@@ -14,6 +17,9 @@ void LoadRunable::run()
|
||||
{
|
||||
return;
|
||||
}
|
||||
ImageInfoData info;
|
||||
QFileInfo finfo(m_file);
|
||||
info.append(StringPair(QObject::tr("Filename"), finfo.fileName()));
|
||||
|
||||
if(m_file.endsWith(".CR2", Qt::CaseInsensitive))
|
||||
{
|
||||
@@ -24,6 +30,7 @@ void LoadRunable::run()
|
||||
raw.imgdata.params.user_flip = 0;
|
||||
raw.unpack();
|
||||
raw.dcraw_process();
|
||||
libraw_data_t *imgdata = &raw.imgdata;
|
||||
libraw_processed_image_t *rawImg = raw.dcraw_make_mem_image();
|
||||
QImage img(rawImg->width, rawImg->height, QImage::Format_RGB888);
|
||||
|
||||
@@ -32,12 +39,25 @@ void LoadRunable::run()
|
||||
{
|
||||
memcpy(img.scanLine(i), rawImg->data+(i*scanLine), scanLine);
|
||||
}
|
||||
info.append(StringPair(QObject::tr("Width"), QString::number(rawImg->width)));
|
||||
info.append(StringPair(QObject::tr("Height"), QString::number(rawImg->height)));
|
||||
info.append(StringPair(QObject::tr("ISO"), QString::number(raw.imgdata.other.iso_speed)));
|
||||
raw.dcraw_clear_mem(rawImg);
|
||||
QMetaObject::invokeMethod(m_receiver, "imageLoaded", Qt::QueuedConnection, Q_ARG(QImage, img));
|
||||
QMetaObject::invokeMethod(m_receiver, "imageLoaded", Qt::QueuedConnection, Q_ARG(QImage, img), Q_ARG(ImageInfoData, info));
|
||||
}
|
||||
else
|
||||
{
|
||||
QImage img(m_file);
|
||||
QMetaObject::invokeMethod(m_receiver, "imageLoaded", Qt::QueuedConnection, Q_ARG(QImage, img));
|
||||
ExifData *exif = exif_data_new_from_file(m_file.toLocal8Bit().constData());
|
||||
info.append(StringPair(QObject::tr("Width"), QString::number(img.width())));
|
||||
info.append(StringPair(QObject::tr("Height"), QString::number(img.height())));
|
||||
if(exif)
|
||||
{
|
||||
char val[1024];
|
||||
ExifEntry *entry = exif_content_get_entry(exif->ifd[EXIF_IFD_EXIF], EXIF_TAG_ISO_SPEED_RATINGS);
|
||||
exif_entry_get_value(entry, val, sizeof(val));
|
||||
info.append(StringPair(QObject::tr("ISO"), QString(val)));
|
||||
}
|
||||
QMetaObject::invokeMethod(m_receiver, "imageLoaded", Qt::QueuedConnection, Q_ARG(QImage, img), Q_ARG(ImageInfoData, info));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <QDebug>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/btrfs.h>
|
||||
#include <QDockWidget>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
@@ -21,6 +22,12 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
|
||||
loading(false),
|
||||
queued(0)
|
||||
{
|
||||
qRegisterMetaType<ImageInfoData>("ImageInfoData");
|
||||
|
||||
m_info = new ImageInfo(this);
|
||||
QDockWidget *infoDock = new QDockWidget(tr("Image info"), this);
|
||||
infoDock->setWidget(m_info);
|
||||
addDockWidget(Qt::LeftDockWidgetArea, infoDock);
|
||||
m_image = new ImageScrollArea(this);
|
||||
setCentralWidget(m_image);
|
||||
resize(800, 600);
|
||||
@@ -30,6 +37,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
|
||||
m_ringList = new ImageRingList(this);
|
||||
connect(m_ringList, SIGNAL(pixmapLoaded(QPixmap)), this, SLOT(pixmapLoaded(QPixmap)));
|
||||
connect(m_ringList, SIGNAL(currentImageChanged()), this, SLOT(updateWindowTitle()));
|
||||
connect(m_ringList, SIGNAL(infoLoaded(ImageInfoData)), m_info, SLOT(setInfo(ImageInfoData)));
|
||||
|
||||
QMenu *fileMenu = new QMenu(tr("File"), this);
|
||||
fileMenu->addAction(tr("Open"), this, SLOT(openFile()), QKeySequence("Ctrl+O"));
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "imageringlist.h"
|
||||
#include "imagescrollarea.h"
|
||||
#include "database.h"
|
||||
#include "imageinfo.h"
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
@@ -13,6 +14,7 @@ class MainWindow : public QMainWindow
|
||||
ImageScrollArea *m_image;
|
||||
ImageRingList *m_ringList;
|
||||
Database *m_database;
|
||||
ImageInfo *m_info;
|
||||
bool loading;
|
||||
int queued;
|
||||
static int socketPair[2];
|
||||
|
||||
Reference in New Issue
Block a user