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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.