This repository has been archived by the owner on Mar 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from camrein/image_conversion_enhancements
Image conversion enhancements
- Loading branch information
Showing
12 changed files
with
204 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include "imagelabel.h" | ||
|
||
#include <QPainter> | ||
|
||
ImageLabel::ImageLabel(QWidget* parent) : ClickLabel{parent}, _image{}, _flags{Qt::DiffuseDither} {} | ||
ImageLabel::~ImageLabel() {} | ||
|
||
QImage ImageLabel::image() const { | ||
return _image; | ||
} | ||
|
||
void ImageLabel::setImage(QImage const& image) { | ||
_image = image; | ||
updateDisplayedImage(); | ||
emit imageLoadedChanged(true); | ||
emit imageChanged(image); | ||
} | ||
|
||
Qt::ImageConversionFlags ImageLabel::conversionFlags() const { | ||
return _flags; | ||
} | ||
|
||
void ImageLabel::setConversionFlags(Qt::ImageConversionFlags const& flags) { | ||
_flags = flags; | ||
updateDisplayedImage(); | ||
emit conversionFlagsChanged(flags); | ||
} | ||
|
||
void ImageLabel::updateDisplayedImage() { | ||
if(!imageLoaded()) { | ||
return; | ||
} | ||
|
||
// Draw white background, otherwise transparency is converted to black. | ||
QImage image{QSize{512, 512}, QImage::Format_ARGB32}; | ||
image.fill(QColor{Qt::white}); | ||
QPainter painter{&image}; | ||
painter.drawImage(0, 0, _image.scaled(image.size())); | ||
|
||
setPixmap(QPixmap::fromImage(image.convertToFormat(QImage::Format_Mono, _flags))); | ||
} | ||
|
||
bool ImageLabel::imageLoaded() const { | ||
return !_image.isNull(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#ifndef IMAGELABEL_H | ||
#define IMAGELABEL_H | ||
|
||
#include "clicklabel.h" | ||
|
||
class ImageLabel : public ClickLabel { | ||
Q_OBJECT | ||
Q_PROPERTY(QImage image READ image WRITE setImage NOTIFY imageChanged) | ||
Q_PROPERTY(Qt::ImageConversionFlags conversionFlags READ conversionFlags WRITE setConversionFlags NOTIFY conversionFlagsChanged) | ||
Q_PROPERTY(bool imageLoaded READ imageLoaded NOTIFY imageLoadedChanged) | ||
|
||
public: | ||
/*! | ||
* Creates a new instance with the given \a parent. | ||
* | ||
* \param parent The parent of the label. | ||
*/ | ||
explicit ImageLabel(QWidget* parent=NULL); | ||
|
||
/*! | ||
* Frees all required resources upon deconstruction. | ||
*/ | ||
virtual ~ImageLabel(); | ||
|
||
/*! | ||
* Gets the currently loaded image without the application of | ||
* any conversion. | ||
* | ||
* \return The currently loaded image. | ||
*/ | ||
QImage image() const; | ||
|
||
/*! | ||
* Changes the currently displayed image to the given image | ||
* and applies the selected conversion method. | ||
* | ||
* \param image The image to load. | ||
*/ | ||
void setImage(QImage const& image); | ||
|
||
/*! | ||
* Gets the currently selected conversion flags. | ||
* | ||
* \return The currently selected conversion flags. | ||
*/ | ||
Qt::ImageConversionFlags conversionFlags() const; | ||
|
||
/*! | ||
* Changes the applied conversion flags to the given one and | ||
* updates the currently displayed image. | ||
* | ||
* \param flags The conversion flags to use. | ||
*/ | ||
void setConversionFlags(Qt::ImageConversionFlags const& flags); | ||
|
||
/*! | ||
* Gets if an image has been loaded. | ||
* | ||
* \return Returns \c true if an image is loaded. | ||
*/ | ||
bool imageLoaded() const; | ||
signals: | ||
/*! | ||
* Fired as soon as the image has been changed. | ||
* | ||
* \param image The new image in its original state (unconverted). | ||
*/ | ||
void imageChanged(QImage const& image); | ||
|
||
/*! | ||
* Fired as soon as the conversion flags hav been changed. | ||
* | ||
* \param flags The newly applied conversion flags. | ||
*/ | ||
void conversionFlagsChanged(Qt::ImageConversionFlags const& flags); | ||
|
||
/*! | ||
* Fired as soon as an image has been loaded. | ||
* | ||
* \param imageLoaded \c true if an image is loaded. | ||
*/ | ||
void imageLoadedChanged(bool imageLoaded); | ||
private: | ||
QImage _image; | ||
Qt::ImageConversionFlags _flags; | ||
|
||
void updateDisplayedImage(); | ||
}; | ||
|
||
#endif // IMAGELABEL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.