Changeset 642 for trunk/src


Ignore:
Timestamp:
Mar 6, 2010, 12:32:46 AM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

gui: Use native file icons in standard Qt file dialogs.

Location:
trunk/src/gui
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gui/itemviews/qfileiconprovider.cpp

    r620 r642  
    9999#ifdef Q_WS_WIN
    100100    QIcon getWinIcon(const QFileInfo &fi) const;
     101#elif defined(Q_WS_PM)
     102    QIcon getPmIcon(const QFileInfo &fi) const;
    101103#elif defined(Q_WS_MAC)
    102104    QIcon getMacIcon(const QFileInfo &fi) const;
     
    319321}
    320322
     323#elif defined(Q_WS_PM)
     324QIcon QFileIconProviderPrivate::getPmIcon(const QFileInfo &fileInfo) const
     325{
     326    QIcon retIcon;
     327
     328    if (fileInfo.isRoot()) {
     329        // Unfortunately, WinLoadFileIcon() returns a regular folder icon for
     330        // paths like "C:\" (and nothing for "C:") instead of a drive icon.
     331        // Getting the latter involves calling WPS object methods so we leave it
     332        // out for now and let the stock Qt drive-specific icons be used instead.
     333        return retIcon;
     334    }
     335
     336    QByteArray path = QDir::toNativeSeparators(
     337        QDir::cleanPath(fileInfo.absoluteFilePath())).toLocal8Bit();
     338    HPOINTER hicon = WinLoadFileIcon(path, FALSE);
     339    if (hicon != NULLHANDLE) {
     340        // we're requesting the system (shared) icon handle which should be
     341        // always the same for the given file until the icon is changed, so use
     342        // the bitmap handles as a key in the pixmap cache
     343        QString key = QString(QLatin1String("qt_hicon_%1")).arg(hicon);
     344        QString keyMini = key + QLatin1String("_m");
     345        QPixmap pixmap;
     346        QPixmapCache::find(key, pixmap);
     347        if (!pixmap.isNull()) {
     348            retIcon.addPixmap(pixmap);
     349            QPixmapCache::find(keyMini, pixmap);
     350            if (!pixmap.isNull())
     351                retIcon.addPixmap(pixmap);
     352        } else {
     353            QPixmap mini;
     354            retIcon = QPixmap::fromPmHPOINTER(hicon, &pixmap, &mini);
     355            if (!retIcon.isNull()) {
     356                // store pixmaps in the cache
     357                Q_ASSERT(!pixmap.isNull() || !mini.isNull());
     358                if (!pixmap.isNull())
     359                    QPixmapCache::insert(key, pixmap);
     360                if (!mini.isNull())
     361                    QPixmapCache::insert(keyMini, mini);
     362            }
     363        }
     364    }
     365
     366    return retIcon;
     367}
     368
    321369#elif defined(Q_WS_MAC)
    322370QIcon QFileIconProviderPrivate::getMacIcon(const QFileInfo &fi) const
     
    410458    if (!icon.isNull())
    411459        return icon;
     460#elif defined Q_WS_PM
     461    if (QApplication::desktopSettingsAware()) {
     462        QIcon icon= d->getPmIcon(info);
     463        if (!icon.isNull())
     464            return icon;
     465    }
    412466#endif
    413467    if (info.isRoot())
  • trunk/src/gui/styles/qcommonstyle.cpp

    r561 r642  
    8989#endif
    9090
     91#ifdef Q_WS_PM
     92#   include <qt_os2.h>
     93#endif
     94
    9195QT_BEGIN_NAMESPACE
    9296
     
    30383042        if (const QStyleOptionToolBar *tbopt = qstyleoption_cast<const QStyleOptionToolBar *>(opt)) {
    30393043            if (tbopt->features & QStyleOptionToolBar::Movable) {
    3040                 ///we need to access the widget here because the style option doesn't 
     3044                ///we need to access the widget here because the style option doesn't
    30413045                //have all the information we need (ie. the layout's margin)
    30423046                const QToolBar *tb = qobject_cast<const QToolBar*>(widget);
     
    46684672        break;
    46694673
     4674#ifdef Q_WS_PM
     4675    case PM_ButtonIconSize:
     4676        ret = int(QStyleHelper::dpiScaled(16.));
     4677    case PM_SmallIconSize:
     4678        if (QApplication::desktopSettingsAware())
     4679            ret = WinQuerySysValue(HWND_DESKTOP, SV_CXICON) / 2;
     4680        else
     4681            ret = int(QStyleHelper::dpiScaled(16.));
     4682        break;
     4683#else
    46704684    case PM_ButtonIconSize:
    46714685    case PM_SmallIconSize:
    46724686        ret = int(QStyleHelper::dpiScaled(16.));
    46734687        break;
     4688#endif
    46744689    case PM_IconViewIconSize:
    46754690        ret = proxy()->pixelMetric(PM_LargeIconSize, opt, widget);
     
    46774692
    46784693    case PM_LargeIconSize:
     4694#ifdef Q_WS_PM
     4695        if (QApplication::desktopSettingsAware())
     4696            ret = WinQuerySysValue(HWND_DESKTOP, SV_CXICON);
     4697        else
     4698            ret = int(QStyleHelper::dpiScaled(32.));
     4699#else
    46794700        ret = int(QStyleHelper::dpiScaled(32.));
     4701#endif
    46804702        break;
    46814703
     
    59545976        break;
    59555977    }
     5978#if defined(Q_WS_PM)
     5979    if (QApplication::desktopSettingsAware() && !icon.isNull()) {
     5980        // make sure the file dialog related icons have a size not smaller than
     5981        // the system icon size by centering them (this makes sure the
     5982        // corresponding items are aligned with file items with system icons)
     5983        switch (standardIcon) {
     5984        case SP_DriveCDIcon:
     5985        case SP_DriveDVDIcon:
     5986        case SP_DriveNetIcon:
     5987        case SP_DriveHDIcon:
     5988        case SP_DriveFDIcon:
     5989        case SP_FileIcon:
     5990        case SP_FileLinkIcon:
     5991        case SP_DirLinkIcon:
     5992        case SP_DirClosedIcon:
     5993        case SP_DesktopIcon:
     5994        case SP_ComputerIcon:
     5995        case SP_DirOpenIcon:
     5996        case SP_FileDialogNewFolder:
     5997        case SP_DirHomeIcon:
     5998        case SP_TrashIcon: {
     5999            static QIcon::Mode modes[] = { QIcon::Normal, QIcon::Active,
     6000                                           QIcon::Disabled, QIcon::Selected };
     6001            static QIcon::State states[] = { QIcon::Off, QIcon::On };
     6002            int small = pixelMetric(PM_SmallIconSize);
     6003            int large = pixelMetric(PM_LargeIconSize);
     6004            for (size_t m = 0; m < sizeof(modes)/sizeof(modes[0]); ++m) {
     6005                for (size_t s = 0; s < sizeof(states)/sizeof(states[0]); ++s) {
     6006                    QIcon::Mode mm = modes[m];
     6007                    QIcon::State ss = states[s];
     6008                    QList<QSize> sizes = icon.availableSizes(mm, ss);
     6009                    QSize smallSz, largeSz;
     6010                    foreach(const QSize &asz, sizes) {
     6011                        if (asz.width() < small)
     6012                            smallSz = asz;
     6013                        else if (asz.width() < large)
     6014                            largeSz = asz;
     6015                        else
     6016                            break;
     6017                    }
     6018                    if (smallSz.isValid()) {
     6019                        QPixmap pixmap = icon.pixmap(smallSz, mm, ss);
     6020                        QPixmap centered(small, small);
     6021                        centered.fill(Qt::transparent);
     6022                        QPainter painter(&centered);
     6023                        int x = (small - pixmap.width()) / 2;
     6024                        int y = (small - pixmap.height()) / 2;
     6025                        painter.drawPixmap(x, y, pixmap);
     6026                        painter.end();
     6027                        icon.addPixmap(centered, mm, ss);
     6028                    }
     6029                    if (largeSz.isValid()) {
     6030                        QPixmap pixmap = icon.pixmap(largeSz, mm, ss);
     6031                        QPixmap centered(large, large);
     6032                        centered.fill(Qt::transparent);
     6033                        QPainter painter(&centered);
     6034                        int x = (large - pixmap.width()) / 2;
     6035                        int y = (large - pixmap.height()) / 2;
     6036                        painter.drawPixmap(x, y, pixmap);
     6037                        painter.end();
     6038                        icon.addPixmap(centered, mm, ss);
     6039                    }
     6040
     6041                }
     6042            }
     6043            break;
     6044        }
     6045        default:
     6046            break;
     6047        }
     6048    }
     6049#endif
    59566050    return icon;
    59576051}
  • trunk/src/gui/styles/qwindowsstyle.cpp

    r561 r642  
    438438
    439439    case PM_SmallIconSize:
     440#if defined(Q_WS_PM)
     441        if (QApplication::desktopSettingsAware())
     442            return QCommonStyle::pixelMetric(pm, opt, widget);
     443#endif
    440444        ret = int(QStyleHelper::dpiScaled(16.));
    441445        break;
    442446
    443447    case PM_LargeIconSize:
     448#if defined(Q_WS_PM)
     449        if (QApplication::desktopSettingsAware())
     450            return QCommonStyle::pixelMetric(pm, opt, widget);
     451#endif
    444452        ret = int(QStyleHelper::dpiScaled(32.));
    445453        break;
     
    13901398            QPixmap pixmap;
    13911399            QString pixmapName = QStyleHelper::uniqueName(QLatin1String("$qt_ia-") + QLatin1String(metaObject()->className()), opt, QSize(size, size))
    1392                   + QLatin1Char('-') + QString::number(pe);                               
     1400                  + QLatin1Char('-') + QString::number(pe);
    13931401            if (!QPixmapCache::find(pixmapName, pixmap)) {
    13941402                int border = size/5;
Note: See TracChangeset for help on using the changeset viewer.