Skip to content

Commit

Permalink
added setImageWithFilePath
Browse files Browse the repository at this point in the history
  • Loading branch information
WangHongshuo committed Jun 14, 2018
1 parent 74acabc commit 1c46533
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 6 deletions.
6 changes: 6 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log: #

- 2018.06.14

Added setImageWithFilePath().

添加用图像文件路径设置图像的方式。

- 2018.01.30:

Added resizing selected rect frame function. And now, I realize all the function I wanted in this class. But it still have some performance issues, I will optimize or rewrite it when I can.
Expand Down
32 changes: 31 additions & 1 deletion ImageWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ ImageWidget::~ImageWidget()
qImageZoomedImage = NULL;
}

void ImageWidget::setImageWithData(QImage img)
void ImageWidget::setImageWithData(QImage &img)
{
if(!isImageCloned)
{
Expand Down Expand Up @@ -73,6 +73,36 @@ void ImageWidget::setImageWithPointer(QImage *img)
}
}

void ImageWidget::setImageWithFilePath(QString &path)
{
if(!isImageCloned)
{
qImageContainer = new QImage;
isImageCloned = true;
}
if(path.isEmpty() || path.isNull())
{
isImageLoaded = false;
return;
}
else
{
qImageContainer->load(path);
if(qImageContainer->isNull())
{
isImageLoaded = false;
return;
}
// qDebug() << qImageContainer->bits() << img.bits();
isImageLoaded = true;
*qImageZoomedImage = qImageContainer->copy();
updateZoomedImage();
if(!isEnableRecordLastParameters)
setDefaultParameters();
update();
}
}

void ImageWidget::clear()
{
if(isImageLoaded)
Expand Down
3 changes: 2 additions & 1 deletion ImageWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ class ImageWidget :
ImageWidget(QWidget *parent);
~ImageWidget();

void setImageWithData(QImage img);
void setImageWithData(QImage &img);
void setImageWithPointer(QImage* img);
void setImageWithFilePath(QString &path);
void setEnableOnlyShowImage(bool flag = false);

// 发送点击位置坐标信号默认关闭,使用前需要开启
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ It's my first time to write a class and this class inherit from QWidget. It can
![](https://github.com/WangHongshuo/Readme_Images_Repository/blob/master/ImageWidget-Qt/ImageWidget-Qt_2.gif)
## Last Change: ##

- 2018.01.30:
- 2018.06.14

Added resizing selected rect frame function. And now, I realize all the function I wanted in this class. But it still have some performance issues, I will optimize or rewrite it when I can.
Added setImageWithFilePath().

添加了改变选中框尺寸的功能,至此该类已经达到了我所需的所有功能,但是还有一些性能上的问题。将来有能力和时间的话会进行优化或重写
添加用图像文件路径设置图像的方式

- Full [Change Log](./ChangeLog.md)

Expand Down
2 changes: 1 addition & 1 deletion selectrect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void SelectRect::receiveParentSizeChangedSignal()
{
ImageWidget *parentWidget = static_cast<ImageWidget *>(this->parent());
this->setGeometry(0,0,parentWidget->width(),parentWidget->height());
qDebug() << this->geometry();
// qDebug() << this->geometry();
drawImageTopLeftPos = parentWidget->getDrawImageTopLeftPos();
update();
}
Expand Down

0 comments on commit 1c46533

Please sign in to comment.