You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tde-style-ia-ora/src/widget/ia_ora.cpp

3427 lines
118 KiB

/*
* Copyright (C) 2007 Gustavo Pichorim Boiko <boiko@mandriva.com>
* Copyright (C) 2006 Laurent Montel <lmontel@mandriva.com>
*
* based on KDE3 HighColor Style (version 1.0)
* Copyright (C) 2001-2002 Karol Szwed <gallium@kde.org>
* (C) 2001-2002 Fredrik Höglund <fredrik@kde.org>
*
* renderGradient() code adapted from the Plastik stype
* Copyright (C) 2003 Sandro Giessl <ceebx@users.sourceforge.net>
*
* Drawing routines adapted from the KDE2 HCStyle,
* Copyright (C) 2000 Daniel M. Duley <mosfet@kde.org>
* (C) 2000 Dirk Mueller <mueller@kde.org>
* (C) 2001 Martijn Klingens <klingens@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <qdict.h>
#include <qdrawutil.h>
#include <qpainter.h>
#include <qpointarray.h>
#include <qstyleplugin.h>
#include <qprogressbar.h>
#include <qcombobox.h>
#include <qheader.h>
#include <qmenubar.h>
#include <qpushbutton.h>
#include <qscrollbar.h>
#include <qslider.h>
#include <qtabbar.h>
#include <qtoolbutton.h>
#include <qtoolbar.h>
#include <qpopupmenu.h>
#include <kstandarddirs.h>
#include <kdrawutil.h>
#include <kpixmapeffect.h>
#include <qradiobutton.h>
#include <qimage.h>
#include <qcheckbox.h>
#include "ia_ora.h"
#include "ia_ora.moc"
#include "bitmaps.h"
#include <qlistview.h>
#include <qlistbox.h>
#include <kdebug.h>
//#define USE_CROSS 1
// -- Style Plugin Interface -------------------------
class ThemeMdvStylePlugin : public QStylePlugin
{
public:
ThemeMdvStylePlugin() {}
~ThemeMdvStylePlugin() {}
QStringList keys() const
{
return QStringList() << "ia_ora";
}
QStyle* create( const QString& key )
{
if ( key == "ia_ora" )
return new MandrivaStyle( );
return 0;
}
};
Q_EXPORT_PLUGIN( ThemeMdvStylePlugin )
// ---------------------------------------------------
// ### Remove globals
QBitmap menuBmp;
static bool scrollmin = false;
static bool scrollmax = false;
static const int itemFrame = 1;
static const int itemHMargin = 3;
static const int itemVMargin = 0;
static const int arrowHMargin = 6;
static const int rightBorder = 12;
static const char* kdeToolbarWidget = "kde toolbar widget";
const int smallButMaxW = 27;
const int smallButMaxH = 20;
// ---------------------------------------------------------------------------
MandrivaStyle::MandrivaColorData::~MandrivaColorData()
{
}
// ---------------------------------------------------------------------------
MandrivaStyle::MandrivaStyle( )
: KStyle( AllowMenuTransparency | FilledFrameWorkaround, WindowsStyleScrollBar )
, m_dataCache (), formMode( false ),kickerMode(false)
{
hoverWidget = 0L;
hoverControl = HoverNone;
m_dataCache.setAutoDelete(true);
horizontalLine = 0;
verticalLine = 0;
// setup pixmap cache...
pixmapCache = new QIntCache<CacheEntry>(150000, 499);
pixmapCache->setAutoDelete(true);
}
MandrivaStyle::~MandrivaStyle()
{
delete pixmapCache;
delete horizontalLine;
delete verticalLine;
}
MandrivaStyle::MandrivaColorData *MandrivaStyle::realizeData (const QColorGroup &cg) const
{
MandrivaColorData *cdata;
//define mandriva color
cdata = new MandrivaColorData;
cdata->spotColor = cg.highlight().rgb();
//blue mdk color
//cg.base() == white
//G0 gb.background()
//B2 gb.hightlight
//Hardcode
if ( cg.background() == QColor( "#EFF3F7" ) )
{
//Be sure to use design color
cdata->shades[0]=QColor( "#EFF3F7" );
cdata->shades[1]=QColor( "#DFE7EF" );
cdata->shades[2]=QColor( "#CFD7DF" );
cdata->shades[3]=QColor( "#C7D3DF" );
cdata->shades[4]=QColor( "#B6C3CF" );
cdata->shades[5]=QColor( "#A6B2C7" );
cdata->shades[6]=QColor( "#8692A6" );
}
else
{
//create algo
cdata->shades[0]=cg.background();
cdata->shades[1]=cdata->shades[0].dark(107);
cdata->shades[2]=cdata->shades[0].dark(115);
cdata->shades[3]=cdata->shades[0].dark(117);
cdata->shades[4]=cdata->shades[0].dark(131);
cdata->shades[5]=cdata->shades[0].dark(144);
cdata->shades[6]=cdata->shades[0].dark(178);
}
if ( cg.highlight() == QColor("#4965AE" ) ) // Blue
{
cdata->blueMdkColor[0]=QColor("#A6B6E7" );
cdata->blueMdkColor[1]=QColor("#8EA2CF" );
cdata->blueMdkColor[2]=QColor("#4965AE" );
cdata->blueMdkColor[3]=QColor("#415DA6" );
cdata->blueMdkColor[4]=QColor("#21459C" );
}
else if ( cg.highlight() == QColor("#8EC7FF" ) ) // Arctic
{
cdata->blueMdkColor[0]=QColor("#EFF7FF" );
cdata->blueMdkColor[1]=QColor("#C7DFFF" );
cdata->blueMdkColor[2]=QColor("#8EC7FF" );
cdata->blueMdkColor[3]=QColor("#79BEFF" );
cdata->blueMdkColor[4]=QColor("#69B6FF" );
}
else if ( cg.highlight() == QColor("#7BAAE7" ) ) // Smooth
{
cdata->blueMdkColor[0]=QColor("#CEE3FF" );
cdata->blueMdkColor[1]=QColor("#ADCFFF" );
cdata->blueMdkColor[2]=QColor("#7BAAE7" );
cdata->blueMdkColor[3]=QColor("#5A8AD6" );
cdata->blueMdkColor[4]=QColor("#427DC6" );
}
else if ( cg.highlight() == QColor("#F7B610" ) ) // Orange
{
cdata->blueMdkColor[0]=QColor("#FFDF10" );
cdata->blueMdkColor[1]=QColor("#FFCB10" );
cdata->blueMdkColor[2]=QColor("#F7B610" );
cdata->blueMdkColor[3]=QColor("#FFA208" );
cdata->blueMdkColor[4]=QColor("#F79600" );
}
else if ( cg.highlight() == QColor("#CFD7DF" ) ) // Gray
{
cdata->blueMdkColor[0]=cdata->shades[1];
cdata->blueMdkColor[1]=cdata->shades[2];
cdata->blueMdkColor[2]=cdata->shades[3];
cdata->blueMdkColor[3]=cdata->shades[4];
cdata->blueMdkColor[4]=cdata->shades[5];
}
else
{
cdata->blueMdkColor[2]=cg.highlight();
cdata->blueMdkColor[0]=cdata->blueMdkColor[2].light(150);
cdata->blueMdkColor[1]=cdata->blueMdkColor[2].light(137);
cdata->blueMdkColor[3]=cdata->blueMdkColor[2].dark(112);
cdata->blueMdkColor[4]=cdata->blueMdkColor[2].dark(130);
}
if (cg.button() == cg.background())
{
for (int i=0; i < 7; ++i)
cdata->buttonColor[i] = cdata->shades[i];
}
else if ( cg.button() == QColor( "#EFF3F7" ) )
{
//Be sure to use design color
cdata->buttonColor[0]=QColor( "#EFF3F7" );
cdata->buttonColor[1]=QColor( "#DFE7EF" );
cdata->buttonColor[2]=QColor( "#CFD7DF" );
cdata->buttonColor[3]=QColor( "#C7D3DF" );
cdata->buttonColor[4]=QColor( "#B6C3CF" );
cdata->buttonColor[5]=QColor( "#A6B2C7" );
cdata->buttonColor[6]=QColor( "#8692A6" );
}
else
{
cdata->buttonColor[0]=cg.button();
cdata->buttonColor[1]=cdata->buttonColor[0].dark(107);
cdata->buttonColor[2]=cdata->buttonColor[0].dark(115);
cdata->buttonColor[3]=cdata->buttonColor[0].dark(117);
cdata->buttonColor[4]=cdata->buttonColor[0].dark(131);
cdata->buttonColor[5]=cdata->buttonColor[0].dark(144);
cdata->buttonColor[6]=cdata->buttonColor[0].dark(178);
}
return cdata;
}
/* We assume this seldom collides, since we can only cache one at a time */
static long hashColorGroup (const QColorGroup &cg)
{
return cg.button().rgb();// << 8 ^ cg.button().rgb();
}
const MandrivaStyle::MandrivaColorData *MandrivaStyle::lookupData (const QColorGroup &cg) const
{
MandrivaColorData *cdata;
long h;
QIntCache<MandrivaColorData> *cache;
h = hashColorGroup (cg);
// Cast away the const crap
// Nasty, but how else would i do it?
cache = (QIntCache<MandrivaColorData> *)&m_dataCache;
cdata = cache->find(h);
if (cdata == 0 || !cdata->isGroup(cg))
{
if (cdata != 0)
{
cache->remove (h);
}
cdata = realizeData (cg);
cache->insert (h, cdata);
}
return cdata;
}
void MandrivaStyle::getShade (const QColorGroup &cg, int shadenr, QColor &res) const
{
const MandrivaColorData *cdata = lookupData(cg);
res = cdata->shades[shadenr];
}
void MandrivaStyle::updateHoverControl(const QPoint &pos)
{
QRegion repaint;
enum Hover oldControl = hoverControl;
hoverControl = HoverNone;
if (!hoverWidget)
return;
if (hoverWidget->inherits("QScrollBar"))
{
QRect subline(querySubControlMetrics(CC_ScrollBar, hoverWidget,
SC_ScrollBarSubLine)),
addline(querySubControlMetrics(CC_ScrollBar, hoverWidget,
SC_ScrollBarAddLine)),
slider(querySubControlMetrics(CC_ScrollBar, hoverWidget,
SC_ScrollBarSlider));
if (subline.contains(pos))
hoverControl = HoverScrollBarSubLine;
else if (addline.contains(pos))
hoverControl = HoverScrollBarAddLine;
else if (slider.contains(pos))
hoverControl = HoverScrollBarSlider;
if (hoverControl == HoverScrollBarSubLine
|| oldControl == HoverScrollBarSubLine)
repaint += subline;
if (hoverControl == HoverScrollBarAddLine
|| oldControl == HoverScrollBarAddLine)
repaint += addline;
if (hoverControl == HoverScrollBarSlider
|| oldControl == HoverScrollBarSlider)
repaint += slider;
}
else if (hoverWidget->inherits("QComboBox"))
{
QComboBox *cb = static_cast<QComboBox*>(hoverWidget);
// for not editable combo, this is not necessary
if (!cb->editable())
return;
QRect comboArrow(querySubControlMetrics(CC_ComboBox, hoverWidget,
SC_ComboBoxArrow)),
comboEditField(querySubControlMetrics(CC_ComboBox, hoverWidget,
SC_ComboBoxEditField));
if (comboArrow.contains(pos))
hoverControl = HoverComboBoxArrow;
else if (comboEditField.contains(pos))
hoverControl = HoverComboBoxEdit;
if (hoverControl == HoverComboBoxArrow
|| oldControl == HoverComboBoxArrow)
repaint += comboArrow;
if (hoverControl == HoverComboBoxEdit
|| oldControl == HoverComboBoxEdit)
repaint += comboEditField;
}
// if we are still in the same subcontrol, return
if (oldControl != hoverControl)
hoverWidget->repaint(repaint, false);
}
void MandrivaStyle::polish(QApplication* app)
{
if (!qstrcmp(app->argv()[0], "kicker"))
kickerMode = true;
}
void MandrivaStyle::polish(QWidget* widget)
{
// Put in order of highest occurance to maximize hit rate
if ( widget->inherits( "QComboBox" )
|| widget->inherits("QScrollBar")
|| widget->inherits("QHeader")
|| widget->inherits( "QSlider" )
|| widget->inherits( "QCheckBox" )
|| widget->inherits("QSplitterHandle"))
{
widget->installEventFilter(this);
if (widget->inherits( "QScrollBar" ) || widget->inherits( "QComboBox" ))
widget->setMouseTracking( true );
}
else if (widget->inherits("QMenuBar")
|| widget->inherits("QPopupMenu") )
{
widget->setBackgroundMode(QWidget::NoBackground);
}
else if (widget->inherits("QPushButton") )
{
widget->installEventFilter(this);
widget->setBackgroundMode( QWidget::PaletteBackground );
}
else if ( widget->inherits( "KToolBarSeparator" ) || widget->inherits( "QToolBarSeparator" ) )
{
widget->setBackgroundMode( QWidget::PaletteBackground );
}
else if (widget->inherits("QToolBarExtensionWidget"))
{
widget->installEventFilter(this);
}
else if ( widget->parentWidget() &&
( ( widget->inherits( "QListBox" ) && widget->parentWidget()->inherits( "QComboBox" ) )
|| widget->inherits( "KCompletionBox" ) ) )
{
QListBox* listbox = (QListBox*) widget;
listbox->setLineWidth( 1 );
listbox->setBackgroundMode( NoBackground );
widget->installEventFilter( this );
}
else if ( !qstrcmp( widget->name(), kdeToolbarWidget) )
{
widget->setBackgroundMode( NoBackground ); // We paint the whole background.
widget->installEventFilter(this);
}
KStyle::polish( widget );
}
void MandrivaStyle::unPolish(QWidget* widget)
{
QFont f = QApplication::font();
QApplication::setFont( f, TRUE ); // get rid of the special fonts for special widget classes
if ( widget->inherits( "QComboBox" )
|| widget->inherits("QScrollBar")
|| widget->inherits("QHeader")
|| widget->inherits( "QSlider" )
|| widget->inherits( "QCheckBox" )
|| widget->inherits("QSplitterHandle"))
{
widget->removeEventFilter(this);
}
else if ( widget->inherits("QMenuBar")
|| widget->inherits("QPopupMenu"))
{
widget->setBackgroundMode(QWidget::PaletteBackground);
}
else if ( widget->inherits("QPushButton") )
{
widget->removeEventFilter(this);
}
else if (widget->inherits("QToolBarExtensionWidget"))
{
widget->removeEventFilter(this);
}
else if ( widget->parentWidget() &&
( ( widget->inherits( "QListBox" ) && widget->parentWidget()->inherits( "QComboBox" ) )
|| widget->inherits( "KCompletionBox" ) ) )
{
QListBox* listbox = (QListBox*) widget;
listbox->setLineWidth( 1 );
listbox->setBackgroundMode( PaletteBackground );
widget->removeEventFilter( this );
widget->clearMask();
}
//For toolbar internal separators, return to button, too (can't use qt_cast here since don't have access to the class)
else if ( widget->inherits( "KToolBarSeparator" ) || widget->inherits( "QToolBarSeparator" ) )
{
widget->setBackgroundMode( QWidget::PaletteBackground );
}
else if ( !qstrcmp( widget->name(), kdeToolbarWidget) )
{
widget->setBackgroundMode( PaletteBackground );
widget->removeEventFilter(this);
}
KStyle::unPolish( widget );
}
/* reimp. */
void MandrivaStyle::renderMenuBlendPixmap( KPixmap& pix, const QColorGroup &cg,
const QPopupMenu* /* popup */ ) const
{
QColor col = cg.background();
//FIXME !!!!!!!!!!!!!!!
#ifdef Q_WS_X11 // Only draw menu gradients on TrueColor, X11 visuals
if ( QPaintDevice::x11AppDepth() >= 24 )
KPixmapEffect::gradient( pix, col.light(120), col.dark(115),
KPixmapEffect::HorizontalGradient );
else
#endif
pix.fill( col );
}
void MandrivaStyle::drawHandle( const MandrivaColorData *cdata,
QPainter *p,
const QRect &r,
const QColorGroup & /*cg*/,
SFlags flags,
const QStyleOption& /*opt*/,
bool /*drawBorder*/ /*for the future remove it*/, bool drawGradient) const
{
int x,y,width,height;
r.rect(&x, &y, &width, &height);
int i = 0;
int delta=0;
//fix for handle toolbar, otherwise it's not center
if (!(flags & Style_Horizontal))
{
if ( drawGradient )
renderGradient( p, QRect(x+2,y+2,width-4, height-4),
cdata->shades[2], cdata->shades[0],false);
if(width > 30)
{
delta = x + (width/2) - 11;
for(i = 0; i < 3; i++)
{
drawHandlePoint (cdata,p, (delta + 9*i),
y + QMAX((height-4)/2,0));
}
}
else
{
drawHandlePoint (cdata, p, x + (width-4)/2 ,
y + QMAX((height-4)/2,0));
}
}
else
{
if( drawGradient )
renderGradient(p, QRect(x+2,y+2,width-4, height-4),
cdata->shades[0],cdata->shades[2], true);
if(height > 30)
{
delta = y + (height / 2) - 11;
for(i = 0; i < 3; i++)
{
drawHandlePoint (cdata, p, x + QMAX((width-4)/2,0),
delta+9*i);
}
}
else
{
drawHandlePoint (cdata,p, x + QMAX((width-4)/2,0),
y + (height-4) / 2);
}
}
}
void MandrivaStyle::drawGroupBox(const MandrivaColorData *cdata, const QColorGroup & cg, QPainter *p, const QRect & r, bool /*active*/, bool sunken)const
{
int x,y,w,h;
x=r.x(); y=r.y(); w=r.width(); h=r.height();
int x2 = x+w-1;
int y2 = y+h-1;
p->setPen(cdata->shades[2]);
p->drawLine(x+1, y2, x2-1, y2);
p->drawLine(x2, y+1, x2, y2-1);
p->drawLine(x+1, y, x2-1, y);
p->drawLine(x, y+1, x, y2-1);
p->setPen( cg.background() );
p->drawPoint( x, y );
p->drawPoint( x, y2 );
p->drawPoint( x2, y );
p->drawPoint( x2, y2 );
p->setPen( sunken ?cg.base():cdata->shades[1] );
p->drawLine( x+1, y+1, x2-1, y+1 );
p->drawLine( x+1, y+2, x+1, y2-2 );
p->setPen( sunken ? cdata->shades[1] :cg.base() );
p->drawLine( x+1, y2-1, x2-1, y2-1 );
p->drawLine( x2-1, y+2, x2-1, y2-2 );
}
void MandrivaStyle::drawLineSeparator(const MandrivaColorData *cdata,
const QColorGroup & cg, QPainter *p,
const QRect & r, bool horizontal,
bool /*active*/, bool /*sunken*/,
bool skipOffset )const
{
QRect line1, line2;
p->fillRect(r, cg.background());
if (horizontal)
{
int offset = 0;
// remove 5 pixels from each side of the line
if (r.width() > 20 && skipOffset)
offset = 3;
// draw the separator in the middle of the given rect
int middle = (r.top() + r.bottom()) / 2;
line1 = QRect(r.x() + offset, middle, r.width() - 2*offset, 1);
line2 = QRect(r.x() + offset, middle+1, r.width() - 2*offset, 1);
}
else
{
int offset = 0;
// remove 5 pixels from each side of the line
if (r.height() > 20 && skipOffset)
offset = 3;
// draw the separator in the middle of the given rect
int middle = (r.left() + r.right()) / 2;
line1 = QRect(middle, r.y() + offset, 1, r.height() - 2*offset);
line2 = QRect(middle+1, r.y() + offset, 1, r.height() - 2*offset);
}
p->setPen(cdata->shades[2]);
p->drawLine(line1.left(), line1.top(), line1.right(), line1.bottom());
p->setPen( cg.base() );
p->drawLine(line2.left(), line2.top(), line2.right(), line2.bottom());
}
void MandrivaStyle::drawFrame( const MandrivaColorData *cdata, const QColorGroup & cg, QPainter *p, const QRect & r, bool active )const
{
//use by checkbox,lineedit,spinbox,combobox
int x,y,w,h;
x=r.x(); y=r.y(); w=r.width(); h=r.height();
int x2 = x+w-1;
int y2 = y+h-1;
p->setPen(cdata->shades[4]);
p->drawLine(x+1, y2, x2-1, y2);
p->drawLine(x2, y+1, x2, y2-1);
//Change color if it's active
if ( active )
p->setPen( cdata->shades[5] );
p->drawLine(x+1, y, x2-1, y);
p->drawLine(x, y+1, x, y2-1);
p->setPen( cg.background() );
p->drawPoint( x, y );
p->drawPoint( x, y2 );
p->drawPoint( x2, y );
p->drawPoint( x2, y2 );
}
// This function draws primitive elements as well as their masks.
void MandrivaStyle::drawPrimitive( PrimitiveElement pe,
QPainter *p,
const QRect &r,
const QColorGroup &cg,
SFlags flags,
const QStyleOption& opt ) const
{
int x, y, xw, yh;
x= r.x();
y= r.y();
xw = r.x()+r.width()-1;
yh = r.y()+r.height()-1;
bool down = flags & Style_Down;
bool on = flags & Style_On;
const MandrivaColorData *cdata = lookupData(cg);
bool sunken = flags & Style_Sunken;
switch(pe)
{
case PE_PanelTabWidget:
{
p->save();
p->setPen(cdata->shades[4]);
p->drawRect(r);
p->restore();
break;
}
case PE_FocusRect:
{
p->save();
p->setPen(cdata->shades[6]);
p->drawWinFocusRect( r );
p->restore();
break;
}
case PE_PanelMenuBar: // Menu
{
//FIXME
p->fillRect(r, cg.brush(QColorGroup::Background));
int x2 = r.x()+r.width()-1;
int y2 = r.y()+r.height()-1;
p->setPen(cdata->shades[2]);
p->drawLine(x, y2, x2, y2);
break;
}
case PE_PanelDockWindow: // Toolbar
{
bool horiz = r.width() > r.height();
//Here, we just draw the border.
int x = r.x();
int y = r.y();
int x2 = r.x() + r.width() - 1;
int y2 = r.y() + r.height() - 1;
int lw = opt.isDefault() ? pixelMetric(PM_DefaultFrameWidth)
: opt.lineWidth();
//FIXME
if (lw)
{
//Gradient border colors.
//(Same as in gradients.cpp)
QColor gradTop = cg.base();
QColor gradBot = cdata->shades[2];
if (horiz)
{
//Top line
p->setPen(gradTop);
p->drawLine(x, y, x2, y);
//Bottom line
p->setPen(gradBot);
p->drawLine(x, y2, x2, y2);
}
else
{
//Left line
p->setPen(gradTop);
p->drawLine(x, y, x, y2);
//Right line
p->setPen(gradBot);
p->drawLine(x2, y, x2, y2);
}
}
break;
}
case PE_DockWindowSeparator:
{
bool horiz = flags & Style_Horizontal;
drawLineSeparator( cdata, cg, p, r, !horiz, true, sunken );
break;
}
case PE_DockWindowResizeHandle:
case PE_Splitter:
{
QRect real(r);
real.addCoords( 1, 0,0 ,0);
QColor color = (hoverWidget == p->device())?cdata->shades[1]:cg.background();
p->fillRect( r, color );
p->setPen( cg.background() );
p->drawPoint( r.x(), 0 );
p->drawPoint( r.width()-1, 0 );
p->drawPoint( r.x(), r.height()-1 );
p->drawPoint( r.width()-1, r.height()-1 );
drawHandle( cdata, p,real,cg,flags,opt, false );
break;
}
case PE_PanelLineEdit:
{
drawFrame( cdata, cg, p, r, true );
break;
}
case PE_Panel: //QListBox and co
{
if(kickerMode)
break;
p->save();
p->setPen(cdata->shades[4]);
p->drawRect(r);
p->restore();
break;
}
case PE_StatusBarSection:
{
p->fillRect(r, cg.background());
break;
}
case PE_PanelPopup:
case PE_WindowFrame:
{
int lw = /*opt.isDefault() ? pixelMetric(PM_DefaultFrameWidth)
: opt.lineWidth()*/1;
if (lw == 1 || lw == 2)
{
QPen oldPen = p->pen();
int x,y,w,h;
r.rect(&x, &y, &w, &h);
int x2 = x+w-1;
int y2 = y+h-1;
p->setPen(sunken ? cg.light() : cdata->shades[2]);
p->drawLine(x, y2, x2, y2);
p->drawLine(x2, y, x2, y2);
p->setPen(sunken ? cdata->shades[2] : cg.light());
p->drawLine(x, y, x2, y);
p->drawLine(x, y, x, y2);
p->setPen(sunken ? cg.midlight() : cdata->shades[2]);
p->drawLine(x+1, y2-1, x2-1, y2-1);
p->drawLine(x2-1, y+1, x2-1, y2-1);
p->setPen(sunken ? cdata->shades[2] : cg.midlight());
p->drawLine(x+1, y+1, x2-1, y+1);
p->drawLine(x+1, y+1, x+1, y2-1);
if( lw == 2 )
{
p->setPen(sunken ? cg.midlight() : cdata->shades[5]);
p->drawLine(x+2, y2-2, x2-2, y2-2);
p->drawLine(x2-1, y+2, x2-2, y2-2);
p->setPen(sunken ? cdata->shades[5] : cg.midlight());
p->drawLine(x+2, y+2, x2-2, y+2);
p->drawLine(x+2, y+2, x+2, y2-2);
}
p->setPen(oldPen);
}
else
KStyle::drawPrimitive(pe, p, r, cg, flags, opt);
break;
}
case PE_GroupBoxFrame:
{
if ( opt.isDefault() || opt.lineWidth() <= 0 )
break;
drawGroupBox( cdata, cg, p, r, true,sunken );
break;
}
#if 0
case PE_PanelGroupBox:
drawPrimitive( PE_GroupBoxFrame, p, r, cg, flags, opt );
break;
#endif
case PE_Separator:
{
drawLineSeparator( cdata, cg, p, r, true, true, sunken );
break;
}
case PE_HeaderArrow:
{
if ( flags & Style_Up )
drawPrimitive( PE_ArrowUp, p, r, cg, Style_Enabled );
else
drawPrimitive( PE_ArrowDown, p, r, cg, Style_Enabled );
break;
}
case PE_HeaderSection:
{
bool horizontal = true;
bool isFirst = false;
if (p && p->device()->devType() == QInternal::Widget) {
QHeader* hdr = dynamic_cast<QHeader*>(p->device());
if (hdr)
{
horizontal = ( hdr->orientation() == Horizontal );
isFirst = hdr->mapToIndex(hdr->sectionAt(r.x() ) ) == 0;
}
}
int x,y,w,h;
r.rect(&x, &y, &w, &h);
QPen oldPen = p->pen();
//TODO verify it
if (flags & Style_MouseOver)
renderGradient( p, QRect(x, y, w, h-1),
cdata->shades[0],cdata->shades[2], !horizontal );
else if ( on )
renderGradient(p, QRect(x, y, w, h-1),
cdata->shades[0],cdata->shades[2], !horizontal );
else if ( down )
renderGradient(p, QRect(x, y, w, h-1),
cdata->shades[2],cdata->shades[1], !horizontal );
else
renderGradient( p, QRect(x, y, w, h-1),
cdata->shades[0],cdata->shades[2], !horizontal );
//don't draw separator for first eleemtn
if ( !isFirst )
{
drawLineSeparator(cdata, cg, p, QRect(x,y,2,h), false, true, false, false);
}
p->setPen( oldPen );
break;
}
case PE_ExclusiveIndicator:
{ //radiobutton
bool enabled = flags & Style_Enabled;
p->setPen( cdata->shades[4] );
p->setBrush( QBrush( enabled ? cg.base() : cdata->shades[0] ) );
p->drawEllipse( r );
bool specificBackground = excludeColor( cg.highlight(), enabled );
if (!(flags & Style_Off))
{
if (flags & Style_On) //on
{
if ( specificBackground )
p->setPen( enabled ? cdata->shades[6]:cdata->shades[3] );
else
p->setPen( enabled ? cdata->blueMdkColor[2]:cdata->shades[3] );
p->drawLine( x+5, y+3, xw-5, y+3 );
p->drawLine( x+4, y+4, xw-4, y+4 );
p->drawLine( x+3, y+5, xw-3, y+5 );
if ( specificBackground )
p->setPen( enabled ? cdata->shades[6]:cdata->shades[5] );
else
p->setPen( enabled ? cdata->blueMdkColor[4]:cdata->shades[5] );
p->drawLine( x+3, y+6, xw-3, y+6 );
p->drawLine( x+4, y+7, xw-4, y+7);
p->drawLine( x+5, y+8, xw-5, y+8 );
}
}
break;
}
case PE_CheckListIndicator:
{
QCheckListItem *item = opt.checkListItem();
if(!item)
return;
int x = r.x(), y = r.y(), w = r.width(), h = r.width();
drawPrimitive(PE_Indicator, p, QRect(x-2, y-2 , w+3, h+3 ) , cg, flags );
break;
}
//case PE_IndicatorMask:
case PE_Indicator:
{ //checkbox
bool enabled = flags & Style_Enabled;
//draw background use base color
QRect ar( x+1, y+1, x+11, y+10 );
p->fillRect (ar, enabled ? cg.base() : cdata->shades[0]);
bool specificBackground = excludeColor( cg.highlight(), enabled );
//TODO mouse over
if (!(flags & Style_Off))
{
if (flags & Style_On) //on
{
#ifdef USE_CROSS
p->setPen( enabled ? cdata->blueMdkColor[2]:cdata->shades[3] );
//TODO look at if we can use a qbitmap directly
p->drawLine( x+2, y+2, x+3, y+2 );
p->drawLine( x+2, y+3, x+4, y+3 );
p->drawLine( x+3, y+4, x+5, y+4 );
p->drawLine( x+4, y+5, x+8, y+5 );
p->drawLine( x+9, y+2, x+10, y+2 );
p->drawLine( x+8, y+3, x+10, y+3 );
p->drawLine( x+7, y+4, x+9, y+4 );
p->setPen( enabled ? cdata->blueMdkColor[4] : cdata->shades[5]);
p->drawLine( x+4, y+6, x+8, y+6 );
p->drawLine( x+3, y+7, x+5, y+7 );
p->drawLine( x+2, y+8, x+4, y+8 );
p->drawLine( x+2, y+9, x+3, y+9 );
p->drawLine( x+9, y+9, x+10, y+9 );
p->drawLine( x+8, y+8, x+10, y+8 );
p->drawLine( x+7, y+7, x+9, y+7 );
#else
if (QApplication::reverseLayout() )
{
if ( specificBackground )
p->setPen( enabled ? cdata->shades[6]:cdata->shades[3] );
else
p->setPen( enabled ? cdata->blueMdkColor[2]:cdata->shades[3] );
p->drawPoint( x+2,y+2 );
p->drawLine( x+2,y+3,x+3,y+3 );
p->drawLine( x+2,y+4,x+4,y+4 );
p->drawLine( x+3,y+5,x+5,y+5 );
p->drawLine( x+4,y+6,x+6,y+6 );
p->drawPoint( x+10,y+5 );
p->drawLine( x+9,y+6,x+10,y+6 );
if ( specificBackground )
p->setPen( enabled ? Qt::black : cdata->shades[4]);
else
p->setPen( enabled ? cdata->blueMdkColor[4] : cdata->shades[4]);
p->drawLine( x+5,y+7,x+10,y+7 );
p->drawLine( x+6,y+8,x+9,y+8 );
p->drawLine( x+7,y+9,x+8,y+9 );
}
else
{
if ( specificBackground )
p->setPen( enabled ? cdata->shades[6]:cdata->shades[3] );
else
p->setPen( enabled ? cdata->blueMdkColor[2]:cdata->shades[3] );
p->drawPoint( x+10,y+2 );
p->drawLine( x+9,y+3,x+10,y+3 );
p->drawLine( x+8,y+4,x+10,y+4 );
p->drawLine( x+7,y+5,x+9,y+5 );
p->drawLine( x+6,y+6,x+8,y+6 );
p->drawPoint( x+2,y+5 );
p->drawLine( x+2,y+6,x+3,y+6 );
if ( specificBackground )
p->setPen( enabled ? Qt::black : cdata->shades[4]);
else
p->setPen( enabled ? cdata->blueMdkColor[4] : cdata->shades[4]);
p->drawLine( x+2,y+7,x+7,y+7 );
p->drawLine( x+3,y+8,x+6,y+8 );
p->drawLine( x+4,y+9,x+5,y+9 );
}
#endif
}
else //tristate
{
if ( specificBackground )
p->setPen( enabled ? cdata->shades[6] : cdata->shades[3]);
else
p->setPen( enabled ? cdata->blueMdkColor[2] : cdata->shades[3]);
p->drawLine( x+4, y+5, x+8, y+5 );
p->drawLine( x+3, y+6, x+9, y+6 );
if ( specificBackground )
p->setPen( enabled ? Qt::black : cdata->shades[5]);
else
p->setPen( enabled ? cdata->blueMdkColor[4] : cdata->shades[5]);
p->drawLine( x+4, y+7, x+8, y+7 );
}
}
drawFrame( cdata, cg, p, r,true );
break;
}
case PE_SizeGrip:
{
int y = r.y();
int x2 = r.width();
int y2 = r.height();
p->setPen( cdata->shades[2] );
p->drawPoint( x2, y );
p->drawPoint( x2-1, y+1 );
p->drawLine( x2-2, y+2, x2-1, y+2 );
p->drawLine( x2-3, y+3, x2-1, y+3 );
p->drawLine( x2-4, y+4, x2-1, y+4 );
p->drawLine( x2-5, y+5, x2-1, y+5 );
p->drawLine( x2-6, y+6, x2-1, y+6 );
p->drawLine( x2-7, y+7, x2-2, y+7 );
p->drawLine( x2-8, y+8, x2-3, y+8 );
p->drawLine( x2-9, y+9, x2-4, y+9 );
p->drawLine( x2-10, y+10, x2-6, y+10 );
p->drawLine( x2-11, y+11, x2-9, y+11 );
p->drawPoint( x2, y+12 );
p->drawLine( x2-1, y+13,x2,y+13 );
p->drawLine( x2-2, y+14,x2-1,y+14 );
//TODO draw last point
p->setPen( cdata->shades[3] );
p->drawLine( x2, y+1, x2, y2-3 );
p->drawPoint( x2-1, y+7 );
p->drawLine( x2-2, y+8, x2-1, y+8 );
p->drawLine( x2-3, y+9, x2-1, y+9 );
p->drawLine( x2-5, y+10, x2-1, y+10 );
p->drawLine( x2-8, y+11, x2-1, y+11 );
p->drawLine( x2-12, y+12, x2-1, y+12 );
p->drawLine( x2-13, y+13, x2-2, y+13 );
p->drawLine( x2-14, y+14, x2-3, y+14 );
p->setPen( cg.background() );
p->drawPoint( x2, y2 );
break;
}
case PE_SpinWidgetUp:
case PE_SpinWidgetDown:
{
p->save();
QRect br;
QRect re( r );
br.setRect( r.x() , r.y(), r.width()+1, r.height() );
bool down = flags & Style_Down;
bool on = flags & Style_On;
bool sunken = on || down;
//Verify
if ( on )
renderGradient(p, br,
cdata->shades[0],cdata->shades[2], /*!horizontal*/ false);
else if ( down )
renderGradient(p, br,
cdata->shades[2],cdata->shades[1], /*!horizontal*/ false);
else if( !sunken && (flags & Style_Enabled ))
renderGradient(p, br,
cdata->shades[2],cdata->shades[0], /*!horizontal*/false );
p->setPen( cdata->shades[5]);
p->drawLine( br.x()-1, br.y(), br.x()-1, br.x()+r.height() ); //TODO verify +1 ???
if ( pe == PE_SpinWidgetUp )
{
QRect tmp( re );
tmp.addCoords( -1, -2, 1, 1 );
p->drawRect( tmp );
//p->drawLine(br.x()-1, br.y()+br.height(), br.x()+br.width()-1, br.y()+br.height() ); //TODO verify +1 ???
p->setPen( cg.background() );
//p->drawPoint( tmp.width()-1, tmp.y()+1 ) ;
}
else
{
QRect tmp( re );
tmp.addCoords( -1, 0, 1, 1 );
p->drawRect( tmp );
//p->drawLine(br.x()-1, br.y(), br.x()+br.width()-1, br.y() ); //TODO verify +1 ???
p->setPen( cg.background() );
//p->drawPoint( tmp.width()-5, tmp.height()-2 ) ;
}
int w = r.width();
int sw = w-4;
if ( sw < 3 )
break;
else if ( !(sw & 1) )
sw--;
sw -= ( sw / 7 ) * 2; // Empty border
//TODO don't use same color for active/inactive
p->setPen( cg.buttonText() );
p->setBrush( cg.buttonText() );
QPointArray a;
if ( pe == PE_SpinWidgetDown )
a.setPoints(QCOORDARRLEN(d_spinarrow), d_spinarrow);
else
{
//move one pixel up
re.addCoords( 0, 1,0,0);
a.setPoints(QCOORDARRLEN(u_spinarrow), u_spinarrow);
}
drawMandrivaArrow( a, p, re, cg, flags, opt );
p->restore();
break;
}
case PE_ScrollBarSlider:
{
bool horizontal = flags & Style_Horizontal;
p->setPen( cdata->shades[5]);
if( scrollmin && scrollmax )
{
QRect tmpRect(r);
if( !horizontal )
tmpRect.addCoords(0,0,0,1);
else
tmpRect.addCoords(0,0,1,0);
p->drawRect( tmpRect );
}
else
p->drawRect( r );
p->setPen( cdata->shades[0]);
if ( horizontal )
{
p->drawLine( r.x(), r.y()+1, r.x(), r.y()+r.height()-2 );
p->drawLine( r.x()+r.width(), r.y() +1 , r.x()+r.width(), r.y()+r.height()-2 );
}
else
{
p->drawLine( r.x()+1, r.y(), r.x()+r.width()-2, r.y() );
p->drawLine( r.x()+1, r.y()+r.height()-1, r.x()+r.width()-2, r.y()+r.height()-1 );
}
// if the mouse is over the slider, the first half of the gradient changes
bool mouseover = flags & Style_MouseOver;
QRect tmpRect(r), firstHalf, secondHalf;
if (horizontal)
{
tmpRect.addCoords( 0, 1, 0, -1 );
firstHalf = QRect(tmpRect.x(), tmpRect.y(), tmpRect.width(), tmpRect.height()/2);
secondHalf = QRect(tmpRect.x(), tmpRect.height()/2 + 1,
tmpRect.width(), tmpRect.height() - (tmpRect.height()/2));
}
else
{
tmpRect.addCoords( 1, 0, -1, 0 );
firstHalf = QRect(tmpRect.x(), tmpRect.y(), tmpRect.width()/2, tmpRect.height());
secondHalf = QRect(tmpRect.width()/2 + 1, tmpRect.y(),
tmpRect.width() - (tmpRect.width()/2), tmpRect.height());
}
// first half of the gradient
// horizontal scrollbars need vertical gradients (that's the reason
// of the !horizontal as the last argument
renderGradient(p, firstHalf, mouseover ? cdata->blueMdkColor[0] : cdata->blueMdkColor[1],
cdata->blueMdkColor[3], !horizontal);
// second half of the gradient
renderGradient(p, secondHalf, cdata->blueMdkColor[4], cdata->blueMdkColor[2], !horizontal);
// draw the points if !scrollmin or !scrollmax
p->setPen( cg.background() );
if (horizontal)
{
if ( !scrollmax )
{
p->drawPoint( tmpRect.x()+ tmpRect.width()-1, tmpRect.y() );
p->drawPoint( tmpRect.x()+tmpRect.width()-1, tmpRect.y()+tmpRect.height()-1 );
}
if ( !scrollmin )
{
p->drawPoint( tmpRect.x(), tmpRect.y() );
p->drawPoint( tmpRect.x(), tmpRect.height() );
}
}
else
{
if ( !scrollmax )
{
p->drawPoint( tmpRect.x(), tmpRect.y()+tmpRect.height()-1 );
p->drawPoint( tmpRect.width(), tmpRect.y()+tmpRect.height()-1 );
}
if ( !scrollmin )
{
p->drawPoint( tmpRect.x(), tmpRect.y() );
p->drawPoint( tmpRect.width(), tmpRect.y() );
}
}
break;
}
case PE_ScrollBarAddPage:
case PE_ScrollBarSubPage: {
int x, y, w, h;
r.rect(&x, &y, &w, &h);
int x2 = x+w-1;
int y2 = y+h-1;
p->setPen( cg.base());
p->drawLine( x,y,x,y2 );
p->drawLine( x2,y,x2,y2 );
p->setPen( cdata->shades[5]);
if (flags & Style_Horizontal) {
p->drawLine(x, y, x2, y);
p->drawLine(x, y2, x2, y2);
p->fillRect( QRect( x, y+1, w, h-2),cdata->shades[0] );
} else {
p->drawLine(x, y, x, y2);
p->drawLine(x2, y, x2, y2);
p->fillRect( QRect( x+1, y, w-2, h),cdata->shades[0] );
}
break;
}
case PE_ScrollBarAddLine:
case PE_ScrollBarSubLine:
{
int x,y,w,h;
r.rect(&x, &y, &w, &h);
bool sunken = on || down;
bool mouseover = flags & Style_MouseOver;
bool horizontal = flags & Style_Horizontal;
// draw the bounding rect
p->setPen( cdata->shades[5]);
p->drawRect( r );
// draw the gradient of the buttons
if (w > 4 && h > 4)
{
if (sunken)
renderGradient(p, QRect(x+1, y+1, w-2, h-2),
cdata->shades[2],cdata->shades[1], !horizontal);
else if ( flags & Style_Enabled )
renderGradient(p, QRect(x+1, y+1, w-2, h-2),
cdata->shades[0], mouseover ? cdata->shades[1] : cdata->shades[2], !horizontal );
}
PrimitiveElement arrow;
// draw some points to get a kind of rounded corner
p->setPen( cg.background() );
if (pe == PE_ScrollBarAddLine)
{
arrow = horizontal ? PE_ArrowRight : PE_ArrowDown;
if ( horizontal )
{
p->drawPoint( r.x()+r.width()-1 ,r.y() );
p->drawPoint( r.x()+r.width()-1 ,r.y()+r.height()-1 );
}
else
{
p->drawPoint( r.x() ,r.y()+r.height()-1 );
p->drawPoint( r.x()+r.width()-1 ,r.y()+r.height()-1 );
}
}
else
{
arrow = horizontal ? PE_ArrowLeft : PE_ArrowUp;
if ( horizontal )
{
p->drawPoint( r.x() ,r.y() );
p->drawPoint( r.x() ,r.y()+r.height()-1 );
}
else
{
p->drawPoint( r.x() ,r.y() );
p->drawPoint( r.x()+r.width()-1 ,r.y() );
}
}
// draw the arrow
drawPrimitive( arrow, p, r, cg, flags );
break;
}
// BUTTONS
// -------------------------------------------------------------------
case PE_ButtonDefault: //default button
case PE_ButtonCommand: // action button
case PE_ButtonDropDown:
case PE_ButtonTool:
{
drawButton(cdata,r,p,cg,flags);
break;
}
case PE_CheckMark:
{
if (menuBmp.isNull())
{
menuBmp = QBitmap( 12 , 12, menu_check_bits, true);
menuBmp.setMask(menuBmp);
}
int x,y;
x=r.x(); y=r.y();
if (!(flags & Style_Off))
{
p->setPen( on ? cdata->blueMdkColor[2] : cg.highlightedText () );
p->drawPixmap(x+3, y+3, menuBmp);
}
break;
}
//FIXME !!!!!!!!!!!!!!!!!!!! scrollbar
case PE_ButtonBevel:
{
int x,y,w,h;
r.rect(&x, &y, &w, &h);
bool sunken = on || down;
int x2 = x+w-1;
int y2 = y+h-1;
// Outer frame
p->setPen(cg.shadow());
p->drawRect(r);
// Bevel
p->setPen(sunken ? cg.mid() : cg.light());
p->drawLine(x+1, y+1, x2-1, y+1);
p->drawLine(x+1, y+1, x+1, y2-1);
p->setPen(sunken ? cg.light() : cg.mid());
p->drawLine(x+2, y2-1, x2-1, y2-1);
p->drawLine(x2-1, y+2, x2-1, y2-1);
if (w > 4 && h > 4) {
if (sunken)
p->fillRect(x+2, y+2, w-4, h-4, cg.button());
/*else
renderGradient( p, QRect(x+2, y+2, w-4, h-4),
cg.button(), flags & Style_Horizontal );*/
}
break;
}
default:
{
if (pe >= PE_ArrowUp && pe <= PE_ArrowLeft)
{
QPointArray a;
//array point define into bitmap.h
switch(pe) {
case PE_ArrowUp:
a.setPoints(QCOORDARRLEN(u_arrow), u_arrow);
break;
case PE_ArrowDown:
a.setPoints(QCOORDARRLEN(d_arrow), d_arrow);
break;
case PE_ArrowLeft:
a.setPoints(QCOORDARRLEN(l_arrow), l_arrow);
break;
default:
a.setPoints(QCOORDARRLEN(r_arrow), r_arrow);
}
drawMandrivaArrow( a, p, r, cg, flags, opt );
}
else
KStyle::drawPrimitive( pe, p, r, cg, flags, opt );
}
} //switch
}
void MandrivaStyle::drawMandrivaArrow( QPointArray a, QPainter *p,
const QRect &r,
const QColorGroup &cg,
SFlags flags,
const QStyleOption& /*opt*/ ) const
{
QPen oldPen = p->pen();
a.translate( r.x() + r.width() / 2, r.y() + r.height() / 2 );
p->setPen(flags & Style_Enabled ? cg.buttonText() : cg.mid() );
p->drawLineSegments( a );
p->setPen( oldPen ); // restore pen
}
void MandrivaStyle::drawKStylePrimitive( KStylePrimitive pe,
QPainter* p,
const QWidget* widget,
const QRect &r,
const QColorGroup &cg,
SFlags flags,
const QStyleOption &opt ) const
{
const MandrivaColorData *cdata = lookupData(cg);
switch(pe)
{
// GENERAL/KICKER HANDLE
// -------------------------------------------------------------------
case KPE_GeneralHandle:
{
drawHandle( cdata, p,r,cg,flags,opt,false );
break;
}
// TOOLBAR HANDLE
// -------------------------------------------------------------------
case KPE_ToolBarHandle:
{
QRect real(r);
real.addCoords( -1, 0,0,0);
drawHandle( cdata, p,r,cg,flags,opt,true );
break;
}
// SLIDER GROOVE
// -------------------------------------------------------------------
case KPE_SliderGroove:
{
const QSlider* sl = static_cast< const QSlider* >( widget );
bool horizontal = sl->orientation() == Horizontal;
//TODO fixme
p->fillRect( QRect( r.x()+1, r.y()+1, r.width()-2, r.height()-2 ),cdata->shades[0] );
p->setPen( cdata->shades[1] );
int pos = sl->sliderStart();
if ( horizontal )
{
//bidi
if (QApplication::reverseLayout() )
p->fillRect( QRect( pos, 1, r.right(), r.height()-2 ),cdata->shades[3] );
else
p->fillRect( QRect( 1, 1, pos, r.height()-2 ),cdata->shades[3] );
for ( int i = 12; i < r.width() ; )
{
p->drawLine( i, r.y()+1, i, r.height()-2 );
i+=12;
}
}
else
{
p->fillRect( QRect( 1, pos, r.width()-2, r.height() ),cdata->shades[3] );
for ( int i = 12; i < r.height() ; )
{
p->drawLine( r.x(), i, r.width(), i );
i+=12;
}
}
drawFrame( cdata, cg, p, r,true /*flags ? */);
break;
}
// SLIDER HANDLE
// -------------------------------------------------------------------
case KPE_SliderHandle:
{
const QSlider* sl = static_cast< const QSlider* >( widget );
bool horizontal = sl->orientation() == Horizontal;
bool mouseOver = (widget == hoverWidget);
int x = r.x();
int y = r.y();
int x2 = r.right();
int y2 = y+r.height();
p->setPen( mouseOver ? cdata->blueMdkColor[1] : cdata->blueMdkColor[2]);
if ( horizontal )
{
p->drawLine( x+1, y, x2-1, y );
p->drawLine( x, y+1, x2, y+1 );
p->drawLine( x, y+2, x2, y+2 );
p->setPen( mouseOver ? cdata->blueMdkColor[2] : cdata->blueMdkColor[4]);
p->drawLine( x, y+4, x2, y+4 );
p->drawLine( x, y+3, x2, y+3 );
p->drawLine( x+1, y+5, x2-1, y+5 );
//draw cross
int newposx = x+r.width()/2;
p->drawLine( newposx-1, y+1, newposx+1,y+1 );
p->drawLine( newposx-2, y+2, newposx+2,y+2 );
p->setPen( mouseOver ? cdata->blueMdkColor[1] : cdata->blueMdkColor[2]);
p->drawLine( newposx-2, y+3, newposx+2,y+3 );
p->drawLine( newposx-1, y+4, newposx+1,y+4 );
}
else //test into kmix
{
p->drawLine( x, y+1, x, y2-1 );
p->drawLine( x+1, y, x+1, y2 );
p->drawLine( x+2, y, x+2, y2 );
p->setPen( mouseOver ? cdata->blueMdkColor[2] : cdata->blueMdkColor[4]);
p->drawLine( x+3, y, x+3, y2 );
p->drawLine( x+4, y, x+4, y2 );
p->drawLine( x+5, y+1, x+5, y2-1 );
//draw cross
int newposy = y+r.height()/2;
p->drawLine( x+1, newposy-1, x+1, newposy+1);
p->drawLine( x+2, newposy-2, x+2, newposy+2);
p->setPen( mouseOver ? cdata->blueMdkColor[1] : cdata->blueMdkColor[2]);
p->drawLine( x+3, newposy-2, x+3, newposy+2);
p->drawLine( x+4, newposy-1, x+4, newposy+1);
}
break;
}
// copied and slightly modified from KStyle.
case KPE_ListViewBranch:
{
// Typical Windows style listview branch element (dotted line).
// Create the dotline pixmaps if not already created
if ( !verticalLine )
{
// make 128*1 and 1*128 bitmaps that can be used for
// drawing the right sort of lines.
verticalLine = new QBitmap( 1, 129, true );
horizontalLine = new QBitmap( 128, 1, true );
QPointArray a( 64 );
QPainter p2;
p2.begin( verticalLine );
int i;
for( i=0; i < 64; i++ )
a.setPoint( i, 0, i*2+1 );
p2.setPen( cdata->shades[4] );
p2.drawPoints( a );
p2.end();
QApplication::flushX();
verticalLine->setMask( *verticalLine );
p2.begin( horizontalLine );
for( i=0; i < 64; i++ )
a.setPoint( i, i*2+1, 0 );
p2.setPen( cdata->shades[4] );
p2.drawPoints( a );
p2.end();
QApplication::flushX();
horizontalLine->setMask( *horizontalLine );
}
p->setPen( cg.mid() );
if (flags & Style_Horizontal)
{
int point = r.x();
int other = r.y();
int end = r.x()+r.width();
int thickness = r.height();
while( point < end )
{
int i = 128;
if ( i+point > end )
i = end-point;
p->drawPixmap( point, other, *horizontalLine, 0, 0, i, thickness );
point += i;
}
}
else
{
int point = r.y();
int other = r.x();
int end = r.y()+r.height();
int thickness = r.width();
int pixmapoffset = (flags & Style_NoChange) ? 0 : 1; // ### Hackish
while( point < end )
{
int i = 128;
if ( i+point > end )
i = end-point;
p->drawPixmap( other, point, *verticalLine, 0, pixmapoffset, thickness, i );
point += i;
}
}
break;
}
default:
KStyle::drawKStylePrimitive( pe, p, widget, r, cg, flags, opt);
}
}
void MandrivaStyle::drawControl( ControlElement element,
QPainter *p,
const QWidget *widget,
const QRect &r,
const QColorGroup &cg,
SFlags flags,
const QStyleOption& opt ) const
{
const MandrivaColorData *cdata = lookupData(cg);
switch (element)
{
case CE_CheckBox:
{
drawPrimitive (PE_Indicator, p, r, cg, flags);
break;
}
//progressbar
case CE_ProgressBarContents:
{
const QProgressBar* pb = (const QProgressBar*)widget;
QRect backend = subRect(SR_ProgressBarContents, widget);
double progress = pb->progress();
bool reverse = QApplication::reverseLayout();
int steps = pb->totalSteps();
if (!pb || !backend.isValid())
return;
//necessary to fill all background
//TODO fix it
p->fillRect(backend , cg.background() );
//draw border
drawPrimitive( PE_PanelLineEdit, p, r, cg );
QRect cr(backend);
cr.addCoords( 1, 1, -2, -2 );
// Draw progress bar gradient
if (progress > 0 || steps == 0)
{
double pg = (steps == 0) ? 0.1 : progress / steps;
int width = QMIN(cr.width(), (int)(pg * cr.width()));
if (steps == 0)
width = QMIN(width,20); //Don't cross squares
if (steps == 0)
{ //Busy indicator
if (width < 1) width = 1; //A busy indicator with width 0 is kind of useless
int remWidth = cr.width() - width; //Never disappear completely
if (remWidth <= 0) remWidth = 1; //Do something non-crashy when too small...
int pstep = int(progress) % ( 2 * remWidth );
if ( pstep > remWidth )
{
//Bounce about.. We're remWidth + some delta, we want to be remWidth - delta...
// - ( (remWidth + some delta) - 2* remWidth ) = - (some deleta - remWidth) = remWidth - some delta..
pstep = - (pstep - 2 * remWidth );
}
if( reverse )
renderGradient(p, QRect(cr.x() + cr.width() - width - pstep, cr.y(), width, cr.height()),
cdata->shades[2],cdata->shades[1], false);
else
renderGradient(p, cr,
cdata->shades[2],cdata->shades[1], false);
p->setPen(cdata->shades[5]);
p->drawLine( backend.x(), backend.y(), backend.width()+1, backend.y());
p->drawLine( backend.x(), backend.y(), backend.x(), backend.height());
return;
}
if( reverse )
{
//convert it as after
//TODO Verify it
QPixmap gradient(1, cr.height()+1);
QPainter painter(&gradient);
KPixmap tempPixmap;
tempPixmap.resize(1, cr.height()/2+1);
KPixmapEffect::gradient(tempPixmap,
cdata->blueMdkColor[1],
cdata->blueMdkColor[3],
KPixmapEffect::VerticalGradient);
painter.drawPixmap(0,0, tempPixmap);
tempPixmap.resize(1, cr.height()+1);
KPixmapEffect::gradient(tempPixmap,
cdata->blueMdkColor[4],
cdata->blueMdkColor[2],
KPixmapEffect::VerticalGradient);
painter.drawPixmap(0, cr.height()/2 +1, tempPixmap);
painter.end();
QRect tmp( cr.width()-width+1, cr.y(),width+1,cr.height() );
tmp.addCoords( 0, 0, 0, 1 );
p->drawTiledPixmap( tmp , gradient );
bool changed = false;
p->setPen( cdata->shades[1]);
for ( int i = 12; i < cr.width() ; )
{
if ( !changed && ( i >cr.width() -width ) )
{
p->setPen( cdata->blueMdkColor[2] );
changed = true;
}
p->drawLine( i, r.y()+1, i, r.height()-2 );
i+=12;
}
p->setPen(cg.background() );
p->drawPoint( cr.width() -width +1, r.y()+1 );
p->drawPoint( cr.width() -width + 1, r.height()-2 );
}
else
{
QPixmap gradient(1, cr.height()+1);
QPainter painter(&gradient);
KPixmap tempPixmap;
tempPixmap.resize(1, cr.height()/2+1);
KPixmapEffect::gradient(tempPixmap,
cdata->blueMdkColor[1],
cdata->blueMdkColor[3],
KPixmapEffect::VerticalGradient);
painter.drawPixmap(0,0, tempPixmap);
tempPixmap.resize(1, cr.height()+1);
KPixmapEffect::gradient(tempPixmap,
cdata->blueMdkColor[4],
cdata->blueMdkColor[2],
KPixmapEffect::VerticalGradient);
painter.drawPixmap(0, cr.height()/2 +1, tempPixmap);
painter.end();
QRect tmp( cr.x(), cr.y(),width-1,cr.height() );
tmp.addCoords( 0, 0, 0, 1 );
p->drawTiledPixmap( tmp , gradient );
bool changed = false;
p->setPen( cdata->blueMdkColor[2] );
for ( int i = 12; i < cr.width() ; )
{
if ( !changed && ( i >width ) )
{
p->setPen( cdata->shades[1] );
changed = true;
}
p->drawLine( i, r.y()+1, i, r.height()-2 );
i+=12;
}
p->setPen(cg.background() );
p->drawPoint( width-1, r.y()+1 );
p->drawPoint( width-1, r.height()-2 );
}
}
break;
}
case CE_ProgressBarLabel:
{
const QProgressBar * pb = (const QProgressBar *) widget;
const int unit_width = pixelMetric( PM_ProgressBarChunkWidth, pb );
int u = r.width() / unit_width;
int p_v = pb->progress();
int t_s = pb->totalSteps();
if ( u > 0 && pb->progress() >= INT_MAX / u && t_s >= u )
{
// scale down to something usable.
p_v /= u;
t_s /= u;
}
// QColor("#4965AE" ) powerpack
if ( pb->percentageVisible() && pb->totalSteps() )
{
int nu = ( u * p_v + t_s/2 ) / t_s;
int x = unit_width * nu;
if (pb->indicatorFollowsStyle() || pb->centerIndicator())
{
if(cg.highlight() == QColor("#4965AE" ))
p->setPen( QColor("#FFFFFF"));
else
p->setPen( QColor( "#000000" ) );
p->setClipRect( r.x(), r.y(), x, r.height() );
p->drawText( r, AlignCenter | SingleLine, pb->progressString() );
if ( pb->progress() != pb->totalSteps() )
{
p->setClipRect( r.x() + x, r.y(), r.width() - x, r.height() );
//second part of progress bar => black
p->setPen( /*cg.highlight()*/QColor( "#000000" ) );
p->drawText( r, AlignCenter | SingleLine, pb->progressString() );
}
}
else
{
if(cg.highlight() == QColor("#4965AE" ))
p->setPen( QColor("#FFFFFF"));
else
p->setPen( QColor( "#000000" ) );
p->drawText( r, AlignCenter | SingleLine, pb->progressString() );
}
}
break;
}
case CE_ToolButtonLabel:
{
KStyle::drawControl(element, p, widget, r, cg, flags, opt);
break;
}
case CE_MenuBarEmptyArea:
case CE_DockWindowEmptyArea:
{
p->fillRect(r, cg.background() );
break;
}
case CE_TabBarTab:
{
const QTabBar* tb = static_cast< const QTabBar* >( widget );
int x, y, xw, yh;
int offset= 0;
x= r.x();
y= r.y();
//verify it
xw = r.x()+r.width()-1;
yh = r.y()+r.height()-1;
//necessary to define type of tab
TabPosition pos;
if (tb->count() == 1)
pos = Single;
else if ((tb->indexOf(opt.tab()->identifier()) == 0))
pos = First;
else if (tb->indexOf(opt.tab()->identifier()) == tb->count() - 1)
pos = Last;
else
pos = Middle;
bool bottom = tb->shape() == QTabBar::RoundedBelow ||
tb->shape() == QTabBar::TriangularBelow;
if ( !bottom )
{
if (flags & Style_Selected )
{
p->fillRect( r, tb->palette().active().brush( QColorGroup::Background ));
//blue-2
p->setPen( cdata->blueMdkColor[2]);
p->drawLine( x+2, y, xw-2, y );
p->drawLine( x+1, y+1, xw-1, y+1 );
//blue-4
p->setPen( cdata->blueMdkColor[4] );
p->drawLine( x, y+2, xw, y+2 );
p->drawLine( x, y+3, xw, y+3 );
p->setPen( cdata->shades[4] );
p->drawLine( xw,y+4,xw,yh);
if ( pos==First )
p->drawLine( x,y+4,x,yh);
else if ( ( pos==Last || pos == Single ) && QApplication::reverseLayout() )
p->drawLine( xw, y+4, xw, yh );
}
else
{
offset = 3;
//grey1
p->fillRect( QRect(x,y+offset,r.width()-1,yh), cdata->shades[1]);
//grey5
p->setPen( cdata->shades[5]);
p->drawLine( x+2,y+offset-1,xw-2,y+offset-1);
p->drawPoint(x+1, y+offset );
p->drawPoint(xw-1, y+offset );
p->drawLine( xw, y+offset+1, xw, yh );
p->drawLine( x, y+offset+1, x, yh );
p->setPen( cdata->shades[4]);
p->drawLine( x, yh, xw,yh);
}
}
else
{
if (flags & Style_Selected )
{
p->fillRect( r, tb->palette().active().brush( QColorGroup::Background ));
p->setPen( cdata->blueMdkColor[2] );
p->drawLine( x, yh-3, xw, yh-3 );
p->drawLine( x, yh-2, xw, yh-2 );
p->setPen( cdata->blueMdkColor[4] );
p->drawLine( x+1, yh-1, xw-1, yh-1 );
p->drawLine( x+2, yh, xw-2, yh );
p->setPen( cdata->shades[4] );
p->drawLine( xw,y,xw,yh-4);
if ( pos==First )
p->drawLine( x,y,x,yh-4);
else if ( ( pos==Last || pos == Single ) && QApplication::reverseLayout() )
p->drawLine( x, y, x, yh-4 ); //CHECK
}
else
{
offset = 3;
//grey1
p->fillRect( QRect(x,y,r.width()-1,yh-offset), cdata->shades[1]);
//grey5
p->setPen( cdata->shades[5]);
p->drawLine( x+2,yh-offset+1,xw-2,yh-offset+1);
p->drawPoint(x+1, yh-offset );
p->drawPoint(xw-1, yh-offset );
p->drawLine( xw, y, xw, yh-4 );
p->drawLine( x, y, x, yh-4 );
p->setPen( cdata->shades[4]);
p->drawLine( x, y, xw,y);
}
}
break;
}
//CHECK
case CE_MenuBarItem:
{
QMenuBar *mb = (QMenuBar*)widget;
QMenuItem *mi = opt.menuItem();
QRect pr = mb->rect();
bool active = flags & Style_Active;
bool focused = flags & Style_HasFocus;
bool down = flags & Style_Down;
QColor textColor = cg.text();
if ( active && focused && down )
{
//top half
QRect half_rect = r;
half_rect.setHeight(r.height()/2);
renderGradient(p, half_rect, cdata->blueMdkColor[1], cdata->blueMdkColor[3], false);
//bottom half
half_rect.setHeight(r.height() - half_rect.height());
half_rect.moveBottom(r.bottom());
renderGradient(p, half_rect, cdata->blueMdkColor[4], cdata->blueMdkColor[2], false);
textColor = cg.highlightedText();
// create the fake rounded corners
QPen oldPen = p->pen();
p->setPen(cg.background());
p->drawPoint(r.topLeft());
p->drawPoint(r.topRight());
p->drawPoint(r.bottomLeft());
p->drawPoint(r.bottomRight());
p->setPen(oldPen);
}
else
renderGradient(p, r, cg.background(), cg.background(),false);
drawItem( p, r, AlignCenter | AlignVCenter | ShowPrefix
| DontClip | SingleLine, cg, flags & Style_Enabled,
mi->pixmap(), mi->text(), -1, &textColor );
break;
}
// POPUPMENU ITEM
// -------------------------------------------------------------------
case CE_PopupMenuItem:
{
const QPopupMenu *popupmenu = (const QPopupMenu *) widget;
QMenuItem *mi = opt.menuItem();
if ( !mi )
{
// Don't leave blank holes if we set NoBackground for the QPopupMenu.
// This only happens when the popupMenu spans more than one column.
if (! (widget->erasePixmap() && !widget->erasePixmap()->isNull()) )
p->fillRect(r, cg.brush(QColorGroup::Background) );
break;
}
int tab = opt.tabWidth();
int checkcol = opt.maxIconWidth();
bool enabled = mi->isEnabled();
bool checkable = popupmenu->isCheckable();
bool active = flags & Style_Active;
bool etchtext = styleHint( SH_EtchDisabledText );
bool reverse = QApplication::reverseLayout();
int x, y, w, h;
r.rect( &x, &y, &w, &h );
if ( checkable )
checkcol = QMAX( checkcol, 20 );
// Are we a menu item separator?
if ( mi->isSeparator() )
{
drawLineSeparator( cdata, cg, p, r, true, active, false );
break;
}
// Draw the menu item background
if( active && (flags & Style_Enabled))
{
//top half
QRect half_rect = r;
half_rect.setHeight(r.height()/2);
renderGradient(p, half_rect, cdata->blueMdkColor[1], cdata->blueMdkColor[3], false);
//bottom half
half_rect.setHeight(r.height() - half_rect.height());
half_rect.moveBottom(r.bottom());
renderGradient(p, half_rect, cdata->blueMdkColor[4], cdata->blueMdkColor[2], false);
// create the fake rounded corners
QPen oldPen = p->pen();
p->setPen(cg.background());
p->drawPoint(r.topLeft());
p->drawPoint(r.topRight());
p->drawPoint(r.bottomLeft());
p->drawPoint(r.bottomRight());
p->setPen(oldPen);
}
// Draw the transparency pixmap
else if ( widget->erasePixmap() && !widget->erasePixmap()->isNull() )
p->drawPixmap( x, y, *widget->erasePixmap(), x, y, w, h );
// Draw a solid background
else
p->fillRect( r, cg.background() );
// Do we have an icon?
#if 0
if ( ( (widget && !qstrcmp(widget->name(),"KMenu" )) ||
(widget->parentWidget() && !qstrcmp(widget->parentWidget()->name(),"KMenu" )) )
&&
#endif
if( mi->iconSet() )
{
QIconSet::Mode mode;
QRect cr = visualRect( QRect(x, y, checkcol, h), r );
// Select the correct icon from the iconset
if ( active )
mode = enabled ? QIconSet::Active : QIconSet::Disabled;
else
mode = enabled ? QIconSet::Normal : QIconSet::Disabled;
#if 0 //don't check menu
// Do we have an icon and are checked at the same time?
// Then draw a "pressed" background behind the icon
if ( checkable && !active && mi->isChecked() )
{
qDrawShadePanel( p, cr.x(), cr.y(), cr.width(), cr.height(),
cg, true, 1, &cg.brush(QColorGroup::Midlight) );
}
#endif
//TEST IT !!!!!!!!!!!!!!
if ( checkable && mi->isChecked() )
{//don't display icon when button is checkable
int cx = reverse ? x+w - checkcol : x;
// Draw the checkmark
SFlags cflags = Style_Default;
cflags |= active ? Style_Enabled : Style_On;
drawPrimitive( PE_CheckMark, p, QRect( cx + itemFrame, y + itemFrame,
checkcol - itemFrame*2, h - itemFrame*2), cg, cflags );
}
else
{
// Draw the icon
QPixmap pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode );
QRect pmr( 0, 0, pixmap.width(), pixmap.height() );
pmr.moveCenter( cr.center() );
p->drawPixmap( pmr.topLeft(), pixmap );
}
}
// Are we checked? (This time without an icon)
else if ( (checkable && mi->isChecked()) )
{
int cx = reverse ? x+w - checkcol : x;
#if 0 //don't create a checked button
// We only have to draw the background if the menu item is inactive
// if it's active the "pressed" background is already drawn
if ( ! active )
qDrawShadePanel( p, cx, y, checkcol, h, cg, true, 1,
&cg.brush(QColorGroup::Midlight) );
#endif
// Draw the checkmark
SFlags cflags = Style_Default;
cflags |= active ? Style_Enabled : Style_On;
drawPrimitive( PE_CheckMark, p, QRect( cx + itemFrame, y + itemFrame,
checkcol - itemFrame*2, h - itemFrame*2), cg, cflags );
}
// Time to draw the menu item label...
int xm = itemFrame + checkcol + itemHMargin; // X position margin
int xp = reverse ? // X position
x + tab + rightBorder + itemHMargin + itemFrame - 1 :
x + xm;
int offset = reverse ? -1 : 1; // Shadow offset for etched text
// Label width (minus the width of the accelerator portion)
int tw = w - xm - tab - arrowHMargin - itemHMargin * 3 - itemFrame + 1;
// Set the color for enabled and disabled text
// (used for both active and inactive menu items)
p->setPen( enabled ? cg.buttonText() : cg.mid() );
// This color will be used instead of the above if the menu item
// is active and disabled at the same time. (etched text)
QColor discol = cg.mid();
// Does the menu item draw it's own label?
if ( mi->custom() )
{
int m = itemVMargin;
// Save the painter state in case the custom
// paint method changes it in some way
QPen oldPen = p->pen();
// Draw etched text if we're inactive and the menu item is disabled
if ( etchtext && !enabled && !active )
{
p->setPen( cg.light() );
mi->custom()->paint( p, cg, active, enabled, xp+offset, y+m+1, tw, h-2*m );
p->setPen( discol );
}
mi->custom()->paint( p, cg, active, enabled, xp, y+m, tw, h-2*m );
p->setPen( oldPen ); // restore pen
}
else
{
// The menu item doesn't draw it's own label
QString s = mi->text();
// Does the menu item have a text label?
if ( !s.isNull() )
{
int t = s.find( '\t' );
int m = itemVMargin;
int text_flags = AlignVCenter | ShowPrefix | DontClip | SingleLine;
text_flags |= reverse ? AlignRight : AlignLeft;
//QColor draw = cg.text();
QColor draw = (active && enabled) ? cg.highlightedText () : cg.text();
p->setPen(draw);
// Does the menu item have a tabstop? (for the accelerator text)
if ( t >= 0 )
{
int tabx = reverse ? x + rightBorder + itemHMargin + itemFrame :
x + w - tab - rightBorder - itemHMargin - itemFrame;
// Draw the right part of the label (accelerator text)
if ( etchtext && !enabled && !active )
{
// Draw etched text if we're inactive and the menu item is disabled
p->setPen( cg.light() );
p->drawText( tabx+offset, y+m+1, tab, h-2*m, text_flags, s.mid( t+1 ) );
p->setPen( discol );
}
p->drawText( tabx, y+m, tab, h-2*m, text_flags, s.mid( t+1 ) );
s = s.left( t );
}
// Draw the left part of the label (or the whole label
// if there's no accelerator)
if ( etchtext && !enabled && !active )
{
// Etched text again for inactive disabled menu items...
p->setPen( cg.light() );
p->drawText( xp+offset, y+m+1, tw, h-2*m, text_flags, s, t );
p->setPen( discol );
}
p->drawText( xp, y+m, tw, h-2*m, text_flags, s, t );
}
// The menu item doesn't have a text label
// Check if it has a pixmap instead
else if ( mi->pixmap() )
{
QPixmap *pixmap = mi->pixmap();
// Draw the pixmap
if ( pixmap->depth() == 1 )
p->setBackgroundMode( OpaqueMode );
int diffw = ( ( w - pixmap->width() ) / 2 )
+ ( ( w - pixmap->width() ) % 2 );
p->drawPixmap( x+diffw, y+itemFrame, *pixmap );
if ( pixmap->depth() == 1 )
p->setBackgroundMode( TransparentMode );
}
}
// Does the menu item have a submenu?
if ( mi->popup() )
{
PrimitiveElement arrow = reverse ? PE_ArrowLeft : PE_ArrowRight;
int dim = pixelMetric(PM_MenuButtonIndicator)- itemFrame;
QRect vr = visualRect( QRect( x + w - arrowHMargin - itemFrame - dim,
y + h / 2 - dim / 2, dim, dim), r );
// Draw an arrow at the far end of the menu item
if ( active )
{
if ( enabled )
discol = cg.buttonText();
QColorGroup g2( cg.highlightedText ()/*white*/, cg.highlight(), /*white*/cg.highlightedText (), /*white*/cg.highlightedText (),
enabled ? cg.highlightedText () : discol, /*discol*/cg.highlightedText (), cg.highlightedText () );
drawPrimitive( arrow, p, vr, g2, Style_Enabled );
}
else
drawPrimitive( arrow, p, vr, cg,
enabled ? Style_Enabled : Style_Default );
}
break;
}
case CE_PushButtonLabel:
{
const QPushButton* button = (const QPushButton*)widget;
bool active = button->isOn() || button->isDown();
int x, y, w, h;
r.rect( &x, &y, &w, &h );
// Shift button contents if pushed.
if ( active )
{
x += pixelMetric(PM_ButtonShiftHorizontal, widget);
y += pixelMetric(PM_ButtonShiftVertical, widget);
flags |= Style_Sunken;
}
// Does the button have a popup menu?
if ( button->isMenuButton() )
{
int dx = pixelMetric( PM_MenuButtonIndicator, widget );
drawPrimitive( PE_ArrowDown, p, QRect(x + w - dx - 2, y + 2, dx, h - 4),
cg, flags, opt );
w -= dx;
}
// Draw the icon if there is one
if ( button->iconSet() && !button->iconSet()->isNull() )
{
QIconSet::Mode mode = QIconSet::Disabled;
QIconSet::State state = QIconSet::Off;
if (button->isEnabled())
mode = button->hasFocus() ? QIconSet::Active : QIconSet::Normal;
if (button->isToggleButton() && button->isOn())
state = QIconSet::On;
QPixmap pixmap = button->iconSet()->pixmap( QIconSet::Small, mode, state );
// Center the iconset if there's no text or pixmap
if (button->text().isEmpty() && !button->pixmap())
p->drawPixmap( x + (w - pixmap.width()) / 2,
y + (h - pixmap.height()) / 2, pixmap );
else
p->drawPixmap( x + 4, y + (h - pixmap.height()) / 2, pixmap );
int pw = pixmap.width();
x += pw + 4;
w -= pw + 4;
}
// Make the label indicate if the button is a default button or not
if ( active || button->isDefault() )
{
// Draw "fake" bold text - this enables the font metrics to remain
// the same as computed in QPushButton::sizeHint(), but gives
// a reasonable bold effect.
//change color of text
drawItem( p, QRect(x, y, w, h), AlignCenter | ShowPrefix,
button->colorGroup(),
button->isEnabled(),
button->pixmap(),
button->text(), -1,
/*button->isDefault() ? &cdata->blueMdkColor[4] :*/ &button->colorGroup().buttonText() );
#if 0
// Normal Text
for(i=0; i<2; i++)
drawItem( p, QRect(x+i, y, w, h), AlignCenter | ShowPrefix,
button->colorGroup(),
button->isEnabled(),
i == 0 ? button->pixmap() : NULL,
button->text(), -1,
&button->colorGroup().buttonText() );
#endif
}
else
{
drawItem( p, QRect(x, y, w, h), AlignCenter | ShowPrefix,
button->colorGroup(),
button->isEnabled(), button->pixmap(),
button->text(), -1,
&button->colorGroup().buttonText() );
}
// Draw a focus rect if the button has focus
if ( flags & Style_HasFocus )
drawPrimitive( PE_FocusRect, p,
QStyle::visualRect(subRect(SR_PushButtonFocusRect, widget), widget),
cg, flags );
break;
}
case CE_PushButton:
{
const QPushButton* btn = static_cast< const QPushButton* >( widget );
if ( widget == hoverWidget )
flags |= Style_MouseOver;
if (isFormWidget(btn))
formMode = true;
drawPrimitive( btn->isDefault( ) ? PE_ButtonDefault : PE_ButtonCommand, p, r, cg, flags );
}
break;
default:
KStyle::drawControl(element, p, widget, r, cg, flags, opt);
}
}
void MandrivaStyle::drawControlMask( ControlElement element,
QPainter *p,
const QWidget *widget,
const QRect &r,
const QStyleOption& opt ) const
{
switch (element)
{
case CE_TabBarTab:
case CE_TabBarLabel:
{
p->fillRect(r,color1);
break;
}
default:
KStyle::drawControlMask(element, p, widget, r, opt);
}
}
void MandrivaStyle::drawComboboxArrow( QPainter *p,
const QWidget *widget,
const QRect &ar,
const QColorGroup &cg,
SFlags flags,
SCFlags active)const
{
const QComboBox * cb = (const QComboBox *) widget;
bool editableCombo = cb->editable();
// Are we enabled?
if ( widget->isEnabled() )
flags |= Style_Enabled;
// Are we "pushed" ?
if ( active & Style_Sunken )
flags |= Style_Sunken;
p->setPen( cg.text() );
//Don't apply background color otherwise it
//destroys gradient.
//p->setBackgroundColor( cg.button() );
QPointArray a;
if ( editableCombo )
a.setPoints(QCOORDARRLEN(c_edit_arrow), c_edit_arrow);
else
a.setPoints(QCOORDARRLEN(c_arrow), c_arrow);
if ( flags & Style_Down )
p->translate( pixelMetric( PM_ButtonShiftHorizontal ),
pixelMetric( PM_ButtonShiftVertical ) );
if ( flags & Style_Enabled )
{
if ( QApplication::reverseLayout() )
{
a.translate( editableCombo ? ar.x() + ar.width() / 2 +1 : ar.x() + ar.width() / 2 +4 ,
editableCombo ? ar.y() + ar.height() / 2 + 1 : ar.y() + ar.height() / 2 );
}
else
{
a.translate( editableCombo ? ar.x() + ar.width() / 2 +1 : ar.x() + ar.width() / 2 -3,
editableCombo ? ar.y() + ar.height() / 2 + 1 : ar.y() + ar.height() / 2 );
}
p->setPen( cg.buttonText() );
p->drawLineSegments( a );
}
else
{
if ( QApplication::reverseLayout() )
{
a.translate( editableCombo ? ar.x() + ar.width() / 2 + 1 : ar.x() + ar.width() / 2 +4,
editableCombo ? ar.y() + ar.height() / 2 + 1: ar.y() + ar.height() / 2 );
}
else
{
a.translate( editableCombo ? ar.x() + ar.width() / 2 + 1 : ar.x() + ar.width() / 2 -3,
editableCombo ? ar.y() + ar.height() / 2 + 1: ar.y() + ar.height() / 2 );
}
p->setPen( cg.light() );
p->drawLineSegments( a );
a.translate( -1, -1 );
p->setPen( cg.mid() );
p->drawLineSegments( a );
}
}
void MandrivaStyle::drawComplexControl( ComplexControl control,
QPainter *p,
const QWidget *widget,
const QRect &r,
const QColorGroup &cg,
SFlags flags,
SCFlags controls,
SCFlags active,
const QStyleOption& opt ) const
{
const MandrivaColorData *cdata = lookupData(cg);
switch(control)
{
case CC_SpinWidget:
{
const QSpinWidget* sw = static_cast< const QSpinWidget* >( widget );
QRect br = visualRect( querySubControlMetrics( CC_SpinWidget, widget, SC_SpinWidgetButtonField ), widget );
//FIXME
p->fillRect( r, widget->isEnabled() ? cg.base() : cg.background() );
if ( controls & SC_SpinWidgetButtonField )
{
if ( controls & SC_SpinWidgetUp)
{
QColorGroup ucg = sw->isUpEnabled() ? cg : sw->palette().disabled();
drawPrimitive( PE_SpinWidgetUp,p, QRect(br.x()+1 , br.y()+1 , br.width()-2 , br.height() / 2 ), ucg, flags, opt);
}
if ( controls & SC_SpinWidgetDown)
{
QColorGroup dcg = sw->isDownEnabled() ? cg : sw->palette().disabled();
drawPrimitive( PE_SpinWidgetDown,p, QRect( br.x()+1 , br.y() + br.height() / 2 , br.width()-2, br.height()/ 2 -1 ), dcg, flags, opt);
}
}
if ( controls & SC_SpinWidgetFrame )
drawPrimitive( PE_PanelLineEdit, p, r, cg );
break;
}
case CC_ToolButton:
{
const QToolButton *tb = (const QToolButton *) widget;
QRect button, menuarea;
button = querySubControlMetrics(control, widget, SC_ToolButton, opt);
menuarea = querySubControlMetrics(control, widget, SC_ToolButtonMenu, opt);
SFlags bflags = flags,
mflags = flags;
// don't want to have the buttoncolor as the background...
p->fillRect(r, cg.background());
bflags &= ~Style_MouseOver;
if (active & SC_ToolButton)
bflags |= Style_Down;
if (active & SC_ToolButtonMenu)
mflags |= Style_Down;
if (controls & SC_ToolButton)
{
// If we're pressed, on, or raised...
if (bflags & (Style_Down | Style_On | Style_Raised) || widget==hoverWidget )
{
drawPrimitive(PE_ButtonTool, p, button, cg, bflags, opt);
}
else if (tb->parentWidget() &&
tb->parentWidget()->backgroundPixmap() &&
!tb->parentWidget()->backgroundPixmap()->isNull())
{
QPixmap pixmap = *(tb->parentWidget()->backgroundPixmap());
p->drawTiledPixmap( r, pixmap, tb->pos() );
}
}
// Draw a toolbutton menu indicator if required
if (controls & SC_ToolButtonMenu)
{
if (mflags & (Style_Down | Style_On | Style_Raised))
drawPrimitive(PE_ButtonDropDown, p, menuarea, cg, mflags, opt);
drawPrimitive(PE_ArrowDown, p, menuarea, cg, mflags, opt);
}
if (tb->hasFocus() && !tb->focusProxy())
{
QRect fr = tb->rect();
fr.addCoords(2, 2, -2, -2);
drawPrimitive(PE_FocusRect, p, fr, cg);
}
// Set the color for the ToolButton menu indicator
p->setPen(cg.buttonText() );
break;
}
case CC_ScrollBar:
{
const QScrollBar *scrollbar = (const QScrollBar *) widget;
QRect addline, subline, addpage, subpage, slider, first, last;
bool maxedOut = (scrollbar->minValue() == scrollbar->maxValue());
scrollmin = ( scrollbar->minValue() == scrollbar->value() );
scrollmax = (( scrollbar->maxValue() == scrollbar->value() )|| maxedOut);
subline = querySubControlMetrics(control, widget, SC_ScrollBarSubLine, opt);
addline = querySubControlMetrics(control, widget, SC_ScrollBarAddLine, opt);
subpage = querySubControlMetrics(control, widget, SC_ScrollBarSubPage, opt);
addpage = querySubControlMetrics(control, widget, SC_ScrollBarAddPage, opt);
slider = querySubControlMetrics(control, widget, SC_ScrollBarSlider, opt);
first = querySubControlMetrics(control, widget, SC_ScrollBarFirst, opt);
last = querySubControlMetrics(control, widget, SC_ScrollBarLast, opt);
if ((controls & SC_ScrollBarSubLine) && subline.isValid())
{
int flags = Style_Enabled;
if (active == SC_ScrollBarSubLine)
flags |= Style_Down;
if (scrollbar->orientation() == Qt::Horizontal)
flags |= Style_Horizontal;
if (hoverWidget == widget && hoverControl == HoverScrollBarSubLine)
flags |= Style_MouseOver;
drawPrimitive(PE_ScrollBarSubLine, p, subline, cg, flags);
}
if ((controls & SC_ScrollBarAddLine) && addline.isValid())
{
int flags = Style_Enabled;
if (active == SC_ScrollBarAddLine)
flags |= Style_Down;
if (scrollbar->orientation() == Qt::Horizontal)
flags |= Style_Horizontal;
if (hoverWidget == widget && hoverControl == HoverScrollBarAddLine)
flags |= Style_MouseOver;
drawPrimitive(PE_ScrollBarAddLine, p, addline, cg, flags);
}
if ((controls & SC_ScrollBarSubPage) && subpage.isValid())
drawPrimitive(PE_ScrollBarSubPage, p, subpage, cg,
Style_Enabled | ((active == SC_ScrollBarSubPage) ?
Style_Down : Style_Default) |
((scrollbar->orientation() == Qt::Horizontal) ?
Style_Horizontal : 0));
if ((controls & SC_ScrollBarAddPage) && addpage.isValid())
drawPrimitive(PE_ScrollBarAddPage, p, addpage, cg,
((maxedOut) ? Style_Default : Style_Enabled) |
((active == SC_ScrollBarAddPage) ?
Style_Down : Style_Default) |
((scrollbar->orientation() == Qt::Horizontal) ?
Style_Horizontal : 0));
if ((controls & SC_ScrollBarFirst) && first.isValid())
drawPrimitive(PE_ScrollBarFirst, p, first, cg,
Style_Enabled | ((active == SC_ScrollBarFirst) ?
Style_Down : Style_Default) |
((scrollbar->orientation() == Qt::Horizontal) ?
Style_Horizontal : 0));
if ((controls & SC_ScrollBarLast) && last.isValid())
drawPrimitive(PE_ScrollBarLast, p, last, cg,
Style_Enabled | ((active == SC_ScrollBarLast) ?
Style_Down : Style_Default) |
((scrollbar->orientation() == Qt::Horizontal) ?
Style_Horizontal : 0));
if ((controls & SC_ScrollBarSlider) && slider.isValid())
{
int flags = Style_Enabled;
if (active == SC_ScrollBarSlider)
flags |= Style_Down;
if (scrollbar->orientation() == Qt::Horizontal)
flags |= Style_Horizontal;
if (hoverWidget == widget && hoverControl == HoverScrollBarSlider)
flags |= Style_MouseOver;
drawPrimitive(PE_ScrollBarSlider, p, slider, cg, flags);
// ### perhaps this should not be able to accept focus if maxedOut?
if (scrollbar->hasFocus())
{
QRect fr(slider.x() + 2, slider.y() + 2,
slider.width() - 5, slider.height() - 5);
drawPrimitive(PE_FocusRect, p, fr, cg, Style_Default);
}
}
break;
}
// COMBOBOX
// -------------------------------------------------------------------
case CC_ComboBox:
{
const QComboBox * cb = (const QComboBox *) widget;
if (isFormWidget(cb))
formMode = true;
// Draw box and arrow
bool reverse = QApplication::reverseLayout();
if ( widget == hoverWidget )
flags |= Style_MouseOver;
bool widgetEnabled = ( widget->isEnabled() );
bool sunken = cb->listBox() ? cb->listBox()->isShown() : false;
//TODO not editable
if( cb->editable())
{
if ((controls & SC_ComboBoxFrame ))
{
drawFrame( cdata, cg, p, r,true /*flags ? */);
}
if( (controls & SC_ComboBoxEditField ))
{
QRect ar = QStyle::visualRect(querySubControlMetrics(CC_ComboBox, widget, SC_ComboBoxEditField), widget );
drawPrimitive( PE_PanelLineEdit, p, ar, cg );
}
//if ( controls & SC_ComboBoxListBoxPopup )
//{
//TODO
//}
if( (controls & SC_ComboBoxArrow ))
{
QRect ar = QStyle::visualRect(querySubControlMetrics(CC_ComboBox, widget, SC_ComboBoxArrow), widget );
bool mouseOver = (flags & Style_MouseOver) && (hoverControl == HoverComboBoxArrow);
if ( sunken )
renderGradient(p, QRect(ar.x()+1, ar.y()+1, ar.width()-1, ar.height()-2), cdata->shades[2], cdata->shades[0], false);
else if ( mouseOver ) // FIXME: should highlight only when the mouse is over the arrow
renderGradient(p, QRect(ar.x()+1, ar.y()+1, ar.width()-1, ar.height()-2), Qt::white, cdata->shades[1], false);
else
renderGradient(p, QRect(ar.x()+1, ar.y()+1, ar.width()-1, ar.height()-2), cdata->shades[0],cdata->shades[2], false);
if ( widgetEnabled )
{
if ( reverse )
{
p->setPen( cg.base() );
p->drawLine( ar.x()+1, ar.y()+1,ar.x()+ar.width()-1, ar.y()+1 );
p->drawLine( ar.width()-1, ar.y()+1, ar.width()-1, ar.height()-2 );
p->setPen( cdata->shades[1]);
p->drawLine( ar.x(), ar.y()+1,ar.x(), ar.height()-2 );
p->drawLine( ar.x(), ar.height()-2, ar.x()+ar.width()-1, ar.height()-2 );
}
else
{
p->setPen( cg.base() );
p->drawLine( ar.x()+1, ar.y()+1,ar.x()+ar.width()-1, ar.y()+1 );
p->drawLine( ar.x()+1, ar.y()+1, ar.x()+1, ar.height()-2 );
p->setPen( cdata->shades[1]);
p->drawLine( ar.x()+ar.width()-1, ar.y()+1,ar.x()+ar.width()-1, ar.height()-2 );
p->drawLine( ar.x()+1, ar.height()-2, ar.x()+ar.width()-1, ar.height()-2 );
}
}
p->setPen( widgetEnabled ? cdata->shades[5] :cdata->shades[4] );
if ( reverse)
p->drawLine( ar.width(), ar.y()+1, ar.width(), ar.height()-2 );
else
p->drawLine( ar.x(), ar.y()+1, ar.x(), ar.height()-2 );
drawComboboxArrow( p,widget,ar,cg,flags,active);
}
}
else
{
QPen oldPen = p->pen();
// Get the button bounding box
QRect ar = QStyle::visualRect(querySubControlMetrics(CC_ComboBox, widget, SC_ComboBoxArrow), widget );
drawButton( cdata,r,p,cg,flags | (sunken ? Style_Down : Style_Default));
//test reverse !
if( reverse )
{
p->setPen(cg.base());
p->drawLine( ar.width()-1,ar.y()+5,ar.width()-1,ar.height()-6);
p->setPen( cdata->shades[2]);
p->drawLine( ar.width(),ar.y()+5,ar.width(),ar.height()-6);
}
else
{
p->setPen(cg.base());
p->drawLine( ar.x()-1,ar.y()+5,ar.x()-1,ar.height()-6);
p->setPen(cdata->shades[2]);
p->drawLine( ar.x()-2,ar.y()+5,ar.x()-2,ar.height()-6);
}
drawComboboxArrow( p,widget,ar,cg,flags,active);
p->setPen( oldPen );// restore pen
}
break;
}
default:
KStyle::drawComplexControl(control, p, widget,
r, cg, flags, controls, active, opt);
}
}
QRect MandrivaStyle::querySubControlMetrics( ComplexControl control,
const QWidget* widget,
SubControl subcontrol,
const QStyleOption& opt ) const
{
switch (control)
{
case CC_SpinWidget:
{
switch ( subcontrol )
{
case SC_SpinWidgetButtonField:
return QRect( widget->width() -14 , 0, 14, widget->height() );
default:
return KStyle::querySubControlMetrics( control, widget, subcontrol, opt );
}
}
//TODO verify it.
case CC_ComboBox:
{
int arrow = 11;
switch ( subcontrol )
{
case SC_ComboBoxFrame:
return QRect( 0, 0, widget->width(), widget->height() );
case SC_ComboBoxArrow:
{
const QComboBox * cb = (const QComboBox *) widget;
return QRect( cb->editable() ? ( widget->width() - arrow - 11 ) : ( widget->width() - arrow- 7 ) , 0, arrow+10 , widget->height() );
}
case SC_ComboBoxEditField:
{
if ( widget->width() < 36 || widget->height() < 22 )
return QRect( 5, 1, widget->width() - arrow-12, widget->height());
else if ( static_cast< const QComboBox* >( widget )->editable() )
return QRect( 1,1, widget->width() - arrow-12, widget->height() - 2 );
else //TODO verify it
return QRect( 5, 1, widget->width() - arrow-12, widget->height() - 2);
}
default:
return KStyle::querySubControlMetrics( control, widget, subcontrol, opt );
}
break;
}
case CC_Slider:
{
const QSlider* sl = static_cast< const QSlider* >( widget );
bool horizontal = sl->orientation() == Horizontal;
QSlider::TickSetting ticks = sl->tickmarks();
int pos = sl->sliderStart();
int handleSize = pixelMetric( PM_SliderThickness, widget );
int len = pixelMetric( PM_SliderLength, widget );
switch ( subcontrol )
{
case SC_SliderHandle:
if ( horizontal )
{
if ( ticks == QSlider::Both )
return QRect( pos, ( sl->height() - handleSize ) / 2, len, handleSize );
else if ( ticks == QSlider::Above )
return QRect( pos, sl->height() - handleSize, len, handleSize );
return QRect( pos, 0, len, handleSize );
}
else
{
if ( ticks == QSlider::Both )
return QRect( ( sl->width() - handleSize ) / 2, pos, handleSize, len );
else if ( ticks == QSlider::Above )
return QRect( sl->width() - handleSize, pos, handleSize, len );
return QRect( 0, pos, handleSize, len );
}
default:
break;
}
break;
}
default:
break;
}
return KStyle::querySubControlMetrics( control, widget, subcontrol, opt );
}
void MandrivaStyle::drawComplexControlMask( ComplexControl control,
QPainter *p,
const QWidget *widget,
const QRect &r,
const QStyleOption& opt ) const
{
//TODO verify
//#if 0
switch (control)
{
// COMBOBOX & TOOLBUTTON MASKS
// -------------------------------------------------------------------
case CC_ComboBox:
case CC_ToolButton:
{
int x1, y1, x2, y2;
r.coords( &x1, &y1, &x2, &y2 );
QCOORD corners[] = { x1,y1, x2,y1, x1,y2, x2,y2 };
p->fillRect( r, color1 );
p->setPen( color0 );
p->drawPoints( QPointArray(4, corners) );
break;
}
default:
KStyle::drawComplexControlMask(control, p, widget, r, opt);
}
//#endif
//KStyle::drawComplexControlMask(control, p, widget, r, opt);
}
int MandrivaStyle::pixelMetric(PixelMetric m, const QWidget *widget) const
{
switch(m)
{
case PM_SplitterWidth:
return 6; //Perhaps 6
case PM_ButtonMargin:
return 2;
case PM_DefaultFrameWidth:
return 1;
case PM_MenuButtonIndicator:
return 13;
case PM_SliderLength:
return 31;
case PM_SliderControlThickness: //VERIFY it
return 6;
case PM_SliderThickness: //VERIFY it
return 6;
case PM_ExclusiveIndicatorWidth: // Radiobutton size
return 13;
case PM_ExclusiveIndicatorHeight:
return 12;
case PM_SpinBoxFrameWidth:
return 1;
case PM_CheckListButtonSize: //TODO FIXME §!!!!!!!!!!!!!!!
return 10;
case PM_ScrollBarSliderMin:
return 21;
case PM_ScrollBarExtent:
return 14; //scrollbar width verify arrow position
//checkBox
case PM_IndicatorWidth:
return 13;
case PM_IndicatorHeight:
return 12;
case PM_TabBarTabShiftVertical:
return 0;
default:
return KStyle::pixelMetric(m, widget);
}
}
QSize MandrivaStyle::sizeFromContents( ContentsType contents,
const QWidget* widget,
const QSize &contentSize,
const QStyleOption& opt ) const
{
switch (contents)
{
//define progressbar default size
case CT_ProgressBar:
return QSize( contentSize.width(), 20 ) ;
case CT_SpinBox:
return QSize( contentSize.width(), contentSize.height()+1);
case CT_LineEdit: {
return contentSize + QSize (1, 1); //add +1 to rect
}
case CT_SizeGrip:
{
return QSize( 15, 15 );
}
case CT_ToolButton:
{
bool onToolbar = widget->parentWidget() && widget->parentWidget()->inherits( "QToolBar" );
if (!onToolbar) //Behaves like a button, so scale appropriately to the border
{
int w = contentSize.width();
int h = contentSize.height();
return QSize( w + 12, h + 10 );
}
else
{
return KStyle::sizeFromContents( contents, widget, contentSize, opt );
}
}
case CT_ComboBox:
{
const QComboBox* combobox = (const QComboBox*) widget;
int h = contentSize.height();
if ( h < 22 )
h = 22;
int arrow = 11;
return QSize( contentSize.width() + arrow + (combobox->editable() ? 26 : 22),
combobox->editable() ? h : contentSize.height() + 10 );
}
// PUSHBUTTON SIZE
// ------------------------------------------------------------------
case CT_PushButton:
{
const QPushButton* button = (const QPushButton*) widget;
int w = contentSize.width();
int h = contentSize.height();
int bm = pixelMetric( PM_ButtonMargin, widget );
int fw = pixelMetric( PM_DefaultFrameWidth, widget ) * 2;
w += bm + fw + 6; // ### Add 6 to make way for bold font.
h += bm + fw;
// Ensure we stick to standard width and heights.
if ( button->isDefault() || button->autoDefault() )
{
if ( w < 80 && !button->pixmap() )
w = 80;
}
if ( h < 30 )
h = 30;
return QSize( w, h );
}
case CT_PopupMenuItem:
{
if ( ! widget || opt.isDefault() )
return contentSize;
const QPopupMenu *popup = (const QPopupMenu *) widget;
bool checkable = popup->isCheckable();
QMenuItem *mi = opt.menuItem();
int maxpmw = opt.maxIconWidth();
int w = contentSize.width(), h = contentSize.height();
if ( mi->custom() )
{
w = mi->custom()->sizeHint().width();
h = mi->custom()->sizeHint().height();
if ( ! mi->custom()->fullSpan() )
h += 2*itemVMargin + 2*itemFrame;
}
else if ( mi->widget() )
{
// do NOT remove this as it ends up doing wrong things
// this if is here to stop processing the item
}
else if ( mi->isSeparator() )
{
w = 30; // Arbitrary
h = 2;
}
else
{
if ( mi->pixmap() )
h = QMAX( h, mi->pixmap()->height() + 2*itemFrame );
else
{
// Ensure that the minimum height for text-only menu items
// is the same as the icon size used by KDE.
h = QMAX( h, 16 + 2*itemFrame );
h = QMAX( h, popup->fontMetrics().height()
+ 2*itemVMargin + 2*itemFrame );
}
if ( mi->iconSet() )
h = QMAX( h, mi->iconSet()->pixmap(
QIconSet::Small, QIconSet::Normal).height() +
2 * itemFrame );
}
if ( ! mi->text().isNull() && mi->text().find('\t') >= 0 )
w += 12;
else if ( mi->popup() )
w += 2 * arrowHMargin;
if ( maxpmw )
w += maxpmw + 6;
if ( checkable && maxpmw < 20 )
w += 20 - maxpmw;
if ( checkable || maxpmw > 0 )
w += 12;
w += rightBorder;
return QSize( w, h );
}
default:
return KStyle::sizeFromContents( contents, widget, contentSize, opt );
}
}
//Why ? why create virtual function ?
// Fix Qt's wacky image alignment
QPixmap MandrivaStyle::stylePixmap(StylePixmap stylepixmap,
const QWidget* widget,
const QStyleOption& opt) const
{
return KStyle::stylePixmap(stylepixmap, widget, opt);
}
bool MandrivaStyle::eventFilter( QObject *object, QEvent *event )
{
if (KStyle::eventFilter( object, event ))
return true;
QToolBar* toolbar;
//Hover highlight on buttons and combos
if ( object->inherits("QPushButton")
|| object->inherits("QComboBox")
|| object->inherits("QScrollBar")
|| object->inherits("QHeader")
|| object->inherits("QSlider")
|| object->inherits("QCheckBox")
|| object->inherits("QSplitterHandle"))
{
if ( (event->type() == QEvent::Enter) && static_cast<QWidget*>(object)->isEnabled())
{
QWidget* button = static_cast<QWidget*>(object);
hoverWidget = button;
button->repaint( false );
}
else if ( (event->type() == QEvent::Leave) && (object == hoverWidget) )
{
QWidget* button = static_cast<QWidget*>(object);
hoverWidget = 0;
hoverControl = HoverNone;
button->repaint( false );
}
if ((object->inherits("QScrollBar") || object->inherits("QComboBox"))
&& event->type() == QEvent::MouseMove)
{
QWidget *button = static_cast<QWidget*>(object);
QMouseEvent *e = static_cast<QMouseEvent*>(event);
// updateHoverControl will trigger a repainting if necessary
updateHoverControl(e->pos());
}
}
else if (object->inherits("QListBox"))
{
if ( event->type() == QEvent::Show || event->type() == QEvent::Hide)
{
QWidget *w = static_cast<QWidget*>(object);
if (w->parentWidget() && w->parentWidget()->inherits("QComboBox"))
w->parentWidget()->repaint(false);
}
}
else if ( object->parent() && !qstrcmp( object->name(), kdeToolbarWidget ) )
{
// Draw a gradient background for custom widgets in the toolbar
// that have specified a "kde toolbar widget" name.
if (event->type() == QEvent::Paint )
{
// Find the top-level toolbar of this widget, since it may be nested in other
// widgets that are on the toolbar.
QWidget *widget = static_cast<QWidget*>(object);
QWidget *parent = static_cast<QWidget*>(object->parent());
int x_offset = widget->x(), y_offset = widget->y();
while (parent && parent->parent() && !qstrcmp( parent->name(), kdeToolbarWidget ) )
{
x_offset += parent->x();
y_offset += parent->y();
parent = static_cast<QWidget*>(parent->parent());
}
QRect r = widget->rect();
QRect pr = parent->rect();
bool horiz_grad = pr.width() < pr.height();
// Check if the parent is a QToolbar, and use its orientation, else guess.
QToolBar* tb = dynamic_cast<QToolBar*>(parent);
if (tb) horiz_grad = tb->orientation() == Qt::Vertical;
QPainter p( widget );
renderGradient(&p, r, parent->colorGroup().background(),parent->colorGroup().background(), horiz_grad);/*,
x_offset, y_offset, pr.width(), pr.height());*/
//FIXME: check this code later
return false; // Now draw the contents
}
}
else if ( object->parent() &&
(toolbar = dynamic_cast<QToolBar*>(object->parent())) )
{
// We need to override the paint event to draw a
// gradient on a QToolBarExtensionWidget.
if ( event->type() == QEvent::Paint )
{
QWidget *widget = static_cast<QWidget*>(object);
QRect wr = widget->rect(), tr = toolbar->rect();
QPainter p( widget );
renderGradient(&p, wr, toolbar->colorGroup().background(),toolbar->colorGroup().background(),
toolbar->orientation() == Qt::Vertical);/*,
wr.x(), wr.y(), tr.width() - 2, tr.height() - 2);*/
//FIXME: check this code later
p.setPen( toolbar->colorGroup().dark() );
if ( toolbar->orientation() == Qt::Horizontal )
p.drawLine( wr.width()-1, 0, wr.width()-1, wr.height()-1 );
else
p.drawLine( 0, wr.height()-1, wr.width()-1, wr.height()-1 );
return true;
}
}
return false;
}
//***************
// renderGradient from PlastikStyle
void MandrivaStyle::renderGradient(QPainter *painter,
const QRect &rect,
const QColor &c1,
const QColor &c2,
bool horizontal) const
{
if((rect.width() <= 0)||(rect.height() <= 0))
return;
// generate a quite unique key for this surface.
CacheEntry search(cGradientTile,
horizontal ? rect.width() : 0,
horizontal ? 0 : rect.height(),
c1.rgb(), c2.rgb(), horizontal );
int key = search.key();
CacheEntry *cacheEntry;
if( (cacheEntry = pixmapCache->find(key)) )
{
if( search == *cacheEntry ) // match! we can draw now...
{
if(cacheEntry->pixmap)
painter->drawTiledPixmap(rect, *(cacheEntry->pixmap) );
return;
}
else
{
// Remove old entry in case of a conflict!
// This shouldn't happen very often, see comment in CacheEntry.
pixmapCache->remove(key);
}
}
// there wasn't anything matching in the cache, create the pixmap now...
QPixmap *result = new QPixmap(horizontal ? rect.width() : 10,
horizontal ? 10 : rect.height());
QPainter p(result);
int r_w = result->rect().width();
int r_h = result->rect().height();
int r_x, r_y, r_x2, r_y2;
result->rect().coords(&r_x, &r_y, &r_x2, &r_y2);
int rDiff, gDiff, bDiff;
int rc, gc, bc;
register int x, y;
rDiff = ( c2.red()) - (rc = c1.red());
gDiff = ( c2.green()) - (gc = c1.green());
bDiff = ( c2.blue()) - (bc = c1.blue());
register int rl = rc << 16;
register int gl = gc << 16;
register int bl = bc << 16;
int rdelta = ((1<<16) / (horizontal ? r_w : r_h)) * rDiff;
int gdelta = ((1<<16) / (horizontal ? r_w : r_h)) * gDiff;
int bdelta = ((1<<16) / (horizontal ? r_w : r_h)) * bDiff;
// these for-loops could be merged, but the if's in the inner loop
// would make it slow
if(!horizontal)
{
for ( y = 0; y < r_h; y++ )
{
rl += rdelta;
gl += gdelta;
bl += bdelta;
p.setPen(QColor(rl>>16, gl>>16, bl>>16));
p.drawLine(r_x, r_y+y, r_x2, r_y+y);
}
}
else
{
for( x = 0; x < r_w; x++)
{
rl += rdelta;
gl += gdelta;
bl += bdelta;
p.setPen(QColor(rl>>16, gl>>16, bl>>16));
p.drawLine(r_x+x, r_y, r_x+x, r_y2);
}
}
p.end();
// draw the result...
painter->drawTiledPixmap(rect, *result);
// insert into cache using the previously created key.
CacheEntry *toAdd = new CacheEntry(search);
toAdd->pixmap = result;
bool insertOk = pixmapCache->insert( key, toAdd, result->width()*result->height()*result->depth()/8 );
if(!insertOk)
delete result;
}
void MandrivaStyle::drawButton( const MandrivaColorData *cdata, const QRect & r, QPainter *p,const QColorGroup &cg, SFlags flags)const
{
QPen oldPen = p->pen();
bool down = flags & Style_Down;
bool on = flags & Style_On;
bool enabled = flags & Style_Enabled;
bool mouseOver = flags & Style_MouseOver;
bool defaultButton = flags & Style_ButtonDefault;
bool sunken = on || down;
int x, y, xw, yh;
x= r.x();
y= r.y();
xw = r.x()+r.width()-1;
yh = r.y()+r.height()-1;
if ( !formMode )
{
if ( !defaultButton || ( defaultButton &&enabled ) )
{
p->setPen( cg.background() );
p->drawRect( r );
//replace background into round
//left/top
p->drawPoint( x+1, y+1 );
p->drawPoint( x+2, y+1 );
p->drawPoint( x+1, y+2 );
//right/top
p->drawPoint( xw-2, y+1 );
p->drawPoint( xw-1, y+1 );
p->drawPoint( xw-1, y+2 );
//right/bottom
p->drawPoint( x+1, yh-2);
p->drawPoint( x+2, yh-1);
p->drawPoint( x+1, yh-1);
//left/bottom
p->drawPoint( xw-2, yh-1 );
p->drawPoint( xw-1, yh-1 );
p->drawPoint( xw-1, yh-2 );
}
else
{
p->setPen( cdata->blueMdkColor[4] );
p->drawLine( x+3, y, xw-3, y );
p->drawLine( x, y+3, x, yh-3 );
p->drawLine( x+3, yh, xw-3, yh );
p->drawLine( xw, y+3, xw, yh-3 );
p->drawPoint( x+2, y+1 );
p->drawPoint( x+1, y+2 );
p->drawPoint( x+1, yh-2 );
p->drawPoint( x+2, yh-1 );
p->drawPoint( xw-2, y+1 );
p->drawPoint( xw-1, y+2 );
p->drawPoint( xw-1, yh-2 );
p->drawPoint( xw-2, yh-1 );
p->setPen( cg.background() );
//left/top
p->drawLine( x, y, x+2, y );
p->drawLine( x, y+1, x+1, y+1 );
p->drawPoint( x, y+2 );
//right/top
p->drawLine( xw-2, y, xw, y );
p->drawLine( xw-1, y+1, xw, y+1 );
p->drawPoint( xw, y+2 );
//left/bottom
p->drawLine( x, yh-1, x+1, yh-1 );
p->drawLine( x, yh, x+2, yh );
p->drawPoint( x, yh-2 );
//right/bottom
p->drawLine( xw-1, yh-1, xw, yh-1 );
p->drawLine( xw-2, yh, xw, yh );
p->drawPoint( xw, yh-2 );
}
}
//FIX toggle button
p->setPen( enabled ? cdata->buttonColor[5] : cdata->buttonColor[4] );
//VERIFY it
p->drawLine( x+3, y+1, xw-3, y+1 );
p->drawLine( x+1, y+3, x+1, yh-3 );
p->drawPoint( x+2, y+2 );
p->setPen( cdata->buttonColor[4] );
p->drawLine( x+3, yh-1, xw-3, yh-1 );
p->drawLine( xw-1,y+3,xw-1,yh-3 );
p->drawPoint( x+2, yh-2 );
p->drawPoint( xw-2, yh-2 );
p->drawPoint( xw-2, y+2 );
p->setPen( ( down||sunken ) ? cg.base() : cdata->buttonColor[1] );
p->drawLine( xw-2, y+3, xw-2, yh-3 );
p->drawLine( x+3, yh-2, xw-3, yh-2 );
p->setPen( ( down || sunken ) ? cdata->buttonColor[2]: cg.base() );
p->drawLine( x+3, y+2, xw-3, y+2 );
p->drawLine( x+2, y+3, x+2, yh-3 );
if ( on )
renderGradient(p, QRect(x+3, y+3, xw-5, yh-5),
cdata->buttonColor[0] ,mouseOver ? cdata->buttonColor[1] : cdata->buttonColor[2], false);
else if ( down ||sunken )
renderGradient(p, QRect(x+3, y+3, xw-4, yh-4),
cdata->buttonColor[2] ,cdata->buttonColor[1], false);
else
renderGradient(p, QRect(x+3, y+3, xw-5, yh-5),
cdata->buttonColor[0] ,mouseOver ? cdata->buttonColor[1] :cdata->buttonColor[2], false);
p->setPen( oldPen ); // restore pen
}
QRect MandrivaStyle::subRect(SubRect r, const QWidget *widget) const
{
switch ( r )
{
case SR_ProgressBarContents:
{
QRect wrect( widget->rect());
return QRect( wrect.x() , wrect.y() , wrect.width(), wrect.height());
}
case SR_PushButtonFocusRect:
{
const QPushButton* button = (const QPushButton*) widget;
QRect wrect(widget->rect());
if (button->isDefault() || button->autoDefault())
return QRect(wrect.x() + 6, wrect.y() + 4, wrect.width() - 12, wrect.height() - 8);
else
return QRect(wrect.x() + 4 , wrect.y() + 5, wrect.width() - 9, wrect.height() - 8);
break;
}
case SR_ComboBoxFocusRect:
{
return querySubControlMetrics( CC_ComboBox, widget, SC_ComboBoxEditField );
}
default:
return KStyle::subRect( r, widget );
}
}
//define handle point
void MandrivaStyle::drawHandlePoint ( const MandrivaColorData *cdata,QPainter *p, int x, int y)const
{
//blue-4
p->save();
p->setPen( cdata->blueMdkColor[4]);
//optimise it and use drawLine;
p->drawPoint(x+1,y);
p->drawPoint(x+2,y);
p->drawPoint(x,y+1);
p->drawPoint(x+1,y+1);
p->drawPoint(x+2,y+1);
p->drawPoint(x+3,y+1);
//blue-2
p->setPen( cdata->blueMdkColor[2]);
p->drawPoint(x, y+2 );
p->drawPoint( x+1, y+2 );
p->drawPoint( x+1, y+3 );
//blue-1
p->setPen( cdata->blueMdkColor[1] );
p->drawPoint( x+2, y+2 );
p->drawPoint( x+3, y+2 );
p->drawPoint( x+2, y+3 );
p->restore();
}
bool MandrivaStyle::excludeColor(const QColor &col, bool active) const
{
if ( active )
{
if ( col == QColor( "#F7B610" )
|| col == QColor( "#8EC7FF" )
|| col == QColor( "#C7D3DF" ) )
return true;
}
return false;
}
bool MandrivaStyle::isFormWidget(const QWidget* widget) const
{
//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;
}
// vim: ts=4 et sw=4