Skip to content

Commit

Permalink
Gui: BitmapFactory new static function to make icon overlays with pix…
Browse files Browse the repository at this point in the history
…maps
  • Loading branch information
abdullahtahiriyo authored and wwmayer committed Jun 22, 2019
1 parent 7602d39 commit db5ef31
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
28 changes: 21 additions & 7 deletions src/Gui/BitmapFactory.cpp
Expand Up @@ -650,13 +650,13 @@ void BitmapFactoryInst::convert(const QImage& p, SoSFImage& img) const
int width = (int)size[0];
int height = (int)size[1];

for (int y = 0; y < height; y++)
for (int y = 0; y < height; y++)
{
unsigned char * line = &bytes[width*numcomponents*(height-(y+1))];
for (int x = 0; x < width; x++)
for (int x = 0; x < width; x++)
{
QRgb rgb = p.pixel(x,y);
switch (numcomponents)
switch (numcomponents)
{
default:
break;
Expand Down Expand Up @@ -699,13 +699,13 @@ void BitmapFactoryInst::convert(const SoSFImage& p, QImage& img) const

img = QImage(width, height, QImage::Format_RGB32);
QRgb * bits = (QRgb*) img.bits();
for (int y = 0; y < height; y++)

for (int y = 0; y < height; y++)
{
const unsigned char * line = &bytes[width*numcomponents*(height-(y+1))];
for (int x = 0; x < width; x++)
for (int x = 0; x < width; x++)
{
switch (numcomponents)
switch (numcomponents)
{
default:
case 1:
Expand All @@ -727,3 +727,17 @@ void BitmapFactoryInst::convert(const SoSFImage& p, QImage& img) const
}
}

QIcon BitmapFactoryInst::mergePixmap (const QIcon &base, const QPixmap &px, Gui::BitmapFactoryInst::Position position)
{
QIcon overlayedIcon;

int w = QApplication::style()->pixelMetric(QStyle::PM_ListViewIconSize);

overlayedIcon.addPixmap(Gui::BitmapFactory().merge(base.pixmap(w, w, QIcon::Normal, QIcon::Off),
px,position), QIcon::Normal, QIcon::Off);

overlayedIcon.addPixmap(Gui::BitmapFactory().merge(base.pixmap(w, w, QIcon::Normal, QIcon::On ),
px,position), QIcon::Normal, QIcon::Off);

return overlayedIcon;
}
15 changes: 9 additions & 6 deletions src/Gui/BitmapFactory.h
Expand Up @@ -91,23 +91,23 @@ class GuiExport BitmapFactoryInst : public Base::Factory
/** Resizes the area of a pixmap
* If the new size is greater than the old one the pixmap
* will be placed in the center. The border area will be made
* depending on \a bgmode transparent or opaque.
* depending on \a bgmode transparent or opaque.
*/
QPixmap resize(int w, int h, const QPixmap& p, Qt::BGMode bgmode) const;
/** Creates an opaque or transparent area in a pixmap
* If the background mode is opaque then this method can
* be used for drawing a smaller pixmap into pixmap \a p.
* be used for drawing a smaller pixmap into pixmap \a p.
* Note: To draw a smaller pixmap into another one the
* area in the resulting pixmap for the small pixmapmust
* be opaque in every pixel, otherwise the drawing may fail.
* area in the resulting pixmap for the small pixmapmust
* be opaque in every pixel, otherwise the drawing may fail.
*
* If the background mode is transparent then this method can
* be used for resizing the pixmap \a p and make the new space
* transparent.
*/
QPixmap fillRect(int x, int y, int w, int h, const QPixmap& p, Qt::BGMode) const;
/** Merges the two pixmaps \a p1 and \a p2 to one pixmap in
* vertical order if \a vertical is true, in horizontal order
* vertical order if \a vertical is true, in horizontal order
* otherwise. The method resizes the resulting pixmap.
*/
QPixmap merge(const QPixmap& p1, const QPixmap& p2, bool vertical) const;
Expand All @@ -117,7 +117,7 @@ class GuiExport BitmapFactoryInst : public Base::Factory
* resize the resulting pixmap.
*/
QPixmap merge(const QPixmap& p1, const QPixmap& p2, Position pos = BitmapFactoryInst::BottomLeft) const;
/** Creates a disabled pixmap of the given pixmap \a p by changing the brightness
/** Creates a disabled pixmap of the given pixmap \a p by changing the brightness
* of all opaque pixels to a higher value.
*/
QPixmap disabled(const QPixmap& p) const;
Expand All @@ -128,6 +128,9 @@ class GuiExport BitmapFactoryInst : public Base::Factory
*/
void convert(const SoSFImage& img, QImage& out) const;

/// Helper method to merge a pixmap into one corner of a QIcon
static QIcon mergePixmap (const QIcon &base, const QPixmap &px, Gui::BitmapFactoryInst::Position position);

private:
bool loadPixmap(const QString& path, QPixmap&) const;
void restoreCustomPaths();
Expand Down

0 comments on commit db5ef31

Please sign in to comment.