Enhancements and Bug fixes
authorFranklin S. Cooper Jr <fcooper@ti.com>
Tue, 29 Apr 2014 16:00:35 +0000 (11:00 -0500)
committerFranklin S. Cooper Jr <fcooper@ti.com>
Tue, 29 Apr 2014 16:00:35 +0000 (11:00 -0500)
* Added a Quit button.
* Added a delete current image button.
* Properly scale image based on the size of the screen.

image-gallery.pro
main.cpp
mainwindow.cpp
mainwindow.h
mainwindow.ui

index 0c9dc1e86e19ec7afa87601d7ac345c3c2da90b0..56e407e11bd1ec4b7d92a8745a83d032ea6c6c23 100644 (file)
@@ -16,3 +16,6 @@ SOURCES += main.cpp\
 HEADERS  += mainwindow.h
 
 FORMS    += mainwindow.ui
+
+target.path += /home/root
+INSTALLS += target
index 6e7efd975207b7f21796a1a9ed8eece2592f4c6c..63a1649261645e95b0bf0808650e70416f92054e 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -1,10 +1,25 @@
 #include <QtGui/QApplication>
 #include "mainwindow.h"
+#include <iostream>
+
+extern QString dirLocation;
 
 int main(int argc, char *argv[])
 {
     QApplication a(argc, argv);
+
+    if (a.arguments().count() != 2)
+    {
+      std::cerr << "You need to pass the absolute path to the directory containing the images\n" << endl;
+      return 1;
+    }
+
+    dirLocation = a.arguments()[1];
     MainWindow w;
+
+    w.setContextMenuPolicy(Qt::NoContextMenu);
+    w.setWindowFlags(Qt::FramelessWindowHint);
+    w.showMaximized();
     w.show();
     return a.exec();
 }
index 176ae7aecbac4edc86efa37d096e6561a881d451..eb80f8521dd64ae7d85f282d9ffe320f6e6d2837 100644 (file)
@@ -1,6 +1,8 @@
 #include "mainwindow.h"
 #include "ui_mainwindow.h"
 
+QString dirLocation;
+
 MainWindow::MainWindow(QWidget *parent) :
     QMainWindow(parent),
     ui(new Ui::MainWindow)
@@ -8,12 +10,13 @@ MainWindow::MainWindow(QWidget *parent) :
 
     ui->setupUi(this);
 
-    image = 0;
+
+    currentIndex = 0;
 
     QStringList filters;
     filters << "*.jpeg" << "*.jpg";
 
-    imagesDir = new QDir ( "/usr/share/camera-images/");
+    imagesDir = new QDir (dirLocation);
 
     imagesDir->setFilter(QDir::Files);
     imagesDir->setNameFilters( filters);
@@ -21,20 +24,17 @@ MainWindow::MainWindow(QWidget *parent) :
     imagesList = imagesDir->entryList();
 
 
-     ui->prevImage->hide();
+     ui->prevImage->setEnabled(false);
     if(imagesList.count() == 0 || imagesList.count() == 1) {
 
-        ui->nextImage->hide();
+        ui->nextImage->setEnabled(false);
 
         if(imagesList.count() == 0) {
-            ui->clearImages->hide();
+            ui->label->clear();
+            ui->label->setText("No images found");
+            ui->clearImages->setEnabled(false);
         }
     }
-
-    if(imagesList.count() > 0)
-        displayImage(0);
-
-
 }
 
 MainWindow::~MainWindow()
