feat: new action for open a dialog to select image files

This commit is contained in:
Gary Wang 2021-11-25 22:54:37 +08:00
parent 560ece0f2f
commit f202bb58f4
4 changed files with 23 additions and 0 deletions

View File

@ -41,6 +41,7 @@ void ActionManager::setupAction(MainWindow *mainWindow)
CREATE_NEW_ACTION(mainWindow, actionPrevPicture);
CREATE_NEW_ACTION(mainWindow, actionNextPicture);
CREATE_NEW_ACTION(mainWindow, actionOpen);
CREATE_NEW_ACTION(mainWindow, actionHorizontalFlip);
CREATE_NEW_ACTION(mainWindow, actionFitInView);
CREATE_NEW_ACTION(mainWindow, actionFitByWidth);
@ -63,6 +64,8 @@ void ActionManager::retranslateUi(MainWindow *mainWindow)
{
Q_UNUSED(mainWindow);
actionOpen->setText(QCoreApplication::translate("MainWindow", "&Open...", nullptr));
actionActualSize->setText(QCoreApplication::translate("MainWindow", "Actual size", nullptr));
actionToggleMaximize->setText(QCoreApplication::translate("MainWindow", "Toggle maximize", nullptr));
actionZoomIn->setText(QCoreApplication::translate("MainWindow", "Zoom in", nullptr));
@ -89,6 +92,7 @@ void ActionManager::retranslateUi(MainWindow *mainWindow)
void ActionManager::setupShortcuts()
{
actionOpen->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_O));
actionActualSize->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_0));
actionZoomIn->setShortcut(QKeySequence(QKeySequence::ZoomIn));
actionZoomOut->setShortcut(QKeySequence(QKeySequence::ZoomOut));

View File

@ -16,6 +16,8 @@ public:
void setupShortcuts();
public:
QAction *actionOpen;
QAction *actionActualSize;
QAction *actionToggleMaximize;
QAction *actionZoomIn;

View File

@ -27,6 +27,8 @@
#include <QWindow>
#include <QFile>
#include <QTimer>
#include <QFileDialog>
#include <QStandardPaths>
MainWindow::MainWindow(QWidget *parent)
: FramelessWindow(parent)
@ -406,6 +408,8 @@ void MainWindow::contextMenuEvent(QContextMenuEvent *event)
QAction * helpAction = m_am->actionHelp;
QAction * propertiesAction = m_am->actionProperties;
menu->addAction(m_am->actionOpen);
if (copyMenu->actions().count() == 1) {
menu->addActions(copyMenu->actions());
} else {
@ -540,6 +544,17 @@ QSize MainWindow::sizeHint() const
return QSize(710, 530);
}
void MainWindow::on_actionOpen_triggered()
{
QStringList picturesLocations = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation);
QUrl pictureUrl = picturesLocations.isEmpty() ? QUrl::fromLocalFile(picturesLocations.first())
: QUrl::fromLocalFile(QDir::homePath());
QList<QUrl> urls(QFileDialog::getOpenFileUrls(this, QString(), pictureUrl));
if (!urls.isEmpty()) {
showUrls(urls);
}
}
void MainWindow::on_actionActualSize_triggered()
{
m_graphicsView->resetScale();

View File

@ -68,6 +68,8 @@ protected:
QSize sizeHint() const override;
private slots:
void on_actionOpen_triggered();
void on_actionActualSize_triggered();
void on_actionToggleMaximize_triggered();
void on_actionZoomIn_triggered();