1 /* This file is (c) 2012 Tvangeste <i.4m.l33t@yandex.ru> 2 * Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */ 3 4 #include "gdappstyle.hh" 5 6 #if QT_VERSION >= 0x040600 7 8 #include "dictionarybar.hh" 9 10 #include <QWidget> 11 #include <QToolButton> 12 #include <QDebug> 13 GdAppStyle(QProxyStyle * parent)14GdAppStyle::GdAppStyle(QProxyStyle * parent) : QProxyStyle(parent) {} 15 pixelMetric(PixelMetric metric,const QStyleOption * option,const QWidget * widget) const16int GdAppStyle::pixelMetric ( PixelMetric metric, const QStyleOption * option, const QWidget * widget) const 17 { 18 int defaultVal = QProxyStyle::pixelMetric(metric, option, widget); 19 20 if ( dictionaryBarButton( widget ) ) 21 { 22 if ( metric == QStyle::PM_ButtonShiftVertical || metric == QStyle::PM_ButtonShiftHorizontal ) 23 { 24 if (option ->state & State_Sunken ) { 25 return defaultVal; 26 } 27 28 if ( option ->state & State_On ) { 29 // No shift for for the checked tool buttons on the dictionary bar, 30 // that's why the whole thing with QProxyStyle is neded, to achieve this. 31 return 0; 32 } 33 } 34 } 35 36 // Qt don't upscale icons for high dpi scales 37 // We limit maximum small icon size to 21 pixel 38 // (standard icon size for Lingvo dictionaries) 39 if( metric == QStyle::PM_SmallIconSize ) 40 return defaultVal < 21 ? defaultVal : 21; 41 42 return defaultVal; 43 } 44 dictionaryBarButton(const QWidget * widget) const45bool GdAppStyle::dictionaryBarButton(const QWidget * widget) const { 46 if (widget) { 47 const QWidget * parent = widget->parentWidget(); 48 if ( parent && 49 qobject_cast<const DictionaryBar *>( parent ) && 50 qobject_cast<const QToolButton *>( widget ) ) 51 return true; 52 } 53 54 return false; 55 } 56 57 #endif // QT_VERSION 58