@@ -47,37 +47,67 @@ void MainWindow::on_prevImage_clicked()
 {
     currentIndex--;
     if(currentIndex <= 0)
-       ui->prevImage->hide();
+       ui->prevImage->setEnabled(false);
 
     if(currentIndex < imagesList.count())
-       ui->nextImage->show();
+       ui->nextImage->setEnabled(true);
 
     displayImage(currentIndex);
 }
 
 void MainWindow::on_clearImages_clicked()
 {
-     ui->nextImage->hide();
-     ui->prevImage->hide();
+
+     QMessageBox::StandardButton reply;
+     reply = QMessageBox::question(this,"Delete Confirmation","Delete image?",QMessageBox::Yes|QMessageBox::No);
+
+     if(reply == QMessageBox::No)
+         return;
+
+     ui->nextImage->setEnabled(false);
+     ui->prevImage->setEnabled(false);
 
      QStringList clearList = imagesDir->entryList();
 
-     for(int x = 0; x < clearList.size() ; x++ ) {
-         imagesDir->remove(clearList[x]);
-     }
 
-     ui->clearImages->hide();
-    ui->label->hide();
+    imagesDir->remove(clearList[currentIndex]);
+
+    imagesDir->refresh();
+
+    imagesList = imagesDir->entryList();
+
+    currentIndex--;
+
+    if(currentIndex < 0)
+        currentIndex = 0;
+
+    ui->nextImage->setEnabled(false);
+    ui->prevImage->setEnabled(false);
+
+    if(imagesList.count() > 1 && imagesList.count() -1 > currentIndex)
+        ui->nextImage->setEnabled(true);
+
+    if(currentIndex > 0)
+        ui->prevImage->setEnabled(true);
+
+    if(imagesList.count() >= 1)
+        displayImage(currentIndex);
+    else {
+        ui->clearImages->setEnabled(false);
+        ui->label->clear();
+        ui->label->setText("No images found");
+    }
+
 
 }
 
 void MainWindow::on_nextImage_clicked()
 {
     currentIndex++;
-    if(currentIndex >= 3)
-       ui->nextImage->hide();
+    if(currentIndex >= imagesList.size()-1)
+       ui->nextImage->setEnabled(false);
 
-    ui->prevImage->show();
+    ui->prevImage->setEnabled(true);
 
     displayImage(currentIndex);
 
@@ -85,16 +115,25 @@ void MainWindow::on_nextImage_clicked()
 
 void MainWindow::displayImage(int index) {
 
+    int width = ui->label->width();
+    int height = ui->label->height();
+    QPixmap image;
+    image.load(dirLocation+imagesList[index]);
+    image = image.scaled(width,height,Qt::KeepAspectRatio);
+    ui->label->setPixmap(image);
 
-    if(image) {
-        delete image;
-    }
-
-    image = new QPixmap("/usr/share/camera-images/"+imagesList[index]);
+}
 
-    ui->label->setPixmap(*image);
+void MainWindow::on_pushButton_clicked()
+{
+    this->close();
+}
+void MainWindow::showEvent(QShowEvent *ev)
+{
+    QMainWindow::showEvent(ev);
 
-    QSize pixSize = image->size();
-    pixSize.scale(size(), Qt::KeepAspectRatio);
-    ui->label->setFixedSize(pixSize);
+    if(imagesList.count() > 0)
+        displayImage(0);
 }
+
+
index 9399d5a9afc71c3a1afc908921aa81e97f25ea1e..5a3087d48a6892eb1d23be022a530dcd0d283668 100644 (file)
@@ -4,6 +4,7 @@
 #include <QMainWindow>
 #include <QDir>
 #include <QDebug>
+#include <QMessageBox>
 
 namespace Ui {
 class MainWindow;
@@ -12,11 +13,14 @@ class MainWindow;
 class MainWindow : public QMainWindow
 {
     Q_OBJECT
-    
+
 public:
     explicit MainWindow(QWidget *parent = 0);
+
     ~MainWindow();
-    
+
+protected:
+    void showEvent(QShowEvent *);
 private slots:
 
     void on_prevImage_clicked();
@@ -25,13 +29,16 @@ private slots:
 
     void on_nextImage_clicked();
 
+    void on_pushButton_clicked();
+
 private:
     Ui::MainWindow *ui;
     void displayImage(int count);
     int currentIndex;
-    QPixmap* image;
     QStringList imagesList;
     QDir* imagesDir;
 };
 
+
+
 #endif // MAINWINDOW_H
index 7ed1aa64e7414d5babfac1168029a26a67451cd4..26344c2a16d464902689a64c2707638ded318668 100644 (file)
    <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>
+   <layout class="QGridLayout" name="gridLayout">
+    <item row="0" column="1">
+     <layout class="QVBoxLayout" name="verticalLayout_4">
+      <item>
+       <layout class="QVBoxLayout" name="verticalLayout_6">
+        <item>
+         <widget class="QLabel" name="label">
+          <property name="styleSheet">
+           <string notr="true"/>
+          </property>
+          <property name="text">
+           <string/>
+          </property>
+          <property name="alignment">
+           <set>Qt::AlignCenter</set>
+          </property>
+         </widget>
+        </item>
+       </layout>
+      </item>
+      <item>
+       <layout class="QVBoxLayout" name="verticalLayout_5">
+        <item>
+         <layout class="QHBoxLayout" name="horizontalLayout_2">
+          <item>
+           <widget class="QPushButton" name="clearImages">
+            <property name="text">
+             <string>Delete</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <widget class="QPushButton" name="pushButton">
+            <property name="text">
+             <string>Quit</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <widget class="QPushButton" name="prevImage">
+            <property name="text">
+             <string>Previous</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <widget class="QPushButton" name="nextImage">
+            <property name="text">
+             <string>Next</string>
+            </property>
+           </widget>
+          </item>
+         </layout>
+        </item>
+       </layout>
+      </item>
+     </layout>
+    </item>
+   </layout>
   </widget>
  </widget>
  <layoutdefault spacing="6" margin="11"/>