Skip to content

Commit

Permalink
click enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
richardyqn committed Jan 21, 2015
1 parent 21f5f91 commit 3f1f5bd
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 41 deletions.
8 changes: 6 additions & 2 deletions Richard_photoList/Richard_photoList.pro
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ TEMPLATE = app

SOURCES += main.cpp\
mainwindow.cpp \
mylabel.cpp
mylabel.cpp \
label.cpp \
clickmenu.cpp

HEADERS += mainwindow.h \
mylabel.h
mylabel.h \
label.h \
clickmenu.h

FORMS += mainwindow.ui

Expand Down
2 changes: 1 addition & 1 deletion Richard_photoList/Richard_photoList.pro.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.2.1, 2015-01-11T16:38:45. -->
<!-- Written by QtCreator 3.2.1, 2015-01-21T02:37:43. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
Expand Down
8 changes: 8 additions & 0 deletions Richard_photoList/clickmenu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "clickmenu.h"

clickMenu::clickMenu()
{
}

clickMenu::~clickMenu() {
}
17 changes: 17 additions & 0 deletions Richard_photoList/clickmenu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef CLICKMENU_H
#define CLICKMENU_H

#include <QAction>


class clickMenu
{
public:
clickMenu();
~clickMenu();
// Copy Constructors and Assignment Operator not defined
// They only create shallow copies
QAction** actionList;
};

#endif // CLICKMENU_H
2 changes: 2 additions & 0 deletions Richard_photoList/label.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include "label.h"

26 changes: 26 additions & 0 deletions Richard_photoList/label.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef LABEL_H
#define LABEL_H

#include <QLabel>
#include <QMenu>
#include <QMouseEvent>
#include <stdio.h>

class Label : public QLabel
{
public:
Label(QWidget* pParent=0, Qt::WindowFlags f=0) : QLabel(pParent, f) {};
Label(const QString& text, QWidget* pParent = 0, Qt::WindowFlags f = 0) : QLabel(text, pParent, f){};

protected :
virtual void mouseReleaseEvent ( QMouseEvent * ev ) {
//fprintf(stderr, "%d\n", ev->globalX());
//fprintf(stderr, "%d\n\n", ev->globalY());

QMenu MyMenu(this);
MyMenu.addActions(this->actions());
MyMenu.exec(ev->globalPos());
}
};

#endif // LABEL_H
1 change: 1 addition & 0 deletions Richard_photoList/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "mainwindow.h"
#include <QApplication>
#include <QDesktopWidget>
#include <stdio.h>

