From 6debf6d419f4c7f37b0e8c2021266695b06561d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Poizl?= Date: Sat, 30 Jul 2016 14:29:07 +0200 Subject: [PATCH] Open file menu --- mainwindow.cpp | 25 ++++++++++++++++++++++++- mainwindow.h | 1 + 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index c799ac8..48760cb 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -2,7 +2,10 @@ #include #include #include -#include +#include +#include +#include +#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), loading(false), @@ -17,6 +20,11 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), m_ringList = new ImageRingList(this); connect(m_ringList, SIGNAL(pixmapLoaded(QPixmap)), this, SLOT(pixmapLoaded(QPixmap))); + QMenu *fileMenu = new QMenu(tr("File"), this); + fileMenu->addAction(tr("Open"), this, SLOT(openFile()), QKeySequence("Ctrl+O")); + fileMenu->addAction(tr("Exit"), this, SLOT(close())); + menuBar()->addMenu(fileMenu); + m_ringList->setDir("/home/nou/Obrázky/jap/dusan-jpg"); } @@ -56,3 +64,18 @@ void MainWindow::pixmapLoaded(QPixmap pix) { m_image->setImage(pix); } + +void MainWindow::openFile() +{ + QStringList standardLocations = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation); + QString path; + if(standardLocations.size()) + path = standardLocations.first(); + + QString file = QFileDialog::getOpenFileName(this, tr("Open file"), path, tr("Images (*.jpg *.png)")); + if(!file.isEmpty()) + { + QFileInfo info(file); + m_ringList->setDir(info.dir().absolutePath()); + } +} diff --git a/mainwindow.h b/mainwindow.h index c40185b..08b445e 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -20,6 +20,7 @@ protected: void keyReleaseEvent(QKeyEvent *event); protected slots: void pixmapLoaded(QPixmap pix); + void openFile(); }; #endif // MAINWINDOW_H