//----------------------------------------------------------------------------- // Function: RibbonGroup::RibbonGroup() //----------------------------------------------------------------------------- RibbonGroup::RibbonGroup(QString const& title, Ribbon* parent) : QToolBar(parent), title_(title) { const int BOTTOM_MARGIN = 15; const int TOP_MARGIN = 10; setIconSize(QSize (32, 32)); setContentsMargins(0, TOP_MARGIN, 0, BOTTOM_MARGIN); layout()->setContentsMargins(0, TOP_MARGIN, 0, BOTTOM_MARGIN); QString style = "QToolBar { margin-top: %1px; margin-left: %1px; margin-right: %1px; margin-bottom: %1px;}"; setStyleSheet(style.arg(QString::number(HMARGIN))); QFontMetrics metrics(font()); setMinimumWidth(metrics.width(title_) + TITLE_MARGIN); }
QRect QsciAccessibleScintillaBase::characterRect(int offset) const { QsciScintillaBase *sb = sciWidget(); int position = offsetAsPosition(sb, offset); int x_vport = sb->SendScintilla(QsciScintillaBase::SCI_POINTXFROMPOSITION, position); int y_vport = sb->SendScintilla(QsciScintillaBase::SCI_POINTYFROMPOSITION, position); const QString ch = text(offset, offset + 1); // Get the character's font metrics. int style = sb->SendScintilla(QsciScintillaBase::SCI_GETSTYLEAT, position); QFontMetrics metrics(fontForStyle(style)); QRect rect(x_vport, y_vport, metrics.width(ch), metrics.height()); rect.moveTo(sb->viewport()->mapToGlobal(rect.topLeft())); return rect; }
/*! \reimp */ QSize QGroupBox::minimumSizeHint() const { Q_D(const QGroupBox); QStyleOptionGroupBox option; initStyleOption(&option); QFontMetrics metrics(fontMetrics()); int baseWidth = metrics.width(d->title) + metrics.width(QLatin1Char(' ')); int baseHeight = metrics.height(); if (d->checkable) { baseWidth += style()->pixelMetric(QStyle::PM_IndicatorWidth); baseWidth += style()->pixelMetric(QStyle::PM_CheckBoxLabelSpacing); baseHeight = qMax(baseHeight, style()->pixelMetric(QStyle::PM_IndicatorHeight)); } QSize size = style()->sizeFromContents(QStyle::CT_GroupBox, &option, QSize(baseWidth, baseHeight), this); return size.expandedTo(QWidget::minimumSizeHint()); }
// ------------------------------------------------------- void RFedd2P::createSymbol() { QFontMetrics metrics(QucsSettings.font); // get size of text int fHeight = metrics.lineSpacing(); int w, i; QString tmp; // draw symbol #define HALFWIDTH 17 int h = 15; Lines.append(new Line(-HALFWIDTH, -h, HALFWIDTH, -h,QPen(Qt::darkBlue,2))); Lines.append(new Line( HALFWIDTH, -h, HALFWIDTH, h,QPen(Qt::darkBlue,2))); Lines.append(new Line(-HALFWIDTH, h, HALFWIDTH, h,QPen(Qt::darkBlue,2))); Lines.append(new Line(-HALFWIDTH, -h,-HALFWIDTH, h,QPen(Qt::darkBlue,2))); i = fHeight/2; tmp = Props.at(0)->Value; w = metrics.width(tmp); Texts.append(new Text(w/-2, -i, tmp)); i = 0; int y = 15-h; Lines.append(new Line(-30, y,-HALFWIDTH, y,QPen(Qt::darkBlue,2))); Ports.append(new Port(-30, y)); tmp = QString::number(i+1); w = metrics.width(tmp); Texts.append(new Text(-20-w, y-fHeight-2, tmp)); i++; Lines.append(new Line(HALFWIDTH, y, 30, y,QPen(Qt::darkBlue,2))); Ports.append(new Port( 30, y)); tmp = QString::number(i+1); Texts.append(new Text( 20, y-fHeight-2, tmp)); y += 60; i++; x1 = -30; y1 = -h-2; x2 = 30; y2 = h+2; tx = x1+4; ty = y1 - fHeight - 4; }
void Widget::paintEvent(QPaintEvent *event) { QPainter painter(this); painter.setPen(QColor("#d4d4d4")); int width = size().width(); Burning *burn = (Burning*) m_parent; int cur_width = burn->getCurrentWidth(); int step = (int) qRound(width/10.0); int till = (int) ((width / 750.0) * cur_width); int full = (int) ((width / 750.0) * 700 ); if (cur_width >= 700) { painter.setPen(QColor(255,255,184)); painter.setBrush(QColor(255,255,184)); painter.drawRect(0,0,full,30); painter.setPen(QColor(255, 175, 175)); painter.setBrush(QColor(255, 175, 175)); painter.drawRect(full, 0, till-full, 30); } else { painter.setPen(QColor(255,255,184)); painter.setBrush(QColor(255,255,184)); painter.drawRect(0,0,till,30); } painter.setPen(QColor(90, 80, 60)); for(int i=1; i <= asize; i++) { painter.drawLine(i*step, 0, i*step, 6); QFont newFont = font(); newFont.setPointSize(7); setFont(newFont); QFontMetrics metrics(font()); int w = metrics.width(num[i-1]); painter.drawText(i*step - w/2, 19, num[i-1]); } QFrame::paintEvent(event); }
void GraphView::drawCurve(AnimationCurve* pCurve) { QRect pixmapSize(geometry()); pixmapSize.adjust(0, 0, 2, 2); // for some reason, we need to padd this to get the full size... m_backBuffer = QPixmap(pixmapSize.size()); m_backBuffer.fill(this, 0, 0); QPainter painter(&m_backBuffer); painter.initFrom(this); painter.setPen(Qt::black); painter.setBrush(QColor(0, 0, 0)); painter.drawRect(geometry()); // draw curve std::vector<ControlPoint> aControlPoints; pCurve->getMainControlPoints(aControlPoints); painter.setPen(Qt::white); painter.setBrush(QColor(255, 255, 255)); std::vector<ControlPoint>::const_iterator itCP = aControlPoints.begin(); for (; itCP != aControlPoints.end(); ++itCP) { const ControlPoint& cp = *itCP; painter.drawEllipse(cp.x, cp.y, 4, 4); } // draw values... QFont newFont = font(); newFont.setPointSize(9); setFont(newFont); QFontMetrics metrics(font()); update(); }
void ExtDatePicker::setFontSize(int s) { QWidget *buttons[]= { // yearBackward, // monthBackward, selectMonth, selectYear, // monthForward, // yearForward }; const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]); int count; QFont font; QRect r; // ----- fontsize=s; for(count=0; count<NoOfButtons; ++count) { font=buttons[count]->font(); font.setPointSize(s); buttons[count]->setFont(font); } QFontMetrics metrics(selectMonth->fontMetrics()); for (int i = 1; ; ++i) { QString str = d->calendar->monthName(i, d->calendar->year(table->getDate()), false); if (str.isNull()) break; r=metrics.boundingRect(str); maxMonthRect.setWidth(QMAX(r.width(), maxMonthRect.width())); maxMonthRect.setHeight(QMAX(r.height(), maxMonthRect.height())); } QSize metricBound = style().sizeFromContents(QStyle::CT_ToolButton, selectMonth, maxMonthRect); selectMonth->setMinimumSize(metricBound); table->setFontSize(s); }
void memorywin_info::recompute_children() { // compute a client rect RECT bounds; bounds.top = bounds.left = 0; bounds.right = m_views[0]->prefwidth() + (2 * EDGE_WIDTH); bounds.bottom = 200; AdjustWindowRectEx(&bounds, DEBUG_WINDOW_STYLE, FALSE, DEBUG_WINDOW_STYLE_EX); // clamp the min/max size set_maxwidth(bounds.right - bounds.left); // get the parent's dimensions RECT parent; GetClientRect(window(), &parent); // edit box gets half of the width RECT editrect; editrect.top = parent.top + EDGE_WIDTH; editrect.bottom = editrect.top + metrics().debug_font_height() + 4; editrect.left = parent.left + EDGE_WIDTH; editrect.right = parent.left + ((parent.right - parent.left) / 2) - EDGE_WIDTH; // combo box gets the other half of the width RECT comborect; comborect.top = editrect.top; comborect.bottom = editrect.bottom; comborect.left = editrect.right + (2 * EDGE_WIDTH); comborect.right = parent.right - EDGE_WIDTH; // memory view gets the rest RECT memrect; memrect.top = editrect.bottom + (2 * EDGE_WIDTH); memrect.bottom = parent.bottom - EDGE_WIDTH; memrect.left = parent.left + EDGE_WIDTH; memrect.right = parent.right - EDGE_WIDTH; // set the bounds of things m_views[0]->set_bounds(memrect); set_editwnd_bounds(editrect); smart_set_window_bounds(m_combownd, window(), comborect); }
void LLVMState::compile(STATE, GCToken gct, CompiledCode* code, CallFrame* call_frame, Class* receiver_class, BlockEnvironment* block_env, bool is_block) { if(!enabled_) return; // TODO: Fix compile policy checks if(!code->keywords()->nil_p()) { metrics().m.jit_metrics.methods_failed++; return; } // In case the method hasn't been internalized yet if(!code->machine_code()) { code->internalize(state, gct, call_frame); } JITCompileRequest* req = JITCompileRequest::create(state, code, receiver_class, 0, block_env, is_block); wait_mutex.lock(); req->set_waiter(&wait_cond); add(state, req); state->set_call_frame(call_frame); { GCIndependent guard(state, 0); wait_cond.wait(wait_mutex); } wait_mutex.unlock(); state->set_call_frame(0); if(state->shared().config.jit_show_compiling) { llvm::outs() << "[[[ JIT compiled " << enclosure_name(code) << "#" << symbol_debug_str(code->name()) << (req->is_block() ? " (block) " : " (method) ") << " ]]]\n"; } }
/* *Function: Print *Inputs:none *Outputs:none *Returns:none */ void GraphPaneData::Print() { IT_IT("GraphPaneData::Print"); QPrinter prt; prt.setDocName(tr("Pen Trace")); prt.setCreator(tr(SYSTEM_NAME)); prt.setOrientation(QPrinter::Landscape); prt.setOutputFileName("~out.ps"); prt.setOutputToFile(false); // if(prt.setup(this)) { // // Handle the case of no printer being selected // if(!prt.printerName().isEmpty()) { QPainter p; p.begin(&prt); QPaintDeviceMetrics metrics(p.device()); // int dpix = metrics.logicalDpiX() ; // inch border int dpiy = metrics.logicalDpiY() ; // QRect body(dpix, dpiy, metrics.width() - dpix*6, metrics.height() - dpiy*2); TheGraph.Plot(p,body,Qt::white); // QFont font("times", 8); p.setFont(font); // p.drawText( body.left() ,body.top(), Title); // p.end(); // } else { QMessageBox::information(this,tr("Print Graph Error"),tr("No Printer Selected!")); }; }; };
QRectF ChannelGraphItem::boundingRect() const { if (cachedRect.isNull()) { QFontMetrics metrics(scene()->font()); int width = metrics.width(name); // we only use upper case characters and digits, so everything is above the baseline int height = metrics.ascent(); // make it at least quadratic if (width < height) width = height; // shift by 0.5 to have sharp lines cachedRect.setLeft(0.5); cachedRect.setTop(0.5); cachedRect.setWidth(width + 2 * margin); cachedRect.setHeight(height + 2 * margin); } return cachedRect; }
// ------------------------------------------------------- // Size of component text. int Component::textSize(int& _dx, int& _dy) { QFontMetrics metrics(QucsSettings.font); // get size of text int tmp, count=0; _dx = _dy = 0; if(showName) { _dx = metrics.width(Name); _dy = metrics.height(); count++; } for(Property *pp = Props.first(); pp != 0; pp = Props.next()) if(pp->display) { // get width of text tmp = metrics.width(pp->Name+"="+pp->Value); if(tmp > _dx) _dx = tmp; _dy += metrics.height(); count++; } return count; }
QString getBlanks(QTextCursor cursor,WERD_RES *word,float dpiCoeffX) { QString blanksString(" "); int blanks = word->word->space(); if (blanks > 1) { QFontMetricsF metrics(cursor.charFormat().font()); float wordPos = dpiCoeffX*(word->word->bounding_box().left()) - cursor.block().blockFormat().leftMargin(); QString aux = cursor.block().text(); float currentPos = metrics.width(aux); blanks = 0; while (currentPos < wordPos) { aux = aux.append(" "); currentPos = metrics.width(aux); blanks++; } blanksString = blanksString.repeated(blanks); } return blanksString; }
void GraphicEQFilterGUIItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { painter->setBrush(Qt::white); if (isSelected()) painter->setBrush(QColor(38, 147, 255)); painter->drawPath(shape()); if (index < 99) { if (isSelected()) painter->setPen(Qt::white); QFont font; font.setPixelSize(9); font.setLetterSpacing(QFont::AbsoluteSpacing, -1); QFontMetrics metrics(font); painter->setFont(font); QString text = QString::number(index + 1); painter->drawText(-metrics.width(text) / 2, metrics.boundingRect('0').height() / 2, text); } }
NotifyUI *NotifyUI::setNotifyText(QString &txt) { //#ifdef InheritQWidget text = txt; QFont font(cns("微软雅黑")); font.setPixelSize(fontsize + 2); QFontMetrics metrics(font); showsize = metrics.size(Qt::TextExpandTabs , txt); resize(showsize); repaint(); //#else // QFont font(cns("微软雅黑")); // font.setPixelSize(fontsize + 2); // setFont(font); // setText(txt); //#endif QPoint p = qApp->desktop()->rect().center(); move(p.x() - this->width() / 2, p.y() + 200); return this; }
// Called just before a plot is going to be displayed. void qt_graphics() { ensureOptionsCreated(); qt->out << GEDesactivate; qt_flushOutBuffer(); qt_connectToServer(); // Set text encoding if (!(qt->codec = qt_encodingToCodec(encoding))) qt->codec = QTextCodec::codecForLocale(); // Set font qt->currentFontSize = qt_optionFontSize; qt->currentFontName = qt_option->FontName; // Set plot metrics QFontMetrics metrics(QFont(qt->currentFontName, qt->currentFontSize)); term->v_char = qt_oversampling * (metrics.ascent() + metrics.descent()); term->h_char = qt_oversampling * metrics.width("0123456789")/10.; term->v_tic = (unsigned int) (term->v_char/2.5); term->h_tic = (unsigned int) (term->v_char/2.5); if (qt_setSize) { term->xmax = qt_oversampling*qt_setWidth; term->ymax = qt_oversampling*qt_setHeight; qt_setSize = false; } // Initialize window qt->out << GESetCurrentWindow << qt_optionWindowId; qt->out << GEInitWindow; qt->out << GEActivate; qt->out << GETitle << qt_option->Title; qt->out << GESetCtrl << qt_optionCtrl; qt->out << GESetWidgetSize << QSize(term->xmax, term->ymax)/qt_oversampling; // Initialize the scene qt->out << GESetSceneSize << QSize(term->xmax, term->ymax)/qt_oversampling; qt->out << GEClear; // Initialize the font qt->out << GESetFont << qt->currentFontName << qt->currentFontSize; }
QSize GrepOutputDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const { const GrepOutputModel *model = dynamic_cast<const GrepOutputModel *>(index.model()); const GrepOutputItem *item = model ? dynamic_cast<const GrepOutputItem *>(model->itemFromIndex(index)) : nullptr; QSize ret = QStyledItemDelegate::sizeHint(option, index); //take account of additional width required for highlighting (bold text) //and line numbers. These are not included in the default Qt size calculation. if(item && item->isText()) { QFont font = option.font; QFontMetrics metrics(font); font.setBold(true); QFontMetrics bMetrics(font); const KTextEditor::Range rng = item->change()->m_range; int width = metrics.width(item->text().left(rng.start().column())) + metrics.width(item->text().right(item->text().length() - rng.end().column())) + bMetrics.width(item->text().mid(rng.start().column(), rng.end().column() - rng.start().column())) + option.fontMetrics.width(i18n("Line %1: ",item->lineNumber())) + std::max(option.decorationSize.width(), 0); ret.setWidth(width); }else{ // This is only used for titles, so not very performance critical QString text; if(item) text = item->text(); else text = index.data().toString(); QTextDocument doc; doc.setDocumentMargin(0); doc.setHtml(text); QSize newSize = doc.size().toSize(); if(newSize.height() > ret.height()) ret.setHeight(newSize.height()); } return ret; }
// OpenGL painting code goes here void GLWidget::paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear screen and depth buffer // Draw cube glLoadIdentity(); // Reset current modelview matrix glTranslatef(0.0f, 0.0f, z); // Move into the screen glRotatef(xrot, 1.0f, 0.0f, 0.0f); // Rotate on X-axis glRotatef(yrot, 0.0f, 1.0f, 0.0f); // Rotate on Y-axis glBindTexture(GL_TEXTURE_2D, texture[filter]); drawCube(); xrot += xspeed; // X-axis rotation yrot += yspeed; // Y-axis rotation // Show message when an enabled OpenGL feature has changed glLoadIdentity(); if ((lightChanged || filterChanged) && changeAmount > 0) { QString str; if (filterChanged) str = QString("Now filtering using ") + filterName[filter]; else // lightChanged str = QString("Lighting is now ") + (glIsEnabled(GL_LIGHTING) ? "on" : "off"); QFont font; QFontMetrics metrics(font); font.setPixelSize(20); font.setBold(true); if (changeAmount < 100) glColor4f(1.0, 1.0, 1.0, static_cast<GLfloat>(changeAmount) / 100); else glColor3f(1.0, 1.0, 1.0); this->renderText(10, 10 + metrics.height(), str, font); changeAmount--; } // Framerate control int delay = time.msecsTo(QTime::currentTime()); if (delay == 0) delay = 1; time = QTime::currentTime(); timer->start(qMax(0, 20 - delay)); }
void TimeTooltip::adjustPosition() { if( mDisplayedText.isEmpty() ) { resize( 0, 0 ); return; } // Get the bounding box required to print the text and add some padding QFontMetrics metrics( mFont ); QRect textbox = metrics.boundingRect( mDisplayedText ); textbox.adjust( -2, -2, 2, 2 ); textbox.moveTo( 0, 0 ); // Resize the widget to fit our needs QSize size( textbox.width() + 1, textbox.height() + TIP_HEIGHT + 1 ); // The desired label position is just above the target QPoint position( mTarget.x() - size.width() / 2, mTarget.y() - size.height() + TIP_HEIGHT / 2 ); // Keep the tooltip on the same screen if possible QRect screen = QApplication::desktop()->screenGeometry( mTarget ); position.setX( qMax( screen.left(), qMin( position.x(), screen.left() + screen.width() - size.width() ) ) ); position.setY( qMax( screen.top(), qMin( position.y(), screen.top() + screen.height() - size.height() ) ) ); move( position ); int tipX = mTarget.x() - position.x(); if( mBox != textbox || mTipX != tipX ) { mBox = textbox; mTipX = tipX; resize( size ); buildPath(); setMask( mMask ); } }
void ScaledFontDWrite::GetGlyphDesignMetrics(const uint16_t* aGlyphs, uint32_t aNumGlyphs, GlyphMetrics* aGlyphMetrics) { DWRITE_FONT_METRICS fontMetrics; mFontFace->GetMetrics(&fontMetrics); vector<DWRITE_GLYPH_METRICS> metrics(aNumGlyphs); mFontFace->GetDesignGlyphMetrics(aGlyphs, aNumGlyphs, &metrics.front()); Float designUnitCorrection = 1.f / fontMetrics.designUnitsPerEm; for (uint32_t i = 0; i < aNumGlyphs; i++) { aGlyphMetrics[i].mXBearing = metrics[i].leftSideBearing * designUnitCorrection * mSize; aGlyphMetrics[i].mXAdvance = metrics[i].advanceWidth * designUnitCorrection * mSize; aGlyphMetrics[i].mYBearing = metrics[i].topSideBearing * designUnitCorrection * mSize; aGlyphMetrics[i].mYAdvance = metrics[i].advanceHeight * designUnitCorrection * mSize; aGlyphMetrics[i].mWidth = (metrics[i].advanceHeight - metrics[i].topSideBearing - metrics[i].bottomSideBearing) * designUnitCorrection * mSize; aGlyphMetrics[i].mHeight = (metrics[i].topSideBearing - metrics[i].verticalOriginY) * designUnitCorrection * mSize; } }
void SideBarWidget::paintEvent( QPaintEvent * ) { QPainter p( this ); p.fillRect( 0, 0, width(), 27, palette().highlight().color() ); QFont f = p.font(); f.setBold( true ); f.setUnderline( true ); f.setPointSize( f.pointSize() + 2 ); p.setFont( f ); p.setPen( palette().highlightedText().color() ); const int tx = m_icon.width()+4; QFontMetrics metrics( f ); const int ty = metrics.ascent(); p.drawText( tx, ty, m_title ); p.drawPixmap( 2, 2, m_icon.transformed( QTransform().rotate( -90 ) ) ); }
void LinearChart::updateRects() { if ( this->model() == 0 ) { return; } this->defineRects(); QFontMetrics metrics( this->font() ); this->HackedCalculateBounds(); myOrigin.setX( metrics.width( QString::number(-1 * myOrder) ) + metrics.width("0") * myNbDigits + myMarginX ); myValuesRect = QRect( myChartRect ); myValuesRect.setX( myOrigin.x() ); myX = qreal( myValuesRect.width() ) / ( this->model()->rowCount() ); this->setAlphaBeta(); qreal delta = myValuesRect.bottom() - ( myOrigin.y() + myMinBottomMargin ); if ( delta < 0 ) { myValuesRect.setHeight( myValuesRect.height() + delta ); this->setAlphaBeta(); } myTitleRect.moveTo( myChartRect.bottomLeft() ); myTitleRect.translate( ( myChartRect.width() - myTitleRect.width())/2, 20 ); }
editwin_info::editwin_info(debugger_windows_interface &debugger, bool is_main_console, LPCSTR title, WNDPROC handler) : debugwin_info(debugger, is_main_console, title, handler), m_editwnd(nullptr), m_edit_defstr(), m_original_editproc(nullptr), m_history_count(0), m_last_history(0) { if (window() == nullptr) return; // create an edit box and override its key handling m_editwnd = CreateWindowEx(EDIT_BOX_STYLE_EX, TEXT("EDIT"), nullptr, EDIT_BOX_STYLE, 0, 0, 100, 100, window(), nullptr, GetModuleHandleUni(), nullptr); m_original_editproc = (WNDPROC)(FPTR)GetWindowLongPtr(m_editwnd, GWLP_WNDPROC); SetWindowLongPtr(m_editwnd, GWLP_USERDATA, (LONG_PTR)this); SetWindowLongPtr(m_editwnd, GWLP_WNDPROC, (LONG_PTR)&editwin_info::static_edit_proc); SendMessage(m_editwnd, WM_SETFONT, (WPARAM)metrics().debug_font(), (LPARAM)FALSE); SendMessage(m_editwnd, EM_LIMITTEXT, (WPARAM)MAX_EDIT_STRING, (LPARAM)0); set_editwnd_text(""); }
void AsyncPanZoomController::ScaleWithFocus(float aScale, const nsIntPoint& aFocus) { FrameMetrics metrics(mFrameMetrics); // Don't set the scale to the inputted value, but rather multiply it in. float scaleFactor = aScale / metrics.mResolution.width; metrics.mResolution.width = metrics.mResolution.height = aScale; // Force a recalculation of the page rect based on the new zoom and the // current CSS page rect (which is unchanged since it's not affected by zoom). SetPageRect(mFrameMetrics.mCSSContentRect); nsIntPoint scrollOffset = metrics.mViewportScrollOffset; scrollOffset.x += aFocus.x * (scaleFactor - 1.0f); scrollOffset.y += aFocus.y * (scaleFactor - 1.0f); metrics.mViewportScrollOffset = scrollOffset; mFrameMetrics = metrics; }
void BalloonTip::createRects() { QFont font = this->font(); font.setBold( true ); font.setPixelSize( 12 ); QFontMetrics metrics( font ); QRect rect = metrics.boundingRect( QRect( 10, 10, 500, 500 ), Qt::TextSingleLine, my_title ); if ( rect.width() < 100 ) { rect.setWidth( 100 ); } font.setPixelSize( 12 ); font.setBold( false ); setFont( font ); metrics = QFontMetrics( font ); my_textRect = metrics.boundingRect( QRect( 10, 30, rect.width() + 90, 500), Qt::TextWordWrap, my_text ); if ( my_textRect.width() < rect.width() ) { my_textRect.setWidth( rect.width() + 90 ); } my_popupRect = QRect( 0, 0, my_textRect.width() + 20, my_textRect.height() + 40 ); }
void QgsFieldExpressionWidget::currentFieldChanged() { updateLineEditStyle(); bool isExpression, isValid; QString fieldName = currentField( &isExpression, &isValid ); // display tooltip if widget is shorter than expression QFontMetrics metrics( mCombo->lineEdit()->font() ); if ( metrics.width( fieldName ) > mCombo->lineEdit()->width() ) { mCombo->setToolTip( fieldName ); } else { mCombo->setToolTip( "" ); } emit fieldChanged( fieldName ); emit fieldChanged( fieldName, isValid ); }
void SwitchLayout::calculateKeyboardSize() { m_MaxTextWidth = 0; // set font-size to 14px, so that we can calculate the max width of all keyboardlayout texts QLabel *text = new QLabel; m_f = text->font(); m_f.setPixelSize(14); text->setFont(m_f); int length = m_KeyboardList.length(); // give the value of m_KeyboradLayoutHeight m_KeyboradLayoutHeight = (length > 5 ? KEYBOARD_ITEM_HEIGHT * 5 : KEYBOARD_ITEM_HEIGHT * length); // give the value of m_MaxTextWidth QFontMetrics metrics(text->font()); for (int i = 0; i < length; i++) { text->setText(m_LayoutInterface->GetLayoutDesc(m_KeyboardList[i])); int textWidth = metrics.boundingRect(text->text()).width(); m_MaxTextWidth = qMax(MinLayoutWindowWidth, qMax(textWidth, m_MaxTextWidth)); } }
void EllipsizedLabel::paintEvent(QPaintEvent *) { FontMetrics metrics(font()); QRect r = contentsRect(); int w = getTextWidth(); if(w != lastWidth) { lastWidth = w; ellipsizedText = metrics.ellipsizedText(originalText, w); } QStyleOption opt; opt.initFrom(this); QPainter painter(this); drawFrame(&painter); style()->drawItemText(&painter, r, getAlignment(), opt.palette, isEnabled(), ellipsizedText, foregroundRole()); }
void ApplicationWindow::print() { printer->setFullPage( TRUE ); if ( printer->setup(this) ) { // printer dialog statusBar()->message( "Printing..." ); QPainter p; if( !p.begin( printer ) ) { // paint on printer statusBar()->message( "Printing aborted", 2000 ); return; } QPaintDeviceMetrics metrics( p.device() ); int dpiy = metrics.logicalDpiY(); int margin = (int) ( (2/2.54)*dpiy ); // 2 cm margins QRect view( margin, margin, metrics.width() - 2*margin, metrics.height() - 2*margin ); QSimpleRichText richText( QStyleSheet::convertFromPlainText(e->text()), QFont(), e->context(), e->styleSheet(), e->mimeSourceFactory(), view.height() ); richText.setWidth( &p, view.width() ); int page = 1; do { richText.draw( &p, margin, margin, view, colorGroup() ); view.moveBy( 0, view.height() ); p.translate( 0 , -view.height() ); p.drawText( view.right() - p.fontMetrics().width( QString::number( page ) ), view.bottom() + p.fontMetrics().ascent() + 5, QString::number( page ) ); if ( view.top() - margin >= richText.height() ) break; printer->newPage(); page++; } while (TRUE); statusBar()->message( "Printing completed", 2000 ); } else { statusBar()->message( "Printing aborted", 2000 ); } }
void TextEdit::filePrint() { if ( !currentEditor() ) return; #ifndef QT_NO_PRINTER QPrinter printer( QPrinter::HighResolution ); printer.setFullPage(TRUE); if ( printer.setup( this ) ) { QPainter p( &printer ); // Check that there is a valid device to print to. if ( !p.device() ) return; QPaintDeviceMetrics metrics( p.device() ); int dpiy = metrics.logicalDpiY(); int margin = (int) ( (2/2.54)*dpiy ); // 2 cm margins QRect view( margin, margin, metrics.width() - 2*margin, metrics.height() - 2*margin ); QFont font( currentEditor()->QWidget::font() ); font.setPointSize( 10 ); // we define 10pt to be a nice base size for printing QSimpleRichText richText( currentEditor()->text(), font, currentEditor()->context(), currentEditor()->styleSheet(), currentEditor()->mimeSourceFactory(), view.height() ); richText.setWidth( &p, view.width() ); int page = 1; do { richText.draw( &p, margin, margin, view, colorGroup() ); view.moveBy( 0, view.height() ); p.translate( 0 , -view.height() ); p.setFont( font ); p.drawText( view.right() - p.fontMetrics().width( QString::number( page ) ), view.bottom() + p.fontMetrics().ascent() + 5, QString::number( page ) ); if ( view.top() - margin >= richText.height() ) break; printer.newPage(); page++; } while (TRUE); } #endif }