📄 klearlook.cpp
字号:
/* $Id: klearlook.cpp,v 1.25 2006/04/26 18:55:41 jck Exp $Klearlook (C) Joerg C. Koenig, 2005 jck@gmx.org----Based upon QtCurve (C) Craig Drummond, 2003 Craig.Drummond@lycos.co.uk Bernhard Rosenkr�zer <bero@r?dh?t.com> Preston Brown <pbrown@r?dh?t.com> Than Ngo <than@r?dh?t.com>Released under the GNU General Public License (GPL) v2.----B???Curve is based on the KDE Light style, 2nd revision:Copyright(c)2000-2001 Trolltech AS (info@trolltech.com)Permission is hereby granted, free of charge, to any person obtaining acopy of this software and associated documentation files(the "Software"),to deal in the Software without restriction, including without limitationthe rights to use, copy, modify, merge, publish, distribute, sublicense,and/or sell copies of the Software, and to permit persons to whom theSoftware is furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALLTHE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISINGFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHERDEALINGS IN THE SOFTWARE.*/#include <kdeversion.h>#include <qmenubar.h>#include <qapplication.h>#include <qpainter.h>#include <qpalette.h>#include <qframe.h>#include <qpushbutton.h>#include <qdrawutil.h>#include <qscrollbar.h>#include <qtabbar.h>#include <qtabwidget.h>#include <qguardedptr.h>#include <qlayout.h>#include <qlineedit.h>#include <qlistview.h>#include <qbitmap.h>#include <qcleanuphandler.h>#include <qimage.h>#include <qcombobox.h>#include <qspinbox.h>#include <qslider.h>#include <qstylefactory.h>#include <qcleanuphandler.h>#include <qcheckbox.h>#include <qradiobutton.h>#include <qtoolbutton.h>#include <qtoolbar.h>#include <qprogressbar.h>#include <qcursor.h>#include <qheader.h>#include <qwidgetstack.h>#include <qsplitter.h>#include <math.h>#include <stdlib.h>#include <unistd.h>#include <sys/types.h>#include "klearlook.h"#include <qsettings.h>#if KDE_VERSION >= 0x30200#include <qfile.h>#include <qdir.h>#endif// Uncomment the following to enable gradients in toolbars and menubars// NOTE: Not yet complete!!!//#define QTC_GRADIENT_TOOLBARS_AND_MENUBARS//static int HIGH_LIGHT_FACTORS[]={ 100, 100, 100, 101, 102, 103, 104, 105 /*def*/, 106, 107, 108 };//#define HIGHLIGHT_FACTOR(X) (X<0||X>10) ? 105 : HIGH_LIGHT_FACTORS[X]#define QTC_HIGHLIGHT_FACTOR 105#define QTC_BORDERED_FRAME_WIDTH 2#define QTC_DEF_FRAME_WIDTH 1 //#define QTC_MIN_BTN_SIZE 10#define QTC_NO_SECT -1#define MENU_POPUP_ITEM_HIGH_HI 7#define MENU_POPUP_ITEM_HIGH_LO 5 //#define MENU_POPUP_SHADOW#define POS_DIV(a, b) ( (a)/(b) + ( ( (a) % (b) >= (b)/2 ) ? 1 : 0 ) )static const int itemHMargin = 6;static const int itemFrame = 2;static const int arrowHMargin = 6;static const int rightBorder = 12;#if KDE_VERSION >= 0x30200 // Try to read $KDEHOME/share/config/kickerrc to find out if kicker is transparent...static QString readEnvPath( const char *env ) { QCString path = getenv( env ); return path.isEmpty() ? QString::null : QFile::decodeName( path );}static bool kickerIsTrans() { QString kdeHome( readEnvPath( getuid() ? "KDEHOME" : "KDEROOTHOME" ) ), cfgFileName; bool trans = false; if ( kdeHome.isEmpty() ) cfgFileName = QDir::homeDirPath() + "/.kde/share/config/kickerrc"; else cfgFileName = QString( kdeHome ) + "/share/config/kickerrc"; QFile cfgFile( cfgFileName ); if ( cfgFile.open( IO_ReadOnly ) ) { QTextStream stream( &cfgFile ); QString line; bool stop = false, inGen = false; while ( !stream.atEnd() && !stop ) { line = stream.readLine(); if ( inGen ) { if ( 0 == line.find( "Transparent=" ) ) // Found it! { if ( -1 != line.find( "true" ) ) trans = true; stop = true; } else if ( line[ 0 ] == QChar( '[' ) ) // Then wasn't in General section... stop = true; } else if ( 0 == line.find( "[General]" ) ) inGen = true; } cfgFile.close(); } return trans;}#endifinline int limit( double c ) { return c < 0.0 ? 0 : c > 255.0 ? 255 : ( int ) c;}inline QColor midColor( const QColor &a, const QColor &b, double factor = 1.0 ) { return QColor( ( a.red() + limit( b.red() * factor ) ) >> 1, ( a.green() + limit( b.green() * factor ) ) >> 1, ( a.blue() + limit( b.blue() * factor ) ) >> 1 );}// Copied from Keramik...static bool isFormWidget( const QWidget *widget ) { //Form widgets are in the KHTMLView, but that has 2 further inner levels //of widgets - QClipperWidget, and outside of that, QViewportWidget QWidget * potentialClipPort = widget->parentWidget(); if ( !potentialClipPort || potentialClipPort->isTopLevel() ) return false; QWidget *potentialViewPort = potentialClipPort->parentWidget(); if ( !potentialViewPort || potentialViewPort->isTopLevel() || qstrcmp( potentialViewPort->name(), "qt_viewport" ) ) return false; QWidget *potentialKHTML = potentialViewPort->parentWidget(); if ( !potentialKHTML || potentialKHTML->isTopLevel() || qstrcmp( potentialKHTML->className(), "KHTMLView" ) ) return false; return true;}static void rgb2hls( double *r, double *g, double *b ) { double min; double max; double red; double green; double blue; double h, l, s; double delta; red = *r; green = *g; blue = *b; if (red > green) { if (red > blue) max = red; else max = blue; if (green < blue) min = green; else min = blue; } else { if (green > blue) max = green; else max = blue; if (red < blue) min = red; else min = blue; } l = (max + min) / 2; s = 0; h = 0; if (max != min) { if (l <= 0.5) s = (max - min) / (max + min); else s = (max - min) / (2 - max - min); delta = max -min; if (red == max) h = (green - blue) / delta; else if (green == max) h = 2 + (blue - red) / delta; else if (blue == max) h = 4 + (red - green) / delta; h *= 60; if (h < 0.0) h += 360; } *r = h; *g = l; *b = s;}static void hls2rgb( double *h, double *l, double *s ) { double hue; double lightness; double saturation; double m1, m2; double r, g, b; lightness = *l; saturation = *s; if (lightness <= 0.5) m2 = lightness * (1 + saturation); else m2 = lightness + saturation - lightness * saturation; m1 = 2 * lightness - m2; if (saturation == 0) { *h = lightness; *l = lightness; *s = lightness; } else { hue = *h + 120; while (hue > 360) hue -= 360; while (hue < 0) hue += 360; if (hue < 60) r = m1 + (m2 - m1) * hue / 60; else if (hue < 180) r = m2; else if (hue < 240) r = m1 + (m2 - m1) * (240 - hue) / 60; else r = m1; hue = *h; while (hue > 360) hue -= 360; while (hue < 0) hue += 360; if (hue < 60) g = m1 + (m2 - m1) * hue / 60; else if (hue < 180) g = m2; else if (hue < 240) g = m1 + (m2 - m1) * (240 - hue) / 60; else g = m1; hue = *h - 120; while (hue > 360) hue -= 360; while (hue < 0) hue += 360;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -