void FSTaskDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QString title = index.data(FSAbstractTaskModel::TitleRole).toString(); QString subTitle = index.data(FSAbstractTaskModel::SubTitleRole).toString(); int progress = index.data(FSAbstractTaskModel::ProgressRole).toInt(); QString mimeIconPath = index.data(FSAbstractTaskModel::MimeIconRole).toString(); // QString actionIconPath= index.data(FSAbstractTaskModel::TitleRole).toString(); if (option.state & QStyle::State_Selected) { painter->setPen(Qt::NoPen); painter->setBrush(QBrush(QColor("#316AC5"))); painter->drawRect(option.rect); } painter->setPen(QPen(Qt::black)); QPixmap icon (mimeIconPath); painter->drawPixmap(5, option.rect.center().y()-icon.height()/2, icon); QRect progressRect = option.rect; progressRect.setX(40); progressRect.setY(option.rect.center().y() - 7); progressRect.setRight(option.rect.right() - 30); progressRect.setHeight(progress < 100 ? 14 : 1); if (progress <100) { QStyleOptionProgressBar progressBarOption; progressBarOption.rect = progressRect; progressBarOption.minimum = 0; progressBarOption.maximum = 100; progressBarOption.progress = progress; progressBarOption.text = QString::number(progress) + "%"; progressBarOption.textVisible = true; progressBarOption.textAlignment = Qt::AlignCenter; qApp->style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, painter); QFontMetrics metrics(painter->font()); if ((option.state & QStyle::State_Selected)) painter->setPen(QPen(Qt::white)); else painter->setPen(QPen(Qt::black)); painter->setFont(QFont(painter->font().family(),10)); painter->drawText(progressRect.topLeft()-QPoint(-5,5),title); painter->setFont(QFont(painter->font().family(),8)); painter->drawText(progressRect.bottomLeft()+QPoint(5,5+metrics.height()), subTitle); } else { QFontMetrics metrics(painter->font()); painter->setFont(QFont(painter->font().family(),10)); painter->drawText(progressRect.topLeft(),title); painter->setFont(QFont(painter->font().family(),8)); painter->drawText(progressRect.topLeft()+QPoint(0,metrics.height()),subTitle); } // QPixmap rightPixmap(actionIconPath); // if (mClicked.contains(index)) // painter->setOpacity(0.4); // else // painter->setOpacity(1); // painter->drawPixmap(option.rect.right() -20, option.rect.center().y()-8, // rightPixmap); }
//VOXOX CHANGE - Add support for ItemList style and change paint structure. void QtUMGroup::paintForeground(QPainter * painter, const QStyleOptionViewItem & option) { QMutexLocker locker(&_mutex); bool isGroupSelected = false;//VOXOX CHANGE by Rolando - 2009.09.03 bool isGroupBlinking = false;//VOXOX CHANGE by Rolando - 2009.09.08 QtUMItemListStyle * itemListStyle = QtUMItemListStyle::getInstance();//VOXOX CHANGE by Rolando - 2009.09.07 isGroupBlinking = isBlinking();//VOXOX CHANGE by Rolando - 2009.09.03 isGroupSelected = _isSelected;//VOXOX CHANGE by Rolando - 2009.10.01 if(isGroupSelected)//VOXOX CHANGE by Rolando - 2009.09.04 { painter->setPen(itemListStyle->getSelectedGroupFontColor());//VOXOX CHANGE by Rolando - 2009.09.04 } else { if(isGroupBlinking){ if(_blinkNow){//VOXOX CHANGE by Rolando - 2009.10.01 painter->setPen(itemListStyle->getGroupBlinkingFontColor());//VOXOX CHANGE by Rolando - 2009.10.01 } else{ painter->setPen(itemListStyle->getNonSelectedGroupFontColor());//VOXOX CHANGE by Rolando - 2009.10.01 } } else{ painter->setPen(itemListStyle->getNonSelectedGroupFontColor());//VOXOX CHANGE by Rolando - 2009.09.04 } } painter->drawPixmap(option.rect.left(),option.rect.top(),getGroupBackGround(option.rect,option, isGroupSelected, isGroupBlinking)); QFont font = option.font; painter->setFont(font); QPixmap px; if (option.state & QStyle::State_Open) { px = itemListStyle->getGroupPixmapOpen(); } else { px = itemListStyle->getGroupPixmapClose(); } int x = option.rect.left(); QRect r = option.rect; painter->drawPixmap(x, r.top() + 3, px); _posXArrowButton = x;//VOXOX CHANGE by Rolando - 2009.09.29 _posYArrowButton = r.top() + 3;//VOXOX CHANGE by Rolando - 2009.09.29 _widthArrowButton = px.width();//VOXOX CHANGE by Rolando - 2009.09.29 _heightArrowButton = px.height();//VOXOX CHANGE by Rolando - 2009.09.29 x += px.width() + 3; r.setLeft(x); int y = ((r.bottom()-r.top())-QFontMetrics(font).height())/2; r.setTop(y + r.top()); painter->drawText(r, Qt::AlignLeft, getGroupName(), 0); //VOXOX CHANGE by Rolando - 2009.08.25 - getting corresponding close button QPixmap closeButtonPixmap; if ((option.state & QStyle::State_Selected) == QStyle::State_Selected) { closeButtonPixmap = QPixmap(":/pics/chat/umtreewidget/btn_close_selected.png");//VOXOX CHANGE by Rolando - 2009.08.25 painter->setPen(_fontColor);//VOXOX CHANGE by Rolando - 2009.09.07 } else { closeButtonPixmap = QPixmap(":/pics/chat/umtreewidget/btn_close_nonselected.png");//VOXOX CHANGE by Rolando - 2009.08.25 painter->setPen(_fontColor);//VOXOX CHANGE by Rolando - 2009.09.07 } //VOXOX CHANGE by Rolando - 2009.08.25 - painting the close button _posXCloseButton = r.right() - closeButtonPixmap.width() - 5;//VOXOX CHANGE by Rolando - 2009.09.16 int centeredCloseButton_y = ((r.bottom() - r.top()) - closeButtonPixmap.size().height()) / 2; painter->drawPixmap(_posXCloseButton, r.top() + centeredCloseButton_y, closeButtonPixmap); _posYCloseButton = r.top() + centeredCloseButton_y; _widthCloseButton = closeButtonPixmap.width();//VOXOX CHANGE by Rolando - 2009.08.27 _heightCloseButton = closeButtonPixmap.height();//VOXOX CHANGE by Rolando - 2009.08.27 }
void MjpegClient::processBlock() { if(m_boundary.isEmpty()) { // still waiting for boundary string defenition, check for content type in data block char * ctypeString = 0; if(m_dataBlock.contains("Content-Type:")) { ctypeString = "Content-Type:"; } else if(m_dataBlock.contains("content-type:")) { // allow for buggy servers (some IP cameras - trendnet, I'm looking at you!) // sometimes dont use proper case in their headers. ctypeString = "content-type:"; } else if(m_dataBlock.contains("Content-type:")) { // allow for another buggy server - Linksys WVC54GCA (Issue 113) ctypeString = "Content-type:"; } else if(m_dataBlock.contains("content-Type:")) { // I dont know of any server that sends it with c-T, but lets cover our bases anyway... ctypeString = "content-Type:"; } if(ctypeString) { int ctypeIdx = m_dataBlock.indexOf(ctypeString); if(ctypeIdx < 0) { qDebug() << "Error: Can't find content-type index in data block, exiting."; exit(); return; } static QString boundaryMarker = "boundary="; int boundaryStartIdx = m_dataBlock.indexOf(boundaryMarker,ctypeIdx); if(boundaryStartIdx < 0) { qDebug() << "Error: Can't find boundary index after the first content-type index in data block, exiting."; exit(); return; } int eolIdx = m_dataBlock.indexOf("\n",boundaryStartIdx); int pos = boundaryStartIdx + boundaryMarker.length(); m_boundary = m_dataBlock.mid(pos, eolIdx - pos); m_boundary.replace("\r",""); // qDebug() << "processBlock(): m_boundary:"<<m_boundary<<", pos:"<<pos<<", eolIdx:"<<eolIdx; } } else { // we have the boundary string defenition, check for the boundary string in the data block. // If found, grab the data from the start of the block up to and including the boundary, leaving any data after the boundary in the block. // What we then have to process could look: // Content-Type.....\r\n(data)--(boundary) // If its the first block, we wait for the boundary, but discard it since the first block is the one that contains the server headers // like the boundary definition, Server:, Connection:, etc. int idx = m_dataBlock.indexOf(m_boundary); while(idx > 0) { QByteArray block = m_dataBlock.left(idx); int blockAndBoundaryLength = idx + m_boundary.length(); m_dataBlock.remove(0,blockAndBoundaryLength); //qDebug() << "processBlock(): block length:"<<block.length()<<", blockAndBoundaryLength:"<<blockAndBoundaryLength; if(m_firstBlock) { //QString string = block; //qDebug() << "processBlock(): Discarding block since first block flag is true. Dump of block:\n"<<string; m_firstBlock = false; } else { static const char * eol1 = "\n\n"; static const char * eol2 = "\r\n\r\n"; int headerLength = 0; if(block.contains(eol2)) headerLength = block.indexOf(eol2,0) + 4; else if(block.contains(eol1)) headerLength = block.indexOf(eol1,0) + 2; if(headerLength) { //QString header = block.left(headerLength); block.remove(0,headerLength); // Block should now be just data //qDebug() << "processBlock(): block length:"<<block.length()<<", headerLength:"<<headerLength<<", header:"<<header; if(block.length() > 0) { QImage frame = QImage::fromData(block); if(!frame.isNull()) { // qDebug() << "processBlock(): New image received, original size:"<<frame.size()<<", bytes:"<<block.length(); if(m_autoResize.width()>0 && m_autoResize.height()>0 && m_autoResize != frame.size()) frame = frame.scaled(m_autoResize); // qDebug() << "processBlock(): Emitting new image, size:"<<frame.size(); emit newImage(frame); } #ifdef MJPEG_TEST QPixmap pix = QPixmap::fromImage(frame); m_label->setPixmap(pix); m_label->resize(pix.width(),pix.height()); #endif } } } // // check for another boundary string in the data before exiting from processBlock() idx = m_dataBlock.indexOf(m_boundary); } } // qDebug() << "processBlock(): End of processing, m_dataBlock.size() remaining:"<<m_dataBlock.size(); }
void KWMThemeClient::doShape() { QBitmap shapemask(width(), height()); shapemask.fill(color0); QPainter p; p.begin(&shapemask); p.setBrush(color1); p.setPen(color1); int x,y; // first the corners int w1 = framePixmaps[FrameTopLeft]->width(); int h1 = framePixmaps[FrameTopLeft]->height(); if (w1 > width()/2) w1 = width()/2; if (h1 > height()/2) h1 = height()/2; if (framePixmaps[FrameTopLeft]->mask()) p.drawPixmap(0,0,*framePixmaps[FrameTopLeft]->mask(), 0,0,w1, h1); else p.fillRect(0,0,w1,h1,color1); int w2 = framePixmaps[FrameTopRight]->width(); int h2 = framePixmaps[FrameTopRight]->height(); if (w2 > width()/2) w2 = width()/2; if (h2 > height()/2) h2 = height()/2; if (framePixmaps[FrameTopRight]->mask()) p.drawPixmap(width()-w2,0,*framePixmaps[FrameTopRight]->mask(), framePixmaps[FrameTopRight]->width()-w2,0,w2, h2); else p.fillRect(width()-w2,0,w2, h2,color1); int w3 = framePixmaps[FrameBottomLeft]->width(); int h3 = framePixmaps[FrameBottomLeft]->height(); if (w3 > width()/2) w3 = width()/2; if (h3 > height()/2) h3 = height()/2; if (framePixmaps[FrameBottomLeft]->mask()) p.drawPixmap(0,height()-h3,*framePixmaps[FrameBottomLeft]->mask(), 0,framePixmaps[FrameBottomLeft]->height()-h3,w3, h3); else p.fillRect(0,height()-h3,w3,h3,color1); int w4 = framePixmaps[FrameBottomRight]->width(); int h4 = framePixmaps[FrameBottomRight]->height(); if (w4 > width()/2) w4 = width()/2; if (h4 > height()/2) h4 = height()/2; if (framePixmaps[FrameBottomRight]->mask()) p.drawPixmap(width()-w4,height()-h4,*framePixmaps[FrameBottomRight]->mask(), framePixmaps[FrameBottomRight]->width()-w4, framePixmaps[FrameBottomRight]->height()-h4, w4, h4); else p.fillRect(width()-w4,height()-h4,w4,h4,color1); QPixmap pm; QWMatrix m; int n,s,w; //top if (framePixmaps[FrameTop]->mask()) { pm = *framePixmaps[FrameTop]->mask(); s = width()-w2-w1; n = s/pm.width(); w = n>0?s/n:s; m.reset(); m.scale(w/(float)pm.width(), 1); pm = pm.xForm(m); x = w1; while (1){ if (pm.width() < width()-w2-x){ p.drawPixmap(x,maxExtent-pm.height()-1, pm); x += pm.width(); } else { p.drawPixmap(x,maxExtent-pm.height()-1, pm, 0,0,width()-w2-x,pm.height()); break; } } } //bottom if (framePixmaps[FrameBottom]->mask()) { pm = *framePixmaps[FrameBottom]->mask(); s = width()-w4-w3; n = s/pm.width(); w = n>0?s/n:s; m.reset(); m.scale(w/(float)pm.width(), 1); pm = pm.xForm(m); x = w3; while (1){ if (pm.width() < width()-w4-x){ p.drawPixmap(x,height()-maxExtent+1,pm); x += pm.width(); } else { p.drawPixmap(x,height()-maxExtent+1,pm, 0,0,width()-w4-x,pm.height()); break; } } } //left if (framePixmaps[FrameLeft]->mask()) { pm = *framePixmaps[FrameLeft]->mask(); s = height()-h3-h1; n = s/pm.height(); w = n>0?s/n:s; m.reset(); m.scale(1, w/(float)pm.height()); pm = pm.xForm(m); y = h1; while (1){ if (pm.height() < height()-h3-y){ p.drawPixmap(maxExtent-pm.width()-1, y, pm); y += pm.height(); } else { p.drawPixmap(maxExtent-pm.width()-1, y, pm, 0,0, pm.width(), height()-h3-y); break; } } } //right if (framePixmaps[FrameRight]->mask()) { pm = *framePixmaps[FrameRight]->mask(); s = height()-h4-h2; n = s/pm.height(); w = n>0?s/n:s; m.reset(); m.scale(1, w/(float)pm.height()); pm = pm.xForm(m); y = h2; while (1){ if (pm.height() < height()-h4-y){ p.drawPixmap(width()-maxExtent+1, y, pm); y += pm.height(); } else { p.drawPixmap(width()-maxExtent+1, y, pm, 0,0, pm.width(), height()-h4-y); break; } } } p.fillRect(maxExtent-1, maxExtent-1, width()-2*maxExtent+2, height()-2*maxExtent+2, color1); setMask(shapemask); }
void setPixmap(const QPixmap &pixmap) { setRect(0.0, 0.0, pixmap.width() + 2 * InnerBorder, pixmap.height() + 2 * InnerBorder); m_pixmapItem->setPos(InnerBorder, InnerBorder); m_pixmapItem->setPixmap(pixmap); }
QVariant KDEPixmapManipulation::contactPhoto(Contact* c, const QSize& size, bool displayPresence) { const QString hash = QString("photo2%1%2%3").arg(size.width()).arg(size.height()).arg(c->isPresent()); QVariant preRendered = c->property(hash.toAscii()); if (preRendered.isValid()) return preRendered; else connect(c,SIGNAL(rebased(Contact*)),this,SLOT(clearCache())); const int radius = (size.height() > 35) ? 7 : 5; const QPixmap* pxmPtr = c->photo(); bool isTracked = displayPresence && c->isTracked(); bool isPresent = displayPresence && c->isPresent(); static QColor presentBrush = KStatefulBrush( KColorScheme::Window, KColorScheme::PositiveText ).brush(QPalette::Normal).color(); static QColor awayBrush = KStatefulBrush( KColorScheme::Window, KColorScheme::NegativeText ).brush(QPalette::Normal).color(); QPixmap pxm; if (pxmPtr) { QPixmap contactPhoto(pxmPtr->scaledToWidth(size.height()-6)); pxm = QPixmap(size); pxm.fill(Qt::transparent); QPainter painter(&pxm); //Clear the pixmap painter.setCompositionMode(QPainter::CompositionMode_Clear); painter.fillRect(0,0,size.width(),size.height(),QBrush(Qt::white)); painter.setCompositionMode(QPainter::CompositionMode_SourceOver); //Add corner radius to the Pixmap QRect pxRect = contactPhoto.rect(); QBitmap mask(pxRect.size()); QPainter customPainter(&mask); customPainter.setRenderHint (QPainter::Antialiasing, true ); customPainter.fillRect (pxRect , Qt::white ); customPainter.setBackground (Qt::black ); customPainter.setBrush (Qt::black ); customPainter.drawRoundedRect(pxRect,radius,radius); contactPhoto.setMask(mask); painter.drawPixmap(3,3,contactPhoto); painter.setBrush(Qt::NoBrush); QPen pen(QApplication::palette().color(QPalette::Disabled,QPalette::Text)); pen.setWidth(isTracked?1:2); painter.setPen(pen); painter.setRenderHint (QPainter::Antialiasing, true ); painter.drawRoundedRect(3,3,pxm.height()-6,pxm.height()-6,radius,radius); //Draw the glow around pixmaps if (isTracked) { if (isPresent) pen.setColor(presentBrush); else pen.setColor(awayBrush); for (int i=2;i<=7;i+=2) { pen.setWidth(i); painter.setPen(pen); painter.setOpacity(0.3f-(((i-2)*0.8f)/10.0f)); painter.drawRoundedRect(3,3,pxm.height()-6,pxm.height()-6,radius,radius); } } } else { pxm = drawDefaultUserPixmap(size,isTracked,isPresent); } c->setProperty(hash.toAscii(),pxm); return pxm; }
SplashScreen::SplashScreen(const QPixmap &pixmap, Qt::WindowFlags f, bool isTestNet) : QSplashScreen(pixmap, f) { setAutoFillBackground(true); // set reference point, paddings int paddingLeft = 14; int paddingTop = 470; int titleVersionVSpace = 17; int titleCopyrightVSpace = 32; float fontFactor = 1.0; // define text to place QString titleText = tr("Mobicoin Core"); QString versionText = QString(tr("Version %1")).arg(QString::fromStdString(FormatFullVersion())); QString copyrightTextBtc = QChar(0xA9)+QString(" 2009-%1 ").arg(COPYRIGHT_YEAR) + QString(tr("The Bitcoin Core developers")); QString copyrightTextDrk = QChar(0xA9)+QString(" 2014-%1 ").arg(COPYRIGHT_YEAR) + QString(tr("The Mobicoin Core developers")); QString testnetAddText = QString(tr("[testnet]")); // define text to place as single text object QString font = "Arial"; // load the bitmap for writing some text over it QPixmap newPixmap; if(isTestNet) { newPixmap = QPixmap(":/images/splash_testnet"); } else { newPixmap = QPixmap(":/images/splash"); } QPainter pixPaint(&newPixmap); pixPaint.setPen(QColor(100,100,100)); // check font size and drawing with pixPaint.setFont(QFont(font, 28*fontFactor)); QFontMetrics fm = pixPaint.fontMetrics(); int titleTextWidth = fm.width(titleText); if(titleTextWidth > 160) { // strange font rendering, Arial probably not found fontFactor = 0.75; } pixPaint.setFont(QFont(font, 28*fontFactor)); fm = pixPaint.fontMetrics(); titleTextWidth = fm.width(titleText); pixPaint.drawText(paddingLeft,paddingTop,titleText); pixPaint.setFont(QFont(font, 15*fontFactor)); pixPaint.drawText(paddingLeft,paddingTop+titleVersionVSpace,versionText); // draw copyright stuff pixPaint.setFont(QFont(font, 10*fontFactor)); pixPaint.drawText(paddingLeft,paddingTop+titleCopyrightVSpace,copyrightTextBtc); pixPaint.drawText(paddingLeft,paddingTop+titleCopyrightVSpace+12,copyrightTextDrk); // draw testnet string if testnet is on if(isTestNet) { QFont boldFont = QFont(font, 10*fontFactor); boldFont.setWeight(QFont::Bold); pixPaint.setFont(boldFont); fm = pixPaint.fontMetrics(); int testnetAddTextWidth = fm.width(testnetAddText); pixPaint.drawText(newPixmap.width()-testnetAddTextWidth-10,newPixmap.height()-25,testnetAddText); } pixPaint.end(); this->setPixmap(newPixmap); subscribeToCoreSignals(); }
void FWObjectDropArea::paintEvent(QPaintEvent *) { int w=width(); int h=height(); QPainter p(this); QPixmap bufferpixmap; bufferpixmap = QPixmap( w , h ); bufferpixmap.fill( Qt::white ); QPainter tp( &bufferpixmap ); tp.setBrush(Qt::black); tp.drawLine(0,0,w-1,0); tp.drawLine(w-1,0,w-1,h-1); tp.drawLine(w-1,h-1,0,h-1); tp.drawLine(0,h-1,0,0); tp.fillRect(1, 1, w-2, h-2, Qt::white); if (object!=nullptr) { QPixmap pm; QString icn_file = (":/Icons/"+object->getTypeName()+"/icon").c_str(); if ( ! QPixmapCache::find( icn_file, pm) ) { pm.load( icn_file ); QPixmapCache::insert( icn_file, pm); } tp.drawPixmap( ((w-pm.width())/2), (h/2)-(2+pm.height()) , pm ); QString t=QString::fromUtf8(object->getName().c_str()); int t_x=2; int t_y=2+h/2; int t_w=w-4; int t_h=h/2-4; tp.drawText( t_x, t_y , t_w, t_h , Qt::AlignHCenter|Qt::AlignTop|Qt::TextWordWrap, t ); } else { QString t = helperText ; int t_x = 2; int t_y = 2; int t_w = w-4; int t_h = h-4; tp.drawText( t_x, t_y , t_w, t_h , Qt::AlignHCenter|Qt::AlignVCenter|Qt::TextWordWrap, t ); } tp.end(); p.drawPixmap( 0, 0, bufferpixmap ); }
void LocalImageLoaderPrivate::prepareImages() { QString file, filename, mime, stickerMime = qsl("image/webp"); int32 filesize = 0; QImage img; QByteArray data; PeerId peer; uint64 id, thumbId = 0; int32 duration = 0; QString thumbExt = "jpg"; ToPrepareMediaType type; bool animated = false; bool ctrlShiftEnter = false; MsgId replyTo = 0; { QMutexLocker lock(loader->toPrepareMutex()); ToPrepareMedias &list(loader->toPrepareMedias()); if (list.isEmpty()) return; file = list.front().file; img = list.front().img; data = list.front().data; peer = list.front().peer; id = list.front().id; type = list.front().type; duration = list.front().duration; ctrlShiftEnter = list.front().ctrlShiftEnter; replyTo = list.front().replyTo; } if (img.isNull()) { if (!file.isEmpty()) { QFileInfo info(file); if (type == ToPrepareAuto) { QString lower(file.toLower()); const QStringList &photoExtensions(cPhotoExtensions()); for (QStringList::const_iterator i = photoExtensions.cbegin(), e = photoExtensions.cend(); i != e; ++i) { if (lower.lastIndexOf(*i) == lower.size() - i->size()) { if (info.size() < MaxUploadPhotoSize) { type = ToPreparePhoto; break; } } } if (type == ToPrepareAuto && info.size() < MaxUploadDocumentSize) { type = ToPrepareDocument; } } if (type == ToPrepareDocument) { mime = mimeTypeForFile(info).name(); } if (type != ToPrepareAuto && info.size() < MaxUploadPhotoSize) { bool opaque = (mime != stickerMime); img = App::readImage(file, 0, opaque, &animated); } filename = info.fileName(); filesize = info.size(); } else if (!data.isEmpty()) { if (type != ToPrepareAudio) { img = App::readImage(data, 0, true, &animated); if (type == ToPrepareAuto) { if (!img.isNull() && data.size() < MaxUploadPhotoSize) { type = ToPreparePhoto; } else if (data.size() < MaxUploadDocumentSize) { type = ToPrepareDocument; } else { img = QImage(); } } } MimeType mimeType = mimeTypeForData(data); if (type == ToPrepareDocument || type == ToPrepareAudio) { mime = mimeType.name(); } if (mime == "image/jpeg") { filename = filedialogDefaultName(qsl("image"), qsl(".jpg"), QString(), true); } else if (type == ToPrepareAudio) { filename = filedialogDefaultName(qsl("audio"), qsl(".ogg"), QString(), true); mime = "audio/ogg"; } else { QString ext; QStringList patterns = mimeType.globPatterns(); if (!patterns.isEmpty()) { ext = patterns.front().replace('*', QString()); } filename = filedialogDefaultName((type == ToPrepareAudio) ? qsl("audio") : qsl("doc"), ext, QString(), true); } filesize = data.size(); } } else { if (type == ToPrepareDocument) { filename = filedialogDefaultName(qsl("image"), qsl(".png"), QString(), true); mime = mimeTypeForName("image/png").name(); data = QByteArray(); { QBuffer b(&data); img.save(&b, "PNG"); } filesize = data.size(); } else { if (img.hasAlphaChannel()) { QImage solid(img.width(), img.height(), QImage::Format_ARGB32_Premultiplied); solid.fill(st::white->c); { QPainter(&solid).drawImage(0, 0, img); } img = solid; } type = ToPreparePhoto; filename = qsl("Untitled.jpg"); filesize = 0; } } if ((img.isNull() && ((type != ToPrepareDocument && type != ToPrepareAudio) || !filesize)) || type == ToPrepareAuto || (img.isNull() && file.isEmpty() && data.isEmpty())) { // if could not decide what type { QMutexLocker lock(loader->toPrepareMutex()); ToPrepareMedias &list(loader->toPrepareMedias()); list.pop_front(); } QTimer::singleShot(1, this, SLOT(prepareImages())); emit imageFailed(id); } else { PreparedPhotoThumbs photoThumbs; QVector<MTPPhotoSize> photoSizes; QVector<MTPDocumentAttribute> attributes(1, MTP_documentAttributeFilename(MTP_string(filename))); MTPPhotoSize thumb(MTP_photoSizeEmpty(MTP_string(""))); MTPPhoto photo(MTP_photoEmpty(MTP_long(0))); MTPDocument document(MTP_documentEmpty(MTP_long(0))); MTPAudio audio(MTP_audioEmpty(MTP_long(0))); QByteArray jpeg; if (type == ToPreparePhoto) { int32 w = img.width(), h = img.height(); QPixmap thumb = (w > 100 || h > 100) ? QPixmap::fromImage(img.scaled(100, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation), Qt::ColorOnly) : QPixmap::fromImage(img); photoThumbs.insert('s', thumb); photoSizes.push_back(MTP_photoSize(MTP_string("s"), MTP_fileLocationUnavailable(MTP_long(0), MTP_int(0), MTP_long(0)), MTP_int(thumb.width()), MTP_int(thumb.height()), MTP_int(0))); QPixmap medium = (w > 320 || h > 320) ? QPixmap::fromImage(img.scaled(320, 320, Qt::KeepAspectRatio, Qt::SmoothTransformation), Qt::ColorOnly) : QPixmap::fromImage(img); photoThumbs.insert('m', medium); photoSizes.push_back(MTP_photoSize(MTP_string("m"), MTP_fileLocationUnavailable(MTP_long(0), MTP_int(0), MTP_long(0)), MTP_int(medium.width()), MTP_int(medium.height()), MTP_int(0))); QPixmap full = (w > 1280 || h > 1280) ? QPixmap::fromImage(img.scaled(1280, 1280, Qt::KeepAspectRatio, Qt::SmoothTransformation), Qt::ColorOnly) : QPixmap::fromImage(img); photoThumbs.insert('y', full); photoSizes.push_back(MTP_photoSize(MTP_string("y"), MTP_fileLocationUnavailable(MTP_long(0), MTP_int(0), MTP_long(0)), MTP_int(full.width()), MTP_int(full.height()), MTP_int(0))); { QBuffer jpegBuffer(&jpeg); full.save(&jpegBuffer, "JPG", 77); } if (!filesize) filesize = jpeg.size(); photo = MTP_photo(MTP_long(id), MTP_long(0), MTP_int(user), MTP_int(unixtime()), MTP_geoPointEmpty(), MTP_vector<MTPPhotoSize>(photoSizes)); thumbId = id; } else if ((type == ToPrepareVideo || type == ToPrepareDocument) && !img.isNull()) { int32 w = img.width(), h = img.height(); QByteArray thumbFormat = "JPG"; int32 thumbQuality = 87; if (animated) { attributes.push_back(MTP_documentAttributeAnimated()); } else if (mime == stickerMime && w > 0 && h > 0 && w <= StickerMaxSize && h <= StickerMaxSize && filesize < StickerInMemory) { attributes.push_back(MTP_documentAttributeSticker(MTP_string(""), MTP_inputStickerSetEmpty())); thumbFormat = "webp"; thumbExt = qsl("webp"); } attributes.push_back(MTP_documentAttributeImageSize(MTP_int(w), MTP_int(h))); if (w < 20 * h && h < 20 * w) { QPixmap full = (w > 90 || h > 90) ? QPixmap::fromImage(img.scaled(90, 90, Qt::KeepAspectRatio, Qt::SmoothTransformation), Qt::ColorOnly) : QPixmap::fromImage(img, Qt::ColorOnly); { QBuffer jpegBuffer(&jpeg); full.save(&jpegBuffer, thumbFormat, thumbQuality); } photoThumbs.insert('0', full); thumb = MTP_photoSize(MTP_string(""), MTP_fileLocationUnavailable(MTP_long(0), MTP_int(0), MTP_long(0)), MTP_int(full.width()), MTP_int(full.height()), MTP_int(0)); thumbId = MTP::nonce<uint64>(); } } if (type == ToPrepareDocument) { document = MTP_document(MTP_long(id), MTP_long(0), MTP_int(unixtime()), MTP_string(mime), MTP_int(filesize), thumb, MTP_int(MTP::maindc()), MTP_vector<MTPDocumentAttribute>(attributes)); } else if (type == ToPrepareAudio) { audio = MTP_audio(MTP_long(id), MTP_long(0), MTP_int(user), MTP_int(unixtime()), MTP_int(duration), MTP_string(mime), MTP_int(filesize), MTP_int(MTP::maindc())); } { QMutexLocker lock(loader->readyMutex()); loader->readyList().push_back(ReadyLocalMedia(type, file, filename, filesize, data, id, thumbId, thumbExt, peer, photo, audio, photoThumbs, document, jpeg, ctrlShiftEnter, replyTo)); } { QMutexLocker lock(loader->toPrepareMutex()); ToPrepareMedias &list(loader->toPrepareMedias()); list.pop_front(); } QTimer::singleShot(1, this, SLOT(prepareImages())); emit imageReady(); } }
///Delegate painter void ImDelegates::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { Q_ASSERT(index.isValid()); QPixmap icon = index.data(Qt::DecorationRole).value<QPixmap>(); int icnWidth = 50; if (!icon.isNull()) { painter->drawPixmap(option.rect.x()+5,option.rect.y()+(option.rect.height()/2)-(icon.height()/2),icon); icnWidth = icon.width(); } QFontMetrics metric(painter->font()); QString text = index.data(Qt::DisplayRole).toString(); QRect requiredRect = metric.boundingRect(option.rect.x()+icnWidth+10,option.rect.y()+metric.height()+5,option.rect.width() - icnWidth - 10 /*margin*/,500,Qt::TextWordWrap|Qt::AlignLeft,text); painter->drawText(requiredRect,Qt::AlignLeft|Qt::TextWordWrap,text); QFont font = painter->font(); font.setBold(true); painter->setFont(font); const QString peerName = index.data((int)Media::TextRecording::Role::AuthorDisplayname).toString(); painter->drawText(option.rect.x()+icnWidth+10,option.rect.y()+metric.height(), peerName); font.setBold(false); painter->setFont(font); }
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(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); } 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); } 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); } }
{ fprintf(stderr, "%s\n", HWApplication::tr("Unknown option argument: %1", "command-line").arg(QString("--") + key).toUtf8().constData()); } fprintf(stderr, "\n%s", getUsage().toUtf8().constData()); return 1; } // end of parameter parsing #if defined Q_OS_WIN QPixmap pixmap(":res/splash.png"); splash = new QLabel(0, Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint); splash->setAttribute(Qt::WA_TranslucentBackground); const QRect deskSize = HWApplication::desktop()->screenGeometry(-1); QPoint splashCenter = QPoint( (deskSize.width() - pixmap.width())/2, (deskSize.height() - pixmap.height())/2 ); splash->move(splashCenter); splash->setPixmap(pixmap); splash->show(); #endif app.setStyle(new QPlastiqueStyle()); QDateTime now = QDateTime::currentDateTime(); srand(now.toTime_t()); rand(); Q_INIT_RESOURCE(hedgewars); qRegisterMetaType<HWTeam>("HWTeam"); bindir->cd(QCoreApplication::applicationDirPath());
CScreenShotView::CScreenShotView(const QList<QRect> &rectList, QScreen *screen, bool onlySelect, QWidget *parent) :QGraphicsView(parent) ,m_windowRectList(rectList) ,m_desktopScreen(screen) ,m_screen(NULL) ,m_backgroundItem(NULL) ,m_selectRectItem(NULL) ,m_toolbarItem(NULL) ,m_currentRectItem(NULL) ,m_tooltipSizeItem(NULL) ,m_previewItem(NULL) ,m_positionType(CSCREEN_POSITION_TYPE_NOT_CONTAIN) ,m_shotStatus(CSCREEN_SHOT_STATE_INITIALIZED) ,m_screenButtonType(CSCREEN_BUTTON_TYPE_UNDEFINED) ,m_isPressed(false) ,m_isLocked(false) ,m_isValid(false) ,m_onlySelect(onlySelect) { C_SCREENSHOT_LOG_FUNCTION; this->setMouseTracking(true); m_screen = new CScreenShotScene(this); this->setScene(m_screen); QRect geometry= screen->geometry(); C_SCREENSHOT_LOG_INFO(QString("screen->geometry() (%1,%2,%3,%4)") .arg(geometry.x()) .arg(geometry.y()) .arg(geometry.width()) .arg(geometry.height())); C_SCREENSHOT_LOG_TEST; QPixmap pixmap = createDesktopPixmap(); C_SCREENSHOT_LOG_TEST; drawPixmap(pixmap); m_backgroundItem = new QGraphicsPixmapItem(m_backgroundPixmap); m_screen->addItem(m_backgroundItem); C_SCREENSHOT_LOG_TEST; this->setGeometry(geometry); m_screen->setSceneRect(QRect(0,0,geometry.width(),geometry.height())); m_sx = 1.0 * geometry.width() / pixmap.width(); m_sy = 1.0 * geometry.height() / pixmap.height(); m_backgroundItem->setScale(m_sx); m_selectRectItem = new CScreenSelectRectItem(m_desktopPixmap); m_selectRectItem->setScale(m_sx); m_selectRectItem->setVisible(false); m_screen->addItem(m_selectRectItem); C_SCREENSHOT_LOG_TEST; //==================== m_toolbarItem = new CScreenEditorToolbarItem; connect(m_toolbarItem,SIGNAL(sigButtonClicked(CScreenButtonType)), this,SLOT(onButtonClicked(CScreenButtonType))); m_toolbarItem->setVisible(false); m_toolbarItem->setZValue(m_selectRectItem->zValue() + 1); m_screen->addItem(m_toolbarItem); m_tooltipSizeItem = new CScreenTooltipItem; C_SCREENSHOT_LOG_TEST; m_tooltipSizeItem->setVisible(false); m_screen->addItem(m_tooltipSizeItem); m_previewItem = new QGraphicsPixmapItem; m_previewItem->setVisible(false); m_previewItem->setZValue(m_toolbarItem->zValue() + 1); C_SCREENSHOT_LOG_TEST; m_screen->addItem(m_previewItem); this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); this->setStyleSheet("QWidget{border: 0px solid #1880ed;}"); #ifdef Q_OS_MAC qApp->installEventFilter(this); #endif QPoint pos = QCursor::pos(); if(geometry.contains(pos)) { //TODO 暂时屏蔽 为了快速启动,耗时400ms // updatePreviewItem(this->mapFromGlobal(pos)); } C_SCREENSHOT_LOG_TEST; }
void Shadows::Private::initPixmap(const QString &element) { #ifdef Q_WS_X11 QPixmap pix = q->pixmap(element); if (!pix.isNull() && pix.handle() == 0) { Pixmap xPix = XCreatePixmap(QX11Info::display(), QX11Info::appRootWindow(), pix.width(), pix.height(), 32); QPixmap tempPix = QPixmap::fromX11Pixmap(xPix, QPixmap::ExplicitlyShared); tempPix.fill(Qt::transparent); QPainter p(&tempPix); p.drawPixmap(QPoint(0, 0), pix); m_shadowPixmaps << tempPix; m_managePixmaps = true; } else { m_shadowPixmaps << pix; } #endif }
bool FskinCreator::create(const QString& path, int width, int height, QImage& img) { if (!QFile::exists(path)) return false; KTar tar(path); if (!tar.open(QIODevice::ReadOnly)) return false; QStringList entries = tar.directory()->entries(); if (entries.count() != 1) return false; const KArchiveEntry* entry = tar.directory()->entry(entries.first()); if (!entry->isDirectory()) return false; const KArchiveDirectory* subdir = static_cast<const KArchiveDirectory*>(entry); const KArchiveEntry* skinconf_entry = subdir->entry("fcitx_skin.conf"); const KArchiveFile* skinconf = static_cast<const KArchiveFile*>(skinconf_entry); if (!skinconf) return false; QByteArray data = skinconf->data(); /// parse ini file content bool skinfont = false; bool skininputbar = false; QPixmap skin; QString resizemode; /// margins int ml = 0, mr = 0, mt = 0, mb = 0; /// font size QFont font; QColor color_en; QColor color_label; QColor color_ch_1st; /// text y position int yen = 0, ych = 0; /// cursor color QColor color_cursor; /// back arrow QPixmap barrow; int xba = 0, yba = 0; /// forward arrow QPixmap farrow; int xfa = 0, yfa = 0; QTextStream ss(data); QString line; QString key, value; do { line = ss.readLine(); if (line.isEmpty() || line.at(0) == '#') continue; if (line.at(0) == '[') { skinfont = (line == "[SkinFont]"); skininputbar = (line == "[SkinInputBar]"); continue; } if (!line.contains('=')) continue; key = line.split('=').at(0); value = line.split('=').at(1); if (value.isEmpty()) continue; if (skinfont) { if (key == "FontSize") { font.setPixelSize(value.toInt()); } else if (key == "InputColor") { color_en = value2color(value); } else if (key == "IndexColor") { color_label = value2color(value); } else if (key == "FirstCandColor") { color_ch_1st = value2color(value); } else if (key == "UserPhraseColor") { QColor color_ch_user = value2color(value); } else if (key == "OtherColor") { QColor color_ch_other = value2color(value); } } else if (skininputbar) { if (key == "BackImg") { const KArchiveEntry* e = subdir->entry(value); const KArchiveFile* pix = static_cast<const KArchiveFile*>(e); if (pix) skin.loadFromData(pix->data()); } else if (key == "Resize") { resizemode = value; } else if (key == "MarginLeft") { ml = value.toInt(); } else if (key == "MarginRight") { mr = value.toInt(); } else if (key == "MarginTop") { mt = value.toInt(); } else if (key == "MarginBottom") { mb = value.toInt(); } else if (key == "InputPos") { yen = value.toInt(); } else if (key == "OutputPos") { ych = value.toInt(); } else if (key == "CursorColor") { color_cursor = value2color(value); } else if (key == "BackArrow") { const KArchiveEntry* e = subdir->entry(value); const KArchiveFile* pix = static_cast<const KArchiveFile*>(e); if (pix) barrow.loadFromData(pix->data()); } else if (key == "ForwardArrow") { const KArchiveEntry* e = subdir->entry(value); const KArchiveFile* pix = static_cast<const KArchiveFile*>(e); if (pix) farrow.loadFromData(pix->data()); } else if (key == "BackArrowX") { xba = value.toInt(); } else if (key == "BackArrowY") { yba = value.toInt(); } else if (key == "ForwardArrowX") { xfa = value.toInt(); } else if (key == "ForwardArrowY") { yfa = value.toInt(); } } } while (!line.isNull()); int fontHeight = QFontMetrics(font).height(); int pinyinw = QFontMetrics(font).width("ABC pinyin"); int zhongwenw = QFontMetrics(font).width("1candidate"); /// save target size int targetHeight = height; int targetWidth = width; height = mt + ych + mb; width = qMax(ml + pinyinw + mr, ml + zhongwenw + mr); width = qMax(width, targetWidth); width = qMax(width, skin.width()); yen = mt + yen - fontHeight; ych = mt + ych - fontHeight; QPixmap pixmap(width, height); pixmap.fill(Qt::transparent); QPainter p(&pixmap); /// corners lt, lb, rt, rb p.drawPixmap(0, 0, skin, 0, 0, ml, mt); p.drawPixmap(0, height - mb, skin, 0, skin.height() - mb, ml, mb); p.drawPixmap(width - mr, 0, skin, skin.width() - mr, 0, mr, mt); p.drawPixmap(width - mr, height - mb, skin, skin.width() - mr, skin.height() - mb, mr, mb); /// left right p.drawPixmap(0, mt, ml, height - mt - mb, skin, 0, mt, ml, skin.height() - mt - mb); p.drawPixmap(width - mr, mt, mr, height - mt - mb, skin, skin.width() - mr, mt, mr, skin.height() - mt - mb); /// top bottom p.drawPixmap(ml, 0, width - ml - mr, mt, skin, ml, 0, skin.width() - ml - mr, mt); p.drawPixmap(ml, height - mb, width - ml - mr, mb, skin, ml, skin.height() - mb, skin.width() - ml - mr, mb); /// middle p.drawPixmap(ml, mt, width - ml - mr, height - mt - mb, skin, ml, mt, skin.width() - ml - mr, skin.height() - mt - mb); /// draw arrows p.drawPixmap(width - xba, yba, barrow); p.drawPixmap(width - xfa, yfa, farrow); /// draw preedit / aux text p.setFont(font); p.setPen(color_en); p.drawText(ml, yen, pinyinw, fontHeight, Qt::AlignCenter, "ABC pinyin"); p.drawLine(ml + pinyinw, yen, ml + pinyinw, yen + fontHeight); /// draw lookup table p.setPen(color_label); int labelw = p.fontMetrics().width("1"); p.drawText(ml, ych, labelw, fontHeight, Qt::AlignCenter, "1"); p.setPen(color_ch_1st); int candidatew = p.fontMetrics().width("candidate"); p.drawText(ml + labelw, ych, candidatew, fontHeight, Qt::AlignCenter, "candidate"); p.end(); if (targetWidth < width || targetHeight < height) { pixmap = pixmap.scaled(targetWidth, targetHeight, Qt::KeepAspectRatio); } img = pixmap.toImage(); return true; }
showAnCalChrRes::showAnCalChrRes(customRect *rect, QImage* origEditImg, QWidget *parent) : QDialog(parent), ui(new Ui::showAnCalChrRes) { ui->setupUi(this); //internOrigEditImg = origEditImg; //Get rectangle //.. globalRect = rect; qreal rx1,ry1,rx2,ry2; //rect->rect().getRect(&rx1,&ry1,&rw,&rh); rect->rect().getCoords(&rx1,&ry1,&rx2,&ry2); globalCalStruct.x1 = (int)rx1; globalCalStruct.y1 = (int)ry1; globalCalStruct.x2 = (int)rx2; globalCalStruct.y2 = (int)ry2; globalCalStruct.canvasW = rect->parameters.W; globalCalStruct.canvasH = rect->parameters.H; //Prepare variables //.. int w, h, W, H; //QPixmap tmpPix(_PATH_DISPLAY_IMAGE); QPixmap tmpPix = QPixmap::fromImage(*origEditImg); W = tmpPix.width(); H = tmpPix.height(); w = rect->parameters.canvas->width(); h = rect->parameters.canvas->height(); //qDebug() << "Canvas w: " << w; //qDebug() << "Canvas h: " << h; //qDebug() << "x1: " << globalCalStruct.x1; //qDebug() << "y1: " << globalCalStruct.y1; //qDebug() << "x2: " << globalCalStruct.x2; //qDebug() << "y2: " << globalCalStruct.y2; //Extrapolate dimensions globalCalStruct.X1 = round( ((float)W/(float)w)*(float)globalCalStruct.x1 ); globalCalStruct.Y1 = round( ((float)H/(float)h)*(float)globalCalStruct.y1 ); globalCalStruct.X2 = round( ((float)W/(float)w)*(float)globalCalStruct.x2 ); globalCalStruct.Y2 = round( ((float)H/(float)h)*(float)globalCalStruct.y2 ); globalCalStruct.lenW = abs(globalCalStruct.X2-globalCalStruct.X1); globalCalStruct.lenH = abs(globalCalStruct.Y2-globalCalStruct.Y1); globalCalStruct.origImgW = W; globalCalStruct.origImgH = H; //qDebug() << "p1: " << globalCalStruct.x1 << ", " << globalCalStruct.y1; //qDebug() << "p2: " << globalCalStruct.x2 << ", " << globalCalStruct.y2; //qDebug() << "P1: " << globalCalStruct.X1 << ", " << globalCalStruct.Y1; //qDebug() << "P2: " << globalCalStruct.X2 << ", " << globalCalStruct.Y2; //qDebug() << "lenW: " << globalCalStruct.lenW; //qDebug() << "lenH: " << globalCalStruct.lenH; //Crop & show image //.. //qDeleteAll(canvasSpec->scene()->items()); int tmpOffset = 10; QPixmap cropped = tmpPix.copy( QRect( globalCalStruct.X1, globalCalStruct.Y1, globalCalStruct.lenW, globalCalStruct.lenH ) ); cropped.save("./tmpImages/tmpCropped.ppm"); QGraphicsScene *scene = new QGraphicsScene(0,0,cropped.width(),cropped.height()); ui->canvasCroped->setBackgroundBrush(cropped); ui->canvasCroped->setCacheMode(QGraphicsView::CacheNone); ui->canvasCroped->setScene( scene ); ui->canvasCroped->resize(cropped.width(),cropped.height()); float toolBarW = ui->frame->width(); int newW = (cropped.width()>toolBarW)?cropped.width():toolBarW; this->resize(QSize(newW+(tmpOffset*2),cropped.height()+(tmpOffset*2)+ui->frame->height())); int framex = round((float)(this->width()-ui->frame->width())/2.0); int framey = ui->canvasCroped->height()+tmpOffset; ui->frame->move(QPoint(framex,framey)); int canvasx = round((float)(this->width()-ui->canvasCroped->width())/2.0); ui->canvasCroped->move(QPoint(canvasx,0)); ui->canvasCroped->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); ui->canvasCroped->setVerticalScrollBarPolicy ( Qt::ScrollBarAlwaysOff ); //Update lines //.. globalRedLine = new customLine(QPoint(0,0),QPoint(0,0),QPen(Qt::red)); globalGreenLine = new customLine(QPoint(0,0),QPoint(0,0),QPen(Qt::green)); globalBlueLine = new customLine(QPoint(0,0),QPoint(0,0),QPen(Qt::blue)); drawSensitivities(); }
void ContactItemDelegate::paint(QPainter *p, const QStyleOptionViewItem &opt, const QModelIndex &index) const { QStyleOptionViewItemV4 ropt = opt; QRect r = opt.rect.adjusted(5, 5, -5, -8); p->save(); /* Selection (behind the avatar) */ ropt.rect.adjust(0, 0, 0, -3); SelectionState sst = NoSelectionState; if (opt.state & QStyle::State_Selected) sst = Selected; else if (opt.state & QStyle::State_MouseOver) sst = MouseOver; else if (index.data(ContactsModel::AlertRole).toBool()) { sst = Alert; p->setOpacity(parentDelegate->alertOpacity()); parentDelegate->startAlertAnimation(); } if (sst != NoSelectionState) { p->drawPixmap(ropt.rect.topLeft(), customSelectionRect(ropt.rect.size(), sst)); if (sst == Alert) p->setOpacity(1); } /* Avatar */ QPixmap avatar = index.data(Qt::DecorationRole).value<QPixmap>(); QPoint avatarPos = QPoint(r.x() + (35 - avatar.width()) / 2, r.y() + (35 - avatar.height()) / 2); if (!avatar.isNull()) { if (avatar.width() > 35 || avatar.height() > 35) avatar = avatar.scaled(QSize(35, 35), Qt::KeepAspectRatio, Qt::SmoothTransformation); p->drawPixmap(avatarPos, avatar); } /* Status */ QPixmap status = index.data(ContactsModel::StatusIndicator).value<QPixmap>(); if (!status.isNull()) p->drawPixmap(avatarPos - QPoint(status.width()/2-2, status.height()/2-3), status); /* Page switch buttons */ int textWidth = 0; if ((opt.state & QStyle::State_Selected) || (opt.state & QStyle::State_MouseOver)) { ContactsView::Page activePage = parentDelegate->view->activePage(); bool isActive = (parentDelegate->view->currentIndex() == index); /* Chat page */ QRect iconRect(r.right()-16+1, r.top()-1, 16, 16); QPixmap pm; if (isActive && activePage == ContactsView::ContactChatPage) pm = QPixmap(QLatin1String(":/icons/chat-active.png")); else if (iconRect.contains(ropt.widget->mapFromGlobal(QCursor::pos()))) pm = QPixmap(QLatin1String(":/icons/chat-hover.png")); else pm = QPixmap(QLatin1String(":/icons/chat-inactive.png")); p->drawPixmap(iconRect.topLeft(), pm); /* Info page */ iconRect = QRect(r.right()-16+1, r.bottom()-16+1, 16, 16); if (isActive && activePage == ContactsView::ContactInfoPage) pm = QPixmap(QLatin1String(":/icons/info-active.png")); else if (iconRect.contains(ropt.widget->mapFromGlobal(QCursor::pos()))) pm = QPixmap(QLatin1String(":/icons/info-hover.png")); else pm = QPixmap(QLatin1String(":/icons/info-inactive.png")); p->drawPixmap(iconRect.topLeft(), pm); textWidth -= 14; } /* Draw nickname */ r.adjust(41, 0, 0, 0); textWidth += r.width(); QString nickname = index.data().toString(); QFont nickFont = p->font(); nickFont.setPixelSize(12); p->setFont(nickFont); /* Caution: horrifically slow */ QFontMetrics metrics = p->fontMetrics(); QRect nickRect = metrics.tightBoundingRect(nickname); p->drawText(r.topLeft() + QPoint(0, nickRect.height()+1), nickname); /* Draw info text */ QModelIndex infoIndex(index.model()->index(index.row(), 2, index.parent())); QString infoText = infoIndex.data(Qt::DisplayRole).toString(); QFont infoFont = QFont(QLatin1String("Arial")); infoFont.setPixelSize(10); infoFont.setStyleHint(QFont::SansSerif); p->setFont(infoFont); infoText = QFontMetrics(infoFont).elidedText(infoText, Qt::ElideRight, textWidth); p->setPen(infoIndex.data(Qt::ForegroundRole).value<QColor>()); p->drawText(r.bottomLeft() - QPoint(0, 1), infoText); p->restore(); }
void QgsDetailedItemDelegate::paintManually( QPainter *thepPainter, const QStyleOptionViewItem &theOption, const QgsDetailedItemData &theData ) const { // // Get the strings and check box properties // //bool myCheckState = theIndex.model()->data(theIndex, Qt::CheckStateRole).toBool(); mpCheckBox->setChecked( theData.isChecked() ); mpCheckBox->setEnabled( theData.isEnabled() ); QPixmap myCbxPixmap( mpCheckBox->size() ); mpCheckBox->render( &myCbxPixmap ); //we will draw this onto the widget further down // // Calculate the widget height and other metrics // QFontMetrics myTitleMetrics( titleFont( theOption ) ); QFontMetrics myDetailMetrics( detailFont( theOption ) ); int myTextStartX = theOption.rect.x() + horizontalSpacing(); int myTextStartY = theOption.rect.y() + verticalSpacing(); int myHeight = myTitleMetrics.height() + verticalSpacing(); // // Draw the item background with a gradient if its highlighted // if ( theOption.state & QStyle::State_Selected ) { drawHighlight( theOption, thepPainter, height( theOption, theData ) ); thepPainter->setPen( theOption.palette.highlightedText().color() ); } else { thepPainter->setPen( theOption.palette.text().color() ); } // // Draw the checkbox // if ( theData.isCheckable() ) { thepPainter->drawPixmap( theOption.rect.x(), theOption.rect.y() + mpCheckBox->height(), myCbxPixmap ); myTextStartX = theOption.rect.x() + myCbxPixmap.width() + horizontalSpacing(); } // // Draw the decoration (pixmap) // bool myIconFlag = false; QPixmap myDecoPixmap = theData.icon(); if ( !myDecoPixmap.isNull() ) { myIconFlag = true; int iconWidth = 32, iconHeight = 32; if ( myDecoPixmap.width() <= iconWidth && myDecoPixmap.height() <= iconHeight ) { // the pixmap has reasonable size int offsetX = 0, offsetY = 0; if ( myDecoPixmap.width() < iconWidth ) offsetX = ( iconWidth - myDecoPixmap.width() ) / 2; if ( myDecoPixmap.height() < iconHeight ) offsetY = ( iconHeight - myDecoPixmap.height() ) / 2; thepPainter->drawPixmap( myTextStartX + offsetX, myTextStartY + offsetY, myDecoPixmap ); } else { // shrink the pixmap, it's too big thepPainter->drawPixmap( myTextStartX, myTextStartY, iconWidth, iconHeight, myDecoPixmap ); } myTextStartX += iconWidth + horizontalSpacing(); } // // Draw the title // myTextStartY += myHeight / 2; thepPainter->setFont( titleFont( theOption ) ); thepPainter->drawText( myTextStartX, myTextStartY, theData.title() ); // // Draw the description with word wrapping if needed // thepPainter->setFont( detailFont( theOption ) ); //return to original font set by client if ( myIconFlag ) { myTextStartY += verticalSpacing(); } else { myTextStartY += myDetailMetrics.height() + verticalSpacing(); } QStringList myList = wordWrap( theData.detail(), myDetailMetrics, theOption.rect.width() - myTextStartX ); QStringListIterator myLineWrapIterator( myList ); while ( myLineWrapIterator.hasNext() ) { QString myLine = myLineWrapIterator.next(); thepPainter->drawText( myTextStartX, myTextStartY, myLine ); myTextStartY += myDetailMetrics.height() - verticalSpacing(); } // // Draw the category. Not sure if we need word wrapping for it. // thepPainter->setFont( categoryFont( theOption ) ); //return to original font set by client thepPainter->drawText( myTextStartX, myTextStartY, theData.category() ); // // Draw the category with word wrapping if needed // /* myTextStartY += verticalSpacing(); if ( myIconFlag ) { myTextStartY += verticalSpacing(); } else { myTextStartY += myCategoryMetrics.height() + verticalSpacing(); } myList = wordWrap( theData.category(), myCategoryMetrics, theOption.rect.width() - myTextStartX ); QStringListIterator myLineWrapIter( myList ); while ( myLineWrapIter.hasNext() ) { QString myLine = myLineWrapIter.next(); thepPainter->drawText( myTextStartX, myTextStartY, myLine ); myTextStartY += myCategoryMetrics.height() - verticalSpacing(); } */ } //render by manual painting
void VerticalLine::draw (QPixmap &buffer, Scaler &, int startIndex, int pixelspace, int startX) { QPainter painter; painter.begin(&buffer); int x2 = data->getX(date); if (x2 == -1) return; int x = startX + (x2 * pixelspace) - (startIndex * pixelspace); if (x == -1) return; painter.setPen(getColor()); painter.drawLine (x, 0, x, buffer.height()); clearSelectionArea(); Q3PointArray array; array.putPoints(0, 4, x - (HANDLE_WIDTH / 2), 0, x + (HANDLE_WIDTH / 2), 0, x + (HANDLE_WIDTH / 2), buffer.height(), x - (HANDLE_WIDTH / 2), buffer.height()); setSelectionArea(new QRegion(array)); if (getStatus() == COBase::Selected) { clearGrabHandles(); int t = (int) buffer.height() / 4; setGrabHandle(new QRegion(x - (HANDLE_WIDTH / 2), 0, HANDLE_WIDTH, HANDLE_WIDTH, QRegion::Rectangle)); painter.fillRect(x - (HANDLE_WIDTH / 2), 0, HANDLE_WIDTH, HANDLE_WIDTH, getColor()); setGrabHandle(new QRegion(x - (HANDLE_WIDTH / 2), t, HANDLE_WIDTH, HANDLE_WIDTH, QRegion::Rectangle)); painter.fillRect(x - (HANDLE_WIDTH / 2), t, HANDLE_WIDTH, HANDLE_WIDTH, getColor()); setGrabHandle(new QRegion(x - (HANDLE_WIDTH / 2), t * 2, HANDLE_WIDTH, HANDLE_WIDTH, QRegion::Rectangle)); painter.fillRect(x - (HANDLE_WIDTH / 2), t * 2, HANDLE_WIDTH, HANDLE_WIDTH, getColor()); setGrabHandle(new QRegion(x - (HANDLE_WIDTH / 2), t * 3, HANDLE_WIDTH, HANDLE_WIDTH, QRegion::Rectangle)); painter.fillRect(x - (HANDLE_WIDTH / 2), t * 3, HANDLE_WIDTH, HANDLE_WIDTH, getColor()); setGrabHandle(new QRegion(x - (HANDLE_WIDTH / 2), t * 4, HANDLE_WIDTH, HANDLE_WIDTH, QRegion::Rectangle)); painter.fillRect(x - (HANDLE_WIDTH / 2), t * 4, HANDLE_WIDTH, HANDLE_WIDTH, getColor()); } painter.end(); }
void LogModelData::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { const static QPixmap listfile(":/Icons/page_white_text.png"); const static QPixmap arrowdown( ":/Icons/arrow-down.png" ); QPalette p = option.palette; auto color = index.data(Qt::BackgroundRole).value<QBrush>(); p.setBrush(QPalette::Window, color); painter->setFont(option.font); if (type == TEHNICAL_MESSAGE) { painter->save(); QFontMetrics fm(option.font); fm.height(); int delta = option.rect.height() - fm.height(); delta /= 2; painter->translate(2, delta); //Вычислаем длину сообщения и отрисовываем его QString tmpText = fm.elidedText(text,Qt::ElideRight,option.rect.width()); painter->drawText(option.rect,Qt::TextSingleLine,tmpText); painter->restore(); } else if (type == INFO_MESSAGE) { if (!index.data(MsgShowRole).toBool()){ if (timeConfirm.isEmpty()){ bool x = index.data(MsgFlashRole).toBool(); Qt::GlobalColor c = x ? Qt::red : Qt::transparent; p.setColor(QPalette::Window, QColor(c)); painter->fillRect(option.rect, c); } painter->save(); if (index.data(MsgConfirmRole).toBool()){ p.setColor(QPalette::Window, QColor(Qt::red)); QRect tmpRect = option.rect; tmpRect.setHeight(tmpRect.height()-1); tmpRect.setWidth(tmpRect.width()-1); painter->fillRect(tmpRect, Qt::red); } QFontMetrics fm(option.font); int delta = option.rect.height() - fm.height(); delta /= 2; painter->translate(2,delta); int offset = 0; //для кнопки открыть сообщение int x = option.rect.right() - arrowdown.width(); int y = option.rect.top() + ( option.rect.height() - arrowdown.height() ) / 2; // if (!listOfFiles.isEmpty()){ painter->drawPixmap(x-22,y-3,listfile); painter->drawPixmap(x-2,y-3,arrowdown); offset += 40; } if (!timeConfirm.isEmpty()) { offset += fm.width(timeConfirm)+4; } //Вычислаем длину сообщения и отрисовываем его QString tmpText = fm.elidedText(text,Qt::ElideRight,option.rect.width()-offset); painter->drawText(option.rect,Qt::TextSingleLine,tmpText); //если необходимо выводим дату подтверждения if (!timeConfirm.isEmpty()) { painter->drawText(option.rect.x()-offset+fm.width(timeConfirm),option.rect.y(),option.rect.width(),option.rect.height(),Qt::AlignRight,timeConfirm); } painter->restore(); } else { QFont itemFont = option.font; setPopipWidget(itemFont); m_popupWidget->resize(option.rect.width(),m_popupWidget->height()); m_popupWidget->setPalette(p); painter->save(); painter->translate(option.rect.x(), option.rect.y()); m_popupWidget->render(painter); painter->restore(); } } }
void KWMThemeClient::paintEvent( QPaintEvent *) { QPainter p; p.begin(widget()); int x,y; // first the corners int w1 = framePixmaps[FrameTopLeft]->width(); int h1 = framePixmaps[FrameTopLeft]->height(); if (w1 > width()/2) w1 = width()/2; if (h1 > height()/2) h1 = height()/2; p.drawPixmap(0,0,*framePixmaps[FrameTopLeft], 0,0,w1, h1); int w2 = framePixmaps[FrameTopRight]->width(); int h2 = framePixmaps[FrameTopRight]->height(); if (w2 > width()/2) w2 = width()/2; if (h2 > height()/2) h2 = height()/2; p.drawPixmap(width()-w2,0,*framePixmaps[FrameTopRight], framePixmaps[FrameTopRight]->width()-w2,0,w2, h2); int w3 = framePixmaps[FrameBottomLeft]->width(); int h3 = framePixmaps[FrameBottomLeft]->height(); if (w3 > width()/2) w3 = width()/2; if (h3 > height()/2) h3 = height()/2; p.drawPixmap(0,height()-h3,*framePixmaps[FrameBottomLeft], 0,framePixmaps[FrameBottomLeft]->height()-h3,w3, h3); int w4 = framePixmaps[FrameBottomRight]->width(); int h4 = framePixmaps[FrameBottomRight]->height(); if (w4 > width()/2) w4 = width()/2; if (h4 > height()/2) h4 = height()/2; p.drawPixmap(width()-w4,height()-h4,*(framePixmaps[FrameBottomRight]), framePixmaps[FrameBottomRight]->width()-w4, framePixmaps[FrameBottomRight]->height()-h4, w4, h4); QPixmap pm; QWMatrix m; int n,s,w; //top pm = *framePixmaps[FrameTop]; if (pm.width() > 0){ s = width()-w2-w1; n = s/pm.width(); w = n>0?s/n:s; m.reset(); m.scale(w/(float)pm.width(), 1); pm = pm.xForm(m); x = w1; while (1){ if (pm.width() < width()-w2-x){ p.drawPixmap(x,maxExtent-pm.height()-1, pm); x += pm.width(); } else { p.drawPixmap(x,maxExtent-pm.height()-1, pm, 0,0,width()-w2-x,pm.height()); break; } } } //bottom pm = *framePixmaps[FrameBottom]; if (pm.width() > 0){ s = width()-w4-w3; n = s/pm.width(); w = n>0?s/n:s; m.reset(); m.scale(w/(float)pm.width(), 1); pm = pm.xForm(m); x = w3; while (1){ if (pm.width() < width()-w4-x){ p.drawPixmap(x,height()-maxExtent+1,pm); x += pm.width(); } else { p.drawPixmap(x,height()-maxExtent+1,pm, 0,0,width()-w4-x,pm.height()); break; } } } //left pm = *framePixmaps[FrameLeft]; if (pm.height() > 0){ s = height()-h3-h1; n = s/pm.height(); w = n>0?s/n:s; m.reset(); m.scale(1, w/(float)pm.height()); pm = pm.xForm(m); y = h1; while (1){ if (pm.height() < height()-h3-y){ p.drawPixmap(maxExtent-pm.width()-1, y, pm); y += pm.height(); } else { p.drawPixmap(maxExtent-pm.width()-1, y, pm, 0,0, pm.width(), height()-h3-y); break; } } } //right pm = *framePixmaps[FrameRight]; if (pm.height() > 0){ s = height()-h4-h2; n = s/pm.height(); w = n>0?s/n:s; m.reset(); m.scale(1, w/(float)pm.height()); pm = pm.xForm(m); y = h2; while (1){ if (pm.height() < height()-h4-y){ p.drawPixmap(width()-maxExtent+1, y, pm); y += pm.height(); } else { p.drawPixmap(width()-maxExtent+1, y, pm, 0,0, pm.width(), height()-h4-y); break; } } } drawTitle(p); QColor c = widget()->colorGroup().background(); // KWM evidently had a 1 pixel border around the client window. We // emulate it here, but should be removed at some point in order to // seamlessly mesh widget themes p.setPen(c); p.drawRect(maxExtent-1, maxExtent-1, width()-(maxExtent-1)*2, height()-(maxExtent-1)*2); // We fill the area behind the wrapped widget to ensure that // shading animation is drawn as smoothly as possible QRect r(layout->cellGeometry(2, 1)); p.fillRect( r.x(), r.y(), r.width(), r.height(), c); p.end(); }
void RenderImage::setPixmap( const QPixmap &p, const QRect& r, CachedImage *o) { if(o != image) { RenderReplaced::setPixmap(p, r, o); return; } bool iwchanged = false; if(o->isErrorImage()) { int iw = p.width() + 8; int ih = p.height() + 8; // we have an alt and the user meant it (its not a text we invented) if ( element() && !alt.isEmpty() && !element()->getAttribute( ATTR_ALT ).isNull()) { const QFontMetrics &fm = style()->fontMetrics(); QRect br = fm.boundingRect ( 0, 0, 1024, 256, Qt::AlignAuto|Qt::WordBreak, alt.string() ); if ( br.width() > iw ) iw = br.width(); if ( br.height() > ih ) ih = br.height(); } if ( iw != intrinsicWidth() ) { setIntrinsicWidth( iw ); iwchanged = true; } if ( ih != intrinsicHeight() ) { setIntrinsicHeight( ih ); iwchanged = true; } } berrorPic = o->isErrorImage(); bool needlayout = false; // Image dimensions have been changed, see what needs to be done if ( ( o->pixmap_size().width() != intrinsicWidth() || o->pixmap_size().height() != intrinsicHeight() || iwchanged) ) { // qDebug("image dimensions have been changed, old: %d/%d new: %d/%d", // intrinsicWidth(), intrinsicHeight(), // o->pixmap_size().width(), o->pixmap_size().height()); if(!o->isErrorImage()) { setIntrinsicWidth( o->pixmap_size().width() ); setIntrinsicHeight( o->pixmap_size().height() ); } // In the case of generated image content using :before/:after, we might not be in the // render tree yet. In that case, we don't need to worry about check for layout, since we'll get a // layout when we get added in to the render tree hierarchy later. if (containingBlock()) { // lets see if we need to relayout at all.. int oldwidth = m_width; int oldheight = m_height; calcWidth(); calcHeight(); if(iwchanged || m_width != oldwidth || m_height != oldheight) needlayout = true; m_width = oldwidth; m_height = oldheight; } } #if APPLE_CHANGES && !KWIQ //FIXME: testing for animations // Stop the previous image, if it may be animating. pix.stopAnimations(); #endif #if APPLE_CHANGES pix.decreaseUseCount(); #endif pix = p; #if APPLE_CHANGES p.increaseUseCount(); #endif if (needlayout) { if (!selfNeedsLayout()) setNeedsLayout(true); if (minMaxKnown()) setMinMaxKnown(false); } else { #if APPLE_CHANGES // FIXME: We always just do a complete repaint, since we always pass in the full pixmap // rect at the moment anyway. resizeCache = QPixmap(); repaintRectangle(QRect(borderLeft()+paddingLeft(), borderTop()+paddingTop(), contentWidth(), contentHeight())); #else // FIXME: This code doesn't handle scaling properly, since it doesn't scale |r|. bool completeRepaint = !resizeCache.isNull(); int cHeight = contentHeight(); int scaledHeight = intrinsicHeight() ? ((o->valid_rect().height()*cHeight)/intrinsicHeight()) : 0; // don't bog down X server doing xforms if(completeRepaint && cHeight >= 5 && o->valid_rect().height() < intrinsicHeight() && (scaledHeight / (cHeight/5) == resizeCache.height() / (cHeight/5))) return; resizeCache = QPixmap(); // for resized animations if(completeRepaint) repaintRectangle(QRect(borderLeft()+paddingLeft(), borderTop()+paddingTop(), contentWidth(), contentHeight())); else { repaintRectangle(QRect(r.x() + borderLeft() + paddingLeft(), r.y() + borderTop() + paddingTop(), r.width(), r.height())); } #endif } }
void StatusLabel::setPict() { string icon; const char *text; if (m_client->getState() == Client::Connecting){ if (getSocketFactory()->isActive()){ if (m_timer == NULL){ m_timer = new QTimer(this); connect(m_timer, SIGNAL(timeout()), this, SLOT(timeout())); m_timer->start(1000); m_bBlink = false; } Protocol *protocol = m_client->protocol(); text = I18N_NOOP("Connecting"); unsigned status; if (m_bBlink){ icon = "online"; status = m_client->getManualStatus(); }else{ icon = "offline"; status = STATUS_OFFLINE; } if (protocol){ for (const CommandDef *cmd = protocol->statusList(); cmd->text; cmd++){ if (cmd->id == status){ icon = cmd->icon; break; } } } }else{ if (m_timer){ delete m_timer; m_timer = NULL; } Protocol *protocol = m_client->protocol(); const CommandDef *cmd = protocol->description(); icon = cmd->icon; int n = icon.find('_'); if (n > 0) icon = icon.substr(0, n); icon += "_inactive"; text = I18N_NOOP("Inactive"); } }else{ if (m_timer){ delete m_timer; m_timer = NULL; } if (m_client->getState() == Client::Error){ icon = "error"; text = I18N_NOOP("Error"); }else{ Protocol *protocol = m_client->protocol(); const CommandDef *cmd = protocol->description(); icon = cmd->icon; text = cmd->text; for (cmd = protocol->statusList(); cmd->text; cmd++){ if (cmd->id == m_client->getStatus()){ icon = cmd->icon; text = cmd->text; break; } } } } QPixmap pict = Pict(icon.c_str()); QString tip = CorePlugin::m_plugin->clientName(m_client); tip += "\n"; tip += i18n(text); setPixmap(pict); QToolTip::add(this, tip); resize(pict.width(), pict.height()); setFixedSize(pict.width(), pict.height()); };
ExportImageForRegression::ExportImageForRegression (const QPixmap &pixmap) : m_width (pixmap.width ()), m_height (pixmap.height ()) { }
QVariant QgsSymbolV2LegendNode::data( int role ) const { if ( role == Qt::DisplayRole ) { return mLabel; } else if ( role == Qt::EditRole ) { return mUserLabel.isEmpty() ? mItem.label() : mUserLabel; } else if ( role == Qt::DecorationRole ) { if ( mPixmap.isNull() || mPixmap.size() != mIconSize ) { QPixmap pix; if ( mItem.symbol() ) { QScopedPointer<QgsRenderContext> context( createTemporaryRenderContext() ); pix = QgsSymbolLayerV2Utils::symbolPreviewPixmap( mItem.symbol(), mIconSize, context.data() ); } else { pix = QPixmap( mIconSize ); pix.fill( Qt::transparent ); } if ( mItem.level() == 0 || ( model() && model()->testFlag( QgsLayerTreeModel::ShowLegendAsTree ) ) ) mPixmap = pix; else { // ident the symbol icon to make it look like a tree structure QPixmap pix2( pix.width() + mItem.level() * indentSize, pix.height() ); pix2.fill( Qt::transparent ); QPainter p( &pix2 ); p.drawPixmap( mItem.level() * indentSize, 0, pix ); p.end(); mPixmap = pix2; } } return mPixmap; } else if ( role == Qt::CheckStateRole ) { if ( !mItem.isCheckable() ) return QVariant(); QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( mLayerNode->layer() ); if ( !vlayer || !vlayer->rendererV2() ) return QVariant(); return vlayer->rendererV2()->legendSymbolItemChecked( mItem.ruleKey() ) ? Qt::Checked : Qt::Unchecked; } else if ( role == RuleKeyRole ) { return mItem.ruleKey(); } else if ( role == SymbolV2LegacyRuleKeyRole ) { return QVariant::fromValue<void*>( mItem.legacyRuleKey() ); } else if ( role == ParentRuleKeyRole ) { return mItem.parentRuleKey(); } return QVariant(); }
void QSkinObject::updateStyle() { //this makes the alpha blending work. just gdi funktions and a conversation from QPixmap to HBITMAP. not really interresting QPixmap so = QPixmap(skinPath + "so.png"); QPixmap sl = QPixmap(skinPath + "sl.png"); QPixmap sr = QPixmap(skinPath + "sr.png"); QPixmap su = QPixmap(skinPath + "su.png"); QPixmap qui = QPixmap(skinPath + "quiButton.png"); skinWidget->setMinimumSize (sr.width() + sl.width() + 128, su.height() + so.height()); widgetMask = QPixmap(skinWidget->width(), skinWidget->height()); widgetMask.fill(Qt::transparent); #ifdef WIN32 if(milchglas) { QImage tmp = QPixmap::QPixmap::grabWindow(QApplication::desktop()->winId(), skinWidget->geometry().x(), skinWidget->geometry().y(), skinWidget->rect().width(), skinWidget->rect().height()).toImage(); fastbluralpha(tmp, 4); widgetMask = QPixmap::fromImage(tmp); } #endif QPainter p(&widgetMask); int lo = skinWidget->width()-(so.width()-68); if(lo < 68) lo = 68; p.drawPixmap(QRect(skinWidget->width()-64, 0,64, so.height()), so, QRect(so.width()-64, 0 , 64, so.height())); p.drawPixmap(QRect(0, 0, 64, so.height()), so, QRect(0, 0 , 64, so.height())); p.drawPixmap(QRect(64, 0, skinWidget->width()-128, so.height()), so, QRect(64, 0, so.width()-128, so.height())); //p.drawPixmap(QRect(sl.width(), height()-su.height(), width(), su.height()), su); p.drawPixmap(QRect(sl.width(), skinWidget->height() - su.height(), skinWidget->width()-sl.width()-sr.width(), su.height()), su, QRect(sl.width(), 0, su.width()-sl.width()-sr.width(), su.height())); p.drawPixmap(QRect(0, skinWidget->height() - su.height(), sl.width(), su.height()), su, QRect(0, 0 , sl.width(), su.height())); p.drawPixmap(QRect(skinWidget->width()-sr.width(), skinWidget->height() - su.height(), sr.width(), su.height()), su, QRect(su.width()-sr.width(), 0 , sr.width(), su.height())); p.drawPixmap(QRect(skinWidget->width()-sr.width(), so.height(), sr.width(), skinWidget->height()-so.height()-su.height()), sr); p.drawPixmap(QRect(0, so.height(), sl.width(), skinWidget->height()-su.height()-so.height()), sl); p.setFont(titleFont); p.setPen(QPen(titleColor, 2)); contentsRect = QRect(sl.width(), so.height(), skinWidget->width() - sr.width() - sl.width(), skinWidget->height() - so.height() - su.height()); p.setBrush(backgroundColor); p.setPen(QPen(Qt::black, 1)); p.drawRect(contentsRect); p.drawText(QRect(sl.width(), 0, skinWidget->width()-qui.width()*3-8-sl.width()-sr.width(), so.height()), Qt::AlignVCenter, skinWidget->windowTitle()); p.end(); skinWidget->setMask(widgetMask.mask()); updateButtons(); }
// ////////////////////////////////////Draw BG image///////////////////////////////////////////////// void LvlScene::DrawBG(int x, int y, int w, int h, int sctID, QPixmap &srcimg, QPixmap &srcimg2, obj_BG &bgsetup) { /* Old Algorith */ //QPixmap BackImg; //QPainter * BGPaint; //QPixmap img; int si_attach, attach; /* New Algorith */ QGraphicsItem * item; //QGraphicsRectItem * itemR=NULL; QColor FillColor; //Fill undrawed space with color long sctW,//Section Width sctH,//Section Height R1W, //Img Width (Row1) R1H, //Img Height (Row1) R1Hc=0, //Crop height from bottom R1Ho=0, //Offset from top R2W, //Img Width (Row2) R2H, //Img Height (Row2) R2Hc=0, //Crop height from bottom R2Ho=0, //Offset from top RectPlus=0, toY; //Placing position Y 0 - top sctW = (long)fabs(x-w); sctH = (long)fabs(y-h); WriteToLog(QtDebugMsg, "Draw BG -> Draw BG Image"); attach = bgsetup.attached; // ///////////////////SingleRow BG/////////////////////////// if((bgsetup.type==0)&&(!bgsetup.editing_tiled)) { WriteToLog(QtDebugMsg, "Draw BG -> Style: SingleRow BG"); R1W = srcimg.width(); R1H = srcimg.height(); if(attach==0) // Get Pixel color (0 - bottom, 1 - top) FillColor = QColor( srcimg.toImage().pixel(0,0) ); // from top else FillColor = QColor( srcimg.toImage().pixel(0,(R1H-1)) ); //from bottom if(attach==0) { // 0 - bottom toY = (sctH>R1H)? sctH-R1H : 0; R1Hc = ((R1H>sctH) ? R1H-sctH : 0); //Crop height from bottom R1Ho = R1Hc; //Offset from top RectPlus=0; } else { // 1 - top toY = 0; R1Hc = ((R1H>sctH) ? R1H-sctH : 0); //Crop height from bottom R1Ho = 0; //Offset from top RectPlus=R1H; } // /////////////////////Draw row////////////////// item = addRect(0, 0, sctW, R1H-R1Hc, Qt::NoPen, QBrush(srcimg.copy(0, R1Ho, R1W, R1H-R1Hc))); item->setData(0, QString("BackGround%1").arg(sctID) ); item->setPos(x, y+toY); item->setZValue(bgZ); if(R1H < sctH) { item = addRect(0, 0, sctW, sctH-R1H, Qt::NoPen, QBrush(FillColor)); item->setData(0, QString("BackGround%1").arg(sctID) ); item->setPos(x,y+RectPlus); item->setZValue(bgZ); } } else // ///////////////////DoubleRow BG//////////////////////// if((bgsetup.type==1)&&(!bgsetup.editing_tiled)) { WriteToLog(QtDebugMsg, "Draw BG -> Style: DoubleRow BG"); si_attach = bgsetup.second_attached; // Second image attach R1W = srcimg.width(); R1H = srcimg.height(); //Fill empty space if((!srcimg2.isNull()) && (si_attach==0)) FillColor = QColor( srcimg2.toImage().pixel(0,0) ); else FillColor = QColor( srcimg.toImage().pixel(0,0) ); toY = (sctH>R1H)? sctH-R1H : 0; R1Hc = ((R1H>sctH) ? R1H-sctH : 0); //Crop height from bottom R1Ho = R1Hc; //Offset from top RectPlus=0; WriteToLog(QtDebugMsg, QString("Draw BG -> Draw first row, params: ")); // /////////////////////Draw first row////////////////// item = addRect(0, 0, sctW, R1H-R1Hc, Qt::NoPen, QBrush(srcimg.copy(0, R1Ho, R1W, R1H-R1Hc))); item->setData(0, QString("BackGround%1").arg(sctID) ); item->setPos(x, y+toY); item->setZValue(bgZ); // /////////////////////Draw first row////////////////// WriteToLog(QtDebugMsg, "Draw BG -> Draw second row"); R2W = srcimg2.width(); R2H = srcimg2.height(); if(si_attach==0) // over first { toY = (sctH-R1H > R2H)? sctH-R2H-R1H : 0; R2Hc = ((R2H+R1H>sctH) ? R2H-(sctH-R1H) : 0); //Crop height from bottom R2Ho = R2Hc; //Offset from top RectPlus=R2H; } else if(si_attach==1) // bottom { toY = (sctH > R2H)? sctH-R2H : 0; R2Hc = ((R2H>sctH) ? R2H-sctH : 0); //Crop height from bottom R2Ho = R2Hc; //Offset from top RectPlus=0; } if((!srcimg2.isNull()) && ((sctH > R1H)||(si_attach==1))) { // /////////////////////Draw second row////////////////// item = addRect(0, 0, sctW, R2H-R2Hc, Qt::NoPen, QBrush( srcimg2.copy(0, R2Ho, R2W, R2H-R2Hc) )); item->setData(0, QString("BackGround%1").arg(sctID) ); item->setPos(x, y+toY); item->setZValue(bgZ+0.0000000001); // /////////////////////Draw second row////////////////// } else if(srcimg2.isNull()) WriteToLog(QtWarningMsg, "Draw BG -> second image is Null"); if( R1H+RectPlus < sctH ) { item = addRect(0, 0, sctW, sctH-R1H-RectPlus, Qt::NoPen, QBrush(FillColor)); item->setData(0, QString("BackGround%1").arg(sctID) ); item->setPos(x,y); item->setZValue(bgZ); } } else // ///////////////////////////////Tiled BG/////////////////////////////// { WriteToLog(QtDebugMsg, "Draw BG -> Style: Tiled"); R1W = srcimg.width(); R1H = srcimg.height(); if(attach==0) { //Attached to Bottom RectPlus = sctH % R1H; toY = (sctH>R1H)? sctH-R1H : 0; //R1Hc = R1H-RectPlus; // Crop height from bottom/Offset from top item = addRect(0, 0, sctW, RectPlus, Qt::NoPen, QBrush(srcimg.copy(0, R1H-RectPlus, R1W, RectPlus)) ); item->setData(0, QString("BackGround%1").arg(sctID) ); item->setPos(x,y); item->setZValue(bgZ); if(sctH >= R1H) { item = addRect(0, 0, sctW, sctH-RectPlus, Qt::NoPen, QBrush(srcimg)); item->setData(0, "BackGround"+QString::number(sctID) ); item->setPos(x,y+RectPlus); item->setZValue(bgZ); } } else { //Attached to Top item = addRect(0, 0, sctW, sctH, Qt::NoPen, QBrush(srcimg)); item->setData(0, QString("BackGround%1").arg(sctID) ); item->setPos(x,y); item->setZValue(bgZ); } } WriteToLog(QtDebugMsg, "acceptedID is "+QString::number(sctID)+" data is "+item->data(0).toString()); WriteToLog(QtDebugMsg, "Draw BG -> Drawed"); }
/*! \reimp */ void QCompactStyle::drawControl( ControlElement element, QPainter *p, const QWidget *widget, const QRect &r, const QColorGroup &g, SFlags flags, const QStyleOption& opt ) { switch ( element ) { case CE_PopupMenuItem: { if (! widget || opt.isDefault()) break; const QPopupMenu *popupmenu = (const QPopupMenu *) widget; QMenuItem *mi = opt.menuItem(); if ( !mi ) break; int tab = opt.tabWidth(); int maxpmw = opt.maxIconWidth(); bool dis = !(flags & Style_Enabled); bool checkable = popupmenu->isCheckable(); bool act = flags & Style_Active; int x, y, w, h; r.rect( &x, &y, &w, &h ); QColorGroup itemg = g; if ( checkable ) maxpmw = QMAX( maxpmw, 8 ); // space for the checkmarks int checkcol = maxpmw; if ( mi && mi->isSeparator() ) { // draw separator p->setPen( g.dark() ); p->drawLine( x, y, x+w, y ); p->setPen( g.light() ); p->drawLine( x, y+1, x+w, y+1 ); return; } QBrush fill = act? g.brush( QColorGroup::Highlight ) : g.brush( QColorGroup::Button ); p->fillRect( x, y, w, h, fill); if ( !mi ) return; if ( mi->isChecked() ) { if ( act && !dis ) { qDrawShadePanel( p, x, y, checkcol, h, g, TRUE, 1, &g.brush( QColorGroup::Button ) ); } else { qDrawShadePanel( p, x, y, checkcol, h, g, TRUE, 1, &g.brush( QColorGroup::Midlight ) ); } } else if ( !act ) { p->fillRect(x, y, checkcol , h, g.brush( QColorGroup::Button )); } if ( mi->iconSet() ) { // draw iconset QIconSet::Mode mode = dis ? QIconSet::Disabled : QIconSet::Normal; if (act && !dis ) mode = QIconSet::Active; QPixmap pixmap; if ( checkable && mi->isChecked() ) pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode, QIconSet::On ); else pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode ); int pixw = pixmap.width(); int pixh = pixmap.height(); if ( act && !dis ) { if ( !mi->isChecked() ) qDrawShadePanel( p, x, y, checkcol, h, g, FALSE, 1, &g.brush( QColorGroup::Button ) ); } QRect cr( x, y, checkcol, h ); QRect pmr( 0, 0, pixw, pixh ); pmr.moveCenter( cr.center() ); p->setPen( itemg.text() ); p->drawPixmap( pmr.topLeft(), pixmap ); QBrush fill = act? g.brush( QColorGroup::Highlight ) : g.brush( QColorGroup::Button ); p->fillRect( x+checkcol + 1, y, w - checkcol - 1, h, fill); } else if ( checkable ) { // just "checking"... int mw = checkcol + motifItemFrame; int mh = h - 2*motifItemFrame; if ( mi->isChecked() ) { SFlags cflags = Style_Default; if (! dis) cflags |= Style_Enabled; if (act) cflags |= Style_On; drawPrimitive( PE_CheckMark, p, QRect(x + motifItemFrame + 2, y + motifItemFrame, mw, mh), itemg, cflags, opt ); } } p->setPen( act ? g.highlightedText() : g.buttonText() ); QColor discol; if ( dis ) { discol = itemg.text(); p->setPen( discol ); } int xm = motifItemFrame + checkcol + motifItemHMargin; if ( mi->custom() ) { int m = motifItemVMargin; p->save(); if ( dis && !act ) { p->setPen( g.light() ); mi->custom()->paint( p, itemg, act, !dis, x+xm+1, y+m+1, w-xm-tab+1, h-2*m ); p->setPen( discol ); } mi->custom()->paint( p, itemg, act, !dis, x+xm, y+m, w-xm-tab+1, h-2*m ); p->restore(); } QString s = mi->text(); if ( !s.isNull() ) { // draw text int t = s.find( '\t' ); int m = motifItemVMargin; const int text_flags = AlignVCenter|ShowPrefix | DontClip | SingleLine; if ( t >= 0 ) { // draw tab text if ( dis && !act ) { p->setPen( g.light() ); p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame+1, y+m+1, tab, h-2*m, text_flags, s.mid( t+1 )); p->setPen( discol ); } p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame, y+m, tab, h-2*m, text_flags, s.mid( t+1 ) ); s = s.left( t ); } if ( dis && !act ) { p->setPen( g.light() ); p->drawText( x+xm+1, y+m+1, w-xm+1, h-2*m, text_flags, s, t ); p->setPen( discol ); } p->drawText( x+xm, y+m, w-xm-tab+1, h-2*m, text_flags, s, t ); } else if ( mi->pixmap() ) { // draw pixmap QPixmap *pixmap = mi->pixmap(); if ( pixmap->depth() == 1 ) p->setBackgroundMode( OpaqueMode ); p->drawPixmap( x+xm, y+motifItemFrame, *pixmap ); if ( pixmap->depth() == 1 ) p->setBackgroundMode( TransparentMode ); } if ( mi->popup() ) { // draw sub menu arrow int dim = (h-2*motifItemFrame) / 2; if ( act ) { if ( !dis ) discol = white; QColorGroup g2( discol, g.highlight(), white, white, dis ? discol : white, discol, white ); drawPrimitive(PE_ArrowRight, p, QRect(x+w - motifArrowHMargin - motifItemFrame - dim, y + h / 2 - dim / 2, dim, dim), g2, Style_Enabled); } else { drawPrimitive(PE_ArrowRight, p, QRect(x+w - motifArrowHMargin - motifItemFrame - dim, y + h / 2 - dim / 2, dim, dim), g, !dis ? Style_Enabled : Style_Default); } } } break; default: QWindowsStyle::drawControl( element, p, widget, r, g, flags, opt ); break; } }
void QgsNorthArrowPlugin::renderNorthArrow( QPainter * theQPainter ) { //Large IF statement controlled by enable check box if ( mEnable ) { if ( theQPainter->isActive() ) { //QgsDebugMsg("Rendering north arrow on active painter"); } else { //QgsDebugMsg("Rendering north arrow on INactive painter!!!"); } QPixmap myQPixmap; //to store the north arrow image in QString myFileNameQString = QDir::cleanPath( QgsApplication::pkgDataPath() + "/images/north_arrows/default.png" ); //QgsDebugMsg("Trying to load " + myFileNameQString); if ( myQPixmap.load( myFileNameQString ) ) { double centerXDouble = myQPixmap.width() / 2; double centerYDouble = myQPixmap.height() / 2; //save the current canvas rotation theQPainter->save(); // //work out how to shift the image so that it rotates // properly about its center //(x cos a + y sin a - x, -x sin a + y cos a - y) // // could move this call to somewhere else so that it is only // called when the projection or map extent changes if ( mAutomatic ) calculateNorthDirection(); double myRadiansDouble = mRotationInt * PI / 180.0; int xShift = static_cast<int>(( ( centerXDouble * cos( myRadiansDouble ) ) + ( centerYDouble * sin( myRadiansDouble ) ) ) - centerXDouble ); int yShift = static_cast<int>(( ( -centerXDouble * sin( myRadiansDouble ) ) + ( centerYDouble * cos( myRadiansDouble ) ) ) - centerYDouble ); // need width/height of paint device int myHeight = theQPainter->device()->height(); int myWidth = theQPainter->device()->width(); //QgsDebugMsg("Rendering north arrow at " + mPlacementLabels.at(mPlacementIndex)); //Determine placement of label from form combo box switch ( mPlacementIndex ) { case 0: // Bottom Left theQPainter->translate( 0, myHeight - myQPixmap.height() ); break; case 1: // Top Left //no need to translate for TL corner because we're already at the origin theQPainter->translate( 0, 0 ); break; case 2: // Top Right theQPainter->translate( myWidth - myQPixmap.width(), 0 ); break; case 3: // Bottom Right theQPainter->translate( myWidth - myQPixmap.width(), myHeight - myQPixmap.height() ); break; default: { //QgsDebugMsg("Unable to determine where to put north arrow so defaulting to top left"); } } //rotate the canvas by the north arrow rotation amount theQPainter->rotate( mRotationInt ); //Now we can actually do the drawing, and draw a smooth north arrow even when rotated theQPainter->setRenderHint( QPainter::SmoothPixmapTransform ); theQPainter->drawPixmap( xShift, yShift, myQPixmap ); //unrotate the canvas again theQPainter->restore(); } else { QFont myQFont( "time", 12, QFont::Bold ); theQPainter->setFont( myQFont ); theQPainter->setPen( Qt::black ); theQPainter->drawText( 10, 20, tr( "North arrow pixmap not found" ) ); } } }
void QStyleItem::paint(QPainter *painter) { if (width() < 1 || height() <1) return; initStyleOption(); switch (m_itemType) { case Button: qApp->style()->drawControl(QStyle::CE_PushButton, m_styleoption, painter); break; case ItemRow :{ QPixmap pixmap; // Only draw through style once const QString pmKey = QLatin1Literal("itemrow") % QString::number(m_styleoption->state,16) % activeControl(); if (!QPixmapCache::find(pmKey, pixmap) || pixmap.width() < width() || height() != pixmap.height()) { int newSize = width(); pixmap = QPixmap(newSize, height()); pixmap.fill(Qt::transparent); QPainter pixpainter(&pixmap); qApp->style()->drawPrimitive(QStyle::PE_PanelItemViewRow, m_styleoption, &pixpainter); if (!qApp->style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected) && selected()) pixpainter.fillRect(m_styleoption->rect, m_styleoption->palette.highlight()); QPixmapCache::insert(pmKey, pixmap); } painter->drawPixmap(0, 0, pixmap); } break; case Item: qApp->style()->drawControl(QStyle::CE_ItemViewItem, m_styleoption, painter); break; case Header: qApp->style()->drawControl(QStyle::CE_Header, m_styleoption, painter); break; case ToolButton: #ifdef Q_OS_MAC if (style() == "mac" && hint().indexOf("segmented") != -1) { const QPaintDevice *target = painter->device(); HIThemeSegmentDrawInfo sgi; sgi.version = 0; sgi.state = isEnabled() ? kThemeStateActive : kThemeStateDisabled; if (sunken()) sgi.state |= kThemeStatePressed; sgi.size = kHIThemeSegmentSizeNormal; sgi.kind = kHIThemeSegmentKindTextured; sgi.value = on() && !sunken() ? kThemeButtonOn : kThemeButtonOff; sgi.adornment |= kHIThemeSegmentAdornmentLeadingSeparator; if (sunken()) { sgi.adornment |= kHIThemeSegmentAdornmentTrailingSeparator; } SInt32 button_height; GetThemeMetric(kThemeMetricButtonRoundedHeight, &button_height); sgi.position = info() == "leftmost" ? kHIThemeSegmentPositionFirst: info() == "rightmost" ? kHIThemeSegmentPositionLast : info() == "h_middle" ? kHIThemeSegmentPositionMiddle : kHIThemeSegmentPositionOnly; QRect centered = m_styleoption->rect; centered.setHeight(button_height); centered.moveCenter(m_styleoption->rect.center()); HIRect hirect = qt_hirectForQRect(centered.translated(0, -1), QRect(0, 0, 0, 0)); HIThemeDrawSegment(&hirect, &sgi, qt_mac_cg_context(target), kHIThemeOrientationNormal); } else #endif qApp->style()->drawComplexControl(QStyle::CC_ToolButton, qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), painter); break; case Tab: qApp->style()->drawControl(QStyle::CE_TabBarTab, m_styleoption, painter); break; case Frame: qApp->style()->drawControl(QStyle::CE_ShapedFrame, m_styleoption, painter); break; case FocusFrame: if (style() == "mac" && hint().indexOf("rounded") != -1) break; // embedded in the line itself else qApp->style()->drawControl(QStyle::CE_FocusFrame, m_styleoption, painter); break; case TabFrame: qApp->style()->drawPrimitive(QStyle::PE_FrameTabWidget, m_styleoption, painter); break; case MenuBar: qApp->style()->drawControl(QStyle::CE_MenuBarEmptyArea, m_styleoption, painter); break; case MenuBarItem: qApp->style()->drawControl(QStyle::CE_MenuBarItem, m_styleoption, painter); break; case MenuItem: case ComboBoxItem: // fall through qApp->style()->drawControl(QStyle::CE_MenuItem, m_styleoption, painter); break; case CheckBox: qApp->style()->drawControl(QStyle::CE_CheckBox, m_styleoption, painter); break; case RadioButton: qApp->style()->drawControl(QStyle::CE_RadioButton, m_styleoption, painter); break; case Edit: { #ifdef Q_OS_MAC if (style() == "mac" && hint().indexOf("rounded") != -1) { const QPaintDevice *target = painter->device(); HIThemeFrameDrawInfo fdi; fdi.version = 0; fdi.state = kThemeStateActive; SInt32 frame_size; GetThemeMetric(kThemeMetricEditTextFrameOutset, &frame_size); fdi.kind = kHIThemeFrameTextFieldRound; if ((m_styleoption->state & QStyle::State_ReadOnly) || !(m_styleoption->state & QStyle::State_Enabled)) fdi.state = kThemeStateInactive; fdi.isFocused = hasFocus(); HIRect hirect = qt_hirectForQRect(m_styleoption->rect, QRect(frame_size, frame_size, frame_size * 2, frame_size * 2)); HIThemeDrawFrame(&hirect, &fdi, qt_mac_cg_context(target), kHIThemeOrientationNormal); } else #endif qApp->style()->drawPrimitive(QStyle::PE_PanelLineEdit, m_styleoption, painter); } break; case MacHelpButton: #ifdef Q_OS_MAC { const QPaintDevice *target = painter->device(); HIThemeButtonDrawInfo fdi; fdi.kind = kThemeRoundButtonHelp; fdi.version = 0; fdi.adornment = 0; fdi.state = sunken() ? kThemeStatePressed : kThemeStateActive; HIRect hirect = qt_hirectForQRect(m_styleoption->rect,QRect(0, 0, 0, 0)); HIThemeDrawButton(&hirect, &fdi, qt_mac_cg_context(target), kHIThemeOrientationNormal, NULL); } #endif break; case Widget: qApp->style()->drawPrimitive(QStyle::PE_Widget, m_styleoption, painter); break; case ScrollAreaCorner: qApp->style()->drawPrimitive(QStyle::PE_PanelScrollAreaCorner, m_styleoption, painter); break; case Splitter: if (m_styleoption->rect.width() == 1) painter->fillRect(0, 0, width(), height(), m_styleoption->palette.dark().color()); else qApp->style()->drawControl(QStyle::CE_Splitter, m_styleoption, painter); break; case ComboBox: { qApp->style()->drawComplexControl(QStyle::CC_ComboBox, qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), painter); // This is needed on mac as it will use the painter color and ignore the palette QPen pen = painter->pen(); painter->setPen(m_styleoption->palette.text().color()); qApp->style()->drawControl(QStyle::CE_ComboBoxLabel, m_styleoption, painter); painter->setPen(pen); } break; case SpinBox: qApp->style()->drawComplexControl(QStyle::CC_SpinBox, qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), painter); break; case Slider: qApp->style()->drawComplexControl(QStyle::CC_Slider, qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), painter); break; case Dial: qApp->style()->drawComplexControl(QStyle::CC_Dial, qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), painter); break; case ProgressBar: qApp->style()->drawControl(QStyle::CE_ProgressBar, m_styleoption, painter); break; case ToolBar: qApp->style()->drawControl(QStyle::CE_ToolBar, m_styleoption, painter); break; case StatusBar: if (style() == "mac") { m_styleoption->rect.adjust(0, 1, 0, 0); qApp->style()->drawControl(QStyle::CE_ToolBar, m_styleoption, painter); m_styleoption->rect.adjust(0, -1, 0, 0); painter->setPen(m_styleoption->palette.dark().color().darker(120)); painter->drawLine(m_styleoption->rect.topLeft(), m_styleoption->rect.topRight()); } else { qApp->style()->drawPrimitive(QStyle::PE_PanelToolBar, m_styleoption, painter); } break; case GroupBox: qApp->style()->drawComplexControl(QStyle::CC_GroupBox, qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), painter); break; case ScrollBar: qApp->style()->drawComplexControl(QStyle::CC_ScrollBar, qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), painter); break; case Menu: { QStyleHintReturnMask val; qApp->style()->styleHint(QStyle::SH_Menu_Mask, m_styleoption, 0, &val); painter->save(); painter->setClipRegion(val.region); painter->fillRect(m_styleoption->rect, m_styleoption->palette.window()); painter->restore(); qApp->style()->drawPrimitive(QStyle::PE_PanelMenu, m_styleoption, painter); QStyleOptionFrame frame; frame.lineWidth = qApp->style()->pixelMetric(QStyle::PM_MenuPanelWidth); frame.midLineWidth = 0; frame.rect = m_styleoption->rect; qApp->style()->drawPrimitive(QStyle::PE_FrameMenu, &frame, painter); } break; default: break; } }