QImage *createRoundButtonBackground(const QMatrix &matrix) const { QRect scaledRect; scaledRect = matrix.mapRect(QRect(0, 0, this->logicalSize.width(), this->logicalSize.height())); QImage *image = new QImage(scaledRect.width(), scaledRect.height(), QImage::Format_ARGB32_Premultiplied); image->fill(QColor(0, 0, 0, 0).rgba()); QPainter painter(image); painter.setRenderHint(QPainter::SmoothPixmapTransform); painter.setRenderHint(QPainter::Antialiasing); painter.setPen(Qt::NoPen); if (Colors::useEightBitPalette){ painter.setPen(QColor(120, 120, 120)); if (this->pressed) painter.setBrush(QColor(60, 60, 60)); else if (this->highlighted) painter.setBrush(QColor(100, 100, 100)); else painter.setBrush(QColor(80, 80, 80)); } else { QLinearGradient outlinebrush(0, 0, 0, scaledRect.height()); QLinearGradient brush(0, 0, 0, scaledRect.height()); brush.setSpread(QLinearGradient::PadSpread); QColor highlight(255, 255, 255, 70); QColor shadow(0, 0, 0, 70); QColor sunken(220, 220, 220, 30); QColor normal1(255, 255, 245, 60); QColor normal2(255, 255, 235, 10); if (this->type == TextButton::PANEL){ normal1 = QColor(200, 170, 160, 50); normal2 = QColor(50, 10, 0, 50); } if (pressed) { outlinebrush.setColorAt(0.0f, shadow); outlinebrush.setColorAt(1.0f, highlight); brush.setColorAt(0.0f, sunken); painter.setPen(Qt::NoPen); } else { outlinebrush.setColorAt(1.0f, shadow); outlinebrush.setColorAt(0.0f, highlight); brush.setColorAt(0.0f, normal1); if (!this->highlighted) brush.setColorAt(1.0f, normal2); painter.setPen(QPen(outlinebrush, 1)); } painter.setBrush(brush); } if (this->type == TextButton::PANEL) painter.drawRect(0, 0, scaledRect.width(), scaledRect.height()); else painter.drawRoundedRect(0, 0, scaledRect.width(), scaledRect.height(), 10, 90, Qt::RelativeSize); return image; }
void QStyleItem::paint(QPainter *painter) { if (width() < 1 || height() <1) return; initStyleOption(); switch (m_itemType) { case Button: qApp->style()->drawControl(QStyle::CE_PushButton, m_styleoption, painter); break; case ItemRow :{ QPixmap pixmap; // Only draw through style once const QString pmKey = QLatin1Literal("itemrow") % QString::number(m_styleoption->state,16) % activeControl(); if (!QPixmapCache::find(pmKey, pixmap) || pixmap.width() < width() || height() != pixmap.height()) { int newSize = width(); pixmap = QPixmap(newSize, height()); pixmap.fill(Qt::transparent); QPainter pixpainter(&pixmap); qApp->style()->drawPrimitive(QStyle::PE_PanelItemViewRow, m_styleoption, &pixpainter); if (!qApp->style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected) && selected()) pixpainter.fillRect(m_styleoption->rect, m_styleoption->palette.highlight()); QPixmapCache::insert(pmKey, pixmap); } painter->drawPixmap(0, 0, pixmap); } break; case Item: qApp->style()->drawControl(QStyle::CE_ItemViewItem, m_styleoption, painter); break; case Header: qApp->style()->drawControl(QStyle::CE_Header, m_styleoption, painter); break; case ToolButton: #ifdef Q_OS_MAC if (style() == "mac" && hint().indexOf("segmented") != -1) { const QPaintDevice *target = painter->device(); HIThemeSegmentDrawInfo sgi; sgi.version = 0; sgi.state = isEnabled() ? kThemeStateActive : kThemeStateDisabled; if (sunken()) sgi.state |= kThemeStatePressed; sgi.size = kHIThemeSegmentSizeNormal; sgi.kind = kHIThemeSegmentKindTextured; sgi.value = on() && !sunken() ? kThemeButtonOn : kThemeButtonOff; sgi.adornment |= kHIThemeSegmentAdornmentLeadingSeparator; if (sunken()) { sgi.adornment |= kHIThemeSegmentAdornmentTrailingSeparator; } SInt32 button_height; GetThemeMetric(kThemeMetricButtonRoundedHeight, &button_height); sgi.position = info() == "leftmost" ? kHIThemeSegmentPositionFirst: info() == "rightmost" ? kHIThemeSegmentPositionLast : info() == "h_middle" ? kHIThemeSegmentPositionMiddle : kHIThemeSegmentPositionOnly; QRect centered = m_styleoption->rect; centered.setHeight(button_height); centered.moveCenter(m_styleoption->rect.center()); HIRect hirect = qt_hirectForQRect(centered.translated(0, -1), QRect(0, 0, 0, 0)); HIThemeDrawSegment(&hirect, &sgi, qt_mac_cg_context(target), kHIThemeOrientationNormal); } else #endif qApp->style()->drawComplexControl(QStyle::CC_ToolButton, qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), painter); break; case Tab: qApp->style()->drawControl(QStyle::CE_TabBarTab, m_styleoption, painter); break; case Frame: qApp->style()->drawControl(QStyle::CE_ShapedFrame, m_styleoption, painter); break; case FocusFrame: if (style() == "mac" && hint().indexOf("rounded") != -1) break; // embedded in the line itself else qApp->style()->drawControl(QStyle::CE_FocusFrame, m_styleoption, painter); break; case TabFrame: qApp->style()->drawPrimitive(QStyle::PE_FrameTabWidget, m_styleoption, painter); break; case MenuBar: qApp->style()->drawControl(QStyle::CE_MenuBarEmptyArea, m_styleoption, painter); break; case MenuBarItem: qApp->style()->drawControl(QStyle::CE_MenuBarItem, m_styleoption, painter); break; case MenuItem: case ComboBoxItem: // fall through qApp->style()->drawControl(QStyle::CE_MenuItem, m_styleoption, painter); break; case CheckBox: qApp->style()->drawControl(QStyle::CE_CheckBox, m_styleoption, painter); break; case RadioButton: qApp->style()->drawControl(QStyle::CE_RadioButton, m_styleoption, painter); break; case Edit: { #ifdef Q_OS_MAC if (style() == "mac" && hint().indexOf("rounded") != -1) { const QPaintDevice *target = painter->device(); HIThemeFrameDrawInfo fdi; fdi.version = 0; fdi.state = kThemeStateActive; SInt32 frame_size; GetThemeMetric(kThemeMetricEditTextFrameOutset, &frame_size); fdi.kind = kHIThemeFrameTextFieldRound; if ((m_styleoption->state & QStyle::State_ReadOnly) || !(m_styleoption->state & QStyle::State_Enabled)) fdi.state = kThemeStateInactive; fdi.isFocused = hasFocus(); HIRect hirect = qt_hirectForQRect(m_styleoption->rect, QRect(frame_size, frame_size, frame_size * 2, frame_size * 2)); HIThemeDrawFrame(&hirect, &fdi, qt_mac_cg_context(target), kHIThemeOrientationNormal); } else #endif qApp->style()->drawPrimitive(QStyle::PE_PanelLineEdit, m_styleoption, painter); } break; case MacHelpButton: #ifdef Q_OS_MAC { const QPaintDevice *target = painter->device(); HIThemeButtonDrawInfo fdi; fdi.kind = kThemeRoundButtonHelp; fdi.version = 0; fdi.adornment = 0; fdi.state = sunken() ? kThemeStatePressed : kThemeStateActive; HIRect hirect = qt_hirectForQRect(m_styleoption->rect,QRect(0, 0, 0, 0)); HIThemeDrawButton(&hirect, &fdi, qt_mac_cg_context(target), kHIThemeOrientationNormal, NULL); } #endif break; case Widget: qApp->style()->drawPrimitive(QStyle::PE_Widget, m_styleoption, painter); break; case ScrollAreaCorner: qApp->style()->drawPrimitive(QStyle::PE_PanelScrollAreaCorner, m_styleoption, painter); break; case Splitter: if (m_styleoption->rect.width() == 1) painter->fillRect(0, 0, width(), height(), m_styleoption->palette.dark().color()); else qApp->style()->drawControl(QStyle::CE_Splitter, m_styleoption, painter); break; case ComboBox: { qApp->style()->drawComplexControl(QStyle::CC_ComboBox, qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), painter); // This is needed on mac as it will use the painter color and ignore the palette QPen pen = painter->pen(); painter->setPen(m_styleoption->palette.text().color()); qApp->style()->drawControl(QStyle::CE_ComboBoxLabel, m_styleoption, painter); painter->setPen(pen); } break; case SpinBox: qApp->style()->drawComplexControl(QStyle::CC_SpinBox, qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), painter); break; case Slider: qApp->style()->drawComplexControl(QStyle::CC_Slider, qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), painter); break; case Dial: qApp->style()->drawComplexControl(QStyle::CC_Dial, qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), painter); break; case ProgressBar: qApp->style()->drawControl(QStyle::CE_ProgressBar, m_styleoption, painter); break; case ToolBar: qApp->style()->drawControl(QStyle::CE_ToolBar, m_styleoption, painter); break; case StatusBar: if (style() == "mac") { m_styleoption->rect.adjust(0, 1, 0, 0); qApp->style()->drawControl(QStyle::CE_ToolBar, m_styleoption, painter); m_styleoption->rect.adjust(0, -1, 0, 0); painter->setPen(m_styleoption->palette.dark().color().darker(120)); painter->drawLine(m_styleoption->rect.topLeft(), m_styleoption->rect.topRight()); } else { qApp->style()->drawPrimitive(QStyle::PE_PanelToolBar, m_styleoption, painter); } break; case GroupBox: qApp->style()->drawComplexControl(QStyle::CC_GroupBox, qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), painter); break; case ScrollBar: qApp->style()->drawComplexControl(QStyle::CC_ScrollBar, qstyleoption_cast<QStyleOptionComplex*>(m_styleoption), painter); break; case Menu: { QStyleHintReturnMask val; qApp->style()->styleHint(QStyle::SH_Menu_Mask, m_styleoption, 0, &val); painter->save(); painter->setClipRegion(val.region); painter->fillRect(m_styleoption->rect, m_styleoption->palette.window()); painter->restore(); qApp->style()->drawPrimitive(QStyle::PE_PanelMenu, m_styleoption, painter); QStyleOptionFrame frame; frame.lineWidth = qApp->style()->pixelMetric(QStyle::PM_MenuPanelWidth); frame.midLineWidth = 0; frame.rect = m_styleoption->rect; qApp->style()->drawPrimitive(QStyle::PE_FrameMenu, &frame, painter); } break; default: break; } }
void QStyleItem::initStyleOption() { QString type = elementType(); if (m_styleoption) m_styleoption->state = 0; switch (m_itemType) { case Button: { if (!m_styleoption) m_styleoption = new QStyleOptionButton(); QStyleOptionButton *opt = qstyleoption_cast<QStyleOptionButton*>(m_styleoption); opt->text = text(); opt->features = (activeControl() == "default") ? QStyleOptionButton::DefaultButton : QStyleOptionButton::None; } break; case ItemRow: { if (!m_styleoption) m_styleoption = new QStyleOptionViewItem(); QStyleOptionViewItem *opt = qstyleoption_cast<QStyleOptionViewItem*>(m_styleoption); opt->features = 0; if (activeControl() == "alternate") opt->features |= QStyleOptionViewItem::Alternate; } break; case Splitter: { if (!m_styleoption) { m_styleoption = new QStyleOption; } } break; case Item: { if (!m_styleoption) { m_styleoption = new QStyleOptionViewItem(); } QStyleOptionViewItem *opt = qstyleoption_cast<QStyleOptionViewItem*>(m_styleoption); opt->features = QStyleOptionViewItem::HasDisplay; opt->text = text(); opt->textElideMode = Qt::ElideRight; QPalette pal = m_styleoption->palette; pal.setBrush(QPalette::Base, Qt::NoBrush); m_styleoption->palette = pal; } break; case Header: { if (!m_styleoption) m_styleoption = new QStyleOptionHeader(); QStyleOptionHeader *opt = qstyleoption_cast<QStyleOptionHeader*>(m_styleoption); opt->text = text(); opt->sortIndicator = activeControl() == "down" ? QStyleOptionHeader::SortDown : activeControl() == "up" ? QStyleOptionHeader::SortUp : QStyleOptionHeader::None; if (info() == QLatin1String("beginning")) opt->position = QStyleOptionHeader::Beginning; else if (info() == QLatin1String("end")) opt->position = QStyleOptionHeader::End; else if (info() == QLatin1String("only")) opt->position = QStyleOptionHeader::OnlyOneSection; else opt->position = QStyleOptionHeader::Middle; } break; case ToolButton: { if (!m_styleoption) m_styleoption = new QStyleOptionToolButton(); QStyleOptionToolButton *opt = qstyleoption_cast<QStyleOptionToolButton*>(m_styleoption); opt->subControls = QStyle::SC_ToolButton; opt->state |= QStyle::State_AutoRaise; opt->activeSubControls = QStyle::SC_ToolButton; } break; case ToolBar: { if (!m_styleoption) m_styleoption = new QStyleOptionToolBar(); } break; case Tab: { if (!m_styleoption) m_styleoption = new QStyleOptionTab(); QStyleOptionTab *opt = qstyleoption_cast<QStyleOptionTab*>(m_styleoption); opt->text = text(); opt->shape = info() == "South" ? QTabBar::RoundedSouth : QTabBar::RoundedNorth; if (activeControl() == QLatin1String("beginning")) opt->position = QStyleOptionTab::Beginning; else if (activeControl() == QLatin1String("end")) opt->position = QStyleOptionTab::End; else if (activeControl() == QLatin1String("only")) opt->position = QStyleOptionTab::OnlyOneTab; else opt->position = QStyleOptionTab::Middle; } break; case Menu: { if (!m_styleoption) m_styleoption = new QStyleOptionMenuItem(); } break; case Frame: { if (!m_styleoption) m_styleoption = new QStyleOptionFrame(); QStyleOptionFrame *opt = qstyleoption_cast<QStyleOptionFrame*>(m_styleoption); opt->frameShape = QFrame::StyledPanel; opt->lineWidth = 1; opt->midLineWidth = 1; } break; case TabFrame: { if (!m_styleoption) m_styleoption = new QStyleOptionTabWidgetFrame(); QStyleOptionTabWidgetFrame *opt = qstyleoption_cast<QStyleOptionTabWidgetFrame*>(m_styleoption); opt->shape = (info() == "South") ? QTabBar::RoundedSouth : QTabBar::RoundedNorth; if (minimum()) opt->selectedTabRect = QRect(value(), 0, minimum(), height()); opt->tabBarSize = QSize(minimum() , height()); // oxygen style needs this hack opt->leftCornerWidgetSize = QSize(value(), 0); } break; case MenuItem: case ComboBoxItem: { if (!m_styleoption) m_styleoption = new QStyleOptionMenuItem(); QStyleOptionMenuItem *opt = qstyleoption_cast<QStyleOptionMenuItem*>(m_styleoption); opt->checked = false; opt->text = text(); } break; case CheckBox: case RadioButton: { if (!m_styleoption) m_styleoption = new QStyleOptionButton(); QStyleOptionButton *opt = qstyleoption_cast<QStyleOptionButton*>(m_styleoption); if (!on()) opt->state |= QStyle::State_Off; opt->text = text(); } break; case Edit: { if (!m_styleoption) m_styleoption = new QStyleOptionFrame(); QStyleOptionFrame *opt = qstyleoption_cast<QStyleOptionFrame*>(m_styleoption); opt->lineWidth = 1; // this must be non-zero } break; case ComboBox :{ if (!m_styleoption) m_styleoption = new QStyleOptionComboBox(); QStyleOptionComboBox *opt = qstyleoption_cast<QStyleOptionComboBox*>(m_styleoption); opt->currentText = text(); } break; case SpinBox: { if (!m_styleoption) m_styleoption = new QStyleOptionSpinBox(); QStyleOptionSpinBox *opt = qstyleoption_cast<QStyleOptionSpinBox*>(m_styleoption); opt->frame = true; if (value() & 0x1) opt->activeSubControls = QStyle::SC_SpinBoxUp; else if (value() & (1<<1)) opt->activeSubControls = QStyle::SC_SpinBoxDown; opt->subControls = QStyle::SC_All; opt->stepEnabled = 0; if (value() & (1<<2)) opt->stepEnabled |= QAbstractSpinBox::StepUpEnabled; if (value() & (1<<3)) opt->stepEnabled |= QAbstractSpinBox::StepDownEnabled; } break; case Slider: case Dial: { if (!m_styleoption) m_styleoption = new QStyleOptionSlider(); QStyleOptionSlider *opt = qstyleoption_cast<QStyleOptionSlider*>(m_styleoption); opt->minimum = minimum(); opt->maximum = maximum(); opt->sliderPosition = value(); opt->singleStep = step(); if (opt->singleStep) { qreal numOfSteps = (opt->maximum - opt->minimum) / opt->singleStep; // at least 5 pixels between tick marks if (numOfSteps && (width() / numOfSteps < 5)) opt->tickInterval = qRound((5*numOfSteps / width()) + 0.5)*step(); else opt->tickInterval = opt->singleStep; } else // default Qt-components implementation opt->tickInterval = opt->maximum != opt->minimum ? 1200 / (opt->maximum - opt->minimum) : 0; opt->sliderValue = value(); opt->subControls = QStyle::SC_SliderGroove | QStyle::SC_SliderHandle; opt->tickPosition = (activeControl() == "tick" ? QSlider::TicksBelow : QSlider::NoTicks); if (opt->tickPosition != QSlider::NoTicks) opt->subControls |= QStyle::SC_SliderTickmarks; opt->activeSubControls = QStyle::SC_None; } break; case ProgressBar: { if (!m_styleoption) m_styleoption = new QStyleOptionProgressBar(); QStyleOptionProgressBar *opt = qstyleoption_cast<QStyleOptionProgressBar*>(m_styleoption); opt->orientation = horizontal() ? Qt::Horizontal : Qt::Vertical; opt->minimum = minimum(); opt->maximum = maximum(); opt->progress = value(); } break; case GroupBox: { if (!m_styleoption) m_styleoption = new QStyleOptionGroupBox(); QStyleOptionGroupBox *opt = qstyleoption_cast<QStyleOptionGroupBox*>(m_styleoption); opt->text = text(); opt->lineWidth = 1; opt->subControls = QStyle::SC_GroupBoxLabel; opt->features = 0; if (sunken()) { // Qt draws an ugly line here so I ignore it opt->subControls |= QStyle::SC_GroupBoxFrame; } else { opt->features |= QStyleOptionFrame::Flat; } if (activeControl() == "checkbox") opt->subControls |= QStyle::SC_GroupBoxCheckBox; } break; case ScrollBar: { if (!m_styleoption) m_styleoption = new QStyleOptionSlider(); QStyleOptionSlider *opt = qstyleoption_cast<QStyleOptionSlider*>(m_styleoption); opt->minimum = minimum(); opt->maximum = maximum(); opt->pageStep = qMax(0, int(horizontal() ? width() : height())); opt->orientation = horizontal() ? Qt::Horizontal : Qt::Vertical; opt->sliderPosition = value(); opt->sliderValue = value(); opt->activeSubControls = (activeControl() == QLatin1String("up")) ? QStyle::SC_ScrollBarSubLine : (activeControl() == QLatin1String("down")) ? QStyle::SC_ScrollBarAddLine: QStyle::SC_ScrollBarSlider; opt->sliderValue = value(); opt->subControls = QStyle::SC_All; } case MenuBar: if (!m_styleoption) { QStyleOptionMenuItem *menuOpt = new QStyleOptionMenuItem(); menuOpt->menuItemType = QStyleOptionMenuItem::EmptyArea; m_styleoption = menuOpt; } break; case MenuBarItem: if (!m_styleoption) { QStyleOptionMenuItem *menuOpt = new QStyleOptionMenuItem(); menuOpt->text = text(); menuOpt->menuItemType = QStyleOptionMenuItem::Normal; m_styleoption = menuOpt; } break; default: break; } if (!m_styleoption) m_styleoption = new QStyleOption(); m_styleoption->styleObject = this; m_styleoption->rect = QRect(m_paintMargins, m_paintMargins, width() - 2* m_paintMargins, height() - 2 * m_paintMargins); if (isEnabled()) m_styleoption->state |= QStyle::State_Enabled; if (m_active) m_styleoption->state |= QStyle::State_Active; if (m_sunken) m_styleoption->state |= QStyle::State_Sunken; if (m_raised) m_styleoption->state |= QStyle::State_Raised; if (m_selected) m_styleoption->state |= QStyle::State_Selected; if (m_focus) m_styleoption->state |= QStyle::State_HasFocus; if (m_on) m_styleoption->state |= QStyle::State_On; if (m_hover) m_styleoption->state |= QStyle::State_MouseOver; if (m_horizontal) m_styleoption->state |= QStyle::State_Horizontal; if (m_hint.indexOf("mini") != -1) { m_styleoption->state |= QStyle::State_Mini; } else if (m_hint.indexOf("small") != -1) { m_styleoption->state |= QStyle::State_Small; } }
QImage *createArrowBackground(const QMatrix &matrix) const { QRect scaledRect; scaledRect = matrix.mapRect(QRect(0, 0, this->logicalSize.width(), this->logicalSize.height())); QImage *image = new QImage(scaledRect.width(), scaledRect.height(), QImage::Format_ARGB32_Premultiplied); image->fill(QColor(0, 0, 0, 0).rgba()); QPainter painter(image); painter.setRenderHint(QPainter::SmoothPixmapTransform); painter.setRenderHint(QPainter::Antialiasing); painter.setPen(Qt::NoPen); if (Colors::useEightBitPalette){ painter.setPen(QColor(120, 120, 120)); if (this->pressed) painter.setBrush(QColor(60, 60, 60)); else if (this->highlighted) painter.setBrush(QColor(100, 100, 100)); else painter.setBrush(QColor(80, 80, 80)); } else { QLinearGradient outlinebrush(0, 0, 0, scaledRect.height()); QLinearGradient brush(0, 0, 0, scaledRect.height()); brush.setSpread(QLinearGradient::PadSpread); QColor highlight(255, 255, 255, 70); QColor shadow(0, 0, 0, 70); QColor sunken(220, 220, 220, 30); QColor normal1 = QColor(200, 170, 160, 50); QColor normal2 = QColor(50, 10, 0, 50); if (pressed) { outlinebrush.setColorAt(0.0f, shadow); outlinebrush.setColorAt(1.0f, highlight); brush.setColorAt(0.0f, sunken); painter.setPen(Qt::NoPen); } else { outlinebrush.setColorAt(1.0f, shadow); outlinebrush.setColorAt(0.0f, highlight); brush.setColorAt(0.0f, normal1); if (!this->highlighted) brush.setColorAt(1.0f, normal2); painter.setPen(QPen(outlinebrush, 1)); } painter.setBrush(brush); } painter.drawRect(0, 0, scaledRect.width(), scaledRect.height()); float xOff = scaledRect.width() / 2; float yOff = scaledRect.height() / 2; float sizex = 3.0f * matrix.m11(); float sizey = 1.5f * matrix.m22(); if (this->type == TextButton::UP) sizey *= -1; QPainterPath path; path.moveTo(xOff, yOff + (5 * sizey)); path.lineTo(xOff - (4 * sizex), yOff - (3 * sizey)); path.lineTo(xOff + (4 * sizex), yOff - (3 * sizey)); path.lineTo(xOff, yOff + (5 * sizey)); painter.drawPath(path); return image; }
void QStyleItem::initStyleOption() { QString type = elementType(); if (m_styleoption) m_styleoption->state = 0; switch (m_itemType) { case Button: { if (!m_styleoption) m_styleoption = new QStyleOptionButton(); QStyleOptionButton *opt = qstyleoption_cast<QStyleOptionButton*>(m_styleoption); opt->text = text(); opt->features = (activeControl() == "default") ? QStyleOptionButton::DefaultButton : QStyleOptionButton::None; } break; case ItemRow: { if (!m_styleoption) m_styleoption = new QStyleOptionViewItemV4(); QStyleOptionViewItemV4 *opt = qstyleoption_cast<QStyleOptionViewItemV4*>(m_styleoption); opt->features = 0; if (activeControl() == "alternate") opt->features |= QStyleOptionViewItemV2::Alternate; } break; case Splitter: { if (!m_styleoption) { m_styleoption = new QStyleOption; } } break; case Item: { if (!m_styleoption) { m_styleoption = new QStyleOptionViewItemV4(); } QStyleOptionViewItemV4 *opt = qstyleoption_cast<QStyleOptionViewItemV4*>(m_styleoption); opt->features = QStyleOptionViewItemV4::HasDisplay; opt->text = text(); opt->textElideMode = Qt::ElideRight; QPalette pal = m_styleoption->palette; pal.setBrush(QPalette::Base, Qt::NoBrush); m_styleoption->palette = pal; } break; case Header: { if (!m_styleoption) m_styleoption = new QStyleOptionHeader(); QStyleOptionHeader *opt = qstyleoption_cast<QStyleOptionHeader*>(m_styleoption); opt->text = text(); opt->sortIndicator = activeControl() == "down" ? QStyleOptionHeader::SortDown : activeControl() == "up" ? QStyleOptionHeader::SortUp : QStyleOptionHeader::None; if (activeControl() == QLatin1String("beginning")) opt->position = QStyleOptionHeader::Beginning; else if (activeControl() == QLatin1String("end")) opt->position = QStyleOptionHeader::End; else if (activeControl() == QLatin1String("only")) opt->position = QStyleOptionHeader::OnlyOneSection; else opt->position = QStyleOptionHeader::Middle; } break; case ToolButton :{ if (!m_styleoption) m_styleoption = new QStyleOptionToolButton(); QStyleOptionToolButton *opt = qstyleoption_cast<QStyleOptionToolButton*>(m_styleoption); opt->subControls = QStyle::SC_ToolButton; opt->state |= QStyle::State_AutoRaise; opt->activeSubControls = QStyle::SC_ToolButton; } break; case ToolBar: { if (!m_styleoption) m_styleoption = new QStyleOptionToolBar(); } break; case Tab: { if (!m_styleoption) m_styleoption = new QStyleOptionTabV3(); QStyleOptionTabV3 *opt = qstyleoption_cast<QStyleOptionTabV3*>(m_styleoption); opt->text = text(); opt->shape = info() == "South" ? QTabBar::RoundedSouth : QTabBar::RoundedNorth; if (activeControl() == QLatin1String("beginning")) opt->position = QStyleOptionTabV3::Beginning; else if (activeControl() == QLatin1String("end")) opt->position = QStyleOptionTabV3::End; else if (activeControl() == QLatin1String("only")) opt->position = QStyleOptionTabV3::OnlyOneTab; else opt->position = QStyleOptionTabV3::Middle; } break; case Menu: { if (!m_styleoption) m_styleoption = new QStyleOptionMenuItem(); } break; case Frame: { if (!m_styleoption) m_styleoption = new QStyleOptionFrameV3(); QStyleOptionFrameV3 *opt = qstyleoption_cast<QStyleOptionFrameV3*>(m_styleoption); opt->frameShape = QFrame::StyledPanel; opt->lineWidth = 1; opt->midLineWidth = 1; } break; case TabFrame: { if (!m_styleoption) m_styleoption = new QStyleOptionTabWidgetFrameV2(); QStyleOptionTabWidgetFrameV2 *opt = qstyleoption_cast<QStyleOptionTabWidgetFrameV2*>(m_styleoption); opt->shape = (info() == "South") ? QTabBar::RoundedSouth : QTabBar::RoundedNorth; if (minimum()) opt->selectedTabRect = QRect(value(), 0, minimum(), height()); opt->tabBarSize = QSize(minimum() , height()); // oxygen style needs this hack opt->leftCornerWidgetSize = QSize(value(), 0); } break; case MenuItem: case ComboBoxItem: { if (!m_styleoption) m_styleoption = new QStyleOptionMenuItem(); QStyleOptionMenuItem *opt = qstyleoption_cast<QStyleOptionMenuItem*>(m_styleoption); opt->checked = false; opt->text = text(); opt->palette = widget()->palette(); } break; case CheckBox: case RadioButton: { if (!m_styleoption) m_styleoption = new QStyleOptionButton(); QStyleOptionButton *opt = qstyleoption_cast<QStyleOptionButton*>(m_styleoption); if (!on()) opt->state |= QStyle::State_Off; opt->text = text(); } break; case Edit: { if (!m_styleoption) m_styleoption = new QStyleOptionFrameV3(); QStyleOptionFrameV3 *opt = qstyleoption_cast<QStyleOptionFrameV3*>(m_styleoption); opt->lineWidth = 1; // this must be non-zero } break; case ComboBox :{ if (!m_styleoption) m_styleoption = new QStyleOptionComboBox(); QStyleOptionComboBox *opt = qstyleoption_cast<QStyleOptionComboBox*>(m_styleoption); opt->currentText = text(); } break; case SpinBox: { if (!m_styleoption) m_styleoption = new QStyleOptionSpinBox(); QStyleOptionSpinBox *opt = qstyleoption_cast<QStyleOptionSpinBox*>(m_styleoption); opt->frame = true; if (value() & 0x1) opt->activeSubControls = QStyle::SC_SpinBoxUp; else if (value() & (1<<1)) opt->activeSubControls = QStyle::SC_SpinBoxDown; opt->subControls = QStyle::SC_All; opt->stepEnabled = 0; if (value() & (1<<2)) opt->stepEnabled |= QAbstractSpinBox::StepUpEnabled; if (value() & (1<<3)) opt->stepEnabled |= QAbstractSpinBox::StepDownEnabled; } break; case Slider: case Dial: { if (!m_styleoption) m_styleoption = new QStyleOptionSlider(); QStyleOptionSlider *opt = qstyleoption_cast<QStyleOptionSlider*>(m_styleoption); opt->minimum = minimum(); opt->maximum = maximum(); // ### fixme - workaround for KDE inverted dial opt->sliderPosition = value(); opt->singleStep = step(); if (opt->singleStep) { qreal numOfSteps = (opt->maximum - opt->minimum) / opt->singleStep; // at least 5 pixels between tick marks if (numOfSteps && (width() / numOfSteps < 5)) opt->tickInterval = qRound((5*numOfSteps / width()) + 0.5)*step(); else opt->tickInterval = opt->singleStep; } else // default Qt-components implementation opt->tickInterval = opt->maximum != opt->minimum ? 1200 / (opt->maximum - opt->minimum) : 0; if (style() == QLatin1String("oxygen") && type == QLatin1String("dial")) opt->sliderValue = maximum() - value(); else opt->sliderValue = value(); opt->subControls = QStyle::SC_SliderGroove | QStyle::SC_SliderHandle; opt->tickPosition = (activeControl() == "below") ? QSlider::TicksBelow : (activeControl() == "above" ? QSlider::TicksAbove: QSlider::NoTicks); if (opt->tickPosition != QSlider::NoTicks) opt->subControls |= QStyle::SC_SliderTickmarks; opt->activeSubControls = QStyle::SC_None; } break; case ProgressBar: { if (QProgressBar *bar= qobject_cast<QProgressBar*>(widget())){ bar->setMaximum(maximum()); bar->setMinimum(minimum()); if (maximum() != minimum()) bar->setValue(1); } if (!m_styleoption) m_styleoption = new QStyleOptionProgressBarV2(); QStyleOptionProgressBarV2 *opt = qstyleoption_cast<QStyleOptionProgressBarV2*>(m_styleoption); opt->orientation = horizontal() ? Qt::Horizontal : Qt::Vertical; opt->minimum = minimum(); opt->maximum = maximum(); opt->progress = value(); } break; case GroupBox: { if (!m_styleoption) m_styleoption = new QStyleOptionGroupBox(); QStyleOptionGroupBox *opt = qstyleoption_cast<QStyleOptionGroupBox*>(m_styleoption); opt->text = text(); opt->lineWidth = 1; opt->subControls = QStyle::SC_GroupBoxLabel; if (sunken()) // Qt draws an ugly line here so I ignore it opt->subControls |= QStyle::SC_GroupBoxFrame; else opt->features |= QStyleOptionFrameV2::Flat; if (activeControl() == "checkbox") opt->subControls |= QStyle::SC_GroupBoxCheckBox; if (QGroupBox *group= qobject_cast<QGroupBox*>(widget())) { group->setTitle(text()); group->setCheckable(opt->subControls & QStyle::SC_GroupBoxCheckBox); } } break; case ScrollBar: { if (!m_styleoption) m_styleoption = new QStyleOptionSlider(); QStyleOptionSlider *opt = qstyleoption_cast<QStyleOptionSlider*>(m_styleoption); opt->minimum = minimum(); opt->maximum = maximum(); opt->pageStep = horizontal() ? width() : height(); opt->orientation = horizontal() ? Qt::Horizontal : Qt::Vertical; opt->sliderPosition = value(); opt->sliderValue = value(); opt->activeSubControls = (activeControl() == QLatin1String("up")) ? QStyle::SC_ScrollBarSubLine : (activeControl() == QLatin1String("down")) ? QStyle::SC_ScrollBarAddLine: QStyle::SC_ScrollBarSlider; opt->sliderValue = value(); opt->subControls = QStyle::SC_All; QScrollBar *bar = qobject_cast<QScrollBar *>(widget()); bar->setMaximum(maximum()); bar->setMinimum(minimum()); bar->setValue(value()); } break; default: break; } if (!m_styleoption) m_styleoption = new QStyleOption(); m_styleoption->rect = QRect(m_paintMargins, m_paintMargins, width() - 2* m_paintMargins, height() - 2 * m_paintMargins); if (isEnabled()) m_styleoption->state |= QStyle::State_Enabled; if (m_active) m_styleoption->state |= QStyle::State_Active; if (m_sunken) m_styleoption->state |= QStyle::State_Sunken; if (m_raised) m_styleoption->state |= QStyle::State_Raised; if (m_selected) m_styleoption->state |= QStyle::State_Selected; if (m_focus) m_styleoption->state |= QStyle::State_HasFocus; if (m_on) m_styleoption->state |= QStyle::State_On; if (m_hover) m_styleoption->state |= QStyle::State_MouseOver; if (m_horizontal) m_styleoption->state |= QStyle::State_Horizontal; if (widget()) { widget()->ensurePolished(); if (type == QLatin1String("tab") && style() != QLatin1String("mac")) { // Some styles actually check the beginning and end position // using widget geometry, so we have to trick it widget()->setGeometry(0, 0, width(), height()); if (activeControl() != "beginning") m_styleoption->rect.translate(1, 0); // Don't position at start of widget if (activeControl() != "end") widget()->resize(200, height()); } #ifdef Q_WS_WIN else widget()->resize(width(), height()); #endif widget()->setEnabled(isEnabled()); m_styleoption->fontMetrics = widget()->fontMetrics(); if (!m_styleoption->palette.resolve()) m_styleoption->palette = widget()->palette(); if (m_hint.contains("mac.mini")) { widget()->setAttribute(Qt::WA_MacMiniSize); } else if (m_hint.contains("mac.small")) { widget()->setAttribute(Qt::WA_MacSmallSize); } } }
void QmaxButton::createArrowBackground(QPainter &painter) { // printf("Arrow BackGround2\n"); QRect scaledRect; scaledRect = matrix.mapRect(QRect(0, 0, this->logicalSize.width(), this->logicalSize.height())); QImage image(scaledRect.width(), scaledRect.height(), QImage::Format_ARGB32_Premultiplied); image.fill(QColor(0, 0, 0, 0).rgba()); //QPainter painter(image); painter.setRenderHint(QPainter::SmoothPixmapTransform); painter.setRenderHint(QPainter::Antialiasing); painter.setPen(Qt::NoPen); painter.drawImage(0, 0, image); if(Colors::useEightBitPalette) { painter.setPen(QColor(120,120,120)); if(this->m_nPressed) painter.setBrush(QColor(60,60,60)); else if(this->m_nHighlight) painter.setBrush(QColor(100,100,100)); else painter.setBrush(QColor(80,80,80)); } else { QLinearGradient outlinebrush(0,0,0,scaledRect.height()); QLinearGradient brush(0,0,0,scaledRect.height()); brush.setSpread(QLinearGradient::PadSpread); QColor highlight(255,255,255,128); QColor shadow(0,0,0,70); QColor sunken(220,220,220,30); QColor normal1(88,88,89,255); QColor normal2(88,88,89,255); QColor normal3(0,0,200,10); QColor normal4(255,255,250,255); if(m_nType==3 || m_nType == 4) { normal1 = QColor(100,180,189,55); normal2 = QColor(100,180,189,255); } if(m_nPressed) { outlinebrush.setColorAt(0.0f,shadow); outlinebrush.setColorAt(1.0f,highlight); brush.setColorAt(1.0f,sunken); painter.setPen(Qt::NoPen); } else { outlinebrush.setColorAt(0.75f,shadow); outlinebrush.setColorAt(0.0f,highlight); brush.setColorAt(0.0f,normal2); if(m_nHighlight) brush.setColorAt(1.0f,normal1); painter.setPen(QPen(outlinebrush,1)); } if(this->isEnabled()==false ) { outlinebrush.setColorAt(1.0f,shadow); outlinebrush.setColorAt(0.0f,highlight); brush.setColorAt(0.0f,normal3); painter.setPen(QPen(outlinebrush,2)); } if(m_nStatus ) { outlinebrush.setColorAt(1.0f,shadow); outlinebrush.setColorAt(0.0f,highlight); brush.setColorAt(0.0f,normal2); painter.setPen(QPen(outlinebrush,1)); } painter.setBrush(brush); } // painter.drawRect(0, 0, scaledRect.width(), scaledRect.height()); float xOff = scaledRect.width() / 2; float yOff = scaledRect.height() / 2; float sizex = 5.0f * matrix.m11(); float sizey = 3.5f * matrix.m22(); if (m_nType == 3) sizey *= -1; QPainterPath path; path.moveTo(xOff, yOff + (5 * sizey)); path.lineTo(xOff - (4 * sizex), yOff - (3 * sizey)); path.lineTo(xOff + (4 * sizex), yOff - (3 * sizey)); path.lineTo(xOff, yOff + (5 * sizey)); painter.drawPath(path); }
void QmaxButton::createButton(QPainter &painter) { QRect scaledRect; scaledRect = matrix.mapRect(QRect(0,0,this->logicalSize.width(),this->logicalSize.height())); QImage bg(this->m_strImage); painter.setRenderHint(QPainter::SmoothPixmapTransform); painter.setRenderHint(QPainter::Antialiasing); painter.setPen(Qt::NoPen); QLinearGradient brush1(0,0,0,scaledRect.height()); painter.drawImage(-2, -2, bg); if(Colors::useEightBitPalette) { painter.setPen(QColor(120,120,120)); if(this->m_nPressed) painter.setBrush(QColor(60,60,60)); else if(this->m_nHighlight) painter.setBrush(QColor(100,100,100)); else painter.setBrush(QColor(80,80,80)); } else { QLinearGradient outlinebrush(0,0,0,scaledRect.height()); QLinearGradient brush(0,0,0,scaledRect.height()); brush.setSpread(QLinearGradient::PadSpread); QColor highlight(255,255,255,128); QColor shadow(0,0,0,70); QColor sunken(220,220,220,30); QColor normal1(255,255,245,60); QColor normal2(255,255,235,10); QColor normal3(200,200,200,10); QColor normal4(255,255,250,255); if(m_nType && m_nType != 5 ) { normal1 = QColor(200,170,160,50); normal2 = QColor(50,10,0,50); } if(m_nPressed) { outlinebrush.setColorAt(0.0f,shadow); outlinebrush.setColorAt(1.0f,highlight); brush.setColorAt(1.0f,sunken); painter.setPen(Qt::NoPen); } else { outlinebrush.setColorAt(1.0f,shadow); outlinebrush.setColorAt(0.0f,highlight); brush.setColorAt(0.0f,normal1); if(m_nHighlight) brush.setColorAt(1.0f,normal2); painter.setPen(QPen(outlinebrush,1)); } if(this->isEnabled()==false ) { outlinebrush.setColorAt(1.0f,shadow); outlinebrush.setColorAt(0.0f,highlight); brush.setColorAt(0.0f,normal3); painter.setPen(QPen(outlinebrush,1)); } if(m_nStatus ) { outlinebrush.setColorAt(1.0f,shadow); outlinebrush.setColorAt(0.0f,highlight); brush.setColorAt(0.0f,normal4); painter.setPen(QPen(outlinebrush,1)); } painter.setBrush(brush); } if(m_nType == 1) painter.drawRect(0,0,scaledRect.width(),scaledRect.height()); else if(m_nType == 0) painter.drawRoundedRect(0,0,scaledRect.width(),scaledRect.height(),40.0,40.0,Qt::RelativeSize); else if(m_nType == 5) painter.drawEllipse(0,0,scaledRect.width(),scaledRect.height()); QFont font( "DejaVu Sans" ); font.setPointSize( 12 ); painter.setFont( font ); brush1.setColorAt(1.0f,QColor(255,255,255,255)); if(this->isEnabled()==false) { brush1.setColorAt(1.0f,QColor(200,200,200,100)); } painter.setPen(QPen(brush1,1)); painter.setBrush(brush1); QFontMetrics fMetrics = painter.fontMetrics(); QSize sz = fMetrics.size( Qt::TextWordWrap, m_strText ); QRectF txtRect( scaledRect.center(), sz ); int xPoint = (scaledRect.width()/2)- ((m_strText.count()/2)*10); int yPoint = scaledRect.height()/2; painter.drawText(xPoint,yPoint,m_strText); }
void ToolButton::paintEvent( QPaintEvent * _pe ) { const bool active = isDown() || isChecked(); QPainter painter(this); painter.setRenderHint(QPainter::SmoothPixmapTransform); painter.setRenderHint(QPainter::Antialiasing); painter.setPen(Qt::NoPen); QLinearGradient outlinebrush(0, 0, 0, height()); QLinearGradient brush(0, 0, 0, height()); brush.setSpread(QLinearGradient::PadSpread); QColor highlight(255, 255, 255, 70); QColor shadow(0, 0, 0, 70); QColor sunken(220, 220, 220, 30); QColor normal1(255, 255, 245, 60); QColor normal2(255, 255, 235, 10); if( active ) { outlinebrush.setColorAt(0.0f, shadow); outlinebrush.setColorAt(1.0f, highlight); brush.setColorAt(0.0f, sunken); painter.setPen(Qt::NoPen); } else { outlinebrush.setColorAt(1.0f, shadow); outlinebrush.setColorAt(0.0f, highlight); brush.setColorAt(0.0f, normal1); if( m_mouseOver == false ) { brush.setColorAt(1.0f, normal2); } painter.setPen(QPen(outlinebrush, 1)); } painter.setBrush(brush); painter.drawRoundedRect( 0, 0, width(), height(), 5, 5 ); const int dd = active ? 1 : 0; QPoint pt = QPoint( ( width() - m_img.width() ) / 2 + dd, 3 + dd ); if( s_iconOnlyMode ) { pt.setY( ( height() - m_img.height() ) / 2 - 1 + dd ); } painter.drawImage( pt, m_img ); if( s_iconOnlyMode == false ) { const QString l = ( active && m_altLabel.isEmpty() == FALSE ) ? m_altLabel : m_label; const int w = painter.fontMetrics().width( l ); painter.setPen( Qt::black ); painter.drawText( ( width() - w ) / 2 +1+dd, height() - 4+dd, l ); painter.setPen( Qt::white ); painter.drawText( ( width() - w ) / 2 +dd, height() - 5+dd, l ); } }
QImage Button::createBackground() const { QImage image(rect().width(), rect().height(), QImage::Format_ARGB32_Premultiplied); image.fill(QColor(0, 0, 0, 0).rgba()); QPainter painter(&image); painter.setRenderHint(QPainter::SmoothPixmapTransform); painter.setRenderHint(QPainter::Antialiasing); painter.setPen(Qt::NoPen); QLinearGradient outlinebrush(0, 0, 0, rect().height()); QLinearGradient brush(0, 0, 0, rect().height()); brush.setSpread(QLinearGradient::PadSpread); QColor highlight(255, 255, 255, 70); QColor shadow(0, 0, 0, 70); QColor sunken(220, 220, 220, 30); QColor normal1(255, 255, 245, 60); QColor normal2(255, 255, 235, 10); if (dark) { normal1 = QColor(200, 170, 160, 50); normal2 = QColor(50, 10, 0, 50); } if (!isEnabled() || isDown()) { outlinebrush.setColorAt(0.0f, shadow); outlinebrush.setColorAt(1.0f, highlight); brush.setColorAt(0.0f, sunken); painter.setPen(Qt::NoPen); } else { outlinebrush.setColorAt(1.0f, shadow); outlinebrush.setColorAt(0.0f, highlight); brush.setColorAt(0.0f, normal1); if (!hover) brush.setColorAt(1.0f, normal2); painter.setPen(QPen(outlinebrush, 1)); } painter.setBrush(brush); if (round) painter.drawRoundedRect(rect(), 15, rect().height()); else painter.drawRect(0, 0, rect().width(), rect().height()); if (text() == "##Left##" || text() == "##Right##") { qreal xCenter = rect().width() * 0.5; qreal yCenter = rect().height() * 0.5; qreal xSize = 12; qreal ySize = 6; if (text() == "##Right##") xSize *= -1; QPainterPath path; path.moveTo(xCenter - xSize, yCenter); path.lineTo(xCenter + xSize, yCenter - ySize); path.lineTo(xCenter + xSize, yCenter + ySize); path.lineTo(xCenter - xSize, yCenter); painter.drawPath(path); } return image; }