本文整理汇总了C++中QRect类的典型用法代码示例。如果您正苦于以下问题:C++ QRect类的具体用法?C++ QRect怎么用?C++ QRect使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QRect类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetHandle
void wxWindowQt::DoGetClientSize(int *width, int *height) const
{
QRect geometry = GetHandle()->geometry();
if (width) *width = geometry.width();
if (height) *height = geometry.height();
}
示例2: map
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;
}
}
}
示例3: double
/*!
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();
}
}
示例4: paint_all
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 );
//.........这里部分代码省略.........
示例5: QString
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();
}
}
示例6: maskImage
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;
}
示例7: paintContact
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");
//.........这里部分代码省略.........
示例8: rect
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);
//.........这里部分代码省略.........
示例9: rectangleToString
// 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;
}
示例10: Pixelator
//.........这里部分代码省略.........
//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();
}
示例11: f
/*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();
}
示例12: initStyleOption
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
//.........这里部分代码省略.........
示例13: PrintPixmap
/* 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;
}
}
示例14: bm
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();
}
示例15: option
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();
}