void KonqCombo::updateItem( const QPixmap& pix, const QString& t, int index, const QString& title ) { // No need to flicker if (itemText( index ) == t && (!itemIcon(index).isNull() && itemIcon(index).pixmap(iconSize()).serialNumber() == pix.serialNumber())) return; // kDebug() << "item=" << t << "index=" << index; setItemText( index, t ); setItemIcon( index, pix ); setItemData( index, title ); update(); }
void KListItem::itemReset( ) { if(layoutType() == KWidget::None) { setLayoutType(KWidget::HBox); setSpacing(3); } QString ico = itemIcon(); QString txt = itemText(); if(m_label == NULL) { m_label = new KLabel(this); addItem(m_label); } if(!ico.isEmpty() && m_icon == NULL) { m_icon = new KImageItem(this); insertItem(m_icon, 0); } if(m_icon) { m_icon->setImagePath(ico); QSize s = m_icon->pixmapSize(); m_icon->setFixWidth(s.width()); } if(m_label) { m_label->setText(txt); } }
void KonqCombo::mousePressEvent( QMouseEvent *e ) { m_dragStart = QPoint(); // null QPoint if ( e->button() == Qt::LeftButton && !itemIcon( currentIndex()).isNull() ) { // check if the pixmap was clicked int x = e->pos().x(); QStyleOptionComboBox comboOpt; getStyleOption(&comboOpt); int x0 = QStyle::visualRect( layoutDirection(), rect(), style()->subControlRect( QStyle::CC_ComboBox, &comboOpt, QStyle::SC_ComboBoxEditField, this ) ).x(); if ( x > x0 + 2 && x < lineEdit()->x() ) { m_dragStart = e->pos(); return; // don't call KComboBox::mousePressEvent! } } QStyleOptionComboBox optCombo; optCombo.initFrom(this); if ( e->button() == Qt::LeftButton && m_pageSecurity != KonqMainWindow::NotCrypted && style()->subElementRect( QStyle::SE_ComboBoxFocusRect, &optCombo, this ).contains( e->pos() ) ) emit showPageSecurity(); KComboBox::mousePressEvent( e ); }
void KonqCombo::slotSetIcon( int index ) { if( itemIcon( index ).isNull()) // on-demand icon loading setItemIcon( index, KonqPixmapProvider::self()->pixmapFor( itemText( index ), KIconLoader::SizeSmall ) ); update(); }
void KonqCombo::getStyleOption(QStyleOptionComboBox* comboOpt) { //We only use this for querying metrics,so it's rough.. comboOpt->init(this); comboOpt->editable = isEditable(); comboOpt->frame = hasFrame(); comboOpt->iconSize = iconSize(); comboOpt->currentIcon = itemIcon(currentIndex()); comboOpt->currentText = currentText(); }
void KonqCombo::popup() { for( int i = 0; i < count(); ++i ) { if( itemIcon( i ).isNull() ) { // on-demand icon loading setItemIcon( i, KonqPixmapProvider::self()->pixmapFor( itemText( i ), KIconLoader::SizeSmall ) ); } } KHistoryComboBox::showPopup(); }
QRect ActionListComboBox::finalizePopupGeometry(const QRect &geometry) const { QRect result = geometry; int width = 0; const int itemCount = count(); const int iconWidth = iconSize().width() + 4; const QFontMetrics &fm = fontMetrics(); for (int i = 0; i < itemCount; ++i) { QModelIndex index = model()->index(i, 0); if (index.isValid()) { const int textWidth = fm.width(index.data().toString()); if (itemIcon(i).isNull()) { width = (qMax(width, textWidth)); } else { width = (qMax(width, textWidth + iconWidth)); } } } QStyleOptionComboBox opt; initStyleOption(&opt); QSize tmp(width, 0); tmp = style()->sizeFromContents(QStyle::CT_ComboBox, &opt, tmp, this); width = tmp.width() + 2 * iconWidth; const int screenWidth = QApplication::desktop()->width(); if ( width>screenWidth/2 ) { width = screenWidth/2; } if (width>geometry.width()) { QSize size = geometry.size(); size.setWidth(width + 10); result.setSize(size); } const int dx = screenWidth - result.right(); if (dx<0) { const int x = geometry.x() + dx; const int y = geometry.y(); result.moveTopLeft(QPoint(x, y)); } return result; }
void ModelManager::AddItem(const QString& modelName, const QString& maxFilename, const QString& thumbFilename) { QListWidgetItem* item = new QListWidgetItem(this); item->setTextAlignment(Qt::AlignHCenter | Qt::AlignBottom | Qt::AlignAbsolute); item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable); QPixmap pixmap(thumbFilename); QIcon itemIcon( pixmap.scaled( QSize(ICON_W, ICON_H) ) ); item->setIcon( itemIcon ); this->setIconSize( QSize(m_iconWidth*1.6, m_iconHight) ); item->setSizeHint( QSize(m_iconWidth*1.6, m_iconHight+24) ); if(modelName.isEmpty()) { QFileInfo fileInfo(maxFilename); item->setText(fileInfo.fileName()); } else item->setText(modelName); m_itemTextList.append( modelName ); }
void FlightVisualization::updateMarker(double latitude, double longitude, double bearing, int planeID) { int direction = int(bearing); // http://stackoverflow.com/questions/1531695/round-to-nearest-five-c-sharp direction = round(direction / (double) DIRECTION_MULTIPLE) * DIRECTION_MULTIPLE; if (bearing < 0) { direction += MAX_DIRECTION; } activePlanes[planeID].planeActive = true; activePlanes[planeID].latitude = latitude; activePlanes[planeID].longitude = longitude; QString planeLabel = QString(DISP_PLANE_PREFIX + "%1").arg(planeID); QString planeLabelNoDisplay = QString(PLANE_NUM_PREFIX + "%1").arg(planeID); // http://www.qtforum.org/article/13839/combobox-items.html //for plane selector QList<QListWidgetItem *> results = popupPlaneSelector->findItems(planeLabel, Qt::MatchExactly); //http://www.java2s.com/Code/Cpp/Qt/Drawsafilledincircle.htm if (results.size() <= 0) { QPixmap pixmap(ICON_PIXMAP_SIZE, ICON_PIXMAP_SIZE); pixmap.fill(Qt::transparent); QPainter painter(&pixmap); painter.setRenderHint(QPainter::Antialiasing, true); QPen pen(Qt::black, ICON_CIRCLE_LINE_WIDTH); painter.setPen(pen); QBrush brush(QColor (COLORS[planeID])); painter.setBrush(brush); painter.drawEllipse(CIRCLE_X_COORD, CIRCLE_Y_COORD, CIRCLE_WIDTH, CIRCLE_HEIGHT); QIcon itemIcon(pixmap); QListWidgetItem * item = new QListWidgetItem(itemIcon, planeLabel, popupPlaneSelector); item->setCheckState(Qt::Checked); popupPlaneSelector->addItem(item); } //for plane info if (ui->planeSelectorComboBox->findText(planeLabelNoDisplay) == NOT_FOUND) { ui->planeSelectorComboBox->addItem(planeLabelNoDisplay); comboIndexToPlaneIDMap[ui->planeSelectorComboBox->findText( planeLabelNoDisplay)] = planeID; } QString str = QString("updateMarker(%1, %2, %3, %4);").arg(planeID).arg( latitude, LAT_LONG_FIELD_WIDTH, FLOAT_FORMATTER, LAT_LONG_NUM_OF_DIGITS).arg(longitude, LAT_LONG_FIELD_WIDTH, FLOAT_FORMATTER, LAT_LONG_NUM_OF_DIGITS).arg( int(direction) / DIRECTION_MULTIPLE); ui->webView->page()->currentFrame()->documentElement().evaluateJavaScript( str); }