// Maps window coordinates to screen coordinates QRect SceneXrender::Window::mapToScreen(int mask, const WindowPaintData &data, const QRect &rect) const { QRect r = rect; if (mask & PAINT_WINDOW_TRANSFORMED) { // Apply the window transformation r.moveTo(r.x() * data.xScale() + data.xTranslation(), r.y() * data.yScale() + data.yTranslation()); r.setWidth(r.width() * data.xScale()); r.setHeight(r.height() * data.yScale()); } // Move the rectangle to the screen position r.translate(x(), y()); if (mask & PAINT_SCREEN_TRANSFORMED) { // Apply the screen transformation r.moveTo(r.x() * screen_paint.xScale() + screen_paint.xTranslation(), r.y() * screen_paint.yScale() + screen_paint.yTranslation()); r.setWidth(r.width() * screen_paint.xScale()); r.setHeight(r.height() * screen_paint.yScale()); } return r; }
void QQuickContext2DFBOTexture::compositeTile(QQuickContext2DTile* tile) { QQuickContext2DFBOTile* t = static_cast<QQuickContext2DFBOTile*>(tile); QRect target = t->rect().intersected(m_canvasWindow); if (target.isValid()) { QRect source = target; source.moveTo(source.topLeft() - t->rect().topLeft()); target.moveTo(target.topLeft() - m_canvasWindow.topLeft()); QOpenGLFramebufferObject::blitFramebuffer(m_fbo, target, t->fbo(), source); } }
//====================================================================== void IacPlot::draw_PRESSURE_IsobarsLabels (QPainter &pnt, Projection *proj) { if (iacReader==NULL || !iacReader->isOk()) { return; } int a,b; QString label="1XXX"; QPen penText(QColor(0,0,0)); QFont fontText = Font::getFont(FONT_IAC_Isobar); QFontMetrics fmet(fontText); QRect rect = fmet.boundingRect(label); pnt.setPen(penText); pnt.setFont(fontText); // use a gradient, because it's a bug sometimes with solid pattern (black background) QLinearGradient gradient; int r = 255; gradient.setColorAt(0, QColor(r,r,r, 140)); gradient.setColorAt(1, QColor(r,r,r, 140)); pnt.setBrush(gradient); //--------------------------------------------------------- // Ecrit les labels //--------------------------------------------------------- std::vector <IAC_Isobar *> *lslines = iacReader->getList_PressureIsobars(); for (uint i=0; i<lslines->size(); i++) { IAC_Isobar * trline= lslines->at(i); std::vector <IAC_Point *> lspoints = trline->points; if (lspoints.size() > 1) { label = label.sprintf("%d", (int)(trline->value+0.5)); rect = fmet.boundingRect(label); IAC_Point *pt = lspoints.at(lspoints.size()/2); proj->map2screen( pt->x, pt->y, &a, &b ); rect.moveTo(a-rect.width()/2, b-rect.height()/2); pnt.drawRect(rect.x()-1, rect.y(), rect.width()+2, fmet.ascent()+2); pnt.drawText(rect, Qt::AlignHCenter|Qt::AlignVCenter, label); // proj->map2screen( pt->x-360, pt->y, &a, &b ); rect.moveTo(a-rect.width()/2, b-rect.height()/2); pnt.drawRect(rect.x()-1, rect.y(), rect.width()+2, fmet.ascent()+2); pnt.drawText(rect, Qt::AlignHCenter|Qt::AlignVCenter, label); } } }
//--------------------------------------------------------------- void IsoLine::drawIsoLineLabels(QPainter &pnt, QColor &couleur, const Projection *proj, int density, int first, double coef,double offset) { std::vector <Segment *>::iterator it; int a,b,c,d; int nb = first; QString label; label = label.sprintf("%d", qRound(value*coef+offset)); QPen penText(couleur); QFont fontText = Font::getFont(FONT_IsolineLabel); QFontMetrics fmet(fontText); QRect rect = fmet.boundingRect(label); pnt.setPen(penText); pnt.setFont(fontText); // use a gradient, because it's a bug sometimes with solid pattern (black background) QLinearGradient gradient; int r = 255; gradient.setColorAt(0, QColor(r,r,r, 170)); gradient.setColorAt(1, QColor(r,r,r, 170)); pnt.setBrush(gradient); //--------------------------------------------------------- // Ecrit les labels //--------------------------------------------------------- for (it=trace.begin(); it!=trace.end(); ++it,nb++) { if (nb % density == 0) { Segment *seg = *it; rect = fmet.boundingRect(label); proj->map2screen( seg->px1, seg->py1, &a, &b ); proj->map2screen( seg->px2, seg->py2, &c, &d ); rect.moveTo((a+c)/2-rect.width()/2, (b+d)/2-rect.height()/2); pnt.drawRect(rect.x()-1, rect.y(), rect.width()+2, fmet.ascent()+2); pnt.drawText(rect, Qt::AlignHCenter|Qt::AlignVCenter, label); // tour du monde ? proj->map2screen( seg->px1-360.0, seg->py1, &a, &b ); proj->map2screen( seg->px2-360.0, seg->py2, &c, &d ); rect.moveTo((a+c)/2-rect.width()/2, (b+d)/2-rect.height()/2); pnt.drawRect(rect.x()-1, rect.y(), rect.width()+2, fmet.ascent()+2); pnt.drawText(rect, Qt::AlignHCenter|Qt::AlignVCenter, label); } } }
void CurrentTrack::drawSourceEmblem( QPainter *const p, const QRect &contentsRect ) { if( m_isStopped ) return; p->save(); p->setOpacity( 0.19 ); if( m_sourceEmblemPath.isEmpty() ) { QPixmap logo = Amarok::semiTransparentLogo( m_albumWidth ); QRect rect = logo.rect(); int y = standardPadding(); int x = contentsRect.right() - rect.width() - y; rect.moveTo( x, y ); QRectF clipRect( rect ); qreal clipY = m_ratingWidget->pos().y() - m_ratingWidget->boundingRect().height() + 8; clipRect.setBottom( clipY ); p->setClipRect( clipRect ); p->drawPixmap( rect, logo ); } else { QSvgRenderer svg( m_sourceEmblemPath ); // paint the emblem half as tall as the applet, anchored at the top-right // assume it is a square emblem qreal height = boundingRect().height() / 2; int y = standardPadding(); int x = contentsRect.right() - y - height; QRectF rect( x, y, height, height ); svg.render( p, rect ); } p->restore(); }
void QQuickContext2DImageTexture::compositeTile(QQuickContext2DTile* tile) { Q_ASSERT(!tile->dirty()); QQuickContext2DImageTile* t = static_cast<QQuickContext2DImageTile*>(tile); QRect target = t->rect().intersected(m_canvasWindow); if (target.isValid()) { QRect source = target; source.moveTo(source.topLeft() - t->rect().topLeft()); target.moveTo(target.topLeft() - m_canvasWindow.topLeft()); m_painter.begin(&m_image); m_painter.setCompositionMode(QPainter::CompositionMode_Source); m_painter.drawImage(target, t->image(), source); m_painter.end(); } }
void QtMaemo6MenuProxy::hideWindow() { const MWidgetFadeAnimationStyle *fadeOutStyle = static_cast<const MWidgetFadeAnimationStyle *>(QtMaemo6StylePrivate::mStyle(QStyle::State_Active, "MWidgetFadeAnimationStyle", "Out")); QRect startGeometry = m_menu->geometry(); QRect finalGeometry = startGeometry; finalGeometry.moveTo(finalGeometry.x(), finalGeometry.y() - finalGeometry.height()); QParallelAnimationGroup* animationGroup = new QParallelAnimationGroup(); QPropertyAnimation *widgetFadeOut = new QPropertyAnimation(animationGroup); widgetFadeOut->setTargetObject(m_menu); widgetFadeOut->setPropertyName("geometry"); widgetFadeOut->setDuration(fadeOutStyle->duration()); widgetFadeOut->setEasingCurve(fadeOutStyle->easingCurve()); widgetFadeOut->setStartValue(startGeometry); widgetFadeOut->setEndValue(finalGeometry); QPalette startPalette = m_appArea->palette(); QPalette finalPalette = startPalette; startPalette.setBrush(QPalette::Window, QBrush(QColor(0, 0, 0, 0))); QPropertyAnimation *backgroundFadeOut = new QPropertyAnimation(animationGroup); backgroundFadeOut->setTargetObject(m_appArea); backgroundFadeOut->setPropertyName("palette"); backgroundFadeOut->setDuration(fadeOutStyle->duration()); backgroundFadeOut->setEasingCurve(fadeOutStyle->easingCurve()); backgroundFadeOut->setStartValue(startPalette); backgroundFadeOut->setEndValue(finalPalette); connect(animationGroup, SIGNAL(finished()), this, SLOT(close())); animationGroup->start(QAbstractAnimation::DeleteWhenStopped); }
void NativeRenderDialog::exportRaster() { QString s; QFileDialog dlg(NULL, tr("Output filename"), QString("%1/%2.png").arg(M_PREFS->getworkingdir()).arg(tr("untitled")), tr("Image files (*.png *.jpg)") + "\n" + tr("All Files (*)")); dlg.setFileMode(QFileDialog::AnyFile); dlg.setDefaultSuffix("png"); dlg.setAcceptMode(QFileDialog::AcceptSave); if (dlg.exec()) { if (dlg.selectedFiles().size()) s = dlg.selectedFiles()[0]; } // QString s = QFileDialog::getSaveFileName(NULL,tr("Output filename"),"",tr("Image files (*.png *.jpg)")); if (s.isNull()) return; QRect theR = thePrinter->pageRect(); theR.moveTo(0, 0); QPixmap pix(theR.size()); if (M_PREFS->getUseShapefileForBackground()) pix.fill(M_PREFS->getWaterColor()); else if (M_PREFS->getBackgroundOverwriteStyle() || !M_STYLE->getGlobalPainter().getDrawBackground()) pix.fill(M_PREFS->getBgColor()); else pix.fill(M_STYLE->getGlobalPainter().getBackgroundColor()); QPainter P(&pix); P.setRenderHint(QPainter::Antialiasing); render(P, theR, options()); pix.save(s); }
void AddressWidget::paintEvent(QPaintEvent *event) { QLineEdit::paintEvent(event); QColor badgeColor = QColor(245, 245, 245); QStyleOptionFrame panel; initStyleOption(&panel); panel.palette = palette(); panel.palette.setColor(QPalette::Base, badgeColor); panel.state = QStyle::State_Active; QRect rectangle = style()->subElementRect(QStyle::SE_LineEditContents, &panel, this); rectangle.setWidth(30); rectangle.moveTo(panel.lineWidth, panel.lineWidth); m_securityBadgeRectangle = rectangle; QPainter painter(this); painter.fillRect(rectangle, badgeColor); painter.setClipRect(rectangle); style()->drawPrimitive(QStyle::PE_PanelLineEdit, &panel, &painter, this); QPalette linePalette = palette(); linePalette.setCurrentColorGroup(QPalette::Disabled); painter.setPen(QPen(linePalette.mid().color(), 1)); painter.drawLine(rectangle.right(), rectangle.top(), rectangle.right(), rectangle.bottom()); }
//------------------------------------------------------------------------- void QGuidoItemContainer::updatePageIndexLabel() { // qDebug() << "updatePageIndexLabel() : " << mGuidoItem->firstVisiblePage() << "-" << mGuidoItem->lastVisiblePage() << "/" << mGuidoItem->pageCount() ; //Updates the page index item. QString pageLabel; if ( mGuidoItem->firstVisiblePage() != mGuidoItem->lastVisiblePage() ) QTextStream(&pageLabel) << mGuidoItem->firstVisiblePage() << "-" << mGuidoItem->lastVisiblePage() << "/" << mGuidoItem->pageCount() ; else QTextStream(&pageLabel) << mGuidoItem->firstVisiblePage() << "/" << mGuidoItem->pageCount() ; QFontMetrics fontMetrics( mPageLabelItem->textItem()->font() ); QRect pageLabelRect = fontMetrics.boundingRect( pageLabel ); pageLabelRect.moveTo( rect().width() , rect().height() ); pageLabelRect.translate( -pageLabelRect.width() + PAGE_LABEL_RECT_OUT_WIDTH , -pageLabelRect.height() + PAGE_LABEL_RECT_OUT_HEIGHT ); pageLabelRect.translate(-5,-2); pageLabelRect.setWidth( pageLabelRect.width() + 10 ); pageLabelRect.setHeight( pageLabelRect.height() + 4 ); QPainterPath pageLabelPath; pageLabelPath.addRoundedRect( pageLabelRect , ROUNDED_RECT_RADIUS , ROUNDED_RECT_RADIUS ); if ( mPageLabelItem->path() != pageLabelPath ) mPageLabelItem->setPath( pageLabelPath ); mPageLabelItem->setText(pageLabel); }
Calibration::Calibration() { QRect desktop = QApplication::desktop()->geometry(); desktop.moveTo(QPoint(0, 0)); setGeometry(desktop); setFocusPolicy(Qt::StrongFocus); setFocus(); setModal(true); int width = qt_screen->deviceWidth(); int height = qt_screen->deviceHeight(); int dx = width / 10; int dy = height / 10; QPoint *points = data.screenPoints; points[QWSPointerCalibrationData::TopLeft] = QPoint(dx, dy); points[QWSPointerCalibrationData::BottomLeft] = QPoint(dx, height - dy); points[QWSPointerCalibrationData::BottomRight] = QPoint(width - dx, height - dy); points[QWSPointerCalibrationData::TopRight] = QPoint(width - dx, dy); points[QWSPointerCalibrationData::Center] = QPoint(width / 2, height / 2); pressCount = 0; }
void DynamicView::paintEvent( QPaintEvent* event ) { TrackView::paintEvent(event); QPainter p( viewport() ); if( m_fadeOutAnim.state() == QTimeLine::Running ) { // both run together p.save(); QRect bg = m_fadingIndexes.rect(); bg.moveTo( m_fadingPointAnchor ); // cover up the background p.fillRect( bg, Qt::white ); if( m_fadebg ) { p.save(); p.setOpacity( 1 - m_fadeOutAnim.currentValue() ); } p.drawPixmap( bg, m_bg ); if( m_fadebg ) { p.restore(); } // qDebug() << "FAST SETOPACITY:" << p.paintEngine()->hasFeature(QPaintEngine::ConstantOpacity); p.setOpacity( 1 - m_fadeOutAnim.currentValue() ); p.drawPixmap( m_fadingPointAnchor, m_fadingIndexes ); p.restore(); if( m_slideAnim.state() == QTimeLine::Running ) { // draw the collapsing entry p.drawPixmap( 0, m_slideAnim.currentFrame(), m_slidingIndex ); } else if( m_fadeOutAnim.state() == QTimeLine::Running && !m_fadeOnly ) { p.drawPixmap( 0, m_bottomAnchor.y(), m_slidingIndex ); } } }
void Interface::Mousemove(QMouseEvent *e) /* mouse start */ { if (CTRL_Pressed && moverecci && TagliaPoi.width() > 10) { moverecci = true; CTRL_Pressed = true; setCursor(Qt::ClosedHandCursor); QRect TMPrect = TagliaPoi; Dmove = ScalePoint(e->pos()); Dmove.setX(Dmove.x() - (TMPrect.width() / 2)); Dmove.setY(Dmove.y() - (TMPrect.height() / 2)); TMPrect.moveTo(Dmove); DisegnaRect(TMPrect.topLeft(),TMPrect.bottomRight()); //////////////qDebug() << "####### TMPrect.width() " << TMPrect.height() << " TMPrect.width() " << TMPrect.width(); //////////////////qDebug() << "####### TagliaPoi " << TagliaPoi; return; } if (Dstart.x() > 0 ) { Dstop = ScalePoint(e->pos()); DisegnaRect(Dstart,Dstop); setCursor(Qt::CrossCursor); moverecci = false; CTRL_Pressed = false; } }
void NativeRenderDialog::exportSVG() { QString s; QFileDialog dlg(NULL, tr("Output filename"), QString("%1/%2.svg").arg(M_PREFS->getworkingdir()).arg(tr("untitled")), tr("SVG files (*.svg)") + "\n" + tr("All Files (*)")); dlg.setFileMode(QFileDialog::AnyFile); dlg.setDefaultSuffix("svg"); dlg.setAcceptMode(QFileDialog::AcceptSave); if (dlg.exec()) { if (dlg.selectedFiles().size()) s = dlg.selectedFiles()[0]; } // QString s = QFileDialog::getSaveFileName(NULL,tr("Output filename"),"",tr("SVG files (*.svg)")); if (s.isNull()) return; QSvgGenerator svgg; QRect theR = thePrinter->pageRect(); theR.moveTo(0, 0); svgg.setSize(theR.size()); svgg.setFileName(s); #if QT_VERSION >= 0x040500 svgg.setViewBox(theR); #endif QPainter P(&svgg); P.setRenderHint(QPainter::Antialiasing); RendererOptions opt = options(); opt.options |= RendererOptions::PrintAllLabels; render(P, theR, opt); }
QWidget *FormWindowBase::widgetUnderMouse(const QPoint &formPos, WidgetUnderMouseMode /* wum */) { // widget_under_mouse might be some temporary thing like the dropLine. We need // the actual widget that's part of the edited GUI. QWidget *rc = widgetAt(formPos); if (!rc || qobject_cast<ConnectionEdit*>(rc)) return 0; if (rc == mainContainer()) { // Refuse main container areas if the main container has a container extension, // for example when hitting QToolBox/QTabWidget empty areas. if (qt_extension<QDesignerContainerExtension*>(core()->extensionManager(), rc)) return 0; return rc; } // If we hit on container extension type container, make sure // we use the top-most current page if (QWidget *container = findContainer(rc, false)) if (QDesignerContainerExtension *c = qt_extension<QDesignerContainerExtension*>(core()->extensionManager(), container)) { // For container that do not have a "stacked" nature (QToolBox, QMdiArea), // make sure the position is within the current page const int ci = c->currentIndex(); if (ci < 0) return 0; QWidget *page = c->widget(ci); QRect pageGeometry = page->geometry(); pageGeometry.moveTo(page->mapTo(this, pageGeometry.topLeft())); if (!pageGeometry.contains(formPos)) return 0; return page; } return rc; }
void NativeRenderDialog::exportPDF() { QString s; QFileDialog dlg(NULL, tr("Output filename"), QString("%1/%2.pdf").arg(M_PREFS->getworkingdir()).arg(tr("untitled")), tr("PDF files (*.pdf)") + "\n" + tr("All Files (*)")); dlg.setFileMode(QFileDialog::AnyFile); dlg.setDefaultSuffix("pdf"); dlg.setAcceptMode(QFileDialog::AcceptSave); if (dlg.exec()) { if (dlg.selectedFiles().size()) s = dlg.selectedFiles()[0]; } // QString s = QFileDialog::getSaveFileName(NULL,tr("Output filename"),"",tr("PDF files (*.pdf)")); if (s.isNull()) return; thePrinter->setOutputFormat(QPrinter::PdfFormat); thePrinter->setOutputFileName(s); QPainter P(thePrinter); P.setRenderHint(QPainter::Antialiasing); QRect theR = thePrinter->pageRect(); theR.moveTo(0, 0); RendererOptions opt = options(); opt.options |= RendererOptions::PrintAllLabels; render(P, theR, opt); }
void AutoCloseMessageBox::setStartPos(int x, int y) { m_startX = x; m_startY = y; QRect r = this->geometry(); r.moveTo(x, y); setGeometry(r); }
//! [5] void VibrationSurface::paintEvent(QPaintEvent *) { QPainter painter(this); QRect rect = geometry(); int dx = 0, dy = 0; if (height() > width()) { dy = height() / NumberOfLevels; rect.setHeight(dy); } else { dx = width() / NumberOfLevels; rect.setWidth(dx); } //! [5] //! [6] for (int i = 0; i < NumberOfLevels; i++) { int x = i * dx; int y = i * dy; int intensity = getIntensity(x, y); QColor color = QColor(40, 80, 10).lighter(100 + intensity); rect.moveTo(x, y); painter.fillRect(rect, color); painter.setPen(color.darker()); painter.drawText(rect, Qt::AlignCenter, QString::number(intensity)); } }
//----------------------------------------------------------------------------- void WidgetBitmapEditor::wheelEvent(QWheelEvent *event) { if ((event->modifiers() & Qt::ControlModifier) == Qt::ControlModifier) { QPoint point = event->globalPos(); point = this->mapFromGlobal(point); QRect labelRect = this->ui->label->rect(); QPoint labelPoint = this->ui->label->pos(); labelRect.moveTo(labelPoint); if (labelRect.contains(point.x(), point.y())) { if (event->orientation() == Qt::Vertical) { int scale = this->mScale; if (event->delta() > 0) scale++; else scale--; this->setScale(scale); this->ui->spinBoxScale->setValue(this->mScale); } event->accept(); } } }
void DialogPreview::wheelEvent(QWheelEvent *event) { if ((event->modifiers() & Qt::ControlModifier) == Qt::ControlModifier) { QPoint point = event->globalPos(); point = this->mapFromGlobal(point); QRect labelRectPreview = this->ui->labelPreview->rect(); QPoint labelPoint = this->ui->labelPreview->pos(); labelRectPreview.moveTo(labelPoint); if (labelRectPreview.contains(point.x(), point.y())) { if (event->orientation() == Qt::Vertical) { int scale = this->mScale; if (event->delta() > 0) { scale++; } else { scale--; } this->setScale(scale); this->ui->spinBoxScale->setValue(this->mScale); } event->accept(); } } }
QRect QLineEditPrivate::cursorRect() const { QRect cr = adjustedContentsRect(); int cix = cr.x() - hscroll + horizontalMargin; QRect crect = control->cursorRect(); crect.moveTo(crect.topLeft() + QPoint(cix, vscroll)); return crect; }
void NativeRenderDialog::print(QPrinter* prt) { QPainter P(prt); P.setRenderHint(QPainter::Antialiasing); QRect theR = prt->pageRect(); theR.moveTo(0, 0); render(P, theR, options()); }
void LDesktop::AlignDesktopPlugins(){ QList<QMdiSubWindow*> wins = bgDesktop->subWindowList(); QSize fit = bgDesktop->size(); //Auto-determine the best grid sizing // It will try to exactly fit the desktop plugin area, with at least 10-20 grid points int xgrid, ygrid; xgrid = ygrid = 32; //while(fit.width()%xgrid != 0){ xgrid = xgrid-1; } //while(fit.height()%ygrid != 0){ ygrid = ygrid-1; } //qDebug() << "Grid:" << xgrid << ygrid << fit.width() << fit.height(); //Make sure there are at least 10 points. It will not fit the area exactly, but should be very close //while(xgrid < 10){ xgrid = xgrid*2; } //while(ygrid < 10){ ygrid = ygrid*2; } //qDebug() << "Grid (adjusted):" << xgrid << ygrid; // xgrid = int(fit.width()/xgrid); //now get the exact pixel size of the grid //ygrid = int(fit.height()/ygrid); //now get the exact pixel size of the grid //qDebug() << "Grid (pixel):" << xgrid << ygrid; //qDebug() << " X-Grid:" << xgrid << "("+QString::number(fit.width()/xgrid)+" points)"; //qDebug() << " Y-Grid:" << ygrid << "("+QString::number(fit.height()/ygrid)+" points)"; for(int i=0; i<wins.length(); i++){ //align the plugin on a grid point (that is not right/bottom edge) QRect geom = wins[i]->geometry(); int x, y; if(geom.x()<0){ x=0; } else{ x = qRound(geom.x()/float(xgrid)) * xgrid; } if(x>= fit.width()){ x = fit.width()-xgrid; geom.setWidth(xgrid); } if(geom.y()<0){ y=0; } else{ y = qRound(geom.y()/float(ygrid)) * ygrid; } if(y>= fit.height()){ y = fit.height()-ygrid; geom.setHeight(ygrid); } geom.moveTo(x,y); //Now adjust the size to also be the appropriate grid multiple geom.setWidth( qRound(geom.width()/float(xgrid))*xgrid ); geom.setHeight( qRound(geom.height()/float(ygrid))*ygrid ); //Now check for edge spillover and adjust accordingly int diff = (geom.x()+geom.width()) - bgDesktop->size().width(); if( diff > 0 ){ geom.moveTo( geom.x() - diff, geom.y() ); } else if( diff > -11 ){ geom.setWidth( geom.width()-diff ); } diff = (geom.y()+geom.height()) - bgDesktop->size().height(); if( diff > 0 ){ geom.moveTo( geom.x(), geom.y() - diff ); } else if( diff > -11 ){ geom.setHeight( geom.height()-diff ); } //Now move the plugin wins[i]->setGeometry(geom); } }
/// Returns the exact bounds of where the actual data resides in this layer QRect KisCloneLayer::exactBounds() const { if (m_d->copyFrom) { QRect rc = m_d->copyFrom->exactBounds(); rc.moveTo(m_d->x, m_d->y); return rc; } return QRect(); }
void KOTodoRichTextDelegate::paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const { if ( index.data( KOTodoModel::IsRichTextRole ).toBool() ) { QStyleOptionViewItemV4 opt = option; initStyleOption( &opt, index ); const QWidget *widget = opt.widget; QStyle *style = widget ? widget->style() : QApplication::style(); QRect textRect = style->subElementRect( QStyle::SE_ItemViewItemText, &opt, widget ); // draw the item without text opt.text.clear(); style->drawControl( QStyle::CE_ItemViewItem, &opt, painter, widget ); // draw the text (rich text) QPalette::ColorGroup cg = opt.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled; if ( cg == QPalette::Normal && !( opt.state & QStyle::State_Active ) ) { cg = QPalette::Inactive; } if ( opt.state & QStyle::State_Selected ) { painter->setPen( QPen( opt.palette.brush( cg, QPalette::HighlightedText ), 0 ) ); } else { painter->setPen( QPen( opt.palette.brush( cg, QPalette::Text ), 0 ) ); } if ( opt.state & QStyle::State_Editing ) { painter->setPen( QPen( opt.palette.brush( cg, QPalette::Text ), 0 ) ); painter->drawRect( textRect.adjusted( 0, 0, -1, -1 ) ); } m_textDoc->setHtml( index.data().toString() ); painter->save(); painter->translate( textRect.topLeft() ); QRect tmpRect = textRect; tmpRect.moveTo( 0, 0 ); m_textDoc->setTextWidth( tmpRect.width() ); m_textDoc->drawContents( painter, tmpRect ); painter->restore(); } else { // align the text at top so that when it has more than two lines // it will just cut the extra lines out instead of aligning centered vertically QStyleOptionViewItem copy = option; copy.displayAlignment = Qt::AlignLeft | Qt::AlignTop; QStyledItemDelegate::paint( painter, copy, index ); } }
void CSVWidget::ColorPickerPopup::showPicker(const QPoint &position, const QColor &initialColor) { QRect geometry = this->geometry(); geometry.moveTo(position); setGeometry(geometry); // Calling getColor() creates a blocking dialog that will continue execution once the user chooses OK or Cancel QColor color = mColorPicker->getColor(initialColor); mColorPicker->setCurrentColor(color); }
void NativeRenderDialog::renderPreview(QPrinter* printer) { /* Set the preview resolution. Having full resolution just for preview * could result in huge delay when opening the dialog the first time. */ printer->setResolution(96); QPainter P(printer); P.setRenderHint(QPainter::Antialiasing); QRect theR = printer->pageRect(); qDebug() << "Rendering preview to: " << theR; theR.moveTo(0, 0); render(P, theR, options()); }
/** * Update the number of unread messages in the tray icon */ void KCheckGmailTray::updateCountImage(QColor color) { kDebug() << k_funcinfo << "Count=" << mMailCount; if(mMailCount == 0) setPixmapEmpty(); else { // adapted from KMSystemTray::updateCount() int oldPixmapWidth = mPixGmail.size().width(); QString countString = QString::number( mMailCount ); QFont countFont = KGlobalSettings::generalFont(); countFont.setBold(true); // decrease the size of the font for the number of unread messages if the // number doesn't fit into the available space float countFontSize = countFont.pointSizeF(); QFontMetrics qfm( countFont ); int width = qfm.width( countString ); if( width > (oldPixmapWidth - 2) ) { countFontSize *= float( oldPixmapWidth - 2 ) / float( width ); countFont.setPointSizeF( countFontSize ); } // Overlay the light KCheckGmail image with the number image QImage iconWithNumberImage = mLightIconImage.copy(); QPainter p( &iconWithNumberImage ); p.setFont( countFont ); KColorScheme scheme( QPalette::Active, KColorScheme::View ); qfm = QFontMetrics( countFont ); QRect boundingRect = qfm.tightBoundingRect( countString ); boundingRect.adjust( 0, 0, 0, 2 ); boundingRect.setHeight( qMin( boundingRect.height(), oldPixmapWidth ) ); boundingRect.moveTo( (oldPixmapWidth - boundingRect.width()) / 2, ((oldPixmapWidth - boundingRect.height()) / 2) - 1 ); p.setOpacity( 0.7 ); p.setBrush( scheme.background( KColorScheme::LinkBackground ) ); p.setPen( scheme.background( KColorScheme::LinkBackground ).color() ); p.drawRoundedRect( boundingRect, 2.0, 2.0 ); p.setBrush( Qt::NoBrush ); // p.setPen( scheme.foreground( KColorScheme::LinkText ).color() ); p.setPen(color); p.setOpacity( 1.0 ); p.drawText( iconWithNumberImage.rect(), Qt::AlignCenter, countString ); setIcon( QPixmap::fromImage( iconWithNumberImage ) ); } }
void EWAHTMLSelector::updateDialogGeometry() { if( m_messagePtr ) { QRect msgRect = m_messagePtr->getVisibleWebViewRect(); msgRect.moveTo( m_messagePtr->getCurrnetScrollPoint() ); QRect dlgRect = m_pDlg->rect(); dlgRect.moveCenter( QPoint( msgRect.center().x(), msgRect.top() + m_messagePtr->getCustomizedVerticalOffset() ) ); m_pDlg->setGeometry( dlgRect ); } update(); }
void AttributeWidget::onItemValuedChanged(QTreeWidgetItem *item, int column) { QVariant v = item->data(0, Qt::UserRole); int type = v.toInt(); int index = m_hashElement[item]; if (column == 0) { if (type != name_item) { return; } m_pCollector->updateFrameName(index, item->text(column)); } else { int value = item->text(column).toInt(); QRect rect = m_pCollector->getFrameByIndex(index)->rect; switch (type) { case x_item: rect.moveTo(value, rect.y()); break; case y_item: rect.moveTo(rect.x(), value); break; case width_item: rect.setWidth(value); break; case height_item: rect.setHeight(value); break; default: return; } m_pCollector->updateFrameRect(index, rect); } }