From: <sh...@us...> - 2004-06-29 23:43:38
|
Update of /cvsroot/sim-icq/sim/sim In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18769/sim Modified Files: Tag: VOVAN icons.cpp icons.h Log Message: Fix drawing icons with alpha channel for win32 Index: icons.cpp =================================================================== RCS file: /cvsroot/sim-icq/sim/sim/icons.cpp,v retrieving revision 1.37.2.1 retrieving revision 1.37.2.2 diff -C2 -d -r1.37.2.1 -r1.37.2.2 *** icons.cpp 29 Jun 2004 06:28:43 -0000 1.37.2.1 --- icons.cpp 29 Jun 2004 23:42:58 -0000 1.37.2.2 *************** *** 52,59 **** public: WrkIconSet(); ! const QImage *getPict(const char *name, unsigned &flags); void clear(); protected: ! const QImage *add(const char *name, const QImage &pict, unsigned flags); }; --- 52,59 ---- public: WrkIconSet(); ! PictDef *getPict(const char *name); void clear(); protected: ! PictDef *add(const char *name, const QImage &pict, unsigned flags); }; *************** *** 63,67 **** FileIconSet(const char *file); ~FileIconSet(); ! const QImage *getPict(const char *name, unsigned &flags); void clear(); protected: --- 63,67 ---- FileIconSet(const char *file); ~FileIconSet(); ! PictDef *getPict(const char *name); void clear(); protected: *************** *** 129,132 **** --- 129,135 ---- for (it = m_defSets.begin(); it != m_defSets.end(); ++it) (*it)->clear(); + #ifdef WIN32 + m_icons.clear(); + #endif } return NULL; *************** *** 139,152 **** } ! const QImage *Icons::getPict(const char *name, unsigned &flags) { list<IconSet*>::iterator it; for (it = m_customSets.begin(); it != m_customSets.end(); ++it){ ! const QImage *res = (*it)->getPict(name, flags); if (res) return res; } for (it = m_defSets.begin(); it != m_defSets.end(); ++it){ ! const QImage *res = (*it)->getPict(name, flags); if (res) return res; --- 142,155 ---- } ! PictDef *Icons::getPict(const char *name) { list<IconSet*>::iterator it; for (it = m_customSets.begin(); it != m_customSets.end(); ++it){ ! PictDef *res = (*it)->getPict(name); if (res) return res; } for (it = m_defSets.begin(); it != m_defSets.end(); ++it){ ! PictDef *res = (*it)->getPict(name); if (res) return res; *************** *** 209,213 **** } if (size == 0){ ! res += s; break; } --- 212,216 ---- } if (size == 0){ ! res += quoteString(s); break; } *************** *** 253,256 **** --- 256,272 ---- } + #ifdef WIN32 + + PictDef *Icons::getPict(const QPixmap &p) + { + unsigned serial = p.serialNumber(); + ICONS_MAP::iterator it = m_icons.find(serial); + if (it == m_icons.end()) + return NULL; + return getPict(it->second.c_str()); + } + + #endif + static Icons *icons = NULL; *************** *** 270,293 **** } ! const QImage *getPict(const char *name, unsigned &flags) { ! return icons->getPict(name, flags); } ! static QPixmap convertToPict(const QImage &img) { QColor c = QApplication::palette().active().button(); unsigned char cr = c.red(); unsigned char cg = c.green(); unsigned char cb = c.blue(); ! QImage image(img.width(), img.height(), 32); ! QBitmap mask(img.width(), img.height()); QPainter pmask(&mask); ! pmask.fillRect(0, 0, img.width(), img.height(), QColor(255, 255, 255)); pmask.setPen(QColor(0, 0, 0)); ! unsigned int *from = (unsigned int*)img.bits(); unsigned int *to = (unsigned int*)image.bits(); ! for (int i = 0; i < img.height(); i++){ ! for (int j = 0; j < img.width(); j++){ unsigned int c = *(from++); unsigned char a = (c >> 24) & 0xFF; --- 286,311 ---- } ! PictDef *getPict(const char *name) { ! return icons->getPict(name); } ! static QPixmap getPixmap(PictDef *d, const char *name) { + #ifdef WIN32 + if (d->pixmap == NULL){ QColor c = QApplication::palette().active().button(); unsigned char cr = c.red(); unsigned char cg = c.green(); unsigned char cb = c.blue(); ! QImage image(d->image->width(), d->image->height(), 32); ! QBitmap mask(d->image->width(), d->image->height()); QPainter pmask(&mask); ! pmask.fillRect(0, 0, d->image->width(), d->image->height(), QColor(255, 255, 255)); pmask.setPen(QColor(0, 0, 0)); ! unsigned int *from = (unsigned int*)d->image->bits(); unsigned int *to = (unsigned int*)image.bits(); ! for (int i = 0; i < d->image->height(); i++){ ! for (int j = 0; j < d->image->width(); j++){ unsigned int c = *(from++); unsigned char a = (c >> 24) & 0xFF; *************** *** 304,312 **** } pmask.end(); ! QPixmap res; ! res.convertFromImage(image); ! res.setMask(mask); ! return res; ! #if 0 QPixmap res; res.convertFromImage(img); --- 322,336 ---- } pmask.end(); ! QPixmap *res = new QPixmap; ! res->convertFromImage(image); ! res->setMask(mask); ! d->pixmap = res; ! } ! ICONS_MAP &icons = getIcons()->m_icons; ! ICONS_MAP::iterator it = icons.find(d->pixmap->serialNumber()); ! if (it == icons.end()) ! icons.insert(ICONS_MAP::value_type(d->pixmap->serialNumber(), name)); ! return *(d->pixmap); ! #else QPixmap res; res.convertFromImage(img); *************** *** 317,330 **** QIconSet Icon(const char *name) { ! unsigned flags; ! const QImage *pict = getPict(name, flags); if (pict == NULL) return QIconSet(); ! QIconSet res(convertToPict(*pict)); string bigName = "big."; bigName += name; ! pict = getPict(bigName.c_str(), flags); if (pict) ! res.setPixmap(convertToPict(*pict), QIconSet::Large); return res; } --- 341,353 ---- QIconSet Icon(const char *name) { ! PictDef *pict = getPict(name); if (pict == NULL) return QIconSet(); ! QIconSet res(getPixmap(pict, name)); string bigName = "big."; bigName += name; ! pict = getPict(bigName.c_str()); if (pict) ! res.setPixmap(getPixmap(pict, bigName.c_str()), QIconSet::Large); return res; } *************** *** 332,345 **** const QImage *Image(const char *name) { ! unsigned flags; ! return getPict(name, flags); } QPixmap Pict(const char *name) { ! const QImage *img = Image(name); ! if (img) ! return convertToPict(*img); ! return QPixmap(); } --- 355,370 ---- const QImage *Image(const char *name) { ! PictDef *p = getPict(name); ! if (p == NULL) ! return NULL; ! return p->image; } QPixmap Pict(const char *name) { ! PictDef *p = getPict(name); ! if (p == NULL) ! return QPixmap(); ! return getPixmap(p, name); } *************** *** 358,365 **** if (name.left(5) == "icon:"){ name = name.mid(5); ! unsigned flags; ! const QImage *icon = getPict(name.latin1(), flags); ! if (icon) ! ((QMimeSourceFactory*)this)->setImage(abs_name, *icon); } return QMimeSourceFactory::data(abs_name); --- 383,389 ---- if (name.left(5) == "icon:"){ name = name.mid(5); ! PictDef *p = getPict(name.latin1()); ! if (p) ! ((QMimeSourceFactory*)this)->setImage(abs_name, *(p->image)); } return QMimeSourceFactory::data(abs_name); *************** *** 373,378 **** { for (PIXMAP_MAP::iterator it = m_icons.begin(); it != m_icons.end(); ++it){ ! if ((*it).second.icon) ! delete (*it).second.icon; } } --- 397,406 ---- { for (PIXMAP_MAP::iterator it = m_icons.begin(); it != m_icons.end(); ++it){ ! if ((*it).second.image) ! delete (*it).second.image; ! #ifdef WIN32 ! if ((*it).second.pixmap) ! delete (*it).second.pixmap; ! #endif } } *************** *** 451,455 **** static QImage makeOffline(unsigned flags, const QImage &p) { ! QImage image(p); unsigned swapColor = flags & ICON_COLOR_MASK; unsigned int *data = (image.depth() > 8) ? (unsigned int *)image.bits() : --- 479,483 ---- static QImage makeOffline(unsigned flags, const QImage &p) { ! QImage image = p.copy(); unsigned swapColor = flags & ICON_COLOR_MASK; unsigned int *data = (image.depth() > 8) ? (unsigned int *)image.bits() : *************** *** 476,480 **** static QImage makeInactive(const QImage &p) { ! QImage image(p); unsigned int *data = (image.depth() > 8) ? (unsigned int *)image.bits() : (unsigned int *)image.colorTable(); --- 504,508 ---- static QImage makeInactive(const QImage &p) { ! QImage image = p.copy(); unsigned int *data = (image.depth() > 8) ? (unsigned int *)image.bits() : (unsigned int *)image.colorTable(); *************** *** 495,499 **** static QImage makeInvisible(unsigned flags, const QImage &p) { ! QImage image(p); unsigned swapColor = flags & ICON_COLOR_MASK; char shift = (flags >> 8) & 0xFF; --- 523,527 ---- static QImage makeInvisible(unsigned flags, const QImage &p) { ! QImage image = p.copy(); unsigned swapColor = flags & ICON_COLOR_MASK; char shift = (flags >> 8) & 0xFF; *************** *** 527,531 **** static QImage merge(const QImage &p1, const QImage &p2) { ! QImage img1(p1); if (img1.depth() != 32) img1 = img1.convertDepth(32); --- 555,559 ---- static QImage merge(const QImage &p1, const QImage &p2) { ! QImage img1 = p1.copy(); if (img1.depth() != 32) img1 = img1.convertDepth(32); *************** *** 568,640 **** } ! const QImage *WrkIconSet::getPict(const char *name, unsigned &flags) { if (name == NULL) return NULL; PIXMAP_MAP::iterator it = m_icons.find(name); ! if (it != m_icons.end()){ ! flags = (*it).second.flags; ! return (*it).second.icon; ! } string n = name; if (n == "online"){ unsigned i; ! const QImage *icon = NULL; const char *icon_name = NULL; for (i = 0; i < getContacts()->nClients(); i++){ Client *client = getContacts()->getClient(i); icon_name = client->protocol()->description()->icon; ! icon = SIM::getPict(icon_name, flags); ! if (icon) break; } ! if (icon == NULL){ icon_name = "ICQ"; ! icon = SIM::getPict(icon_name, flags); } ! if (icon == NULL) return NULL; ! return add(name, *icon, flags); } if (n == "offline"){ ! const QImage *icon = SIM::getPict("online", flags); ! if (icon == NULL) return NULL; ! return add(name, makeOffline(flags, *icon), flags); } if (n == "inactive"){ ! const QImage *icon = SIM::getPict("online", flags); ! if (icon == NULL) return NULL; ! return add(name, makeInactive(*icon), flags); } if (n == "invisible"){ ! const QImage *icon = SIM::getPict("online", flags); ! if (icon == NULL) return NULL; ! return add(name, makeInvisible(flags, *icon), flags); } int pos = n.find('_'); if (pos > 0){ ! const QImage *icon = SIM::getPict(n.substr(0, pos).c_str(), flags); QImage res; ! if (icon){ string s = n.substr(pos + 1); if (s == "online"){ ! res = *icon; }else if (s == "offline"){ ! res = makeOffline(flags, *icon); }else if (s == "invisible"){ ! res = makeInvisible(flags, *icon); }else if (s == "inactive"){ ! res = makeInactive(*icon); }else{ ! unsigned f; ! const QImage *i = SIM::getPict(s.c_str(), f); ! if (i) ! res = merge(*icon, *i); } ! return add(name, res, flags); } } --- 596,665 ---- } ! PictDef *WrkIconSet::getPict(const char *name) { if (name == NULL) return NULL; PIXMAP_MAP::iterator it = m_icons.find(name); ! if (it != m_icons.end()) ! return &(*it).second; string n = name; if (n == "online"){ unsigned i; ! PictDef *p = NULL; const char *icon_name = NULL; for (i = 0; i < getContacts()->nClients(); i++){ Client *client = getContacts()->getClient(i); icon_name = client->protocol()->description()->icon; ! p = SIM::getPict(icon_name); ! if (p) break; } ! if (p == NULL){ icon_name = "ICQ"; ! p = SIM::getPict(icon_name); } ! if (p == NULL) return NULL; ! return add(name, *(p->image), p->flags); } if (n == "offline"){ ! PictDef *p = SIM::getPict("online"); ! if (p == NULL) return NULL; ! return add(name, makeOffline(p->flags, *(p->image)), p->flags); } if (n == "inactive"){ ! PictDef *p = SIM::getPict("online"); ! if (p == NULL) return NULL; ! return add(name, makeInactive(*(p->image)), p->flags); } if (n == "invisible"){ ! PictDef *p = SIM::getPict("online"); ! if (p == NULL) return NULL; ! return add(name, makeInvisible(p->flags, *(p->image)), p->flags); } int pos = n.find('_'); if (pos > 0){ ! PictDef *p = SIM::getPict(n.substr(0, pos).c_str()); QImage res; ! if (p){ string s = n.substr(pos + 1); if (s == "online"){ ! res = *(p->image); }else if (s == "offline"){ ! res = makeOffline(p->flags, *(p->image)); }else if (s == "invisible"){ ! res = makeInvisible(p->flags, *(p->image)); }else if (s == "inactive"){ ! res = makeInactive(*(p->image)); }else{ ! PictDef *pp = SIM::getPict(s.c_str()); ! if (pp) ! res = merge(*(p->image), *(pp->image)); } ! return add(name, res, p->flags); } } *************** *** 647,663 **** { for (PIXMAP_MAP::iterator it = m_icons.begin(); it != m_icons.end(); ++it){ ! if ((*it).second.icon) ! delete (*it).second.icon; } m_icons.clear(); } ! const QImage *WrkIconSet::add(const char *name, const QImage &pict, unsigned flags) { PictDef p; ! p.icon = new QImage(pict); p.flags = flags; m_icons.insert(PIXMAP_MAP::value_type(name, p)); ! return m_icons.find(name)->second.icon; } --- 672,695 ---- { for (PIXMAP_MAP::iterator it = m_icons.begin(); it != m_icons.end(); ++it){ ! if ((*it).second.image) ! delete (*it).second.image; ! #ifdef WIN32 ! if ((*it).second.pixmap) ! delete (*it).second.pixmap; ! #endif } m_icons.clear(); } ! PictDef *WrkIconSet::add(const char *name, const QImage &pict, unsigned flags) { PictDef p; ! p.image = new QImage(pict); p.flags = flags; + #ifdef WIN32 + p.pixmap = NULL; + #endif m_icons.insert(PIXMAP_MAP::value_type(name, p)); ! return &m_icons.find(name)->second; } *************** *** 676,680 **** } ! const QImage *FileIconSet::getPict(const char *name, unsigned &flags) { if (name == NULL) --- 708,712 ---- } ! PictDef *FileIconSet::getPict(const char *name) { if (name == NULL) *************** *** 683,688 **** if (it == m_icons.end()) return NULL; ! flags = (*it).second.flags; ! if ((*it).second.icon == NULL){ #ifdef USE_KDE if (!it->second.system.empty()){ --- 715,719 ---- if (it == m_icons.end()) return NULL; ! if ((*it).second.image == NULL){ #ifdef USE_KDE if (!it->second.system.empty()){ *************** *** 694,699 **** } if (!pict.isNull()){ ! (*it).second.icon = new QImage(pict->convertToImage()); ! return (*it).second.icon; } } --- 725,730 ---- } if (!pict.isNull()){ ! (*it).second.image = new QImage(pict->convertToImage()); ! return (*it).second; } } *************** *** 704,711 **** if (!m_zip->readFile(QString::fromUtf8(it->second.file.c_str()), &arr)) return NULL; ! (*it).second.icon = new QImage(arr); ! (*it).second.icon->convertDepth(32); } ! return (*it).second.icon; } --- 735,742 ---- if (!m_zip->readFile(QString::fromUtf8(it->second.file.c_str()), &arr)) return NULL; ! (*it).second.image = new QImage(arr); ! (*it).second.image->convertDepth(32); } ! return &((*it).second); } *************** *** 713,720 **** { for (PIXMAP_MAP::iterator it = m_icons.begin(); it != m_icons.end(); ++it){ ! if ((*it).second.icon == NULL) ! continue; ! delete (*it).second.icon; ! (*it).second.icon = NULL; } } --- 744,757 ---- { for (PIXMAP_MAP::iterator it = m_icons.begin(); it != m_icons.end(); ++it){ ! if ((*it).second.image){ ! delete (*it).second.image; ! (*it).second.image = NULL; ! } ! #ifdef WIN32 ! if ((*it).second.pixmap){ ! delete (*it).second.pixmap; ! (*it).second.pixmap = NULL; ! } ! #endif } } *************** *** 787,791 **** if (!strcmp(el, "icon")){ PictDef p; ! p.icon = NULL; p.file = m_file; p.flags = m_flags; --- 824,831 ---- if (!strcmp(el, "icon")){ PictDef p; ! p.image = NULL; ! #ifdef WIN32 ! p.pixmap = NULL; ! #endif p.file = m_file; p.flags = m_flags; Index: icons.h =================================================================== RCS file: /cvsroot/sim-icq/sim/sim/icons.h,v retrieving revision 1.5.2.1 retrieving revision 1.5.2.2 diff -C2 -d -r1.5.2.1 -r1.5.2.2 *** icons.h 29 Jun 2004 06:28:43 -0000 1.5.2.1 --- icons.h 29 Jun 2004 23:42:58 -0000 1.5.2.2 *************** *** 39,43 **** typedef struct PictDef { ! QImage *icon; string file; #ifdef USE_KDE --- 39,46 ---- typedef struct PictDef { ! QImage *image; ! #ifdef WIN32 ! QPixmap *pixmap; ! #endif string file; #ifdef USE_KDE *************** *** 60,64 **** IconSet(); virtual ~IconSet(); ! virtual const QImage *getPict(const char *name, unsigned &flags) = 0; virtual void clear() = 0; void parseSmiles(const QString&, unsigned &start, unsigned &size, string &name); --- 63,67 ---- IconSet(); virtual ~IconSet(); ! virtual PictDef *getPict(const char *name) = 0; virtual void clear() = 0; void parseSmiles(const QString&, unsigned &start, unsigned &size, string &name); *************** *** 71,74 **** --- 74,83 ---- }; + #ifdef WIN32 + + typedef map<unsigned, string> ICONS_MAP; + + #endif + class EXPORT Icons : public QObject, public EventReceiver { *************** *** 77,81 **** Icons(); ~Icons(); ! const QImage *getPict(const char *name, unsigned &flags); QString parseSmiles(const QString&); list<string> getSmile(const char *name); --- 86,90 ---- Icons(); ~Icons(); ! PictDef *getPict(const char *name); QString parseSmiles(const QString&); list<string> getSmile(const char *name); *************** *** 86,89 **** --- 95,102 ---- void removeIconSet(IconSet*); list<IconSet*> m_customSets; + #ifdef WIN32 + PictDef *getPict(const QPixmap &pict); + ICONS_MAP m_icons; + #endif protected slots: void iconChanged(int); |