87 lines
2.2 KiB
C++
87 lines
2.2 KiB
C++
#include "mainwindow.h"
|
|
#include <QScrollArea>
|
|
#include <QDir>
|
|
#include <QKeyEvent>
|
|
#include <QMenu>
|
|
#include <QMenuBar>
|
|
#include <QFileDialog>
|
|
#include <QStandardPaths>
|
|
|
|
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
|
|
loading(false),
|
|
queued(0)
|
|
{
|
|
m_image = new ImageScrollArea(this);
|
|
setCentralWidget(m_image);
|
|
resize(800, 600);
|
|
|
|
setWindowTitle(tr("Image Selector"));
|
|
|
|
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);
|
|
|
|
QMenu *viewMenu = new QMenu(tr("View"), this);
|
|
viewMenu->addAction(tr("Zoom In"), m_image, SLOT(zoomIn()), QKeySequence::ZoomIn);
|
|
viewMenu->addAction(tr("Zoom Out"), m_image, SLOT(zoomOut()), QKeySequence::ZoomOut);
|
|
viewMenu->addAction(tr("Best Fit"), m_image, SLOT(bestFit()), QKeySequence("Ctrl+1"));
|
|
viewMenu->addAction(tr("1:1"), m_image, SLOT(oneToOne()));
|
|
menuBar()->addMenu(viewMenu);
|
|
}
|
|
|
|
MainWindow::~MainWindow()
|
|
{
|
|
}
|
|
|
|
void MainWindow::keyPressEvent(QKeyEvent *event)
|
|
{
|
|
if(!loading)
|
|
{
|
|
switch (event->key())
|
|
{
|
|
case Qt::Key_Left:
|
|
m_ringList->decrement();
|
|
break;
|
|
case Qt::Key_Right:
|
|
m_ringList->increment();
|
|
break;
|
|
default:
|
|
event->ignore();
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
event->ignore();
|
|
}
|
|
}
|
|
|
|
void MainWindow::keyReleaseEvent(QKeyEvent *event)
|
|
{
|
|
event->ignore();
|
|
}
|
|
|
|
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());
|
|
}
|
|
}
|