Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/dialogs/qsidebar.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the QtGui module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    5656QT_BEGIN_NAMESPACE
    5757
     58void QSideBarDelegate::initStyleOption(QStyleOptionViewItem *option,
     59                                         const QModelIndex &index) const
     60{
     61    QStyledItemDelegate::initStyleOption(option,index);
     62    QVariant value = index.data(QUrlModel::EnabledRole);
     63    if (value.isValid()) {
     64        //If the bookmark/entry is not enabled then we paint it in gray
     65        if (!qvariant_cast<bool>(value))
     66            option->state &= ~QStyle::State_Enabled;
     67    }
     68}
     69
    5870/*!
    5971    QUrlModel lets you have indexes from a QFileSystemModel to a list.  When QFileSystemModel
     
    8799
    88100    if (index.data(Qt::DecorationRole).isNull())
    89         flags &= ~Qt::ItemIsEnabled;
    90 
    91     if (invalidUrls.contains(index.data(UrlRole).toUrl()))
    92101        flags &= ~Qt::ItemIsEnabled;
    93102
     
    194203            if (!invalidUrls.contains(url))
    195204                invalidUrls.append(url);
     205            //The bookmark is invalid then we set to false the EnabledRole
     206            setData(index, false, EnabledRole);
     207        } else {
     208            //The bookmark is valid then we set to true the EnabledRole
     209            setData(index, true, EnabledRole);
    196210        }
    197211
     
    234248        if (!url.isValid() || url.scheme() != QLatin1String("file"))
    235249            continue;
     250        //this makes sure the url is clean
     251        const QString cleanUrl = QDir::cleanPath(url.toLocalFile());
     252        url = QUrl::fromLocalFile(cleanUrl);
     253
    236254        for (int j = 0; move && j < rowCount(); ++j) {
    237             if (index(j, 0).data(UrlRole) == url) {
     255            QString local = index(j, 0).data(UrlRole).toUrl().toLocalFile();
     256#if defined(Q_OS_WIN)
     257            if (index(j, 0).data(UrlRole).toUrl().toLocalFile().toLower() == cleanUrl.toLower()) {
     258#else
     259            if (index(j, 0).data(UrlRole).toUrl().toLocalFile() == cleanUrl) {
     260#endif
    238261                removeRow(j);
    239262                if (j <= row)
     
    243266        }
    244267        row = qMax(row, 0);
    245         QModelIndex idx = fileSystemModel->index(url.toLocalFile());
     268        QModelIndex idx = fileSystemModel->index(cleanUrl);
    246269        if (!fileSystemModel->isDir(idx))
    247270            continue;
    248271        insertRows(row, 1);
    249272        setUrl(index(row, 0), url, idx);
    250         watching.append(QPair<QModelIndex, QString>(idx, url.toLocalFile()));
     273        watching.append(qMakePair(idx, cleanUrl));
    251274    }
    252275}
     
    271294        return;
    272295    if (fileSystemModel != 0) {
    273         disconnect(model, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),
    274             this, SLOT(dataChanged(const QModelIndex &, const QModelIndex &)));
     296        disconnect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
     297            this, SLOT(dataChanged(QModelIndex,QModelIndex)));
    275298        disconnect(model, SIGNAL(layoutChanged()),
    276299            this, SLOT(layoutChanged()));
    277         disconnect(model, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
     300        disconnect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
    278301            this, SLOT(layoutChanged()));
    279302    }
    280303    fileSystemModel = model;
    281304    if (fileSystemModel != 0) {
    282         connect(model, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),
    283             this, SLOT(dataChanged(const QModelIndex &, const QModelIndex &)));
     305        connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
     306            this, SLOT(dataChanged(QModelIndex,QModelIndex)));
    284307        connect(model, SIGNAL(layoutChanged()),
    285308            this, SLOT(layoutChanged()));
    286         connect(model, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
     309        connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
    287310            this, SLOT(layoutChanged()));
    288311    }
     
    357380    urlModel->setFileSystemModel(model);
    358381    setModel(urlModel);
    359 
    360     connect(selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
    361             this, SLOT(clicked(const QModelIndex &)));
     382    setItemDelegate(new QSideBarDelegate(this));
     383
     384    connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
     385            this, SLOT(clicked(QModelIndex)));
    362386#ifndef QT_NO_DRAGANDDROP
    363387    setDragDropMode(QAbstractItemView::DragDrop);
    364388#endif
    365389    setContextMenuPolicy(Qt::CustomContextMenu);
    366     connect(this, SIGNAL(customContextMenuRequested(const QPoint &)),
    367             this, SLOT(showContextMenu(const QPoint &)));
     390    connect(this, SIGNAL(customContextMenuRequested(QPoint)),
     391            this, SLOT(showContextMenu(QPoint)));
    368392    urlModel->setUrls(newUrls);
    369393    setCurrentIndex(this->model()->index(0,0));
     
    391415void QSidebar::selectUrl(const QUrl &url)
    392416{
    393     disconnect(selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
    394                this, SLOT(clicked(const QModelIndex &)));
     417    disconnect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
     418               this, SLOT(clicked(QModelIndex)));
    395419
    396420    selectionModel()->clear();
     
    402426    }
    403427
    404     connect(selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
    405             this, SLOT(clicked(const QModelIndex &)));
     428    connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
     429            this, SLOT(clicked(QModelIndex)));
    406430}
    407431
Note: See TracChangeset for help on using the changeset viewer.