diff --git a/imageinfo.cpp b/imageinfo.cpp new file mode 100644 index 0000000..bac61a2 --- /dev/null +++ b/imageinfo.cpp @@ -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 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); +} diff --git a/imageinfo.h b/imageinfo.h new file mode 100644 index 0000000..1c31271 --- /dev/null +++ b/imageinfo.h @@ -0,0 +1,20 @@ +#ifndef IMAGEINFO_H +#define IMAGEINFO_H + +#include + +typedef QPair StringPair; +typedef QVector ImageInfoData; + +Q_DECLARE_METATYPE(ImageInfoData); + +class ImageInfo : public QTreeWidget +{ + Q_OBJECT +public: + ImageInfo(QWidget *parent); +public slots: + void setInfo(ImageInfoData info); +}; + +#endif // IMAGEINFO_H diff --git a/imageringlist.cpp b/imageringlist.cpp index 7f36724..14f6b1b 100644 --- a/imageringlist.cpp +++ b/imageringlist.cpp @@ -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()); } } diff --git a/imageringlist.h b/imageringlist.h index fffed21..c921ff6 100644 --- a/imageringlist.h +++ b/imageringlist.h @@ -6,6 +6,7 @@ #include #include #include +#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 ImagePtr; @@ -54,6 +57,7 @@ protected: QList::iterator decrement(QList::iterator iter); signals: void pixmapLoaded(QPixmap pix); + void infoLoaded(ImageInfoData info); void currentImageChanged(); protected slots: void imageLoaded(Image *image); diff --git a/imageselector.pro b/imageselector.pro index 7e8070f..7436d7c 100644 --- a/imageselector.pro +++ b/imageselector.pro @@ -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 diff --git a/loadrunable.cpp b/loadrunable.cpp index f976ee3..c32a7a8 100644 --- a/loadrunable.cpp +++ b/loadrunable.cpp @@ -1,6 +1,9 @@ #include "loadrunable.h" #include "imageringlist.h" #include +#include "imageinfo.h" +#include +#include 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)); } } diff --git a/mainwindow.cpp b/mainwindow.cpp index 68fd4cb..2e44f44 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -21,6 +22,12 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), loading(false), queued(0) { + qRegisterMetaType("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")); diff --git a/mainwindow.h b/mainwindow.h index 9caca6a..cd3747e 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -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];