void KxMenuItemWidget::paintEvent(QPaintEvent *event) { // Do not draw invisible menu items if(!fMenuItem->isVisible()) return; QStylePainter painter(this); QStyleOptionMenuItem opt = getStyleOption(); QRect boxRect; bool inOptionBox = false; QWidget *q = parentWidget(); const int hmargin = q->style()->pixelMetric(QStyle::PM_MenuDesktopFrameWidth, 0, q), iconWidth = q->style()->pixelMetric(QStyle::PM_SmallIconSize, 0, q); if(!fMenuItem->isSeparator()) { if(fMenuItem->hasOptionBox()) { boxRect.setRect(rect().right() - hmargin - iconWidth, rect().top(), iconWidth, rect().height()); QPoint p = QCursor::pos(); p = mapFromGlobal(p); if(boxRect.contains(p)) { inOptionBox = true; } else { // Subtract option box rect from style option rect int newRight = opt.rect.right() - iconWidth - hmargin; opt.rect.setRight(newRight); } } } // Draw general menu item opt.rect.adjust(0, 0, -1, 0); painter.drawControl(QStyle::CE_MenuItem, opt); // Draw shortcut QKeySequence shortcutSeq = fMenuItem->shortcut(); if(!shortcutSeq.isEmpty()) { // shortcut bounds QRect scRect = opt.rect; QString shortcut = shortcutSeq.toString(QKeySequence::NativeText); QMenu *menu = qobject_cast<QMenu *>(parentWidget()); Q_ASSERT(menu != NULL); int shortcutWidth = 12; // default value in case there is no font if ( menu ) { QFontMetrics metrics(fMenuItem->font().resolve(menu->font())); shortcutWidth = metrics.width(shortcut); } scRect.setLeft(scRect.right() - shortcutWidth); if(inOptionBox || !fMenuItem->hasOptionBox()) { scRect.translate(-iconWidth, 0); } scRect.translate(-kShortcutRightMargin, 0); painter.drawItemText(scRect, Qt::AlignRight | Qt::AlignVCenter, palette(), true, shortcut); } // Draw option box if(!fMenuItem->isSeparator() && fMenuItem->hasOptionBox()) { QIcon* boxIcon = NULL; QVariant v = fMenuItem->optionBoxAction()->property( "optionBoxIcon" ); if ( v.isValid() ) { QString optionBoxIcon; optionBoxIcon = v.toString(); boxIcon = KxQtHelper::createIcon( optionBoxIcon ); } if ( boxIcon == NULL ) { boxIcon = new QIcon(":/optionBox.png"); } boxRect.setRect(rect().right() - hmargin - iconWidth, rect().top()+(rect().height()-iconWidth)/2, iconWidth, iconWidth); boxIcon->paint(&painter, boxRect, Qt::AlignCenter, fMenuItem->isEnabled() ? QIcon::Normal : QIcon::Disabled); delete boxIcon; } }
void QItemDelegate::doLayout(const QStyleOptionViewItem &option, QRect *checkRect, QRect *pixmapRect, QRect *textRect, bool hint) const { Q_ASSERT(checkRect && pixmapRect && textRect); Q_D(const QItemDelegate); const QWidget *widget = d->widget(option); QStyle *style = widget ? widget->style() : QApplication::style(); const bool hasCheck = checkRect->isValid(); const bool hasPixmap = pixmapRect->isValid(); const bool hasText = textRect->isValid(); const int textMargin = hasText ? style->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, widget) + 1 : 0; const int pixmapMargin = hasPixmap ? style->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, widget) + 1 : 0; const int checkMargin = hasCheck ? style->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, widget) + 1 : 0; int x = option.rect.left(); int y = option.rect.top(); int w, h; textRect->adjust(-textMargin, 0, textMargin, 0); // add width padding if (textRect->height() == 0 && (!hasPixmap || !hint)) { //if there is no text, we still want to have a decent height for the item sizeHint and the editor size textRect->setHeight(option.fontMetrics.height()); } QSize pm(0, 0); if (hasPixmap) { pm = pixmapRect->size(); pm.rwidth() += 2 * pixmapMargin; } if (hint) { h = qMax(checkRect->height(), qMax(textRect->height(), pm.height())); if (option.decorationPosition == QStyleOptionViewItem::Left || option.decorationPosition == QStyleOptionViewItem::Right) { w = textRect->width() + pm.width(); } else { w = qMax(textRect->width(), pm.width()); } } else { w = option.rect.width(); h = option.rect.height(); } int cw = 0; QRect check; if (hasCheck) { cw = checkRect->width() + 2 * checkMargin; if (hint) w += cw; if (option.direction == Qt::RightToLeft) { check.setRect(x + w - cw, y, cw, h); } else { check.setRect(x + checkMargin, y, cw, h); } } // at this point w should be the *total* width QRect display; QRect decoration; switch (option.decorationPosition) { case QStyleOptionViewItem::Top: { if (hasPixmap) pm.setHeight(pm.height() + pixmapMargin); // add space h = hint ? textRect->height() : h - pm.height(); if (option.direction == Qt::RightToLeft) { decoration.setRect(x, y, w - cw, pm.height()); display.setRect(x, y + pm.height(), w - cw, h); } else { decoration.setRect(x + cw, y, w - cw, pm.height()); display.setRect(x + cw, y + pm.height(), w - cw, h); } break; } case QStyleOptionViewItem::Bottom: { if (hasText) textRect->setHeight(textRect->height() + textMargin); // add space h = hint ? textRect->height() + pm.height() : h; if (option.direction == Qt::RightToLeft) { display.setRect(x, y, w - cw, textRect->height()); decoration.setRect(x, y + textRect->height(), w - cw, h - textRect->height()); } else { display.setRect(x + cw, y, w - cw, textRect->height()); decoration.setRect(x + cw, y + textRect->height(), w - cw, h - textRect->height()); } break; } case QStyleOptionViewItem::Left: { if (option.direction == Qt::LeftToRight) { decoration.setRect(x + cw, y, pm.width(), h); display.setRect(decoration.right() + 1, y, w - pm.width() - cw, h); } else { display.setRect(x, y, w - pm.width() - cw, h); decoration.setRect(display.right() + 1, y, pm.width(), h); } break; } case QStyleOptionViewItem::Right: { if (option.direction == Qt::LeftToRight) { display.setRect(x + cw, y, w - pm.width() - cw, h); decoration.setRect(display.right() + 1, y, pm.width(), h); } else { decoration.setRect(x, y, pm.width(), h); display.setRect(decoration.right() + 1, y, w - pm.width() - cw, h); } break; } default: qWarning("doLayout: decoration position is invalid"); decoration = *pixmapRect; break; } if (!hint) { // we only need to do the internal layout if we are going to paint *checkRect = QStyle::alignedRect(option.direction, Qt::AlignCenter, checkRect->size(), check); *pixmapRect = QStyle::alignedRect(option.direction, option.decorationAlignment, pixmapRect->size(), decoration); // the text takes up all available space, unless the decoration is not shown as selected if (option.showDecorationSelected) *textRect = display; else *textRect = QStyle::alignedRect(option.direction, option.displayAlignment, textRect->size().boundedTo(display.size()), display); } else { *checkRect = check; *pixmapRect = decoration; *textRect = display; } }
////////////////////////////////////////////////////////////////////// // Called to draw an overlay bitmap containing grid and text that // does not need to be recreated every fft data update. ////////////////////////////////////////////////////////////////////// void CPlotter::drawOverlay() { if (m_OverlayPixmap.isNull()) return; int w = m_OverlayPixmap.width(); int h = m_OverlayPixmap.height(); int x,y; float pixperdiv; QRect rect; QPainter painter(&m_OverlayPixmap); painter.initFrom(this); // horizontal grids (size and grid calcs could be moved to resize) m_VerDivs = h/m_VdivDelta+1; m_HorDivs = qMin(w/m_HdivDelta, HORZ_DIVS_MAX); if (m_HorDivs % 2) m_HorDivs++; // we want an odd number of divs so that we have a center line //m_OverlayPixmap.fill(Qt::black); // fill background with gradient QLinearGradient gradient(0, 0, 0 ,h); gradient.setColorAt(0, QColor(0x20,0x20,0x20,0xFF)); gradient.setColorAt(1, QColor(0x4F,0x4F,0x4F,0xFF)); painter.setBrush(gradient); painter.drawRect(0, 0, w, h); // Draw demod filter box if (m_FilterBoxEnabled) { // Clamping no longer necessary as we do it in mouseMove() //ClampDemodParameters(); m_DemodFreqX = xFromFreq(m_DemodCenterFreq); m_DemodLowCutFreqX = xFromFreq(m_DemodCenterFreq + m_DemodLowCutFreq); m_DemodHiCutFreqX = xFromFreq(m_DemodCenterFreq + m_DemodHiCutFreq); int dw = m_DemodHiCutFreqX - m_DemodLowCutFreqX; painter.setBrush(Qt::SolidPattern); painter.setOpacity(0.3); painter.fillRect(m_DemodLowCutFreqX, 0, dw, h, Qt::gray); painter.setOpacity(1.0); painter.setPen(QPen(QColor(0xFF,0x71,0x71,0xFF), 1, Qt::SolidLine)); painter.drawLine(m_DemodFreqX, 0, m_DemodFreqX, h); } // create Font to use for scales QFont Font("Arial"); Font.setPointSize(m_FontSize); QFontMetrics metrics(Font); Font.setWeight(QFont::Normal); painter.setFont(Font); // draw vertical grids pixperdiv = (float)w / (float)m_HorDivs; y = h - h/m_VerDivs/2; painter.setPen(QPen(QColor(0xF0,0xF0,0xF0,0x30), 1, Qt::DotLine)); for (int i = 1; i < m_HorDivs; i++) { x = (int)((float)i*pixperdiv); painter.drawLine(x, 0, x, y); } if (m_CenterLineEnabled) { // center line x = xFromFreq(m_CenterFreq); if (x > 0 && x < w) { painter.setPen(QPen(QColor(0x78,0x82,0x96,0xFF), 1, Qt::SolidLine)); painter.drawLine(x, 0, x, y); } } // draw frequency values makeFrequencyStrs(); painter.setPen(QColor(0xD8,0xBA,0xA1,0xFF)); y = h - (h/m_VerDivs); m_XAxisYCenter = h - metrics.height()/2; for (int i = 1; i < m_HorDivs; i++) { x = (int)((float)i*pixperdiv - pixperdiv/2); rect.setRect(x, y, (int)pixperdiv, h/m_VerDivs); painter.drawText(rect, Qt::AlignHCenter|Qt::AlignBottom, m_HDivText[i]); } m_dBStepSize = abs(m_MaxdB-m_MindB)/(double)m_VerDivs; pixperdiv = (float)h / (float)m_VerDivs; painter.setPen(QPen(QColor(0xF0,0xF0,0xF0,0x30), 1,Qt::DotLine)); for (int i = 1; i < m_VerDivs; i++) { y = (int)((float) i*pixperdiv); painter.drawLine(5*metrics.width("0",-1), y, w, y); } // draw amplitude values painter.setPen(QColor(0xD8,0xBA,0xA1,0xFF)); //Font.setWeight(QFont::Light); painter.setFont(Font); int dB = m_MaxdB; m_YAxisWidth = metrics.width("-120 "); for (int i = 1; i < m_VerDivs; i++) { dB -= m_dBStepSize; // move to end if want to include maxdb y = (int)((float)i*pixperdiv); rect.setRect(0, y-metrics.height()/2, m_YAxisWidth, metrics.height()); painter.drawText(rect, Qt::AlignRight|Qt::AlignVCenter, QString::number(dB)); } if (!m_Running) { // if not running so is no data updates to draw to screen // copy into 2Dbitmap the overlay bitmap. m_2DPixmap = m_OverlayPixmap.copy(0,0,w,h); // trigger a new paintEvent update(); } }
bool Tileset::New(const QString &img_filename, const QString& root_folder, bool one_image) { if (img_filename.isEmpty()) return false; _initialized = false; // Retrieve the tileset name from the image filename _tileset_name = CreateTilesetName(img_filename); _tileset_definition_filename = "data/tilesets/" + _tileset_name + ".lua"; // Check existence of a previous lua definition file if (QFile::exists(_tileset_definition_filename)) { _tileset_definition_filename.clear(); _tileset_name.clear(); qDebug("Failed to create tileset, it already exists: %s", _tileset_definition_filename.toStdString().c_str()); return false; } _tileset_image_filename = "data/tilesets/" + _tileset_name + img_filename.mid(img_filename.length() - 4, 4); // Prepare the tile vector and load the tileset image tiles.clear(); tiles.resize(256); QRect rectangle; QImage entire_tileset; QString tileset_full_path = root_folder + _tileset_image_filename; if (!entire_tileset.load(tileset_full_path, "png")) { qDebug("Failed to load tileset image: %s", tileset_full_path.toStdString().c_str()); return false; } if (one_image) { tiles[0].convertFromImage(entire_tileset); } else { for(uint32_t row = 0; row < num_rows; ++row) { for(uint32_t col = 0; col < num_cols; ++col) { rectangle.setRect(col * TILE_WIDTH, row * TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT); QImage tile = entire_tileset.copy(rectangle); if(!tile.isNull()) { // linearize the tile index uint32_t i = num_rows * row + col; tiles[i].convertFromImage(tile); } else { qDebug("Image loading error!"); } } } } // Initialize the rest of the tileset data std::vector<int32_t> blank_entry(4, 0); for(uint32_t i = 0; i < 16; ++i) for(uint32_t j = 0; j < 16; ++j) walkability.insert(std::make_pair(i * 16 + j, blank_entry)); autotileability.clear(); _animated_tiles.clear(); _initialized = true; return true; } // Tileset::New(...)
//void MeshViewer::draw_density_colorbar(QPainter *painter) //{ // const int barwidth = 20; // const int barheight = 200; // painter->save(); // painter->translate(0.8*width(), 0.7*height()); // painter->save(); // int h1, s1, v1; // int h2, s2, v2; // int color[3]; // color[0] = 250; // color[1] = 0; // color[2] = 250; // QColor d_light(color[0], color[1], color[2]); // // color[0] = 0; // color[1] = 127; // color[2] = 0; // QColor d_dark(color[0], color[1], color[2]); // d_light.getHsv( &h1, &s1, &v1 ); // d_dark.getHsv( &h2, &s2, &v2 ); // QRect rect(0, -100, barwidth, barheight); // painter->setClipRect( rect ); // painter->setClipping( true ); // // painter->fillRect( rect, d_dark ); // // const int sectionSize = 4; // // int numIntervals; // numIntervals = rect.height() / sectionSize; // // for ( int i = 0; i < numIntervals; i++ ) // { // QRect colorsection; // colorsection.setRect( rect.x(), rect.y() + i * sectionSize, // rect.width(), sectionSize ); // // const double ratio = i / static_cast<double>( numIntervals ); // QColor c; // c.setHsv( h1 + qRound( ratio * ( h2 - h1 ) ), // s1 + qRound( ratio * ( s2 - s1 ) ), // v1 + qRound( ratio * ( v2 - v1 ) ) ); // /*int color[3]; // c.getRgb(&color[0], &color[1], &color[2]);*/ // painter->fillRect( colorsection, c ); // } // painter->restore(); //} // void MeshViewer::draw_curvature_colorbar(QPainter *painter) { const int barwidth = 20; const int barheight = 200; painter->save(); painter->translate(0.8*width(), 0.7*height()); painter->save(); int h1, s1, v1; int h2, s2, v2; int color[3]; color[0] = 250; color[1] = 0; color[2] = 0; QColor d_light(color[0], color[1], color[2]); color[0] = 0; color[1] = 0; color[2] = 255; QColor d_dark(color[0], color[1], color[2]); d_light.getHsv( &h1, &s1, &v1 ); d_dark.getHsv( &h2, &s2, &v2 ); QRect rect(0, -100, barwidth, barheight); painter->setClipRect( rect ); painter->setClipping( true ); painter->fillRect( rect, d_dark ); int sectionSize = 4; int numIntervals; numIntervals = rect.height() / sectionSize; for ( int i = 0; i < numIntervals; i++ ) { QRect colorsection; colorsection.setRect( rect.x(), rect.y() + i * sectionSize, rect.width(), sectionSize ); const double ratio = i / static_cast<double>( numIntervals ); QColor c; c.setHsv( h1 + qRound( ratio * ( h2 - h1 ) ), s1 + qRound( ratio * ( s2 - s1 ) ), v1 + qRound( ratio * ( v2 - v1 ) ) ); /*int color[3]; c.getRgb(&color[0], &color[1], &color[2]);*/ painter->fillRect( colorsection, c ); } painter->restore(); sectionSize = 8; painter->translate(barwidth, 0); QFont font("Times", 10); painter->setPen(Qt::black); painter->setFont(font); double max_curve=surfacedata->get_max_meancurvature(); double min_curve=surfacedata->get_min_meancurvature(); double cur_step = (max_curve-min_curve)/ sectionSize; for ( int i = 0; i <= sectionSize; i++ ) { QString str = QString::number(i*cur_step+min_curve); painter->drawText(5, barheight/2-barheight/8*i, str); } painter->restore(); }
void IconDelegate::doLayout(const QStyleOptionViewItem &option, QRect *checkRect, QRect *pixmapRect, QRect *textRect, bool hint) const { Q_ASSERT(checkRect && pixmapRect && textRect); int x = option.rect.left(); int y = option.rect.top(); int w, h; textRect->adjust(-textMargin, 0, textMargin, 0); // add width padding QSize pm(0, 0); if (pixmapRect->isValid()) pm = option.decorationSize; if (hint) { w = qMax(textRect->width(), pm.width()); h = qMax(textRect->height(), pm.height()); } else { w = option.rect.width(); h = option.rect.height(); } int cw = 0; QRect check; if (checkRect->isValid()) { check.setRect(x, y, checkRect->width() + textMargin * 2, h); cw = check.width(); if (option.direction == Qt::LeftToRight) x += cw; } QRect display; QRect decoration; QStyleOptionViewItem::Position position = option.decorationPosition; if (option.direction == Qt::RightToLeft) { if (position == QStyleOptionViewItem::Right) position = QStyleOptionViewItem::Left; else if (position == QStyleOptionViewItem::Left) position = QStyleOptionViewItem::Right; } switch (position) { case QStyleOptionViewItem::Top: { if (!pm.isEmpty()) pm.setHeight(pm.height() + textMargin); // add space decoration.setRect(x, y, w, pm.height()); h = hint ? textRect->height() : h - pm.height(); display.setRect(x, y + pm.height(), w, h); break; } case QStyleOptionViewItem::Bottom: { if (!textRect->isEmpty()) textRect->setHeight(textRect->height() + textMargin); // add space h = hint ? textRect->height() + pm.height() : h; decoration.setRect(x, y + h - pm.height(), w, pm.height()); h = hint ? textRect->height() : h - pm.height(); display.setRect(x, y, w, h); break; } case QStyleOptionViewItem::Left: { if (!pm.isEmpty()) pm.setWidth(pm.width() + textMargin); // add space decoration.setRect(x, y, pm.width(), h); w = hint ? textRect->width() : w - pm.width() - cw; display.setRect(x + pm.width(), y, w, h); break; } case QStyleOptionViewItem::Right: { if (!textRect->isEmpty()) textRect->setWidth(textRect->width() + textMargin); // add space w = hint ? textRect->width() + pm.width() : w; decoration.setRect(x + w - pm.width() - cw, y, pm.width(), h); w = hint ? textRect->width() : w - pm.width() - cw; display.setRect(x, y, w, h); break; } default: qWarning("doLayout: decoration positon is invalid"); decoration = *pixmapRect; break; } if (!hint) { // we only need to do the internal layout if we are going to paint *checkRect = QStyle::alignedRect(option.direction, Qt::AlignCenter, checkRect->size(), check); *pixmapRect = QStyle::alignedRect(option.direction, option.decorationAlignment, pixmapRect->size(), decoration); } else { *checkRect = check; *pixmapRect = decoration; } *textRect = display; }
// Repaint the state of a window. Active or inactive windows differ // only in the look of the titlebar. If only_label is true then only // the label string is repainted. This is used for the titlebar // animation with animate = TRUE. void KMDITitleLabel::paintState(bool only_label, bool colors_have_changed, bool animate){ KMDIWindow *w; QRect title_rect=QRect(0,0,width(),height()); QRect r = title_rect; bool double_buffering = false; QPixmap* buffer = 0; int x; // Nice, but this would make the class KWM dependant. // if (r.width() <= 0 || r.height() <= 0 // || getDecoration()!=KWM::normalDecoration) // return; // int x; w=(KMDIWindow *)(parent()->parent()->parent()); is_active=w->IsSelected(); TITLEBAR_LOOK look = options.TitlebarLook; if (look == H_SHADED || look == V_SHADED){ // the new("horizontal") horizontal (and vertical) shading code if (colors_have_changed){ aShadepm.resize(0,0); iaShadepm.resize(0,0); } // the user selected shading. Do a plain titlebar anyway if the // shading would be senseless (higher performance and less memory // consumption) if (is_active){ if ( kapp->activeTitleColor == activeTitleBlend) look = PLAIN; } else { if ( kapp->inactiveTitleColor == inactiveTitleBlend) look = PLAIN; } } // the following is the old/handmade vertical shading code // if (options.TitlebarLook == SHADED){ // if (is_active && shaded_pm_active && shaded_pm_active_color != myapp->activeTitleColor){ // delete shaded_pm_active; // shaded_pm_active = 0; // } // if (is_active && shaded_pm_inactive && shaded_pm_inactive_color != myapp->inactiveTitleColor){ // delete shaded_pm_inactive; // shaded_pm_inactive = 0; // } // } // if (options.TitlebarLook == SHADED // && // (is_active && (!shaded_pm_active) // || (!is_active && !shaded_pm_inactive)) // ){ // int i,y; // QImage image (50, TITLEBAR_HEIGHT, 8, TITLEBAR_HEIGHT); // QColor col = is_active ? myapp->activeTitleColor : myapp->inactiveTitleColor; // for ( i=0; i<TITLEBAR_HEIGHT; i++ ){ // image.setColor( i, col.light(100+(i-TITLEBAR_HEIGHT/2)*3).rgb()); // } // for (y=0; y<TITLEBAR_HEIGHT; y++ ) { // uchar *pix = image.scanLine(y); // for (x=0; x<50; x++) // *pix++ = is_active ? TITLEBAR_HEIGHT-1-y : y; // } // if (is_active){ // shaded_pm_active = new("QPixmap") QPixmap; // *shaded_pm_active = image; // shaded_pm_active_color = myapp->activeTitleColor; // } // else{ // shaded_pm_inactive = new("QPixmap") QPixmap; // *shaded_pm_inactive = image; // shaded_pm_inactive_color = myapp->inactiveTitleColor; // } // } QPainter p; if (only_label && animate){ double_buffering = (look == H_SHADED || look == V_SHADED || look == PIXMAP); titlestring_offset += titlestring_offset_delta; if (!double_buffering){ if (titlestring_offset_delta > 0) bitBlt(this, r.x()+titlestring_offset_delta, r.y(), this, r.x(), r.y(), r.width()-titlestring_offset_delta, r.height()); else bitBlt(this, r.x(), r.y(), this, r.x()-titlestring_offset_delta, r.y(), r.width()+titlestring_offset_delta, r.height()); } } if (!double_buffering) p.begin( this ); else { // enable double buffering to avoid flickering with horizontal shading buffer = new("QPixmap") QPixmap(r.width(), r.height()); p.begin(buffer); r.setRect(0,0,r.width(),r.height()); } QPixmap *pm; p.setClipRect(r); p.setClipping(True); // old handmade vertical shading code // if (options.TitlebarLook == SHADED || options.TitlebarLook == PIXMAP){ // if (options.TitlebarLook == SHADED) // pm = is_active ? shaded_pm_active : shaded_pm_inactive; // else if (look == PIXMAP){ pm = is_active ? options.titlebarPixmapActive: options.titlebarPixmapInactive; for (x = r.x(); x < r.x() + r.width(); x+=pm->width()) p.drawPixmap(x, r.y(), *pm); } else if (look == H_SHADED || look == V_SHADED ){ // the new("horizontal") horizontal shading code QPixmap* pm = 0; if (is_active){ if (aShadepm.size() != r.size()){ aShadepm.resize(r.width(), r.height()); kwm_gradientFill( aShadepm, kapp->activeTitleColor, activeTitleBlend, look == V_SHADED ); //aShadepm.gradientFill( activeTitleColor, activeTitleBlend, look == V_SHADED ); } pm = &aShadepm; } else { if (iaShadepm.size() != r.size()){ iaShadepm.resize(r.width(), r.height()); kwm_gradientFill( iaShadepm, kapp->inactiveTitleColor, inactiveTitleBlend, look == V_SHADED ); // iaShadepm.gradientFill(inactiveTitleColor, inactiveTitleBlend, // look == V_SHADED ); } pm = &iaShadepm; } p.drawPixmap( r.x(), r.y(), *pm ); } else { // TitlebarLook == TITLEBAR_PLAIN p.setBackgroundColor( is_active ? kapp->activeTitleColor : kapp->inactiveTitleColor); if (only_label && !double_buffering && animate){ p.eraseRect(QRect(r.x(), r.y(), TITLE_ANIMATION_STEP+1, r.height())); p.eraseRect(QRect(r.x()+r.width()-TITLE_ANIMATION_STEP-1, r.y(), TITLE_ANIMATION_STEP+1, r.height())); } else { p.eraseRect(r); } } p.setClipping(False); if (is_active) qDrawShadePanel( &p, r, colorGroup(), true ); p.setPen(is_active ? kapp->activeTextColor : kapp->inactiveTextColor); QFont fnt = kapp->generalFont; fnt.setPointSize(12); fnt.setBold(true); p.setFont(fnt); bool titlestring_too_large = (p.fontMetrics().width(QString(" ")+label+" ")>r.width()); if (titlestring_offset_delta > 0){ if (titlestring_offset > 0 && titlestring_offset > r.width() - p.fontMetrics().width(QString(" ")+label+" ")){ titlestring_offset_delta *= -1; } } else { if (titlestring_offset < 0 && titlestring_offset + p.fontMetrics().width(QString(" ")+label+" ") < r.width()){ titlestring_offset_delta *= -1; } } if (!titlestring_too_large) titlestring_offset = 0; p.setClipRect(r); p.setClipping(True); p.drawText(r.x()+(options.TitleAnimation?titlestring_offset:0), r.y()+p.fontMetrics().ascent(), QString(" ")+label+" "); p.setClipping(False); p.end(); if (double_buffering){ bitBlt(this, title_rect.x(), title_rect.y(), buffer, 0,0, buffer->width(), buffer->height()); delete buffer; } }
void GM_SettingsListDelegate::paint(QPainter* painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionViewItemV4 opt = option; initStyleOption(&opt, index); const QWidget* w = opt.widget; const QStyle* style = w ? w->style() : QApplication::style(); const Qt::LayoutDirection direction = w ? w->layoutDirection() : QApplication::layoutDirection(); const int height = opt.rect.height(); const int center = height / 2 + opt.rect.top(); // Prepare title font QFont titleFont = opt.font; titleFont.setBold(true); titleFont.setPointSize(titleFont.pointSize() + 1); const QFontMetrics titleMetrics(titleFont); #ifdef Q_OS_WIN const QPalette::ColorRole colorRole = QPalette::Text; #else const QPalette::ColorRole colorRole = opt.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Text; #endif int leftPosition = m_padding; int rightPosition = opt.rect.right() - m_padding - 16; // 16 for remove button // Draw background style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, w); // Draw checkbox const int checkboxSize = 18; const int checkboxYPos = center - (checkboxSize / 2); QStyleOptionViewItemV4 opt2 = opt; opt2.checkState == Qt::Checked ? opt2.state |= QStyle::State_On : opt2.state |= QStyle::State_Off; QRect styleCheckBoxRect = style->subElementRect(QStyle::SE_ViewItemCheckIndicator, &opt2, w); styleCheckBoxRect.setRect(leftPosition, checkboxYPos, styleCheckBoxRect.width(), styleCheckBoxRect.height()); QRect visualCheckBoxRect = style->visualRect(direction, opt.rect, styleCheckBoxRect); opt2.rect = visualCheckBoxRect; style->drawPrimitive(QStyle::PE_IndicatorViewItemCheck, &opt2, painter, w); leftPosition = styleCheckBoxRect.right() + m_padding; // Draw icon const int iconSize = 32; const int iconYPos = center - (iconSize / 2); QRect iconRect(leftPosition, iconYPos, iconSize, iconSize); QRect visualIconRect = style->visualRect(direction, opt.rect, iconRect); QPixmap pixmap = index.data(Qt::DecorationRole).value<QIcon>().pixmap(iconSize); painter->drawPixmap(visualIconRect, pixmap); leftPosition = iconRect.right() + m_padding; // Draw script name const QString &name = index.data(Qt::DisplayRole).toString(); const int leftTitleEdge = leftPosition + 2; const int rightTitleEdge = rightPosition - m_padding; const int leftPosForVersion = titleMetrics.width(name) + m_padding; QRect nameRect(leftTitleEdge, opt.rect.top() + m_padding, rightTitleEdge - leftTitleEdge, titleMetrics.height()); QRect visualNameRect = style->visualRect(direction, opt.rect, nameRect); painter->setFont(titleFont); style->drawItemText(painter, visualNameRect, Qt::AlignLeft, opt.palette, true, name, colorRole); // Draw version const QString &version = index.data(Qt::UserRole).toString(); QRect versionRect(nameRect.x() + leftPosForVersion, nameRect.y(), rightTitleEdge - leftPosForVersion, titleMetrics.height()); QFont versionFont = titleFont; versionFont.setBold(false); painter->setFont(versionFont); style->drawItemText(painter, versionRect, Qt::AlignLeft, opt.palette, true, version, colorRole); // Draw description const int infoYPos = nameRect.bottom() + opt.fontMetrics.leading(); QRect infoRect(visualNameRect.x(), infoYPos, nameRect.width(), opt.fontMetrics.height()); const QString &info = opt.fontMetrics.elidedText(index.data(Qt::UserRole + 1).toString(), Qt::ElideRight, infoRect.width()); painter->setFont(opt.font); style->drawItemText(painter, infoRect, Qt::TextSingleLine | Qt::AlignLeft, opt.palette, true, info, colorRole); // Draw remove button const int removeIconSize = 16; const int removeIconYPos = center - (removeIconSize / 2); QRect removeIconRect(rightPosition, removeIconYPos, removeIconSize, removeIconSize); QRect visualRemoveIconRect = style->visualRect(direction, opt.rect, removeIconRect); painter->drawPixmap(visualRemoveIconRect, m_removePixmap); }
void Slider::drawSlider(QPainter *p, const QRect &r) { const QPalette& pal = palette(); QBrush brBack(pal.window()); QBrush brMid; QBrush brDark(pal.dark()); QRect cr; int ipos, dist1; double rpos; int lineDist; if (d_bwTrough > 0) { // qDrawShadePanel(p, r.x(), r.y(), //r.width(), r.height(), //pal, TRUE, d_bwTrough,0); cr.setRect(r.x() + d_bwTrough, r.y() + d_bwTrough, r.width() - 2 * d_bwTrough, r.height() - 2 * d_bwTrough); brMid = pal.mid(); } else { cr = r; brMid = brBack; } rpos = (value() - minValue()) / (maxValue() - minValue()); lineDist = d_borderWidth - 1; if (lineDist < 1) lineDist = 1; if (d_orient == Qt::Horizontal) { dist1 = int(double(cr.width() - d_thumbLength) * rpos); ipos = cr.x() + dist1; markerPos = ipos + d_thumbHalf; // // draw background // if (d_bgStyle & BgSlot) { drawHsBgSlot(p, cr, QRect(ipos, cr.y(), d_thumbLength, cr.height()), brMid); } else { p->fillRect(cr.x(), cr.y(), dist1, cr.height(), brMid); p->fillRect(ipos + d_thumbLength, cr.y(), cr.width() - d_thumbLength - dist1, cr.height(), brMid); } // // Draw thumb // //qDrawShadePanel(p,ipos, cr.y(), d_thumbLength, cr.height(), // pal, FALSE, d_borderWidth, &brBack); QPixmap thumbp; bool loaded = thumbp.load(":images/slider_thumb_h.png"); if (loaded) p->drawPixmap(ipos, cr.y(), thumbp); if (lineDist > 1) qDrawShadeLine(p, markerPos, cr.y() + lineDist, markerPos, cr.y() + cr.height() - lineDist, pal, TRUE, 1); else { p->setPen(pal.dark().color()); p->drawLine(markerPos - 1, cr.y() + lineDist, markerPos - 1, cr.y() + cr.height() - lineDist - 1); p->setPen(pal.light().color()); p->drawLine(markerPos, cr.y() + lineDist, markerPos, cr.y() + cr.height() - lineDist - 1); } } else {//Vertical slider dist1 = int(double(cr.height() - d_thumbLength) * (1.0 - rpos)); ipos = cr.y() + dist1; markerPos = ipos + d_thumbHalf; //NOTE: this is adding the middle line in the slider if (d_bgStyle & BgSlot) { drawVsBgSlot(p, cr, QRect(cr.left(), ipos, cr.width(), d_thumbLength), brMid); } else { //p->fillRect(cr.x(),cr.y(),cr.width(),ipos,brMid); //p->fillRect(cr.x(), ipos + d_thumbLength, cr.width(), //cr.height() - d_thumbLength - dist1, brMid); } //This adds the thumb slider //qDrawShadePanel(p,cr.x(),ipos , cr.width(), d_thumbLength, // pal,FALSE,d_borderWidth, &brBack); QPixmap thumbp; bool loaded = thumbp.load(":images/slider_thumb.png"); int knobx = cr.x() + 2; int knoby = ipos - 12; QRect knobRect(knobx, knoby, 18, 33); //printf("Slider: Knob position X: %d Y: %d\n", knobx, knoby); if (loaded) { p->setCompositionMode(QPainter::CompositionMode_SourceAtop); //QPainter::CompositionMode_SourceOver); //p->drawPixmap(knobx, knoby, thumbp); p->setClipping(false); p->drawPixmap(knobRect, thumbp); } // if (lineDist > 1) // qDrawShadeLine(p, cr.x() + lineDist , markerPos, // cr.x() + cr.width() - lineDist, markerPos, // pal, TRUE, 1); // else // { // // p->setPen(pal.dark().color()); // p->drawLine(cr.x() + lineDist, markerPos - 1 , // cr.x() + cr.width() - lineDist - 1, markerPos - 1); // p->setPen(pal.light().color()); // p->drawLine(cr.x() + lineDist, markerPos, // cr.x() + cr.width() - lineDist - 1 , markerPos); // } } }
void RectDrawing::drawBack(QPainter* p, DrawParams* dp) { if (!dp) dp = drawParams(); if (_rect.width()<=0 || _rect.height()<=0) return; QRect r = _rect; QColor normal = dp->backColor(); if (dp->selected()) normal = normal.light(); bool isCurrent = dp->current(); if (dp->drawFrame() || isCurrent) { // 3D raised/sunken frame effect... QColor high = normal.light(); QColor low = normal.dark(); p->setPen( isCurrent ? low:high); p->drawLine(r.left(), r.top(), r.right(), r.top()); p->drawLine(r.left(), r.top(), r.left(), r.bottom()); p->setPen( isCurrent ? high:low); p->drawLine(r.right(), r.top(), r.right(), r.bottom()); p->drawLine(r.left(), r.bottom(), r.right(), r.bottom()); r.setRect(r.x()+1, r.y()+1, r.width()-2, r.height()-2); } if (r.width()<=0 || r.height()<=0) return; if (dp->shaded()) { // some shading bool goDark = qGray(normal.rgb())>128; int rBase, gBase, bBase; normal.rgb(&rBase, &gBase, &bBase); p->setBrush(Qt::NoBrush); // shade parameters: int d = 7; float factor = 0.1, forth=0.7, back1 =0.9, toBack2 = .7, back2 = 0.97; // coefficient corrections because of rectangle size int s = r.width(); if (s > r.height()) s = r.height(); if (s<100) { forth -= .3 * (100-s)/100; back1 -= .2 * (100-s)/100; back2 -= .02 * (100-s)/100; } // maximal color difference int rDiff = goDark ? -rBase/d : (255-rBase)/d; int gDiff = goDark ? -gBase/d : (255-gBase)/d; int bDiff = goDark ? -bBase/d : (255-bBase)/d; QColor shadeColor; while (factor<.95) { shadeColor.setRgb((int)(rBase+factor*rDiff+.5), (int)(gBase+factor*gDiff+.5), (int)(bBase+factor*bDiff+.5)); p->setPen(shadeColor); p->drawRect(r); r.setRect(r.x()+1, r.y()+1, r.width()-2, r.height()-2); if (r.width()<=0 || r.height()<=0) return; factor = 1.0 - ((1.0 - factor) * forth); } // and back (1st half) while (factor>toBack2) { shadeColor.setRgb((int)(rBase+factor*rDiff+.5), (int)(gBase+factor*gDiff+.5), (int)(bBase+factor*bDiff+.5)); p->setPen(shadeColor); p->drawRect(r); r.setRect(r.x()+1, r.y()+1, r.width()-2, r.height()-2); if (r.width()<=0 || r.height()<=0) return; factor = 1.0 - ((1.0 - factor) / back1); } // and back (2nd half) while ( factor>.01) { shadeColor.setRgb((int)(rBase+factor*rDiff+.5), (int)(gBase+factor*gDiff+.5), (int)(bBase+factor*bDiff+.5)); p->setPen(shadeColor); p->drawRect(r); r.setRect(r.x()+1, r.y()+1, r.width()-2, r.height()-2); if (r.width()<=0 || r.height()<=0) return; factor = factor * back2; } } // fill inside p->setPen(Qt::NoPen); p->setBrush(normal); p->drawRect(r); }
////////////////////////////////////////////////////////////////////// // Called to draw an overlay bitmap containing grid and text that // does not need to be recreated every fft data update. ////////////////////////////////////////////////////////////////////// void CPlotter::drawOverlay() { if (m_OverlayPixmap.isNull()) return; int w = m_OverlayPixmap.width(); int h = m_OverlayPixmap.height(); int x,y; float pixperdiv; QRect rect; QPainter painter(&m_OverlayPixmap); painter.initFrom(this); // horizontal grids (size and grid calcs could be moved to resize) m_VerDivs = h/m_VdivDelta+1; m_HorDivs = qMin(w/m_HdivDelta, HORZ_DIVS_MAX); if (m_HorDivs % 2) m_HorDivs++; // we want an odd number of divs so that we have a center line //m_OverlayPixmap.fill(Qt::black); // fill background with gradient QLinearGradient gradient(0, 0, 0 ,h); gradient.setColorAt(0, QColor(0x20,0x20,0x20,0xFF)); gradient.setColorAt(1, QColor(0x4F,0x4F,0x4F,0xFF)); painter.setBrush(gradient); painter.drawRect(0, 0, w, h); // Draw demod filter box if (m_FilterBoxEnabled) { // Clamping no longer necessary as we do it in mouseMove() //ClampDemodParameters(); m_DemodFreqX = xFromFreq(m_DemodCenterFreq); m_DemodLowCutFreqX = xFromFreq(m_DemodCenterFreq + m_DemodLowCutFreq); m_DemodHiCutFreqX = xFromFreq(m_DemodCenterFreq + m_DemodHiCutFreq); int dw = m_DemodHiCutFreqX - m_DemodLowCutFreqX; painter.setBrush(Qt::SolidPattern); painter.setOpacity(0.3); painter.fillRect(m_DemodLowCutFreqX, 0, dw, h, Qt::gray); painter.setOpacity(1.0); painter.setPen(QPen(QColor(0xFF,0x71,0x71,0xFF), 1, Qt::SolidLine)); painter.drawLine(m_DemodFreqX, 0, m_DemodFreqX, h); } // create Font to use for scales QFont Font("Arial"); Font.setPointSize(m_FontSize); QFontMetrics metrics(Font); Font.setWeight(QFont::Normal); painter.setFont(Font); // draw vertical grids pixperdiv = (float)w / (float)m_HorDivs; y = h - h/m_VerDivs/2; painter.setPen(QPen(QColor(0xF0,0xF0,0xF0,0x30), 1, Qt::DotLine)); for (int i = 1; i < m_HorDivs; i++) { x = (int)((float)i*pixperdiv); painter.drawLine(x, 0, x, y); } //Draw Bookmark Tags m_BookmarkTags.clear(); static const QFontMetrics fm(painter.font()); static const int fontHeight = fm.ascent()+1; // height(); static const int slant = 5; static const int levelHeight = fontHeight+5; static const int nLevels = 3; QList<BookmarkInfo> bookmarks = Bookmarks::Get().getBookmarksInRange(m_CenterFreq+m_FftCenter-m_Span/2, m_CenterFreq+m_FftCenter+m_Span/2); int tagEnd[nLevels] = {0}; for(int i=0; i<bookmarks.size(); i++) { x=xFromFreq(bookmarks[i].frequency); #if defined(_WIN16) || defined(_WIN32) || defined(_WIN64) int nameWidth= fm.width(bookmarks[i].name); #else int nameWidth= fm.boundingRect(bookmarks[i].name).width(); #endif int level = 0; for(; level<nLevels && tagEnd[level]>x; level++); level%=nLevels; tagEnd[level]=x+nameWidth+slant-1; m_BookmarkTags.append(qMakePair<QRect, qint64>(QRect(x, level*levelHeight, nameWidth+slant, fontHeight), bookmarks[i].frequency)); QColor color = QColor(bookmarks[i].GetColor()); color.setAlpha(0x60); painter.setPen(QPen(color, 1, Qt::DashLine)); painter.drawLine(x, level*levelHeight+fontHeight+slant, x, y); //Vertical line painter.setPen(QPen(color, 1, Qt::SolidLine)); painter.drawLine(x+slant, level*levelHeight+fontHeight, x+nameWidth+slant-1, level*levelHeight+fontHeight); //Horizontal line painter.drawLine(x+1,level*levelHeight+fontHeight+slant-1, x+slant-1, level*levelHeight+fontHeight+1); //Diagonal line /* painter.setPen(QPen(QColor(0xF0,0xF0,0xF0,0xB0), 1, Qt::SolidLine)); QPolygon polygon(6); polygon.setPoint(0, 0, 10); polygon.setPoint(1, 5, 15); polygon.setPoint(2, 5+nameWidth, 15); polygon.setPoint(3, 5+nameWidth, 0); polygon.setPoint(4, 5, 0); polygon.setPoint(5, 0, 5); polygon.translate(x, level*18); painter.drawPolygon(polygon); */ color.setAlpha(0xFF); painter.setPen(QPen(color, 2, Qt::SolidLine)); painter.drawText(x+slant,level*levelHeight, nameWidth, fontHeight, Qt::AlignVCenter | Qt::AlignHCenter, bookmarks[i].name); } if (m_CenterLineEnabled) { // center line x = xFromFreq(m_CenterFreq); if (x > 0 && x < w) { painter.setPen(QPen(QColor(0x78,0x82,0x96,0xFF), 1, Qt::SolidLine)); painter.drawLine(x, 0, x, y); } } // draw frequency values makeFrequencyStrs(); painter.setPen(QColor(0xD8,0xBA,0xA1,0xFF)); y = h - (h/m_VerDivs); m_XAxisYCenter = h - metrics.height()/2; for (int i = 1; i < m_HorDivs; i++) { x = (int)((float)i*pixperdiv - pixperdiv/2); rect.setRect(x, y, (int)pixperdiv, h/m_VerDivs); painter.drawText(rect, Qt::AlignHCenter|Qt::AlignBottom, m_HDivText[i]); } m_dBStepSize = fabs(m_MaxdB - m_MindB)/(float)m_VerDivs; pixperdiv = (float)h / (float)m_VerDivs; painter.setPen(QPen(QColor(0xF0,0xF0,0xF0,0x30), 1,Qt::DotLine)); for (int i = 1; i < m_VerDivs; i++) { y = (int)((float) i*pixperdiv); painter.drawLine(5*metrics.width("0",-1), y, w, y); } // draw amplitude values painter.setPen(QColor(0xD8,0xBA,0xA1,0xFF)); //Font.setWeight(QFont::Light); painter.setFont(Font); int dB = m_MaxdB; m_YAxisWidth = metrics.width("-120 "); for (int i = 1; i < m_VerDivs; i++) { dB -= m_dBStepSize; // move to end if want to include maxdb y = (int)((float)i*pixperdiv); rect.setRect(0, y-metrics.height()/2, m_YAxisWidth, metrics.height()); painter.drawText(rect, Qt::AlignRight|Qt::AlignVCenter, QString::number(dB)); } if (!m_Running) { // if not running so is no data updates to draw to screen // copy into 2Dbitmap the overlay bitmap. m_2DPixmap = m_OverlayPixmap.copy(0,0,w,h); // trigger a new paintEvent update(); } painter.end(); }
void ThinSlider::drawSlider(QPainter *p, const QRect &r) { p->setRenderHint(QPainter::Antialiasing); const QPalette& pal = palette(); QBrush brBack(pal.window()); QBrush brMid(pal.mid()); QBrush brDark(pal.dark()); QRect cr; int ipos,dist1; double rpos; int xrad = 4; int yrad = 4; // for the empty side QColor e_mask_edge = pal.mid().color(); QColor e_mask_center = pal.midlight().color(); int e_alpha = 215; e_mask_edge.setAlpha(e_alpha); e_mask_center.setAlpha(e_alpha); QLinearGradient e_mask; e_mask.setColorAt(0, e_mask_edge); e_mask.setColorAt(0.5, e_mask_center); e_mask.setColorAt(1, e_mask_edge); // for the full side rpos = (value() - minValue()) / (maxValue() - minValue()); int f_brightness = 155 * rpos + 100; int f_alpha; int f_edge; if (pal.currentColorGroup() == QPalette::Disabled) { f_alpha = 185; f_edge = 100; } else { f_alpha = 127; f_edge = 0; } QColor f_mask_center = QColor(f_brightness, f_brightness, f_brightness, f_alpha); QColor f_mask_edge = QColor(f_edge, f_edge, f_edge, f_alpha); QLinearGradient f_mask; f_mask.setColorAt(0, f_mask_edge); f_mask.setColorAt(0.5, f_mask_center); f_mask.setColorAt(1, f_mask_edge); // for the thumb QLinearGradient thumbGrad; QColor thumb_edge = pal.dark().color(); QColor thumb_center = pal.midlight().color(); thumbGrad.setColorAt(0, thumb_edge); thumbGrad.setColorAt(0.5, thumb_center); thumbGrad.setColorAt(1, thumb_edge); if (d_orient == Qt::Horizontal) { cr.setRect(r.x(), r.y() + d_mMargin, r.width(), r.height() - 2*d_mMargin); // // Draw background // QPainterPath bg_rect = MusECore::roundedPath(cr, xrad, yrad, (MusECore::Corner) (MusECore::UpperLeft | MusECore::UpperRight | MusECore::LowerLeft | MusECore::LowerRight) ); p->fillPath(bg_rect, d_fillColor); dist1 = int(double(cr.width() - d_thumbLength) * rpos); ipos = cr.x() + dist1; markerPos = ipos + d_thumbHalf; // // Draw empty right side // e_mask.setStart(QPointF(0, cr.y())); e_mask.setFinalStop(QPointF(0, cr.y() + cr.height())); QPainterPath e_rect = MusECore::roundedPath(ipos + d_thumbLength, cr.y(), cr.width() - d_thumbLength - dist1, cr.height(), xrad, yrad, (MusECore::Corner) (MusECore::UpperRight | MusECore::LowerRight) ); p->fillPath(e_rect, QBrush(e_mask)); // // Draw full left side // f_mask.setStart(QPointF(0, cr.y())); f_mask.setFinalStop(QPointF(0, cr.y() + cr.height())); QPainterPath f_rect = MusECore::roundedPath(cr.x(), cr.y(), ipos + 1, cr.height(), xrad, yrad, (MusECore::Corner) (MusECore::LowerLeft | MusECore::UpperLeft) ); p->fillPath(f_rect, QBrush(f_mask)); // // Draw thumb // QPainterPath thumb_rect = MusECore::roundedPath(ipos, r.y(), d_thumbLength, r.height(), 2, 2, (MusECore::Corner) (MusECore::UpperLeft | MusECore::UpperRight | MusECore::LowerLeft | MusECore::LowerRight) ); thumbGrad.setStart(QPointF(0, cr.y())); thumbGrad.setFinalStop(QPointF(0, cr.y() + cr.height())); p->fillPath(thumb_rect, QBrush(thumbGrad)); // center line p->fillRect(ipos + d_thumbHalf, cr.y(), 1, cr.height(), pal.dark().color()); } else // (d_orient == Qt::Vertical) { cr.setRect(r.x() + d_mMargin, r.y(), r.width() - 2*d_mMargin, r.height()); // // Draw background // QPainterPath bg_rect = MusECore::roundedPath(cr, xrad, yrad, (MusECore::Corner) (MusECore::UpperLeft | MusECore::UpperRight | MusECore::LowerLeft | MusECore::LowerRight) ); p->fillPath(bg_rect, d_fillColor); dist1 = int(double(cr.height() - d_thumbLength) * (1.0 - rpos)); ipos = cr.y() + dist1; markerPos = ipos + d_thumbHalf; // // Draw empty upper filling // e_mask.setStart(QPointF(cr.x(), 0)); e_mask.setFinalStop(QPointF(cr.x() + cr.width(), 0)); QPainterPath e_rect = MusECore::roundedPath(cr.x(), cr.y(), cr.width(), ipos + 1, xrad, yrad, (MusECore::Corner) (MusECore::UpperLeft | MusECore::UpperRight) ); p->fillPath(e_rect, QBrush(e_mask)); // // Draw lower filling mask // f_mask.setStart(QPointF(cr.x(), 0)); f_mask.setFinalStop(QPointF(cr.x() + cr.width(), 0)); QPainterPath f_rect = MusECore::roundedPath(cr.x(), ipos + d_thumbLength, cr.width(), cr.height() - d_thumbLength - dist1, xrad, yrad, (MusECore::Corner) (MusECore::LowerLeft | MusECore::LowerRight) ); p->fillPath(f_rect, QBrush(f_mask)); // // Draw thumb // QPainterPath thumb_rect = MusECore::roundedPath(r.x(), ipos, r.width(), d_thumbLength, 2, 2, (MusECore::Corner) (MusECore::UpperLeft | MusECore::UpperRight | MusECore::LowerLeft | MusECore::LowerRight) ); thumbGrad.setStart(QPointF(cr.x(), 0)); thumbGrad.setFinalStop(QPointF(cr.x() + cr.width(), 0)); p->fillPath(thumb_rect, QBrush(thumbGrad)); // center line p->fillRect(cr.x(), ipos + d_thumbHalf, cr.width(), 1, pal.dark().color()); } }
QRect SkinStyle::subControlRect(ComplexControl control, const QStyleOptionComplex * option, SubControl subControl, const QWidget * widget) const { QRect rect = SystemStyle::subControlRect(control, option, subControl, widget); switch (control) { case CC_Slider: if (const QStyleOptionSlider * slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) { if (subControl == SC_SliderHandle) { int tickOffset = pixelMetric(PM_SliderTickmarkOffset, option, widget); int thickness = pixelMetric(PM_SliderControlThickness, option, widget); bool horizontal = slider->orientation == Qt::Horizontal; int len = pixelMetric(PM_SliderLength, option, widget) + 8; //size of handle / 2 int motifBorder = pixelMetric(PM_DefaultFrameWidth); int sliderPos = sliderPositionFromValue(slider->minimum, slider->maximum, slider->sliderPosition, horizontal ? slider->rect.width() - len - 2 * motifBorder : slider->rect.height() - len - 2 * motifBorder, slider->upsideDown); if (horizontal) { rect = visualRect(slider->direction, slider->rect, QRect(sliderPos + motifBorder, tickOffset + motifBorder, len, thickness - 2 * motifBorder)); } else { rect = visualRect(slider->direction, slider->rect, QRect(tickOffset + motifBorder, sliderPos + motifBorder, thickness - 2 * motifBorder, len)); } } } break; case CC_ScrollBar: if (const QStyleOptionSlider * scrollbar = qstyleoption_cast<const QStyleOptionSlider *>(option)) { QRect scrollBarRect = scrollbar->rect; int grooveMargin = pixelMetric(PM_ButtonDefaultIndicator, scrollbar, widget); int scrollBarExtent = pixelMetric(PM_ScrollBarExtent, scrollbar, widget); int sliderMaxLength = ((scrollbar->orientation == Qt::Horizontal) ? scrollbar->rect.width() + grooveMargin : scrollbar->rect.height()) - 2 * (_arrowUpWidth); int sliderLength = _scrollbarHandleHeight; int sliderStart = _arrowUpWidth + sliderPositionFromValue(scrollbar->minimum, scrollbar->maximum, scrollbar->sliderPosition, sliderMaxLength - sliderLength, scrollbar->upsideDown); switch (subControl) { case SC_ScrollBarSlider: //Handle if (scrollbar->orientation == Qt::Horizontal) { rect.setRect(sliderStart, 0, sliderLength, scrollBarExtent); } else { rect.setRect(0, sliderStart, scrollBarExtent, sliderLength); } break; case SC_ScrollBarSubLine: //Top/left button if (scrollbar->orientation == Qt::Horizontal) { rect.setRect(scrollBarRect.left(), scrollBarRect.top(), _arrowUpWidth, scrollBarExtent); } else { rect.setRect(scrollBarRect.left(), scrollBarRect.top(), scrollBarExtent, _arrowUpHeight); } break; case SC_ScrollBarAddLine: //Bottom/right button if (scrollbar->orientation == Qt::Horizontal) { rect.setRect(scrollBarRect.right() - _arrowUpWidth + grooveMargin, scrollBarRect.top(), _arrowUpWidth, _arrowUpHeight); } else { rect.setRect(scrollBarRect.left(), scrollBarRect.bottom() - _arrowUpWidth + grooveMargin, _arrowUpWidth, _arrowUpHeight); } break; case SC_ScrollBarGroove: if (scrollbar->orientation == Qt::Horizontal) { rect = scrollBarRect.adjusted(_arrowUpWidth, - 2 * grooveMargin, - _arrowUpWidth + grooveMargin, 0); } else { rect = scrollBarRect.adjusted(-grooveMargin, _arrowUpWidth, 0, - _arrowUpWidth + grooveMargin); } break; default: break; } rect = visualRect(scrollbar->direction, scrollBarRect, rect); } break; default: break; } return rect; }
QRect PopupDrawHelper::subControlRect(ComplexControl control, const QStyleOptionComplex* opt, SubControl subControl, const QWidget* widget) const { #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) QRect rect = QCommonStyle::subControlRect(control, opt, subControl, widget); #else QRect rect = QWindowsStyle::subControlRect(control, opt, subControl, widget); #endif switch (control) { case CC_TitleBar: if (const StyleOptionPopupTitleBar* bar = qstyleoption_cast<const StyleOptionPopupTitleBar*>(opt)) { const int controlMargin = 2; const int controlHeight = bar->rect.height() - controlMargin/* *2*/; const int delta = controlHeight + controlMargin; switch (subControl) { case SC_TitleBarLabel: { QRect rc = opt->rect; QRect labelRect = bar->fontMetrics.boundingRect(bar->text); int titleBarHeight = proxy()->pixelMetric(PM_TitleBarHeight, opt, widget); rc.setHeight(titleBarHeight); int width = labelRect.width(); labelRect.moveCenter(rc.center()); labelRect.setLeft(0); labelRect.setWidth(qMax(rc.width(), width)); if (bar->subControls & SC_TitleBarCloseButton) { QRect ir = proxy()->subControlRect(CC_TitleBar, bar, SC_TitleBarCloseButton, widget); labelRect.adjust(bar->subControls & SC_TitleBarSysMenu ? delta : controlMargin, 0, -ir.width(), controlMargin); } else labelRect.adjust(bar->subControls & SC_TitleBarSysMenu ? delta : controlMargin, 0, controlMargin, controlMargin); rect = labelRect; break; } case SC_TitleBarCloseButton: { QRect rc = opt->rect; QRect rcButton; rcButton.setHeight(13); rcButton.setWidth(13); int titleBarHeight = proxy()->pixelMetric(PM_TitleBarHeight, opt, widget); rc.setHeight(titleBarHeight); int offsetX = rc.right() - 13 - 2; int offsetY = (rc.height() - rcButton.height())/2; rcButton.translate(offsetX, offsetY); rect = rcButton; break; } case SC_TitleBarSysMenu : { QRect rc = opt->rect; rc.setRect(bar->rect.left() + controlMargin, bar->rect.top() + controlMargin, controlHeight, controlHeight); rect = rc; break; } default: break; } } break; default: #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) return QCommonStyle::subControlRect(control, opt, subControl, widget); #else return QWindowsStyle::subControlRect(control, opt, subControl, widget); #endif } return rect; }
void M11TabBar::paintEvent(QPaintEvent*) { QStyleOptionTab tabOverlap; tabOverlap.shape = shape(); int overlap = style()->pixelMetric(QStyle::PM_TabBarBaseOverlap, &tabOverlap, this); QWidget *theParent = parentWidget(); QStyleOptionTabBarBase optTabBase; optTabBase.init(this); optTabBase.shape = shape(); if (theParent && overlap > 0) { QRect rect; switch (tabOverlap.shape) { case M11TabBar::RoundedNorth: case M11TabBar::TriangularNorth: rect.setRect(0, height() - overlap, width(), overlap); break; case M11TabBar::RoundedSouth: case M11TabBar::TriangularSouth: rect.setRect(0, 0, width(), overlap); break; case M11TabBar::RoundedEast: case M11TabBar::TriangularEast: rect.setRect(0, 0, overlap, height()); break; case M11TabBar::RoundedWest: case M11TabBar::TriangularWest: rect.setRect(width() - overlap, 0, overlap, height()); break; } optTabBase.rect = rect; } QStylePainter p(this); p.fillRect(rect(), Utils::instance().gradientTopToBottom(rect())); QPen pen = p.pen(); int selected = -1; int cut = -1; bool rtl = optTabBase.direction == Qt::RightToLeft; bool verticalTabs = (shape() == M11TabBar::RoundedWest || shape() == M11TabBar::RoundedEast || shape() == M11TabBar::TriangularWest || shape() == M11TabBar::TriangularEast); QStyleOptionTab cutTab; QStyleOptionTab selectedTab; for (int i = 0; i < count(); ++i) { QStyleOptionTabV2 tab = getStyleOption(i); if (!(tab.state & QStyle::State_Enabled)) { tab.palette.setCurrentColorGroup(QPalette::Disabled); } // If this tab is partially obscured, make a note of it so that we can pass the information // along when we draw the tear. if ((!verticalTabs && (!rtl && tab.rect.left() < 0) || (rtl && tab.rect.right() > width())) || (verticalTabs && tab.rect.top() < 0)) { cut = i; cutTab = tab; } // Don't bother drawing a tab if the entire tab is outside of the visible tab bar. if ((!verticalTabs && (tab.rect.right() < 0 || tab.rect.left() > width())) || (verticalTabs && (tab.rect.bottom() < 0 || tab.rect.top() > height()))) continue; optTabBase.tabBarRect |= tab.rect; if (i == currentIndex()) { selected = i; selectedTab = tab; optTabBase.selectedTabRect = tab.rect; } QIcon icon = tabIcon(i); QSize iconSize = icon.actualSize(QSize(tab.rect.height(), tab.rect.height())); int iconMargin = (tab.rect.height() - iconSize.height()) / 2; QRect iconRect(tab.rect.left() + iconMargin, tab.rect.top(), iconSize.width(), tab.rect.height()); QString text = tabText(i); QRect textRect( tab.rect.left() + iconMargin + iconSize.width(), tab.rect.top(), tab.rect.width() - iconSize.width(), tab.rect.height() ); p.fillRect( tab.rect, i == currentIndex() ? Utils::instance().palette().base() : tab.rect.contains(mapFromGlobal(QCursor::pos())) ? Utils::instance().palette().light() : Utils::instance().gradientTopToBottom(tab.rect) ); p.setPen(Utils::instance().palette().dark().color()); switch (shape()) { // override the widget's border to make it consistent over inactive tabs case M11TabBar::RoundedNorth: case M11TabBar::TriangularNorth: if (i == currentIndex()) { p.drawRect(tab.rect.adjusted(0, 0, -1, 0)); } else { p.drawLine(tab.rect.bottomLeft(), tab.rect.bottomRight()); } break; case M11TabBar::RoundedSouth: case M11TabBar::TriangularSouth: if (i == currentIndex()) { p.drawRect(tab.rect.adjusted(0, -1, -1, -1)); } else { p.drawLine(tab.rect.topLeft(), tab.rect.topRight()); } break; case M11TabBar::RoundedEast: case M11TabBar::TriangularEast: if (i == currentIndex()) { p.drawRect(tab.rect.adjusted(-1, 0, -1, -1)); } else { p.drawLine(tab.rect.topLeft(), tab.rect.bottomLeft()); } break; case M11TabBar::RoundedWest: case M11TabBar::TriangularWest: if (i == currentIndex()) { p.drawRect(tab.rect.adjusted(0, 0, 0, -1)); } else { p.drawLine(tab.rect.topRight(), tab.rect.bottomRight()); } break; default: Q_ASSERT(false); break; } p.setPen(m_tabLabelColors.contains(i) ? m_tabLabelColors.value(i).color() : pen); QString textToDraw = fontMetrics().elidedText( text, elideMode(), 1 + ( verticalTabs ? tabRect(i).height() : tabRect(i).width() ) - style()->pixelMetric(QStyle::PM_TabBarTabHSpace, &tab, this), Qt::TextShowMnemonic ); p.drawItemPixmap(iconRect, Qt::AlignCenter, icon.pixmap(iconSize)); p.drawItemText( textRect, Qt::AlignLeft | Qt::AlignVCenter, QPalette(), tab.state & QStyle::State_Enabled, textToDraw ); p.setPen(pen); } if (!drawBase()) { p.setBackgroundMode(Qt::TransparentMode); } else { // p.drawPrimitive(QStyle::PE_FrameTabBarBase, optTabBase); } // Only draw the tear indicator if necessary. Most of the time we don't need too. if (cut >= 0) { cutTab.rect = rect(); cutTab.rect = style()->subElementRect(QStyle::SE_TabBarTearIndicator, &cutTab, this); p.drawPrimitive(QStyle::PE_IndicatorTabTear, cutTab); } // p.setPen(Qt::black); // p.drawRect(rect()); }
void Slider::getScrollMode(QPoint &p, const Qt::MouseButton &button, int &scrollMode, int &direction) { if (cursorHoming() && button == Qt::LeftButton) { if (d_sliderRect.contains(p)) { scrollMode = ScrMouse; direction = 0; int mp = 0; QRect cr; QPoint cp; int ipos, dist1; double rpos; int lineDist; if (d_bwTrough > 0) cr.setRect(d_sliderRect.x() + d_bwTrough, d_sliderRect.y() + d_bwTrough, d_sliderRect.width() - 2 * d_bwTrough, d_sliderRect.height() - 2 * d_bwTrough); else cr = d_sliderRect; rpos = (value() - minValue()) / (maxValue() - minValue()); lineDist = d_borderWidth - 1; if (lineDist < 1) lineDist = 1; if (d_orient == Qt::Horizontal) { dist1 = int(double(cr.width() - d_thumbLength) * rpos); ipos = cr.x() + dist1; mp = ipos + d_thumbHalf; p.setX(mp); cp = mapToGlobal(QPoint(mp, p.y())); } else { dist1 = int(double(cr.height() - d_thumbLength) * (1.0 - rpos)); ipos = cr.y() + dist1; mp = ipos + d_thumbHalf; p.setY(mp); cp = mapToGlobal(QPoint(p.x(), mp)); } cursor().setPos(cp.x(), cp.y()); } } else { int currentPos; if (d_orient == Qt::Horizontal) currentPos = p.x(); else currentPos = p.y(); if (d_sliderRect.contains(p)) { if ((currentPos > markerPos - d_thumbHalf) && (currentPos < markerPos + d_thumbHalf)) { scrollMode = ScrMouse; direction = 0; } else { scrollMode = ScrPage; if (((currentPos > markerPos) && (d_orient == Qt::Horizontal)) || ((currentPos <= markerPos) && (d_orient != Qt::Horizontal))) direction = 1; else direction = -1; } } else { scrollMode = ScrNone; direction = 0; } } }
void QHexEdit::paintEvent(QPaintEvent *event) { QPainter painter(viewport()); if (event->rect() != _cursorRect) { // process some useful calculations int pxOfsX = horizontalScrollBar()->value(); int pxPosStartY = _pxCharHeight; // draw some patterns if needed painter.fillRect(event->rect(), viewport()->palette().color(QPalette::Base)); if (_addressArea) painter.fillRect(QRect(-pxOfsX, event->rect().top(), _pxPosHexX - _pxGapAdrHex/2 - pxOfsX, height()), _addressAreaColor); if (_asciiArea) { int linePos = _pxPosAsciiX - (_pxGapHexAscii / 2); painter.setPen(Qt::gray); painter.drawLine(linePos - pxOfsX, event->rect().top(), linePos - pxOfsX, height()); } painter.setPen(viewport()->palette().color(QPalette::WindowText)); // paint address area if (_addressArea) { QString address; for (int row=0, pxPosY = _pxCharHeight; row < (_dataShown.size()/BYTES_PER_LINE); row++, pxPosY +=_pxCharHeight) { address = QString("%1").arg(_bPosFirst + row*BYTES_PER_LINE + _addressOffset, _addrDigits, 16, QChar('0')); painter.drawText(_pxPosAdrX - pxOfsX, pxPosY, address); } } // paint hex and ascii area QPen colStandard = QPen(viewport()->palette().color(QPalette::WindowText)); // TODO: make these configurable QPen colUsageRead = QPen(QColor(0, 0, 224)); QPen colUsageWrite = QPen(QColor(0, 0, 224)); QPen colUsageExec = QPen(QColor(224, 0, 0)); QPen colUsageRWExec = QPen(QColor(224, 0, 224)); painter.setBackgroundMode(Qt::TransparentMode); for (int row = 0, pxPosY = pxPosStartY; row <= _rowsShown; row++, pxPosY +=_pxCharHeight) { QByteArray hex; int pxPosX = _pxPosHexX - pxOfsX; int pxPosAsciiX2 = _pxPosAsciiX - pxOfsX; qint64 bPosLine = row * BYTES_PER_LINE; for (int colIdx = 0; ((bPosLine + colIdx) < _dataShown.size() and (colIdx < BYTES_PER_LINE)); colIdx++) { QColor c = viewport()->palette().color(QPalette::Base); painter.setPen(colStandard); qint64 posBa = _bPosFirst + bPosLine + colIdx; if ((getSelectionBegin() <= posBa) && (getSelectionEnd() > posBa)) { c = _brushSelection.color(); painter.setPen(_penSelection); } else { /* TODO if (_highlighting) if (_markedShown.at((int)(posBa - _bPosFirst))) { c = _brushHighlighted.color(); painter.setPen(_penHighlighted); } */ uint8_t this_usage = usage(posBa); if (this_usage & UsageExec && this_usage & UsageRead) { painter.setPen(colUsageRWExec); } else if (this_usage & UsageExec) { painter.setPen(colUsageExec); } else if (this_usage & UsageRead) { painter.setPen(colUsageRead); } else if (this_usage & UsageWrite) { painter.setPen(colUsageWrite); } } // render hex value QRect r; if (colIdx == 0) r.setRect(pxPosX, pxPosY - _pxCharHeight + _pxSelectionSub, 2*_pxCharWidth, _pxCharHeight); else r.setRect(pxPosX - _pxCharWidth, pxPosY - _pxCharHeight + _pxSelectionSub, 3*_pxCharWidth, _pxCharHeight); painter.fillRect(r, c); hex = _hexDataShown.mid((bPosLine + colIdx) * 2, 2); painter.drawText(pxPosX, pxPosY, hex); pxPosX += 3*_pxCharWidth; // render ascii value if (_asciiArea) { char ch = _dataShown.at(bPosLine + colIdx); if ((ch < 0x20) or (ch > 0x7e)) ch = '.'; r.setRect(pxPosAsciiX2, pxPosY - _pxCharHeight + _pxSelectionSub, _pxCharWidth, _pxCharHeight); painter.fillRect(r, c); painter.drawText(pxPosAsciiX2, pxPosY, QChar(ch)); pxPosAsciiX2 += _pxCharWidth; } } } painter.setBackgroundMode(Qt::TransparentMode); painter.setPen(viewport()->palette().color(QPalette::WindowText)); } // paint cursor if (_blink && !_readOnly && hasFocus()) painter.fillRect(_cursorRect, this->palette().color(QPalette::WindowText)); else painter.drawText(_pxCursorX, _pxCursorY, _hexDataShown.mid(_cursorPosition - _bPosFirst * 2, 1)); // emit event, if size has changed if (_lastEventSize != _editorSize) { _lastEventSize = _editorSize; emit currentSizeChanged(_lastEventSize); } }
void QMainWindow::moveToolBar( QToolBar * t , QMouseEvent * e ) { if ( e->type() == Event_MouseButtonPress ) { //debug( "saw press" ); d->moving = 0; d->offset = e->pos(); d->pos = QCursor::pos(); return; } else if ( e->type() == Event_MouseButtonRelease ) { //debug( "saw release" ); if ( d->moving ) { qApp->removeEventFilter( this ); d->moving = 0; } return; } //debug( "saw move" ); // with that out of the way, let's concentrate on the moves... // first, the threshold QPoint p( QCursor::pos() ); if ( !d->moving && QABS( p.x() - d->pos.x() ) < 3 && QABS( p.y() - d->pos.y() ) < 3 ) return; // okay. it's a real move. // debug( "move event to %d, %d", p.x(), p.y() ); if ( !d->moving ) { d->moving = t; qApp->installEventFilter( this ); } QPoint lp( mapFromGlobal( p ) ); QMainWindowPrivate::ToolBarDock * dock = 0; // five possible cases: in each of the docs, and outside. if ( centralWidget()->geometry().contains( lp ) || !rect().contains( lp ) ) { // not a dock if ( t->parentWidget() ) { t->recreate( 0, 0, QPoint( p.x() - d->offset.x(), p.y() - d->offset.y() ), TRUE ); QApplication::syncX(); dock = d->tornOff; } else { t->move( p.x() - d->offset.x(), p.y() - d->offset.y() ); } } else if ( lp.y() < centralWidget()->y() ) { //top dock dock = d->top; } else if ( lp.y() >= centralWidget()->y() + centralWidget()->height() ) { // bottom dock dock = d->bottom; } else if ( lp.x() < centralWidget()->x() ) { // bottom dock dock = d->left; } else if ( lp.x() >= centralWidget()->x() + centralWidget()->width() ) { // right dock dock = d->right; } else { fatal( "never to happen" ); } if ( !dock ) return; debug( "1" ); // at this point dock points to the new dock QMainWindowPrivate::ToolBar * ct; ct = takeToolBarFromDock( t, d->top ); if ( !ct ) ct = takeToolBarFromDock( t, d->left ); if ( !ct ) ct = takeToolBarFromDock( t, d->right ); if ( !ct ) ct = takeToolBarFromDock( t, d->bottom ); if ( dock != d->tornOff && !ct ) ct = takeToolBarFromDock( t, d->tornOff ); if ( dock == d->tornOff || ct == 0 ) return; debug( "2" ); QMainWindowPrivate::ToolBar * c = dock->first(); QRect inLine; QRect betweenLines; int linestart = 0; while( c && ct ) { debug( "3 %p %p", c, ct ); if ( c->nl ) { if ( dock == d->top ) { betweenLines.setRect( 0, 0, width(), c->t->y() + c->t->height()/4 ); } else if ( dock == d->bottom ) { betweenLines.setRect( 0, c->t->y() + c->t->height()/4, width(), c->t->height()/2 ); } else if ( dock == d->left ) { betweenLines.setRect( 0, 0, c->t->x() + c->t->width()/4, height() ); } else { betweenLines.setRect( c->t->x() + 3*c->t->width()/4, 0, c->t->width()/2, height() ); } linestart = dock->at(); } if ( dock == d->top || dock == d->bottom ) { inLine.setRect( c->t->x()-c->t->height()/4, c->t->y(), c->t->height()/2, c->t->height() ); } else { inLine.setRect( c->t->x(), c->t->y() - c->t->width()/4, c->t->width(), c->t->width()/2 ); } if ( inLine.contains( lp ) ) { // ct goes in just before c, and takes over nl dock->insert( dock->at(), ct ); if ( t->parentWidget() != this ) t->recreate( this, 0, QPoint( 0, -t->height() ), TRUE ); t->setOrientation( (dock == d->top || dock == d->bottom ) ? QToolBar::Horizontal : QToolBar::Vertical ); ct->nl = c->nl; c->nl = FALSE; ct = 0; triggerLayout(); } else { QMainWindowPrivate::ToolBar * c2 = dock->next(); if ( c2 == 0 || c2->nl ) { // about to do the next line, so check whether c // should go in above this line if ( betweenLines.contains( lp ) ) { dock->insert( linestart, ct ); if ( t->parentWidget() != this ) t->recreate( this, 0, QPoint( 0, -t->height() ), TRUE ); t->setOrientation( (dock == d->top || dock == d->bottom ) ? QToolBar::Horizontal : QToolBar::Vertical ); ct->nl = TRUE; ct = 0; triggerLayout(); } else { // perhaps at the end of this line? let's see if ( dock == d->top || dock == d->bottom ) inLine.setRect( c->t->x() + c->t->width(), c->t->y(), width() - c->t->x() - c->t->width(), c->t->height() ); else inLine.setRect( c->t->x(), c->t->y() + c->t->height(), c->t->width(), height() - c->t->y() - c->t->height()); if ( inLine.contains( lp ) ) { dock->insert( dock->at(), ct ); if ( t->parentWidget() != this ) t->recreate( this, 0, QPoint( 0, -t->height() ), TRUE ); t->setOrientation( (dock == d->top || dock == d->bottom ) ? QToolBar::Horizontal : QToolBar::Vertical ); ct->nl = FALSE; ct = 0; triggerLayout(); } } } c = c2; } } debug( "4" ); // okay, is it at the very end? if ( ct ) { debug( "4a" ); dock->append( ct ); if ( t->parentWidget() != this ) t->recreate( this, 0, QPoint( 0, -t->height() ), TRUE ); t->setOrientation( (dock == d->top || dock == d->bottom ) ? QToolBar::Horizontal : QToolBar::Vertical ); ct->nl = TRUE; triggerLayout(); } }
/*!\reimp */ void QWindowsStyle::drawScrollBarControls( QPainter* p, const QScrollBar* sb, int sliderStart, uint controls, uint activeControl ) { #ifndef QT_NO_SCROLLBAR #define ADD_LINE_ACTIVE ( activeControl == AddLine ) #define SUB_LINE_ACTIVE ( activeControl == SubLine ) QColorGroup g = sb->colorGroup(); int sliderMin, sliderMax, sliderLength, buttonDim; scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim ); if (sliderStart > sliderMax) { // sanity check sliderStart = sliderMax; } int b = 0; int dimB = buttonDim; QRect addB; QRect subB; QRect addPageR; QRect subPageR; QRect sliderR; int addX, addY, subX, subY; int length = HORIZONTAL ? sb->width() : sb->height(); int extent = HORIZONTAL ? sb->height() : sb->width(); if ( HORIZONTAL ) { subY = addY = ( extent - dimB ) / 2; subX = b; addX = length - dimB - b; } else { subX = addX = ( extent - dimB ) / 2; subY = b; addY = length - dimB - b; } subB.setRect( subX,subY,dimB,dimB ); addB.setRect( addX,addY,dimB,dimB ); int sliderEnd = sliderStart + sliderLength; int sliderW = extent - b*2; if ( HORIZONTAL ) { subPageR.setRect( subB.right() + 1, b, sliderStart - subB.right() - 1 , sliderW ); addPageR.setRect( sliderEnd, b, addX - sliderEnd, sliderW ); sliderR .setRect( sliderStart, b, sliderLength, sliderW ); } else { subPageR.setRect( b, subB.bottom() + 1, sliderW, sliderStart - subB.bottom() - 1 ); addPageR.setRect( b, sliderEnd, sliderW, addY - sliderEnd ); sliderR .setRect( b, sliderStart, sliderW, sliderLength ); } bool maxedOut = (sb->maxValue() == sb->minValue()); if ( controls & AddLine ) { qDrawWinPanel( p, addB.x(), addB.y(), addB.width(), addB.height(), g, ADD_LINE_ACTIVE, &g.brush( QColorGroup::Button ) ); drawArrow( p, VERTICAL ? DownArrow : RightArrow, ADD_LINE_ACTIVE, addB.x()+2, addB.y()+2, addB.width()-4, addB.height()-4, g, !maxedOut ); } if ( controls & SubLine ) { qDrawWinPanel( p, subB.x(), subB.y(), subB.width(), subB.height(), g, SUB_LINE_ACTIVE, &g.brush( QColorGroup::Button ) ); drawArrow( p, VERTICAL ? UpArrow : LeftArrow, SUB_LINE_ACTIVE, subB.x()+2, subB.y()+2, subB.width()-4, subB.height()-4, g, !maxedOut ); } QBrush br = g.brush( QColorGroup::Light ).pixmap() ? g.brush( QColorGroup::Light ) : QBrush(g.light(), Dense4Pattern); p->setBrush( br ); p->setPen( NoPen ); p->setBackgroundMode( OpaqueMode ); if ( maxedOut ) { p->drawRect( sliderR ); } else { if ( (controls & SubPage && SubPage == activeControl) || (controls & AddPage && AddPage == activeControl) ) { QBrush b = p->brush(); QColor c = p->backgroundColor(); // p->fillRect( AddPage == activeControl? addPageR : subPageR, g.fillDark() ); p->setBackgroundColor( g.dark() ); p->setBrush( QBrush(g.shadow(), Dense4Pattern) ); p->drawRect( AddPage == activeControl? addPageR : subPageR ); p->setBackgroundColor( c ); p->setBrush( b ); } if ( controls & SubPage && SubPage != activeControl) p->drawRect( subPageR ); if ( controls & AddPage && AddPage != activeControl) p->drawRect( addPageR ); if ( controls & Slider ) { if ( !maxedOut ) { QPoint bo = p->brushOrigin(); if ( !sb->testWState(WState_GlobalBrushOrigin) ) p->setBrushOrigin(sliderR.topLeft()); qDrawWinPanel( p, sliderR.x(), sliderR.y(), sliderR.width(), sliderR.height(), g, FALSE, &g.brush( QColorGroup::Button ) ); p->setBrushOrigin(bo); } } } // ### perhaps this should not be able to accept focus if maxedOut? if ( sb->hasFocus() && (controls & Slider) ) drawFocusRect(p, QRect(sliderR.x()+2, sliderR.y()+2, sliderR.width()-5, sliderR.height()-5), g, &sb->backgroundColor()); #endif }
static void drawDial ( const QStyleOptionSlider *option, QPainter *painter ) { QPalette pal = option->palette; QColor buttonColor = pal.button().color(); const int width = option->rect.width(); const int height = option->rect.height(); const bool enabled = option->state & QStyle::State_Enabled; qreal r = qMin(width, height) / 2; r -= r/50; const qreal penSize = r/20.0; painter->save(); painter->setRenderHint(QPainter::Antialiasing); // Draw notches if (option->subControls & QStyle::SC_DialTickmarks) { painter->setPen(option->palette.dark().color().darker(120)); painter->drawLines(calcLines(option)); } // Cache dial background QString a = QString::fromLatin1("qdial"); QRect rect = option->rect; QPixmap internalPixmapCache; QImage imageCache; QPainter *p = painter; QString unique = uniqueName((a), option, option->rect.size()); int txType = painter->deviceTransform().type() | painter->worldTransform().type(); bool doPixmapCache = txType <= QTransform::TxTranslate; if (doPixmapCache && QPixmapCache::find(unique, internalPixmapCache)) { painter->drawPixmap(option->rect.topLeft(), internalPixmapCache); } else { if (doPixmapCache) { rect.setRect(0, 0, option->rect.width(), option->rect.height()); imageCache = QImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied); imageCache.fill(0); p = new QPainter(&imageCache); } //--BEGIN_STYLE_PIXMAPCACHE(QString::fromLatin1("qdial")); p->setRenderHint(QPainter::Antialiasing); const qreal d_ = r / 6; const qreal dx = option->rect.x() + d_ + (width - 2 * r) / 2 + 1; const qreal dy = option->rect.y() + d_ + (height - 2 * r) / 2 + 1; QRectF br = QRectF(dx + 0.5, dy + 0.5, int(r * 2 - 2 * d_ - 2), int(r * 2 - 2 * d_ - 2)); buttonColor.setHsv(buttonColor .hue(), qMin(140, buttonColor .saturation()), qMax(180, buttonColor.value())); QColor shadowColor(0, 0, 0, 20); if (enabled) { // Drop shadow qreal shadowSize = qMax(1.0, penSize/2.0); QRectF shadowRect= br.adjusted(-2*shadowSize, -2*shadowSize, 2*shadowSize, 2*shadowSize); QRadialGradient shadowGradient(shadowRect.center().x(), shadowRect.center().y(), shadowRect.width()/2.0, shadowRect.center().x(), shadowRect.center().y()); shadowGradient.setColorAt(qreal(0.91), QColor(0, 0, 0, 40)); shadowGradient.setColorAt(qreal(1.0), Qt::transparent); p->setBrush(shadowGradient); p->setPen(Qt::NoPen); p->translate(shadowSize, shadowSize); p->drawEllipse(shadowRect); p->translate(-shadowSize, -shadowSize); // Main gradient QRadialGradient gradient(br.center().x() - br.width()/3, dy, br.width()*1.3, br.center().x(), br.center().y() - br.height()/2); gradient.setColorAt(0, buttonColor.lighter(110)); gradient.setColorAt(qreal(0.5), buttonColor); gradient.setColorAt(qreal(0.501), buttonColor.darker(102)); gradient.setColorAt(1, buttonColor.darker(115)); p->setBrush(gradient); } else { p->setBrush(Qt::NoBrush); } p->setPen(QPen(buttonColor.darker(280))); p->drawEllipse(br); p->setBrush(Qt::NoBrush); p->setPen(buttonColor.lighter(110)); p->drawEllipse(br.adjusted(1, 1, -1, -1)); if (option->state & QStyle::State_HasFocus) { QColor highlight = pal.highlight().color(); highlight.setHsv(highlight.hue(), qMin(160, highlight.saturation()), qMax(230, highlight.value())); highlight.setAlpha(127); p->setPen(QPen(highlight, 2.0)); p->setBrush(Qt::NoBrush); p->drawEllipse(br.adjusted(-1, -1, 1, 1)); } //--END_STYLE_PIXMAPCACHE if (doPixmapCache) { p->end(); delete p; internalPixmapCache = QPixmap::fromImage(imageCache); painter->drawPixmap(option->rect.topLeft(), internalPixmapCache); QPixmapCache::insert(unique, internalPixmapCache); } } QPointF dp = calcRadialPos(option, qreal(0.70)); buttonColor = buttonColor.lighter(104); buttonColor.setAlphaF(qreal(0.8)); const qreal ds = r/qreal(7.0); QRectF dialRect(dp.x() - ds, dp.y() - ds, 2*ds, 2*ds); QRadialGradient dialGradient(dialRect.center().x() + dialRect.width()/2, dialRect.center().y() + dialRect.width(), dialRect.width()*2, dialRect.center().x(), dialRect.center().y()); dialGradient.setColorAt(1, buttonColor.darker(140)); dialGradient.setColorAt(qreal(0.4), buttonColor.darker(120)); dialGradient.setColorAt(0, buttonColor.darker(110)); if (penSize > 3.0) { painter->setPen(QPen(QColor(0, 0, 0, 25), penSize)); painter->drawLine(calcRadialPos(option, qreal(0.90)), calcRadialPos(option, qreal(0.96))); } painter->setBrush(dialGradient); painter->setPen(QColor(255, 255, 255, 150)); painter->drawEllipse(dialRect.adjusted(-1, -1, 1, 1)); painter->setPen(QColor(0, 0, 0, 80)); painter->drawEllipse(dialRect); painter->restore(); }
bool Tileset::Load(const QString &def_filename, const QString& root_folder, bool one_image) { if (def_filename.isEmpty()) return false; _initialized = false; // Reset container data autotileability.clear(); walkability.clear(); _animated_tiles.clear(); // Create filenames from the tileset name _tileset_name = CreateTilesetName(def_filename); _tileset_definition_filename = def_filename; // Set up for reading the tileset definition file. ReadScriptDescriptor read_data; if(!read_data.OpenFile(root_folder.toStdString() + def_filename.toStdString())) { _initialized = false; return false; } if (!read_data.OpenTable("tileset")) { read_data.CloseFile(); qDebug("Failed to open the 'tileset' table"); return false; } _tileset_image_filename = QString::fromStdString(read_data.ReadString("image")); // Prepare the tile vector and load the tileset image tiles.clear(); tiles.resize(256); QRect rectangle; QImage entire_tileset; QString tileset_full_path = root_folder + _tileset_image_filename; if (!entire_tileset.load(tileset_full_path, "png")) { qDebug("Failed to load tileset image: %s", tileset_full_path.toStdString().c_str()); return false; } if (one_image) { tiles[0].convertFromImage(entire_tileset); } else { for(uint32_t row = 0; row < num_rows; ++row) { for(uint32_t col = 0; col < num_cols; ++col) { rectangle.setRect(col * TILE_WIDTH, row * TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT); QImage tile = entire_tileset.copy(rectangle); if(!tile.isNull()) { // linearize the tile index uint32_t i = num_rows * row + col; tiles[i].convertFromImage(tile); } else { qDebug("Image loading error!"); } } } } // Read in autotiling information. if(read_data.DoesTableExist("autotiling") == true) { // Contains the keys (indeces, if you will) of this table's entries std::vector<int32_t> keys; uint32_t table_size = read_data.GetTableSize("autotiling"); read_data.OpenTable("autotiling"); read_data.ReadTableKeys(keys); for(uint32_t i = 0; i < table_size; ++i) autotileability[keys[i]] = read_data.ReadString(keys[i]); read_data.CloseTable(); } // make sure table exists first // Read in walkability information. if(read_data.DoesTableExist("walkability") == true) { std::vector<int32_t> vect; // used to read in vectors from the data file read_data.OpenTable("walkability"); for(int32_t i = 0; i < 16; ++i) { read_data.OpenTable(i); // Make sure that at least one row exists if(read_data.IsErrorDetected() == true) { read_data.CloseTable(); read_data.CloseTable(); read_data.CloseFile(); _initialized = false; return false; } for(int32_t j = 0; j < 16; ++j) { read_data.ReadIntVector(j, vect); if(read_data.IsErrorDetected() == false) walkability[i * 16 + j] = vect; vect.clear(); } // iterate through all tiles in a row read_data.CloseTable(); } // iterate through all rows of the walkability table read_data.CloseTable(); } // make sure table exists first // Read in animated tiles. if(read_data.DoesTableExist("animated_tiles") == true) { uint32_t table_size = read_data.GetTableSize("animated_tiles"); read_data.OpenTable("animated_tiles"); for(uint32_t i = 1; i <= table_size; ++i) { _animated_tiles.push_back(std::vector<AnimatedTileData>()); std::vector<AnimatedTileData>& tiles = _animated_tiles.back(); // Calculate loop end: an animated tile is comprised of a tile id // and a time, so the loop end is really half the table size. uint32_t tile_count = read_data.GetTableSize(i) / 2; read_data.OpenTable(i); for(uint32_t index = 1; index <= tile_count; index++) { AnimatedTileData anim_tile; anim_tile.tile_id = read_data.ReadUInt(index * 2 - 1); anim_tile.time = read_data.ReadUInt(index * 2); tiles.push_back(anim_tile); } // iterate through all tiles in one animated tile read_data.CloseTable(); } // iterate through all animated tiles in the table read_data.CloseTable(); } // make sure table exists first read_data.CloseTable(); read_data.CloseFile(); _initialized = true; return true; } // Tileset::Load(...)
/*! \return Bounding rectangle of the pipe ( without borders ) in widget coordinates */ QRect QwtThermo::pipeRect() const { const QRect cr = contentsRect(); int mbd = 0; if ( d_data->scalePos != NoScale ) { int d1, d2; scaleDraw()->getBorderDistHint( font(), d1, d2 ); mbd = qMax( d1, d2 ); } int bw = d_data->borderWidth; QRect tRect; if ( d_data->orientation == Qt::Horizontal ) { switch ( d_data->scalePos ) { case TopScale: { tRect.setRect( cr.x() + mbd + bw, cr.y() + cr.height() - d_data->pipeWidth - 2 * bw, cr.width() - 2 * ( bw + mbd ), d_data->pipeWidth ); break; } case BottomScale: case NoScale: default: { tRect.setRect( cr.x() + mbd + bw, cr.y() + d_data->borderWidth, cr.width() - 2 * ( bw + mbd ), d_data->pipeWidth ); break; } } } else // Qt::Vertical { switch ( d_data->scalePos ) { case RightScale: { tRect.setRect( cr.x() + bw, cr.y() + mbd + bw, d_data->pipeWidth, cr.height() - 2 * ( bw + mbd ) ); break; } case LeftScale: case NoScale: default: { tRect.setRect( cr.x() + cr.width() - 2 * bw - d_data->pipeWidth, cr.y() + mbd + bw, d_data->pipeWidth, cr.height() - 2 * ( bw + mbd ) ); break; } } } return tRect; }
void QHexEdit::paintEvent(QPaintEvent *event) { QPainter painter(viewport()); int pxOfsX = horizontalScrollBar()->value(); if (event->rect() != _cursorRect) { int pxPosStartY = _pxCharHeight; // draw some patterns if needed painter.fillRect(event->rect(), viewport()->palette().color(QPalette::Base)); if (_addressArea) painter.fillRect(QRect(-pxOfsX, event->rect().top(), _pxPosHexX - _pxGapAdrHex/2, height()), _addressAreaColor); if (_asciiArea) { int linePos = _pxPosAsciiX - (_pxGapHexAscii / 2); painter.setPen(Qt::gray); painter.drawLine(linePos - pxOfsX, event->rect().top(), linePos - pxOfsX, height()); } painter.setPen(viewport()->palette().color(QPalette::WindowText)); // paint address area if (_addressArea) { QString address; for (int row=0, pxPosY = _pxCharHeight; row <= (_dataShown.size()/_bytesPerLine); row++, pxPosY +=_pxCharHeight) { address = QString("%1").arg(_bPosFirst + row*_bytesPerLine + _addressOffset, _addrDigits, 16, QChar('0')); painter.drawText(_pxPosAdrX - pxOfsX, pxPosY, address); } } // paint hex and ascii area QPen colStandard = QPen(viewport()->palette().color(QPalette::WindowText)); painter.setBackgroundMode(Qt::TransparentMode); for (int row = 0, pxPosY = pxPosStartY; row <= _rowsShown; row++, pxPosY +=_pxCharHeight) { QByteArray hex; int pxPosX = _pxPosHexX - pxOfsX; int pxPosAsciiX2 = _pxPosAsciiX - pxOfsX; qint64 bPosLine = row * _bytesPerLine; for (int colIdx = 0; ((bPosLine + colIdx) < _dataShown.size() && (colIdx < _bytesPerLine)); colIdx++) { QColor c = viewport()->palette().color(QPalette::Base); painter.setPen(colStandard); qint64 posBa = _bPosFirst + bPosLine + colIdx; if ((getSelectionBegin() <= posBa) && (getSelectionEnd() > posBa)) { c = _brushSelection.color(); painter.setPen(_penSelection); } else { if (_highlighting) if (_markedShown.at((int)(posBa - _bPosFirst))) { c = _brushHighlighted.color(); painter.setPen(_penHighlighted); } } // render hex value QRect r; if (colIdx == 0) r.setRect(pxPosX, pxPosY - _pxCharHeight + _pxSelectionSub, 2*_pxCharWidth, _pxCharHeight); else r.setRect(pxPosX - _pxCharWidth, pxPosY - _pxCharHeight + _pxSelectionSub, 3*_pxCharWidth, _pxCharHeight); painter.fillRect(r, c); hex = _hexDataShown.mid((bPosLine + colIdx) * 2, 2); painter.drawText(pxPosX, pxPosY, hexCaps()?hex.toUpper():hex); pxPosX += 3*_pxCharWidth; // render ascii value if (_asciiArea) { int ch = (uchar)_dataShown.at(bPosLine + colIdx); if ( ch < ' ' || ch > '~' ) ch = '.'; r.setRect(pxPosAsciiX2, pxPosY - _pxCharHeight + _pxSelectionSub, _pxCharWidth, _pxCharHeight); painter.fillRect(r, c); painter.drawText(pxPosAsciiX2, pxPosY, QChar(ch)); pxPosAsciiX2 += _pxCharWidth; } } } painter.setBackgroundMode(Qt::TransparentMode); painter.setPen(viewport()->palette().color(QPalette::WindowText)); } // _cursorPosition counts in 2, _bPosFirst counts in 1 int hexPositionInShowData = _cursorPosition - 2 * _bPosFirst; // due to scrolling the cursor can go out of the currently displayed data if ((hexPositionInShowData >= 0) && (hexPositionInShowData < _hexDataShown.size())) { // paint cursor if (_readOnly) { // make the background stick out QColor color = viewport()->palette().dark().color(); painter.fillRect(QRect(_pxCursorX - pxOfsX, _pxCursorY - _pxCharHeight + _pxSelectionSub, _pxCharWidth, _pxCharHeight), color); } else { if (_blink && hasFocus()) painter.fillRect(_cursorRect, this->palette().color(QPalette::WindowText)); } if (_editAreaIsAscii) { // every 2 hex there is 1 ascii int asciiPositionInShowData = hexPositionInShowData / 2; int ch = (uchar)_dataShown.at(asciiPositionInShowData); if (ch < ' ' || ch > '~') ch = '.'; painter.drawText(_pxCursorX - pxOfsX, _pxCursorY, QChar(ch)); } else { painter.drawText(_pxCursorX - pxOfsX, _pxCursorY, _hexDataShown.mid(hexPositionInShowData, 1)); } } // emit event, if size has changed if (_lastEventSize != _chunks->size()) { _lastEventSize = _chunks->size(); emit currentSizeChanged(_lastEventSize); } }
void TabBarWidgetMacStyle::tabLayout(const QStyleOptionTab *pOption, const QWidget *pWidget, QRect *pTextRect, QRect *pIconRect) const { // Compute our tab layout // Note: adapted from QCommonStylePrivate::tabLayout()... Q_ASSERT(pTextRect); Q_ASSERT(pIconRect); QRect textRect = pOption->rect; bool verticalTab = (pOption->shape == QTabBar::RoundedWest) || (pOption->shape == QTabBar::RoundedEast) || (pOption->shape == QTabBar::TriangularWest) || (pOption->shape == QTabBar::TriangularEast); if (verticalTab) { textRect.setRect(0, 0, textRect.height(), textRect.width()); } if (!pOption->leftButtonSize.isEmpty()) { textRect.adjust(-4, 0, 0, 0); } int horizontalShift = pixelMetric(QStyle::PM_TabBarTabShiftHorizontal, pOption, pWidget); int verticalShift = pixelMetric(QStyle::PM_TabBarTabShiftVertical, pOption, pWidget); int horizontalPadding = pixelMetric(QStyle::PM_TabBarTabHSpace, pOption, pWidget)/2; int verticalPadding = pixelMetric(QStyle::PM_TabBarTabVSpace, pOption, pWidget)/2; if ( (pOption->shape == QTabBar::RoundedSouth) || (pOption->shape == QTabBar::TriangularSouth)) { verticalShift = -verticalShift; } textRect.adjust(horizontalPadding, verticalShift-verticalPadding, horizontalShift-horizontalPadding, verticalPadding); if ((pOption->state & QStyle::State_Selected) != 0) { textRect.setTop(textRect.top()-verticalShift); textRect.setRight(textRect.right()-horizontalShift); } if (!pOption->leftButtonSize.isEmpty()) { textRect.setLeft( textRect.left() +(verticalTab? pOption->leftButtonSize.height(): pOption->leftButtonSize.width())); } if (!pOption->rightButtonSize.isEmpty()) { textRect.setRight( textRect.right() -(verticalTab? pOption->rightButtonSize.height(): pOption->rightButtonSize.width())); } if (!pOption->icon.isNull()) { QSize iconSize = pOption->iconSize; if (!iconSize.isValid()) { int iconExtent = pixelMetric(QStyle::PM_SmallIconSize); iconSize = QSize(iconExtent, iconExtent); } QSize tabIconSize = pOption->icon.actualSize(iconSize, ((pOption->state & QStyle::State_Enabled) != 0)? QIcon::Normal: QIcon::Disabled, ((pOption->state & QStyle::State_Selected) != 0)? QIcon::On: QIcon::Off); tabIconSize = QSize(qMin(tabIconSize.width(), iconSize.width()), qMin(tabIconSize.height(), iconSize.height())); *pIconRect = QRect(textRect.left(), textRect.center().y()-tabIconSize.height()/2, tabIconSize.width(), tabIconSize.height()); if (!verticalTab) { *pIconRect = visualRect(pOption->direction, pOption->rect, *pIconRect); } textRect.setLeft(textRect.left()+tabIconSize.width()+4); } if (!verticalTab) { textRect = visualRect(pOption->direction, pOption->rect, textRect); } *pTextRect = textRect; }
void MaskWidget::paintEvent(QPaintEvent* e) { if (!m_desktopPixmap.isNull()) { m_curPos = QCursor::pos(); QPainter painter(this); painter.drawPixmap(0, 0, m_desktopPixmap); if (!m_bScreenShotDone) { if (!m_bDragging) { m_curRc.setRect(-9999, -9999, 19999, 19999); for (std::vector<RECT>::iterator it = g_winRects.begin(); it != g_winRects.end(); ++it) { QRect rect; rect.setRect(it->left, it->top, it->right - it->left, it->bottom - it->top); if (rect.contains(QCursor::pos()) && m_curRc.contains(rect)/* && rect.height() > 5 && rect.width() > 5*/) { m_curRc = rect; //break; } } } else { m_curRc = QRect(m_startPoint, QCursor::pos()); } } painter.save(); painter.setPen(Qt::NoPen); painter.setBrush(QColor(0, 0, 0, 120)); QPolygon p1(QRect(0, 0, width(), height())); QPolygon p2(m_curRc, true); p1 = p1.subtracted(p2); painter.drawPolygon(p1); painter.restore(); painter.save(); QPen pen = painter.pen(); if (m_bScreenShotDone || m_bMousePressing) { pen.setWidth(2); pen.setColor(QColor(6, 157, 213)); pen.setStyle(Qt::DashDotDotLine); } else { pen.setWidth(4); pen.setColor(QColor(0, 255, 0)); pen.setStyle(Qt::SolidLine); } painter.setPen(pen); painter.drawRect(m_curRc); painter.restore(); painter.save(); QRect ori(m_curPos.x() - 15, m_curPos.y() - 11, 30, 22); QPixmap magnifier(126, 122); QPainter painter2(&magnifier); painter2.save(); painter2.fillRect(0, 0, 126, 122, QBrush(QColor(51, 51, 51, 200))); painter2.restore(); QPen p = painter2.pen(); p.setWidth(1); p.setColor(QColor(51, 51, 51)); painter2.setPen(p); painter2.drawRect(0, 0, 125, 93); p.setWidth(2); p.setColor(QColor(255, 255, 255)); painter2.setPen(p); painter2.drawRect(2, 2, 122, 90); painter2.drawPixmap(3, 3, m_desktopPixmap.copy(ori).scaled(120, 88)); p.setWidth(4); p.setColor(QColor(0, 122, 179, 128)); painter2.setPen(p); painter2.drawLine(5, 45, 121, 45); painter2.drawLine(61, 5, 61, 89); p.setWidth(1); p.setColor(QColor(255, 255, 255)); painter2.setPen(p); painter2.drawText(6, 105, QString("%1 x %2").arg(m_curRc.width()).arg(m_curRc.height())); QImage image = m_desktopPixmap.toImage(); QRgb rgb = image.pixel(m_curPos.x()-1, m_curPos.y()-1); painter2.drawText(6, 118, QString("rgb(%1,%2,%3").arg(qRed(rgb)).arg(qGreen(rgb)).arg(qBlue(rgb))); QPoint showPoint(m_curPos.x() + 10, m_curPos.y() + 10); if (m_curPos.y() + 130 > this->height()) showPoint.setY(m_curPos.y() - 130); if (m_curPos.x() + 130 > this->width()) showPoint.setX(m_curPos.x() - 130); painter.drawPixmap(showPoint, magnifier); } }
QRect KScrollBar::subControlRect(QStyle::SubControl sc) { QRect ret; const QRect scrollBarRect = QRect(QPoint(0, 0), size().toSize()); int sbextent = m_buttonHeight; switch (sc) { case QStyle::SC_ScrollBarSubLine: // top/left button if (m_orientation == Qt::Horizontal) { int buttonWidth = qMin(scrollBarRect.width() / 2, sbextent); ret.setRect(0, 0, buttonWidth, scrollBarRect.height()); } else { int buttonHeight = qMin(scrollBarRect.height() / 2, sbextent); ret.setRect(0, 0, scrollBarRect.width(), buttonHeight); } return ret; case QStyle::SC_ScrollBarAddLine: // bottom/right button if (m_orientation == Qt::Horizontal) { int buttonWidth = qMin(scrollBarRect.width()/2, sbextent); ret.setRect(scrollBarRect.width() - buttonWidth, 0, buttonWidth, scrollBarRect.height()); } else { int buttonHeight = qMin(scrollBarRect.height()/2, sbextent); ret.setRect(0, scrollBarRect.height() - buttonHeight, scrollBarRect.width(), buttonHeight); } return ret; } int maxlen = ((m_orientation == Qt::Horizontal) ? width() : height()) - (sbextent * 2); int sliderlen = sliderPixels(); int sliderstart = sbextent + sliderPositionFromValue(m_minimum, m_maximum, m_value, maxlen - sliderlen, false); switch (sc) { case QStyle::SC_ScrollBarSubPage: // between top/left button and slider if (m_orientation == Qt::Horizontal) ret.setRect(sbextent, 0, sliderstart - sbextent, scrollBarRect.height()); else ret.setRect(0, sbextent, scrollBarRect.width(), sliderstart - sbextent); break; case QStyle::SC_ScrollBarAddPage: // between bottom/right button and slider if (m_orientation == Qt::Horizontal) ret.setRect(sliderstart + sliderlen, 0, maxlen - sliderstart - sliderlen + sbextent, scrollBarRect.height()); else ret.setRect(0, sliderstart + sliderlen, scrollBarRect.width(), maxlen - sliderstart - sliderlen + sbextent); break; case QStyle::SC_ScrollBarGroove: if (m_orientation == Qt::Horizontal) ret.setRect(sbextent, 0, scrollBarRect.width() - sbextent * 2, scrollBarRect.height()); else ret.setRect(0, sbextent, scrollBarRect.width(), scrollBarRect.height() - sbextent * 2); break; case QStyle::SC_ScrollBarSlider: if (m_orientation == Qt::Horizontal) ret.setRect(sliderstart, 0, sliderlen, scrollBarRect.height()); else ret.setRect(0, sliderstart, scrollBarRect.width(), sliderlen); break; default: break; } return ret; }
/*! Redraw the liquid in thermometer pipe. \param painter Painter */ void QwtThermo::drawThermo(QPainter *painter) { int alarm = 0, taval = 0; QRect fRect; QRect aRect; QRect bRect; int inverted = ( d_data->maxValue < d_data->minValue ); // // Determine if value exceeds alarm threshold. // Note: The alarm value is allowed to lie // outside the interval (minValue, maxValue). // if (d_data->alarmEnabled) { if (inverted) { alarm = ((d_data->alarmLevel >= d_data->maxValue) && (d_data->alarmLevel <= d_data->minValue) && (d_data->value >= d_data->alarmLevel)); } else { alarm = (( d_data->alarmLevel >= d_data->minValue) && (d_data->alarmLevel <= d_data->maxValue) && (d_data->value >= d_data->alarmLevel)); } } // // transform values // int tval = transform(d_data->value); if (alarm) taval = transform(d_data->alarmLevel); // // calculate recangles // if ( d_data->orientation == Qt::Horizontal ) { if (inverted) { bRect.setRect(d_data->thermoRect.x(), d_data->thermoRect.y(), tval - d_data->thermoRect.x(), d_data->thermoRect.height()); if (alarm) { aRect.setRect(tval, d_data->thermoRect.y(), taval - tval + 1, d_data->thermoRect.height()); fRect.setRect(taval + 1, d_data->thermoRect.y(), d_data->thermoRect.x() + d_data->thermoRect.width() - (taval + 1), d_data->thermoRect.height()); } else { fRect.setRect(tval, d_data->thermoRect.y(), d_data->thermoRect.x() + d_data->thermoRect.width() - tval, d_data->thermoRect.height()); } } else { bRect.setRect(tval + 1, d_data->thermoRect.y(), d_data->thermoRect.width() - (tval + 1 - d_data->thermoRect.x()), d_data->thermoRect.height()); if (alarm) { aRect.setRect(taval, d_data->thermoRect.y(), tval - taval + 1, d_data->thermoRect.height()); fRect.setRect(d_data->thermoRect.x(), d_data->thermoRect.y(), taval - d_data->thermoRect.x(), d_data->thermoRect.height()); } else { fRect.setRect(d_data->thermoRect.x(), d_data->thermoRect.y(), tval - d_data->thermoRect.x() + 1, d_data->thermoRect.height()); } } } else // Qt::Vertical { if (tval < d_data->thermoRect.y()) tval = d_data->thermoRect.y(); else { if (tval > d_data->thermoRect.y() + d_data->thermoRect.height()) tval = d_data->thermoRect.y() + d_data->thermoRect.height(); } if (inverted) { bRect.setRect(d_data->thermoRect.x(), tval + 1, d_data->thermoRect.width(), d_data->thermoRect.height() - (tval + 1 - d_data->thermoRect.y())); if (alarm) { aRect.setRect(d_data->thermoRect.x(), taval, d_data->thermoRect.width(), tval - taval + 1); fRect.setRect(d_data->thermoRect.x(), d_data->thermoRect.y(), d_data->thermoRect.width(), taval - d_data->thermoRect.y()); } else { fRect.setRect(d_data->thermoRect.x(), d_data->thermoRect.y(), d_data->thermoRect.width(), tval - d_data->thermoRect.y() + 1); } } else { bRect.setRect(d_data->thermoRect.x(), d_data->thermoRect.y(), d_data->thermoRect.width(), tval - d_data->thermoRect.y()); if (alarm) { aRect.setRect(d_data->thermoRect.x(),tval, d_data->thermoRect.width(), taval - tval + 1); fRect.setRect(d_data->thermoRect.x(),taval + 1, d_data->thermoRect.width(), d_data->thermoRect.y() + d_data->thermoRect.height() - (taval + 1)); } else { fRect.setRect(d_data->thermoRect.x(),tval, d_data->thermoRect.width(), d_data->thermoRect.y() + d_data->thermoRect.height() - tval); } } } // // paint thermometer // const QColor bgColor = #if QT_VERSION < 0x040000 colorGroup().color(QColorGroup::Background); #else palette().color(QPalette::Background); #endif painter->fillRect(bRect, bgColor); if (alarm) painter->fillRect(aRect, d_data->alarmBrush); painter->fillRect(fRect, d_data->fillBrush); }
void PlIconViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const { QString title = VLCModel::getMeta( index, COLUMN_TITLE ); QString artist = VLCModel::getMeta( index, COLUMN_ARTIST ); QFont font( index.data( Qt::FontRole ).value<QFont>() ); painter->setFont( font ); QFontMetrics fm = painter->fontMetrics(); int averagewidth = fm.averageCharWidth(); QSize rectSize = option.rect.size(); int art_width = averagewidth * ICON_SCALER; int art_height = averagewidth * ICON_SCALER; QPixmap artPix = VLCModel::getArtPixmap( index, QSize( art_width, art_height) ); paintBackground( painter, option, index ); painter->save(); QRect artRect( option.rect.x() + ( rectSize.width() - artPix.width() ) / 2, option.rect.y() - averagewidth*3 + ( rectSize.height() - artPix.height() ) / 2, artPix.width(), artPix.height() ); // Draw the drop shadow painter->save(); painter->setOpacity( 0.7 ); painter->setBrush( QBrush( Qt::darkGray ) ); painter->setPen( Qt::NoPen ); painter->drawRoundedRect( artRect.adjusted( 0, 0, 2, 2 ), ART_RADIUS, ART_RADIUS ); painter->restore(); // Draw the art pixmap QPainterPath artRectPath; artRectPath.addRoundedRect( artRect, ART_RADIUS, ART_RADIUS ); painter->setClipPath( artRectPath ); painter->drawPixmap( artRect, artPix ); painter->setClipping( false ); if( option.state & QStyle::State_Selected ) painter->setPen( option.palette.color( QPalette::HighlightedText ) ); //Draw children indicator if( !index.data( PLModel::IsLeafNodeRole ).toBool() ) { QRect r( option.rect ); r.setSize( QSize( 25, 25 ) ); r.translate( 5, 5 ); if( index.data( PLModel::IsCurrentsParentNodeRole ).toBool() ) { painter->setOpacity( 0.75 ); QPainterPath nodeRectPath; nodeRectPath.addRoundedRect( r, 4, 4 ); painter->fillPath( nodeRectPath, option.palette.color( QPalette::Highlight ) ); painter->setOpacity( 1.0 ); } QPixmap dirPix( ":/type/node" ); QRect r2( dirPix.rect() ); r2.moveCenter( r.center() ); painter->drawPixmap( r2, dirPix ); } // Draw title font.setItalic( true ); QRect textRect; textRect.setRect( option.rect.x() , artRect.bottom() + fm.height()/2, option.rect.width(), fm.height() ); painter->drawText( textRect, fm.elidedText( title, Qt::ElideRight, textRect.width() ), QTextOption( Qt::AlignCenter ) ); // Draw artist painter->setPen( painter->pen().color().lighter( 150 ) ); font.setItalic( false ); painter->setFont( font ); fm = painter->fontMetrics(); textRect.moveTop( textRect.bottom() + 1 ); painter->drawText( textRect, fm.elidedText( artist, Qt::ElideRight, textRect.width() ), QTextOption( Qt::AlignCenter ) ); painter->restore(); }
void MolWidget::paintEvent( QPaintEvent * ) { using adcontrols::ChemicalFormula; QPainter painter( this ); if ( ctabs_.empty() ) { QRect rc = painter.viewport(); rc.setRect( rc.x() + 1, rc.y() + 1, rc.width() - 2, rc.height() - 2 ); painter.drawRect( rc ); painter.setFont( QFont( "Decorative" ) ); painter.drawText( rc, Qt::AlignHCenter | Qt::AlignCenter, "Drop MOL file here" ); return; } const adcontrols::CTable& ctab = ctabs_.back().second; std::wstring formula = ChemicalFormula::getFormula( ctab ); std::vector< std::wstring > hydrogens; do { typedef boost::char_separator< wchar_t > separator; typedef boost::tokenizer< boost::char_separator<wchar_t> , std::wstring::const_iterator , std::wstring > tokenizer; separator sep( L" ", L"" ); tokenizer tokens( formula, sep ); for ( tokenizer::iterator it = tokens.begin(); it != tokens.end(); ++it ) hydrogens.push_back( *it ); } while(0); std::wstring stdformula = ChemicalFormula().standardFormula( formula ); double m = ChemicalFormula().getMonoIsotopicMass( stdformula ); std::wostringstream label; label << stdformula << " mass: " << std::fixed << std::setprecision(10) << m; painter.drawText( 16, 24, qtwrapper::qstring( label.str() ) ); // painter.drawText( 16, 24 + 16, qtwrapper::qstring( formula ) ); // --- draw molecule -- painter.translate( painter.window().center() ); painter.setFont( QFont( "Decorative" ) ); const double factor = 25; for ( size_t n = 0; n < ctab.atoms().size(); ++n ) { const adcontrols::CTable::Atom& a = ctab.atom( n ); if ( hydrogens[ n ].find( L"H" ) == std::string::npos ) painter.setPen( QColor( Qt::black ) ); else painter.setPen( QColor( Qt::red ) ); //QRectF rc( a.x * factor - 16, a.y * factor - 16, 32, 32 ); //painter.drawText( rc, Qt::AlignCenter | Qt::AlignHCenter, qtwrapper::qstring::copy( a.symbol ) ); painter.drawText( a.x * factor, a.y * factor, qtwrapper::qstring::copy( a.symbol ) ); } for ( const adcontrols::CTable::Bond& b: ctab.bonds() ) { adcontrols::CTable::Atom a1 = ctab.atom( b.first_atom_number - 1 ); adcontrols::CTable::Atom a2 = ctab.atom( b.second_atom_number - 1 ); a1.x *= factor; a1.y *= factor; a2.x *= factor; a2.y *= factor; if ( b.bond_type == 1 ) { painter.setPen( QColor( Qt::blue ) ); painter.drawLine( a1.x, a1.y, a2.x, a2.y ); } else if ( b.bond_type == 2 ) { painter.setPen( QColor( Qt::blue ) ); double dx = a2.x - a1.x; double dy = a2.y - a1.y; double L = std::sqrt( ( dx * dx ) + ( dy * dy ) ); const int offset = 2; do { double x1 = a1.x - offset * dy / L; double x2 = a2.x - offset * dy / L; double y1 = a1.y - offset * (-dx) / L; double y2 = a2.y - offset * (-dx) / L; painter.drawLine( x1, y1, x2, y2 ); } while(0); do { double x1 = a1.x + offset * dy / L; double x2 = a2.x + offset * dy / L; double y1 = a1.y + offset * (-dx) / L; double y2 = a2.y + offset * (-dx) / L; painter.drawLine( x1, y1, x2, y2 ); } while(0); } else if ( b.bond_type == 3 ) { painter.setPen( QColor( Qt::blue ) ); painter.drawLine( a1.x, a1.y, a2.x, a2.y ); double dx = a2.x - a1.x; double dy = a2.y - a1.y; double L = std::sqrt( ( dx * dx ) + ( dy * dy ) ); const int offset = 3; do { double x1 = a1.x - offset * dy / L; double x2 = a2.x - offset * dy / L; double y1 = a1.y - offset * (-dx) / L; double y2 = a2.y - offset * (-dx) / L; painter.drawLine( x1, y1, x2, y2 ); } while(0); do { double x1 = a1.x + offset * dy / L; double x2 = a2.x + offset * dy / L; double y1 = a1.y + offset * (-dx) / L; double y2 = a2.y + offset * (-dx) / L; painter.drawLine( x1, y1, x2, y2 ); } while(0); } } std::vector< key_ctable_pair_t >::iterator it = std::remove_if( ctabs_.begin(), ctabs_.end() , boost::bind( &key_ctable_pair_t::first, _1 ) == QString( "delete me" ) ); ctabs_.erase( it, ctabs_.end() ); }
void PlastikClient::paintEvent(QPaintEvent *e) { QRegion region = e->region(); PlastikHandler *handler = Handler(); if (oldCaption != caption() ) clearCaptionPixmaps(); bool active = isActive(); bool toolWindow = isToolWindow(); QPainter painter(widget() ); // often needed coordinates QRect r = widget()->rect(); int r_w = r.width(); // int r_h = r.height(); int r_x, r_y, r_x2, r_y2; r.getCoords(&r_x, &r_y, &r_x2, &r_y2); const int borderLeft = layoutMetric(LM_BorderLeft); const int borderRight = layoutMetric(LM_BorderRight); const int borderBottom = layoutMetric(LM_BorderBottom); const int titleHeight = layoutMetric(LM_TitleHeight); const int titleEdgeTop = layoutMetric(LM_TitleEdgeTop); const int titleEdgeBottom = layoutMetric(LM_TitleEdgeBottom); const int titleEdgeLeft = layoutMetric(LM_TitleEdgeLeft); const int titleEdgeRight = layoutMetric(LM_TitleEdgeRight); const int borderBottomTop = r_y2-borderBottom+1; const int borderLeftRight = r_x+borderLeft-1; const int borderRightLeft = r_x2-borderRight+1; const int titleEdgeBottomBottom = r_y+titleEdgeTop+titleHeight+titleEdgeBottom-1; const int sideHeight = borderBottomTop-titleEdgeBottomBottom-1; QRect Rtitle = QRect(r_x+titleEdgeLeft+buttonsLeftWidth(), r_y+titleEdgeTop, r_x2-titleEdgeRight-buttonsRightWidth()-(r_x+titleEdgeLeft+buttonsLeftWidth()), titleEdgeBottomBottom-(r_y+titleEdgeTop) ); QRect tempRect; // topSpacer if(titleEdgeTop > 0) { tempRect.setRect(r_x+2, r_y, r_w-2*2, titleEdgeTop ); if (tempRect.isValid() && region.contains(tempRect) ) { painter.drawTiledPixmap(tempRect, handler->pixmap(qubes_label, TitleBarTileTop, active, toolWindow) ); } } // leftTitleSpacer int titleMarginLeft = 0; int titleMarginRight = 0; if(titleEdgeLeft > 0) { tempRect.setRect(r_x, r_y, borderLeft, titleEdgeTop+titleHeight+titleEdgeBottom); if (tempRect.isValid() && region.contains(tempRect) ) { painter.drawTiledPixmap(tempRect, handler->pixmap(qubes_label, TitleBarLeft, active, toolWindow) ); titleMarginLeft = borderLeft; } } // rightTitleSpacer if(titleEdgeRight > 0) { tempRect.setRect(borderRightLeft, r_y, borderRight, titleEdgeTop+titleHeight+titleEdgeBottom); if (tempRect.isValid() && region.contains(tempRect) ) { painter.drawTiledPixmap(tempRect, handler->pixmap(qubes_label, TitleBarRight, active, toolWindow) ); titleMarginRight = borderRight; } } // titleSpacer const QPixmap &caption = captionPixmap(); if(Rtitle.width() > 0) { m_captionRect = captionRect(); // also update m_captionRect! if (m_captionRect.isValid() && region.contains(m_captionRect) ) { painter.drawTiledPixmap(m_captionRect, caption); } // left to the title tempRect.setRect(r_x+titleMarginLeft, m_captionRect.top(), m_captionRect.left() - (r_x+titleMarginLeft), m_captionRect.height() ); if (tempRect.isValid() && region.contains(tempRect) ) { painter.drawTiledPixmap(tempRect, handler->pixmap(qubes_label, TitleBarTile, active, toolWindow) ); } // right to the title tempRect.setRect(m_captionRect.right()+1, m_captionRect.top(), (r_x2-titleMarginRight) - m_captionRect.right(), m_captionRect.height() ); if (tempRect.isValid() && region.contains(tempRect) ) { painter.drawTiledPixmap(tempRect, handler->pixmap(qubes_label, TitleBarTile, active, toolWindow) ); } } // leftSpacer if(borderLeft > 0 && sideHeight > 0) { tempRect.setCoords(r_x, titleEdgeBottomBottom+1, borderLeftRight, borderBottomTop-1); if (tempRect.isValid() && region.contains(tempRect) ) { painter.drawTiledPixmap(tempRect, handler->pixmap(qubes_label, BorderLeftTile, active, toolWindow) ); } } // rightSpacer if(borderRight > 0 && sideHeight > 0) { tempRect.setCoords(borderRightLeft, titleEdgeBottomBottom+1, r_x2, borderBottomTop-1); if (tempRect.isValid() && region.contains(tempRect) ) { painter.drawTiledPixmap(tempRect, handler->pixmap(qubes_label, BorderRightTile, active, toolWindow) ); } } // bottomSpacer if(borderBottom > 0) { int l = r_x; int r = r_x2; tempRect.setRect(r_x, borderBottomTop, borderLeft, borderBottom); if (tempRect.isValid() && region.contains(tempRect) ) { painter.drawTiledPixmap(tempRect, handler->pixmap(qubes_label, BorderBottomLeft, active, toolWindow) ); l = tempRect.right()+1; } tempRect.setRect(borderRightLeft, borderBottomTop, borderLeft, borderBottom); if (tempRect.isValid() && region.contains(tempRect) ) { painter.drawTiledPixmap(tempRect, handler->pixmap(qubes_label, BorderBottomRight, active, toolWindow) ); r = tempRect.left()-1; } tempRect.setCoords(l, borderBottomTop, r, r_y2); if (tempRect.isValid() && region.contains(tempRect) ) { painter.drawTiledPixmap(tempRect, handler->pixmap(qubes_label, BorderBottomTile, active, toolWindow) ); } } }