diff --git a/Richard_photoList/Richard_photoList.pro b/Richard_photoList/Richard_photoList.pro index c5391cc..9aa4b5c 100644 --- a/Richard_photoList/Richard_photoList.pro +++ b/Richard_photoList/Richard_photoList.pro @@ -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 diff --git a/Richard_photoList/Richard_photoList.pro.user b/Richard_photoList/Richard_photoList.pro.user index f6e1d7f..580e671 100644 --- a/Richard_photoList/Richard_photoList.pro.user +++ b/Richard_photoList/Richard_photoList.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/Richard_photoList/main.cpp b/Richard_photoList/main.cpp index 6aa3447..d0923ee 100644 --- a/Richard_photoList/main.cpp +++ b/Richard_photoList/main.cpp @@ -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(); diff --git a/Richard_photoList/mainwindow.cpp b/Richard_photoList/mainwindow.cpp index 38bd889..508f11b 100644 --- a/Richard_photoList/mainwindow.cpp +++ b/Richard_photoList/mainwindow.cpp @@ -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 = "" + 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; @@ -68,6 +110,8 @@ MainWindow::~MainWindow() delete ui; } + + void MainWindow::on_hideImage_released() { clearImage(); @@ -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); } } @@ -126,3 +170,8 @@ void MainWindow::on_showImage_released() clearImage(); addImage(); } + +void MainWindow::on_hello_released() +{ + clearImage(); +} diff --git a/Richard_photoList/mainwindow.h b/Richard_photoList/mainwindow.h index be95ba0..93a1ba1 100644 --- a/Richard_photoList/mainwindow.h +++ b/Richard_photoList/mainwindow.h @@ -11,6 +11,11 @@ #include #include #include +#include +#include +#include +#include +#include "mylabel.h" namespace Ui { class MainWindow; @@ -29,6 +34,8 @@ private slots: void on_showImage_released(); + void on_hello_released(); + private: Ui::MainWindow *ui; QGridLayout* gridLayout; @@ -37,7 +44,9 @@ private slots: QScrollArea* area; QVBoxLayout* entireLayout; QLabel** imageLabel; + QLabel** imageName; QPixmap** imageMap; + QDir* dir; void clearImage(); void addImage(); diff --git a/Richard_photoList/mainwindow.ui b/Richard_photoList/mainwindow.ui index afa97e2..45e4ded 100644 --- a/Richard_photoList/mainwindow.ui +++ b/Richard_photoList/mainwindow.ui @@ -18,7 +18,7 @@ 20 - 10 + 20 113 32 @@ -36,8 +36,8 @@ - 80 - 50 + 140 + 40 113 32 @@ -52,6 +52,57 @@ Show Image + + + + 260 + 20 + 113 + 32 + + + + + 300 + 50 + + + + Delete + + + + + + 120 + 90 + 113 + 32 + + + + + 300 + 50 + + + + Rename + + + + + + 160 + 150 + 113 + 32 + + + + Hello + + diff --git a/Richard_photoList/mylabel.cpp b/Richard_photoList/mylabel.cpp new file mode 100644 index 0000000..281f31a --- /dev/null +++ b/Richard_photoList/mylabel.cpp @@ -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()); +} diff --git a/Richard_photoList/mylabel.h b/Richard_photoList/mylabel.h new file mode 100644 index 0000000..bfb0c17 --- /dev/null +++ b/Richard_photoList/mylabel.h @@ -0,0 +1,22 @@ +#ifndef MYLABEL_H +#define MYLABEL_H + +#include +#include +#include + +class Widget : public QWidget +{ + Q_OBJECT + +public: + Widget(QWidget *parent = 0); + ~Widget(); + +public slots: + void customMenuRequested(QPoint pos); + +private: + QLabel *label; +}; +#endif diff --git a/hello/hello.pro b/hello/hello.pro new file mode 100644 index 0000000..8a908d8 --- /dev/null +++ b/hello/hello.pro @@ -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 diff --git a/hello/hello.pro.user b/hello/hello.pro.user new file mode 100644 index 0000000..d7d399f --- /dev/null +++ b/hello/hello.pro.user @@ -0,0 +1,266 @@ + + + + + + EnvironmentId + {db3e1557-086a-4178-9b2c-c4af1acd9f93} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.3 clang 64bit + Desktop Qt 5.3 clang 64bit + qt.53.clang_64_kit + 0 + 0 + 0 + + /Users/richardyu/Documents/groundstation/build-hello-Desktop_Qt_5_3_clang_64bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + /Users/richardyu/Documents/groundstation/build-hello-Desktop_Qt_5_3_clang_64bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 2 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + -1 + + + + false + %{buildDir} + Custom Executable + + ProjectExplorer.CustomExecutableRunConfiguration + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 16 + + + Version + 16 + + diff --git a/hello/main.cpp b/hello/main.cpp new file mode 100644 index 0000000..b48f94e --- /dev/null +++ b/hello/main.cpp @@ -0,0 +1,11 @@ +#include "mainwindow.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + + return a.exec(); +} diff --git a/hello/mainwindow.cpp b/hello/mainwindow.cpp new file mode 100644 index 0000000..49d64fc --- /dev/null +++ b/hello/mainwindow.cpp @@ -0,0 +1,14 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); +} + +MainWindow::~MainWindow() +{ + delete ui; +} diff --git a/hello/mainwindow.h b/hello/mainwindow.h new file mode 100644 index 0000000..a3948a9 --- /dev/null +++ b/hello/mainwindow.h @@ -0,0 +1,22 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +namespace Ui { +class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + +private: + Ui::MainWindow *ui; +}; + +#endif // MAINWINDOW_H diff --git a/hello/mainwindow.ui b/hello/mainwindow.ui new file mode 100644 index 0000000..6050363 --- /dev/null +++ b/hello/mainwindow.ui @@ -0,0 +1,24 @@ + + MainWindow + + + + 0 + 0 + 400 + 300 + + + + MainWindow + + + + + + + + + + +