Exemple #1
0
QVariant KrVfsModel::data(const QModelIndex& index, int role) const
{
    if (!index.isValid() || index.row() >= rowCount())
        return QVariant();
    vfile *vf = _vfiles.at(index.row());
    if (vf == 0)
        return QVariant();

    switch (role) {
    case Qt::FontRole:
        return _defaultFont;
    case Qt::EditRole: {
        if (index.column() == 0) {
            return vf->vfile_getName();
        }
        return QVariant();
    }
    case Qt::UserRole: {
        if (index.column() == 0) {
            return nameWithoutExtension(vf, false);
        }
        return QVariant();
    }
    case Qt::ToolTipRole:
    case Qt::DisplayRole: {
        switch (index.column()) {
        case KrViewProperties::Name: {
            return nameWithoutExtension(vf);
        }
        case KrViewProperties::Ext: {
            QString nameOnly = nameWithoutExtension(vf);
            const QString& vfName = vf->vfile_getName();
            return vfName.mid(nameOnly.length() + 1);
        }
        case KrViewProperties::Size: {
            if (vf->vfile_isDir() && vf->vfile_getSize() <= 0) {
                //HACK add <> brackets AFTER translating - otherwise KUIT thinks it's a tag
                static QString label = QString("<") +
                    i18nc("Show the string 'DIR' instead of file size in detailed view (for folders)", "DIR") + ">";
                return label;
            } else
                return (properties()->humanReadableSize) ?
                       KIO::convertSize(vf->vfile_getSize()) + "  " :
                       KRpermHandler::parseSize(vf->vfile_getSize()) + ' ';
        }
        case KrViewProperties::Type: {
            if (vf == _dummyVfile)
                return QVariant();
            QMimeDatabase db;
            QMimeType mt = db.mimeTypeForName(vf->vfile_getMime());
            if (mt.isValid())
                return mt.comment();
            return QVariant();
        }
        case KrViewProperties::Modified: {
            if (vf == _dummyVfile)
                return QVariant();
            time_t time = vf->vfile_getTime_t();
            struct tm* t = localtime((time_t *) & time);

            QDateTime tmp(QDate(t->tm_year + 1900, t->tm_mon + 1, t->tm_mday), QTime(t->tm_hour, t->tm_min));
            return QLocale().toString(tmp, QLocale::ShortFormat);
        }
        case KrViewProperties::Permissions: {
            if (vf == _dummyVfile)
                return QVariant();
            if (properties()->numericPermissions) {
                QString perm;
                return perm.sprintf("%.4o", vf->vfile_getMode() & PERM_BITMASK);
            }
            return vf->vfile_getPerm();
        }
        case KrViewProperties::KrPermissions: {
            if (vf == _dummyVfile)
                return QVariant();
            return KrView::krPermissionString(vf);
        }
        case KrViewProperties::Owner: {
            if (vf == _dummyVfile)
                return QVariant();
            return vf->vfile_getOwner();
        }
        case KrViewProperties::Group: {
            if (vf == _dummyVfile)
                return QVariant();
            return vf->vfile_getGroup();
        }
        default: return QString();
        }
        return QVariant();
    }
    case Qt::DecorationRole: {
        switch (index.column()) {
        case KrViewProperties::Name: {
            if (properties()->displayIcons) {
                if (_justForSizeHint)
                    return QPixmap(_view->fileIconSize(), _view->fileIconSize());
                return _view->getIcon(vf);
            }
            break;
        }
        default:
            break;
        }
        return QVariant();
    }
    case Qt::TextAlignmentRole: {
        switch (index.column()) {
        case KrViewProperties::Size:
            return QVariant(Qt::AlignRight | Qt::AlignVCenter);
        default:
            return QVariant(Qt::AlignLeft | Qt::AlignVCenter);
        }
        return QVariant();
    }
    case Qt::BackgroundRole:
    case Qt::ForegroundRole: {
        KrColorItemType colorItemType;
        colorItemType.m_activePanel = _view->isFocused();
        int actRow = index.row();
        if (_alternatingTable) {
            int itemNum = _view->itemsPerPage();
            if (itemNum == 0)
                itemNum++;
            if ((itemNum & 1) == 0)
                actRow += (actRow / itemNum);
        }
        colorItemType.m_alternateBackgroundColor = (actRow & 1);
        colorItemType.m_currentItem = _view->getCurrentIndex().row() == index.row();
        colorItemType.m_selectedItem = _view->isSelected(index);
        if (vf->vfile_isSymLink()) {
            if (vf->vfile_isBrokenLink())
                colorItemType.m_fileType = KrColorItemType::InvalidSymlink;
            else
                colorItemType.m_fileType = KrColorItemType::Symlink;
        } else if (vf->vfile_isDir())
            colorItemType.m_fileType = KrColorItemType::Directory;
        else if (vf->vfile_isExecutable())
            colorItemType.m_fileType = KrColorItemType::Executable;
        else
            colorItemType.m_fileType = KrColorItemType::File;

        KrColorGroup cols;
        KrColorCache::getColorCache().getColors(cols, colorItemType);

        if (colorItemType.m_selectedItem) {
            if (role == Qt::ForegroundRole)
                return cols.highlightedText();
            else
                return cols.highlight();
        }
        if (role == Qt::ForegroundRole)
            return cols.text();
        else
            return cols.background();
    }
    default:
        return QVariant();
    }
}
Exemple #2
0
void KgColors::generatePreview()
{
    const int currentPage = colorTabWidget->currentIndex();

    preview->clear();

    if (currentPage == activeTabIdx || currentPage == inactiveTabIdx) {
        PreviewItem *pwMarkCur = new PreviewItem(preview, i18n("Selected + Current"));
        PreviewItem *pwMark2   = new PreviewItem(preview, i18n("Selected 2"));
        PreviewItem *pwMark1   = new PreviewItem(preview, i18n("Selected 1"));
        PreviewItem *pwCurrent = new PreviewItem(preview, i18n("Current"));
        PreviewItem *pwInvLink = new PreviewItem(preview, i18n("Invalid symlink"));
        PreviewItem *pwSymLink = new PreviewItem(preview, i18n("Symbolic link"));
        PreviewItem *pwApp     = new PreviewItem(preview, i18n("Application"));
        PreviewItem *pwFile    = new PreviewItem(preview, i18n("File"));
        PreviewItem *pwDir     = new PreviewItem(preview, i18n("Directory"));

        bool isActive = currentPage == 0;

        // create local color cache instance, which does NOT affect the color cache instance using to paint the panels
        KrColorCache colCache;

        // create local color settings instance, which initially contains the setings from krConfig
        KrColorSettings colorSettings;

        // copy over local settings to color settings instance, which does not affect the persisted krConfig settings
        QList<QString> names = KrColorSettings::getColorNames();
        for (QList<QString>::Iterator it = names.begin(); it != names.end(); ++it) {
            KonfiguratorColorChooser * chooser = getColorSelector(*it);
            if (!chooser)
                continue;
            colorSettings.setColorTextValue(*it, chooser->getValue());
            if (chooser->isValueRGB())
                colorSettings.setColorValue(*it, chooser->getColor());
            else
                colorSettings.setColorValue(*it, QColor());
        }

        colorSettings.setBoolValue("KDE Default", generals->find("KDE Default")->isChecked());
        colorSettings.setBoolValue("Enable Alternate Background", generals->find("Enable Alternate Background")->isChecked());
        colorSettings.setBoolValue("Show Current Item Always", generals->find("Show Current Item Always")->isChecked());
        colorSettings.setBoolValue("Dim Inactive Colors", generals->find("Dim Inactive Colors")->isChecked());
        colorSettings.setNumValue("Dim Factor", dimFactor->value());

        // let the color cache use the local color settings
        colCache.setColors(colorSettings);

        // ask the local color cache for certain color groups and use them to color the preview
        KrColorGroup cg;

        // setting the background color
        colCache.getColors(cg, KrColorItemType(KrColorItemType::File, false, isActive, false, false));
        QPalette pal = preview->palette();
        pal.setColor(QPalette::Base, cg.background());
        preview->setPalette(pal);

        colCache.getColors(cg, KrColorItemType(KrColorItemType::Directory, false, isActive, false, false));
        pwDir->setColor(cg.text(), cg.background());
        colCache.getColors(cg, KrColorItemType(KrColorItemType::File, true, isActive, false, false));
        pwFile->setColor(cg.text(), cg.background());
        colCache.getColors(cg, KrColorItemType(KrColorItemType::Executable, false, isActive, false, false));
        pwApp->setColor(cg.text(), cg.background());
        colCache.getColors(cg, KrColorItemType(KrColorItemType::Symlink, true, isActive, false, false));
        pwSymLink->setColor(cg.text(), cg.background());
        colCache.getColors(cg, KrColorItemType(KrColorItemType::InvalidSymlink, false, isActive, false, false));
        pwInvLink->setColor(cg.text(), cg.background());
        colCache.getColors(cg, KrColorItemType(KrColorItemType::File, true, isActive, true, false));
        pwCurrent->setColor(cg.text(), cg.background());
        colCache.getColors(cg, KrColorItemType(KrColorItemType::File, false, isActive, false, true));
        pwMark1->setColor(cg.highlightedText(), cg.highlight());
        colCache.getColors(cg, KrColorItemType(KrColorItemType::File, true, isActive, false, true));
        pwMark2->setColor(cg.highlightedText(), cg.highlight());
        colCache.getColors(cg, KrColorItemType(KrColorItemType::File, false, isActive, true, true));
        pwMarkCur->setColor(cg.highlightedText(), cg.highlight());
    }
#ifdef SYNCHRONIZER_ENABLED
    else if (currentPage == synchronizerTabIdx) {
        PreviewItem *pwDelete    = new PreviewItem(preview, i18n("Delete"));
        PreviewItem *pwRightCopy = new PreviewItem(preview, i18n("Copy to right"));
        PreviewItem *pwLeftCopy  = new PreviewItem(preview, i18n("Copy to left"));
        PreviewItem *pwDiffers   = new PreviewItem(preview, i18n("Differing"));
        PreviewItem *pwEquals    = new PreviewItem(preview, i18n("Equals"));

        pwEquals->setColor(getColorSelector("Synchronizer Equals Foreground")->getColor(),
                           getColorSelector("Synchronizer Equals Background")->getColor());
        pwDiffers->setColor(getColorSelector("Synchronizer Differs Foreground")->getColor(),
                            getColorSelector("Synchronizer Differs Background")->getColor());
        pwLeftCopy->setColor(getColorSelector("Synchronizer LeftCopy Foreground")->getColor(),
                             getColorSelector("Synchronizer LeftCopy Background")->getColor());
        pwRightCopy->setColor(getColorSelector("Synchronizer RightCopy Foreground")->getColor(),
                              getColorSelector("Synchronizer RightCopy Background")->getColor());
        pwDelete->setColor(getColorSelector("Synchronizer Delete Foreground")->getColor(),
                           getColorSelector("Synchronizer Delete Background")->getColor());
    }
#endif
    else if (currentPage == otherTabIdx) {
        PreviewItem *pwNonMatch = new PreviewItem(preview, i18n("Quicksearch non-match"));
        PreviewItem *pwMatch    = new PreviewItem(preview, i18n("Quicksearch match"));
        pwMatch->setColor(getColorSelector("Quicksearch Match Foreground")->getColor(),
                          getColorSelector("Quicksearch Match Background")->getColor());
        pwNonMatch->setColor(getColorSelector("Quicksearch Non-match Foreground")->getColor(),
                             getColorSelector("Quicksearch Non-match Background")->getColor());
        PreviewItem *pwStatusActive = new PreviewItem(preview, i18n("Statusbar active"));
        PreviewItem *pwStatusInactive = new PreviewItem(preview, i18n("Statusbar inactive"));
        pwStatusActive->setColor(getColorSelector("Statusbar Foreground Active")->getColor(),
                                 getColorSelector("Statusbar Background Active")->getColor());
        pwStatusInactive->setColor(getColorSelector("Statusbar Foreground Inactive")->getColor(),
                                   getColorSelector("Statusbar Background Inactive")->getColor());
    }
}