int QMotifStyle_QtDShell::__override_styleHint(int hint0, const QStyleOption* opt1, const QWidget* widget2, QStyleHintReturn* returnData3, bool static_call) const { if (static_call) { return QMotifStyle::styleHint((QStyle::StyleHint )hint0, (const QStyleOption* )opt1, (const QWidget* )widget2, (QStyleHintReturn* )returnData3); } else { return styleHint((QStyle::StyleHint )hint0, (const QStyleOption* )opt1, (const QWidget* )widget2, (QStyleHintReturn* )returnData3); } }
int QCommonStyle_QtDShell::__override_styleHint(int sh0, const QStyleOption* opt1, const QWidget* w2, QStyleHintReturn* shret3, bool static_call) const { if (static_call) { return QCommonStyle::styleHint((QStyle::StyleHint )sh0, (const QStyleOption* )opt1, (const QWidget* )w2, (QStyleHintReturn* )shret3); } else { return styleHint((QStyle::StyleHint )sh0, (const QStyleOption* )opt1, (const QWidget* )w2, (QStyleHintReturn* )shret3); } }
static QFontEngine *loadFromDatabase(QFontDef &req, const QFontPrivate *d) { #if defined(QT_MAC_USE_COCOA) QCFString fontName = NULL; #else ATSFontFamilyRef familyRef = 0; ATSFontRef fontRef = 0; #endif QStringList family_list = familyList(req); const char *stylehint = styleHint(req); if (stylehint) family_list << QLatin1String(stylehint); // add QFont::defaultFamily() to the list, for compatibility with previous versions family_list << QApplication::font().defaultFamily(); QMutexLocker locker(fontDatabaseMutex()); QFontDatabasePrivate *db = privateDb(); if (!db->count) initializeDb(); for (int i = 0; i < family_list.size(); ++i) { for (int k = 0; k < db->count; ++k) { if (db->families[k]->name.compare(family_list.at(i), Qt::CaseInsensitive) == 0) { QByteArray family_name = db->families[k]->name.toUtf8(); #if defined(QT_MAC_USE_COCOA) QCFType<CTFontRef> ctFont = CTFontCreateWithName(QCFString(db->families[k]->name), 12, NULL); if (ctFont) { fontName = CTFontCopyFullName(ctFont); goto found; } #else familyRef = ATSFontFamilyFindFromName(QCFString(db->families[k]->name), kATSOptionFlagsDefault); if (familyRef) { fontRef = ATSFontFindFromName(QCFString(db->families[k]->name), kATSOptionFlagsDefault); goto found; } #endif } } } found: #ifdef QT_MAC_USE_COCOA if (fontName) return new QCoreTextFontEngineMulti(fontName, req, d->kerning); #else if (familyRef) { QCFString actualName; if (ATSFontFamilyGetName(familyRef, kATSOptionFlagsDefault, &actualName) == noErr) req.family = actualName; return new QFontEngineMacMulti(familyRef, fontRef, req, d->kerning); } #endif return NULL; }
static void validateGridColor(QColor& gridColor, const GuiContext& ctx) { if (gridColor.isValid()) return; auto style = ctx.style(); QStyleOptionViewItem option; ctx.initStyleOption(option); option.widget = ctx.widget; const int gridHint = style->styleHint(QStyle::SH_Table_GridLineColor, &option, ctx.widget); gridColor = static_cast<QRgb>(gridHint); }
static QFontEngine *loadWin(const QFontPrivate *d, int script, const QFontDef &req) { // list of families to try QStringList family_list = familyList(req); const char *stylehint = styleHint(d->request); if (stylehint) family_list << QLatin1String(stylehint); // append the default fallback font for the specified script // family_list << ... ; ########### // add the default family QString defaultFamily = QApplication::font().family(); if (! family_list.contains(defaultFamily)) family_list << defaultFamily; // add QFont::defaultFamily() to the list, for compatibility with // previous versions family_list << QApplication::font().defaultFamily(); // null family means find the first font matching the specified script family_list << QString(); QtFontDesc desc; QFontEngine *fe = 0; QList<int> blacklistedFamilies; while (!fe) { for (int i = 0; i < family_list.size(); ++i) { QString family, foundry; parseFontName(family_list.at(i), foundry, family); FM_DEBUG("loadWin: >>>>>>>>>>>>>>trying to match '%s'", family.toLatin1().data()); QT_PREPEND_NAMESPACE(match)(script, req, family, foundry, -1, &desc, blacklistedFamilies); if (desc.family) break; } if (!desc.family) break; fe = loadEngine(script, req, d->hdc, d->dpi, d->rawMode, &desc, family_list); if (!fe) blacklistedFamilies.append(desc.familyIndex); } return fe; }
void MiamStyle::drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const { switch (element) { case CE_MenuBarItem: { const QStyleOptionMenuItem *somi = static_cast<const QStyleOptionMenuItem*>(option); const bool act = somi->state & (State_Sunken | State_Selected); QPalette palette = QApplication::palette(); QBrush brush; //bool dirtyHackMnemonic = widget->property("dirtyHackMnemonic").toBool(); if (act/* || dirtyHackMnemonic && option->rect.x() == 0*/) { painter->setPen(palette.highlight().color()); brush = palette.highlight().color().light(); painter->setBrush(brush); painter->drawRect(option->rect.adjusted(0, 0, -1, -1)); } else { brush = palette.window(); painter->fillRect(option->rect, palette.window()); } uint alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine; if (/*dirtyHackMnemonic == false &&*/ !styleHint(SH_UnderlineShortcut, somi, widget)) { alignment |= Qt::TextHideMnemonic; } if (qAbs(palette.text().color().value() - brush.color().value()) < 128) { painter->setPen(palette.highlightedText().color()); } else { painter->setPen(palette.text().color()); } painter->drawText(option->rect, alignment, somi->text); break; } case CE_MenuBarEmptyArea: { painter->fillRect(option->rect, QApplication::palette().window()); break; } default: QProxyStyle::drawControl(element, option, painter, widget); } }
void QFontDatabase::load(const QFontPrivate *d, int script) { // sanity checks if(!QFontCache::instance) qWarning("QFont: Must construct a QApplication before a QFont"); Q_ASSERT(script >= 0 && script < QUnicodeTables::ScriptCount); Q_UNUSED(script); QFontDef req = d->request; req.pixelSize = qt_mac_pixelsize(req, d->dpi); // set the point size to 0 to get better caching req.pointSize = 0; QFontCache::Key key = QFontCache::Key(req, QUnicodeTables::Common, d->screen); if(!(d->engineData = QFontCache::instance->findEngineData(key))) { d->engineData = new QFontEngineData; QFontCache::instance->insertEngineData(key, d->engineData); } else { d->engineData->ref.ref(); } if(d->engineData->engine) // already loaded return; // set it to the actual pointsize, so QFontInfo will do the right thing req.pointSize = qRound(qt_mac_pointsize(d->request, d->dpi)); QFontEngine *e = QFontCache::instance->findEngine(key); if(!e && qt_enable_test_font && req.family == QLatin1String("__Qt__Box__Engine__")) { e = new QTestFontEngine(req.pixelSize); e->fontDef = req; } if(e) { Q_ASSERT(e->type() == QFontEngine::Multi || e->type() == QFontEngine::TestFontEngine); e->ref.ref(); d->engineData->engine = e; return; // the font info and fontdef should already be filled } //find the font QStringList family_list = req.family.split(QLatin1Char(',')); // append the substitute list for each family in family_list { QStringList subs_list; for(QStringList::ConstIterator it = family_list.begin(); it != family_list.end(); ++it) subs_list += QFont::substitutes(*it); family_list += subs_list; } const char *stylehint = styleHint(req); if (stylehint) family_list << QLatin1String(stylehint); // add QFont::defaultFamily() to the list, for compatibility with // previous versions family_list << QApplication::font().defaultFamily(); ATSFontFamilyRef familyRef = 0; ATSFontRef fontRef = 0; QFontDatabasePrivate *db = privateDb(); if (!db->count) initializeDb(); for(int i = 0; i < family_list.size(); ++i) { for (int k = 0; k < db->count; ++k) { if (db->families[k]->name.compare(family_list.at(i), Qt::CaseInsensitive) == 0) { QByteArray family_name = db->families[k]->name.toUtf8(); familyRef = ATSFontFamilyFindFromName(QCFString(db->families[k]->name), kATSOptionFlagsDefault); if (familyRef) { fontRef = ATSFontFindFromName(QCFString(db->families[k]->name), kATSOptionFlagsDefault); goto FamilyFound; } } } } FamilyFound: //fill in the engine's font definition QFontDef fontDef = d->request; //copy.. if(fontDef.pointSize < 0) fontDef.pointSize = qt_mac_pointsize(fontDef, d->dpi); else fontDef.pixelSize = qt_mac_pixelsize(fontDef, d->dpi); #if 0 ItemCount name_count; if(ATSUCountFontNames(fontID, &name_count) == noErr && name_count) { ItemCount actualName_size; if(ATSUGetIndFontName(fontID, 0, 0, 0, &actualName_size, 0, 0, 0, 0) == noErr && actualName_size) { QByteArray actualName(actualName_size); if(ATSUGetIndFontName(fontID, 0, actualName_size, actualName.data(), &actualName_size, 0, 0, 0, 0) == noErr && actualName_size) fontDef.family = QString::fromUtf8(actualName); } } #else { QCFString actualName; if(ATSFontFamilyGetName(familyRef, kATSOptionFlagsDefault, &actualName) == noErr) fontDef.family = actualName; } #endif QFontEngine *engine = new QFontEngineMacMulti(familyRef, fontRef, fontDef, d->kerning); d->engineData->engine = engine; engine->ref.ref(); //a ref for the engineData->engine QFontCache::instance->insertEngine(key, engine); }
void WindowsModernStyle::drawControl( ControlElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { switch ( element ) { case CE_MenuBarEmptyArea: return; case CE_MenuBarItem: if ( option->state & QStyle::State_Sunken && option->state & QStyle::State_Enabled ) { painter->setPen( m_colorMenuBorder ); QLinearGradient gradient( option->rect.topLeft(), option->rect.bottomLeft() ); gradient.setColorAt( 0.0, m_colorMenuTitleBegin ); gradient.setColorAt( 1.0, m_colorMenuTitleEnd ); painter->setBrush( gradient ); painter->drawRect( option->rect.adjusted( 0, 0, -1, 0 ) ); } else if ( option->state & QStyle::State_Selected && option->state & QStyle::State_Enabled ) { painter->setPen( m_colorItemBorder ); QLinearGradient gradient( option->rect.topLeft(), option->rect.bottomLeft() ); gradient.setColorAt( 0.0, m_colorItemBackgroundBegin ); gradient.setColorAt( 1.0, m_colorItemBackgroundEnd ); painter->setBrush( gradient ); painter->drawRect( option->rect.adjusted( 0, 0, -1, -1 ) ); } if ( const QStyleOptionMenuItem* optionItem = qstyleoption_cast<const QStyleOptionMenuItem*>( option ) ) { int flags = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine; if ( !styleHint( SH_UnderlineShortcut, option, widget ) ) flags |= Qt::TextHideMnemonic; if ( !optionItem->icon.isNull() ) { QPixmap pixmap = optionItem->icon.pixmap( pixelMetric( PM_SmallIconSize, option, widget ), QIcon::Normal ); drawItemPixmap( painter, option->rect, flags, pixmap ); } else { drawItemText( painter, option->rect, flags, option->palette, true, optionItem->text, QPalette::Text ); } } return; case CE_MenuEmptyArea: painter->fillRect( option->rect, m_colorMenuBackground ); return; case CE_MenuItem: { if ( option->state & QStyle::State_Selected && option->state & QStyle::State_Enabled ) { painter->setPen( m_colorItemBorder ); painter->setBrush( m_colorItemBackgroundBegin ); painter->drawRect( option->rect.adjusted( 1, 0, -3, -1 ) ); } else { QLinearGradient gradient( QPoint( 0, 0 ), QPoint( 25, 0 ) ); gradient.setColorAt( 0.0, m_colorBarBegin ); gradient.setColorAt( 1.0, m_colorBarEnd ); QRect margin = option->rect; margin.setWidth( 25 ); painter->fillRect( margin, gradient ); QRect background = option->rect; background.setLeft( margin.right() + 1 ); painter->fillRect( background, m_colorMenuBackground ); } if ( const QStyleOptionMenuItem* optionItem = qstyleoption_cast<const QStyleOptionMenuItem*>( option ) ) { if ( optionItem->menuItemType == QStyleOptionMenuItem::Separator ) { painter->setPen( m_colorSeparator ); painter->drawLine( option->rect.left() + 32, ( option->rect.top() + option->rect.bottom() ) / 2, option->rect.right(), ( option->rect.top() + option->rect.bottom() ) / 2 ); return; } QRect checkRect = option->rect.adjusted( 2, 1, -2, -2 ); checkRect.setWidth( 20 ); if ( optionItem->checked && option->state & QStyle::State_Enabled ) { painter->setPen( m_colorItemBorder ); if ( option->state & QStyle::State_Selected && option->state & QStyle::State_Enabled ) painter->setBrush( m_colorItemSunkenBegin ); else painter->setBrush( m_colorItemCheckedBegin ); painter->drawRect( checkRect ); } if ( !optionItem->icon.isNull() ) { QIcon::Mode mode; if ( optionItem->state & State_Enabled ) mode = ( optionItem->state & State_Selected ) ? QIcon::Active : QIcon::Normal; else mode = QIcon::Disabled; QIcon::State state = optionItem->checked ? QIcon::On : QIcon::Off; QPixmap pixmap = optionItem->icon.pixmap( pixelMetric( PM_SmallIconSize, option, widget ), mode, state ); QRect rect = pixmap.rect(); rect.moveCenter( checkRect.center() ); painter->drawPixmap( rect.topLeft(), pixmap ); } else if ( optionItem->checked ) { QStyleOption optionCheckMark; optionCheckMark.initFrom( widget ); optionCheckMark.rect = checkRect; if ( !( option->state & State_Enabled ) ) optionCheckMark.palette.setBrush( QPalette::Text, optionCheckMark.palette.brush( QPalette::Disabled, QPalette::Text ) ); drawPrimitive( PE_IndicatorMenuCheckMark, &optionCheckMark, painter, widget ); } QRect textRect = option->rect.adjusted( 32, 1, -16, -1 ); int flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine; if ( !styleHint( SH_UnderlineShortcut, option, widget ) ) flags |= Qt::TextHideMnemonic; QString text = optionItem->text; int pos = text.indexOf( '\t' ); if ( pos >= 0 ) { drawItemText( painter, textRect, flags | Qt::AlignRight, option->palette, option->state & State_Enabled, text.mid( pos + 1 ), QPalette::Text ); text = text.left( pos ); } drawItemText( painter, textRect, flags, option->palette, option->state & State_Enabled, text, QPalette::Text ); if ( optionItem->menuItemType == QStyleOptionMenuItem::SubMenu ) { QStyleOption optionArrow; optionArrow.initFrom( widget ); optionArrow.rect = option->rect.adjusted( 0, 4, -4, -4 ); optionArrow.rect.setLeft( option->rect.right() - 12 ); optionArrow.state = option->state & State_Enabled; drawPrimitive( PE_IndicatorArrowRight, &optionArrow, painter, widget ); } } return; } case CE_ToolBar: { QRect rect = option->rect; bool vertical = false; if ( const QToolBar* toolBar = qobject_cast<const QToolBar*>( widget ) ) { vertical = ( toolBar->orientation() == Qt::Vertical ); if ( vertical ) rect.setBottom( toolBar->childrenRect().bottom() + 2 ); else rect.setRight( toolBar->childrenRect().right() + 2 ); } painter->save(); QRegion region = rect.adjusted( 2, 0, -2, 0 ); region += rect.adjusted( 0, 2, 0, -2 ); region += rect.adjusted( 1, 1, -1, -1 ); painter->setClipRegion( region ); QLinearGradient gradient; if ( vertical ) gradient = QLinearGradient( rect.topLeft(), rect.topRight() ); else gradient = QLinearGradient( rect.topLeft(), rect.bottomLeft() ); gradient.setColorAt( 0.0, m_colorBarBegin ); gradient.setColorAt( 0.4, m_colorBarMiddle ); gradient.setColorAt( 0.6, m_colorBarMiddle ); gradient.setColorAt( 1.0, m_colorBarEnd ); painter->fillRect( rect, gradient ); painter->setPen( vertical ? m_colorBorderLight : m_colorBorder ); painter->drawLine( rect.bottomLeft() + QPoint( 2, 0 ), rect.bottomRight() - QPoint( 2, 0 ) ); painter->setPen( vertical ? m_colorBorder : m_colorBorderLight ); painter->drawLine( rect.topRight() + QPoint( 0, 2 ), rect.bottomRight() - QPoint( 0, 2 ) ); painter->setPen( m_colorBorderLight ); painter->drawPoint( rect.bottomRight() - QPoint( 1, 1 ) ); painter->restore(); return; } case CE_DockWidgetTitle: { QLinearGradient gradient( option->rect.topLeft(), option->rect.bottomLeft() ); gradient.setColorAt( 0.0, m_colorBarBegin ); gradient.setColorAt( 1.0, m_colorBarEnd ); painter->fillRect( option->rect, gradient ); if ( const QStyleOptionDockWidget* optionDockWidget = qstyleoption_cast<const QStyleOptionDockWidget*>( option ) ) { QRect rect = option->rect.adjusted( 6, 0, -4, 0 ); if ( optionDockWidget->closable ) rect.adjust( 0, 0, -16, 0 ); if ( optionDockWidget->floatable ) rect.adjust( 0, 0, -16, 0 ); QString text = painter->fontMetrics().elidedText( optionDockWidget->title, Qt::ElideRight, rect.width() ); drawItemText( painter, rect, Qt::AlignLeft | Qt::AlignVCenter, option->palette, option->state & State_Enabled, text, QPalette::WindowText ); } return; } case CE_TabBarTabShape: if ( isStyledTabBar( widget ) ) { bool firstTab = false; bool lastTab = false; bool bottom = false; if ( const QStyleOptionTab* optionTab = qstyleoption_cast<const QStyleOptionTab*>( option ) ) { if ( optionTab->position == QStyleOptionTab::Beginning ) firstTab = true; else if ( optionTab->position == QStyleOptionTab::End ) lastTab = true; else if ( optionTab->position == QStyleOptionTab::OnlyOneTab ) firstTab = lastTab = true; if ( optionTab->shape == QTabBar::RoundedSouth ) bottom = true; } QRect rect = option->rect; painter->save(); if ( option->state & State_Selected ) { if ( bottom ) rect.adjust( firstTab ? 0 : -2, -1, lastTab ? -1 : 1, -1 ); else rect.adjust( firstTab ? 0 : -2, 0, lastTab ? -1 : 1, 1 ); } else { if ( bottom ) { rect.adjust( 0, -1, lastTab ? -1 : 0, -2 ); painter->setClipRect( rect.adjusted( 0, 1, 1, 1 ) ); } else { rect.adjust( 0, 1, lastTab ? -1 : 0, 0 ); painter->setClipRect( rect.adjusted( 0, 0, 1, 0 ) ); } } QLinearGradient gradient; if ( bottom ) gradient = QLinearGradient( rect.bottomLeft(), rect.topLeft() ); else gradient = QLinearGradient( rect.topLeft(), rect.bottomLeft() ); if ( option->state & State_Selected ) { gradient.setColorAt( 0.0, m_colorItemBackgroundBegin ); gradient.setColorAt( 1.0, option->palette.window().color() ); painter->setPen( m_colorBorder ); } else if ( option->state & State_MouseOver && option->state & State_Enabled ) { gradient.setColorAt( 0.0, m_colorItemBackgroundBegin ); gradient.setColorAt( 1.0, m_colorItemBackgroundEnd ); painter->setPen( m_colorBorderLight ); } else { gradient.setColorAt( 0.0, m_colorBarMiddle ); gradient.setColorAt( 1.0, m_colorBarEnd ); painter->setPen( m_colorBorderLight ); } painter->setBrush( gradient ); painter->drawRect( rect ); painter->restore(); return; } break; case CE_ToolBoxTabShape: { QRect rect = option->rect.adjusted( 0, 0, -1, -1 ); QLinearGradient gradient( rect.topLeft(), rect.bottomLeft() ); if ( option->state & QStyle::State_Sunken ) { gradient.setColorAt( 0.0, m_colorItemSunkenBegin ); gradient.setColorAt( 1.0, m_colorItemSunkenEnd ); painter->setPen( m_colorBorder ); } else if ( option->state & State_MouseOver && option->state & State_Enabled ) { gradient.setColorAt( 0.0, m_colorItemBackgroundBegin ); gradient.setColorAt( 1.0, m_colorItemBackgroundEnd ); painter->setPen( m_colorBorder ); } else { gradient.setColorAt( 0.0, m_colorBarMiddle ); gradient.setColorAt( 1.0, m_colorBarEnd ); painter->setPen( m_colorBorderLight ); } painter->setBrush( gradient ); painter->drawRect( rect ); return; } case CE_Splitter: if ( qobject_cast<const QMainWindow*>( widget->window() ) ) return; break; default: break; } if ( useVista() ) QWindowsVistaStyle::drawControl( element, option, painter, widget ); else QWindowsXPStyle::drawControl( element, option, painter, widget ); }
void QFontDatabase::load(const QFontPrivate *d, int script) { // sanity checks if(!qApp) qWarning("QFont: Must construct a QApplication before a QFont"); Q_ASSERT(script >= 0 && script < QUnicodeTables::ScriptCount); Q_UNUSED(script); QFontDef req = d->request; req.pixelSize = qt_mac_pixelsize(req, d->dpi); // set the point size to 0 to get better caching req.pointSize = 0; QFontCache::Key key = QFontCache::Key(req, QUnicodeTables::Common, d->screen); if(!(d->engineData = QFontCache::instance()->findEngineData(key))) { d->engineData = new QFontEngineData; QFontCache::instance()->insertEngineData(key, d->engineData); } else { d->engineData->ref.ref(); } if(d->engineData->engine) // already loaded return; // set it to the actual pointsize, so QFontInfo will do the right thing req.pointSize = qRound(qt_mac_pointsize(d->request, d->dpi)); QFontEngine *e = QFontCache::instance()->findEngine(key); if(!e && qt_enable_test_font && req.family == QLatin1String("__Qt__Box__Engine__")) { e = new QTestFontEngine(req.pixelSize); e->fontDef = req; } if(e) { e->ref.ref(); d->engineData->engine = e; return; // the font info and fontdef should already be filled } //find the font QStringList family_list = familyList(req); const char *stylehint = styleHint(req); if (stylehint) family_list << QLatin1String(stylehint); // add QFont::defaultFamily() to the list, for compatibility with // previous versions family_list << QApplication::font().defaultFamily(); ATSFontFamilyRef familyRef = 0; ATSFontRef fontRef = 0; QMutexLocker locker(fontDatabaseMutex()); QFontDatabasePrivate *db = privateDb(); if (!db->count) initializeDb(); for(int i = 0; i < family_list.size(); ++i) { for (int k = 0; k < db->count; ++k) { if (db->families[k]->name.compare(family_list.at(i), Qt::CaseInsensitive) == 0) { QByteArray family_name = db->families[k]->name.toUtf8(); familyRef = ATSFontFamilyFindFromName(QCFString(db->families[k]->name), kATSOptionFlagsDefault); if (familyRef) { fontRef = ATSFontFindFromName(QCFString(db->families[k]->name), kATSOptionFlagsDefault); goto FamilyFound; } else { #if defined(QT_MAC_USE_COCOA) // ATS and CT disagrees on what the family name should be, // use CT to look up the font if ATS fails. QCFString familyName = QString::fromAscii(family_name); QCFType<CTFontRef> CTfontRef = CTFontCreateWithName(familyName, 12, NULL); QCFType<CTFontDescriptorRef> fontDescriptor = CTFontCopyFontDescriptor(CTfontRef); QCFString displayName = (CFStringRef)CTFontDescriptorCopyAttribute(fontDescriptor, kCTFontDisplayNameAttribute); familyRef = ATSFontFamilyFindFromName(displayName, kATSOptionFlagsDefault); if (familyRef) { fontRef = ATSFontFindFromName(displayName, kATSOptionFlagsDefault); goto FamilyFound; } #endif } } } } FamilyFound: //fill in the engine's font definition QFontDef fontDef = d->request; //copy.. if(fontDef.pointSize < 0) fontDef.pointSize = qt_mac_pointsize(fontDef, d->dpi); else fontDef.pixelSize = qt_mac_pixelsize(fontDef, d->dpi); #if 0 ItemCount name_count; if(ATSUCountFontNames(fontID, &name_count) == noErr && name_count) { ItemCount actualName_size; if(ATSUGetIndFontName(fontID, 0, 0, 0, &actualName_size, 0, 0, 0, 0) == noErr && actualName_size) { QByteArray actualName(actualName_size); if(ATSUGetIndFontName(fontID, 0, actualName_size, actualName.data(), &actualName_size, 0, 0, 0, 0) == noErr && actualName_size) fontDef.family = QString::fromUtf8(actualName); } } #else { QCFString actualName; if(ATSFontFamilyGetName(familyRef, kATSOptionFlagsDefault, &actualName) == noErr) fontDef.family = actualName; } #endif #ifdef QT_MAC_USE_COCOA QFontEngine *engine = new QCoreTextFontEngineMulti(familyRef, fontRef, fontDef, d->kerning); #elif 1 QFontEngine *engine = new QFontEngineMacMulti(familyRef, fontRef, fontDef, d->kerning); #else ATSFontFamilyRef atsFamily = familyRef; ATSFontFamilyRef atsFontRef = fontRef; FMFont fontID; FMFontFamily fmFamily; FMFontStyle fntStyle = 0; fmFamily = FMGetFontFamilyFromATSFontFamilyRef(atsFamily); if (fmFamily == kInvalidFontFamily) { // Use the ATSFont then... fontID = FMGetFontFromATSFontRef(atsFontRef); } else { if (fontDef.weight >= QFont::Bold) fntStyle |= ::bold; if (fontDef.style != QFont::StyleNormal) fntStyle |= ::italic; FMFontStyle intrinsicStyle; FMFont fnt = 0; if (FMGetFontFromFontFamilyInstance(fmFamily, fntStyle, &fnt, &intrinsicStyle) == noErr) fontID = FMGetATSFontRefFromFont(fnt); } OSStatus status; const int maxAttributeCount = 5; ATSUAttributeTag tags[maxAttributeCount + 1]; ByteCount sizes[maxAttributeCount + 1]; ATSUAttributeValuePtr values[maxAttributeCount + 1]; int attributeCount = 0; Fixed size = FixRatio(fontDef.pixelSize, 1); tags[attributeCount] = kATSUSizeTag; sizes[attributeCount] = sizeof(size); values[attributeCount] = &size; ++attributeCount; tags[attributeCount] = kATSUFontTag; sizes[attributeCount] = sizeof(fontID); values[attributeCount] = &fontID; ++attributeCount; CGAffineTransform transform = CGAffineTransformIdentity; if (fontDef.stretch != 100) { transform = CGAffineTransformMakeScale(float(fontDef.stretch) / float(100), 1); tags[attributeCount] = kATSUFontMatrixTag; sizes[attributeCount] = sizeof(transform); values[attributeCount] = &transform; ++attributeCount; } ATSUStyle style; status = ATSUCreateStyle(&style); Q_ASSERT(status == noErr); Q_ASSERT(attributeCount < maxAttributeCount + 1); status = ATSUSetAttributes(style, attributeCount, tags, sizes, values); Q_ASSERT(status == noErr); QFontEngine *engine = new QFontEngineMac(style, fontID, fontDef, /*multiEngine*/ 0); ATSUDisposeStyle(style); #endif d->engineData->engine = engine; engine->ref.ref(); //a ref for the engineData->engine QFontCache::instance()->insertEngine(key, engine); }
static QFontEngine *loadFromDatabase(QFontDef &req, const QFontPrivate *d) { #if defined(QT_MAC_USE_COCOA) QCFString fontName = NULL; #else ATSFontFamilyRef familyRef = 0; ATSFontRef fontRef = 0; #endif QStringList family_list = familyList(req); const char *stylehint = styleHint(req); if (stylehint) family_list << QLatin1String(stylehint); // add QFont::defaultFamily() to the list, for compatibility with previous versions family_list << QApplication::font().defaultFamily(); QMutexLocker locker(fontDatabaseMutex()); QFontDatabasePrivate *db = privateDb(); if (!db->count) initializeDb(); for (int i = 0; i < family_list.size(); ++i) { for (int k = 0; k < db->count; ++k) { if (db->families[k]->name.compare(family_list.at(i), Qt::CaseInsensitive) == 0) { #if defined(QT_MAC_USE_COCOA) CFStringRef familyName = QCFString::toCFStringRef(db->families[k]->name); QCFType<CTFontDescriptorRef> descriptor = CTFontDescriptorCreateWithAttributes( QCFType<CFDictionaryRef>(CFDictionaryCreate(kCFAllocatorDefault, (const void**)&kCTFontFamilyNameAttribute, (const void**)&familyName, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks))); CFRelease(familyName); QCFType<CTFontRef> ctFont = CTFontCreateWithFontDescriptor(descriptor, 0, NULL); if (ctFont) { fontName = CTFontCopyFullName(ctFont); goto found; } #else familyRef = ATSFontFamilyFindFromName(QCFString(db->families[k]->name), kATSOptionFlagsDefault); if (familyRef) { fontRef = ATSFontFindFromName(QCFString(db->families[k]->name), kATSOptionFlagsDefault); goto found; } #endif } } } found: #ifdef QT_MAC_USE_COCOA if (fontName) return new QCoreTextFontEngineMulti(fontName, req, d->kerning); #else if (familyRef) { QCFString actualName; if (ATSFontFamilyGetName(familyRef, kATSOptionFlagsDefault, &actualName) == noErr) req.family = actualName; return new QFontEngineMacMulti(familyRef, fontRef, req, d->kerning); } #endif return NULL; }
/*! \reimp */ void QCDEStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *widget) const { switch (pe) { case PE_IndicatorCheckBox: { bool down = opt->state & State_Sunken; bool on = opt->state & State_On; bool showUp = !(down ^ on); QBrush fill = (showUp || (opt->state & State_NoChange)) ? opt->palette.brush(QPalette::Button) : opt->palette.brush(QPalette::Mid); qDrawShadePanel(p, opt->rect, opt->palette, !showUp, pixelMetric(PM_DefaultFrameWidth), &opt->palette.brush(QPalette::Button)); if (on || (opt->state & State_NoChange)) { QRect r = opt->rect; QPolygon a(7 * 2); int i, xx, yy; xx = r.x() + 3; yy = r.y() + 5; if (opt->rect.width() <= 9) { // When called from CE_MenuItem in QMotifStyle xx -= 2; yy -= 2; } for (i = 0; i < 3; i++) { a.setPoint(2 * i, xx, yy); a.setPoint(2 * i + 1, xx, yy + 2); xx++; yy++; } yy -= 2; for (i = 3; i < 7; i++) { a.setPoint(2 * i, xx, yy); a.setPoint(2 * i + 1, xx, yy + 2); xx++; yy--; } if (opt->state & State_NoChange) p->setPen(opt->palette.dark().color()); else p->setPen(opt->palette.foreground().color()); p->drawPolyline(a); } if (!(opt->state & State_Enabled) && styleHint(SH_DitherDisabledText)) p->fillRect(opt->rect, QBrush(p->background().color(), Qt::Dense5Pattern)); } break; case PE_IndicatorRadioButton: { QRect r = opt->rect; #define INTARRLEN(x) sizeof(x)/(sizeof(int)*2) static const int pts1[] = { // up left lines 1,9, 1,8, 0,7, 0,4, 1,3, 1,2, 2,1, 3,1, 4,0, 7,0, 8,1, 9,1 }; static const int pts4[] = { // bottom right lines 2,10, 3,10, 4,11, 7,11, 8,10, 9,10, 10,9, 10,8, 11,7, 11,4, 10,3, 10,2 }; static const int pts5[] = { // inner fill 4,2, 7,2, 9,4, 9,7, 7,9, 4,9, 2,7, 2,4 }; bool down = opt->state & State_Sunken; bool on = opt->state & State_On; QPolygon a(INTARRLEN(pts1), pts1); //center when rect is larger than indicator size int xOffset = 0; int yOffset = 0; int indicatorWidth = pixelMetric(PM_ExclusiveIndicatorWidth); int indicatorHeight = pixelMetric(PM_ExclusiveIndicatorWidth); if (r.width() > indicatorWidth) xOffset += (r.width() - indicatorWidth)/2; if (r.height() > indicatorHeight) yOffset += (r.height() - indicatorHeight)/2; p->translate(xOffset, yOffset); a.translate(r.x(), r.y()); QPen oldPen = p->pen(); QBrush oldBrush = p->brush(); p->setPen((down || on) ? opt->palette.dark().color() : opt->palette.light().color()); p->drawPolyline(a); a.setPoints(INTARRLEN(pts4), pts4); a.translate(r.x(), r.y()); p->setPen((down || on) ? opt->palette.light().color() : opt->palette.dark().color()); p->drawPolyline(a); a.setPoints(INTARRLEN(pts5), pts5); a.translate(r.x(), r.y()); QColor fillColor = on ? opt->palette.dark().color() : opt->palette.background().color(); p->setPen(fillColor); p->setBrush(on ? opt->palette.brush(QPalette::Dark) : opt->palette.brush(QPalette::Window)); p->drawPolygon(a); if (!(opt->state & State_Enabled) && styleHint(SH_DitherDisabledText)) p->fillRect(opt->rect, QBrush(p->background().color(), Qt::Dense5Pattern)); p->setPen(oldPen); p->setBrush(oldBrush); p->translate(-xOffset, -yOffset); } break; default: QMotifStyle::drawPrimitive(pe, opt, p, widget); } }
void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const { if (!panelWidget(widget)) return QProxyStyle::drawComplexControl(control, option, painter, widget); QRect rect = option->rect; switch (control) { case CC_ToolButton: if (const QStyleOptionToolButton *toolbutton = qstyleoption_cast<const QStyleOptionToolButton *>(option)) { QRect button, menuarea; button = subControlRect(control, toolbutton, SC_ToolButton, widget); menuarea = subControlRect(control, toolbutton, SC_ToolButtonMenu, widget); State bflags = toolbutton->state; if (bflags & State_AutoRaise) { if (!(bflags & State_MouseOver)) { bflags &= ~State_Raised; } } State mflags = bflags; if (toolbutton->state & State_Sunken) { if (toolbutton->activeSubControls & SC_ToolButton) bflags |= State_Sunken; if (toolbutton->activeSubControls & SC_ToolButtonMenu) mflags |= State_Sunken; } QStyleOption tool(0); tool.palette = toolbutton->palette; if (toolbutton->subControls & SC_ToolButton) { tool.rect = button; tool.state = bflags; drawPrimitive(PE_PanelButtonTool, &tool, painter, widget); } QStyleOptionToolButton label = *toolbutton; label.palette = panelPalette(option->palette, lightColored(widget)); int fw = pixelMetric(PM_DefaultFrameWidth, option, widget); label.rect = button.adjusted(fw, fw, -fw, -fw); drawControl(CE_ToolButtonLabel, &label, painter, widget); if (toolbutton->subControls & SC_ToolButtonMenu) { tool.state = mflags; tool.rect = menuarea.adjusted(1, 1, -1, -1); if (mflags & (State_Sunken | State_On | State_Raised)) { painter->setPen(Qt::gray); painter->drawLine(tool.rect.topLeft(), tool.rect.bottomLeft()); if (mflags & (State_Sunken)) { QColor shade(0, 0, 0, 50); painter->fillRect(tool.rect.adjusted(0, -1, 1, 1), shade); } #ifndef Q_WS_MAC else if (mflags & (State_MouseOver)) { QColor shade(255, 255, 255, 50); painter->fillRect(tool.rect.adjusted(0, -1, 1, 1), shade); } #endif } tool.rect = tool.rect.adjusted(2, 2, -2, -2); drawPrimitive(PE_IndicatorArrowDown, &tool, painter, widget); } else if (toolbutton->features & QStyleOptionToolButton::HasMenu && !widget->property("noArrow").toBool()) { int arrowSize = 6; QRect ir = toolbutton->rect.adjusted(1, 1, -1, -1); QStyleOptionToolButton newBtn = *toolbutton; newBtn.palette = panelPalette(option->palette); newBtn.rect = QRect(ir.right() - arrowSize - 1, ir.height() - arrowSize - 2, arrowSize, arrowSize); drawPrimitive(PE_IndicatorArrowDown, &newBtn, painter, widget); } } break; case CC_ComboBox: if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) { painter->save(); bool isEmpty = cb->currentText.isEmpty() && cb->currentIcon.isNull(); bool reverse = option->direction == Qt::RightToLeft; bool drawborder = !(widget && widget->property("hideborder").toBool()); bool alignarrow = !(widget && widget->property("alignarrow").toBool()); // Draw tool button if (drawborder) { QLinearGradient grad(option->rect.topRight(), option->rect.bottomRight()); grad.setColorAt(0, QColor(255, 255, 255, 20)); grad.setColorAt(0.4, QColor(255, 255, 255, 60)); grad.setColorAt(0.7, QColor(255, 255, 255, 50)); grad.setColorAt(1, QColor(255, 255, 255, 40)); painter->setPen(QPen(grad, 0)); painter->drawLine(rect.topRight(), rect.bottomRight()); grad.setColorAt(0, QColor(0, 0, 0, 30)); grad.setColorAt(0.4, QColor(0, 0, 0, 70)); grad.setColorAt(0.7, QColor(0, 0, 0, 70)); grad.setColorAt(1, QColor(0, 0, 0, 40)); painter->setPen(QPen(grad, 0)); if (!reverse) painter->drawLine(rect.topRight() - QPoint(1,0), rect.bottomRight() - QPoint(1,0)); else painter->drawLine(rect.topLeft(), rect.bottomLeft()); } QStyleOption toolbutton = *option; if (isEmpty) toolbutton.state &= ~(State_Enabled | State_Sunken); painter->save(); if (drawborder) painter->setClipRect(toolbutton.rect.adjusted(0, 0, -2, 0)); drawPrimitive(PE_PanelButtonTool, &toolbutton, painter, widget); painter->restore(); // Draw arrow int menuButtonWidth = 12; int left = !reverse ? rect.right() - menuButtonWidth : rect.left(); int right = !reverse ? rect.right() : rect.left() + menuButtonWidth; QRect arrowRect((left + right) / 2 + (reverse ? 6 : -6), rect.center().y() - 3, 9, 9); if (!alignarrow) { int labelwidth = option->fontMetrics.width(cb->currentText); if (reverse) arrowRect.moveLeft(qMax(rect.width() - labelwidth - menuButtonWidth - 2, 4)); else arrowRect.moveLeft(qMin(labelwidth + menuButtonWidth - 2, rect.width() - menuButtonWidth - 4)); } if (option->state & State_On) arrowRect.translate(QProxyStyle::pixelMetric(PM_ButtonShiftHorizontal, option, widget), QProxyStyle::pixelMetric(PM_ButtonShiftVertical, option, widget)); QStyleOption arrowOpt = *option; arrowOpt.rect = arrowRect; if (isEmpty) arrowOpt.state &= ~(State_Enabled | State_Sunken); if (styleHint(SH_ComboBox_Popup, option, widget)) { arrowOpt.rect.translate(0, -3); drawPrimitive(PE_IndicatorArrowUp, &arrowOpt, painter, widget); arrowOpt.rect.translate(0, 6); drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, painter, widget); } else { drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, painter, widget); } painter->restore(); } break; default: QProxyStyle::drawComplexControl(control, option, painter, widget); break; } }
void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const { if (!panelWidget(widget)) return QProxyStyle::drawControl(element, option, painter, widget); switch (element) { case CE_Splitter: painter->fillRect(option->rect, Utils::StyleHelper::borderColor()); break; case CE_TabBarTabShape: // Most styles draw a single dark outline. This looks rather ugly when combined with our // single pixel dark separator so we adjust the first tab to compensate for this if (const QStyleOptionTabV3 *tab = qstyleoption_cast<const QStyleOptionTabV3 *>(option)) { QStyleOptionTabV3 adjustedTab = *tab; if (tab->cornerWidgets == QStyleOptionTab::NoCornerWidgets && ( tab->position == QStyleOptionTab::Beginning || tab->position == QStyleOptionTab::OnlyOneTab)) { if (option->direction == Qt::LeftToRight) adjustedTab.rect = adjustedTab.rect.adjusted(-1, 0, 0, 0); else adjustedTab.rect = adjustedTab.rect.adjusted(0, 0, 1 ,0); } QProxyStyle::drawControl(element, &adjustedTab, painter, widget); return; } break; case CE_MenuBarItem: painter->save(); if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) { QColor highlightOutline = Utils::StyleHelper::borderColor().lighter(120); bool act = mbi->state & State_Selected && mbi->state & State_Sunken; bool dis = !(mbi->state & State_Enabled); Utils::StyleHelper::menuGradient(painter, option->rect, option->rect); QStyleOptionMenuItem item = *mbi; item.rect = mbi->rect; QPalette pal = mbi->palette; pal.setBrush(QPalette::ButtonText, dis ? Qt::gray : Qt::black); item.palette = pal; QCommonStyle::drawControl(element, &item, painter, widget); QRect r = option->rect; if (act) { // Fill| QColor baseColor = Utils::StyleHelper::baseColor(); QLinearGradient grad(option->rect.topLeft(), option->rect.bottomLeft()); grad.setColorAt(0, baseColor.lighter(120)); grad.setColorAt(1, baseColor.lighter(130)); painter->fillRect(option->rect.adjusted(1, 1, -1, 0), grad); // Outline painter->setPen(QPen(highlightOutline, 0)); painter->drawLine(QPoint(r.left(), r.top() + 1), QPoint(r.left(), r.bottom())); painter->drawLine(QPoint(r.right(), r.top() + 1), QPoint(r.right(), r.bottom())); painter->drawLine(QPoint(r.left() + 1, r.top()), QPoint(r.right() - 1, r.top())); highlightOutline.setAlpha(60); painter->setPen(QPen(highlightOutline, 0)); painter->drawPoint(r.topLeft()); painter->drawPoint(r.topRight()); QPalette pal = mbi->palette; uint alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine; if (!styleHint(SH_UnderlineShortcut, mbi, widget)) alignment |= Qt::TextHideMnemonic; pal.setBrush(QPalette::Text, dis ? Qt::gray : QColor(0, 0, 0, 60)); drawItemText(painter, item.rect.translated(0, 1), alignment, pal, mbi->state & State_Enabled, mbi->text, QPalette::Text); pal.setBrush(QPalette::Text, dis ? Qt::gray : Qt::white); drawItemText(painter, item.rect, alignment, pal, mbi->state & State_Enabled, mbi->text, QPalette::Text); } } painter->restore(); break; case CE_ComboBoxLabel: if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) { if (panelWidget(widget)) { painter->save(); QRect editRect = subControlRect(CC_ComboBox, cb, SC_ComboBoxEditField, widget); QPalette customPal = cb->palette; if (!cb->currentIcon.isNull()) { QIcon::Mode mode = cb->state & State_Enabled ? QIcon::Normal : QIcon::Disabled; QPixmap pixmap = cb->currentIcon.pixmap(cb->iconSize, mode); QRect iconRect(editRect); iconRect.setWidth(cb->iconSize.width() + 4); iconRect = alignedRect(cb->direction, Qt::AlignLeft | Qt::AlignVCenter, iconRect.size(), editRect); if (cb->editable) painter->fillRect(iconRect, customPal.brush(QPalette::Base)); drawItemPixmap(painter, iconRect, Qt::AlignCenter, pixmap); if (cb->direction == Qt::RightToLeft) editRect.translate(-4 - cb->iconSize.width(), 0); else editRect.translate(cb->iconSize.width() + 4, 0); // Reserve some space for the down-arrow editRect.adjust(0, 0, -13, 0); } QString text = option->fontMetrics.elidedText(cb->currentText, Qt::ElideRight, editRect.width()); if ((option->state & State_Enabled)) { painter->setPen(QColor(0, 0, 0, 70)); painter->drawText(editRect.adjusted(1, 0, -1, 0), Qt::AlignLeft | Qt::AlignVCenter, text); } else { painter->setOpacity(0.8); } painter->setPen(Utils::StyleHelper::panelTextColor()); painter->drawText(editRect.adjusted(1, 0, -1, 0), Qt::AlignLeft | Qt::AlignVCenter, text); painter->restore(); } else { QProxyStyle::drawControl(element, option, painter, widget); } } break; case CE_SizeGrip: { painter->save(); QColor dark = Qt::white; dark.setAlphaF(0.1); int x, y, w, h; option->rect.getRect(&x, &y, &w, &h); int sw = qMin(h, w); if (h > w) painter->translate(0, h - w); else painter->translate(w - h, 0); int sx = x; int sy = y; int s = 4; painter->setPen(dark); if (option->direction == Qt::RightToLeft) { sx = x + sw; for (int i = 0; i < 4; ++i) { painter->drawLine(x, sy, sx, sw); sx -= s; sy += s; } } else { for (int i = 0; i < 4; ++i) { painter->drawLine(sx, sw, sw, sy); sx += s; sy += s; } } painter->restore(); } break; case CE_MenuBarEmptyArea: { Utils::StyleHelper::menuGradient(painter, option->rect, option->rect); painter->save(); painter->setPen(Utils::StyleHelper::borderColor()); painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight()); painter->restore(); } break; case CE_ToolBar: { QRect rect = option->rect; bool horizontal = option->state & State_Horizontal; rect = option->rect; // Map offset for global window gradient QPoint offset = widget->window()->mapToGlobal(option->rect.topLeft()) - widget->mapToGlobal(option->rect.topLeft()); QRect gradientSpan; if (widget) gradientSpan = QRect(offset, widget->window()->size()); bool drawLightColored = lightColored(widget); if (horizontal) Utils::StyleHelper::horizontalGradient(painter, gradientSpan, rect, drawLightColored); else Utils::StyleHelper::verticalGradient(painter, gradientSpan, rect, drawLightColored); if (!drawLightColored) painter->setPen(Utils::StyleHelper::borderColor()); else painter->setPen(QColor(0x888888)); if (horizontal) { // Note: This is a hack to determine if the // toolbar should draw the top or bottom outline // (needed for the find toolbar for instance) QColor lighter(Utils::StyleHelper::sidebarHighlight()); if (drawLightColored) lighter = QColor(255, 255, 255, 180); if (widget && widget->property("topBorder").toBool()) { painter->drawLine(rect.topLeft(), rect.topRight()); painter->setPen(lighter); painter->drawLine(rect.topLeft() + QPoint(0, 1), rect.topRight() + QPoint(0, 1)); } else { painter->drawLine(rect.bottomLeft(), rect.bottomRight()); painter->setPen(lighter); painter->drawLine(rect.topLeft(), rect.topRight()); } } else { painter->drawLine(rect.topLeft(), rect.bottomLeft()); painter->drawLine(rect.topRight(), rect.bottomRight()); } } break; default: QProxyStyle::drawControl(element, option, painter, widget); break; } }
void TabBarWidgetMacStyle::drawControl(ControlElement pElement, const QStyleOption *pOption, QPainter *pPainter, const QWidget *pWidget) const { // Draw a tab bar tab label // Note: anything else is done by our parent... if (pElement == CE_TabBarTabLabel) { // Note: adapted from QCommonStyle::drawControl()... if (auto tab = qstyleoption_cast<const QStyleOptionTab *>(pOption)) { uint alignment = Qt::AlignCenter|Qt::TextShowMnemonic; if (styleHint(SH_UnderlineShortcut, pOption, pWidget) == 0) { alignment |= Qt::TextHideMnemonic; } bool isVerticalTab = (tab->shape == QTabBar::RoundedWest) || (tab->shape == QTabBar::RoundedEast) || (tab->shape == QTabBar::TriangularWest) || (tab->shape == QTabBar::TriangularEast); QRect tabRect = tab->rect; if (isVerticalTab) { pPainter->save(); int x, y, rotation; if ( (tab->shape == QTabBar::RoundedEast) || (tab->shape == QTabBar::TriangularEast)) { x = tabRect.x()+tabRect.width(); y = tabRect.y(); rotation = 90; } else { x = tabRect.x(); y = tabRect.y()+tabRect.height(); rotation = -90; } QTransform transform = QTransform::fromTranslate(x, y); transform.rotate(rotation); pPainter->setTransform(transform, true); } QRect iconRect; tabLayout(tab, pWidget, &tabRect, &iconRect); if (!tab->icon.isNull()) { pPainter->drawPixmap(iconRect.x(), iconRect.y(), tab->icon.pixmap(pWidget->window()->windowHandle(), tab->iconSize, ((tab->state & State_Enabled) != 0)? QIcon::Normal: QIcon::Disabled, ((tab->state & State_Selected) != 0)? QIcon::On: QIcon::Off)); } drawItemText(pPainter, tabRect, int(alignment), tab->palette, (tab->state & State_Enabled) != 0, tab->text, ( ((tab->state & State_Selected) != 0) && ((tab->state & State_Active) != 0))? QPalette::BrightText: QPalette::WindowText); if (isVerticalTab) { pPainter->restore(); } if ((tab->state & State_HasFocus) != 0) { const int Offset = 1+pixelMetric(PM_DefaultFrameWidth); int x1 = tab->rect.left(); int x2 = tab->rect.right()-1; QStyleOptionFocusRect option; option.QStyleOption::operator=(*tab); option.rect.setRect(x1+1+Offset, tab->rect.y()+Offset, x2-x1-2*Offset, tab->rect.height()-2*Offset); drawPrimitive(PE_FrameFocusRect, &option, pPainter, pWidget); } } } else { QProxyStyle::drawControl(pElement, pOption, pPainter, pWidget); } }
void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const { if (!panelWidget(widget)) return QProxyStyle::drawControl(element, option, painter, widget); switch (element) { case CE_Splitter: painter->fillRect(option->rect, StyleHelper::borderColor()); break; case CE_TabBarTabShape: // Most styles draw a single dark outline. This looks rather ugly when combined with our // single pixel dark separator so we adjust the first tab to compensate for this if (const QStyleOptionTabV3 *tab = qstyleoption_cast<const QStyleOptionTabV3 *>(option)) { QStyleOptionTabV3 adjustedTab = *tab; if (tab->cornerWidgets == QStyleOptionTab::NoCornerWidgets && ( tab->position == QStyleOptionTab::Beginning || tab->position == QStyleOptionTab::OnlyOneTab)) { if (option->direction == Qt::LeftToRight) adjustedTab.rect = adjustedTab.rect.adjusted(-1, 0, 0, 0); else adjustedTab.rect = adjustedTab.rect.adjusted(0, 0, 1 ,0); } QProxyStyle::drawControl(element, &adjustedTab, painter, widget); return; } break; case CE_MenuBarItem: painter->save(); if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) { QColor highlightOutline = StyleHelper::borderColor().lighter(120); bool act = mbi->state & State_Sunken; bool dis = !(mbi->state & State_Enabled); StyleHelper::menuGradient(painter, option->rect, option->rect); QStyleOptionMenuItem item = *mbi; item.rect = mbi->rect; QPalette pal = mbi->palette; pal.setBrush(QPalette::ButtonText, dis ? Qt::gray : Qt::black); item.palette = pal; QCommonStyle::drawControl(element, &item, painter, widget); QRect r = option->rect; if (act) { // Fill| QColor baseColor = StyleHelper::baseColor(); QLinearGradient grad(option->rect.topLeft(), option->rect.bottomLeft()); grad.setColorAt(0, baseColor.lighter(120)); grad.setColorAt(1, baseColor.lighter(130)); painter->fillRect(option->rect.adjusted(1, 1, -1, 0), grad); // Outline painter->setPen(QPen(highlightOutline, 0)); painter->drawLine(QPoint(r.left(), r.top() + 1), QPoint(r.left(), r.bottom())); painter->drawLine(QPoint(r.right(), r.top() + 1), QPoint(r.right(), r.bottom())); painter->drawLine(QPoint(r.left() + 1, r.top()), QPoint(r.right() - 1, r.top())); highlightOutline.setAlpha(60); painter->setPen(QPen(highlightOutline, 0)); painter->drawPoint(r.topLeft()); painter->drawPoint(r.topRight()); QPalette pal = mbi->palette; uint alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine; if (!styleHint(SH_UnderlineShortcut, mbi, widget)) alignment |= Qt::TextHideMnemonic; pal.setBrush(QPalette::Text, dis ? Qt::gray : QColor(0, 0, 0, 60)); drawItemText(painter, item.rect.translated(0, 1), alignment, pal, mbi->state & State_Enabled, mbi->text, QPalette::Text); pal.setBrush(QPalette::Text, dis ? Qt::gray : Qt::white); drawItemText(painter, item.rect, alignment, pal, mbi->state & State_Enabled, mbi->text, QPalette::Text); } } painter->restore(); break; case CE_ComboBoxLabel: if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) { if (panelWidget(widget)) { painter->save(); QRect editRect = subControlRect(CC_ComboBox, cb, SC_ComboBoxEditField, widget); QPalette customPal = cb->palette; bool drawIcon = !(widget && widget->property("hideicon").toBool()); if (!cb->currentIcon.isNull() && drawIcon) { QIcon::Mode mode = cb->state & State_Enabled ? QIcon::Normal : QIcon::Disabled; QPixmap pixmap = cb->currentIcon.pixmap(cb->iconSize, mode); QRect iconRect(editRect); iconRect.setWidth(cb->iconSize.width() + 4); iconRect = alignedRect(cb->direction, Qt::AlignLeft | Qt::AlignVCenter, iconRect.size(), editRect); if (cb->editable) painter->fillRect(iconRect, customPal.brush(QPalette::Base)); drawItemPixmap(painter, iconRect, Qt::AlignCenter, pixmap); if (cb->direction == Qt::RightToLeft) editRect.translate(-4 - cb->iconSize.width(), 0); else editRect.translate(cb->iconSize.width() + 4, 0); // Reserve some space for the down-arrow editRect.adjust(0, 0, -13, 0); } QLatin1Char asterisk('*'); int elideWidth = editRect.width(); bool notElideAsterisk = widget && widget->property("notelideasterisk").toBool() && cb->currentText.endsWith(asterisk) && option->fontMetrics.width(cb->currentText) > elideWidth; QString text; if (notElideAsterisk) { elideWidth -= option->fontMetrics.width(asterisk); text = asterisk; } text.prepend(option->fontMetrics.elidedText(cb->currentText, Qt::ElideRight, elideWidth)); if ((option->state & State_Enabled)) { painter->setPen(QColor(0, 0, 0, 70)); painter->drawText(editRect.adjusted(1, 0, -1, 0), Qt::AlignLeft | Qt::AlignVCenter, text); } else { painter->setOpacity(0.8); } painter->setPen(StyleHelper::panelTextColor()); painter->drawText(editRect.adjusted(1, 0, -1, 0), Qt::AlignLeft | Qt::AlignVCenter, text); painter->restore(); } else { QProxyStyle::drawControl(element, option, painter, widget); } } break; case CE_SizeGrip: { painter->save(); QColor dark = Qt::white; dark.setAlphaF(0.1); int x, y, w, h; option->rect.getRect(&x, &y, &w, &h); int sw = qMin(h, w); if (h > w) painter->translate(0, h - w); else painter->translate(w - h, 0); int sx = x; int sy = y; int s = 4; painter->setPen(dark); if (option->direction == Qt::RightToLeft) { sx = x + sw; for (int i = 0; i < 4; ++i) { painter->drawLine(x, sy, sx, sw); sx -= s; sy += s; } } else { for (int i = 0; i < 4; ++i) { painter->drawLine(sx, sw, sw, sy); sx += s; sy += s; } } painter->restore(); } break; case CE_MenuBarEmptyArea: { StyleHelper::menuGradient(painter, option->rect, option->rect); painter->save(); painter->setPen(StyleHelper::borderColor()); painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight()); painter->restore(); } break; case CE_ToolBar: { QRect rect = option->rect; bool horizontal = option->state & State_Horizontal; rect = option->rect; // Map offset for global window gradient QPoint offset = widget->window()->mapToGlobal(option->rect.topLeft()) - widget->mapToGlobal(option->rect.topLeft()); QRect gradientSpan; if (widget) gradientSpan = QRect(offset, widget->window()->size()); bool drawLightColored = lightColored(widget); if (horizontal) StyleHelper::horizontalGradient(painter, gradientSpan, rect, drawLightColored); else StyleHelper::verticalGradient(painter, gradientSpan, rect, drawLightColored); if (!drawLightColored) painter->setPen(StyleHelper::borderColor()); else painter->setPen(QColor(0x888888)); if (horizontal) { // Note: This is a hack to determine if the // toolbar should draw the top or bottom outline // (needed for the find toolbar for instance) QColor lighter(StyleHelper::sidebarHighlight()); if (drawLightColored) lighter = QColor(255, 255, 255, 180); if (widget && widget->property("topBorder").toBool()) { painter->drawLine(rect.topLeft(), rect.topRight()); painter->setPen(lighter); painter->drawLine(rect.topLeft() + QPoint(0, 1), rect.topRight() + QPoint(0, 1)); } else { painter->drawLine(rect.bottomLeft(), rect.bottomRight()); painter->setPen(lighter); painter->drawLine(rect.topLeft(), rect.topRight()); } } else { painter->drawLine(rect.topLeft(), rect.bottomLeft()); painter->drawLine(rect.topRight(), rect.bottomRight()); } } break; #if defined(Q_OS_MAC) case CE_ToolButtonLabel: if (const QStyleOptionToolButton *tb = qstyleoption_cast<const QStyleOptionToolButton *>(option)) { QStyleOptionToolButton myTb = *tb; myTb.state &= ~State_AutoRaise; QRect cr = tb->rect; bool needText = false; int alignment = 0; bool down = tb->state & (State_Sunken | State_On); // The down state is special for QToolButtons in a toolbar on the Mac // The text is a bit bolder and gets a drop shadow and the icons are also darkened. // This doesn't really fit into any particular case in QIcon, so we // do the majority of the work ourselves. if (!(tb->features & QStyleOptionToolButton::Arrow)) { Qt::ToolButtonStyle tbstyle = tb->toolButtonStyle; if (tb->icon.isNull() && !tb->text.isEmpty()) tbstyle = Qt::ToolButtonTextOnly; switch (tbstyle) { case Qt::ToolButtonTextOnly: { needText = true; alignment = Qt::AlignCenter; break; } case Qt::ToolButtonIconOnly: case Qt::ToolButtonTextBesideIcon: case Qt::ToolButtonTextUnderIcon: { QRect pr = cr; QIcon::Mode iconMode = (tb->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled; QIcon::State iconState = (tb->state & State_On) ? QIcon::On : QIcon::Off; QPixmap pixmap = tb->icon.pixmap(tb->rect.size().boundedTo(tb->iconSize), iconMode, iconState); // Draw the text if it's needed. if (tb->toolButtonStyle != Qt::ToolButtonIconOnly) { needText = true; if (tb->toolButtonStyle == Qt::ToolButtonTextUnderIcon) { QMainWindow *mw = widget ? qobject_cast<QMainWindow *>(widget->window()) : 0; if (mw && mw->unifiedTitleAndToolBarOnMac()) { pr.setHeight(pixmap.size().height() / pixmap.devicePixelRatio()); cr.adjust(0, pr.bottom() + 1, 0, 1); } else { pr.setHeight(pixmap.size().height() / pixmap.devicePixelRatio() + 6); cr.adjust(0, pr.bottom(), 0, -3); } alignment |= Qt::AlignCenter; } else { pr.setWidth(pixmap.width() / pixmap.devicePixelRatio() + 8); cr.adjust(pr.right(), 0, 0, 0); alignment |= Qt::AlignLeft | Qt::AlignVCenter; } } proxy()->drawItemPixmap(painter, pr, Qt::AlignCenter, pixmap); break; } default: Q_ASSERT(false); break; } if (needText) { QPalette pal = tb->palette; QPalette::ColorRole role = QPalette::WindowText; if (!proxy()->styleHint(SH_UnderlineShortcut, tb, widget)) alignment |= Qt::TextHideMnemonic; if (tbstyle == Qt::ToolButtonTextOnly || (tbstyle != Qt::ToolButtonTextOnly && !down)) { painter->drawText(cr, alignment, tb->text); if (down && tbstyle == Qt::ToolButtonTextOnly) { pal = QApplication::palette("QMenu"); pal.setCurrentColorGroup(tb->palette.currentColorGroup()); role = QPalette::HighlightedText; } } proxy()->drawItemText(painter, cr, alignment, pal, tb->state & State_Enabled, tb->text, role); } } else { QProxyStyle::drawControl(element, option, painter, widget); } } break; #endif default: QProxyStyle::drawControl(element, option, painter, widget); break; } }
void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const { if (!panelWidget(widget)) return d->style->drawControl(element, option, painter, widget); switch (element) { case CE_MenuBarItem: painter->save(); if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) { QColor highlightOutline = StyleHelper::borderColor().lighter(120); bool act = mbi->state & State_Selected && mbi->state & State_Sunken; bool dis = !(mbi->state & State_Enabled); StyleHelper::menuGradient(painter, option->rect, option->rect); QStyleOptionMenuItem item = *mbi; item.rect = mbi->rect; QPalette pal = mbi->palette; pal.setBrush(QPalette::ButtonText, dis ? Qt::gray : Qt::black); item.palette = pal; QCommonStyle::drawControl(element, &item, painter, widget); QRect r = option->rect; if (act) { // Fill| QColor baseColor = StyleHelper::baseColor(); QLinearGradient grad(option->rect.topLeft(), option->rect.bottomLeft()); grad.setColorAt(0, baseColor.lighter(120)); grad.setColorAt(1, baseColor.lighter(130)); painter->fillRect(option->rect.adjusted(1, 1, -1, 0), grad); // Outline painter->setPen(QPen(highlightOutline, 0)); painter->drawLine(QPoint(r.left(), r.top() + 1), QPoint(r.left(), r.bottom())); painter->drawLine(QPoint(r.right(), r.top() + 1), QPoint(r.right(), r.bottom())); painter->drawLine(QPoint(r.left() + 1, r.top()), QPoint(r.right() - 1, r.top())); highlightOutline.setAlpha(60); painter->setPen(QPen(highlightOutline, 0)); painter->drawPoint(r.topLeft()); painter->drawPoint(r.topRight()); QPalette pal = mbi->palette; uint alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine; if (!styleHint(SH_UnderlineShortcut, mbi, widget)) alignment |= Qt::TextHideMnemonic; pal.setBrush(QPalette::Text, dis ? Qt::gray : QColor(0, 0, 0, 60)); drawItemText(painter, item.rect.translated(0, 1), alignment, pal, mbi->state & State_Enabled, mbi->text, QPalette::Text); pal.setBrush(QPalette::Text, dis ? Qt::gray : Qt::white); drawItemText(painter, item.rect, alignment, pal, mbi->state & State_Enabled, mbi->text, QPalette::Text); } } painter->restore(); break; case CE_ComboBoxLabel: if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) { if (panelWidget(widget)) { QRect editRect = subControlRect(CC_ComboBox, cb, SC_ComboBoxEditField, widget); QPalette customPal = cb->palette; if (!cb->currentIcon.isNull()) { QIcon::Mode mode = cb->state & State_Enabled ? QIcon::Normal : QIcon::Disabled; QPixmap pixmap = cb->currentIcon.pixmap(cb->iconSize, mode); QRect iconRect(editRect); iconRect.setWidth(cb->iconSize.width() + 4); iconRect = alignedRect(cb->direction, Qt::AlignLeft | Qt::AlignVCenter, iconRect.size(), editRect); if (cb->editable) painter->fillRect(iconRect, customPal.brush(QPalette::Base)); drawItemPixmap(painter, iconRect, Qt::AlignCenter, pixmap); if (cb->direction == Qt::RightToLeft) editRect.translate(-4 - cb->iconSize.width(), 0); else editRect.translate(cb->iconSize.width() + 4, 0); // Reserve some space for the down-arrow editRect.adjust(0, 0, -13, 0); } customPal.setBrush(QPalette::All, QPalette::ButtonText, QColor(0, 0, 0, 70)); QString text = option->fontMetrics.elidedText(cb->currentText, Qt::ElideRight, editRect.width()); drawItemText(painter, editRect.translated(0, 1), visualAlignment(option->direction, Qt::AlignLeft | Qt::AlignVCenter), customPal, cb->state & State_Enabled, text, QPalette::ButtonText); customPal.setBrush(QPalette::All, QPalette::ButtonText, StyleHelper::panelTextColor()); drawItemText(painter, editRect, visualAlignment(option->direction, Qt::AlignLeft | Qt::AlignVCenter), customPal, cb->state & State_Enabled, text, QPalette::ButtonText); } else { d->style->drawControl(element, option, painter, widget); } } break; case CE_SizeGrip: { painter->save(); QColor dark = Qt::white; dark.setAlphaF(0.1); int x, y, w, h; option->rect.getRect(&x, &y, &w, &h); int sw = qMin(h, w); if (h > w) painter->translate(0, h - w); else painter->translate(w - h, 0); int sx = x; int sy = y; int s = 4; painter->setPen(dark); if (option->direction == Qt::RightToLeft) { sx = x + sw; for (int i = 0; i < 4; ++i) { painter->drawLine(x, sy, sx, sw); sx -= s; sy += s; } } else { for (int i = 0; i < 4; ++i) { painter->drawLine(sx, sw, sw, sy); sx += s; sy += s; } } painter->restore(); } break; case CE_MenuBarEmptyArea: { StyleHelper::menuGradient(painter, option->rect, option->rect); painter->save(); painter->setPen(StyleHelper::borderColor()); painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight()); painter->restore(); } break; case CE_ToolBar: { QString key; key.sprintf("mh_toolbar %d %d %d", option->rect.width(), option->rect.height(), StyleHelper::baseColor().rgb());; QPixmap pixmap; QPainter *p = painter; QRect rect = option->rect; if (StyleHelper::usePixmapCache() && !QPixmapCache::find(key, pixmap)) { pixmap = QPixmap(option->rect.size()); p = new QPainter(&pixmap); rect = QRect(0, 0, option->rect.width(), option->rect.height()); } bool horizontal = option->state & State_Horizontal; // Map offset for global window gradient QPoint offset = widget->window()->mapToGlobal(option->rect.topLeft()) - widget->mapToGlobal(option->rect.topLeft()); QRect gradientSpan; if (widget) { gradientSpan = QRect(offset, widget->window()->size()); } if (horizontal) StyleHelper::horizontalGradient(p, gradientSpan, rect); else StyleHelper::verticalGradient(p, gradientSpan, rect); painter->setPen(StyleHelper::borderColor()); if (horizontal) { // Note: This is a hack to determine if the // toolbar should draw the top or bottom outline // (needed for the find toolbar for instance) QColor lighter(255, 255, 255, 40); if (widget && widget->property("topBorder").toBool()) { p->drawLine(rect.topLeft(), rect.topRight()); p->setPen(lighter); p->drawLine(rect.topLeft() + QPoint(0, 1), rect.topRight() + QPoint(0, 1)); } else { p->drawLine(rect.bottomLeft(), rect.bottomRight()); p->setPen(lighter); p->drawLine(rect.topLeft(), rect.topRight()); } } else { p->drawLine(rect.topLeft(), rect.bottomLeft()); p->drawLine(rect.topRight(), rect.bottomRight()); } if (StyleHelper::usePixmapCache() && !QPixmapCache::find(key, pixmap)) { painter->drawPixmap(rect.topLeft(), pixmap); p->end(); delete p; QPixmapCache::insert(key, pixmap); } } break; default: d->style->drawControl(element, option, painter, widget); break; } }
void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const { if (!panelWidget(widget)) return d->style->drawComplexControl(control, option, painter, widget); QRect rect = option->rect; switch (control) { case CC_ToolButton: if (const QStyleOptionToolButton *toolbutton = qstyleoption_cast<const QStyleOptionToolButton *>(option)) { QString buttonType = widget->property("type").toString(); QRect button, menuarea; button = subControlRect(control, toolbutton, SC_ToolButton, widget); menuarea = subControlRect(control, toolbutton, SC_ToolButtonMenu, widget); State bflags = toolbutton->state; if (bflags & State_AutoRaise) { if (!(bflags & State_MouseOver)) { bflags &= ~State_Raised; } } State mflags = bflags; if (toolbutton->state & State_Sunken) { if (toolbutton->activeSubControls & SC_ToolButton) bflags |= State_Sunken; if (toolbutton->activeSubControls & SC_ToolButtonMenu) mflags |= State_Sunken; } QStyleOption tool(0); tool.palette = toolbutton->palette; if (toolbutton->subControls & SC_ToolButton) { // if (buttonType == "dockbutton") { tool.rect = button; tool.state = bflags; drawPrimitive(PE_PanelButtonTool, &tool, painter, widget); // } /*else { // paint status bar button style if (bflags & State_Sunken || bflags & State_On) drawCornerImage(d->buttonImage_pressed, painter, option->rect, 2, 2, 2, 2); else if (bflags & State_Enabled) { #ifndef Q_WS_MAC if (bflags & State_MouseOver) { drawCornerImage(d->buttonImage, painter, option->rect, 2, 2, 2, 2); QColor shade(255, 255, 255, 50); painter->fillRect(button.adjusted(1, 1, -1, -1), shade); } #endif } }*/ } if (toolbutton->state & State_HasFocus) { QStyleOptionFocusRect fr; fr.QStyleOption::operator=(*toolbutton); fr.rect.adjust(3, 3, -3, -3); if (toolbutton->features & QStyleOptionToolButton::MenuButtonPopup) fr.rect.adjust(0, 0, -pixelMetric(QStyle::PM_MenuButtonIndicator, toolbutton, widget), 0); QPen oldPen = painter->pen(); QColor focusColor = StyleHelper::panelTextColor(); focusColor.setAlpha(120); QPen outline(focusColor, 1); outline.setStyle(Qt::DotLine); painter->setPen(outline); QRect r = option->rect.adjusted(2, 2, -2, -2); painter->drawRect(r); painter->setPen(oldPen); } QStyleOptionToolButton label = *toolbutton; label.palette = panelPalette(option->palette); int fw = pixelMetric(PM_DefaultFrameWidth, option, widget); label.rect = button.adjusted(fw, fw, -fw, -fw); drawControl(CE_ToolButtonLabel, &label, painter, widget); if (toolbutton->subControls & SC_ToolButtonMenu) { tool.state = mflags; tool.rect = menuarea.adjusted(1, 1, -1, -1); if (mflags & (State_Sunken | State_On | State_Raised)) { painter->setPen(Qt::gray); painter->drawLine(tool.rect.topLeft(), tool.rect.bottomLeft()); if (mflags & (State_Sunken)) { QColor shade(0, 0, 0, 50); painter->fillRect(tool.rect.adjusted(0, -1, 1, 1), shade); } #ifndef Q_WS_MAC else if (mflags & (State_MouseOver)) { QColor shade(255, 255, 255, 50); painter->fillRect(tool.rect.adjusted(0, -1, 1, 1), shade); } #endif } tool.rect = tool.rect.adjusted(2, 2, -2, -2); drawPrimitive(PE_IndicatorArrowDown, &tool, painter, widget); } else if (toolbutton->features & QStyleOptionToolButton::HasMenu) { int arrowSize = 6; QRect ir = toolbutton->rect.adjusted(1, 1, -1, -1); QStyleOptionToolButton newBtn = *toolbutton; newBtn.palette = panelPalette(option->palette); newBtn.rect = QRect(ir.right() - arrowSize - 1, ir.height() - arrowSize - 2, arrowSize, arrowSize); drawPrimitive(PE_IndicatorArrowDown, &newBtn, painter, widget); } } break; case CC_ComboBox: if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) { painter->save(); bool isEmpty = cb->currentText.isEmpty() && cb->currentIcon.isNull(); bool reverse = option->direction == Qt::RightToLeft; // Draw tool button QLinearGradient grad(option->rect.topRight(), option->rect.bottomRight()); grad.setColorAt(0, QColor(255, 255, 255, 20)); grad.setColorAt(0.4, QColor(255, 255, 255, 60)); grad.setColorAt(0.7, QColor(255, 255, 255, 50)); grad.setColorAt(1, QColor(255, 255, 255, 40)); painter->setPen(QPen(grad, 0)); painter->drawLine(rect.topRight(), rect.bottomRight()); painter->drawLine(rect.topLeft(), rect.bottomLeft()); grad.setColorAt(0, QColor(0, 0, 0, 30)); grad.setColorAt(0.4, QColor(0, 0, 0, 70)); grad.setColorAt(0.7, QColor(0, 0, 0, 70)); grad.setColorAt(1, QColor(0, 0, 0, 40)); painter->setPen(QPen(grad, 0)); if (!reverse) painter->drawLine(rect.topRight() - QPoint(1,0), rect.bottomRight() - QPoint(1,0)); else painter->drawLine(rect.topLeft(), rect.bottomLeft()); QStyleOption toolbutton = *option; if (isEmpty) toolbutton.state &= ~(State_Enabled | State_Sunken); painter->save(); painter->setClipRect(toolbutton.rect.adjusted(0, 0, -2, 0)); drawPrimitive(PE_PanelButtonTool, &toolbutton, painter, widget); painter->restore(); // Draw arrow int menuButtonWidth = 12; int left = !reverse ? rect.right() - menuButtonWidth : rect.left(); int right = !reverse ? rect.right() : rect.left() + menuButtonWidth; QRect arrowRect((left + right) / 2 + (reverse ? 6 : -6), rect.center().y() - 3, 9, 9); if (option->state & State_On) arrowRect.translate(d->style->pixelMetric(PM_ButtonShiftHorizontal, option, widget), d->style->pixelMetric(PM_ButtonShiftVertical, option, widget)); QStyleOption arrowOpt = *option; arrowOpt.rect = arrowRect; if (isEmpty) arrowOpt.state &= ~(State_Enabled | State_Sunken); if (styleHint(SH_ComboBox_Popup, option, widget)) { arrowOpt.rect.translate(0, -3); drawPrimitive(PE_IndicatorArrowUp, &arrowOpt, painter, widget); arrowOpt.rect.translate(0, 6); drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, painter, widget); } else { drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, painter, widget); } painter->restore(); } break; default: d->style->drawComplexControl(control, option, painter, widget); break; } }
void MiamStyle::drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const { switch (element) { #if !defined(Q_OS_OSX) case CE_Splitter: break; #endif case CE_MenuBarItem:{ const QStyleOptionMenuItem *somi = static_cast<const QStyleOptionMenuItem*>(option); const bool act = somi->state & (State_Sunken | State_Selected); QPalette palette = QApplication::palette(); QBrush brush; if (act) { painter->setPen(palette.highlight().color()); brush = palette.highlight().color().lighter(); painter->setBrush(brush); painter->drawRect(option->rect.adjusted(0, 0, -1, -1)); } else { brush = palette.window(); painter->fillRect(option->rect, palette.window()); } uint alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine; if (!styleHint(SH_UnderlineShortcut, somi, widget)) { alignment |= Qt::TextHideMnemonic; } if (somi->state.testFlag(QStyle::State_Enabled)) { if (SettingsPrivate::instance()->isCustomTextColorOverriden()) { if (act) { painter->setPen(palette.highlightedText().color()); } else { painter->setPen(palette.text().color()); } } else { if (qAbs(palette.text().color().value() - brush.color().value()) < 128) { painter->setPen(palette.highlightedText().color()); } else { painter->setPen(palette.text().color()); } } } /*else if (act) { painter->setPen(palette.mid().color()); }*/ painter->drawText(option->rect, alignment, somi->text); break; } case CE_MenuItem: if (const QStyleOptionMenuItem *menuitem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) { QGuiApplication *app = static_cast<QGuiApplication*>(QGuiApplication::instance()); qreal checkcol = 25 / app->devicePixelRatio(); qreal gutterWidth = 3 / app->devicePixelRatio(); QRect rect = option->rect; //draw vertical menu line if (option->direction == Qt::LeftToRight) checkcol += rect.x(); int x, y, w, h; menuitem->rect.getRect(&x, &y, &w, &h); int tab = menuitem->tabWidth; bool dis = !(menuitem->state & State_Enabled); bool checked = menuitem->checkType != QStyleOptionMenuItem::NotCheckable ? menuitem->checked : false; bool act = menuitem->state & State_Selected; QPalette palette = QApplication::palette(); if (menuitem->menuItemType == QStyleOptionMenuItem::Separator) { int yoff = y - 1 + h / 2; qreal separatorSize = 6 / app->devicePixelRatio(); QPoint p1 = QPoint(x + checkcol, yoff); QPoint p2 = QPoint(x + w + separatorSize, yoff); painter->save(); painter->fillRect(menuitem->rect, palette.window()); painter->setPen(palette.mid().color()); painter->drawLine(p1, p2); painter->restore(); return; } QString s = menuitem->text; QBrush fill; if (act) { fill = palette.highlight().color().lighter(); } else { fill = palette.window(); } painter->fillRect(menuitem->rect, fill); QRect vCheckRect = visualRect(option->direction, menuitem->rect, QRect(menuitem->rect.x(), menuitem->rect.y(), checkcol - (gutterWidth + menuitem->rect.x()), menuitem->rect.height())); if (checked) { QStyleOptionMenuItem newMi = *menuitem; int windowsItemFrame = 2; newMi.rect = visualRect(option->direction, menuitem->rect, QRect(menuitem->rect.x() + windowsItemFrame, menuitem->rect.y() + windowsItemFrame, checkcol - 2 * windowsItemFrame, menuitem->rect.height() - 2 * windowsItemFrame) ); painter->setRenderHint(QPainter::Antialiasing, true); proxy()->drawPrimitive(PE_IndicatorMenuCheckMark, &newMi, painter, widget); painter->setRenderHint(QPainter::Antialiasing, false); } if (!menuitem->icon.isNull()) { QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal; if (act && !dis) { mode = QIcon::Active; } QPixmap pixmap; if (checked) { pixmap = menuitem->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize, option, widget), mode, QIcon::On); } else { pixmap = menuitem->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize, option, widget), mode); } const int pixw = pixmap.width() / pixmap.devicePixelRatio(); const int pixh = pixmap.height() / pixmap.devicePixelRatio(); QRect pmr(0, 0, pixw, pixh); pmr.moveCenter(vCheckRect.center()); painter->setPen(palette.text().color()); painter->drawPixmap(pmr.topLeft(), pixmap); } //painter->setPen(palette.buttonText().color()); QColor textColor = palette.text().color(); if (dis) { textColor = palette.mid().color(); painter->setPen(textColor); } else if (act && SettingsPrivate::instance()->isCustomTextColorOverriden()) { textColor = palette.highlightedText().color(); painter->setPen(textColor); } int xm = checkcol + 2 + (gutterWidth - menuitem->rect.x()) - 1; int xpos = menuitem->rect.x() + xm; /// int windowsItemVMargin = 3, windowsRightBorder = 3; QRect textRect(xpos, y + windowsItemVMargin, w - xm - windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin); QRect vTextRect = visualRect(option->direction, menuitem->rect, textRect); if (!s.isEmpty()) { // draw text painter->save(); int t = s.indexOf(QLatin1Char('\t')); int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine; if (!proxy()->styleHint(SH_UnderlineShortcut, menuitem, widget)) { text_flags |= Qt::TextHideMnemonic; } text_flags |= Qt::AlignLeft; if (t >= 0) { QRect vShortcutRect = visualRect(option->direction, menuitem->rect, QRect(textRect.topRight(), QPoint(menuitem->rect.right(), textRect.bottom()))); painter->drawText(vShortcutRect, text_flags, s.mid(t + 1)); s = s.left(t); } QFont font = menuitem->font; if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem) { font.setBold(true); } painter->setFont(font); painter->setPen(textColor); painter->drawText(vTextRect, text_flags, s.left(t)); painter->restore(); } if (menuitem->menuItemType == QStyleOptionMenuItem::SubMenu) {// draw sub menu arrow int dim = (h - 2 * 5) / 2; PrimitiveElement arrow; arrow = (option->direction == Qt::RightToLeft) ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight; xpos = x + w - 2 - 2 - dim; QRect vSubMenuRect = visualRect(option->direction, menuitem->rect, QRect(xpos, y + h / 2 - dim / 2, dim, dim)); QStyleOptionMenuItem newMI = *menuitem; newMI.rect = vSubMenuRect; newMI.state = dis ? State_None : State_Enabled; proxy()->drawPrimitive(arrow, &newMI, painter, widget); } } break; case CE_MenuBarEmptyArea:{ painter->fillRect(option->rect, QApplication::palette().window()); break; } default: QProxyStyle::drawControl(element, option, painter, widget); } }