QSize ProgressListDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { QFontMetrics fontMetrics = option.fontMetrics; int itemHeight = d->separatorPixels; int itemWidth = d->leftMargin + d->rightMargin + d->iconWidth + d->separatorPixels * 2 + fontMetrics.height(); int textSize = fontMetrics.height(); if (!d->getInfoMessage(index).isEmpty()) { textSize = fontMetrics.size(Qt::TextSingleLine, d->getInfoMessage(index)).height(); itemHeight += textSize; } if (!d->getSizeProcessed(index).isEmpty() || !d->getSpeed(index).isEmpty() || !d->getSizeTotal(index).isEmpty()) { textSize = fontMetrics.size(Qt::TextSingleLine, d->getSizeProcessed(index)).height(); itemHeight += textSize; } if (d->getPercent(index) > 0) { itemHeight += d->progressBar->sizeHint().height(); } if (d->editorHeight > 0) itemHeight += d->editorHeight; if (itemHeight + d->separatorPixels >= d->minimumItemHeight) itemHeight += d->separatorPixels; else itemHeight = d->minimumItemHeight; return QSize(itemWidth + MIN_CONTENT_PIXELS, itemHeight); }
//----------------------------------------------------------------------------- QSize ctkPushButtonPrivate::buttonSizeHint()const { Q_Q(const ctkPushButton); int w = 0, h = 0; QStyleOptionButton opt; opt.initFrom(q); // icon QSize iconSize = q->iconSize(); int ih = iconSize.height(); int iw = iconSize.width() + this->IconSpacing; w += iw; h = qMax(h, ih); // text QString string(q->text()); bool empty = string.isEmpty(); if (empty) { string = QString::fromLatin1("XXXX"); } QFontMetrics fm = q->fontMetrics(); QSize sz = fm.size(Qt::TextShowMnemonic, string); if(!empty || !w) { w += sz.width(); } h = qMax(h, sz.height()); //opt.rect.setSize(QSize(w, h)); // PM_MenuButtonIndicator depends on the height QSize buttonSize = (q->style()->sizeFromContents(QStyle::CT_PushButton, &opt, QSize(w, h), q). expandedTo(QApplication::globalStrut())); return buttonSize; }
QSize DragBarButton::sizeHint() const { constPolish(); int m = 3; int tw = 0; int th = 0; int pw = 0; int ph = 0; if ( !text().isEmpty() ) { QFontMetrics fm = fontMetrics(); QSize sz = fm.size( ShowPrefix, text() ); tw = 64; // Minimum size th = sz.height(); } if ( m_pIcon ) { pw = m_pIcon->width(); ph = m_pIcon->height(); } int h = QMAX(ph,th)+2*m; int w = m + pw + (tw!=0 && pw!=0 ?m:0) + tw + m + 22; QSize size; if(m_orientation == Qt::Vertical) { size = QSize(w, h).expandedTo(QApplication::globalStrut()); } else { size = QSize(h, w).expandedTo(QApplication::globalStrut()); } return size; }
QSize SmallPushButton::sizeHint() const { QFontMetrics fm = fontMetrics(); QSize sz = fm.size(Qt::TextShowMnemonic, text()); return QSize(sz.width() + sz.width()/8 + 4, sz.height() + sz.height()/8 + 4); }
QSize SmallPushButton::sizeHint() const { QFontMetrics fm = fontMetrics(); QSize sz = fm.size(ShowPrefix, text()); return QSize(sz.width() + sz.width()/8 + 4, sz.height() + sz.height()/8 + 4); }
//----------------------------------------------------------------------------- QSize ctkCollapsibleButton::buttonSizeHint()const { int w = 0, h = 0; QStyleOptionButton opt; opt.initFrom(this); // indicator QSize indicatorSize = QSize(style()->pixelMetric(QStyle::PM_IndicatorWidth, &opt, this), style()->pixelMetric(QStyle::PM_IndicatorHeight, &opt, this)); int indicatorSpacing = style()->pixelMetric(QStyle::PM_CheckBoxLabelSpacing, &opt, this); int ih = indicatorSize.height(); int iw = indicatorSize.width() + indicatorSpacing; w += iw; h = qMax(h, ih); // text QString string(this->text()); bool empty = string.isEmpty(); if (empty) { string = QString::fromLatin1("XXXX"); } QFontMetrics fm = this->fontMetrics(); QSize sz = fm.size(Qt::TextShowMnemonic, string); if(!empty || !w) { w += sz.width(); } h = qMax(h, sz.height()); //opt.rect.setSize(QSize(w, h)); // PM_MenuButtonIndicator depends on the height QSize buttonSize = (style()->sizeFromContents(QStyle::CT_PushButton, &opt, QSize(w, h), this). expandedTo(QApplication::globalStrut())); return buttonSize; }
QSize ExtendedButton::sizeHint() const { int w = 0, h = 0; QStyleOptionButton opt; initStyleOption(&opt); // calculate contents size... bool showButtonBoxIcons = qobject_cast<QDialogButtonBox*>(parentWidget()) && style()->styleHint(QStyle::SH_DialogButtonBox_ButtonsHaveIcons); if (!icon().isNull() || showButtonBoxIcons) { int ih = opt.iconSize.height(); int iw = opt.iconSize.width() + 4; w += iw; h = qMax(h, ih); } QString s(text()); bool empty = s.isEmpty(); if (empty) s = QString::fromLatin1("XXXX"); QFontMetrics fm = fontMetrics(); QSize sz = fm.size(Qt::TextShowMnemonic, s); if (m_contentOrientation == Qt::Horizontal) { if(!empty || !w) w += sz.width(); if(!empty || !h) h = qMax(h, sz.height()); } else { if(!empty || !w) w = qMax(w, sz.width()); if (!empty && !h) h += m_contentInterval; if(!empty || !h) h += sz.height(); } opt.rect.setSize(QSize(w, h)); // PM_MenuButtonIndicator depends on the height if (menu()) w += style()->pixelMetric(QStyle::PM_MenuButtonIndicator, &opt, this); if (m_horizontalPadding < 0 && m_verticalPadding < 0) { return (style()->sizeFromContents(QStyle::CT_PushButton, &opt, QSize(w, h), this). expandedTo(QApplication::globalStrut())); } else { return QSize(w + 2 * m_horizontalPadding, h + 2 * m_verticalPadding); } }
/*!\reimp */ void QRadioButton::updateMask() { QBitmap bm(width(),height()); { bm.fill(color0); QPainter p( &bm, this ); int x, y, w, h; GUIStyle gs = style(); QFontMetrics fm = fontMetrics(); QSize lsz = fm.size(ShowPrefix, text()); QSize sz = style().exclusiveIndicatorSize(); if ( gs == WindowsStyle ) sz.setWidth(sz.width()+1); y = 0; x = sz.width() + gutter; w = width() - x; h = height(); QColorGroup cg(color1,color1, color1,color1,color1,color1,color1,color1, color0); style().drawItem( &p, x, y, w, h, AlignLeft|AlignVCenter|ShowPrefix, cg, TRUE, pixmap(), text() ); x = 0; y = (height() - lsz.height() + fm.height() - sz.height())/2; style().drawExclusiveIndicatorMask(&p, x, y, sz.width(), sz.height(), isOn() ); if ( hasFocus() ) { y = 0; x = sz.width() + gutter; w = width() - x; h = height(); QRect br = style().itemRect( &p, x, y, w, h, AlignLeft|AlignVCenter|ShowPrefix, isEnabled(), pixmap(), text() ); br.setLeft( br.left()-3 ); br.setRight( br.right()+2 ); br.setTop( br.top()-2 ); br.setBottom( br.bottom()+2); br = br.intersect( QRect(0,0,width(),height()) ); if ( !text().isEmpty() ) style().drawFocusRect( &p, br, cg ); else { br.setRight( br.left()-1 ); br.setLeft( br.left()-16 ); br.setTop( br.top() ); br.setBottom( br.bottom() ); style().drawFocusRect( &p, br, cg ); } } } setMask(bm); }
void NotificationDialog::getDataFromDatabase(){ ui->tableWidget->setRowCount(0); bool disconnect = false; bool connected = true; if(!db.isOpen()){ disconnect = true; connected = parent->connectToDatabase(&db, false, this); } if(connected){ for(int i = 0; i < parent->cNotifications.size(); i++){ QLabel * item = new QLabel; QStringList columnNames = parent->getColumnsNames("Customers"); QVector<QStringList> retrievedData = parent->executeSelectCommand("Customers", columnNames, "ID=" + QString::number(parent->cNotifications[i].customer)); if(!retrievedData.isEmpty()){ if(!retrievedData[0].isEmpty()){ item->setText(retrievedData[columnNames.indexOf("Surname")][0] + " " + retrievedData[columnNames.indexOf("Name")][0] + " " + retrievedData[columnNames.indexOf("Patronomic")][0] + "\nТелефонный номер: (" + retrievedData[columnNames.indexOf("PhoneCode")][0] + ")" + retrievedData[columnNames.indexOf("PhoneNumber")][0] + "\nПО: " + parent->cNotifications[i].soft + "\nДата истечения лицензии: " + parent->cNotifications[i].date); QFontMetrics fontMetrics = item->fontMetrics(); QSize textSize = fontMetrics.size(0, item->text()); int textWidth = textSize.width() + 30; int textHeight = textSize.height() + 20; item->setMinimumSize(textWidth, textHeight); item->resize(textWidth, textHeight); ui->tableWidget->setRowCount(ui->tableWidget->rowCount() + 1); ui->tableWidget->setCellWidget(ui->tableWidget->rowCount() - 1, 0, item); ui->tableWidget->setRowHeight(ui->tableWidget->rowCount() - 1, textHeight); } } } for(int i = 0; i < parent->lNotifications.size(); i++){ QLabel * item = new QLabel; item->setText("ПО: " + parent->lNotifications[i].soft + "\nОсталось лицензий: " + QString::number(parent->lNotifications[i].count)); QFontMetrics fontMetrics = item->fontMetrics(); QSize textSize = fontMetrics.size(0, item->text()); int textWidth = textSize.width() + 30; int textHeight = textSize.height() + 20; item->setMinimumSize(textWidth, textHeight); item->resize(textWidth, textHeight); ui->tableWidget->setRowCount(ui->tableWidget->rowCount() + 1); ui->tableWidget->setCellWidget(ui->tableWidget->rowCount() - 1, 0, item); ui->tableWidget->setRowHeight(ui->tableWidget->rowCount() - 1, textHeight); } } if(disconnect) parent->disconnectFromDatabase(&db); }
QSize TickSlider::biggestLabel() const { QSize maxsize; QFontMetrics fm = fontMetrics(); for (const QString& label : m_tick_labels) { QSize labelsize = fm.size(Qt::TextSingleLine, label); maxsize = maxsize.expandedTo(labelsize); } return maxsize; }
QSize RepeatWidget::sizeHint() const { // TODO: Merge with LookAheadWidget::sizeHint QFontMetrics metrics = fontMetrics(); _textSize = metrics.size( 0, _content->text() ); _childSize = _child->sizeHint(); int height = _textSize.height() + bdSize + _childSize.height() + bdSize + 2*pw; int width = 2 * pw + QMAX(_childSize.width(), 4*bdSize + _textSize.width()); return QSize(width,height); }
QSize HackCalculateFontSize(QFontMetrics fm, QString str ) { QStringList list = QStringList::split( QString::fromLatin1("\n"), str ); int maxWidth = 0; int height = 0; for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { QSize size = fm.size( 0, *it ); maxWidth = QMAX( maxWidth, size.width() ); height += size.height(); } return QSize( maxWidth, height ); }
IntSize RenderThemeQt::sizeForFont(RenderStyle* style) const { const QFontMetrics fm(style->font().font()); QSize size(0, 0); switch (style->appearance()) { case CheckboxAppearance: { break; } case RadioAppearance: { break; } case PushButtonAppearance: case ButtonAppearance: { QSize sz = fm.size(Qt::TextShowMnemonic, QString::fromLatin1("X")); QStyleOptionButton opt; sz = QApplication::style()->sizeFromContents(QStyle::CT_PushButton, &opt, sz, 0); size.setHeight(sz.height()); break; } case MenulistAppearance: { QSize sz; sz.setHeight(qMax(fm.lineSpacing(), 14) + 2); QStyleOptionComboBox opt; sz = QApplication::style()->sizeFromContents(QStyle::CT_ComboBox, &opt, sz, 0); size.setHeight(sz.height()); break; } case TextFieldAppearance: { const int verticalMargin = 1; const int horizontalMargin = 2; int h = qMax(fm.lineSpacing(), 14) + 2*verticalMargin; int w = fm.width(QLatin1Char('x')) * 17 + 2*horizontalMargin; QStyleOptionFrameV2 opt; opt.lineWidth = QApplication::style()->pixelMetric(QStyle::PM_DefaultFrameWidth, &opt, 0); QSize sz = QApplication::style()->sizeFromContents(QStyle::CT_LineEdit, &opt, QSize(w, h).expandedTo(QApplication::globalStrut()), 0); size.setHeight(sz.height()); break; } default: break; } return size; }
/*! \reimp */ QSize QToolButton::sizeHint() const { Q_D(const QToolButton); if (d->sizeHint.isValid()) return d->sizeHint; ensurePolished(); int w = 0, h = 0; QStyleOptionToolButton opt; initStyleOption(&opt); QFontMetrics fm = fontMetrics(); if (opt.toolButtonStyle != Qt::ToolButtonTextOnly) { QSize icon = opt.iconSize; w = icon.width(); h = icon.height(); #ifdef Q_WS_MAC extern CGFloat qt_mac_get_scalefactor(); w /= qt_mac_get_scalefactor(); h /= qt_mac_get_scalefactor(); #endif } if (opt.toolButtonStyle != Qt::ToolButtonIconOnly) { QSize textSize = fm.size(Qt::TextShowMnemonic, text()); textSize.setWidth(textSize.width() + fm.width(QLatin1Char(' '))*2); if (opt.toolButtonStyle == Qt::ToolButtonTextUnderIcon) { h += 4 + textSize.height(); if (textSize.width() > w) w = textSize.width(); } else if (opt.toolButtonStyle == Qt::ToolButtonTextBesideIcon) { w += 4 + textSize.width(); if (textSize.height() > h) h = textSize.height(); } else { // TextOnly w = textSize.width(); h = textSize.height(); } } opt.rect.setSize(QSize(w, h)); // PM_MenuButtonIndicator depends on the height if (d->popupMode == MenuButtonPopup) w += style()->pixelMetric(QStyle::PM_MenuButtonIndicator, &opt, this); d->sizeHint = style()->sizeFromContents(QStyle::CT_ToolButton, &opt, QSize(w, h), this). expandedTo(QApplication::globalStrut()); return d->sizeHint; }
//----------------------------------------------------------------------------- QList<QRect> ctkAxesWidgetPrivate::labelRects(const QList<QPoint>& extremities, QSize offset)const { Q_Q(const ctkAxesWidget); QFontMetrics fm = q->fontMetrics(); QSize letterSize = fm.size(Qt::TextShowMnemonic, "X") + QSize(1,1); QSize halfLetterSize = letterSize / 2; QList<QRect> rects; for (int i = 0; i < 6; ++i) { rects << QRect(extremities[i] + QPoint(cos(this->AxesAngles[i]) * (offset.width()+halfLetterSize.width()), -sin(this->AxesAngles[i]) * (offset.height()+halfLetterSize.height())) - QPoint(halfLetterSize.width(), halfLetterSize.height()), letterSize); } return rects; }
/*! \reimp */ QSize QPushButton::sizeHint() const { Q_D(const QPushButton); if (d->sizeHint.isValid() && d->lastAutoDefault == autoDefault()) return d->sizeHint; d->lastAutoDefault = autoDefault(); ensurePolished(); int w = 0, h = 0; QStyleOptionButton opt; initStyleOption(&opt); // calculate contents size... #ifndef QT_NO_ICON bool showButtonBoxIcons = qobject_cast<QDialogButtonBox*>(parentWidget()) && style()->styleHint(QStyle::SH_DialogButtonBox_ButtonsHaveIcons); if (!icon().isNull() || showButtonBoxIcons) { int ih = opt.iconSize.height(); int iw = opt.iconSize.width() + 4; w += iw; h = qMax(h, ih); } #endif QString s(text()); bool empty = s.isEmpty(); if (empty) s = QString::fromLatin1("XXXX"); QFontMetrics fm = fontMetrics(); QSize sz = fm.size(Qt::TextShowMnemonic, s); if(!empty || !w) w += sz.width(); if(!empty || !h) h = qMax(h, sz.height()); opt.rect.setSize(QSize(w, h)); // PM_MenuButtonIndicator depends on the height #ifndef QT_NO_MENU if (menu()) w += style()->pixelMetric(QStyle::PM_MenuButtonIndicator, &opt, this); #endif d->sizeHint = (style()->sizeFromContents(QStyle::CT_PushButton, &opt, QSize(w, h), this). expandedTo(QApplication::globalStrut())); return d->sizeHint; }
void QmaxButton::createSideButton(QPainter &painter) { QRect scaledRect; scaledRect = matrix.mapRect(QRect(0,0,this->logicalSize.width(),this->logicalSize.height())); QColor color1(80,85,85,255); QColor color(189,198,198,255); QColor color2(155,150,158,255); QPoint start(0,40); QPoint end(40,80); QLinearGradient gradient(start,end); QLinearGradient brush1(0,0,0,scaledRect.height()); QPen pen(QBrush(color),2); if(m_nPressed) { painter.setPen(pen); gradient.setColorAt(0,color); gradient.setColorAt(1,color2); } else { painter.setPen(Qt::NoPen); gradient.setColorAt(0,color1); gradient.setColorAt(1,color1); } painter.setBrush(gradient); painter.drawRect(0,0,100,80); painter.drawPixmap(0, 0, this->m_strImage); QFont font( "DejaVu Sans" ); font.setPointSize( 12 ); painter.setFont( font ); brush1.setColorAt(1.0f,QColor(255,255,255,255)); if(this->isEnabled()==false) { brush1.setColorAt(1.0f,QColor(200,200,200,100)); } painter.setPen(QPen(brush1,1)); painter.setBrush(brush1); QFontMetrics fMetrics = painter.fontMetrics(); QSize sz = fMetrics.size( Qt::TextWordWrap, m_strText ); QRectF txtRect( scaledRect.center(), sz ); int xPoint = (scaledRect.width()/2)- ((m_strText.count()/2)); int yPoint = scaledRect.height()/2; painter.drawText(xPoint,yPoint,m_strText); }
void SessionButton::slot_soundClicked() { bool snd=!soundIcon->isEnabled(); soundIcon->setEnabled ( snd ); if ( snd ) sound->setText ( tr ( "Enabled" ) ); else sound->setText ( tr ( "Disabled" ) ); QFontMetrics fm ( sound->font() ); sound->setFixedSize ( fm.size ( Qt::TextSingleLine,sound->text() ) + QSize ( 8,4 ) ); X2goSettings st ( "sessions" ); st.setting()->setValue ( sid+"/sound", ( QVariant ) snd ); st.setting()->sync(); }
const QSize& DateTimeEditor::getCharSize() const { if (m_font != font() || m_charSize.isEmpty()) { m_font = font(); const QFontMetrics metrics = fontMetrics(); m_charSize.setWidth(0); m_charSize.setHeight(0); const QString chars = "0123456789-: YMDHS"; for (const QChar& c : chars) { const QSize cSize = metrics.size(0, c); m_charSize = m_charSize.expandedTo(cSize); } } return m_charSize; }
/*! \reimp */ QSize QPushButton::sizeHint() const { Q_D(const QPushButton); if (d->sizeHint.isValid()) return d->sizeHint; ensurePolished(); int w = 0, h = 0; QStyleOptionButton opt; initStyleOption(&opt); // calculate contents size... #ifndef QT_NO_ICON if (!icon().isNull()) { int ih = opt.iconSize.height(); int iw = opt.iconSize.width() + 4; w += iw; h = qMax(h, ih); } #endif #ifndef QT_NO_MENU if (menu()) w += style()->pixelMetric(QStyle::PM_MenuButtonIndicator, &opt, this); #endif QString s(text()); bool empty = s.isEmpty(); if (empty) s = QString::fromLatin1("XXXX"); QFontMetrics fm = fontMetrics(); QSize sz = fm.size(Qt::TextShowMnemonic, s); if(!empty || !w) w += sz.width(); if(!empty || !h) h = qMax(h, sz.height()); d->sizeHint = (style()->sizeFromContents(QStyle::CT_PushButton, &opt, QSize(w, h), this). expandedTo(QApplication::globalStrut())); return d->sizeHint; }
QSize StyledButton::sizeHint() const { // Based off QPushButton // TODO: Cache result int w = 0, h = 0; ensurePolished(); // Initialize button style options QStyleOptionButton opt; initStyleOption(&opt); // Add icon size if(!icon().isNull()) { int ih = opt.iconSize.height(); int iw = opt.iconSize.width() + 4; w += iw; h = qMax(h, ih); } // Add text size QString s(text()); bool empty = s.isEmpty(); if(empty) s = QString::fromLatin1("XXXX"); QFontMetrics fm = fontMetrics(); QSize sz = fm.size(Qt::TextShowMnemonic, s); if(!empty || !w) w += sz.width(); if(!empty || !h) h = qMax(h, sz.height()); // Add margins and return QMargins margins = contentsMargins(); QSize sizeHint = QSize( w + margins.left() + margins.right(), h + margins.top() + margins.bottom()); return sizeHint; }
QSize ActionLabel::sizeHint() const { ensurePolished(); int w = 0, h = 0; QStyleOptionToolButton opt; initStyleOption(&opt); QString s(text()); bool empty = s.isEmpty(); if (empty) s = QString::fromLatin1("XXXX"); QFontMetrics fm = fontMetrics(); QSize sz = fm.size(Qt::TextShowMnemonic, s); if(!empty || !w) w += sz.width(); if(!empty || !h) h = qMax(h, sz.height()); opt.rect.setSize(QSize(w, h)); // PM_MenuButtonIndicator depends on the height if (!icon().isNull()) { int ih = opt.iconSize.height(); int iw = opt.iconSize.width() + 4; w += iw; h = qMax(h, ih); } if (menu()) w += style()->pixelMetric(QStyle::PM_MenuButtonIndicator, &opt, this); h += 4; w += 8; QSize sizeHint = (style()->sizeFromContents(QStyle::CT_PushButton, &opt, QSize(w, h), this). expandedTo(QApplication::globalStrut())); return sizeHint; }
QSize KMultiTabBarButton::sizeHint() const { constPolish(); int w = 0, h = 0; // calculate contents size... #ifndef QT_NO_ICONSET if ( iconSet() && !iconSet()->isNull() ) { int iw = iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).width() + 4; int ih = iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height(); w += iw; h = QMAX( h, ih ); } #endif if ( isMenuButton() ) w += style().pixelMetric(QStyle::PM_MenuButtonIndicator, this); if ( pixmap() ) { QPixmap *pm = (QPixmap *)pixmap(); w += pm->width(); h += pm->height(); } else { QString s( text() ); bool empty = s.isEmpty(); if ( empty ) s = QString::fromLatin1("XXXX"); QFontMetrics fm = fontMetrics(); QSize sz = fm.size( ShowPrefix, s ); if(!empty || !w) w += sz.width(); if(!empty || !h) h = QMAX(h, sz.height()); } return (style().sizeFromContents(QStyle::CT_ToolButton, this, QSize(w, h)). expandedTo(QApplication::globalStrut())); }
void VCWidget::paintEvent(QPaintEvent* e) { int caption_x = 0; int caption_y = 0; // First paint whatever QFrame wants to QFrame::paintEvent(e); // Draw the widget's caption QPainter painter(this); QFontMetrics metrics = painter.fontMetrics(); QSize textSize = metrics.size(SingleLine, caption()); caption_x = static_cast<int> (floor((width() / 2.0) - (textSize.width() / 2.0))); caption_y = static_cast<int> (floor((height() / 2.0) + ((textSize.height() - metrics.leading()) / 2.0))); painter.drawText(caption_x, caption_y, caption()); /* Draw selection frame */ if (_app->mode() == App::Design && _app->virtualConsole()->selectedWidget() == this) { // Draw a dotted line around the widget QPen pen(DotLine); pen.setWidth(2); painter.setPen(pen); painter.drawRect(1, 1, rect().width() - 1, rect().height() - 1); // Draw a resize handle QBrush b(SolidPattern); painter.fillRect(rect().width() - 10, rect().height() - 10, 10, 10, b); } }
void CodeAtlas::TopicLODMaker::modifyTree() { typedef SymbolWordAttr::WordMap WordMap; QList<WordMap> inputWordList; QRectF sceneRect = UIManager::instance()->getScene().sceneRect(); float maxRange = max(sceneRect.width(), sceneRect.height()); int standardViewRange = 300; // 300 * 300 screen float minLod = standardViewRange / maxRange; float avgSize = 0; // use tfidf to compute priority LodMerger lodMerger; int ithNode = 0; SymbolTree* tree = m_tree; LodAttr::Ptr lodAttr = tree->getRoot()->getOrAddAttr<LodAttr>(); QList<SymbolNode::Ptr> nodeList; SmartDepthIterator it(tree->getRoot(), SmartDepthIterator::PREORDER, SymbolInfo::ClassStruct|SymbolInfo::FunctionSignalSlot); for (SymbolNode::Ptr node; node = *it; ++it, ++ithNode) { SymbolInfo info = node->getSymInfo(); if (info.elementType() & SymbolInfo::Folder) continue; SymbolWordAttr::Ptr wordAttr = node->getAttr<SymbolWordAttr>(); if (wordAttr.isNull())continue; const WordMap& wordWeightMap = wordAttr->getNameWordWeightMap(); if (!wordWeightMap.size())continue; UIElementAttr::Ptr uiAttr = node->getAttr<UIElementAttr>(); if (uiAttr.isNull())continue; NodeUIItem::Ptr uiItem = uiAttr->getUIItem(); if (uiItem.isNull())continue; QRectF rectInScene = uiItem->mapToScene(uiItem->entityRect()).boundingRect(); lodMerger.addItem(rectInScene.center(), rectInScene.width()* 0.5f); inputWordList.push_back(wordWeightMap); WordMap::iterator beg = inputWordList.back().begin(); WordMap::iterator end = inputWordList.back().end(); for (WordMap::iterator pW = beg; pW != end; ++pW) { *pW *= (rectInScene.width() * rectInScene.height()); } nodeList.push_back(node); avgSize += rectInScene.width(); if (info.isTopLevel()) { it.skipSubTree(); } } if (!inputWordList.size()) return; avgSize /= inputWordList.size(); float maxLod = max(40 / avgSize, minLod); printf("%d symbols to perform LOD filter\n", inputWordList.size()); float viewSize[2] = {55,30}; for (float lod = maxLod; lod >= minLod; lod /= 2.5f) { // cluster nodes lodMerger.setMinMergeSize(QSizeF(viewSize[0] / lod, viewSize[1] / lod)); lodMerger.compute(); // collect words int nCluster = lodMerger.getClusterNum(); if (!nCluster) return; typedef SymbolWordAttr::WordMap WordMap; QVector<WordMap> clusterWordList(nCluster); for (int i = 0; i < lodMerger.getInputItemNum(); ++i) { int clusterID = lodMerger.getClusterID(i); const WordMap& wordWeightMap = inputWordList[i]; SymbolWordAttr::insertWords(clusterWordList[clusterID], wordWeightMap); } // compute tfidf TFIDFMaker tfidfMaker; for (int i = 0; i < clusterWordList.size(); ++i) { WordMap::Iterator pW; for (pW = clusterWordList[i].begin(); pW != clusterWordList[i].end(); ++pW) { tfidfMaker.addWord(i, pW.key(), pW.value()); } } tfidfMaker.computeTFIDF(); // extract words from each cluster typedef LodAttr::WordCloudItem WordCloudItem; WordCloudItem wcItem; QList<WordCloudItem> txtItemList; float minP = FLT_MAX, maxP = 0; for (int ithCluster = 0; ithCluster < nCluster; ++ithCluster) { const QRectF& rect = lodMerger.getClusterRect(ithCluster); float topLeft[2] = {rect.center().x(), rect.center().y()}; float dim[2] = {rect.width()*0.5f, rect.height()*0.5f}; WordMap& wordMap = clusterWordList[ithCluster]; // find best word for each cluster WordMap::Iterator pBestWord; float maxPriority = -FLT_MAX; for (WordMap::Iterator pW = wordMap.begin(); pW!= wordMap.end(); ++pW) { int wordID = pW.key(); float priority = tfidfMaker.getTFIDF(ithCluster, wordID); if (priority > maxPriority) { maxPriority = priority; pBestWord = pW; } } if (maxPriority == -FLT_MAX) continue; // record that word wcItem.m_clusterID = ithCluster; int wordID = pBestWord.key(); float visualPriority = sqrt(rect.width() * rect.width() + rect.height() * rect.height()); wcItem.m_txt = SymbolWordAttr::getWord(wordID); wcItem.m_priority = tfidfMaker.getTFIDF(ithCluster, wordID) * (visualPriority) ; minP = min(minP, wcItem.m_priority); maxP = max(maxP, wcItem.m_priority); float frag[2] = {0.5,0.5};//{rand()/float(RAND_MAX)*2.f-1.f, rand()/float(RAND_MAX)*2.f-1.f}; wcItem.m_pos.rx() = topLeft[0] + frag[0] * dim[0] * 0.5f; wcItem.m_pos.ry() = topLeft[1] + frag[1] * dim[1] * 0.5f; txtItemList.push_back(wcItem); } int nTxtItem = txtItemList.size(); // compute view size float minFontSize = 12, maxFontSize = 25, interval = 4; QFont font("Tahoma", 7, QFont::Light); for (int i = 0; i < nTxtItem; ++i) { WordCloudItem &item = txtItemList[i]; float fOffset = (maxFontSize-minFontSize)*sqrt((item.m_priority-minP)/(maxP-minP+1e-3)); int iOffset = int(fOffset / interval) * interval; int fs = minFontSize + iOffset; item.m_fontSize = fs; //printf("pointsize: %d maxSize = %f min %f p%f\n", fs, maxP, minP, item.m_priority); font.setPointSize(item.m_fontSize); QFontMetrics fm = QFontMetrics(font); item.m_viewSize = fm.size(0, item.m_txt); } lodAttr->addLodWordCloud(lod, txtItemList); printf("lod = %f words = %d\n", lod, txtItemList.size()); // prepare next input QList<QRectF> clusterRectList; for (int i = 0; i < nCluster; ++i) { clusterRectList.push_back(lodMerger.getClusterRect(i)); } inputWordList = clusterWordList.toList(); lodMerger.clearAll(); lodMerger.addItem(clusterRectList); } }
void QP_PartWidget::paintEvent(QPaintEvent *) { /*---the paint area---*/ QPainter paint(this); if (partinfo->type == QTParted::extended) { QColor color = Qt::cyan; paint.fillRect(2, 2, width()-4, height()-4, color); } else { int used_size; /*---draw a rect with filesystem color---*/ paint.fillRect(5, 5, width()-10, height()-10, partinfo->fsspec->color()); /*---fill with white color---*/ paint.fillRect(8, 8, width()-16, height()-16, Qt::white); /*---if you know how much space is used fill calculate the size for fill---* *---with yellow color ---*/ if (partinfo->min_size != -1) { float size = partinfo->mb_end()-partinfo->mb_start(); used_size = (int)(((width()-16)*partinfo->mb_min_size()) / size); } else { used_size = width()-16; } /*---if it is an empty partition or you cannot know how much filesystem is used... * just fill with the right color!---*/ if ((partinfo->isFree()) || (partinfo->min_size == -1)) { /*---just fill with the grey color (in fsspec!)... * but of course if this is a "true" partition (min_size == -1) * then fill with the right color---*/ paint.fillRect(8, 8, used_size, height()-16, partinfo->fsspec->color()); } else { /*---just fill with yellow in the sized used!---*/ paint.fillRect(8, 8, used_size, height()-16, Qt::yellow); } } /*--- draw a small border around if the partition has focus ---*/ if (Selected()) { QStyleOption opt; opt.initFrom(this); opt.state=QStyle::State_Active|QStyle::State_Enabled|QStyle::State_HasFocus; style()->drawPrimitive(QStyle::PE_FrameFocusRect, &opt, &paint, this); } /*---get the font metrics of the paint area---*/ QFontMetrics fm = paint.fontMetrics(); /*---create the showed label---*/ QString label; QString partname = partinfo->partname().mid(5); //remove the "/dev/" from the name /*---if it was not possible to get how the filesystem is filled...---*/ if (partinfo->min_size == -1) { label = QString("%1") .arg(partname); } else { /*---try to set the label with (device) GB---*/ QString partsize = MB2String(partinfo->mb_min_size()); label = QString("%1 (%2)") .arg(partname) .arg(partsize); /*---if the size of the label is too big just use the size!---*/ QSize sizeText = fm.size(Qt::TextSingleLine, label); if (sizeText.width() > width()-10) { /*---use the size in MByte or in GByte---*/ if (partinfo->mb_min_size() > 1024) { partsize.sprintf("%3.2fGB", partinfo->mb_min_size() / 1024); label = QString("(%1)") .arg(partsize); } else { partsize.sprintf("%3.2fMB", partinfo->mb_min_size()); label = QString("(%1)") .arg(partsize); } } } /*---get the size of the label---*/ QSize sizeText = fm.size(Qt::TextSingleLine, label); /*---if this is a primary or a logical partition draw label and pixmap---*/ if (partinfo->type != QTParted::extended) { if (sizeText.width() <= width()-10) { paint.setPen(QPen(Qt::black, 1)); QPoint pt; pt.setX((width()-sizeText.width())/2); //pt.setY((height()-sizeText.height())/2 + 10); pt.setY((height()-sizeText.height())); paint.drawText(pt, label); } if (partinfo->fsspec->pixmap().width() < (width()-12)) { paint.drawPixmap(3, 3, partinfo->fsspec->pixmap()); } } }
void RenderThemeQStyle::computeSizeBasedOnStyle(RenderStyle* renderStyle) const { QSize size(0, 0); const QFontMetrics fm(renderStyle->font().font()); QStyle* style = qStyle(); switch (renderStyle->appearance()) { case TextAreaPart: case SearchFieldPart: case TextFieldPart: { int padding = findFrameLineWidth(style); renderStyle->setPaddingLeft(Length(padding, Fixed)); renderStyle->setPaddingRight(Length(padding, Fixed)); renderStyle->setPaddingTop(Length(padding, Fixed)); renderStyle->setPaddingBottom(Length(padding, Fixed)); break; } default: break; } // If the width and height are both specified, then we have nothing to do. if (!renderStyle->width().isIntrinsicOrAuto() && !renderStyle->height().isAuto()) return; switch (renderStyle->appearance()) { case CheckboxPart: { QStyleOption styleOption; styleOption.state |= QStyle::State_Small; int checkBoxWidth = style->pixelMetric(QStyle::PM_IndicatorWidth, &styleOption); checkBoxWidth *= renderStyle->effectiveZoom(); size = QSize(checkBoxWidth, checkBoxWidth); break; } case RadioPart: { QStyleOption styleOption; styleOption.state |= QStyle::State_Small; int radioWidth = style->pixelMetric(QStyle::PM_ExclusiveIndicatorWidth, &styleOption); radioWidth *= renderStyle->effectiveZoom(); size = QSize(radioWidth, radioWidth); break; } case PushButtonPart: case ButtonPart: { QStyleOptionButton styleOption; styleOption.state |= QStyle::State_Small; QSize contentSize = fm.size(Qt::TextShowMnemonic, QString::fromLatin1("X")); QSize pushButtonSize = style->sizeFromContents(QStyle::CT_PushButton, &styleOption, contentSize, 0); styleOption.rect = QRect(0, 0, pushButtonSize.width(), pushButtonSize.height()); QRect layoutRect = style->subElementRect(QStyle::SE_PushButtonLayoutItem, &styleOption, 0); // If the style supports layout rects we use that, and compensate accordingly // in paintButton() below. if (!layoutRect.isNull()) size.setHeight(layoutRect.height()); else size.setHeight(pushButtonSize.height()); break; } case MenulistPart: { QStyleOptionComboBox styleOption; styleOption.state |= QStyle::State_Small; int contentHeight = qMax(fm.lineSpacing(), 14) + 2; QSize menuListSize = style->sizeFromContents(QStyle::CT_ComboBox, &styleOption, QSize(0, contentHeight), 0); size.setHeight(menuListSize.height()); break; } default: break; } // FIXME: Check is flawed, since it doesn't take min-width/max-width into account. if (renderStyle->width().isIntrinsicOrAuto() && size.width() > 0) renderStyle->setMinWidth(Length(size.width(), Fixed)); if (renderStyle->height().isAuto() && size.height() > 0) renderStyle->setMinHeight(Length(size.height(), Fixed)); }
static void computeSizeBasedOnStyle(RenderStyle* renderStyle) { // If the width and height are both specified, then we have nothing to do. if (!renderStyle->width().isIntrinsicOrAuto() && !renderStyle->height().isAuto()) return; QSize size(0, 0); const QFontMetrics fm(renderStyle->font().font()); QStyle* applicationStyle = QApplication::style(); switch (renderStyle->appearance()) { case CheckboxAppearance: { QStyleOption styleOption; styleOption.state |= QStyle::State_Small; int checkBoxWidth = applicationStyle->pixelMetric(QStyle::PM_IndicatorWidth, &styleOption); size = QSize(checkBoxWidth, checkBoxWidth); break; } case RadioAppearance: { QStyleOption styleOption; styleOption.state |= QStyle::State_Small; int radioWidth = applicationStyle->pixelMetric(QStyle::PM_ExclusiveIndicatorWidth, &styleOption); size = QSize(radioWidth, radioWidth); break; } case PushButtonAppearance: case ButtonAppearance: { QStyleOptionButton styleOption; styleOption.state |= QStyle::State_Small; QSize contentSize = fm.size(Qt::TextShowMnemonic, QString::fromLatin1("X")); QSize pushButtonSize = applicationStyle->sizeFromContents(QStyle::CT_PushButton, &styleOption, contentSize, 0); styleOption.rect = QRect(0, 0, pushButtonSize.width(), pushButtonSize.height()); QRect layoutRect = applicationStyle->subElementRect(QStyle::SE_PushButtonLayoutItem, &styleOption, 0); // If the style supports layout rects we use that, and // compensate accordingly in paintButton() below. if (!layoutRect.isNull()) { size.setHeight(layoutRect.height()); } else { size.setHeight(pushButtonSize.height()); } break; } case MenulistAppearance: { QStyleOptionComboBox styleOption; styleOption.state |= QStyle::State_Small; int contentHeight = qMax(fm.lineSpacing(), 14) + 2; QSize menuListSize = applicationStyle->sizeFromContents(QStyle::CT_ComboBox, &styleOption, QSize(0, contentHeight), 0); size.setHeight(menuListSize.height()); break; } case TextFieldAppearance: { const int verticalMargin = 1; const int horizontalMargin = 2; int h = qMax(fm.lineSpacing(), 14) + 2*verticalMargin; int w = fm.width(QLatin1Char('x')) * 17 + 2*horizontalMargin; QStyleOptionFrameV2 opt; opt.lineWidth = applicationStyle->pixelMetric(QStyle::PM_DefaultFrameWidth, &opt, 0); QSize sz = applicationStyle->sizeFromContents(QStyle::CT_LineEdit, &opt, QSize(w, h).expandedTo(QApplication::globalStrut()), 0); size.setHeight(sz.height()); break; } default: break; } // FIXME: Check is flawed, since it doesn't take min-width/max-width into account. if (renderStyle->width().isIntrinsicOrAuto() && size.width() > 0) renderStyle->setWidth(Length(size.width(), Fixed)); if (renderStyle->height().isAuto() && size.height() > 0) renderStyle->setHeight(Length(size.height(), Fixed)); }
//---------------------------------------------------------------- // shortenTextToFit // bool shortenTextToFit(QPainter & painter, const QRect & bbox, int textAlignment, const QString & text, QString & textLeft, QString & textRight) { static const QString ellipsis("..."); // in case style sheet is used, get fontmetrics from painter: QFontMetrics fm = painter.fontMetrics(); const int bboxWidth = bbox.width(); textLeft.clear(); textRight.clear(); QSize sz = fm.size(Qt::TextSingleLine, text); int textWidth = sz.width(); if (textWidth <= bboxWidth || bboxWidth <= 0) { // text fits, nothing to do: if (textAlignment & Qt::AlignLeft) { textLeft = text; } else { textRight = text; } return false; } // scale back the estimate to avoid cutting out too much of text, // because not all characters have the same width: const double stepScale = 0.78; const int textLen = text.size(); int numToRemove = 0; int currLen = textLen - numToRemove; int aLen = currLen / 2; int bLen = currLen - aLen; while (currLen > 1) { // estimate (conservatively) how much text to remove: double excess = double(textWidth) / double(bboxWidth) - 1.0; if (excess <= 0.0) { break; } double excessLen = std::max<double>(1.0, stepScale * double(currLen) * excess / (excess + 1.0)); numToRemove += int(excessLen); currLen = textLen - numToRemove; aLen = currLen / 2; bLen = currLen - aLen; QString tmp = text.left(aLen) + ellipsis + text.right(bLen); sz = fm.size(Qt::TextSingleLine, tmp); textWidth = sz.width(); } if (currLen < 2) { // too short, give up: aLen = 0; bLen = 0; } if (textAlignment & Qt::AlignLeft) { textLeft = text.left(aLen) + ellipsis; textRight = text.right(bLen); } else { textLeft = text.left(aLen); textRight = ellipsis + text.right(bLen); } return true; }
QSize RibbonButton::sizeHint() const { ensurePolished(); int w = 0, h = 0; QStyleOptionToolButton opt; initStyleOption(&opt); QString textButton = text(); if (!textButton.isEmpty() && (bool)style()->styleHint((QStyle::StyleHint)RibbonStyle::SH_RibbonItemUpperCase, 0, this)) textButton = textButton.toUpper(); QFontMetrics fm = fontMetrics(); if (opt.toolButtonStyle != Qt::ToolButtonTextOnly) { QSize icon = opt.iconSize; QAction* action = defaultAction(); if (action && !action->icon().isNull()) icon = action->icon().actualSize(QSize(32,32)); w = icon.width(); h = icon.height(); } bool indicatorCenter = false; QToolButton::ToolButtonPopupMode mode = QToolButton::popupMode(); if (opt.toolButtonStyle != Qt::ToolButtonIconOnly) { if (opt.toolButtonStyle == Qt::ToolButtonTextUnderIcon) { QString strFirstRow, strSecondRow; CommonStyle::splitString(textButton, strFirstRow, strSecondRow); QSize textFirstSize; if (!strFirstRow.isEmpty()) textFirstSize = fm.size(Qt::TextShowMnemonic, strFirstRow); if (!strSecondRow.isEmpty()) { QSize textSecondSize = fm.size(Qt::TextShowMnemonic, strSecondRow); textFirstSize.setWidth(qMax(textFirstSize.width(), textSecondSize.width())); } indicatorCenter = strSecondRow.isEmpty() && opt.features & QStyleOptionToolButton::HasMenu; h = style()->pixelMetric((QStyle::PixelMetric)RibbonStyle::PM_RibbonHeightGroup, 0, this); // if the text is more than icon if (textFirstSize.width() > w) w = textFirstSize.width(); // add pixel w += mode == MenuButtonPopup || mode == QToolButton::InstantPopup ? 4 : 10; } else { QSize textSize = fm.size(Qt::TextShowMnemonic, textButton); textSize.setWidth(textSize.width() + fm.width(QLatin1Char(' '))*2); h = style()->pixelMetric((QStyle::PixelMetric)RibbonStyle::PM_RibbonHeightGroup, 0, 0)/3; if (opt.toolButtonStyle == Qt::ToolButtonTextBesideIcon) { w += 3 + textSize.width(); if (mode != InstantPopup) w += 3; if (textSize.height() > h) h = textSize.height(); } else w = textSize.width() + 3; } } else { h = style()->pixelMetric((QStyle::PixelMetric)RibbonStyle::PM_RibbonHeightGroup, 0, 0)/3; w = h; } opt.rect.setSize(QSize(w, h)); // PM_MenuButtonIndicator depends on the height if ((mode== MenuButtonPopup || mode == QToolButton::InstantPopup) && !indicatorCenter) w += style()->pixelMetric(QStyle::PM_MenuButtonIndicator, &opt, this); return QSize(w, h).expandedTo(QApplication::globalStrut()); }