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/itemviews/qitemdelegate.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**
     
    4848#include <qlineedit.h>
    4949#include <qtextedit.h>
     50#include <qplaintextedit.h>
    5051#include <qpainter.h>
    5152#include <qpalette.h>
     
    185186
    186187    \ingroup model-view
    187     \mainclass
     188
    188189
    189190    QItemDelegate can be used to provide custom display features and editor
     
    219220    while editing takes place. Editors are created with a
    220221    QItemEditorFactory; a default static instance provided by
    221     QItemEditorFactory is installed on all item delagates. You can set
     222    QItemEditorFactory is installed on all item delegates. You can set
    222223    a custom factory using setItemEditorFactory() or set a new default
    223224    factory with QItemEditorFactory::setDefaultFactory(). It is the
     
    255256    \row    \o \l Qt::BackgroundColorRole \o QColor (obsolete; use Qt::BackgroundRole instead)
    256257    \row    \o \l Qt::CheckStateRole \o Qt::CheckState
    257     \row    \o \l Qt::DecorationRole \o QIcon and QColor
     258    \row    \o \l Qt::DecorationRole \o QIcon, QPixmap and QColor
    258259    \row    \o \l Qt::DisplayRole \o QString and types with a string representation
    259260    \row    \o \l Qt::EditRole \o See QItemEditorFactory for details
     
    352353{
    353354    QString text;
    354     switch (value.type()) {
     355    switch (value.userType()) {
     356        case QMetaType::Float:
     357            text = option.locale.toString(value.toFloat(), 'g');
     358            break;
    355359        case QVariant::Double:
    356360            text = option.locale.toString(value.toDouble(), 'g', DBL_DIG);
     
    574578
    575579/*!
    576     Gets data drom the \a editor widget and stores it in the specified
     580    Gets data from the \a editor widget and stores it in the specified
    577581    \a model at the item \a index.
    578582
     
    719723            elided += option.fontMetrics.elidedText(text.mid(start),
    720724                                                    option.textElideMode, textRect.width());
    721             if (end != -1)
    722                 elided += QChar::LineSeparator;
    723725        }
    724726        d->textLayout.setText(elided);
     
    861863/*!
    862864    \internal
     865
     866    Code duplicated in QCommonStylePrivate::viewItemLayout
    863867*/
    864868
     
    882886
    883887    textRect->adjust(-textMargin, 0, textMargin, 0); // add width padding
    884     if (textRect->height() == 0 && !hasPixmap)
     888    if (textRect->height() == 0 && (!hasPixmap || !hint)) {
     889        //if there is no text, we still want to have a decent height for the item sizeHint and the editor size
    885890        textRect->setHeight(option.fontMetrics.height());
     891    }
    886892
    887893    QSize pm(0, 0);
     
    10541060
    10551061        QPixmap selected = QPixmap(QPixmap::fromImage(img));
    1056         int n = (img.numBytes() >> 10) + 1;
     1062        int n = (img.byteCount() >> 10) + 1;
    10571063        if (QPixmapCache::cacheLimit() < n)
    10581064            QPixmapCache::setCacheLimit(n);
     
    11951201        case Qt::Key_Return:
    11961202#ifndef QT_NO_TEXTEDIT
    1197             if (qobject_cast<QTextEdit*>(editor))
     1203            if (qobject_cast<QTextEdit *>(editor) || qobject_cast<QPlainTextEdit *>(editor))
    11981204                return false; // don't filter enter key events for QTextEdit
    11991205            // We want the editor to be able to process the key press
     
    12191225            editor->parentWidget()->setFocus();
    12201226        return true;
    1221     } else if (event->type() == QEvent::FocusOut || event->type() == QEvent::Hide) {
     1227    } else if (event->type() == QEvent::FocusOut || (event->type() == QEvent::Hide && editor->isWindow())) {
    12221228        //the Hide event will take care of he editors that are in fact complete dialogs
    12231229        if (!editor->isActiveWindow() || (QApplication::focusWidget() != editor)) {
     
    12341240                return false;
    12351241#endif
    1236             // Opening a modal dialog will start a new eventloop
    1237             // that will process the deleteLater event.
    1238             if (QApplication::activeModalWidget()
    1239                 && !QApplication::activeModalWidget()->isAncestorOf(editor)
    1240                 && qobject_cast<QDialog*>(QApplication::activeModalWidget()))
    1241                 return false;
     1242
    12421243            emit commitData(editor);
    12431244            emit closeEditor(editor, NoHint);
     
    12971298    }
    12981299
    1299     Qt::CheckState state = (static_cast<Qt::CheckState>(value.toInt()) == Qt::Checked
     1300    Qt::CheckState state;
     1301    if ( flags & Qt::ItemIsTristate ) {
     1302        state = static_cast<Qt::CheckState>( (value.toInt() + 1) % 3 );
     1303    } else {
     1304        state = (static_cast<Qt::CheckState>(value.toInt()) == Qt::Checked
    13001305                            ? Qt::Unchecked : Qt::Checked);
     1306    }
     1307
    13011308    return model->setData(index, state, Qt::CheckStateRole);
    13021309}
     
    13211328    value = index.data(Qt::TextAlignmentRole);
    13221329    if (value.isValid())
    1323         opt.displayAlignment = (Qt::Alignment)value.toInt();
     1330        opt.displayAlignment = Qt::Alignment(value.toInt());
    13241331
    13251332    // set foreground brush
Note: See TracChangeset for help on using the changeset viewer.