Initial Commit
authorFranklin S Cooper Jr <fcooper@ti.com>
Tue, 18 Feb 2014 18:20:28 +0000 (12:20 -0600)
committerFranklin S Cooper Jr <fcooper@ti.com>
Tue, 18 Feb 2014 18:20:28 +0000 (12:20 -0600)
image-gallery.pro [new file with mode: 0644]
main.cpp [new file with mode: 0644]
mainwindow.cpp [new file with mode: 0644]
mainwindow.h [new file with mode: 0644]
mainwindow.ui [new file with mode: 0644]

diff --git a/image-gallery.pro b/image-gallery.pro
new file mode 100644 (file)
index 0000000..0c9dc1e
--- /dev/null
@@ -0,0 +1,18 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator 2014-02-07T15:52:22
+#
+#-------------------------------------------------
+
+QT       += core gui
+
+TARGET = image-gallery
+TEMPLATE = app
+
+
+SOURCES += main.cpp\
+        mainwindow.cpp
+
+HEADERS  += mainwindow.h
+
+FORMS    += mainwindow.ui
diff --git a/main.cpp b/main.cpp
new file mode 100644 (file)
index 0000000..6e7efd9
--- /dev/null
+++ b/main.cpp
@@ -0,0 +1,10 @@
+#include <QtGui/QApplication>
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+    QApplication a(argc, argv);
+    MainWindow w;
+    w.show();
+    return a.exec();
+}
diff --git a/mainwindow.cpp b/mainwindow.cpp
new file mode 100644 (file)
index 0000000..176ae7a
--- /dev/null
@@ -0,0 +1,100 @@
+#include "mainwindow.h"
+#include "ui_mainwindow.h"
+
+MainWindow::MainWindow(QWidget *parent) :
+    QMainWindow(parent),
+    ui(new Ui::MainWindow)
+{
+
+    ui->setupUi(this);
+
+    image = 0;
+
+    QStringList filters;
+    filters << "*.jpeg" << "*.jpg";
+
+    imagesDir = new QDir ( "/usr/share/camera-images/");
+
+    imagesDir->setFilter(QDir::Files);
+    imagesDir->setNameFilters( filters);
+    imagesDir->setSorting(QDir::Name);
+    imagesList = imagesDir->entryList();
+
+
+     ui->prevImage->hide();
+    if(imagesList.count() == 0 || imagesList.count() == 1) {
+
+        ui->nextImage->hide();
+
+        if(imagesList.count() == 0) {
+            ui->clearImages->hide();
+        }
+    }
+
+    if(imagesList.count() > 0)
+        displayImage(0);
+
+
+}
+
+MainWindow::~MainWindow()
+{
+    delete ui;
+}
+
+
+void MainWindow::on_prevImage_clicked()
+{
+    currentIndex--;
+    if(currentIndex <= 0)
+       ui->prevImage->hide();
+
+    if(currentIndex < imagesList.count())
+       ui->nextImage->show();
+
+    displayImage(currentIndex);
+}
+
+void MainWindow::on_clearImages_clicked()
+{
+     ui->nextImage->hide();
+     ui->prevImage->hide();
+
+     QStringList clearList = imagesDir->entryList();
+
+     for(int x = 0; x < clearList.size() ; x++ ) {
+         imagesDir->remove(clearList[x]);
+     }
+
+     ui->clearImages->hide();
+    ui->label->hide();
+
+}
+
+void MainWindow::on_nextImage_clicked()
+{
+    currentIndex++;
+    if(currentIndex >= 3)
+       ui->nextImage->hide();
+
+    ui->prevImage->show();
+
+    displayImage(currentIndex);
+
+}
+
+void MainWindow::displayImage(int index) {
+
+
+    if(image) {
+        delete image;
+    }
+
+    image = new QPixmap("/usr/share/camera-images/"+imagesList[index]);
+
+    ui->label->setPixmap(*image);
+
+    QSize pixSize = image->size();
+    pixSize.scale(size(), Qt::KeepAspectRatio);
+    ui->label->setFixedSize(pixSize);
+}
diff --git a/mainwindow.h b/mainwindow.h
new file mode 100644 (file)
index 0000000..9399d5a
--- /dev/null
@@ -0,0 +1,37 @@
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+#include <QDir>
+#include <QDebug>
+
+namespace Ui {
+class MainWindow;
+}
+
+class MainWindow : public QMainWindow
+{
+    Q_OBJECT
+    
+public:
+    explicit MainWindow(QWidget *parent = 0);
+    ~MainWindow();
+    
+private slots:
+
+    void on_prevImage_clicked();
+
+    void on_clearImages_clicked();
+
+    void on_nextImage_clicked();
+
+private:
+    Ui::MainWindow *ui;
+    void displayImage(int count);
+    int currentIndex;
+    QPixmap* image;
+    QStringList imagesList;
+    QDir* imagesDir;
+};
+
+#endif // MAINWINDOW_H
diff --git a/mainwindow.ui b/mainwindow.ui
new file mode 100644 (file)
index 0000000..7ed1aa6
--- /dev/null
@@ -0,0 +1,93 @@
+<?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>680</width>
+    <height>386</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>MainWindow</string>
+  </property>
+  <widget class="QWidget" name="centralWidget">
+   <widget class="QLabel" name="label">
+    <property name="geometry">
+     <rect>
+      <x>0</x>
+      <y>0</y>
+      <width>391</width>
+      <height>191</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string/>
+    </property>
+   </widget>
+   <widget class="QPushButton" name="prevImage">
+    <property name="geometry">
+     <rect>
+      <x>0</x>
+      <y>210</y>
+      <width>93</width>
+      <height>27</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>Previous</string>
+    </property>
+   </widget>
+   <widget class="QPushButton" name="nextImage">
+    <property name="geometry">
+     <rect>
+      <x>300</x>
+      <y>210</y>
+      <width>93</width>
+      <height>27</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>Next</string>
+    </property>
+   </widget>
+   <widget class="QPushButton" name="clearImages">
+    <property name="geometry">
+     <rect>
+      <x>150</x>
+      <y>210</y>
+      <width>93</width>
+      <height>27</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>Clear</string>
+    </property>
+   </widget>
+  </widget>
+  <widget class="QMenuBar" name="menuBar">
+   <property name="geometry">
+    <rect>
+     <x>0</x>
+     <y>0</y>
+     <width>680</width>
+     <height>23</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QStatusBar" name="statusBar"/>
+  <widget class="QToolBar" name="mainToolBar">
+   <attribute name="toolBarArea">
+    <enum>TopToolBarArea</enum>
+   </attribute>
+   <attribute name="toolBarBreak">
+    <bool>false</bool>
+   </attribute>
+  </widget>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <resources/>
+ <connections/>
+</ui>