Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
richardyqn committed Jan 11, 2015
1 parent a25dd54 commit 77169a7
Show file tree
Hide file tree
Showing 14 changed files with 531 additions and 15 deletions.
8 changes: 6 additions & 2 deletions Richard_photoList/Richard_photoList.pro
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ TEMPLATE = app


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

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

FORMS += mainwindow.ui

QMAKE_MAC_SDK = macosx10.9
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, 2014-11-23T10:57:38. -->
<!-- Written by QtCreator 3.2.1, 2015-01-11T14:56:20. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
Expand Down
4 changes: 2 additions & 2 deletions Richard_photoList/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ int main(int argc, char *argv[])
QApplication a(argc, argv);
MainWindow w;
QDesktopWidget dw;
int x=dw.width()*0.8;
int y=dw.height()*0.8;
int x=dw.width()*0.9;
int y=dw.height()*0.9;
w.setFixedSize(x,y);
w.show();

Expand Down
63 changes: 56 additions & 7 deletions Richard_photoList/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,40 +25,82 @@ MainWindow::MainWindow(QWidget *parent) :
centralWidget->setLayout(entireLayout);

// 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 columns = 4;

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

long listCount = 0;

imageLabel = new QLabel*[rows * columns];
imageMap = new QPixmap*[rows * columns];
imageName = new QLabel*[rows * columns];

//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++) {
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;

// fileinfo contains the path of every image
QFileInfo fileinfo = list.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::KeepAspectRatio));
imageName[index] = new QLabel();
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();
imageName[index]->setText(temp);

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

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);
entireLayout->addWidget(ui->showImage);
entireLayout->addWidget(ui->deleteImage);
entireLayout->addWidget(ui->renameImage);
entireLayout->addWidget(ui->hello);
entireLayout->addWidget(area);

}

MainWindow::~MainWindow()
{
delete dir;
delete []imageMap;
delete []imageName;
delete []imageLabel;
delete gridLayout;
delete gridWidget;
Expand All @@ -68,6 +110,8 @@ MainWindow::~MainWindow()
delete ui;
}



void MainWindow::on_hideImage_released()
{
clearImage();
Expand Down Expand Up @@ -112,7 +156,7 @@ void MainWindow::addImage() {
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::KeepAspectRatio));
imageLabel[index]->setPixmap(imageMap[index] ->scaled(w,h,Qt::KeepAspectRatioByExpanding));
gridLayout->addWidget(imageLabel[index],k,j);
}
}
Expand All @@ -126,3 +170,8 @@ void MainWindow::on_showImage_released()
clearImage();
addImage();
}

void MainWindow::on_hello_released()
{
clearImage();
}
9 changes: 9 additions & 0 deletions Richard_photoList/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
#include <QRect>
#include <QGridLayout>
#include <QScrollArea>
#include <QDir>
#include <QStringList>
#include <QFileInfoList>
#include <QFileInfo>
#include "mylabel.h"

namespace Ui {
class MainWindow;
Expand All @@ -29,6 +34,8 @@ private slots:

void on_showImage_released();

void on_hello_released();

private:
Ui::MainWindow *ui;
QGridLayout* gridLayout;
Expand All @@ -37,7 +44,9 @@ private slots:
QScrollArea* area;
QVBoxLayout* entireLayout;
QLabel** imageLabel;
QLabel** imageName;
QPixmap** imageMap;
QDir* dir;
void clearImage();
void addImage();

Expand Down
57 changes: 54 additions & 3 deletions Richard_photoList/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<property name="geometry">
<rect>
<x>20</x>
<y>10</y>
<y>20</y>
<width>113</width>
<height>32</height>
</rect>
Expand All @@ -36,8 +36,8 @@
<widget class="QPushButton" name="showImage">
<property name="geometry">
<rect>
<x>80</x>
<y>50</y>
<x>140</x>
<y>40</y>
<width>113</width>
<height>32</height>
</rect>
Expand All @@ -52,6 +52,57 @@
<string>Show Image</string>
</property>
</widget>
<widget class="QPushButton" name="deleteImage">
<property name="geometry">
<rect>
<x>260</x>
<y>20</y>
<width>113</width>
<height>32</height>
</rect>
</property>
<property name="maximumSize">
<size>
<width>300</width>
<height>50</height>
</size>
</property>
<property name="text">
<string>Delete</string>
</property>
</widget>
<widget class="QPushButton" name="renameImage">
<property name="geometry">
<rect>
<x>120</x>
<y>90</y>
<width>113</width>
<height>32</height>
</rect>
</property>
<property name="maximumSize">
<size>
<width>300</width>
<height>50</height>
</size>
</property>
<property name="text">
<string>Rename</string>
</property>
</widget>
<widget class="QPushButton" name="hello">
<property name="geometry">
<rect>
<x>160</x>
<y>150</y>
<width>113</width>
<height>32</height>
</rect>
</property>
<property name="text">
<string>Hello</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
Expand Down
24 changes: 24 additions & 0 deletions Richard_photoList/mylabel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "mylabel.h"

Widget::Widget(QWidget *parent)
: QWidget(parent)
{
QVBoxLayout *l=new QVBoxLayout(this);
label= new QLabel(this);
label->setContextMenuPolicy(Qt::CustomContextMenu);
connect(label, SIGNAL(customContextMenuRequested(QPoint)),
SLOT(customMenuRequested(QPoint)));
l->addWidget(label);
}

Widget::~Widget(){}

void Widget::customMenuRequested(QPoint pos){
//QModelIndex index=label->indexAt(pos);

QMenu *menu=new QMenu(this);
menu->addAction(new QAction("Action 1", this));
menu->addAction(new QAction("Action 2", this));
menu->addAction(new QAction("Action 3", this));
menu->popup(label->pos());
}
22 changes: 22 additions & 0 deletions Richard_photoList/mylabel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef MYLABEL_H
#define MYLABEL_H

#include <QLabel>
#include <QVBoxLayout>
#include <QMenu>

class Widget : public QWidget
{
Q_OBJECT

public:
Widget(QWidget *parent = 0);
~Widget();

public slots:
void customMenuRequested(QPoint pos);

private:
QLabel *label;
};
#endif
20 changes: 20 additions & 0 deletions hello/hello.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#-------------------------------------------------
#
# Project created by QtCreator 2015-01-11T16:13:41
#
#-------------------------------------------------

QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = hello
TEMPLATE = app


SOURCES += main.cpp\
mainwindow.cpp

HEADERS += mainwindow.h

FORMS += mainwindow.ui
Loading

0 comments on commit 77169a7

Please sign in to comment.