void GraphView::drawBlank() { QRect pixmapSize(geometry()); pixmapSize.adjust(0, 0, 2, 2); // for some reason, we need to pad this to get the full size... m_backBuffer = QPixmap(pixmapSize.size()); m_backBuffer.fill(this, 0, 0); }
void WeatherButton::generateIcons() { if ( !pixmap() ) return; QImage image = pixmap()->convertToImage(); image = image.smoothScale( pixmapSize(), QImage::ScaleMin ); KIconEffect effect; m_normalIcon = effect.apply( image, KIcon::Panel, KIcon::DefaultState ); m_activeIcon = effect.apply( image, KIcon::Panel, KIcon::ActiveState ); }
void HbRepeatIconItem::paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget ) { Q_UNUSED(option); Q_UNUSED(widget); if(!mConnected) { connect(&mTimer,SIGNAL(timeout()),this,SLOT(updateAnimation())); } // Chec the status of timer if (!mTimer.isActive()) { mTimer.start(122); } if(mParentRect != parentItem()->boundingRect()) { resizeEvent(0); // need to regenerate optimized pixmap. } QPixmap newblit(boundingRect().size().toSize()); newblit.fill(Qt::white); QPainter p; p.begin(&newblit); if(mOrientation == Qt::Horizontal){ QSizeF pixmapSize(boundingRect().size().width(),mIcon.height()); if (QApplication::layoutDirection() == Qt::RightToLeft) { p.drawPixmap(QPointF(0,0), *mRepeatPixmap, QRectF(QPointF(mIcon.width()-mOffset,0),pixmapSize)); } else { p.drawPixmap(QPointF(0,0), *mRepeatPixmap, QRectF(QPointF(mOffset,0),pixmapSize)); } } else{ QSizeF pixmapSize(mIcon.width(),boundingRect().size().height()); p.drawPixmap(QPointF(0,0), *mRepeatPixmap, QRectF(QPointF(0,mOffset),pixmapSize)); } p.end(); if(!mMask.isNull()) { newblit.setMask(mMask); } painter->drawPixmap(QPointF(0,0),newblit); }
void GraphView::drawCurve(AnimationCurve* pCurve) { QRect pixmapSize(geometry()); pixmapSize.adjust(0, 0, 2, 2); // for some reason, we need to padd this to get the full size... m_backBuffer = QPixmap(pixmapSize.size()); m_backBuffer.fill(this, 0, 0); QPainter painter(&m_backBuffer); painter.initFrom(this); painter.setPen(Qt::black); painter.setBrush(QColor(0, 0, 0)); painter.drawRect(geometry()); // draw curve std::vector<ControlPoint> aControlPoints; pCurve->getMainControlPoints(aControlPoints); painter.setPen(Qt::white); painter.setBrush(QColor(255, 255, 255)); std::vector<ControlPoint>::const_iterator itCP = aControlPoints.begin(); for (; itCP != aControlPoints.end(); ++itCP) { const ControlPoint& cp = *itCP; painter.drawEllipse(cp.x, cp.y, 4, 4); } // draw values... QFont newFont = font(); newFont.setPointSize(9); setFont(newFont); QFontMetrics metrics(font()); update(); }
void AccountWidget::update( const QPersistentModelIndex& idx, int accountIdx ) { Tomahawk::Accounts::Account* account = idx.data( Tomahawk::Accounts::AccountModel::ChildrenOfFactoryRole ) .value< QList< Tomahawk::Accounts::Account* > >().at( accountIdx ); if ( account ) { const QPixmap& pixmap = account->icon(); QSize pixmapSize( 32, 32 ); m_imageLabel->setPixmap( pixmap.scaled( pixmapSize, Qt::KeepAspectRatio, Qt::SmoothTransformation ) ); m_imageLabel->setFixedSize( pixmapSize ); QFontMetrics fm = m_idLabel->fontMetrics(); m_idLabel->setText( account->accountFriendlyName() ); m_idLabel->setToolTip( "<b>" + account->accountServiceName() + "</b><br>" + account->accountFriendlyName() ); //we already know it's a factory because of the FactoryProxy Tomahawk::Accounts::AccountFactory* fac = qobject_cast< Tomahawk::Accounts::AccountFactory* >( idx.data( Tomahawk::Accounts::AccountModel::AccountData ) .value< QObject* >() ); if ( fac->factoryId() == "twitteraccount" ) { m_inviteContainer->setVisible( false ); m_inviteButton->setVisible( false ); } switch ( account->connectionState() ) { case Tomahawk::Accounts::Account::Connected: if ( account->enabled() ) m_statusToggle->setChecked( true ); else qDebug() << "AccountWidget warning:" << account->accountFriendlyName() << "is Connected but Disabled!"; m_spinner->fadeOut(); m_statusToggle->setBackChecked( true ); setInviteWidgetsEnabled( true ); break; case Tomahawk::Accounts::Account::Connecting: if ( !account->enabled() ) qDebug() << "AccountWidget warning:" << account->accountFriendlyName() << "is Connecting but Disabled!"; m_spinner->fadeIn(); m_statusToggle->setBackChecked( false ); setInviteWidgetsEnabled( false ); break; case Tomahawk::Accounts::Account::Disconnected: if ( !account->enabled() ) m_statusToggle->setChecked( false ); else qDebug() << "AccountWidget warning:" << account->accountFriendlyName() << "is Disconnected but Enabled!"; m_spinner->fadeOut(); m_statusToggle->setBackChecked( false ); setInviteWidgetsEnabled( false ); break; case Tomahawk::Accounts::Account::Disconnecting: if ( account->enabled() ) qDebug() << "AccountWidget warning:" << account->accountFriendlyName() << "is Disconnecting but Enabled!"; m_spinner->fadeIn(); m_statusToggle->setBackChecked( true ); setInviteWidgetsEnabled( false ); } } }
void AccountWidget::update( const QPersistentModelIndex& idx, int accountIdx ) { Tomahawk::Accounts::Account* account = idx.data( Tomahawk::Accounts::AccountModel::ChildrenOfFactoryRole ) .value< QList< Tomahawk::Accounts::Account* > >().at( accountIdx ); if ( account ) { const QPixmap& pixmap = account->icon(); QSize pixmapSize( scaled( 32, 32 ) ); m_imageLabel->setPixmap( pixmap.scaled( pixmapSize, Qt::KeepAspectRatio, Qt::SmoothTransformation ) ); m_imageLabel->setFixedSize( pixmapSize ); QFontMetrics fm = m_idLabel->fontMetrics(); m_idLabel->setText( account->accountFriendlyName() ); m_idLabel->setToolTip( "<b>" + account->accountServiceName() + "</b><br>" + account->accountFriendlyName() ); switch ( account->connectionState() ) { case Tomahawk::Accounts::Account::Connected: { if ( account->enabled() ) m_statusToggle->setChecked( true ); else tDebug() << "AccountWidget warning:" << account->accountFriendlyName() << "is Connected but Disabled!"; m_spinner->fadeOut(); m_statusToggle->setBackChecked( true ); setInviteWidgetsEnabled( true ); break; } case Tomahawk::Accounts::Account::Connecting: { if ( !account->enabled() ) tDebug() << "AccountWidget warning:" << account->accountFriendlyName() << "is Connecting but Disabled!"; m_spinner->fadeIn(); m_statusToggle->setBackChecked( false ); setInviteWidgetsEnabled( false ); break; } case Tomahawk::Accounts::Account::Disconnected: { if ( !account->enabled() ) m_statusToggle->setChecked( false ); else tDebug() << "AccountWidget warning:" << account->accountFriendlyName() << "is Disconnected but Enabled!"; m_spinner->fadeOut(); m_statusToggle->setBackChecked( false ); setInviteWidgetsEnabled( false ); break; } case Tomahawk::Accounts::Account::Disconnecting: { if ( account->enabled() ) tDebug() << "AccountWidget warning:" << account->accountFriendlyName() << "is Disconnecting but Enabled!"; m_spinner->fadeIn(); m_statusToggle->setBackChecked( true ); setInviteWidgetsEnabled( false ); } } if ( !account->enabled() && account->connectionState() == Tomahawk::Accounts::Account::Disconnected ) { m_spinner->fadeOut(); m_statusToggle->setBackChecked( false ); m_statusToggle->setChecked( false ); setInviteWidgetsEnabled( false ); } else if ( account->enabled() && account->connectionState() == Tomahawk::Accounts::Account::Connected ) { m_spinner->fadeOut(); m_statusToggle->setBackChecked( true ); m_statusToggle->setChecked( true ); setInviteWidgetsEnabled( true ); } } }
bool TextCreator::create(const QString &path, int width, int height, QImage &img) { // Filter out unwanted mimetypes KMimeType::Ptr mimeType = KMimeType::findByPath(path); if(mimeType->is("text/rtf")) return false; if(!m_splitter) { m_splitter = new KPixmapSplitter; QString pixmap = locate("data", "konqueror/pics/thumbnailfont_7x4.png"); if(!pixmap.isEmpty()) { // FIXME: make font/glyphsize configurable... m_splitter->setPixmap(QPixmap(pixmap)); m_splitter->setItemSize(QSize(4, 7)); } } bool ok = false; // determine some sizes... // example: width: 60, height: 64 QSize pixmapSize(width, height); if(height * 3 > width * 4) pixmapSize.setHeight(width * 4 / 3); else pixmapSize.setWidth(height * 3 / 4); if(pixmapSize != m_pixmap.size()) m_pixmap.resize(pixmapSize); // one pixel for the rectangle, the rest. whitespace int xborder = 1 + pixmapSize.width() / 16; // minimum x-border int yborder = 1 + pixmapSize.height() / 16; // minimum y-border QSize chSize = m_splitter->itemSize(); // the size of one char int xOffset = chSize.width(); int yOffset = chSize.height(); // calculate a better border so that the text is centered int canvasWidth = pixmapSize.width() - 2 * xborder; int canvasHeight = pixmapSize.height() - 2 * yborder; int numCharsPerLine = (int)(canvasWidth / chSize.width()); int numLines = (int)(canvasHeight / chSize.height()); // assumes an average line length of <= 120 chars const int bytesToRead = 120 * numLines; // create text-preview QFile file(path); if(file.open(IO_ReadOnly)) { if(!m_data || m_dataSize < bytesToRead + 1) { delete[] m_data; m_data = new char[bytesToRead + 1]; m_dataSize = bytesToRead + 1; } int read = file.readBlock(m_data, bytesToRead); if(read > 0) { ok = true; m_data[read] = '\0'; QString text = QString::fromLocal8Bit(m_data); // FIXME: maybe strip whitespace and read more? m_pixmap.fill(QColor(245, 245, 245)); // light-grey background QRect rect; int rest = m_pixmap.width() - (numCharsPerLine * chSize.width()); xborder = QMAX(xborder, rest / 2); // center horizontally rest = m_pixmap.height() - (numLines * chSize.height()); yborder = QMAX(yborder, rest / 2); // center vertically // end centering int x = xborder, y = yborder; // where to paint the characters int posNewLine = m_pixmap.width() - (chSize.width() + xborder); int posLastLine = m_pixmap.height() - (chSize.height() + yborder); bool newLine = false; Q_ASSERT(posNewLine > 0); const QPixmap *fontPixmap = &(m_splitter->pixmap()); for(uint i = 0; i < text.length(); i++) { if(x > posNewLine || newLine) // start a new line? { x = xborder; y += yOffset; if(y > posLastLine) // more text than space break; // after starting a new line, we also jump to the next // physical newline in the file if we don't come from one if(!newLine) { int pos = text.find('\n', i); if(pos == -1) break; i = pos + 1; } newLine = false; } // check for newlines in the text (unix,dos) QChar ch = text.at(i); if(ch == '\n') { newLine = true; continue; } else if(ch == '\r' && text.at(i + 1) == '\n') { newLine = true; i++; // skip the next character (\n) as well continue; } rect = m_splitter->coordinates(ch); if(!rect.isEmpty()) { bitBlt(&m_pixmap, QPoint(x, y), fontPixmap, rect, Qt::CopyROP); } x += xOffset; // next character } if(ok) img = m_pixmap.convertToImage(); } file.close(); } return ok; }