int main(int argc, char *argv[])
{
Expand Down
140 changes: 104 additions & 36 deletions Richard_photoList/mainwindow.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "stdio.h"


// I want to display 100 rows of pictures
// each row contains 8 columns;
const int rows = 100;
const int columns = 6;
long totalElements = rows * columns;

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
Expand Down Expand Up @@ -28,47 +36,54 @@ MainWindow::MainWindow(QWidget *parent) :
const int w = 300;
const int h = 300;

// I want to display 100 rows of pictures
// each row contains 8 columns;
const int rows = 100;
const int columns = 6;

dir = new QDir("/Users/richardyu/Pictures/photolist");
QStringList filters;
filters << "*png" << "*jpg" << "*JPEG" << "*.bmp";
filters << "*png" << "*jpg" << "*JPEG" << "*.bmp" << "deleted";
dir->setNameFilters(filters);
QFileInfoList list = dir->entryInfoList();

long listCount = 0;
fileInfoList = new QFileInfoList(dir->entryInfoList());

imageLabel = new QLabel*[rows * columns];
imageMap = new QPixmap*[rows * columns];
imageName = new QLabel*[rows * columns];
int listCount = 0;
imageLabel = new Label*[totalElements];
imageMap = new QPixmap*[totalElements];
imageName = new Label*[totalElements];
//menuList = new clickMenu*[totalElements];
//for (int i = 0; i < totalElements; i++) menuList[i] = NULL;
actionList = new QAction**[totalElements];
for (int i = 0; i < totalElements; i++) actionList[i] = NULL;

//QLabel* filename;


// double for loop, treat the image grid like a matrix
// for every row, display each column in the current row
for (int k = 0; k < rows; k=k+2) {
for (int j = 0; j < columns; j++) {

// When all files in the directory are added to the screen
// Jump out of the loop using 'goto'
if (listCount == list.size()) goto jump;
if (listCount == fileInfoList->size()) goto jump;

// fileinfo contains the path of every image
QFileInfo fileinfo = list.at(listCount);
QFileInfo fileinfo = fileInfoList->at(listCount);

auto int index = k*columns + j;
imageLabel[index] = new QLabel();
imageName[index] = new QLabel();
imageLabel[index] = new Label();
imageName[index] = new Label();
imageMap[index] = new QPixmap(fileinfo.absoluteFilePath());
imageLabel[index]->setPixmap(imageMap[index]->scaled(w,h,Qt::KeepAspectRatio));
//Widget* tmp(imageLabel[index]);
//filename = new QLabel;
QString temp = "<font color='red'>" + fileinfo.fileName();
QString temp = "<font color='blue'>" + fileinfo.fileName();
imageName[index]->setText(temp);

actionList[index] = new QAction*[2];
actionList[index][0] = new QAction("Rename", imageLabel[index]);
actionList[index][1] = new QAction("Delete", imageLabel[index]);
imageLabel[index]->addAction(actionList[index][0]);
imageLabel[index]->addAction(actionList[index][1]);
connect(actionList[index][0], SIGNAL(triggered()), this, SLOT(onAction1()));
connect(actionList[index][1], SIGNAL(triggered()), this, SLOT(onAction2()));
fprintf(stderr, "hello\n");
gridLayout->addWidget(imageLabel[index],k,j);
//gridLayout->addWidget(tmp,k,j);
gridLayout->addWidget(imageName[index],k+1,j);
Expand All @@ -78,13 +93,6 @@ MainWindow::MainWindow(QWidget *parent) :

jump: listCount = 0;


//QPixmap* tmpmap = new QPixmap("/Users/richardyu/Pictures/conduct.png");
//QLabel* tmplabel;
//tmplabel->setPixmap(tmpmap->scaled(w,h,Qt::KeepAspectRatioByExpanding));
//Widget* tmpwidget = new Widget(tmplabel);
//gridLayout->addWidget(tmpwidget, 0, 80);

area->setWidget(gridWidget);
entireLayout->setAlignment(Qt::AlignTop);
entireLayout->addWidget(ui->hideImage);
Expand All @@ -99,9 +107,16 @@ MainWindow::MainWindow(QWidget *parent) :
MainWindow::~MainWindow()
{
delete dir;
if (actionList != NULL)
for (int i = 0; i < totalElements; i++) {
if (actionList[i] != NULL)
delete [] (actionList[i]);
}
delete [] actionList;
delete []imageMap;
delete []imageName;
delete []imageLabel;
delete fileInfoList;
delete gridLayout;
delete gridWidget;
delete area;
Expand All @@ -115,7 +130,24 @@ void MainWindow::on_hideImage_released()
clearImage();
}


void MainWindow::onAction2() {
/*
QFileInfo fileInfo = fileInfoList->at(listCount);
QString fileOldName = fileInfo.fileName();
QString fileNewName = "_deleted" + fileOldName;
dir->rename(fileOldName, fileNewName);
*/
clearImage();
//addImage();
}

void MainWindow::onAction1() {

}

void MainWindow::clearImage() {

delete []imageMap;
imageMap = NULL;
delete []imageLabel;
Expand All @@ -136,29 +168,65 @@ void MainWindow::addImage() {
area->setBackgroundRole(QPalette::Dark);

// image hight and width
const int w = 150;
const int h = 150;
const int w = 300;
const int h = 300;

// I want to display 100 rows of pictures
// each row contains 8 columns;
const int rows = 100;
const int columns = 8;
//const int rows = 100;
//const int columns = 8;
dir = new QDir("/Users/richardyu/Pictures/photolist");
QStringList filters;
filters << "*png" << "*jpg" << "*JPEG" << "*.bmp" << "deleted";
dir->setNameFilters(filters);
fileInfoList = new QFileInfoList(dir->entryInfoList());

imageLabel = new QLabel*[rows * columns];
imageMap = new QPixmap*[rows * columns];
long listCount = 0;
imageLabel = new Label*[totalElements];
imageMap = new QPixmap*[totalElements];
imageName = new Label*[totalElements];

// double for loop, treat the image grid like a matrix
// for every row, display each column in the current row
for (int k = 0; k < rows; k++) {
actionList = new QAction**[totalElements];
for (int i = 0; i < totalElements; i++) actionList[i] = NULL;

for (int k = 0; k < rows; k=k+2) {
for (int j = 0; j < columns; j++) {

// When all files in the directory are added to the screen
// Jump out of the loop using 'goto'
if (listCount == fileInfoList->size()) goto jump;

// fileinfo contains the path of every image
QFileInfo fileinfo = fileInfoList->at(listCount);

auto int index = k*columns + j;
imageLabel[index] = new QLabel();
imageMap[index] = new QPixmap("/Users/richardyu/Pictures/conduct.png");
imageLabel[index]->setPixmap(imageMap[index] ->scaled(w,h,Qt::KeepAspectRatioByExpanding));
imageLabel[index] = new Label();
imageName[index] = new Label();
imageMap[index] = new QPixmap(fileinfo.absoluteFilePath());
imageLabel[index]->setPixmap(imageMap[index]->scaled(w,h,Qt::KeepAspectRatio));
//Widget* tmp(imageLabel[index]);
//filename = new QLabel;
QString temp = "<font color='blue'>" + fileinfo.fileName();
imageName[index]->setText(temp);

actionList[index] = new QAction*[2];
actionList[index][0] = new QAction("Rename", imageLabel[index]);
actionList[index][1] = new QAction("Delete", imageLabel[index]);
imageLabel[index]->addAction(actionList[index][0]);
imageLabel[index]->addAction(actionList[index][1]);
connect(actionList[index][0], SIGNAL(triggered()), this, SLOT(onAction1()));
connect(actionList[index][1], SIGNAL(triggered()), this, SLOT(onAction2()));

gridLayout->addWidget(imageLabel[index],k,j);
//gridLayout->addWidget(tmp,k,j);
gridLayout->addWidget(imageName[index],k+1,j);
listCount++;
}
}

jump: listCount = 0;


area->setWidget(gridWidget);
entireLayout->addWidget(area);
}
Expand Down
20 changes: 18 additions & 2 deletions Richard_photoList/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,22 @@
#include <QFileInfoList>
#include <QFileInfo>
#include "mylabel.h"
#include "label.h"

namespace Ui {
class MainWindow;
}

typedef struct clickMenu {
QAction* action1;
QAction* action2;
QAction* action3;
QAction* action4;
QAction* action5;

} clickMenu;


class MainWindow : public QMainWindow
{
Q_OBJECT
Expand All @@ -35,6 +46,8 @@ private slots:
void on_showImage_released();

void on_hello_released();
void onAction2();
void onAction1();

private:
Ui::MainWindow *ui;
Expand All @@ -43,10 +56,13 @@ private slots:
QWidget* gridWidget;
QScrollArea* area;
QVBoxLayout* entireLayout;
QLabel** imageLabel;
QLabel** imageName;
Label** imageLabel;
Label** imageName;
QPixmap** imageMap;
QDir* dir;
clickMenu** menuList;
QAction*** actionList;
QFileInfoList* fileInfoList;
void clearImage();
void addImage();

Expand Down

0 comments on commit 3f1f5bd

Please sign in to comment.