91 lines
2.1 KiB
C++
91 lines
2.1 KiB
C++
#ifndef MAINWINDOW_H
|
|
#define MAINWINDOW_H
|
|
|
|
#include <QImage>
|
|
#include <QLabel>
|
|
#include <QMainWindow>
|
|
#include <QPixmap>
|
|
#include <QScrollArea>
|
|
#include <QString>
|
|
|
|
class QAction;
|
|
class QMenu;
|
|
class QPushButton;
|
|
class QSlider;
|
|
|
|
class ImageLabel final : public QLabel
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit ImageLabel(QWidget *parent = nullptr);
|
|
|
|
Q_SIGNALS:
|
|
void doubleClicked();
|
|
|
|
protected:
|
|
void mouseDoubleClickEvent(QMouseEvent *event) override;
|
|
};
|
|
|
|
class MainWindow final : public QMainWindow
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit MainWindow(QWidget *parent = nullptr);
|
|
|
|
private Q_SLOTS:
|
|
void openImage();
|
|
void saveImage();
|
|
void saveImageAs();
|
|
void zoomIn();
|
|
void zoomOut();
|
|
void fitToWindow();
|
|
void resetView();
|
|
void rotateLeft();
|
|
void rotateRight();
|
|
void flipHorizontal();
|
|
void flipVertical();
|
|
void grayscale();
|
|
void invertColors();
|
|
void updateZoomFromSlider(int value);
|
|
|
|
private:
|
|
void createActions();
|
|
void createMenus();
|
|
void createToolbar();
|
|
void createCentralWidget();
|
|
void setImage(const QImage &image, const QString &path = QString());
|
|
void updateImageView();
|
|
void setZoomFactor(double factor);
|
|
void applyTransformedImage(const QImage &image);
|
|
void updateActions();
|
|
bool ensureImageLoaded(const QString &actionName) const;
|
|
bool writeImageToPath(const QString &path);
|
|
|
|
ImageLabel *imageLabel_ = nullptr;
|
|
QScrollArea *scrollArea_ = nullptr;
|
|
QSlider *zoomSlider_ = nullptr;
|
|
|
|
QImage currentImage_;
|
|
QString currentPath_;
|
|
double zoomFactor_ = 1.0;
|
|
|
|
QAction *openAction_ = nullptr;
|
|
QAction *saveAction_ = nullptr;
|
|
QAction *saveAsAction_ = nullptr;
|
|
QAction *exitAction_ = nullptr;
|
|
QAction *zoomInAction_ = nullptr;
|
|
QAction *zoomOutAction_ = nullptr;
|
|
QAction *fitAction_ = nullptr;
|
|
QAction *resetAction_ = nullptr;
|
|
QAction *rotateLeftAction_ = nullptr;
|
|
QAction *rotateRightAction_ = nullptr;
|
|
QAction *flipHorizontalAction_ = nullptr;
|
|
QAction *flipVerticalAction_ = nullptr;
|
|
QAction *grayscaleAction_ = nullptr;
|
|
QAction *invertAction_ = nullptr;
|
|
};
|
|
|
|
#endif // MAINWINDOW_H
|