Files
chengnan/MainWindow.h
luochen570 573c9d746c
Some checks failed
Build Windows Release / Build Windows x64 Release on Linux (MinGW + Qt + OpenCV) (push) Failing after 2m15s
Implement Qt OpenCV image processing app
2026-05-30 23:09:27 +08:00

101 lines
2.6 KiB
C++

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QImage>
#include <QLabel>
#include <QMainWindow>
#include <QPixmap>
#include <QScrollArea>
#include <QString>
#include <functional>
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 extractObjects();
void classifyImage();
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 updateSingleView(ImageLabel *label, const QImage &image);
void setZoomFactor(double factor);
void applyTransformedImage(const QImage &image, const QString &message = QString());
void processImageInThread(const QString &actionName, const QString &doneMessage, const std::function<QImage(QImage)> &processor);
void updateActions();
bool ensureImageLoaded(const QString &actionName) const;
bool writeImageToPath(const QString &path);
ImageLabel *originalLabel_ = nullptr;
ImageLabel *processedLabel_ = nullptr;
QScrollArea *originalScrollArea_ = nullptr;
QScrollArea *processedScrollArea_ = nullptr;
QSlider *zoomSlider_ = nullptr;
QImage originalImage_;
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;
QAction *extractAction_ = nullptr;
QAction *classifyAction_ = nullptr;
};
#endif // MAINWINDOW_H