diff --git a/src/view/imageview.cpp b/src/view/imageview.cpp index c2e619b..f2609fd 100644 --- a/src/view/imageview.cpp +++ b/src/view/imageview.cpp @@ -132,43 +132,24 @@ void ImageView::RotateImage(const int &index) } -void ImageView::savecurrentPic() -{ - QString filename = QFileDialog::getSaveFileName(this, tr("Save Image"), "", tr("Images (*.png *.bmp *.jpg)")); //选择路径 - image().save(filename); -} -void ImageView::savecurrentPicAs() -{ - QFileDialog fileDialog; - QString fileName = fileDialog.getSaveFileName(this, tr("Open File"), "/home", tr("png")); - if (fileName == "") { - return; - } - QFile file(fileName); - if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { - QMessageBox::warning(this, tr("error"), tr("open file error")); - return; - } else { - image().save(fileName, "png"); - } -} -void ImageView::openImage(QImage *img) -{ - if (!img->isNull() && scene()) { - QPixmap pic = QPixmap::fromImage(*img); - if (!pic.isNull()) { - scene()->clear(); - m_pixmapItem = new QGraphicsPixmapItem(pic); - m_pixmapItem->setTransformationMode(Qt::SmoothTransformation); - QRectF rect = m_pixmapItem->boundingRect(); - setSceneRect(rect); - scene()->addItem(m_pixmapItem); - fitWindow(); - } - } -} + +//void ImageView::openImage(QImage *img) +//{ +// if (!img->isNull() && scene()) { +// QPixmap pic = QPixmap::fromImage(*img); +// if (!pic.isNull()) { +// scene()->clear(); +// m_pixmapItem = new QGraphicsPixmapItem(pic); +// m_pixmapItem->setTransformationMode(Qt::SmoothTransformation); +// QRectF rect = m_pixmapItem->boundingRect(); +// setSceneRect(rect); +// scene()->addItem(m_pixmapItem); +// fitWindow(); +// } +// } +//} qreal ImageView::imageRelativeScale() const { diff --git a/src/view/imageview.h b/src/view/imageview.h index abddecf..2b6b56c 100644 --- a/src/view/imageview.h +++ b/src/view/imageview.h @@ -42,12 +42,8 @@ public slots: void fitImage(); //旋转图片,感觉index角度,-为左,+为右 void RotateImage(const int &index); - //保存图片 - void savecurrentPic(); - //另存为 - void savecurrentPicAs(); - //打开该图片 - void openImage(QImage *img); +// //打开该图片 +// void openImage(QImage *img); //窗口大小改变事件 void resizeEvent(QResizeEvent *event) override; diff --git a/tests/test_mainwindow.cpp b/tests/test_mainwindow.cpp index 5e79234..45e67db 100644 --- a/tests/test_mainwindow.cpp +++ b/tests/test_mainwindow.cpp @@ -23,12 +23,14 @@ #include #include +#include #define private public #define protected public #include "ocrapplication.h" - +#include "mainwidget.h" +#include "view/imageview.h" //初始拉起主界面 TEST(MainWindow, mainwindow) { @@ -38,3 +40,59 @@ TEST(MainWindow, mainwindow) } //其余case +//初始拉起主界面,带有参数的 +TEST(MainWindow, mainwindow_openFile) +{ + QString picPath = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation) + "/Wallpapers/luca-micheli-ruWkmt3nU58-unsplash.jpg"; + OcrApplication instance; + instance.openFile(picPath); + bool bRet = false; + while (!bRet) { + if (!TessOcrUtils::instance()->isRunning()) { + bRet = true; + QTest::qWait(1000); + } + } + + instance.openImage(QImage(picPath).scaled(200, 200)); + + bRet = false; + while (!bRet) { + if (!TessOcrUtils::instance()->isRunning()) { + bRet = true; + QTest::qWait(1000); + } + } + + instance.openImageAndName(QImage(picPath).scaled(10, 10), picPath); + QTest::qWait(2000); +} + +//初始拉起主界面,带有参数的 +TEST(MainWidget, MainWidget_show) +{ + MainWidget *a = new MainWidget(); + a->loadHtml(""); + a->loadHtml("test"); + a->loadString(""); + a->loadString("test"); + a->slotCopy(); + a->deleteLater(); + a = nullptr; + QTest::qWait(2000); +} + +TEST(ImageView, ImageView_show) +{ + QString picPath = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation) + "/Wallpapers/luca-micheli-ruWkmt3nU58-unsplash.jpg"; + ImageView *imageView = new ImageView(); + imageView->openImage(picPath); + imageView->fitImage(); + imageView->fitWindow(); + imageView->autoFit(); + imageView->imageRelativeScale(); + imageView->setScaleValue(1.1); + imageView->setScaleValue(0.9); + imageView->RotateImage(90); + QTest::qWait(2000); +}