src/gui/widgets/qcombobox.cpp
branchGCC_SURGE
changeset 31 5daf16870df6
parent 30 5dc02b23752f
child 33 3e2da88830cd
equal deleted inserted replaced
27:93b982ccede2 31:5daf16870df6
    54 #include <qevent.h>
    54 #include <qevent.h>
    55 #include <qlayout.h>
    55 #include <qlayout.h>
    56 #include <qscrollbar.h>
    56 #include <qscrollbar.h>
    57 #include <qtreeview.h>
    57 #include <qtreeview.h>
    58 #include <qheaderview.h>
    58 #include <qheaderview.h>
       
    59 #include <qmath.h>
    59 #ifndef QT_NO_IM
    60 #ifndef QT_NO_IM
    60 #include "qinputcontext.h"
    61 #include "qinputcontext.h"
    61 #endif
    62 #endif
    62 #include <private/qapplication_p.h>
    63 #include <private/qapplication_p.h>
    63 #include <private/qcombobox_p.h>
    64 #include <private/qcombobox_p.h>
   110 
   111 
   111 QStyleOptionMenuItem QComboMenuDelegate::getStyleOption(const QStyleOptionViewItem &option,
   112 QStyleOptionMenuItem QComboMenuDelegate::getStyleOption(const QStyleOptionViewItem &option,
   112                                                         const QModelIndex &index) const
   113                                                         const QModelIndex &index) const
   113 {
   114 {
   114     QStyleOptionMenuItem menuOption;
   115     QStyleOptionMenuItem menuOption;
   115     menuOption.palette = option.palette.resolve(QApplication::palette("QMenu"));
   116 
       
   117     QPalette resolvedpalette = option.palette.resolve(QApplication::palette("QMenu"));
       
   118     QVariant value = index.data(Qt::ForegroundRole);
       
   119     if (qVariantCanConvert<QBrush>(value)) {
       
   120         resolvedpalette.setBrush(QPalette::WindowText, qvariant_cast<QBrush>(value));
       
   121         resolvedpalette.setBrush(QPalette::ButtonText, qvariant_cast<QBrush>(value));
       
   122         resolvedpalette.setBrush(QPalette::Text, qvariant_cast<QBrush>(value));
       
   123     }
       
   124     menuOption.palette = resolvedpalette;
   116     menuOption.state = QStyle::State_None;
   125     menuOption.state = QStyle::State_None;
   117     if (mCombo->window()->isActiveWindow())
   126     if (mCombo->window()->isActiveWindow())
   118         menuOption.state = QStyle::State_Active;
   127         menuOption.state = QStyle::State_Active;
   119     if ((option.state & QStyle::State_Enabled) && (index.model()->flags(index) & Qt::ItemIsEnabled))
   128     if ((option.state & QStyle::State_Enabled) && (index.model()->flags(index) & Qt::ItemIsEnabled))
   120         menuOption.state |= QStyle::State_Enabled;
   129         menuOption.state |= QStyle::State_Enabled;
   141         break; }
   150         break; }
   142     default:
   151     default:
   143         menuOption.icon = qvariant_cast<QPixmap>(variant);
   152         menuOption.icon = qvariant_cast<QPixmap>(variant);
   144         break;
   153         break;
   145     }
   154     }
   146 
   155     if (qVariantCanConvert<QBrush>(index.data(Qt::BackgroundRole))) {
       
   156         menuOption.palette.setBrush(QPalette::All, QPalette::Background,
       
   157                                     qvariant_cast<QBrush>(index.data(Qt::BackgroundRole)));
       
   158     }
   147     menuOption.text = index.model()->data(index, Qt::DisplayRole).toString()
   159     menuOption.text = index.model()->data(index, Qt::DisplayRole).toString()
   148                            .replace(QLatin1Char('&'), QLatin1String("&&"));
   160                            .replace(QLatin1Char('&'), QLatin1String("&&"));
   149     menuOption.tabWidth = 0;
   161     menuOption.tabWidth = 0;
   150     menuOption.maxIconWidth =  option.decorationSize.width() + 4;
   162     menuOption.maxIconWidth =  option.decorationSize.width() + 4;
   151     menuOption.menuRect = option.rect;
   163     menuOption.menuRect = option.rect;
   318         if (minimumContentsLength > 0)
   330         if (minimumContentsLength > 0)
   319             sh.setWidth(qMax(sh.width(), minimumContentsLength * fm.width(QLatin1Char('X')) + (hasIcon ? iconSize.width() + 4 : 0)));
   331             sh.setWidth(qMax(sh.width(), minimumContentsLength * fm.width(QLatin1Char('X')) + (hasIcon ? iconSize.width() + 4 : 0)));
   320 
   332 
   321 
   333 
   322         // height
   334         // height
   323         sh.setHeight(qMax(fm.height(), 14) + 2);
   335         sh.setHeight(qMax(qCeil(QFontMetricsF(fm).height()), 14) + 2);
   324         if (hasIcon) {
   336         if (hasIcon) {
   325             sh.setHeight(qMax(sh.height(), iconSize.height() + 2));
   337             sh.setHeight(qMax(sh.height(), iconSize.height() + 2));
   326         }
   338         }
   327 
   339 
   328         // add style and strut values
   340         // add style and strut values
  1278     \property QComboBox::maxVisibleItems
  1290     \property QComboBox::maxVisibleItems
  1279     \brief the maximum allowed size on screen of the combo box, measured in items
  1291     \brief the maximum allowed size on screen of the combo box, measured in items
  1280 
  1292 
  1281     By default, this property has a value of 10.
  1293     By default, this property has a value of 10.
  1282 
  1294 
  1283     \note This property is ignored for non-editable comboboxes in Mac style.
  1295     \note This property is ignored for non-editable comboboxes in styles that returns
       
  1296     false for QStyle::SH_ComboBox_Popup such as the Mac style or the Gtk+ Style.
  1284 */
  1297 */
  1285 int QComboBox::maxVisibleItems() const
  1298 int QComboBox::maxVisibleItems() const
  1286 {
  1299 {
  1287     Q_D(const QComboBox);
  1300     Q_D(const QComboBox);
  1288     return d->maxVisibleItems;
  1301     return d->maxVisibleItems;
  2358 #ifndef QT_NO_TREEVIEW
  2371 #ifndef QT_NO_TREEVIEW
  2359                 if (d->model->hasChildren(idx) && treeView && treeView->isExpanded(idx))
  2372                 if (d->model->hasChildren(idx) && treeView && treeView->isExpanded(idx))
  2360                     toCheck.push(idx);
  2373                     toCheck.push(idx);
  2361 #endif
  2374 #endif
  2362                 ++count;
  2375                 ++count;
  2363                 if (!usePopup && count > d->maxVisibleItems) {
  2376                 if (!usePopup && count >= d->maxVisibleItems) {
  2364                     toCheck.clear();
  2377                     toCheck.clear();
  2365                     break;
  2378                     break;
  2366                 }
  2379                 }
  2367             }
  2380             }
  2368         }
  2381         }