Changeset View
Changeset View
Standalone View
Standalone View
liboxygen/oxygenhelper.cpp
Show All 21 Lines | |||||
22 | 22 | | |||
23 | #include "oxygenhelper.h" | 23 | #include "oxygenhelper.h" | ||
24 | #include "liboxygen.h" | 24 | #include "liboxygen.h" | ||
25 | 25 | | |||
26 | #include <KColorUtils> | 26 | #include <KColorUtils> | ||
27 | #include <KColorScheme> | 27 | #include <KColorScheme> | ||
28 | #include <KWindowSystem> | 28 | #include <KWindowSystem> | ||
29 | 29 | | |||
30 | #if OXYGEN_USE_KDE4 | | |||
31 | #include <KGlobalSettings> | | |||
32 | #endif | | |||
33 | | ||||
34 | #include <QApplication> | 30 | #include <QApplication> | ||
35 | #include <QWidget> | 31 | #include <QWidget> | ||
36 | #include <QPainter> | 32 | #include <QPainter> | ||
37 | #include <QTextStream> | 33 | #include <QTextStream> | ||
38 | #include <math.h> | 34 | #include <math.h> | ||
39 | 35 | | |||
40 | #if OXYGEN_HAVE_X11 | 36 | #if OXYGEN_HAVE_X11 | ||
41 | #include <QX11Info> | 37 | #include <QX11Info> | ||
42 | #endif | 38 | #endif | ||
43 | 39 | | |||
44 | #if OXYGEN_HAVE_X11 && QT_VERSION < 0x050000 | | |||
45 | #include <X11/Xlib-xcb.h> | | |||
46 | #endif | | |||
47 | | ||||
48 | namespace Oxygen | 40 | namespace Oxygen | ||
49 | { | 41 | { | ||
50 | 42 | | |||
51 | const qreal Helper::_slabThickness = 0.45; | 43 | const qreal Helper::_slabThickness = 0.45; | ||
52 | const qreal Helper::_shadowGain = 1.5; | 44 | const qreal Helper::_shadowGain = 1.5; | ||
53 | const qreal Helper::_glowBias = 0.6; | 45 | const qreal Helper::_glowBias = 0.6; | ||
54 | 46 | | |||
55 | //____________________________________________________________________ | 47 | //____________________________________________________________________ | ||
56 | Helper::Helper( KSharedConfig::Ptr config ): | 48 | Helper::Helper( KSharedConfig::Ptr config ): | ||
57 | _config( config ) | 49 | _config( config ) | ||
58 | { init(); } | 50 | { init(); } | ||
59 | 51 | | |||
60 | //____________________________________________________________________ | 52 | //____________________________________________________________________ | ||
61 | #if OXYGEN_USE_KDE4 | | |||
62 | Helper::Helper( const QByteArray& name ): | | |||
63 | _componentData( name, 0, KComponentData::SkipMainComponentRegistration ), | | |||
64 | _config( _componentData.config() ) | | |||
65 | { init(); } | | |||
66 | #endif | | |||
67 | | ||||
68 | //____________________________________________________________________ | | |||
69 | KSharedConfig::Ptr Helper::config() const | 53 | KSharedConfig::Ptr Helper::config() const | ||
70 | { return _config; } | 54 | { return _config; } | ||
71 | 55 | | |||
72 | //____________________________________________________________________ | 56 | //____________________________________________________________________ | ||
73 | void Helper::loadConfig() | 57 | void Helper::loadConfig() | ||
74 | { | 58 | { | ||
75 | 59 | | |||
76 | #if OXYGEN_USE_KDE4 | | |||
77 | _contrast = KGlobalSettings::contrastF( _config ); | | |||
78 | #else | | |||
79 | _contrast = KColorScheme::contrastF( _config ); | 60 | _contrast = KColorScheme::contrastF( _config ); | ||
80 | #endif | | |||
81 | 61 | | |||
82 | _bgcontrast = qMin( 1.0, 0.9*_contrast/0.7 ); | 62 | _bgcontrast = qMin( 1.0, 0.9*_contrast/0.7 ); | ||
83 | 63 | | |||
84 | _viewFocusBrush = KStatefulBrush( KColorScheme::View, KColorScheme::FocusColor, _config ); | 64 | _viewFocusBrush = KStatefulBrush( KColorScheme::View, KColorScheme::FocusColor, _config ); | ||
85 | _viewHoverBrush = KStatefulBrush( KColorScheme::View, KColorScheme::HoverColor, _config ); | 65 | _viewHoverBrush = KStatefulBrush( KColorScheme::View, KColorScheme::HoverColor, _config ); | ||
86 | _viewNegativeTextBrush = KStatefulBrush( KColorScheme::View, KColorScheme::NegativeText, _config ); | 66 | _viewNegativeTextBrush = KStatefulBrush( KColorScheme::View, KColorScheme::NegativeText, _config ); | ||
87 | 67 | | |||
88 | } | 68 | } | ||
▲ Show 20 Lines • Show All 704 Lines • ▼ Show 20 Line(s) | 768 | { | |||
793 | Q_UNUSED( id ); | 773 | Q_UNUSED( id ); | ||
794 | return false; | 774 | return false; | ||
795 | #endif | 775 | #endif | ||
796 | } | 776 | } | ||
797 | 777 | | |||
798 | //______________________________________________________________________________________ | 778 | //______________________________________________________________________________________ | ||
799 | QPixmap Helper::highDpiPixmap( int width, int height ) const | 779 | QPixmap Helper::highDpiPixmap( int width, int height ) const | ||
800 | { | 780 | { | ||
801 | #if QT_VERSION >= 0x050300 | | |||
802 | const qreal dpiRatio( qApp->devicePixelRatio() ); | 781 | const qreal dpiRatio( qApp->devicePixelRatio() ); | ||
803 | QPixmap pixmap( width*dpiRatio, height*dpiRatio ); | 782 | QPixmap pixmap( width*dpiRatio, height*dpiRatio ); | ||
804 | pixmap.setDevicePixelRatio( dpiRatio ); | 783 | pixmap.setDevicePixelRatio( dpiRatio ); | ||
805 | return pixmap; | 784 | return pixmap; | ||
806 | #else | | |||
807 | return QPixmap( width, height ); | | |||
808 | #endif | | |||
809 | } | 785 | } | ||
810 | 786 | | |||
811 | //______________________________________________________________________________________ | 787 | //______________________________________________________________________________________ | ||
812 | qreal Helper::devicePixelRatio( const QPixmap& pixmap ) const | 788 | qreal Helper::devicePixelRatio( const QPixmap& pixmap ) const | ||
813 | { | 789 | { | ||
814 | #if QT_VERSION >= 0x050300 | | |||
815 | return pixmap.devicePixelRatio(); | 790 | return pixmap.devicePixelRatio(); | ||
816 | #else | | |||
817 | Q_UNUSED(pixmap); | | |||
818 | return 1; | | |||
819 | #endif | | |||
820 | } | 791 | } | ||
821 | 792 | | |||
822 | //______________________________________________________________________________ | 793 | //______________________________________________________________________________ | ||
823 | bool Helper::isX11( void ) | 794 | bool Helper::isX11( void ) | ||
824 | { | 795 | { | ||
825 | #if OXYGEN_HAVE_X11 | 796 | #if OXYGEN_HAVE_X11 | ||
826 | #if QT_VERSION >= 0x050000 | | |||
827 | static const bool s_isX11 = KWindowSystem::isPlatformX11(); | 797 | static const bool s_isX11 = KWindowSystem::isPlatformX11(); | ||
828 | return s_isX11; | 798 | return s_isX11; | ||
829 | #else | | |||
830 | return true; | | |||
831 | #endif | | |||
832 | #endif | 799 | #endif | ||
833 | 800 | | |||
834 | return false; | 801 | return false; | ||
835 | 802 | | |||
836 | } | 803 | } | ||
837 | 804 | | |||
838 | bool Helper::isWayland( void ) | 805 | bool Helper::isWayland( void ) | ||
839 | { | 806 | { | ||
840 | #if QT_VERSION >= 0x050000 | | |||
841 | static const bool s_isWayland = KWindowSystem::isPlatformWayland(); | 807 | static const bool s_isWayland = KWindowSystem::isPlatformWayland(); | ||
842 | return s_isWayland; | 808 | return s_isWayland; | ||
843 | #else | | |||
844 | return false; | | |||
845 | #endif | | |||
846 | } | 809 | } | ||
847 | 810 | | |||
848 | #if OXYGEN_HAVE_X11 | 811 | #if OXYGEN_HAVE_X11 | ||
849 | 812 | | |||
850 | //____________________________________________________________________ | 813 | //____________________________________________________________________ | ||
851 | xcb_connection_t* Helper::connection( void ) | 814 | xcb_connection_t* Helper::connection( void ) | ||
852 | { | 815 | { | ||
853 | 816 | | |||
854 | #if QT_VERSION >= 0x050000 | | |||
855 | return QX11Info::connection(); | 817 | return QX11Info::connection(); | ||
856 | #else | | |||
857 | static xcb_connection_t* connection = nullptr; | | |||
858 | if( !connection ) | | |||
859 | { | | |||
860 | Display* display = QX11Info::display(); | | |||
861 | if( display ) connection = XGetXCBConnection( display ); | | |||
862 | } | | |||
863 | return connection; | | |||
864 | #endif | | |||
865 | } | 818 | } | ||
866 | 819 | | |||
867 | //____________________________________________________________________ | 820 | //____________________________________________________________________ | ||
868 | xcb_atom_t Helper::createAtom( const QString& name ) const | 821 | xcb_atom_t Helper::createAtom( const QString& name ) const | ||
869 | { | 822 | { | ||
870 | if( !isX11() ) return 0; | 823 | if( !isX11() ) return 0; | ||
871 | xcb_intern_atom_cookie_t cookie( xcb_intern_atom( connection(), false, name.size(), qPrintable( name ) ) ); | 824 | xcb_intern_atom_cookie_t cookie( xcb_intern_atom( connection(), false, name.size(), qPrintable( name ) ) ); | ||
872 | ScopedPointer<xcb_intern_atom_reply_t> reply( xcb_intern_atom_reply( connection(), cookie, nullptr) ); | 825 | ScopedPointer<xcb_intern_atom_reply_t> reply( xcb_intern_atom_reply( connection(), cookie, nullptr) ); | ||
▲ Show 20 Lines • Show All 100 Lines • ▼ Show 20 Line(s) | |||||
973 | 926 | | |||
974 | #endif | 927 | #endif | ||
975 | 928 | | |||
976 | 929 | | |||
977 | //____________________________________________________________________ | 930 | //____________________________________________________________________ | ||
978 | void Helper::init( void ) | 931 | void Helper::init( void ) | ||
979 | { | 932 | { | ||
980 | 933 | | |||
981 | #if OXYGEN_USE_KDE4 | | |||
982 | _contrast = KGlobalSettings::contrastF( _config ); | | |||
983 | #else | | |||
984 | _contrast = KColorScheme::contrastF( _config ); | 934 | _contrast = KColorScheme::contrastF( _config ); | ||
985 | #endif | | |||
986 | 935 | | |||
987 | // background contrast is calculated so that it is 0.9 | 936 | // background contrast is calculated so that it is 0.9 | ||
988 | // when KGlobalSettings contrast value of 0.7 | 937 | // when KGlobalSettings contrast value of 0.7 | ||
989 | _bgcontrast = qMin( 1.0, 0.9*_contrast/0.7 ); | 938 | _bgcontrast = qMin( 1.0, 0.9*_contrast/0.7 ); | ||
990 | 939 | | |||
991 | _backgroundCache.setMaxCost( 64 ); | 940 | _backgroundCache.setMaxCost( 64 ); | ||
992 | 941 | | |||
993 | #if OXYGEN_HAVE_X11 | 942 | #if OXYGEN_HAVE_X11 | ||
Show All 16 Lines |