Advertisement
Guest User

Untitled

a guest
Jun 16th, 2017
539
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.06 KB | None | 0 0
  1. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
  2. index aa4e224..b08fd7e 100644
  3. --- a/src/CMakeLists.txt
  4. +++ b/src/CMakeLists.txt
  5. @@ -7,6 +7,7 @@ SET(GTK-OXYGEN-SOURCES
  6. engine.cpp
  7. utilities.cpp
  8. colormapper.cpp
  9. + qcolorutils.cpp
  10. rcproperties.cpp)
  11.  
  12. ADD_LIBRARY(oxygenengine SHARED ${GTK-OXYGEN-SOURCES})
  13. diff --git a/src/engine.cpp b/src/engine.cpp
  14. index 26b1bb7..73a484d 100644
  15. --- a/src/engine.cpp
  16. +++ b/src/engine.cpp
  17. @@ -28,6 +28,7 @@
  18. #include "dummyapplication.h"
  19. #include "utilities.h"
  20. #include "colormapper.h"
  21. +#include "qcolorutils.h"
  22. #include "rcproperties.h"
  23.  
  24. #include <time.h>
  25. @@ -269,6 +270,11 @@ void Engine::drawButton(bool defaultButton)
  26. ENGINE_SETUP(QStyleOptionButton, QImage::Format_ARGB32, true, QPalette::Window)
  27. // Handle default buttons (ones that get activated when you press enter)
  28. option.features = defaultButton ? QStyleOptionButton::DefaultButton : QStyleOptionButton::None;
  29. +
  30. + // change palette button background color to deal with button position in main window
  31. + option.palette.setColor( QPalette::Button, QColorUtils::backgroundColor( option.palette.color( QPalette::Button ), m_topLeft.y(), m_toplevelSize.height() ) );
  32. +
  33. + // draw
  34. m_qtStyle->drawControl(QStyle::CE_PushButton, &option, &p, m_dummyButton);
  35. ENGINE_FINISH
  36. }
  37. @@ -995,17 +1001,41 @@ void Engine::drawOxygenBackground(bool draw)
  38.  
  39. if (!image)
  40. {
  41. - QPalette palette(ColorMapper::mapGtkToQt(m_style, GTK_STATE_NORMAL, false));
  42. - QPalette::ColorGroup colorGroup = (m_state == GTK_STATE_INSENSITIVE) ? QPalette::Inactive : QPalette::Normal;
  43. - image = verticalGradient(palette.color(colorGroup, QPalette::Window), m_size.width(), m_size.height(), 0);
  44. -
  45. - QImage *rGradient = radialGradient(palette.color(colorGroup, QPalette::Window),\
  46. - m_size.width(), m_size.height());
  47. - QPainter p(image);
  48. + // create new image and make transparent
  49. + image = new QImage( m_size, QImage::Format_ARGB32);
  50. + image->fill( Qt::transparent );
  51. + QPainter p( image );
  52. +
  53. + // store palette, colorgroup and color locally
  54. + const QPalette palette(ColorMapper::mapGtkToQt(m_style, GTK_STATE_NORMAL, false));
  55. + const QPalette::ColorGroup colorGroup = (m_state == GTK_STATE_INSENSITIVE) ? QPalette::Inactive : QPalette::Normal;
  56. + const QColor color( palette.color( colorGroup, QPalette::Window ) );
  57. +
  58. + // the hard-coded metrics are copied for kdebase/workspace/libs/oxygen/oxygenhelper.cpp
  59. + const int gradientHeight = 64;
  60. + const int yShift = 23;
  61. + const int splitY( qMin(300, (3*m_size.height())/4 ) );
  62. + const QRect upperRect( 0, -yShift, m_size.width(), splitY);
  63. +
  64. + // draw upper linear gradient
  65. + QImage* vGradient( verticalGradient( color, m_size.width(), splitY, 0 ) );
  66. p.setCompositionMode(QPainter::CompositionMode_SourceOver);
  67. - p.drawImage(0, 0, *rGradient);
  68. - p.end();
  69. + p.drawImage( upperRect, *vGradient );
  70. + delete vGradient;
  71. +
  72. + // draw lower flat part
  73. + const QRect lowerRect(0, splitY - yShift, m_size.width(), m_size.height() - splitY + yShift );
  74. + p.fillRect( lowerRect, QColorUtils::backgroundBottomColor(color));
  75. +
  76. + // draw upper radial gradient
  77. + const int radialW( qMin(600, m_size.width() ) );
  78. + QRect radialRect( (m_size.width() - radialW) / 2, 0, radialW, gradientHeight);
  79. + radialRect.translate( 0, -yShift );
  80. + QImage* rGradient( radialGradient( color, radialW, gradientHeight ) );
  81. + p.drawImage( radialRect, *rGradient);
  82. delete rGradient;
  83. + p.end();
  84. +
  85. if (draw)
  86. {
  87. ENGINE_DRAW(true)
  88. @@ -1093,9 +1123,9 @@ QImage* Engine::verticalGradient(const QColor &color, int width, int height, int
  89. image->fill(Qt::transparent);
  90.  
  91. QLinearGradient gradient(0, offset, 0, height + offset);
  92. - gradient.setColorAt(0.0, color.lighter(103));
  93. + gradient.setColorAt(0.0, QColorUtils::backgroundTopColor(color) );
  94. gradient.setColorAt(0.5, color);
  95. - gradient.setColorAt(1.0, color);
  96. + gradient.setColorAt(1.0, QColorUtils::backgroundBottomColor(color) );
  97.  
  98. QPainter p(image);
  99. p.setCompositionMode(QPainter::CompositionMode_Source);
  100. @@ -1108,17 +1138,12 @@ QImage* Engine::verticalGradient(const QColor &color, int width, int height, int
  101. QImage* Engine::radialGradient(const QColor &color, int width, int height)
  102. {
  103. QImage *image = new QImage(width, height, QImage::Format_ARGB32);
  104. - int focalPoint = 350;
  105. image->fill(Qt::transparent);
  106. -
  107. - // Need to find something better, but i don't understand oxygen code
  108. - // Help wanted ;)
  109. - if (focalPoint > width / 2)
  110. - focalPoint = width / 2;
  111.  
  112. - QColor radialColor = color.lighter(110);
  113. + QColor radialColor = QColorUtils::backgroundRadialColor(color);
  114. radialColor.setAlpha(255);
  115. - QRadialGradient gradient(width/2, 0, focalPoint);
  116. +
  117. + QRadialGradient gradient(64, height-64, 64);
  118. gradient.setColorAt(0, radialColor);
  119. radialColor.setAlpha(101);
  120. gradient.setColorAt(0.5, radialColor);
  121. @@ -1128,7 +1153,8 @@ QImage* Engine::radialGradient(const QColor &color, int width, int height)
  122. gradient.setColorAt(1, radialColor);
  123.  
  124. QPainter p(image);
  125. - p.fillRect(QRect(0, 0, width, height), gradient);
  126. + p.scale(width/128.0,1);
  127. + p.fillRect(QRect(0,0,128,height), gradient);
  128. p.end();
  129.  
  130. return image;
  131. diff --git a/src/qcolorutils.cpp b/src/qcolorutils.cpp
  132. new file mode 100644
  133. index 0000000..cfb6801
  134. --- /dev/null
  135. +++ b/src/qcolorutils.cpp
  136. @@ -0,0 +1,410 @@
  137. +/* This file is part of the KDE project
  138. + * Copyright ( C ) 2007 Matthew Woehlke <mw_triad@users.sourceforge.net>
  139. + * Copyright ( C ) 2007 Thomas Zander <zander@kde.org>
  140. + * Copyright ( C ) 2007 Zack Rusin <zack@kde.org>
  141. + *
  142. + * This library is free software; you can redistribute it and/or
  143. + * modify it under the terms of the GNU Library General Public
  144. + * License as published by the Free Software Foundation; either
  145. + * version 2 of the License, or ( at your option ) any later version.
  146. + *
  147. + * This library is distributed in the hope that it will be useful,
  148. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  149. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  150. + * Library General Public License for more details.
  151. + *
  152. + * You should have received a copy of the GNU Library General Public License
  153. + * along with this library; see the file COPYING.LIB. If not, write to
  154. + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  155. + * Boston, MA 02110-1301, USA.
  156. + */
  157. +
  158. +#include "qcolorutils.h"
  159. +#include <cmath>
  160. +
  161. +namespace QColorUtils
  162. +{
  163. +
  164. + //___________________________________________________________
  165. + // contrast
  166. + static qreal _contrast = 0.5;
  167. + static qreal _bgcontrast = 0.5;
  168. + void setContrast( qreal value )
  169. + {
  170. + _contrast = value;
  171. + _bgcontrast = qMin( 1.0, 0.9*_contrast/0.7 );
  172. + }
  173. +
  174. + //___________________________________________________________
  175. + const qreal& contrast( void )
  176. + { return _contrast; }
  177. +
  178. + //___________________________________________________________
  179. + const qreal& backgroundContrast( void )
  180. + { return _bgcontrast; }
  181. +
  182. + //____________________________________________________________________
  183. + bool lowThreshold(const QColor &color)
  184. + {
  185. +
  186. + const QColor darker( shade(color, MidShade, 0.5 ) );
  187. + return luma(darker) > luma(color);
  188. +
  189. + }
  190. +
  191. + //____________________________________________________________________
  192. + bool highThreshold(const QColor &color)
  193. + {
  194. + const QColor lighter( shade(color, LightShade, 0.5 ) );
  195. + return luma(lighter) < luma(color);
  196. + }
  197. +
  198. + //_________________________________________________________________________
  199. + QColor backgroundTopColor(const QColor &color)
  200. + {
  201. + if( lowThreshold(color) ) return shade(color, MidlightShade, 0.0);
  202. + else {
  203. + const qreal my( luma( shade(color, LightShade, 0.0) ) );
  204. + const qreal by( luma(color) );
  205. + return shade(color, (my - by) * backgroundContrast());
  206. + }
  207. +
  208. + }
  209. +
  210. + //_________________________________________________________________________
  211. + QColor backgroundBottomColor(const QColor &color)
  212. + {
  213. +
  214. + const QColor midColor( shade(color, MidShade, 0.0) );
  215. + if( lowThreshold(color) ) return midColor;
  216. + else {
  217. +
  218. + const qreal by( luma(color) );
  219. + const qreal my( luma(midColor) );
  220. + return shade(color, (my - by) * backgroundContrast());
  221. +
  222. + }
  223. + }
  224. + //_________________________________________________________________________
  225. + QColor backgroundRadialColor(const QColor &color)
  226. + {
  227. +
  228. + if( lowThreshold(color) ) return shade(color, LightShade, 0.0);
  229. + else if( highThreshold( color ) ) return color;
  230. + else return shade(color, LightShade, backgroundContrast() );
  231. + }
  232. +
  233. + //____________________________________________________________________
  234. + QColor backgroundColor(const QColor &color, int height, int y )
  235. + {
  236. +
  237. + qreal ratio( qreal(y)/qMin(300, 3*height/4) );
  238. + if( ratio < 0.5 )
  239. + {
  240. +
  241. + const qreal a( 2.0*ratio );
  242. + return mix(backgroundTopColor(color), color, a );
  243. +
  244. + } else {
  245. +
  246. + const qreal a( 2.0*ratio-1 );
  247. + return mix(color, backgroundBottomColor(color), a );
  248. +
  249. + }
  250. +
  251. + }
  252. +
  253. + //___________________________________________________________________
  254. + // luma coefficient
  255. + static const qreal yc[3] = { 0.2126, 0.7152, 0.0722 };
  256. +
  257. + //___________________________________________________________________
  258. + static inline qreal mixQreal( qreal a, qreal b, qreal bias )
  259. + { return a + ( b - a ) * bias; }
  260. +
  261. + //___________________________________________________________________
  262. + static inline qreal normalize( qreal a )
  263. + { return ( a < 1.0 ? ( a > 0.0 ? a : 0.0 ) : 1.0 ); }
  264. +
  265. + //___________________________________________________________________
  266. + static inline qreal gamma( qreal n )
  267. + { return pow( normalize( n ), 2.2 ); }
  268. +
  269. + //___________________________________________________________________
  270. + static inline qreal igamma(qreal n)
  271. + { return pow(normalize(n), 1.0/2.2); }
  272. +
  273. + //___________________________________________________________________
  274. + static inline qreal wrap( qreal a, qreal d = 1.0 )
  275. + {
  276. + qreal r = fmod( a, d );
  277. + return ( r < 0.0 ? d + r : ( r > 0.0 ? r : 0.0 ) );
  278. + }
  279. +
  280. + //___________________________________________________________________
  281. + // hcy representation of a colors
  282. + class HCY
  283. + {
  284. +
  285. + public:
  286. +
  287. + //! constructor
  288. + HCY( const QColor& color )
  289. + {
  290. +
  291. + // transparency
  292. + a = color.alphaF();
  293. +
  294. + // luma component
  295. + y = luma( color );
  296. +
  297. + qreal r = gamma( color.redF() );
  298. + qreal g = gamma( color.greenF() );
  299. + qreal b = gamma( color.blueF() );
  300. +
  301. + // hue component
  302. + qreal p = qMax( qMax( r, g ), b );
  303. + qreal n = qMin( qMin( r, g ), b );
  304. + qreal d = 6.0 * ( p - n );
  305. + if( n == p ) h = 0.0;
  306. + else if( r == p ) h = ( ( g - b ) / d );
  307. + else if( g == p ) h = ( ( b - r ) / d ) + ( 1.0 / 3.0 );
  308. + else h = ( ( r - g ) / d ) + ( 2.0 / 3.0 );
  309. +
  310. + // chroma component
  311. + if( r == g && g == b ) c = 0.0;
  312. + else c = qMax( ( y - n ) / y, ( p - y ) / ( 1 - y ) );
  313. +
  314. + }
  315. +
  316. + //! convert back to color
  317. + QColor qColor() const
  318. + {
  319. + // start with sane component values
  320. + qreal _h = wrap( h );
  321. + qreal _c = normalize( c );
  322. + qreal _y = normalize( y );
  323. +
  324. + // calculate some needed variables
  325. + qreal _hs = _h * 6.0, th, tm;
  326. + if( _hs < 1.0 )
  327. + {
  328. +
  329. + th = _hs;
  330. + tm = yc[0] + yc[1] * th;
  331. +
  332. + } else if( _hs < 2.0 ) {
  333. +
  334. + th = 2.0 - _hs;
  335. + tm = yc[1] + yc[0] * th;
  336. +
  337. + } else if( _hs < 3.0 ) {
  338. +
  339. + th = _hs - 2.0;
  340. + tm = yc[1] + yc[2] * th;
  341. +
  342. + } else if( _hs < 4.0 ) {
  343. +
  344. + th = 4.0 - _hs;
  345. + tm = yc[2] + yc[1] * th;
  346. +
  347. + } else if( _hs < 5.0 ) {
  348. +
  349. + th = _hs - 4.0;
  350. + tm = yc[2] + yc[0] * th;
  351. +
  352. + } else {
  353. +
  354. + th = 6.0 - _hs;
  355. + tm = yc[0] + yc[2] * th;
  356. +
  357. + }
  358. +
  359. + // calculate RGB channels in sorted order
  360. + qreal tn, to, tp;
  361. + if( tm >= _y )
  362. + {
  363. +
  364. + tp = _y + _y * _c * ( 1.0 - tm ) / tm;
  365. + to = _y + _y * _c * ( th - tm ) / tm;
  366. + tn = _y - ( _y * _c );
  367. +
  368. + } else {
  369. +
  370. + tp = _y + ( 1.0 - _y ) * _c;
  371. + to = _y + ( 1.0 - _y ) * _c * ( th - tm ) / ( 1.0 - tm );
  372. + tn = _y - ( 1.0 - _y ) * _c * tm / ( 1.0 - tm );
  373. +
  374. + }
  375. +
  376. + // return RGB channels in appropriate order
  377. + if( _hs < 1.0 ) return QColor::fromRgbF( igamma( tp ), igamma( to ), igamma( tn ), a );
  378. + else if( _hs < 2.0 ) return QColor::fromRgbF( igamma( to ), igamma( tp ), igamma( tn ), a );
  379. + else if( _hs < 3.0 ) return QColor::fromRgbF( igamma( tn ), igamma( tp ), igamma( to ), a );
  380. + else if( _hs < 4.0 ) return QColor::fromRgbF( igamma( tn ), igamma( to ), igamma( tp ), a );
  381. + else if( _hs < 5.0 ) return QColor::fromRgbF( igamma( to ), igamma( tn ), igamma( tp ), a );
  382. + else return QColor::fromRgbF( igamma( tp ), igamma( tn ), igamma( to ), a );
  383. + }
  384. +
  385. + qreal h;
  386. + qreal c;
  387. + qreal y;
  388. + qreal a;
  389. +
  390. + };
  391. +
  392. + //___________________________________________________________________
  393. + qreal luma( const QColor &color )
  394. + {
  395. +
  396. + // RGB ratios
  397. + return
  398. + gamma( color.redF() )*yc[0] +
  399. + gamma( color.greenF() )*yc[1] +
  400. + gamma( color.blueF() )*yc[2];
  401. + }
  402. +
  403. + //___________________________________________________________________
  404. + qreal contrastRatio( const QColor &c1, const QColor &c2 )
  405. + {
  406. + qreal y1 = luma( c1 ), y2 = luma( c2 );
  407. + if( y1 > y2 ) return ( y1 + 0.05 ) / ( y2 + 0.05 );
  408. + else return ( y2 + 0.05 ) / ( y1 + 0.05 );
  409. + }
  410. +
  411. + //___________________________________________________________________
  412. + QColor lighten( const QColor &color, qreal ky, qreal kc )
  413. + {
  414. + HCY c( color );
  415. + c.y = 1.0 - normalize( ( 1.0 - c.y ) * ( 1.0 - ky ) );
  416. + c.c = 1.0 - normalize( ( 1.0 - c.c ) * kc );
  417. + return c.qColor();
  418. + }
  419. +
  420. + //___________________________________________________________________
  421. + QColor darken( const QColor &color, qreal ky, qreal kc )
  422. + {
  423. + HCY c( color );
  424. + c.y = normalize( c.y * ( 1.0 - ky ) );
  425. + c.c = normalize( c.c * kc );
  426. + return c.qColor();
  427. + }
  428. +
  429. + //___________________________________________________________________
  430. + static inline QColor tintHelper( const QColor &base, const QColor &color, qreal amount )
  431. + {
  432. + HCY result( mix( base, color, pow( amount, 0.3 ) ) );
  433. + result.y = mixQreal( luma( base ), result.y, amount );
  434. +
  435. + return result.qColor();
  436. + }
  437. +
  438. + //___________________________________________________________________
  439. + QColor tint( const QColor &base, const QColor &color, qreal amount )
  440. + {
  441. + if( amount <= 0.0 ) return base;
  442. + if( amount >= 1.0 ) return color;
  443. + if( isnan( amount ) ) return base;
  444. +
  445. + double ri = contrastRatio( base, color );
  446. + double rg = 1.0 + ( ( ri + 1.0 ) * amount * amount * amount );
  447. + double u = 1.0, l = 0.0;
  448. + QColor result;
  449. + for ( int i = 12 ; i ; --i )
  450. + {
  451. +
  452. + double a = 0.5 * ( l+u );
  453. + result = tintHelper( base, color, a );
  454. + double ra = contrastRatio( base, result );
  455. + if( ra > rg ) u = a;
  456. + else l = a;
  457. +
  458. + }
  459. +
  460. + return result;
  461. +
  462. + }
  463. +
  464. + //___________________________________________________________________
  465. + QColor mix( const QColor &c1, const QColor &c2, qreal bias )
  466. + {
  467. + if( bias <= 0.0 ) return c1;
  468. + if( bias >= 1.0 ) return c2;
  469. + if( isnan( bias ) ) return c1;
  470. +
  471. + qreal r = mixQreal( c1.redF(), c2.redF(), bias );
  472. + qreal g = mixQreal( c1.greenF(), c2.greenF(), bias );
  473. + qreal b = mixQreal( c1.blueF(), c2.blueF(), bias );
  474. + qreal a = mixQreal( c1.alphaF(), c2.alphaF(), bias );
  475. +
  476. + return QColor::fromRgbF( r, g, b, a );
  477. + }
  478. +
  479. +
  480. + //___________________________________________________________________
  481. + QColor shade(const QColor &color, ShadeRole role)
  482. + { return shade(color, role, _contrast ); }
  483. +
  484. + //___________________________________________________________________
  485. + QColor shade(const QColor &color, ShadeRole role, qreal contrast, qreal chromaAdjust)
  486. + {
  487. +
  488. + // nan -> 1.0
  489. + contrast = (1.0 > contrast ? (-1.0 < contrast ? contrast : -1.0) : 1.0);
  490. + qreal y = luma(color), yi = 1.0 - y;
  491. +
  492. + if (y < 0.006)
  493. + {
  494. +
  495. + // handle very dark colors (base, mid, dark, shadow == midlight, light)
  496. + switch (role)
  497. + {
  498. +
  499. + case LightShade: return shade(color, 0.05 + 0.95 * contrast, chromaAdjust);
  500. + case MidShade: return shade(color, 0.01 + 0.20 * contrast, chromaAdjust); case DarkShade: return shade(color, 0.02 + 0.40 * contrast, chromaAdjust);
  501. + default: return shade(color, 0.03 + 0.60 * contrast, chromaAdjust);
  502. +
  503. + }
  504. +
  505. + } else if (y > 0.93) {
  506. +
  507. + // handle very light colors (base, midlight, light == mid, dark, shadow)
  508. + switch (role)
  509. + {
  510. +
  511. + case MidlightShade: return shade(color, -0.02 - 0.20 * contrast, chromaAdjust);
  512. + case DarkShade: return shade(color, -0.06 - 0.60 * contrast, chromaAdjust);
  513. + case ShadowShade: return shade(color, -0.10 - 0.90 * contrast, chromaAdjust);
  514. + default: return shade(color, -0.04 - 0.40 * contrast, chromaAdjust);
  515. +
  516. + }
  517. +
  518. + } else {
  519. +
  520. + // handle everything else
  521. + qreal lightAmount = (0.05 + y * 0.55) * (0.25 + contrast * 0.75);
  522. + qreal darkAmount = ( - y ) * (0.55 + contrast * 0.35);
  523. + switch (role)
  524. + {
  525. + case LightShade: return shade(color, lightAmount, chromaAdjust);
  526. + case MidlightShade: return shade(color, (0.15 + 0.35 * yi) * lightAmount, chromaAdjust);
  527. + case MidShade: return shade(color, (0.35 + 0.15 * y) * darkAmount, chromaAdjust);
  528. + case DarkShade: return shade(color, darkAmount, chromaAdjust);
  529. + default: return darken(shade(color, darkAmount, chromaAdjust), 0.5 + 0.3 * y);
  530. + }
  531. +
  532. + }
  533. +
  534. + }
  535. +
  536. + //___________________________________________________________________
  537. + QColor shade( const QColor &color, qreal ky, qreal kc )
  538. + {
  539. + HCY c( color );
  540. + c.y = normalize( c.y + ky );
  541. + c.c = normalize( c.c + kc );
  542. + return c.qColor();
  543. + }
  544. +
  545. +
  546. +}
  547. diff --git a/src/qcolorutils.h b/src/qcolorutils.h
  548. new file mode 100644
  549. index 0000000..f2d3b9f
  550. --- /dev/null
  551. +++ b/src/qcolorutils.h
  552. @@ -0,0 +1,110 @@
  553. +#ifndef qcolorutils_h
  554. +#define qcolorutils_h
  555. +
  556. +/*
  557. + * Copyright (C) 2010 Hugo Pereira Da Costa <hugo@oxygen-icons.org>
  558. + *
  559. + * copied from kdelibs/kdeui/color/kcolorutils.h
  560. + * Copyright (C) 2007 Matthew Woehlke <mw_triad@users.sourceforge.net>
  561. + * Copyright (C) 2007 Thomas Zander <zander@kde.org>
  562. + * Copyright (C) 2007 Zack Rusin <zack@kde.org>
  563. + *
  564. + * This library is free software; you can redistribute it and/or
  565. + * modify it under the terms of the GNU Library General Public
  566. + * License as published by the Free Software Foundation; either
  567. + * version 2 of the License, or (at your option) any later version.
  568. + *
  569. + * This library is distributed in the hope that it will be useful,
  570. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  571. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  572. + * Library General Public License for more details.
  573. + *
  574. + * You should have received a copy of the GNU Library General Public License
  575. + * along with this library; see the file COPYING.LIB. If not, write to
  576. + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  577. + * Boston, MA 02110-1301, USA.
  578. + */
  579. +
  580. +#include <QColor>
  581. +
  582. +/*
  583. + * A set of methods used to work with colors.
  584. + */
  585. +namespace QColorUtils
  586. +{
  587. +
  588. + //! set contrast values
  589. + void setContrast( qreal );
  590. +
  591. + //! contrast
  592. + const qreal& contrast( void );
  593. +
  594. + //! background contrast
  595. + const qreal& backgroundContrast( void );
  596. +
  597. + //!@name color utilities
  598. + //@{
  599. + bool lowThreshold( const QColor& );
  600. + bool highThreshold( const QColor& );
  601. + QColor backgroundTopColor( const QColor& );
  602. + QColor backgroundBottomColor( const QColor& );
  603. + QColor backgroundRadialColor( const QColor& );
  604. +
  605. + //! returns menu background color matching position in a top level widget of given height
  606. + QColor backgroundColor(const QColor &color, int height, int y);
  607. +
  608. + //@}
  609. +
  610. + /*!
  611. + Calculate the luma of a color. Luma is weighted sum of gamma-adjusted
  612. + R'G'B' components of a color. The result is similar to qGray. The range
  613. + is from 0.0 (black) to 1.0 (white).
  614. + */
  615. + qreal luma(const QColor&);
  616. +
  617. + /*!
  618. + Calculate the contrast ratio between two colors, according to the
  619. + W3C/WCAG2.0 algorithm, (Lmax + 0.05)/(Lmin + 0.05), where Lmax and Lmin
  620. + are the luma values of the lighter color and the darker color,
  621. + respectively.
  622. + */
  623. + qreal contrastRatio(const QColor&, const QColor&);
  624. +
  625. + //! Adjust the luma of a color by changing its distance from white.
  626. + QColor lighten(const QColor&, qreal amount = 0.5, qreal chromaInverseGain = 1.0);
  627. +
  628. + //! Adjust the luma of a color by changing its distance from black.
  629. + QColor darken(const QColor&, qreal amount = 0.5, qreal chromaGain = 1.0);
  630. +
  631. + //! Create a new color by tinting one color with another
  632. + QColor tint(const QColor &base, const QColor &color, qreal amount = 0.3);
  633. +
  634. + //! mix two colors
  635. + QColor mix(const QColor &c1, const QColor &c2, qreal bias = 0.5);
  636. +
  637. + enum ShadeRole
  638. + {
  639. +
  640. + // The light color is lighter than dark() or shadow() and contrasts with the base color.
  641. + LightShade,
  642. +
  643. + // The midlight color is in between base() and light().
  644. + MidlightShade,
  645. +
  646. + // The mid color is in between base() and dark().
  647. + MidShade,
  648. +
  649. + // The dark color is in between mid() and shadow().
  650. + DarkShade,
  651. +
  652. + // The shadow color is darker than light() or midlight() and contrasts the base color.
  653. + ShadowShade
  654. +
  655. + };
  656. +
  657. + QColor shade(const QColor&, ShadeRole);
  658. + QColor shade(const QColor&, ShadeRole, qreal contrast, qreal chromaAdjust = 0.0);
  659. + QColor shade(const QColor&, qreal lumaAmount, qreal chromaAmount = 0.0);
  660. +}
  661. +
  662. +#endif
  663. diff --git a/src/rcproperties.cpp b/src/rcproperties.cpp
  664. index a41c000..be7eb2e 100644
  665. --- a/src/rcproperties.cpp
  666. +++ b/src/rcproperties.cpp
  667. @@ -26,6 +26,7 @@
  668. #include "utilities.h"
  669. #include "rcproperties.h"
  670. #include "engine.h"
  671. +#include "qcolorutils.h"
  672.  
  673. #include <QtDebug>
  674. #include <QToolTip>
  675. @@ -225,6 +226,9 @@ void RcProperties::setColorProperties()
  676. mapColor("text[INSENSITIVE]", QPalette::Disabled, QPalette::Text);
  677. mapColor("base[INSENSITIVE]", QPalette::Disabled, QPalette::Base);
  678.  
  679. + // Contrast
  680. + QColorUtils::setContrast( qreal( kdeConfigValue("/share/config/kdeglobals", "KDE/contrast", 0.5, true ).second.toInt() )/10 );
  681. +
  682. // Tooltips
  683. QColor tooltipBg(convertColor(kdeConfigValue("/share/config/kdeglobals", "Colors:Tooltip/BackgroundNormal", QToolTip::palette().color(QPalette::Active, QPalette::Base), true).second));
  684. QColor tooltipFg(convertColor(kdeConfigValue("/share/config/kdeglobals", "Colors:Tooltip/ForegroundNormal", QToolTip::palette().color(QPalette::Active, QPalette::Text), true).second));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement