void wxWindowQt::DoGetClientSize(int *width, int *height) const { QRect geometry = GetHandle()->geometry(); if (width) *width = geometry.width(); if (height) *height = geometry.height(); }
void IsometricRenderer::drawTileLayer(QPainter *painter, const TileLayer *layer, const QRectF &exposed) const { const int tileWidth = map()->tileWidth(); const int tileHeight = map()->tileHeight(); if (tileWidth <= 0 || tileHeight <= 1) return; QRect rect = exposed.toAlignedRect(); if (rect.isNull()) rect = boundingRect(layer->bounds()); const QSize maxTileSize = layer->maxTileSize(); const int extraWidth = maxTileSize.width() - tileWidth; const int extraHeight = maxTileSize.height() - tileHeight; rect.adjust(-extraWidth, 0, 0, extraHeight); // Determine the tile and pixel coordinates to start at QPointF tilePos = pixelToTileCoords(rect.x(), rect.y()); QPoint rowItr = QPoint((int) std::floor(tilePos.x()), (int) std::floor(tilePos.y())); QPointF startPos = tileToPixelCoords(rowItr); startPos.rx() -= tileWidth / 2; startPos.ry() += tileHeight; // Compensate for the layer position rowItr -= QPoint(layer->x(), layer->y()); /* Determine in which half of the tile the top-left corner of the area we * need to draw is. If we're in the upper half, we need to start one row * up due to those tiles being visible as well. How we go up one row * depends on whether we're in the left or right half of the tile. */ const bool inUpperHalf = startPos.y() - rect.y() > tileHeight / 2; const bool inLeftHalf = rect.x() - startPos.x() < tileWidth / 2; if (inUpperHalf) { if (inLeftHalf) { --rowItr.rx(); startPos.rx() -= tileWidth / 2; } else { --rowItr.ry(); startPos.rx() += tileWidth / 2; } startPos.ry() -= tileHeight / 2; } // Determine whether the current row is shifted half a tile to the right bool shifted = inUpperHalf ^ inLeftHalf; for (int y = startPos.y(); y - tileHeight < rect.bottom(); y += tileHeight / 2) { QPoint columnItr = rowItr; for (int x = startPos.x(); x < rect.right(); x += tileWidth) { if (layer->contains(columnItr)) { const Cell &cell = layer->cellAt(columnItr); if (!cell.isEmpty()) { const QImage qimg = cell.toImage(); const QPoint qpos(x, y - qimg.height()); painter->drawImage(qpos, qimg); } } // Advance to the next column ++columnItr.rx(); --columnItr.ry(); } // Advance to the next row if (!shifted) { ++rowItr.rx(); startPos.rx() += tileWidth / 2; shifted = true; } else { ++rowItr.ry(); startPos.rx() -= tileWidth / 2; shifted = false; } } }
/*! Paint the identifier to a given rect. \param painter Painter \param rect Rect where to paint */ void QwtLegendItem::drawIdentifier( QPainter *painter, const QRect &rect) const { if ( rect.isEmpty() ) return; if ( (d_data->identifierMode & ShowLine ) && (d_data->curvePen.style() != Qt::NoPen) ) { painter->save(); painter->setPen(QwtPainter::scaledPen(d_data->curvePen)); QwtPainter::drawLine(painter, rect.left(), rect.center().y(), rect.right(), rect.center().y()); painter->restore(); } if ( (d_data->identifierMode & ShowSymbol) && (d_data->symbol->style() != QwtSymbol::NoSymbol) ) { QSize symbolSize = QwtPainter::metricsMap().screenToLayout(d_data->symbol->size()); // scale the symbol size down if it doesn't fit into rect. if ( rect.width() < symbolSize.width() ) { const double ratio = double(symbolSize.width()) / double(rect.width()); symbolSize.setWidth(rect.width()); symbolSize.setHeight(qRound(symbolSize.height() / ratio)); } if ( rect.height() < symbolSize.height() ) { const double ratio = double(symbolSize.width()) / double(rect.width()); symbolSize.setHeight(rect.height()); symbolSize.setWidth(qRound(symbolSize.width() / ratio)); } QRect symbolRect; symbolRect.setSize(symbolSize); symbolRect.moveCenter(rect.center()); painter->save(); painter->setBrush(d_data->symbol->brush()); painter->setPen(QwtPainter::scaledPen(d_data->symbol->pen())); d_data->symbol->draw(painter, symbolRect); painter->restore(); } }
void DiagramCanvas::paint_all( QRect& r ) { int i; QPainter p( &buffer ); QPen pen; QBrush brush; QPointArray a; QColor color; QRegion mask, crossing_disk; set<double>::iterator dbl_it; for ( i=0; i<crossingList.size(); ++i ) { Crossing *c = crossingList[i]; c->under->underpasses.insert( c->under->underpasses.end(), c->position_on_understrand ); } for ( i=0; i<edgeList.size(); ++i ) { Edge *e = edgeList[i]; pen.setWidth( e->thickness ); pen.setColor( CANVAS ); p.setPen( pen ); QPoint v, v1, v2, p1, p2 ; p1 = e->vertex[begin]->position; p2 = e->vertex[end]->position; p.drawLine( p1, p2 ); /* if (e->edge_type==singular) { v = p1 - p2; v1.setX( v.x() - v.y() ); v1.setY( v.x() + v.y() ); v2.setX( v.x() + v.y() ); v2.setY( -v.x() + v.y() ); v1 = 5 * v1 / sqrt( double (v1.x() * v1.x() + v1.y() * v1.y()) ); v2 = 5 * v2 / sqrt( double (v2.x() * v2.x() + v2.y() * v2.y()) ); v = v / 2; pen.setWidth( ARROW ); p.setPen( pen ); p.drawLine( p2+v, p2+v1+v ); p.drawLine( p2+v, p2+v2+v ); } */ } for ( i=0; i<edgeList.size(); ++i ) { Edge *e = edgeList[i]; color = (e->edge_type == drilled) ? DRILLED : colorList[e->arc_id % 18 ]; pen.setWidth( e->thickness ); pen.setColor( color ); p.setPen( pen ); brush.setColor( color ); brush.setStyle( SolidPattern ); p.setBrush( brush ); if ( e->underpasses.size() > 0 ) { p.setClipping( TRUE ); mask = QRegion( 0, 0, width(), height(), QRegion::Rectangle ); for ( dbl_it=e->underpasses.begin(); dbl_it!=e->underpasses.end(); ++dbl_it ) { QPoint center = time_to_point( e, *dbl_it ); crossing_disk = QRegion( center.x()-7, center.y()-7, 14, 14 , QRegion::Ellipse ); mask -= crossing_disk; } p.setClipRegion( mask ); QPoint v, v1, v2, p1, p2 ; p1 = e->vertex[begin]->position; p2 = e->vertex[end]->position; p.drawLine( p1, p2 ); /* if (e->edge_type==singular) { v = p1 - p2; v1.setX( v.x() - v.y() ); v1.setY( v.x() + v.y() ); v2.setX( v.x() + v.y() ); v2.setY( -v.x() + v.y() ); v1 = 5 * v1 / sqrt( double (v1.x() * v1.x() + v1.y() * v1.y()) ); v2 = 5 * v2 / sqrt( double (v2.x() * v2.x() + v2.y() * v2.y()) ); v = v / 2; pen.setWidth( ARROW ); p.setPen( pen ); p.drawLine( p2+v, p2+v1+v ); p.drawLine( p2+v, p2+v2+v ); } */ p.setClipping( FALSE ); } else { QPoint v, v1, v2, p1, p2 ; p1 = e->vertex[begin]->position; p2 = e->vertex[end]->position; p.drawLine( p1, p2 ); /* if (e->edge_type==singular) { v = p1 - p2; v1.setX( v.x() - v.y() ); v1.setY( v.x() + v.y() ); v2.setX( v.x() + v.y() ); v2.setY( -v.x() + v.y() ); v1 = 5 * v1 / sqrt( double (v1.x() * v1.x() + v1.y() * v1.y()) ); v2 = 5 * v2 / sqrt( double (v2.x() * v2.x() + v2.y() * v2.y()) ); v = v / 2; pen.setWidth( ARROW ); p.setPen( pen ); p.drawLine( p2+v, p2+v1+v ); p.drawLine( p2+v, p2+v2+v ); } */ } e->underpasses.clear(); } p.end(); bitBlt( this, r.x(), r.y(), &buffer, r.x(), r.y(), r.width(), r.height() ); }
void DesktopWindow::loadItemPositions() { // load custom item positions customItemPos_.clear(); Settings& settings = static_cast<Application*>(qApp)->settings(); QString configFile = QString("%1/desktop-items-%2.conf").arg(settings.profileDir(settings.profileName())).arg(screenNum_); QSettings file(configFile, QSettings::IniFormat); QSize grid = listView_->gridSize(); QRect workArea = qApp->desktop()->availableGeometry(screenNum_); workArea.adjust(12, 12, -12, -12); char* dektopPath = fm_path_to_str(fm_path_get_desktop()); QString desktopDir = QString(dektopPath) + QString("/"); g_free(dektopPath); Q_FOREACH(const QString& name, file.childGroups()) { if(!QFile::exists(desktopDir + name.toUtf8())) { // the file may have been removed from outside LXQT continue; } file.beginGroup(name); QVariant var = file.value("pos"); if(var.isValid()) { QPoint customPos = var.toPoint(); if (customPos.x() >= workArea.x() && customPos.y() >= workArea.y() && customPos.x() + listView_->gridSize().width() <= workArea.right() + 1 && customPos.y() + listView_->gridSize().height() <= workArea.bottom() + 1) { // correct positions that are't aligned to the grid qreal w = qAbs((qreal)customPos.x() - (qreal)workArea.x()) / (qreal)(grid.width() + listView_->spacing()); qreal h = qAbs(customPos.y() - (qreal)workArea.y()) / (qreal)(grid.height() + listView_->spacing()); customPos.setX(workArea.x() + qRound(w) * (grid.width() + listView_->spacing())); customPos.setY(workArea.y() + qRound(h) * (grid.height() + listView_->spacing())); while(customItemPos_.values().contains(customPos)) { customPos.setY(customPos.y() + grid.height() + listView_->spacing()); if(customPos.y() + grid.height() > workArea.bottom() + 1) { customPos.setX(customPos.x() + grid.width() + listView_->spacing()); customPos.setY(workArea.top()); } } customItemPos_[name.toUtf8()] = customPos; } } file.endGroup(); } }
QImage KisPixelSelection::maskImage(const QRect & rc) const { // If part of a KisAdjustmentLayer, there may be no parent device. QImage image; QRect bounds; if (m_d->parentPaintDevice) { bounds = m_d->parentPaintDevice->exactBounds(); bounds = bounds.intersect(rc); image = QImage(bounds.width(), bounds.height(), QImage::Format_RGB32); } else { bounds = rc; image = QImage(bounds.width(), bounds.height(), QImage::Format_RGB32); } KisHLineConstIteratorPixel it = createHLineConstIterator(bounds.x(), bounds.y(), bounds.width()); for (int y2 = bounds.y(); y2 < bounds.height() - bounds.y(); ++y2) { QRgb *pixel= reinterpret_cast<QRgb *>(image.scanLine(y2)); int x2 = 0; while (!it.isDone()) { quint8 s = MAX_SELECTED - *(it.rawData()); qint32 c = qRgb(s, s, s); pixel[x2] = c; ++x2; ++it; } it.nextRow(); // XXX: Why wasn't this line here? Used to be // present in 1.6. } return image; }
void paintContact(QPainter* mp, const QStyleOptionViewItem& option, const QModelIndex& index, GCUserViewItem* item) const { mp->save(); QStyleOptionViewItem o = option; QPalette palette = o.palette; MUCItem::Role r = item->s.mucItem().role(); QRect rect = o.rect; if(nickColoring_) { if(r == MUCItem::Moderator) palette.setColor(QPalette::Text, colorModerator_); else if(r == MUCItem::Participant) palette.setColor(QPalette::Text, colorParticipant_); else if(r == MUCItem::Visitor) palette.setColor(QPalette::Text, colorVisitor_); else palette.setColor(QPalette::Text, colorNoRole_); } mp->fillRect(rect, (o.state & QStyle::State_Selected) ? palette.color(QPalette::Highlight) : palette.color(QPalette::Base)); if(showAvatar_) { QPixmap ava = item->avatar(); if(ava.isNull()) { ava = IconsetFactory::iconPixmap("psi/default_avatar"); } ava = AvatarFactory::roundedAvatar(ava, avatarRadius_, avatarSize_); QRect avaRect(rect); avaRect.setWidth(ava.width()); avaRect.setHeight(ava.height()); if(!avatarAtLeft_) { avaRect.moveTopRight(rect.topRight()); avaRect.translate(-1, 1); rect.setRight(avaRect.left() - 1); } else { avaRect.translate(1, 1); rect.setLeft(avaRect.right() + 1); } mp->drawPixmap(avaRect, ava); } QPixmap status = showStatusIcons_ ? item->icon() : QPixmap(); int h = rect.height(); int sh = status.isNull() ? 0 : status.height(); rect.setHeight(qMax(sh, fontHeight_)); rect.moveTop(rect.top() + (h - rect.height())/2); if(!status.isNull()) { QRect statusRect(rect); statusRect.setWidth(status.width()); statusRect.setHeight(status.height()); statusRect.translate(1, 1); mp->drawPixmap(statusRect, status); rect.setLeft(statusRect.right() + 2); } else rect.setLeft(rect.left() + 2); mp->setPen(QPen((o.state & QStyle::State_Selected) ? palette.color(QPalette::HighlightedText) : palette.color(QPalette::Text))); mp->setFont(o.font); mp->setClipRect(rect); QTextOption to; to.setWrapMode(QTextOption::NoWrap); mp->drawText(rect, index.data(Qt::DisplayRole).toString(), to); QList<QPixmap> rightPixs; if(showClients_) { GCUserView *gcuv = (GCUserView*)item->treeWidget(); GCMainDlg* dlg = gcuv->mainDlg(); QPixmap clientPix; if(dlg) { UserListItem u; const QString &nick = item->text(0); Jid caps_jid(/*s.mucItem().jid().isEmpty() ? */ dlg->jid().withResource(nick) /* : s.mucItem().jid()*/); CapsManager *cm = dlg->account()->client()->capsManager(); QString client_name = cm->clientName(caps_jid); QString client_version = (client_name.isEmpty() ? QString() : cm->clientVersion(caps_jid)); UserResource ur; ur.setStatus(item->s); ur.setClient(client_name,client_version,""); u.userResourceList().append(ur); QStringList clients = u.clients(); if(!clients.isEmpty()) clientPix = IconsetFactory::iconPixmap("clients/" + clients.takeFirst()); } if(!clientPix.isNull()) rightPixs.push_back(clientPix); } if(showAffiliations_) { MUCItem::Affiliation a = item->s.mucItem().affiliation(); QPixmap pix; if(a == MUCItem::Owner) pix = IconsetFactory::iconPixmap("affiliation/owner"); else if(a == MUCItem::Admin) pix = IconsetFactory::iconPixmap("affiliation/admin"); else if(a == MUCItem::Member) pix = IconsetFactory::iconPixmap("affiliation/member"); else if(a == MUCItem::Outcast) pix = IconsetFactory::iconPixmap("affiliation/outcast"); else pix = IconsetFactory::iconPixmap("affiliation/noaffiliation"); if(!pix.isNull()) rightPixs.push_back(pix); } mp->restore(); if(rightPixs.isEmpty()) return; int sumWidth = 0; foreach (const QPixmap& pix, rightPixs) { sumWidth += pix.width(); } sumWidth += rightPixs.count(); QColor bgc = (option.state & QStyle::State_Selected) ? palette.color(QPalette::Highlight) : palette.color(QPalette::Base); QColor tbgc = bgc; tbgc.setAlpha(0); QLinearGradient grad(rect.right() - sumWidth - 20, 0, rect.right() - sumWidth, 0); grad.setColorAt(0, tbgc); grad.setColorAt(1, bgc); QBrush tbakBr(grad); QRect gradRect(rect); gradRect.setLeft(gradRect.right() - sumWidth - 20); mp->fillRect(gradRect, tbakBr); QRect iconRect(rect); for (int i=0; i<rightPixs.size(); i++) { const QPixmap pix = rightPixs[i]; iconRect.setRight(iconRect.right() - pix.width() -1); mp->drawPixmap(iconRect.topRight(), pix); } }
void PseudoStateCanvas::draw(QPainter & p) { if (!visible() || ((xpm == 0) && !manual_size)) return; QRect r = rect(); QRect intern_r; p.setBackgroundMode(::Qt::OpaqueMode); if (xpm != 0) p.drawPixmap(r.topLeft(), *xpm); else { // jork join manually sized if (horiz) { intern_r.setX(r.x() + 1); intern_r.setWidth(r.width() - 2); intern_r.setY(r.y() + 6); intern_r.setHeight(3); } else { intern_r.setX(r.x() + 6); intern_r.setWidth(3); intern_r.setY(r.y() + 1); intern_r.setHeight(r.height() - 2); } p.fillRect(intern_r, ::Qt::black); } if (selected()) show_mark(p, r); FILE * fp = svg(); if (fp != 0) { bool big = the_canvas()->zoom() >= 1.0; int px = (int) x(); int py = (int) y(); switch (browser_node->get_type()) { case InitialPS: if (big) fprintf(fp, "<ellipse fill=\"black\" cx=\"%d\" cy=\"%d\" rx=\"8.5\" ry=\"8.5\" />\n", px + 9, py + 9); else fprintf(fp, "<ellipse fill=\"black\" cx=\"%d\" cy=\"%d\" rx=\"5.5\" ry=\"5.5\" />\n", px + 7, py + 7); break; case EntryPointPS: if (big) fprintf(fp, "<ellipse fill=\"white\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" cx=\"%d\" cy=\"%d\" rx=\"8.5\" ry=\"8.5\" />\n", px + 9, py + 9); else fprintf(fp, "<ellipse fill=\"white\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" cx=\"%d\" cy=\"%d\" rx=\"5.5\" ry=\"5.5\" />\n", px + 7, py + 7); break; case FinalPS: if (big) { fprintf(fp, "<g>\n" "\t<ellipse fill=\"white\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" cx=\"%d\" cy=\"%d\" rx=\"11.5\" ry=\"11.5\" />\n", px + 12, py + 12); fprintf(fp, "\t<ellipse fill=\"black\" cx=\"%d\" cy=\"%d\" rx=\"8.5\" ry=\"8.5\" />\n" "</g>\n", px + 12, py + 12); } else { fprintf(fp, "<g>\n" "\t<ellipse fill=\"white\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" cx=\"%d\" cy=\"%d\" rx=\"7.5\" ry=\"7.5\" />\n", px + 8, py + 8); fprintf(fp, "\t<ellipse fill=\"black\" cx=\"%d\" cy=\"%d\" rx=\"4.5\" ry=\"4.5\" />\n" "</g>\n", px + 8, py + 8); } break; case TerminatePS: if (big) { fprintf(fp, "<g>\n" "\t<line stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", px + 1, py + 1, px + 19, py + 19); fprintf(fp, "\t<line stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n" "</g>\n", px + 19, py + 1, px + 1, py + 19); } else{ fprintf(fp, "<g>\n" "\t<line stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", px + 2, py + 2, px + 12, py + 12); fprintf(fp, "\t<line stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n" "</g>\n", px + 12, py + 2, px + 2, py + 12); } break; case ExitPointPS: if (big) { fprintf(fp, "<g>\n" "\t<ellipse fill=\"white\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" cx=\"%d\" cy=\"%d\" rx=\"8.5\" ry=\"8.5\" />\n", px + 9, py + 9); fprintf(fp, "\t<line stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", px + 4, py + 4, px + 14, py + 14); fprintf(fp, "\t<line stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n" "</g>\n", px + 14, py + 4, px + 4, py + 14); } else { fprintf(fp, "<g>\n" "\t<ellipse fill=\"white\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" cx=\"%d\" cy=\"%d\" rx=\"5.5\" ry=\"5.5\" />\n", px + 7, py + 7); fprintf(fp, "\t<line stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", px + 4, py + 4, px + 10, py + 10); fprintf(fp, "\t<line stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n" "</g>\n", px + 10, py + 4, px + 4, py + 10); } break; case DeepHistoryPS: if (big) { fprintf(fp, "<g>\n" "\t<ellipse fill=\"white\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" cx=\"%d\" cy=\"%d\" rx=\"12.5\" ry=\"12.5\" />\n", px + 12, py + 12); fprintf(fp, "\t<line stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", px + 4, py + 8, px + 4, py + 16); fprintf(fp, "\t<line stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", px + 10, py + 8, px + 10, py + 16); fprintf(fp, "\t<line stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", px + 4, py + 12, px + 10, py + 12); fprintf(fp, "\t<line stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", px + 12, py + 9, px + 20, py + 9); fprintf(fp, "\t<line stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", px + 13, py + 6, px + 19, py + 12); fprintf(fp, "\t<line stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", px + 13, py + 12, px + 19, py + 6); fprintf(fp, "\t<line stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n" "</g>\n", px + 16, py + 5, px + 16, py + 13); } else { fprintf(fp, "<g>\n" "\t<ellipse fill=\"white\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" cx=\"%d\" cy=\"%d\" rx=\"7.5\" ry=\"7.5\" />\n", px + 8, py + 8); fprintf(fp, "\t<line stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", px + 4, py + 6, px + 4, py + 10); fprintf(fp, "\t<line stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", px + 7, py + 6, px + 7, py + 10); fprintf(fp, "\t<line stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", px + 4, py + 8, px + 7, py + 8); fprintf(fp, "\t<line stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", px + 9, py + 7, px + 13, py + 7); fprintf(fp, "\t<line stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", px + 9, py + 5, px + 13, py + 9); fprintf(fp, "\t<line stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", px + 9, py + 9, px + 13, py + 5); fprintf(fp, "\t<line stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n" "</g>\n", px + 11, py + 5, px + 11, py + 9); } break; case ShallowHistoryPS: if (big) { fprintf(fp, "<g>\n" "\t<ellipse fill=\"white\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" cx=\"%d\" cy=\"%d\" rx=\"12.5\" ry=\"12.5\" />\n", px + 12, py + 12); fprintf(fp, "\t<line stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", px + 8, py + 8, px + 8, py + 16); fprintf(fp, "\t<line stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", px + 15, py + 8, px + 15, py + 16); fprintf(fp, "\t<line stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n" "</g>\n", px + 8, py + 12, px + 15, py + 12); } else { fprintf(fp, "<g>\n" "\t<ellipse fill=\"white\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" cx=\"%d\" cy=\"%d\" rx=\"7.5\" ry=\"7.5\" />\n", px + 8, py + 8); fprintf(fp, "\t<line stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", px + 5, py + 5, px + 5, py + 11); fprintf(fp, "\t<line stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", px + 11, py + 5, px + 11, py + 11); fprintf(fp, "\t<line stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n" "</g>\n", px + 5, py + 8, px + 11, py + 8); } break; case JunctionPS: if (big) fprintf(fp, "<ellipse fill=\"black\" stroke=\"none\" cx=\"%d\" cy=\"%d\" rx=\"6.5\" ry=\"6.5\" />\n", px + 7, py + 7); else fprintf(fp, "<ellipse fill=\"black\" stroke=\"none\" cx=\"%d\" cy=\"%d\" rx=\"4.5\" ry=\"4.5\" />\n", px + 5, py + 5); break; case ChoicePS: // note : shadow not produced if (big) fprintf(fp, "<polygon fill=\"white\" stroke=\"black\" stroke-opacity=\"1\" points =\"%d,%d %d,%d %d,%d %d,%d\" />\n", px + 3, py + 18, px + 12, py + 1, px + 21, py + 18, px + 12, py + 35); else fprintf(fp, "<polygon fill=\"white\" stroke=\"black\" stroke-opacity=\"1\" points =\"%d,%d %d,%d %d,%d %d,%d\" />\n", px + 2, py + 12, px + 8, py + 1, px + 14, py + 12, px + 8, py + 23); break; case ForkPS: case JoinPS: if (horiz) { if (manual_size) fprintf(fp, "<line stroke=\"black\" stroke-width=\"3\" stroke-opacity=\"1\" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", intern_r.x(), intern_r.y(), intern_r.x() + intern_r.width() - 1, intern_r.y()); else if (big) fprintf(fp, "<line stroke=\"black\" stroke-width=\"3\" stroke-opacity=\"1\" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", px + 1, py + 6, px + 23, py + 6); else fprintf(fp, "<line stroke=\"black\" stroke-width=\"3\" stroke-opacity=\"1\" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", px + 1, py + 6, px + 16, py + 6); } else { if (manual_size) fprintf(fp, "<line stroke=\"black\" stroke-width=\"3\" stroke-opacity=\"1\" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", intern_r.x(), intern_r.y(), intern_r.x(), intern_r.y() + intern_r.height() - 1); else if (big) fprintf(fp, "<line stroke=\"black\" stroke-width=\"3\" stroke-opacity=\"1\" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", px + 6, py + 1, px + 6, py + 24); else fprintf(fp, "<line stroke=\"black\" stroke-width=\"3\" stroke-opacity=\"1\" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", px + 6, py + 1, px + 6, py + 17); } break; default: break; } } }
// Read and write rectangle in X11 resource syntax "12x12+4+3" static QString rectangleToString(const QRect &r) { QString result; QTextStream(&result) << r.width() << 'x' << r.height() << forcesign << r.x() << r.y(); return result; }
/*override*/ void FilesGDelegate::paint(QPainter* pPainter, const QStyleOptionViewItem& option, const QModelIndex& index) const { // adapted from Trolltech's Pixelator (GPL V2 or V3) http://doc.trolltech.com/4.3/itemviews-pixelator.html int nCol (index.column()); if (0 == nCol) { return QItemDelegate::paint(pPainter, option, index); } //int nRow (index.row()); double r ((index.model()->data(index, Qt::DisplayRole).toString() == "" ? 0 : (CELL_HEIGHT - 0)/5)); pPainter->save(); pPainter->setRenderHint(QPainter::Antialiasing, true); pPainter->setPen(Qt::NoPen); const Note* pNote (m_pCommonData->getUniqueNotes().getFlt(nCol - 1)); bool bSel (0 != (QStyle::State_Selected & option.state)); bool bCrt (0 != (QStyle::State_HasFocus & option.state)); bool bActive (0 != (QStyle::State_Active & option.state)); // "active" is true if the parent window has keyboard focus /*QColor colSev (getNoteColor(*pNote)); //ttt2 perhaps try to derive all these colors from the global pallette (e.g. option.palette.highlight(), option.palette.highlightedText(), ...) QColor colBkg (colSev); QColor colFg (option.palette.color(QPalette::Active, QPalette::Highlight)); //ttt3 not necessarily "Active" //QColor colFg (Qt::black); //ttt3 not necessarily "Active" if (colFg.green() >= 160 && colFg.red() >= 160) { colFg = QColor(0, 0, 0); } if (bSel) { QColor c (colBkg); colBkg = colFg; colFg = c; }*/ //ttt2 perhaps try to derive all these colors from the global pallette (e.g. option.palette.highlight(), option.palette.highlightedText(), ...) QColor colNote; double dGradStart, dGradEnd; m_pCommonData->getNoteColor(*pNote, m_pCommonData->getUniqueNotes().getFltVec(), colNote, dGradStart, dGradEnd); QColor colSel (option.palette.color(QPalette::Active, QPalette::Highlight)); //ttt3 not necessarily "Active" //qDebug("gr %f %f", dGradStart, dGradEnd); QColor colFg, colBkg; colBkg = bSel ? colSel : colNote; if (colSel.green() >= 160 && colSel.red() >= 160) { // for better contrast we use something dark if the "highlight" color is light //colFg = QColor(0, 0, 0); colFg = option.palette.color(QPalette::Active, QPalette::HighlightedText); } else { colFg = bSel ? colNote : colSel; } //colBkg = QColor(220, 255, 230); QLinearGradient grad (option.rect.x(), 0, option.rect.x() + option.rect.width(), 0); /*switch(nCol % 4) { case 0: grad.setColorAt(0, colBkg.lighter(120)); grad.setColorAt(0.4, colBkg); grad.setColorAt(0.6, colBkg); grad.setColorAt(1, colBkg.darker(120)); break; case 1: grad.setColorAt(0, colBkg.lighter(120)); grad.setColorAt(0.4, colBkg); grad.setColorAt(0.6, colBkg); grad.setColorAt(1, colBkg); break; case 2: grad.setColorAt(0, colBkg); grad.setColorAt(0.4, colBkg); grad.setColorAt(0.6, colBkg); grad.setColorAt(1, colBkg); break; case 3: grad.setColorAt(0, colBkg); grad.setColorAt(0.4, colBkg); grad.setColorAt(0.6, colBkg); grad.setColorAt(1, colBkg.darker(120)); break; }*/ /* switch(nCol % 4) { case 0: configureGradient(grad, colBkg, 0, 1); break; case 1: configureGradient(grad, colBkg, 0, 0.33); break; case 2: configureGradient(grad, colBkg, 0.33, 0.67); break; case 3: configureGradient(grad, colBkg, 0.67, 1); break; } */ configureGradient(grad, colBkg, dGradStart, dGradEnd); //pPainter->fillRect(option.rect, colBkg); pPainter->fillRect(option.rect, grad); if (0 != r) { pPainter->setBrush(QBrush(colFg)); pPainter->drawEllipse( QRectF(option.rect.x() + option.rect.width()/2.0 - r, option.rect.y() + option.rect.height()/2.0 - r, 2*r, 2*r)); } if (bCrt && bActive) { pPainter->setRenderHint(QPainter::Antialiasing, false); const int ADJ (0); QRect r (option.rect); r.adjust(ADJ, ADJ, -ADJ - 1, -ADJ - 1); pPainter->setBrush(QBrush(Qt::NoBrush)); QPen pen (pPainter->pen()); pen.setStyle(Qt::DotLine); //pen.setColor(Qt::black); pen.setColor(colFg); pPainter->setPen(pen); pPainter->drawRect(r); } pPainter->restore(); }
/*override*/ void FileHeaderView::paintSection(QPainter* pPainter, const QRect& r, int nLogicalIndex) const { if (0 == nLogicalIndex) { pPainter->save(); QFont f (pPainter->font()); f.setWeight(QFont::Bold); pPainter->setFont(f); QHeaderView::paintSection(pPainter, r, nLogicalIndex); pPainter->restore(); return; } pPainter->save(); // partial copy from Qt's implementation of QHeaderView (qheaderview.cpp) QStyleOptionHeader opt; initStyleOption(&opt); opt.rect = r; opt.section = nLogicalIndex; int nVisual (visualIndex(nLogicalIndex)); if (count() == 1) opt.position = QStyleOptionHeader::OnlyOneSection; else if (nVisual == 0) opt.position = QStyleOptionHeader::Beginning; else if (nVisual == count() - 1) opt.position = QStyleOptionHeader::End; else opt.position = QStyleOptionHeader::Middle; opt.selectedPosition = QStyleOptionHeader::NotAdjacent; style()->drawControl(QStyle::CE_Header, &opt, pPainter, this); static bool s_bCutInit (false); if (!s_bCutInit) { s_bCutInit = true; int n (r.width()), m (r.height()); QRect r1 (0, 0, n, m); QImage img (n, m, QImage::Format_RGB32); QPainter pntr (&img); pntr.fillRect(r1, QColor(255, 255, 255)); opt.rect = r1; style()->drawControl(QStyle::CE_Header, &opt, &pntr); //img.save("/home/ciobi/tmp/3/hdr1.png"); m /= 2; double v1 (QColor(img.pixel(n - 3, m)).valueF()); double v2 (QColor(img.pixel(n - 2, m)).valueF()); double v3 (QColor(img.pixel(n - 1, m)).valueF()); //qDebug("%f %f %f", v1, v2, v3); if ((v1 > v2 + 0.07 && v3 > v2 + 0.07) || (v1 < v2 - 0.07 && v3 < v2 - 0.07)) { s_nCut = 3; //ttt2 hard-coded, must be kept in synch with CELL_WIDTH } // qDebug("cut: %d", s_nCut); } pPainter->restore(); pPainter->save(); pPainter->setFont(m_pCommonData->getLabelFont()); { // bold for selected QModelIndexList l (m_pCommonData->m_pFilesG->selectionModel()->selection().indexes()); for (QModelIndexList::iterator it = l.begin(); it != l.end(); ++it) { const QModelIndex& ndx (*it); if (ndx.column() == nLogicalIndex) { QFont f (pPainter->font()); f.setWeight(QFont::Bold); pPainter->setFont(f); break; } } } const Note* p (m_pCommonData->getUniqueNotes().getFltVec().at(nLogicalIndex - 1)); if (Note::ERR == p->getSeverity()) { pPainter->setPen(ERROR_PEN_COLOR()); } else if (Note::SUPPORT == p->getSeverity()) { pPainter->setPen(SUPPORT_PEN_COLOR()); } QRect r1 (r); r1.adjust(0, 0, -s_nCut, 0); pPainter->drawText(r1, Qt::AlignCenter, getNoteLabel(p)); pPainter->restore(); }
void PlaylistDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const { QStyleOptionViewItemV4 opt = option; initStyleOption( &opt, QModelIndex() ); qApp->style()->drawControl( QStyle::CE_ItemViewItem, &opt, painter ); if ( option.state & QStyle::State_Selected && option.state & QStyle::State_Active ) { opt.palette.setColor( QPalette::Text, opt.palette.color( QPalette::HighlightedText ) ); } painter->save(); painter->setRenderHint( QPainter::Antialiasing ); painter->setPen( opt.palette.color( QPalette::Text ) ); QTextOption to; to.setAlignment( Qt::AlignCenter ); QFont font = opt.font; font.setPixelSize( 10 ); QFont boldFont = font; boldFont.setBold( true ); boldFont.setPixelSize( 11 ); QFont figFont = boldFont; figFont.setPixelSize( 10 ); QPixmap icon; RecentlyPlayedPlaylistsModel::PlaylistTypes type = (RecentlyPlayedPlaylistsModel::PlaylistTypes)index.data( RecentlyPlayedPlaylistsModel::PlaylistTypeRole ).toInt(); if( type == RecentlyPlayedPlaylistsModel::StaticPlaylist ) icon = m_playlistIcon; else if( type == RecentlyPlayedPlaylistsModel::AutoPlaylist ) icon = m_autoIcon; else if( type == RecentlyPlayedPlaylistsModel::Station ) icon = m_stationIcon; QRect pixmapRect = option.rect.adjusted( 10, 13, -option.rect.width() + 48, -13 ); icon = icon.scaled( pixmapRect.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation ); painter->drawPixmap( pixmapRect, icon ); if ( type != RecentlyPlayedPlaylistsModel::Station ) { painter->save(); painter->setFont( figFont ); QString tracks = index.data( RecentlyPlayedPlaylistsModel::TrackCountRole ).toString(); int width = painter->fontMetrics().width( tracks ); // int bottomEdge = pixmapRect // right edge 10px past right edge of pixmapRect // bottom edge flush with bottom of pixmap QRect rect( pixmapRect.right() - width , 0, width - 8, 0 ); rect.adjust( -2, 0, 0, 0 ); rect.setTop( pixmapRect.bottom() - painter->fontMetrics().height() - 1 ); rect.setBottom( pixmapRect.bottom() + 1 ); QColor figColor( "#464b55" ); painter->setPen( figColor ); painter->setBrush( figColor ); TomahawkUtils::drawBackgroundAndNumbers( painter, tracks, rect ); painter->restore(); } QPixmap avatar = index.data( RecentlyPlayedPlaylistsModel::PlaylistRole ).value< Tomahawk::playlist_ptr >()->author()->avatar( Source::FancyStyle ); if ( avatar.isNull() ) avatar = m_defaultAvatar; QRect r( option.rect.width() - avatar.width() - 10, option.rect.top() + option.rect.height()/2 - avatar.height()/2, avatar.width(), avatar.height() ); painter->drawPixmap( r, avatar ); painter->setFont( font ); QString author = index.data( RecentlyPlayedPlaylistsModel::PlaylistRole ).value< Tomahawk::playlist_ptr >()->author()->friendlyName(); if ( author.indexOf( '@' ) > 0 ) author = author.mid( 0, author.indexOf( '@' ) ); const int w = painter->fontMetrics().width( author ) + 2; QRect avatarNameRect( opt.rect.width() - 10 - w, r.bottom(), w, opt.rect.bottom() - r.bottom() ); painter->drawText( avatarNameRect, author, QTextOption( Qt::AlignCenter ) ); const int leftEdge = opt.rect.width() - qMin( avatarNameRect.left(), r.left() ); QString descText; if ( type == RecentlyPlayedPlaylistsModel::Station ) { descText = index.data( RecentlyPlayedPlaylistsModel::DynamicPlaylistRole ).value< Tomahawk::dynplaylist_ptr >()->generator()->sentenceSummary(); } else { descText = index.data( RecentlyPlayedPlaylistsModel::ArtistRole ).toString(); } QColor c = painter->pen().color(); if ( !( option.state & QStyle::State_Selected && option.state & QStyle::State_Active ) ) { painter->setPen( QColor( Qt::gray ).darker() ); } QRect rectText = option.rect.adjusted( 66, 20, -leftEdge - 10, -8 ); #ifdef Q_WS_MAC rectText.adjust( 0, 1, 0, 0 ); #elif defined Q_WS_WIN rectText.adjust( 0, 2, 0, 0 ); #endif painter->drawText( rectText, descText ); painter->setPen( c ); painter->setFont( font ); painter->setFont( boldFont ); painter->drawText( option.rect.adjusted( 56, 6, -100, -option.rect.height() + 20 ), index.data().toString() ); painter->restore(); }
/* Prints a QPixmap, optionally displaying the print setup dialog first */ void PrintPixmap(QPixmap pixmap, bool displayDialog, QWidget *pParent, QPrinter *pPrinter) { bool deletePrinter = false; if (pixmap.isNull() == true) { return; } // Create a printer device. Analogous to a Windows device context if (pPrinter == NULL) { deletePrinter = true; pPrinter = new QPrinter(); if (pPrinter == NULL) { return; } } bool bPrint = true; if (displayDialog) { QPrintDialog dlg(pPrinter, pParent); if (dlg.exec() == QDialog::Rejected) { bPrint = false; } } if (bPrint == true) { double dAspect = 1.0; // the aspect ratio of the pixmap = width / height dAspect = static_cast<double>(pixmap.width()) / static_cast<double>(pixmap.height()); // the QPainter provides an interface for drawing to a device, analogous // to Windows GDI, with the printer being the device context in this case QPainter p; if (p.begin(pPrinter) == false) { if (deletePrinter) { delete pPrinter; } return; } QRect rcViewport = p.viewport(); // the printable area in device coords // Determine how large we can make the pixmap on the paper without // losing any of it off the edges of the paper. iPrintWidth and iPrintHeight // will be the size of the pixmap on the paper, in printer device coords. int iPrintWidth = rcViewport.width(); int iPrintHeight = rcViewport.height(); double pAspect = static_cast<double>(iPrintWidth) / static_cast<double>(iPrintHeight); // aspect ratio of the paper // unless the aspect ratios of the paper and pixmap are equal, we will have unused // space above and below or left and right of the printed image. double ratioAspects = pAspect / dAspect; if (ratioAspects > 1.0) { // paper is wider than the image: empty space left and right // reduce iPrintWidth accordingly iPrintWidth = iPrintWidth / ratioAspects; } else { // paper is taller than the image: empty space above and below // reduce iPrintHeight accordingly iPrintHeight = iPrintHeight * ratioAspects; } // specify the pixel dimensions of the pixmap p.setWindow(pixmap.rect()); // specify the location and size to draw the pixmap on the paper p.setViewport(rcViewport.left() + (rcViewport.width() - iPrintWidth) / 2, rcViewport.top() + (rcViewport.height() - iPrintHeight) / 2, iPrintWidth, iPrintHeight); // draw the pixmap to the print device p.drawPixmap(0, 0, pixmap); // tell the printer that we are done; this will trigger a form feed p.end(); } if (deletePrinter) { delete pPrinter; } }
void VisualFrame::setGeometry(QFrame::Shadow shadow, const QRect &inner, const QRect &outer) { // first call, generate corner regions if (corner[North].isEmpty() && s_cornerSize) { QBitmap bm(2*s_cornerSize, 2*s_cornerSize); bm.fill(Qt::black); QPainter p(&bm); p.setPen(Qt::NoPen); p.setBrush(Qt::white); p.drawEllipse(0,0,2*s_cornerSize,2*s_cornerSize); p.end(); QRegion circle(bm); corner[North] = circle & QRegion(0,0,s_cornerSize,s_cornerSize); // tl corner[South] = circle & QRegion(s_cornerSize,0,s_cornerSize,s_cornerSize); // tr corner[South].translate(-corner[South].boundingRect().left(), 0); corner[West] = circle & QRegion(0,s_cornerSize,s_cornerSize,s_cornerSize); // bl corner[West].translate(0, -corner[West].boundingRect().top()); corner[East] = circle & QRegion(s_cornerSize,s_cornerSize,s_cornerSize,s_cornerSize); // br corner[East].translate(-corner[East].boundingRect().topLeft()); } const Type t = type(shadow); notInited &= ~(1 << t); sizes[t][North] = inner.y() - outer.y(); sizes[t][South] = outer.bottom() - inner.bottom(); sizes[t][East] = outer.right() - inner.right(); sizes[t][West] = inner.x() - outer.x(); extends[t][North] = -outer.y(); extends[t][South] = outer.bottom() - 99; extends[t][East] = outer.right() - 99; extends[t][West] = -outer.x(); }
void LibraryItemDelegate::paintCoverOnTrack(QPainter *painter, const QStyleOptionViewItem &opt, const QStandardItem *track) const { Settings *settings = Settings::instance(); const QImage *image = _libraryTreeView->expandedCover(static_cast<AlbumItem*>(track->parent())); if (image && !image->isNull()) { // Copy QStyleOptionViewItem to be able to expand it to the left, and take the maximum available space QStyleOptionViewItem option(opt); option.rect.setX(0); int totalHeight = track->model()->rowCount(track->parent()->index()) * option.rect.height(); QImage scaled; QRect subRect; int row = _proxy->mapFromSource(track->index()).row(); if (totalHeight > option.rect.width()) { scaled = image->scaledToWidth(option.rect.width()); subRect = option.rect.translated(option.rect.width() - scaled.width(), -option.rect.y() + option.rect.height() * row); } else { scaled = image->scaledToHeight(totalHeight); int dx = option.rect.width() - scaled.width(); subRect = option.rect.translated(-dx, -option.rect.y() + option.rect.height() * row); } // Fill with white when there are too much tracks to paint (height of all tracks is greater than the scaled image) QImage subImage = scaled.copy(subRect); if (scaled.height() < subRect.y() + subRect.height()) { subImage.fill(option.palette.base().color()); } painter->save(); painter->setOpacity(1 - settings->coverBelowTracksOpacity()); painter->drawImage(option.rect, subImage); // Over paint black pixel in white QRect t(option.rect.x(), option.rect.y(), option.rect.width() - scaled.width(), option.rect.height()); QImage white(t.size(), QImage::Format_ARGB32); white.fill(option.palette.base().color()); painter->setOpacity(1.0); painter->drawImage(t, white); // Create a mix with 2 images: first one is a 3 pixels subimage of the album cover which is expanded to the left border // The second one is a computer generated gradient focused on alpha channel QImage leftBorder = scaled.copy(0, subRect.y(), 3, option.rect.height()); if (!leftBorder.isNull()) { // Because the expanded border can look strange to one, is blurred with some gaussian function leftBorder = leftBorder.scaled(t.width(), option.rect.height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); leftBorder = ImageUtils::blurred(leftBorder, leftBorder.rect(), 10, false); painter->setOpacity(1 - settings->coverBelowTracksOpacity()); painter->drawImage(t, leftBorder); QLinearGradient linearAlphaBrush(0, 0, leftBorder.width(), 0); linearAlphaBrush.setColorAt(0, QApplication::palette().base().color()); linearAlphaBrush.setColorAt(1, Qt::transparent); painter->setOpacity(1.0); painter->setCompositionMode(QPainter::CompositionMode_SourceOver); painter->setPen(Qt::NoPen); painter->setBrush(linearAlphaBrush); painter->drawRect(t); } painter->restore(); } // Display a light selection rectangle when one is moving the cursor painter->save(); QColor color = opt.palette.highlight().color(); color.setAlphaF(0.66); if (opt.state.testFlag(QStyle::State_MouseOver) && !opt.state.testFlag(QStyle::State_Selected)) { painter->setPen(opt.palette.highlight().color()); painter->setBrush(color.lighter(lighterValue)); painter->drawRect(opt.rect.adjusted(0, 0, -1, -1)); } else if (opt.state.testFlag(QStyle::State_Selected)) { // Display a not so light rectangle when one has chosen an item. It's darker than the mouse over painter->setPen(opt.palette.highlight().color()); painter->setBrush(color.lighter(150)); painter->drawRect(opt.rect.adjusted(0, 0, -1, -1)); } painter->restore(); }
static QRect inflateButtonRect(const QRect& originalRect) { QStyleOptionButton option; option.state |= QStyle::State_Small; option.rect = originalRect; QRect layoutRect = QApplication::style()->subElementRect(QStyle::SE_PushButtonLayoutItem, &option, 0); if (!layoutRect.isNull()) { int paddingLeft = layoutRect.left() - originalRect.left(); int paddingRight = originalRect.right() - layoutRect.right(); int paddingTop = layoutRect.top() - originalRect.top(); int paddingBottom = originalRect.bottom() - layoutRect.bottom(); return originalRect.adjusted(-paddingLeft, -paddingTop, paddingRight, paddingBottom); } else { return originalRect; } }
/** Check if color needs to be inverted then paint text. */ void LibraryItemDelegate::paintText(QPainter *p, const QStyleOptionViewItem &opt, const QRect &rectText, const QString &text, const QStandardItem *item) const { p->save(); if (text.isEmpty()) { p->setPen(opt.palette.mid().color()); QFontMetrics fmf(SettingsPrivate::instance()->font(SettingsPrivate::FF_Library)); p->drawText(rectText, Qt::AlignVCenter, fmf.elidedText(tr("(empty)"), Qt::ElideRight, rectText.width())); } else { if (opt.state.testFlag(QStyle::State_Selected) || opt.state.testFlag(QStyle::State_MouseOver)) { if (SettingsPrivate::instance()->isCustomTextColorOverriden()) { p->setPen(opt.palette.highlightedText().color()); } else if (qAbs(opt.palette.highlight().color().lighter(lighterValue).value() - opt.palette.highlightedText().color().value()) < 128) { p->setPen(opt.palette.text().color()); } else { p->setPen(opt.palette.highlightedText().color()); } } if (item->data(Miam::DF_Highlighted).toBool()) { QFont f = p->font(); f.setBold(true); p->setFont(f); } p->drawText(rectText, Qt::AlignVCenter, text); } p->restore(); }
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)); }
void UserListDelegate::paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const { // Get title, description and icon QIcon mediaIcon = QIcon(qvariant_cast<QIcon>(index.data(Qt::DecorationRole))); QString title = index.data(Qt::DisplayRole).toString(); QString description = index.data(Qt::UserRole + 1).toString(); QString time = index.data(Qt::ToolTipRole).toString(); QRect r = option.rect; QPen linePen(QColor::fromRgb(211,211,211), 1, Qt::SolidLine); QPen lineMarkedPen(QColor::fromRgb(0,90,131), 1, Qt::SolidLine); QPen fontPen(QColor::fromRgb(51,51,51), 1, Qt::SolidLine); QPen fontMarkedPen(Qt::white, 1, Qt::SolidLine); // If a user is selected (pressed), changing the color(background) and size of the border area if (option.state & QStyle::State_Selected) { QLinearGradient gradientSelected(r.left(),r.top(),r.left(),r.height()+r.top()); gradientSelected.setColorAt(0.0, QColor::fromRgb(195,213,255)); gradientSelected.setColorAt(1.0, QColor::fromRgb(177,215,246)); painter->setBrush(gradientSelected); painter->drawRect(r); //BORDER painter->setPen(lineMarkedPen); painter->drawLine(r.topLeft(),r.topRight()); painter->drawLine(r.topRight(),r.bottomRight()); painter->drawLine(r.bottomLeft(),r.bottomRight()); painter->drawLine(r.topLeft(),r.bottomLeft()); painter->setPen(fontMarkedPen); } else { //BACKGROUND //ALTERNATING COLORS painter->setBrush( (index.row() % 2) ? Qt::white : QColor(252,252,252) ); painter->drawRect(r); //BORDER painter->setPen(linePen); painter->drawLine(r.topLeft(),r.topRight()); painter->drawLine(r.topRight(),r.bottomRight()); painter->drawLine(r.bottomLeft(),r.bottomRight()); painter->drawLine(r.topLeft(),r.bottomLeft()); painter->setPen(fontPen); } // The offset for the installation image int imageSpace = 10; if (!mediaIcon.isNull()) { r = option.rect.adjusted(2, 2, -1, -1); mediaIcon.paint(painter, r, Qt::AlignVCenter|Qt::AlignLeft); imageSpace = 85; } //TITLE r = option.rect.adjusted(imageSpace, 10, -10, -27); painter->setFont( QFont( "Lucida Grande", 12, QFont::Normal ) ); painter->drawText(r.left(), r.top(), r.width(), r.height(), Qt::AlignTop|Qt::AlignLeft, title, &r); // TIME r = option.rect.adjusted(60, 10, -10, -27); painter->setFont( QFont( "Lucida Grande", 8, QFont::Normal ) ); painter->drawText(r.left(), r.top(), r.width(), r.height(), Qt::AlignTop|Qt::AlignRight, time , &r); //DESCRIPTION r = option.rect.adjusted(imageSpace, 35, -10, 10); painter->setFont( QFont( "Lucida Grande", 8, QFont::Normal ) ); //If the last message is long, it is cut, for convenient display if (description.size() > 30) { description.remove(30, description.size()); description.append("..."); } painter->drawText(r.left(), r.top(), r.width(), r.height(), Qt::AlignLeft, description, &r); }
//___________________________________________________________ void TileSet::render(const QRect &r, QPainter *p, Tiles t) const { const bool oldHint( p->testRenderHint( QPainter::SmoothPixmapTransform ) ); if( _stretch ) p->setRenderHint( QPainter::SmoothPixmapTransform, true ); // check initialization if( _pixmaps.size() < 9 ) return; int x0, y0, w, h; r.getRect(&x0, &y0, &w, &h); // calculate pixmaps widths int wLeft(0); int wRight(0); if( _w1+_w3 > 0 ) { qreal wRatio( qreal( _w1 )/qreal( _w1 + _w3 ) ); wLeft = (t&Right) ? qMin( _w1, int(w*wRatio) ):_w1; wRight = (t&Left) ? qMin( _w3, int(w*(1.0-wRatio)) ):_w3; } // calculate pixmap heights int hTop(0); int hBottom(0); if( _h1+_h3 > 0 ) { qreal hRatio( qreal( _h1 )/qreal( _h1 + _h3 ) ); hTop = (t&Bottom) ? qMin( _h1, int(h*hRatio) ):_h1; hBottom = (t&Top) ? qMin( _h3, int(h*(1.0-hRatio)) ):_h3; } // calculate corner locations w -= wLeft + wRight; h -= hTop + hBottom; const int x1 = x0 + wLeft; const int x2 = x1 + w; const int y1 = y0 + hTop; const int y2 = y1 + h; const int w2 = _pixmaps.at(7).width(); const int h2 = _pixmaps.at(5).height(); // corner if( bits(t, Top|Left) ) p->drawPixmap(x0, y0, _pixmaps.at(0), 0, 0, wLeft, hTop); if( bits(t, Top|Right) ) p->drawPixmap(x2, y0, _pixmaps.at(2), _w3-wRight, 0, wRight, hTop); if( bits(t, Bottom|Left) ) p->drawPixmap(x0, y2, _pixmaps.at(6), 0, _h3-hBottom, wLeft, hBottom); if( bits(t, Bottom|Right) ) p->drawPixmap(x2, y2, _pixmaps.at(8), _w3-wRight, _h3-hBottom, wRight, hBottom ); // top and bottom if( w > 0 ) { if (t & Top ) { if( _stretch ) p->drawPixmap(x1, y0, w, hTop, _pixmaps.at(1)); else p->drawTiledPixmap(x1, y0, w, hTop, _pixmaps.at(1)); } if (t & Bottom ) { if( _stretch ) p->drawPixmap(x1, y2, w, hBottom, _pixmaps.at(7), 0, _h3-hBottom, w2, hBottom ); else p->drawTiledPixmap(x1, y2, w, hBottom, _pixmaps.at(7), 0, _h3-hBottom ); } } // left and right if( h > 0 ) { if (t & Left ) { if( _stretch ) p->drawPixmap(x0, y1, wLeft, h, _pixmaps.at(3)); else p->drawTiledPixmap(x0, y1, wLeft, h, _pixmaps.at(3)); } if (t & Right ) { if( _stretch ) p->drawPixmap(x2, y1, wRight, h, _pixmaps.at(5), _w3-wRight, 0, wRight, h2 ); else p->drawTiledPixmap(x2, y1, wRight, h, _pixmaps.at(5), _w3-wRight, 0 ); } } // center if ( (t & Center) && h > 0 && w > 0 ) { if( _stretch ) p->drawPixmap(x1, y1, w, h, _pixmaps.at(4)); else p->drawTiledPixmap(x1, y1, w, h, _pixmaps.at(4)); } if( _stretch ) p->setRenderHint( QPainter::SmoothPixmapTransform, oldHint ); }
void PartitionBarsView::drawSection( QPainter* painter, const QRect& rect_, int x, int width, const QModelIndex& index ) { QColor color = index.isValid() ? index.data( Qt::DecorationRole ).value< QColor >() : ColorUtils::unknownDisklabelColor(); bool isFreeSpace = index.isValid() ? index.data( PartitionModel::IsFreeSpaceRole ).toBool() : true; QRect rect = rect_; const int y = rect.y(); const int height = rect.height(); const int radius = qMax( 1, CORNER_RADIUS - ( VIEW_HEIGHT - height ) / 2 ); painter->setClipRect( x, y, width, height ); painter->translate( 0.5, 0.5 ); rect.adjust( 0, 0, -1, -1 ); if ( selectionMode() != QAbstractItemView::NoSelection && // no hover without selection m_hoveredIndex.isValid() && index == m_hoveredIndex ) { if ( canBeSelected( index ) ) painter->setBrush( color.lighter( 115 ) ); else painter->setBrush( color ); } else { painter->setBrush( color ); } QColor borderColor = color.darker(); painter->setPen( borderColor ); painter->drawRoundedRect( rect, radius, radius ); // Draw shade if ( !isFreeSpace ) rect.adjust( 2, 2, -2, -2 ); QLinearGradient gradient( 0, 0, 0, height / 2 ); qreal c = isFreeSpace ? 0 : 1; gradient.setColorAt( 0, QColor::fromRgbF( c, c, c, 0.3 ) ); gradient.setColorAt( 1, QColor::fromRgbF( c, c, c, 0 ) ); painter->setPen( Qt::NoPen ); painter->setBrush( gradient ); painter->drawRoundedRect( rect, radius, radius ); if ( selectionMode() != QAbstractItemView::NoSelection && index.isValid() && selectionModel() && !selectionModel()->selectedIndexes().isEmpty() && selectionModel()->selectedIndexes().first() == index ) { painter->setPen( QPen( borderColor, 1 ) ); QColor highlightColor = QPalette().highlight().color(); highlightColor = highlightColor.lighter( 500 ); highlightColor.setAlpha( 120 ); painter->setBrush( highlightColor ); QRect selectionRect = rect; selectionRect.setX( x + 1 ); selectionRect.setWidth( width - 3 ); //account for the previous rect.adjust if ( rect.x() > selectionRect.x() ) //hack for first item selectionRect.adjust( rect.x() - selectionRect.x(), 0, 0, 0 ); if ( rect.right() < selectionRect.right() ) //hack for last item selectionRect.adjust( 0, 0, - ( selectionRect.right() - rect.right() ), 0 ); selectionRect.adjust( SELECTION_MARGIN, SELECTION_MARGIN, -SELECTION_MARGIN, -SELECTION_MARGIN ); painter->drawRoundedRect( selectionRect, radius - 1, radius - 1 ); } painter->translate( -0.5, -0.5 ); }
void CompositorHelper::handleLeaveEvent() { if (shouldCaptureMouse()) { //QWidget* mainWidget = (QWidget*)qApp->getWindow(); static auto renderingWidget = PluginContainer::getInstance().getPrimaryWidget(); static QWidget* mainWidget = nullptr; if (mainWidget == nullptr) { mainWidget = renderingWidget->parentWidget(); } QRect mainWidgetFrame; { mainWidgetFrame = renderingWidget->geometry(); auto topLeft = mainWidgetFrame.topLeft(); auto topLeftScreen = renderingWidget->mapToGlobal(topLeft); mainWidgetFrame.moveTopLeft(topLeftScreen); } QRect uncoveredRect = mainWidgetFrame; foreach(QWidget* widget, QApplication::topLevelWidgets()) { if (widget->isWindow() && widget->isVisible() && widget != mainWidget) { QRect widgetFrame = widget->frameGeometry(); if (widgetFrame.intersects(uncoveredRect)) { QRect intersection = uncoveredRect & widgetFrame; if (intersection.top() > uncoveredRect.top()) { uncoveredRect.setBottom(intersection.top() - 1); } else if (intersection.bottom() < uncoveredRect.bottom()) { uncoveredRect.setTop(intersection.bottom() + 1); } if (intersection.left() > uncoveredRect.left()) { uncoveredRect.setRight(intersection.left() - 1); } else if (intersection.right() < uncoveredRect.right()) { uncoveredRect.setLeft(intersection.right() + 1); } } } } _ignoreMouseMove = true; auto sendToPos = uncoveredRect.center(); QCursor::setPos(sendToPos); _lastKnownRealMouse = sendToPos; } }
// QListView does item layout in a very inflexible way, so let's do our custom layout again. // FIXME: this is very inefficient, but due to the design flaw of QListView, this is currently the only workaround. void DesktopWindow::relayoutItems() { loadItemPositions(); // something may have changed // qDebug("relayoutItems()"); if(relayoutTimer_) { // this slot might be called from the timer, so we cannot delete it directly here. relayoutTimer_->deleteLater(); relayoutTimer_ = NULL; } QDesktopWidget* desktop = qApp->desktop(); int screen = 0; int row = 0; int rowCount = proxyModel_->rowCount(); for(;;) { if(desktop->isVirtualDesktop()) { if(screen >= desktop->numScreens()) break; }else { screen = screenNum_; } QRect workArea = desktop->availableGeometry(screen); workArea.adjust(12, 12, -12, -12); // add a 12 pixel margin to the work area // qDebug() << "workArea" << screen << workArea; // FIXME: we use an internal class declared in a private header here, which is pretty bad. QSize grid = listView_->gridSize(); QPoint pos = workArea.topLeft(); for(; row < rowCount; ++row) { QModelIndex index = proxyModel_->index(row, 0); int itemWidth = delegate_->sizeHint(listView_->getViewOptions(), index).width(); FmFileInfo* file = proxyModel_->fileInfoFromIndex(index); QByteArray name = fm_file_info_get_name(file); QHash<QByteArray, QPoint>::iterator it = customItemPos_.find(name); if(it != customItemPos_.end()) { // the item has a custom position QPoint customPos = *it; // center the contents vertically listView_->setPositionForIndex(customPos + QPoint((grid.width() - itemWidth) / 2, 0), index); // qDebug() << "set custom pos:" << name << row << index << customPos; continue; } // check if the current pos is alredy occupied by a custom item bool used = false; for(it = customItemPos_.begin(); it != customItemPos_.end(); ++it) { QPoint customPos = *it; if(QRect(customPos, grid).contains(pos)) { used = true; break; } } if(used) { // go to next pos --row; } else { // center the contents vertically listView_->setPositionForIndex(pos + QPoint((grid.width() - itemWidth) / 2, 0), index); // qDebug() << "set pos" << name << row << index << pos; } // move to next cell in the column pos.setY(pos.y() + grid.height() + listView_->spacing()); if(pos.y() + grid.height() > workArea.bottom() + 1) { // if the next position may exceed the bottom of work area, go to the top of next column pos.setX(pos.x() + grid.width() + listView_->spacing()); pos.setY(workArea.top()); // check if the new column exceeds the right margin of work area if(pos.x() + grid.width() > workArea.right() + 1) { if(desktop->isVirtualDesktop()) { // in virtual desktop mode, go to next screen ++screen; break; } } } } if(row >= rowCount) break; } }
void toPieChart::paintChart(QPainter *p, QRect rect) { QFontMetrics fm = p->fontMetrics(); int right = rect.width(); int bottom = rect.height(); double tot = 0; { for (std::list<double>::iterator i = Values.begin(); i != Values.end(); i++) tot += *i; } if (!Title.isEmpty()) { p->save(); QFont f = p->font(); f.setBold(true); p->setFont(f); QRect bounds = fm.boundingRect(0, 0, rect.width(), rect.height(), FONT_ALIGN, Title); p->drawText(0, 2, rect.width(), bounds.height(), Qt::AlignHCenter | Qt::AlignTop, Title); p->restore(); p->translate(0, bounds.height() + 2); bottom -= bounds.height() + 2; } if (Legend) { int lwidth = 0; int lheight = 0; toResult *Result = dynamic_cast<toResult *>(this); std::list<double>::iterator j = Values.begin(); { for (std::list<QString>::iterator i = Labels.begin(); i != Labels.end(); i++) { QString sizstr; if (j != Values.end()) { if (DisplayPercent) sizstr.sprintf("%0.1f", 100 * (*j) / tot); else sizstr = toQValue::formatNumber(*j); sizstr += Postfix; } if (!(*i).isEmpty()) { QString str = Utils::toTranslateMayby(Result ? Result->sqlName() : QString::fromLatin1("toPieChart"), *i); str += QString::fromLatin1(" ("); str += sizstr; str += QString::fromLatin1(")"); QRect bounds = fm.boundingRect(0, 0, 10000, 10000, FONT_ALIGN, str); if (lwidth < bounds.width()) lwidth = bounds.width(); lheight += bounds.height(); } } if (j != Values.end()) j++; } if (lheight > 0) { lheight += 4; lwidth += 14; } int lx = rect.width() - lwidth - 2; int ly = 2; if (lx < 50) lx = 50; right = lx; p->save(); p->setBrush(Qt::white); p->drawRect(lx, ly, lwidth, lheight); p->restore(); lx += 12; ly += 2; int cp = 0; j = Values.begin(); for (std::list<QString>::iterator i = Labels.begin(); i != Labels.end(); i++) { QString sizstr; if (j != Values.end()) { if (DisplayPercent) sizstr.sprintf("%0.1f", 100 * (*j) / tot); else sizstr = toQValue::formatNumber(*j); sizstr += Postfix; } if (!(*i).isEmpty()) { QString str = Utils::toTranslateMayby(Result ? Result->sqlName() : QString::fromLatin1("toPieChart"), *i); str += QString::fromLatin1(" ("); str += sizstr; str += QString::fromLatin1(")"); QRect bounds = fm.boundingRect(lx, ly, 100000, 100000, FONT_ALIGN, str); p->drawText(bounds, FONT_ALIGN, str); p->save(); QBrush brush(Utils::toChartBrush(cp)); p->setBrush(brush.color()); p->drawRect(lx - 10, ly + bounds.height() / 2 - fm.ascent() / 2, 8, fm.ascent()); if (brush.style() != Qt::SolidPattern) { p->setBrush(QBrush(Qt::white, brush.style())); p->drawRect(lx - 10, ly + bounds.height() / 2 - fm.ascent() / 2, 8, fm.ascent()); } p->restore(); ly += bounds.height(); } cp++; if (j != Values.end()) j++; } } if (tot == 0) { p->drawText(QRect(2, 2, right - 4, bottom - 4), Qt::AlignCenter// | Qt::WordBreak , tr("All values are 0 in this chart")); return ; } int cp = 0; int pos = 0; unsigned int count = 0; ChartRect = p->combinedTransform().mapRect(QRect(2, 2, right - 4, bottom - 4)); Angels.clear(); for (std::list<double>::iterator i = Values.begin(); i != Values.end(); i++) { count++; int size = int(*i * 5760 / tot); if (count == Values.size()) size = 5760 - pos; if (size > 0) { p->save(); QBrush brush(Utils::toChartBrush(cp)); p->setBrush(brush.color()); p->drawPie(2, 2, right - 4, bottom - 4, pos, size); if (brush.style() != Qt::SolidPattern) { p->setBrush(QBrush(Qt::white, brush.style())); p->drawPie(2, 2, right - 4, bottom - 4, pos, size); } p->restore(); pos += size; } Angels.insert(Angels.end(), pos); cp++; } }
void SingleCellViewGraphPanelPlotOverlayWidget::drawCoordinates(QPainter *pPainter, const QPoint &pPoint, const QColor &pBackgroundColor, const QColor &pForegroundColor, const Location &pLocation, const bool &pCanMoveLocation) { // Retrieve the size of coordinates as they will appear on the screen, // which means using the same font as the one used for the axes // Note: normally, pPoint would be a QPointF, but we want the coordinates to // be drawn relative to something (see paintEvent()) and the only way // to guarantee that everything will be painted as expected is to use // QPoint. Indeed, if we were to use QPointF, then QPainter would have // to do some rouding and though everything should be fine (since we // always add/subtract a rounded number), it happens that it's not // always the case. Indeed, we should always have a gap of one pixel // between the coordinates and pPoint, but it could happen that we // have either no gap or one of two pixels... pPainter->setFont(mOwner->axisFont(QwtPlot::xBottom)); QPointF point = mOwner->canvasPoint(pPoint, false); QString coordinates = QString("X: %1\nY: %2").arg(QLocale().toString(point.x(), 'g', 15), QLocale().toString(point.y(), 'g', 15)); QRect coordinatesRect = pPainter->boundingRect(qApp->desktop()->availableGeometry(), 0, coordinates); // Determine where the coordinates and its background should be drawn switch (pLocation) { case TopLeft: coordinatesRect.moveTo(pPoint.x()-coordinatesRect.width()-1, pPoint.y()-coordinatesRect.height()-1); break; case TopRight: coordinatesRect.moveTo(pPoint.x()+2, pPoint.y()-coordinatesRect.height()-1); break; case BottomLeft: coordinatesRect.moveTo(pPoint.x()-coordinatesRect.width()-1, pPoint.y()+2); break; case BottomRight: coordinatesRect.moveTo(pPoint.x()+2, pPoint.y()+2); break; } if (pCanMoveLocation) { QwtScaleMap canvasMapX = mOwner->canvasMap(QwtPlot::xBottom); QwtScaleMap canvasMapY = mOwner->canvasMap(QwtPlot::yLeft); QPoint topLeftPoint = QPoint(canvasMapX.transform(mOwner->minX()), canvasMapY.transform(mOwner->maxY())); QPoint bottomRightPoint = QPoint(canvasMapX.transform(mOwner->maxX()), canvasMapY.transform(mOwner->minY())); if (coordinatesRect.top() < topLeftPoint.y()) coordinatesRect.moveTop(pPoint.y()+2); else if (coordinatesRect.top()+coordinatesRect.height()-1 > bottomRightPoint.y()) coordinatesRect.moveTop(pPoint.y()-coordinatesRect.height()-1); if (coordinatesRect.left() < topLeftPoint.x()) coordinatesRect.moveLeft(pPoint.x()+2); else if (coordinatesRect.left()+coordinatesRect.width()-1 > bottomRightPoint.x()) coordinatesRect.moveLeft(pPoint.x()-coordinatesRect.width()-1); // Note: the -1 for the else-if tests is because fillRect() below works // on (0, 0; width-1, height-1)... } // Draw a filled rectangle to act as the background for the coordinates // we are to show pPainter->fillRect(coordinatesRect, pBackgroundColor); // Draw the text for the coordinates, using a white pen QPen pen = pPainter->pen(); pen.setColor(pForegroundColor); pPainter->setPen(pen); pPainter->drawText(coordinatesRect, coordinates); }
int KReportItemField::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) { OROTextBox * tb = new OROTextBox(); tb->setPosition(scenePosition(position()) + offset); tb->setSize(sceneSize(size())); tb->setFont(font()); tb->setFlags(textFlags()); tb->setTextStyle(textStyle()); tb->setLineStyle(lineStyle()); tb->setCanGrow(m_canGrow->value().toBool()); tb->setWordWrap(m_wordWrap->value().toBool()); QString str; QString ids = itemDataSource(); if (!ids.isEmpty()) { #ifdef KREPORT_SCRIPTING if (ids.left(1) == QLatin1String("=") && script) { //Everything after = is treated as code if (!ids.contains(QLatin1String("PageTotal()"))) { QVariant v = script->evaluate(ids.mid(1)); str = v.toString(); } else { str = ids.mid(1); tb->setRequiresPostProcessing(true); } } else #else Q_UNUSED(script); #endif if (ids.left(1) == QLatin1String("$")) { //Everything past $ is treated as a string str = ids.mid(1); } else { str = data.toString(); } } else { str = m_itemValue->value().toString(); } tb->setText(str); //Work out the size of the text if (tb->canGrow()) { QRect r; if (tb->wordWrap()) { //Grow vertically QFontMetrics metrics(font()); QRect temp(tb->position().x(), tb->position().y(), tb->size().width(), 5000); // a large vertical height r = metrics.boundingRect(temp, tb->flags(), str); } else { //Grow Horizontally QFontMetrics metrics(font()); QRect temp(tb->position().x(), tb->position().y(), 5000, tb->size().height()); // a large vertical height r = metrics.boundingRect(temp, tb->flags(), str); } tb->setSize(r.size() + QSize(4,4)); } if (page) { page->insertPrimitive(tb); } if (section) { OROPrimitive *clone = tb->clone(); clone->setPosition(scenePosition(position())); section->addPrimitive(clone); } int height = scenePosition(position()).y() + tb->size().height(); //If there is no page to add the item to, delete it now because it wont be deleted later if (!page) { delete tb; } return height; }
void DeckButtonsLayout::setGeometry( const QRect& _r ) { QLayout::setGeometry( _r ); int left; int top; int right; int bottom; getContentsMargins( &left, &top, &right, &bottom ); const QRect r = _r.adjusted( left, top, right, bottom ); const QAbstractButton* button = backwardButton ? backwardButton : forwardButton; qreal factor = 1; if ( !button ) { if ( RoundButton ) { const int min = qMin( r.height(), r.width() ); QRect rect = QRect( QPoint(), QSize( min, min ) ); rect.moveCenter( r.center() ); RoundButton->setGeometry( rect ); } return; } else if ( backwardButton && forwardButton ) { factor = (qreal)r.width() /(qreal)( button->sizeHint().width() *2 ); } else if ( RoundButton ) { factor = (qreal)r.width() /(qreal)( button->sizeHint().width() +( RoundButton->sizeHint().width() /2 ) ); } else { factor = (qreal)r.width() /(qreal)( button->sizeHint().width() ); } if ( RoundButton ) { int height = (qreal)RoundButton->sizeHint().height() *factor; while ( height > r.height() ) { factor -= 0.1; height = (qreal)RoundButton->sizeHint().height() *factor; } QRect rect( QPoint(), QSize( height, height ) ); rect.moveCenter( r.center() ); if ( backwardButton && forwardButton ) { // nothing to do } else if ( backwardButton ) { rect.moveRight( r.right() ); } else if ( forwardButton ) { rect.moveLeft( r.left() ); } RoundButton->setGeometry( rect ); } else { int height = (qreal)button->sizeHint().height() *factor; while ( height > r.height() ) { factor -= 0.1; height = (qreal)button->sizeHint().height() *factor; } } const QSize bs = QSize( (qreal)button->sizeHint().width() *factor, (qreal)button->sizeHint().height() *factor ); if ( backwardButton ) { QRect gr = RoundButton ? QRect( QPoint(), RoundButton->size() ) : r; QRect rect = QRect( QPoint(), bs ); if ( RoundButton ) { gr.moveTopLeft( RoundButton->pos() ); } rect.moveCenter( gr.center() ); rect.moveRight( gr.center().x() +1 ); backwardButton->setGeometry( rect ); } if ( forwardButton ) { QRect gr = RoundButton ? QRect( QPoint(), RoundButton->size() ) : r; QRect rect = QRect( QPoint(), bs ); if ( RoundButton ) { gr.moveTopLeft( RoundButton->pos() ); } rect.moveCenter( gr.center() ); rect.moveLeft( gr.center().x() ); forwardButton->setGeometry( rect ); } if ( RoundButton ) { RoundButton->raise(); } }
/** Albums have covers usually. */ void LibraryItemDelegate::drawAlbum(QPainter *painter, QStyleOptionViewItem &option, QStandardItem *item) const { /// XXX: reload cover with high resolution when one has increased coverSize (every 64px) static QImageReader imageReader; SettingsPrivate *settingsPrivate = SettingsPrivate::instance(); // Album has no picture yet bool itemHasNoIcon = item->icon().isNull(); if (itemHasNoIcon) { // Check first if an inner cover should be displayed if (item->data(Miam::DF_InternalCover).toString().isEmpty()) { QString coverPath = item->data(Miam::DF_CoverPath).toString(); if (!coverPath.isEmpty()) { // qDebug() << Q_FUNC_INFO << "loading external cover from harddrive"; imageReader.setFileName(QDir::fromNativeSeparators(coverPath)); imageReader.setScaledSize(QSize(_coverSize, _coverSize)); item->setIcon(QPixmap::fromImage(imageReader.read())); itemHasNoIcon = false; } } else { FileHelper fh(item->data(Miam::DF_InternalCover).toString()); std::unique_ptr<Cover> cover(fh.extractCover()); if (cover) { QPixmap p; if (p.loadFromData(cover->byteArray(), cover->format())) { if (!p.isNull()) { item->setIcon(p); itemHasNoIcon = false; } //} else { // qDebug() << Q_FUNC_INFO << "couldn't load data into QPixmap"; } //} else { // qDebug() << Q_FUNC_INFO << "couldn't extract inner cover"; } } } painter->save(); QRect cover; if (QGuiApplication::isLeftToRight()) { cover = QRect(option.rect.x() + 1, option.rect.y() + 1, _coverSize, _coverSize); } else { cover = QRect(option.rect.width() + 19 - _coverSize - 1, option.rect.y() + 1, _coverSize, _coverSize); } // If font size is greater than the cover, align it if (_coverSize < option.rect.height() - 2) { painter->translate(0, (option.rect.height() - 1 - _coverSize) / 2); } if (itemHasNoIcon) { if (_iconOpacity <= 0.25) { painter->setOpacity(_iconOpacity); } else { painter->setOpacity(0.25); } painter->drawPixmap(cover, QPixmap(":/icons/disc")); } else { painter->setOpacity(_iconOpacity); QPixmap p = option.icon.pixmap(QSize(_coverSize, _coverSize)); painter->drawPixmap(cover, p); } painter->restore(); // Add an icon on the right if album is from some remote location bool isRemote = item->data(Miam::DF_IsRemote).toBool(); int offsetWidth = 0; if (isRemote) { int iconSize = 31; QRect iconRemoteRect(option.rect.x() + option.rect.width() - (iconSize + 4), (option.rect.height() - iconSize)/ 2 + option.rect.y() + 2, iconSize, iconSize); QPixmap iconRemote(item->data(Miam::DF_IconPath).toString()); painter->save(); painter->setOpacity(0.5); painter->drawPixmap(iconRemoteRect, iconRemote); painter->restore(); offsetWidth = iconSize; } option.textElideMode = Qt::ElideRight; QRect rectText; // It's possible to have missing covers in your library, so we need to keep alignment. if (QGuiApplication::isLeftToRight()) { rectText = QRect(option.rect.x() + _coverSize + 5, option.rect.y(), option.rect.width() - (_coverSize + 7) - offsetWidth, option.rect.height() - 1); } else { rectText = QRect(option.rect.x(), option.rect.y(), option.rect.width() - _coverSize - 5, option.rect.height()); } QFontMetrics fmf(settingsPrivate->font(SettingsPrivate::FF_Library)); QString s = fmf.elidedText(option.text, Qt::ElideRight, rectText.width()); this->paintText(painter, option, rectText, s, item); }
QRect& glViewRect::GetTileNumbers() { QRect r; r.setCoords(x_start, y_start, x_end, y_end); return r; }
void QRoundedRect::compile(QSqlDatabase &db, int nSceneId,int &count,int index) { count++; //QBasicGraphicsItem::compile(db, nSceneId, count, index); QSqlQuery sqlquery(db); sqlquery.prepare("INSERT INTO polygon(nItemId ,nSceneId,ePolygonClass,eLineType ,nLineWidth,nLineColor," "eStyle,nBackColor,nForeColor,nAlpha,nPointX,nPointY,nWidth,nHeight,nRadius,eCornerType," "nZvalue,nCollidindId)" "VALUES (:nItemId,:nSceneId,:ePolygonClass ,:eLineType ,:nLineWidth,:nLineColor,:eStyle," ":nBackColor,:nForeColor,:nAlpha,:nPointX,:nPointY,:nWidth,:nHeight,:nRadius,:eCornerType," ":nZvalue,:nCollidindId)"); sqlquery.bindValue(":nItemId",QVariant(count));// 表 id sqlquery.bindValue(":nSceneId",QVariant(nSceneId));// 所在场景 id sqlquery.bindValue(":ePolygonClass",QVariant(4)); //4 代表类型为圆角矩形 sqlquery.bindValue(":eLineType",QVariant(nLineType+1));// 线形 sqlquery.bindValue(":nLineWidth",QVariant(GetLineWidth()));// 线宽 sqlquery.bindValue(":nLineColor",QVariant(ColorToInt(GetLineColor()))); //颜色 sqlquery.bindValue(":eStyle",QVariant(GetPattern()+1));// 样式 sqlquery.bindValue(":nBackColor",QVariant(ColorToInt(GetBackColor()))); //背景色 sqlquery.bindValue(":nForeColor",QVariant(ColorToInt(GetFrontColor()))); //前景色 sqlquery.bindValue(":nAlpha",QVariant(GetAlpha()));// 透明度 QRect rect = this->sceneBoundingRect().toRect(); sqlquery.bindValue(":nStartX",QVariant(rect.x()));//x sqlquery.bindValue(":nStartY",QVariant(rect.y()));//y sqlquery.bindValue(":nWidth",QVariant(rect.width()));//w sqlquery.bindValue(":nHeight",QVariant(rect.height()));//h sqlquery.bindValue(":nRadius",QVariant(GetxRadius())); // sqlquery.bindValue(":eCornerType",QVariant(GetyRadius())); // sqlquery.bindValue(":nZvalue",QVariant(zValue()));//层次 sqlquery.bindValue(":nCollidindId",QVariant(index));//碰撞ID bool result = false; result = sqlquery.exec(); qDebug() << "insert RoundedRect table :"<<result; SamDrawScene *pScene = dynamic_cast<SamDrawScene *>(scene()); if(pScene && pScene->nIsSceneOrWindow == 2) { //是自定义键盘的item //先新建键盘——item关联表 item表在派生类中创建 //QSqlQuery sqlquery(db); sqlquery.prepare("INSERT INTO kbAndItem(nKeyBoardId , nItemId ,nId,nItemTableType ) " "VALUES (:nKeyBoardId ,:nItemId ,:nId,:nItemTableType)"); sqlquery.bindValue(":nKeyBoardId",QVariant(nSceneId)); sqlquery.bindValue(":nItemId",QVariant(count)); sqlquery.bindValue(":nId",QVariant(id())); sqlquery.bindValue(":nItemTableType",QVariant((int)SAM_DRAW_OBJECT_ROUNDEDRECT)); bool result = false; result = sqlquery.exec(); qDebug() << "insert kbAndItem table :"<<result; } if(pScene && pScene->nIsSceneOrWindow != 2) { //窗口或者场景item //先新建键盘——item关联表 //item表在派生类中创建 //QSqlQuery sqlquery(db); sqlquery.prepare("INSERT INTO sceneAndItem(nSceneId,nItemId,nId,nItemTableType)" "VALUES(:nSceneId,:nItemId,:nId,:nItemTableType)"); sqlquery.bindValue(":nSceneId",QVariant(nSceneId)); sqlquery.bindValue(":nItemId",QVariant(count)); sqlquery.bindValue(":nId",QVariant(id())); //int t = this->GroupType(); sqlquery.bindValue(":nItemTableType",QVariant((int)SAM_DRAW_OBJECT_ROUNDEDRECT)); bool result = false; result = sqlquery.exec(); qDebug() << "insert sceneAndItem table :"<<result; } }