void QuartzButton::drawButton(QPainter *p) { // Never paint if the pixmaps have not been created if (!quartz_initialized) return; QColor c; if (isLeft() ) c = KDecoration::options()->color(KDecoration::ColorTitleBar, decoration()->isActive()).light(130); else c = KDecoration::options()->color(KDecoration::ColorTitleBlend, decoration()->isActive()); // Fill the button background with an appropriate color p->fillRect(0, 0, width(), height(), c ); // If we have a decoration bitmap, then draw that // otherwise we paint a menu button (with mini icon), or a onAllDesktops button. if( deco ) { int xOff = (width()-10)/2; int yOff = (height()-10)/2; p->setPen( Qt::black ); p->drawPixmap(isDown() ? xOff+2: xOff+1, isDown() ? yOff+2 : yOff+1, *deco); p->setPen( KDecoration::options()->color(KDecoration::ColorButtonBg, decoration()->isActive()).light(150) ); p->drawPixmap(isDown() ? xOff+1: xOff, isDown() ? yOff+1 : yOff, *deco); } else { QPixmap btnpix; int Offset = 0; if (type() == OnAllDesktopsButton) { if (isDown()) Offset = 1; // Select the right onAllDesktops button to paint if (decoration()->isActive()) btnpix = isOn() ? *pinDownPix : *pinUpPix; else btnpix = isOn() ? *ipinDownPix : *ipinUpPix; } else btnpix = decoration()->icon().pixmap( QIconSet::Small, QIconSet::Normal); // Shrink the miniIcon for tiny titlebars. if ( height() < 16) { QPixmap tmpPix; // Smooth scale the image tmpPix.convertFromImage( btnpix.convertToImage().smoothScale(height(), height())); p->drawPixmap( 0, 0, tmpPix ); } else { Offset += (height() - 16)/2; p->drawPixmap( Offset, Offset, btnpix ); } } }
void KisPaintingAssistantsManager::updateAction() { if (decoration()) { bool enabled = !decoration()->assistants().isEmpty(); m_toggleAssistant->setChecked(decoration()->visible()); m_toggleAssistant->setEnabled(enabled); m_togglePreview->setChecked(decoration()->outlineVisibility()); m_togglePreview->setEnabled(enabled); } else { m_toggleAssistant->setEnabled(false); } }
void KisMirrorManager::setView(QPointer<KisView> imageView) { if (m_imageView) { m_mirrorCanvas->disconnect(); } m_imageView = imageView; if (m_imageView && !decoration()) { m_imageView->canvasBase()->addDecoration(new KisMirrorAxis(m_imageView->viewManager()->resourceProvider(), m_imageView)); } if (m_imageView && decoration()) { connect(m_mirrorCanvas, SIGNAL(toggled(bool)), dynamic_cast<KisCanvasController*>(m_imageView->canvasController()), SLOT(mirrorCanvas(bool))); }
inline type_detail type_id_traits(Traits) { return type_detail( typeid(typename detail::unwrap_value_type<Traits>::type), decoration(detail::unwrap_decoration<Traits>::value) ); }
void QWaylandEglWindow::bindContentFBO() { if (decoration()) { contentFBO(); m_contentFBO->bind(); } }
QVariant Channel::data(int role) const { switch (role) { case DisplayRole: return display(); case DecorationRole: return decoration(); case NameRole: return name(); case NumberRole: return number(); case TypeRole: return type(); case LanguageRole: return language(); case UrlRole: return url(); case XmltvIdRole: return xmltvId(); case CategoriesRole: return categories(); case LogoRole: return logo(); case ProtectedRole: return passwordProtected(); default: return QVariant(); } }
void KWQTableDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const { painter->save(); drawBackground(painter, option, index); QStyleOptionViewItem opt = option; opt.decorationSize = QSize(0, 0); QPixmap decorationPixmap; QVariant decorationVariant = index.data(Qt::DecorationRole); if (!decorationVariant.isNull()) { decorationPixmap = decoration(option, decorationVariant); opt.decorationPosition = QStyleOptionViewItem::Right; opt.decorationAlignment = Qt::AlignRight | Qt::AlignVCenter; opt.decorationSize = QSize(decorationPixmap.width(), decorationPixmap.height()); drawDecoration(painter, opt, opt.rect, decorationPixmap); } opt.rect.adjust(0, 0, -opt.decorationSize.width(), 0); const KWQTableModel *model = static_cast<const KWQTableModel *>(index.model()); if (!model->checkBlanksSyntax(index.data(Qt::DisplayRole).toString())) { QPalette::ColorGroup cg = QPalette::Normal; opt.palette.setColor(cg, QPalette::Text, Qt::red); } opt.font = index.data(Qt::FontRole).value<QFont>(); drawDisplay(painter, opt, opt.rect, index.data(Qt::DisplayRole).toString()); if (!index.data(KWQTableModel::SoundRole).isNull()) painter->fillRect(option.rect.right() - 3, option.rect.top(), 4, 4, Qt::red); drawFocus(painter, opt, option.rect); painter->restore(); }
//___________________________________________________ void Button::reconfigure( void ) { // animation auto d = qobject_cast<Decoration*>(decoration()); if( d ) m_animation->setDuration( d->internalSettings()->buttonAnimationsDuration() ); }
docstring const InsetListings::buttonLabel(BufferView const & bv) const { // FIXME UNICODE if (decoration() == InsetLayout::CLASSIC) return isOpen(bv) ? _("Listing") : getNewLabel(_("Listing")); else return getNewLabel(_("Listing")); }
void IconDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { Q_ASSERT(index.isValid()); const QAbstractItemModel *model = index.model(); Q_ASSERT(model); QStyleOptionViewItem opt = option; // set font QVariant value = model->data(index, Qt::FontRole); if (value.isValid()) opt.font = qvariant_cast<QFont>(value); // set text alignment value = model->data(index, Qt::TextAlignmentRole); if (value.isValid()) opt.displayAlignment = QFlag(value.toInt()); // set text color value = model->data(index, Qt::TextColorRole); if (value.isValid() && qvariant_cast<QColor>(value).isValid()) opt.palette.setColor(QPalette::Text, qvariant_cast<QColor>(value)); // do layout value = model->data(index, Qt::DecorationRole); QPixmap pixmap = decoration(opt, value); QRect pixmapRect = pixmap.rect(); QFontMetrics fontMetrics(opt.font); QString text = model->data(index, Qt::DisplayRole).toString(); QRect textRect(0, 0, 0,0); //QRect textRect(0, 0, fontMetrics.width(text), fontMetrics.lineSpacing()); value = model->data(index, Qt::CheckStateRole); QRect checkRect = check(opt, opt.rect, value); Qt::CheckState checkState = static_cast<Qt::CheckState>(value.toInt()); doLayout(opt, &checkRect, &pixmapRect, &textRect, false); // draw the background color if (option.showDecorationSelected && (option.state & QStyle::State_Selected)) { QPalette::ColorGroup cg = option.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled; painter->fillRect(option.rect, option.palette.brush(cg, QPalette::Highlight)); } else { value = model->data(index, Qt::BackgroundColorRole); if (value.isValid() && qvariant_cast<QColor>(value).isValid()) painter->fillRect(option.rect, qvariant_cast<QColor>(value)); } // draw the item drawCheck(painter, opt, checkRect, checkState); drawDecoration(painter, opt, pixmapRect, pixmap); // drawDisplay(painter, opt, textRect, text); drawFocus(painter, opt, textRect); }
void K3b::DeviceDelegate::paint( QPainter* painter, const QStyleOptionViewItem& optionOrig, const QModelIndex& index ) const { if ( index.data( K3b::DeviceModel::IsDevice ).toBool() ) { painter->save(); painter->setRenderHint(QPainter::Antialiasing); // HACK: we erase the branch QStyleOptionViewItemV4 option( optionOrig ); option.rect.setLeft( 0 ); painter->fillRect( option.rect, option.palette.base() ); QStyle* style = QApplication::style(); const FontsAndMetrics fam( option.font ); const QPalette::ColorRole textRole = (option.state & QStyle::State_Selected) ? QPalette::HighlightedText : QPalette::Text; const QRect itemRect( option.rect.left() + fam.margin, option.rect.top() + fam.margin, option.rect.width() - 2*fam.margin, option.rect.height() - 2*fam.margin ); const QSize iconSize( itemRect.height(), itemRect.height() ); const QSize mediumSize( itemRect.width() - iconSize.width() - fam.margin, itemRect.height() - fam.spacing - fam.deviceFontM.height() ); const QSize devicemSize( itemRect.width() - iconSize.width() - fam.margin, itemRect.height() - fam.spacing - fam.mediumFontM.height() ); const QRect iconRect = style->alignedRect( option.direction, Qt::AlignLeft | Qt::AlignVCenter, iconSize, itemRect ); const QRect mediumRect = style->alignedRect( option.direction, Qt::AlignRight | Qt::AlignTop, mediumSize, itemRect ); const QRect deviceRect = style->alignedRect( option.direction, Qt::AlignRight | Qt::AlignBottom, devicemSize, itemRect ); // draw background style->drawPrimitive( QStyle::PE_PanelItemViewItem, &option, painter ); // draw decoration QPixmap pixmap = decoration( option, index, iconSize ); painter->drawPixmap( iconRect, pixmap ); // draw medium text painter->setFont( fam.mediumFont ); QString text = index.data( Qt::DisplayRole ).toString(); style->drawItemText( painter, mediumRect, option.displayAlignment, option.palette, option.state & QStyle::State_Enabled, fam.mediumFontM.elidedText( text, option.textElideMode, mediumRect.width() ), textRole ); // draw fixed device text painter->setFont( fam.deviceFont ); text = index.data( K3b::DeviceModel::Vendor ).toString() + " - " + index.data( K3b::DeviceModel::Description ).toString(); style->drawItemText( painter, deviceRect, option.displayAlignment, option.palette, option.state & QStyle::State_Enabled, fam.deviceFontM.elidedText( text, option.textElideMode, deviceRect.width() ), textRole ); painter->restore(); } else { KFileItemDelegate::paint( painter, optionOrig, index ); } }
void LaptopButton::drawButton(QPainter *p) { bool smallBtn = width() == btnWidth1; if(btnPix1){ if(decoration()->isActive()){ if(isDown()) p->drawPixmap(0, 0, smallBtn ? *btnDownPix1 : *btnDownPix2); else p->drawPixmap(0, 0, smallBtn ? *btnPix1 : *btnPix2); } else{ if(isDown()) p->drawPixmap(0, 0, smallBtn ? *iBtnDownPix1 : *iBtnDownPix2); else p->drawPixmap(0, 0, smallBtn ? *iBtnPix1 : *iBtnPix2); } } else{ QPalette g = options()->palette(KDecoration::ColorButtonBg, decoration()->isActive()); g.setCurrentColorGroup( QPalette::Active ); int w = width(); int h = height(); p->fillRect(1, 1, w-2, h-2, isDown() ? g.color(QPalette::Mid) : g.color(QPalette::Button) ); p->setPen(isDown() ? g.color( QPalette::Dark ) : g.color( QPalette::Light )); p->drawLine(0, 0, w-1, 0); p->drawLine(0, 0, 0, w-1); p->setPen(isDown() ? g.color( QPalette::Light ) : g.color( QPalette::Dark )); p->drawLine(w-1, 0, w-1, h-1); p->drawLine(0, h-1, w-1, h-1); } QPainterPath path; path.addRegion( deco ); QPoint offset( (width()-8)/2, (height()-8)/2 ); if( isDown() ) offset += QPoint( 1, 1 ); p->translate( offset ); p->setPen( Qt::NoPen ); p->setBrush( btnForeground ); p->drawPath( path ); }
GLuint QWaylandEglWindow::contentFBO() const { if (!decoration()) return 0; if (m_resize || !m_contentFBO) { QOpenGLFramebufferObject *old = m_contentFBO; m_contentFBO = new QOpenGLFramebufferObject(geometry().width(), geometry().height(), QOpenGLFramebufferObject::CombinedDepthStencil); delete old; m_resize = false; } return m_contentFBO->handle(); }
void TasksViewDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const { // TODO use doLayout const QRect cbRect = checkBoxRect(option, Qt::Checked); int firstLineHeight = qMax(cbRect.height(), option.fontMetrics.height()); const QVariant decorationVariant = index.data(Qt::DecorationRole); const QPixmap decorationPixmap = decoration(option, decorationVariant); const QString runningTime = index.data(TasksViewRole_RunningTime).toString(); const int left = decorationPixmap.width() + option.fontMetrics.width(runningTime); QRect r = option.rect.translated(left + 5, 0); r.setRight(cbRect.left()); r.setTop(r.top() + firstLineHeight); editor->setGeometry(r); }
void QItemDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const { if (!editor) return; Q_ASSERT(index.isValid()); QPixmap pixmap = decoration(option, index.data(Qt::DecorationRole)); QString text = QItemDelegatePrivate::replaceNewLine(index.data(Qt::DisplayRole).toString()); QRect pixmapRect = QRect(QPoint(0, 0), option.decorationSize).intersected(pixmap.rect()); QRect textRect = textRectangle(0, option.rect, option.font, text); QRect checkRect = check(option, textRect, index.data(Qt::CheckStateRole)); QStyleOptionViewItem opt = option; opt.showDecorationSelected = true; // let the editor take up all available space doLayout(opt, &checkRect, &pixmapRect, &textRect, false); editor->setGeometry(textRect); }
//_______________________________________________ QColor Button::buttonDetailColor(const QPalette &palette) const { auto d( qobject_cast<Decoration*>( decoration().data() ) ); if( d->isAnimated() ) { return KColorUtils::mix( buttonDetailColor( palette, false ), buttonDetailColor( palette, true ), d->opacity() ); } else { return buttonDetailColor( palette, isActive()); } }
QVariant XmltvCrewMember::data(int role) const { switch (role) { case DisplayRole: return display(); case DecorationRole: return decoration(); case NameRole: return name(); case TypeRole: return type(); case ProgrammeRole: return programme(); case StartRole: return start(); default: return QVariant(); } }
void KisPaintingAssistantsManager::setView(QPointer<KisView> imageView) { if (m_imageView) { m_toggleAssistant->disconnect(); if (decoration()) { decoration()->disconnect(this); } } m_imageView = imageView; if (m_imageView && !decoration()) { KisPaintingAssistantsDecoration* deco = new KisPaintingAssistantsDecoration(m_imageView); m_imageView->canvasBase()->addDecoration(deco); } if (m_imageView && decoration()) { connect(m_toggleAssistant, SIGNAL(triggered()), decoration(), SLOT(toggleAssistantVisible())); connect(m_togglePreview, SIGNAL(triggered()), decoration(), SLOT(toggleOutlineVisible())); connect(decoration(), SIGNAL(assistantChanged()), SLOT(updateAction())); } updateAction(); }
//___________________________________________________ bool Button::isActive( void ) const { return decoration().data()->client().data()->isActive(); }
void KeyWidget::paintEvent(QPaintEvent*){ const QColor bgColor(68, 64, 64); const QColor keyColor(112, 110, 110); const QColor highlightColor(136, 176, 240); const QColor highlightAnimColor(136, 200, 240); const QColor animColor(112, 200, 110); uint count = keyMap.count(); // Determine which keys to highlight QBitArray highlight; switch(mouseDownMode){ case SET: highlight = newSelection; break; case ADD: highlight = selection | newSelection; break; case SUBTRACT: highlight = selection & ~newSelection; break; case TOGGLE: highlight = selection ^ newSelection; break; default: highlight = selection; } QPainter painter(this); #if QT_VERSION >= QT_VERSION_CHECK(5, 3, 0) int ratio = painter.device()->devicePixelRatio(); #else int ratio = 1; #endif float xScale = (float)width() / (keyMap.width() + KEY_SIZE) * ratio; float yScale = (float)height() / (keyMap.height() + KEY_SIZE) * ratio; // Draw background painter.setPen(Qt::NoPen); painter.setRenderHint(QPainter::Antialiasing, true); painter.setBrush(QBrush(bgColor)); painter.drawRect(0, 0, width(), height()); // Draw mouse highlight (if any) if(mouseDownMode != NONE && (mouseDownX != mouseCurrentX || mouseDownY != mouseCurrentY)){ int x1 = (mouseDownX > mouseCurrentX) ? mouseCurrentX : mouseDownX; int x2 = (mouseDownX > mouseCurrentX) ? mouseDownX : mouseCurrentX; int y1 = (mouseDownY > mouseCurrentY) ? mouseCurrentY : mouseDownY; int y2 = (mouseDownY > mouseCurrentY) ? mouseDownY : mouseCurrentY; painter.setPen(QPen(highlightColor, 0.5)); QColor bColor = highlightColor; bColor.setAlpha(128); painter.setBrush(QBrush(bColor)); painter.drawRect(x1, y1, x2 - x1, y2 - y1); } // Draw key backgrounds on a separate pixmap so that a drop shadow can be applied to them. int wWidth = width(), wHeight = height(); KeyMap::Model model = keyMap.model(); QPixmap keyBG(wWidth * ratio, wHeight * ratio); keyBG.fill(QColor(0, 0, 0, 0)); QPainter bgPainter(&keyBG); bgPainter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing); bgPainter.setPen(Qt::NoPen); for(uint i = 0; i < count; i++){ const KeyPos& key = *keyMap.key(i); float x = key.x + 6.f - key.width / 2.f + 1.f; float y = key.y + 6.f - key.height / 2.f + 1.f; float w = key.width - 2.f; float h = key.height - 2.f; // In RGB mode, ignore volume wheel on K70/K95 if(model != KeyMap::K65 && _rgbMode && (!strcmp(key.name, "volup") || !strcmp(key.name, "voldn"))) continue; // Set color based on key highlight if(highlight.testBit(i)){ if(animation.testBit(i)) bgPainter.setBrush(QBrush(highlightAnimColor)); else bgPainter.setBrush(QBrush(highlightColor)); } else if(animation.testBit(i)) bgPainter.setBrush(QBrush(animColor)); else bgPainter.setBrush(QBrush(keyColor)); if(!strcmp(key.name, "mr") || !strcmp(key.name, "m1") || !strcmp(key.name, "m2") || !strcmp(key.name, "m3") || !strcmp(key.name, "light") || !strcmp(key.name, "lock") || (model == KeyMap::K65 && !strcmp(key.name, "mute"))){ // Switch keys are circular x += w / 8.f; y += h / 8.f; w *= 0.75f; h *= 0.75f; bgPainter.drawEllipse(QRectF(x * xScale, y * yScale, w * xScale, h * yScale)); } else { if(!strcmp(key.name, "enter")){ if(key.height == 24){ // ISO enter key isn't rectangular y = key.y + 1.f; h = 10.f; bgPainter.drawRect(QRectF((x + w - 13.f) * xScale, y * yScale, 13.f * xScale, 22.f * yScale)); } else { // US enter key isn't perfectly centered, needs an extra pixel on the left to appear correctly x -= 1.f; w += 1.f; } } else if(!strcmp(key.name, "rshift") || !strcmp(key.name, "stop")){ // A few other keys also need extra pixels x -= 1.f; w += 1.f; } else if(!strcmp(key.name, "caps") || !strcmp(key.name, "lshift") || !strcmp(key.name, "next")){ w += 1.f; } bgPainter.drawRect(QRectF(x * xScale, y * yScale, w * xScale, h * yScale)); } } // Render the key decorations (RGB -> light circles, binding -> key names) on yet another layer QPixmap decoration(wWidth * ratio, wHeight * ratio); decoration.fill(QColor(0, 0, 0, 0)); QPainter decPainter(&decoration); decPainter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing); if(_rgbMode){ // Draw key colors (RGB mode) decPainter.setPen(QPen(QColor(255, 255, 255), 1.5)); for(uint i = 0; i < count; i++){ const KeyPos& key = *keyMap.key(i); if(model != KeyMap::K65 && _rgbMode && (!strcmp(key.name, "volup") || !strcmp(key.name, "voldn"))) continue; float x = key.x + 6.f - 1.8f; float y = key.y + 6.f - 1.8f; float w = 3.6f; float h = 3.6f; decPainter.setBrush(QBrush(_colorMap[key.name])); decPainter.drawEllipse(QRectF(x * xScale, y * yScale, w * xScale, h * yScale)); } } else { // Draw key names decPainter.setBrush(Qt::NoBrush); QFont font = painter.font(); font.setBold(true); font.setPixelSize(5.25f * yScale); QFont font0 = font; for(uint i = 0; i < count; i++){ const KeyPos& key = *keyMap.key(i); float x = key.x + 6.f - key.width / 2.f + 1.f; float y = key.y + 6.f - key.height / 2.f; float w = key.width - 2.f; float h = key.height; // Print the key's friendly name (with some exceptions) QString keyName = KbBind::globalRemap(key.name); QString name = key.friendlyName(false); name = name.split(" ").last(); struct _names { const char* keyName, *displayName; }; _names names[] = { {"light", "☼"}, {"lock", "☒"}, {"mute", "◖⊘"}, {"volup", keyMap.model() == KeyMap::K65 ? "◖))" : "▲"}, {"voldn", keyMap.model() == KeyMap::K65 ? "◖)" : "▼"}, {"prtscn", "PrtScn\nSysRq"}, {"scroll", "Scroll\nLock"}, {"pause", "Pause\nBreak"}, {"stop", "▪"}, {"prev", "|◂◂"}, {"play", "▸||"}, {"next", "▸▸|"}, {"pgup", "Page\nUp"}, {"pgdn", "Page\nDown"}, {"numlock", "Num\nLock"}, {"caps", "Caps"}, {"lshift", "Shift"}, {"rshift", "Shift"}, #ifdef Q_OS_MACX {"lctrl", "⌃"}, {"rctrl", "⌃"}, {"lwin", "⌘"}, {"rwin", "⌘"}, {"lalt", "⌥"}, {"ralt", "⌥"}, #else {"lctrl", "Ctrl"}, {"rctrl", "Ctrl"}, {"lwin", "❖"}, {"rwin", "❖"}, {"lalt", "Alt"}, {"ralt", "Alt"}, #endif {"rmenu", "▤"}, {"up", "▲"}, {"left", "◀"}, {"down", "▼"}, {"right", "▶"} }; for(uint k = 0; k < sizeof(names) / sizeof(_names); k++){ if(keyName == names[k].keyName){ name = names[k].displayName; break; } } if(keyName == "mr" || keyName == "m1" || keyName == "m2" || keyName == "m3" || keyName == "up" || keyName == "down" || keyName == "left" || keyName == "right") // Use a smaller size for MR, M1 - M3, and arrow keys font.setPixelSize(font.pixelSize() * 0.75); else if(keyName == "end") // Use a smaller size for "End" to match everything else in that area font.setPixelSize(font.pixelSize() * 0.65); else if(keyName == "light" #ifndef Q_OS_MACX || keyName == "lwin" || keyName == "rwin" #endif ) // Use a larger font size for Win and Brightness to compensate for the unicode symbols looking smaller (Linux only) font.setPixelSize(font.pixelSize() * 1.3); // Determine the appropriate size to draw the text at decPainter.setFont(font); QRectF rect(x * xScale, y * yScale - 1, w * xScale, h * yScale); int flags = Qt::AlignHCenter | Qt::AlignVCenter | Qt::TextWordWrap; QRectF bounds = decPainter.boundingRect(rect, flags, name); while((bounds.height() >= rect.height() - 8. || bounds.width() >= rect.width() - 2.) && font.pixelSize() >= 5){ // Scale font size down until it fits inside the key font.setPixelSize(font.pixelSize() - 2); decPainter.setFont(font); bounds = decPainter.boundingRect(rect, flags, name); } // Pick color based on key function QString bind = _bindMap.value(key.name); QString def = KbBind::defaultAction(key.name); if(bind.isEmpty()) // Unbound - red decPainter.setPen(QColor(255, 136, 136)); else if(KbBind::isProgram(bind)) // Custom program - orange decPainter.setPen(QColor(255, 224, 192)); else if(KbBind::isSpecial(bind) && (bind == def || !KbBind::isSpecial(def))) // Special function - blue (only if not mapped to a different function - if a special function is remapped, color it yellow) decPainter.setPen(QColor(128, 224, 255)); else if(KbBind::isMedia(bind) && (bind == def || !KbBind::isMedia(def))) // Media key - green decPainter.setPen(QColor(160, 255, 168)); else if(bind == def) // Standard key - white decPainter.setPen(QColor(255, 255, 255)); else // Remapped key - yellow decPainter.setPen(QColor(255, 248, 128)); decPainter.drawText(rect, flags, name); font = font0; } } // Create drop shadow effects QGraphicsDropShadowEffect* bgEffect = new QGraphicsDropShadowEffect; // Have to use "new", creating these on the stack causes a crash... bgEffect->setBlurRadius(2.); bgEffect->setColor(QColor(0, 0, 0, 32)); bgEffect->setOffset(0, 1); QGraphicsDropShadowEffect* decEffect = new QGraphicsDropShadowEffect; decEffect->setBlurRadius(4.); decEffect->setColor(QColor(0, 0, 0, 104)); decEffect->setOffset(0, 1); // Apply them to the pixmaps QGraphicsPixmapItem* bgItem = new QGraphicsPixmapItem(keyBG); bgItem->setGraphicsEffect(bgEffect); QGraphicsPixmapItem* decItem = new QGraphicsPixmapItem(decoration); decItem->setGraphicsEffect(decEffect); // Render everything QGraphicsScene* scene = new QGraphicsScene; scene->addItem(bgItem); scene->addItem(decItem); // It has to be rendered onto yet another pixmap or else DPI scaling will look terrible... QPixmap final(wWidth * ratio, wHeight * ratio); final.fill(QColor(0, 0, 0, 0));
/*! Renders the delegate using the given \a painter and style \a option for the item specified by \a index. When reimplementing this function in a subclass, you should update the area held by the option's \l{QStyleOption::rect}{rect} variable, using the option's \l{QStyleOption::state}{state} variable to determine the state of the item to be displayed, and adjust the way it is painted accordingly. For example, a selected item may need to be displayed differently to unselected items, as shown in the following code: \snippet examples/itemviews/pixelator/pixeldelegate.cpp 2 \dots After painting, you should ensure that the painter is returned to its the state it was supplied in when this function was called. For example, it may be useful to call QPainter::save() before painting and QPainter::restore() afterwards. \sa QStyle::State */ void QItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { Q_D(const QItemDelegate); Q_ASSERT(index.isValid()); QStyleOptionViewItemV4 opt = setOptions(index, option); const QStyleOptionViewItemV2 *v2 = qstyleoption_cast<const QStyleOptionViewItemV2 *>(&option); opt.features = v2 ? v2->features : QStyleOptionViewItemV2::ViewItemFeatures(QStyleOptionViewItemV2::None); const QStyleOptionViewItemV3 *v3 = qstyleoption_cast<const QStyleOptionViewItemV3 *>(&option); opt.locale = v3 ? v3->locale : QLocale(); opt.widget = v3 ? v3->widget : 0; // prepare painter->save(); if (d->clipPainting) painter->setClipRect(opt.rect); // get the data and the rectangles QVariant value; QPixmap pixmap; QRect decorationRect; value = index.data(Qt::DecorationRole); if (value.isValid()) { // ### we need the pixmap to call the virtual function pixmap = decoration(opt, value); if (value.type() == QVariant::Icon) { d->tmp.icon = qvariant_cast<QIcon>(value); d->tmp.mode = d->iconMode(option.state); d->tmp.state = d->iconState(option.state); const QSize size = d->tmp.icon.actualSize(option.decorationSize, d->tmp.mode, d->tmp.state); decorationRect = QRect(QPoint(0, 0), size); } else { d->tmp.icon = QIcon(); decorationRect = QRect(QPoint(0, 0), pixmap.size()); } } else { d->tmp.icon = QIcon(); decorationRect = QRect(); } QString text; QRect displayRect; value = index.data(Qt::DisplayRole); if (value.isValid() && !value.isNull()) { text = QItemDelegatePrivate::valueToText(value, opt); displayRect = textRectangle(painter, d->textLayoutBounds(opt), opt.font, text); } QRect checkRect; Qt::CheckState checkState = Qt::Unchecked; value = index.data(Qt::CheckStateRole); if (value.isValid()) { checkState = static_cast<Qt::CheckState>(value.toInt()); checkRect = check(opt, opt.rect, value); } // do the layout doLayout(opt, &checkRect, &decorationRect, &displayRect, false); // draw the item drawBackground(painter, opt, index); drawCheck(painter, opt, checkRect, checkState); drawDecoration(painter, opt, decorationRect, pixmap); drawDisplay(painter, opt, displayRect, text); drawFocus(painter, opt, displayRect); // done painter->restore(); }
int main() { // 1) Default constructors create empty intervals std::cout << I<double>() << std::endl; std::cout << DI<double>() << std::endl << std::endl; // 1.1) The same could be achieved by static functions std::cout << I<double>::empty() << std::endl; std::cout << DI<double>::empty() << std::endl << std::endl; // 2) There are also static functions to create entire intervals std::cout << I<double>::entire() << std::endl; std::cout << DI<double>::entire() << std::endl << std::endl; // 2.1) The same can be achieved by using the constructor with two parameters std::cout << I<double>(-INF, INF) << std::endl; std::cout << DI<double>(-INF, INF) << std::endl << std::endl; // 3) The parameter constructor can be used to create all kinds of nonempty intervals std::cout << I<double>(-3.0, INF) << std::endl; std::cout << DI<double>(5.0, 27.7) << std::endl << std::endl; // 3.1) For decorated intervals it is also possible to specify a decoration std::cout << DI<double>(5.0, 27.7, p1788::decoration::decoration::def) << std::endl << std::endl; // 3.2) But take care: the parameters are number literals which are computed and rounded by the compiler // Hence the following interval is not an enclosure of 1/10 // Note: This is also a reasopn why a constructor with one floating point parameter is not supported std::cout << I<double>(0.1, 0.1) << std::endl << std::endl; // 4) To ensure enclosure you can use the string constructor // Notice the difference in the output compared to the constructor above std::cout << I<double>("[0.1, 0.1]") << std::endl; std::cout << I<double>("[0.1, 1/10]") << std::endl; std::cout << DI<double>("[0.1]_trv") << std::endl; std::cout << I<double>("[1/10]_dac") << std::endl; std::cout << DI<double>("0.1000000?") << std::endl << std::endl; // 5) Additionally it is possible to convert interval types // Auxiliary intervals I<double> i("[0.1, 0.1]"); DI<double> di("[0.1, 1.1]_dac"); std::cout << p1788::io::precision(10); // increase the precision of the output to see a difference // 5.1) Different bound types std::cout << i << std::endl; std::cout << I<float>( i ) << std::endl; std::cout << di << std::endl; std::cout << DI<float>( di ) << std::endl << std::endl; // 5.2) Bare interval <-> decorated interval std::cout << I<double>( di ) << std::endl; std::cout << I<float>( di ) << std::endl; std::cout << DI<double>( i ) << std::endl; std::cout << DI<float>( i ) << std::endl << std::endl; // 5.4) And the same for casts std::cout << static_cast< I<float> >( i ) << std::endl; std::cout << static_cast< I<double> >( di ) << std::endl; std::cout << static_cast< DI<double> >( i ) << std::endl << std::endl; // 6) Set a decoration std::cout << DI<double>( i, p1788::decoration::decoration::def ) << std::endl; std::cout << DI<float>( i, p1788::decoration::decoration::trv ) << std::endl << std::endl; // 6.1) And get a decoration std::cout << decoration( di ) << std::endl; // function std::cout << DI<double>::decoration( di ) << std::endl << std::endl; // static // 7) In case of invalid input an empty interval (bare interval constructor) // or a NaI (decorated interval constructor) will be created std::cout << I<double>(5.0,0.0) << std::endl; std::cout << I<double>("foo") << std::endl; std::cout << DI<double>("[1.0,inf]_com") << std::endl << std::endl; // 7.1) and of course std::cout << DI<double>::nai() << std::endl; return 0; }
void KeyWidget::paintEvent(QPaintEvent*){ const QColor bgColor(68, 64, 64); const QColor keyColor(112, 110, 110); const QColor sniperColor(130, 90, 90); const QColor highlightColor(136, 176, 240); const QColor highlightAnimColor(136, 200, 240); const QColor animColor(112, 200, 110); // Determine which keys to highlight QBitArray highlight; switch(mouseDownMode){ case SET: highlight = newSelection; break; case ADD: highlight = selection | newSelection; break; case SUBTRACT: highlight = selection & ~newSelection; break; case TOGGLE: highlight = selection ^ newSelection; break; default: highlight = selection; } QPainter painter(this); #if QT_VERSION >= QT_VERSION_CHECK(5, 3, 0) int ratio = painter.device()->devicePixelRatio(); #else int ratio = 1; #endif int wWidth = width(), wHeight = height(); KeyMap::Model model = keyMap.model(); float scale, offX, offY; drawInfo(scale, offX, offY); // Draw background painter.setPen(Qt::NoPen); painter.setRenderHint(QPainter::Antialiasing, true); if(model == KeyMap::M65){ // M65: Draw overlay if(!m65Overlay) m65Overlay = new QImage(":/img/overlay_m65.png"); const QImage& overlay = *m65Overlay; painter.setBrush(palette().brush(QPalette::Window)); painter.drawRect(0, 0, width(), height()); float oXScale = scale / 9.f, oYScale = scale / 9.f; // The overlay has a resolution of 9px per keymap unit float x = (2.f + offX) * scale, y = (-2.f + offY) * scale; // It is positioned at (2, -2) int w = overlay.width() * oXScale, h = overlay.height() * oYScale; // We need to transform the image with QImage::scaled() because painter.drawImage() will butcher it, even with smoothing enabled // However, the width/height need to be rounded to integers int iW = round(w), iH = round(h); painter.drawImage(QRectF(x - (iW - w) / 2.f, y - (iH - h) / 2.f, iW, iH), overlay.scaled(iW, iH, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); } else { // Otherwise, draw a solid background painter.setBrush(QBrush(bgColor)); painter.drawRect(0, 0, width(), height()); } // Draw mouse highlight (if any) if(mouseDownMode != NONE && (mouseDownX != mouseCurrentX || mouseDownY != mouseCurrentY)){ int x1 = (mouseDownX > mouseCurrentX) ? mouseCurrentX : mouseDownX; int x2 = (mouseDownX > mouseCurrentX) ? mouseDownX : mouseCurrentX; int y1 = (mouseDownY > mouseCurrentY) ? mouseCurrentY : mouseDownY; int y2 = (mouseDownY > mouseCurrentY) ? mouseDownY : mouseCurrentY; painter.setPen(QPen(highlightColor, 0.5)); QColor bColor = highlightColor; bColor.setAlpha(128); painter.setBrush(QBrush(bColor)); painter.drawRect(x1, y1, x2 - x1, y2 - y1); } // Draw key backgrounds on a separate pixmap so that a drop shadow can be applied to them. QPixmap keyBG(wWidth * ratio, wHeight * ratio); keyBG.fill(QColor(0, 0, 0, 0)); QPainter bgPainter(&keyBG); bgPainter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing); bgPainter.setPen(Qt::NoPen); QHashIterator<QString, Key> k(keyMap); uint i = -1; while(k.hasNext()){ k.next(); i++; const Key& key = k.value(); float x = key.x + offX - key.width / 2.f + 1.f; float y = key.y + offY - key.height / 2.f + 1.f; float w = key.width - 2.f; float h = key.height - 2.f; // In RGB mode, ignore keys without LEDs if((_rgbMode && !key.hasLed) || (!_rgbMode && !key.hasScan)) continue; // Set color based on key highlight bgPainter.setOpacity(1.); if(highlight.testBit(i)){ if(animation.testBit(i)) bgPainter.setBrush(QBrush(highlightAnimColor)); else bgPainter.setBrush(QBrush(highlightColor)); } else if(animation.testBit(i)){ bgPainter.setBrush(QBrush(animColor)); } else { if(!strcmp(key.name, "sniper")) // Sniper key uses a reddish base color instead of the usual grey bgPainter.setBrush(QBrush(sniperColor)); else { bgPainter.setBrush(QBrush(keyColor)); if(KeyMap::isMouse(model)) bgPainter.setOpacity(0.7); } } if(!strcmp(key.name, "mr") || !strcmp(key.name, "m1") || !strcmp(key.name, "m2") || !strcmp(key.name, "m3") || !strcmp(key.name, "light") || !strcmp(key.name, "lock") || (model == KeyMap::K65 && !strcmp(key.name, "mute"))){ // Switch keys are circular x += w / 8.f; y += h / 8.f; w *= 0.75f; h *= 0.75f; bgPainter.drawEllipse(QRectF(x * scale, y * scale, w * scale, h * scale)); } else { if(!strcmp(key.name, "enter")){ if(key.height == 24){ // ISO enter key isn't rectangular y = key.y + 1.f; h = 10.f; bgPainter.drawRect(QRectF((x + w - 13.f) * scale, y * scale, 13.f * scale, 22.f * scale)); } else { // US enter key isn't perfectly centered, needs an extra pixel on the left to appear correctly x -= 1.f; w += 1.f; } } else if(!strcmp(key.name, "rshift") || !strcmp(key.name, "stop")){ // A few other keys also need extra pixels x -= 1.f; w += 1.f; } else if(!strcmp(key.name, "caps") || !strcmp(key.name, "lshift") || !strcmp(key.name, "next")){ w += 1.f; } bgPainter.drawRect(QRectF(x * scale, y * scale, w * scale, h * scale)); } } // Render the key decorations (RGB -> light circles, binding -> key names) on yet another layer QPixmap decoration(wWidth * ratio, wHeight * ratio); decoration.fill(QColor(0, 0, 0, 0)); QPainter decPainter(&decoration); decPainter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing); if(_rgbMode){ // Draw key colors (RGB mode) decPainter.setPen(QPen(QColor(255, 255, 255), 1.5)); QHashIterator<QString, Key> k(keyMap); uint i = -1; while(k.hasNext()){ k.next(); i++; const Key& key = k.value(); if(!key.hasLed) continue; float x = key.x + offX - 1.8f; float y = key.y + offY - 1.8f; float w = 3.6f; float h = 3.6f; if(_displayColorMap.contains(key.name)) decPainter.setBrush(QBrush(_displayColorMap.value(key.name))); else decPainter.setBrush(QBrush(_colorMap.value(key.name))); decPainter.drawEllipse(QRectF(x * scale, y * scale, w * scale, h * scale)); } } else { // Draw key names decPainter.setBrush(Qt::NoBrush); QFont font = painter.font(); font.setBold(true); font.setPixelSize(5.25f * scale); QFont font0 = font; QHashIterator<QString, Key> k(keyMap); uint i = -1; while(k.hasNext()){ k.next(); i++; const Key& key = k.value(); if(!key.hasScan) continue; float x = key.x + offX - key.width / 2.f + 1.f; float y = key.y + offY - key.height / 2.f; float w = key.width - 2.f; float h = key.height; // Print the key's friendly name (with some exceptions) QString keyName = KbBind::globalRemap(key.name); QString name = key.friendlyName(false); name = name.split(" ").last(); struct { const char* keyName, *displayName; } names[] = { {"light", "☼"}, {"lock", "☒"}, {"mute", "◖⊘"}, {"volup", keyMap.model() == KeyMap::K65 ? "◖))" : "▲"}, {"voldn", keyMap.model() == KeyMap::K65 ? "◖)" : "▼"}, {"prtscn", "PrtScn\nSysRq"}, {"scroll", "Scroll\nLock"}, {"pause", "Pause\nBreak"}, {"stop", "▪"}, {"prev", "|◂◂"}, {"play", "▸||"}, {"next", "▸▸|"}, {"pgup", "Page\nUp"}, {"pgdn", "Page\nDown"}, {"numlock", "Num\nLock"}, {"caps", "Caps"}, {"lshift", "Shift"}, {"rshift", "Shift"}, #ifdef Q_OS_MACX {"lctrl", "⌃"}, {"rctrl", "⌃"}, {"lwin", "⌘"}, {"rwin", "⌘"}, {"lalt", "⌥"}, {"ralt", "⌥"}, #else {"lctrl", "Ctrl"}, {"rctrl", "Ctrl"}, {"lwin", "❖"}, {"rwin", "❖"}, {"lalt", "Alt"}, {"ralt", "Alt"}, #endif {"rmenu", "▤"}, {"up", "▲"}, {"left", "◀"}, {"down", "▼"}, {"right", "▶"}, {"mouse1", ""}, {"mouse2", ""}, {"mouse3", "∙"}, {"dpiup", "▲"}, {"dpidn", "▼"}, {"wheelup", "▲"}, {"wheeldn", "▼"}, {"dpi", "◉"}, {"mouse5", "▲"}, {"mouse4", "▼"}, {"sniper", "⊕"} }; for(uint k = 0; k < sizeof(names) / sizeof(names[0]); k++){ if(keyName == names[k].keyName){ name = names[k].displayName; break; } } if(keyName == "mr" || keyName == "m1" || keyName == "m2" || keyName == "m3" || keyName == "up" || keyName == "down" || keyName == "left" || keyName == "right") // Use a smaller size for MR, M1 - M3, and arrow keys font.setPixelSize(font.pixelSize() * 0.75); else if(keyName == "end") // Use a smaller size for "End" to match everything else in that area font.setPixelSize(font.pixelSize() * 0.65); else if(keyName == "light" #ifndef Q_OS_MACX || keyName == "lwin" || keyName == "rwin" #endif ) // Use a larger font size for Super (Linux only) and Brightness to compensate for the unicode symbols looking smaller font.setPixelSize(font.pixelSize() * 1.3); // Determine the appropriate size to draw the text at decPainter.setFont(font); QRectF rect(x * scale, y * scale - 1, w * scale, h * scale); int flags = Qt::AlignHCenter | Qt::AlignVCenter | Qt::TextWordWrap; QRectF bounds = decPainter.boundingRect(rect, flags, name); while((bounds.height() >= rect.height() - 8. || bounds.width() >= rect.width() - 2.) && font.pixelSize() >= 5){ // Scale font size down until it fits inside the key font.setPixelSize(font.pixelSize() - 2); decPainter.setFont(font); bounds = decPainter.boundingRect(rect, flags, name); } // Pick color based on key function QString bind = _bindMap.value(key.name); QString def = KbBind::defaultAction(key.name); if(bind.isEmpty()) // Unbound - red decPainter.setPen(QColor(255, 136, 136)); else if(KeyAction(bind).isProgram()) // Custom program - orange decPainter.setPen(QColor(255, 224, 192)); else if(KeyAction(bind).isSpecial() && (bind == def || !KeyAction(def).isSpecial())) // Special function - blue (only if not mapped to a different function - if a special function is remapped, color it yellow) decPainter.setPen(QColor(128, 224, 255)); else if(KeyAction(bind).isMedia() && (bind == def || !KeyAction(def).isMedia())) // Media key - green decPainter.setPen(QColor(160, 255, 168)); else if(bind == def) // Standard key - white decPainter.setPen(QColor(255, 255, 255)); else // Remapped key - yellow decPainter.setPen(QColor(255, 248, 128)); decPainter.drawText(rect, flags, name); font = font0; } } // Create drop shadow effects QGraphicsDropShadowEffect* bgEffect = new QGraphicsDropShadowEffect; // Have to use "new", creating these on the stack causes a crash... bgEffect->setBlurRadius(2.); bgEffect->setColor(QColor(0, 0, 0, 32)); bgEffect->setOffset(0, 1); QGraphicsDropShadowEffect* decEffect = new QGraphicsDropShadowEffect; decEffect->setBlurRadius(4.); decEffect->setColor(QColor(0, 0, 0, 104)); decEffect->setOffset(0, 1); // Apply them to the pixmaps QGraphicsPixmapItem* bgItem = new QGraphicsPixmapItem(keyBG); bgItem->setGraphicsEffect(bgEffect); QGraphicsPixmapItem* decItem = new QGraphicsPixmapItem(decoration); decItem->setGraphicsEffect(decEffect); // Render everything QGraphicsScene* scene = new QGraphicsScene; scene->addItem(bgItem); scene->addItem(decItem); // It has to be rendered onto yet another pixmap or else DPI scaling will look terrible... QPixmap final(wWidth * ratio, wHeight * ratio); final.fill(QColor(0, 0, 0, 0));