replaceitem.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <qpainter.h>
00013 #include <qstyle.h>
00014 #include <qpalette.h>
00015 #include <qcheckbox.h>
00016
00017 #include "replaceitem.h"
00018
00019 bool ReplaceItem::s_listview_done = false;
00020
00021
00022 bool ReplaceItem::hasCheckedChildren() const
00023 {
00024 ReplaceItem const * item = firstChild();
00025 while ( item )
00026 {
00027 if ( item->isOn() )
00028 {
00029 return true;
00030 }
00031 item = item->nextSibling();
00032 }
00033 return false;
00034 }
00035
00036 void ReplaceItem::stateChange( bool state )
00037 {
00038 if ( s_listview_done && justClicked() )
00039 {
00040 setChecked( state );
00041 }
00042 }
00043
00044 void ReplaceItem::setChecked( bool checked )
00045 {
00046 if ( !isFile() )
00047 {
00048 if ( checked || !(parent()->hasCheckedChildren()))
00049 {
00050 if ( parent()->isOn() != checked )
00051 {
00052 parent()->_clicked = false;
00053 parent()->setOn( checked );
00054 }
00055 }
00056 return;
00057 }
00058
00059
00060 ReplaceItem * item = firstChild();
00061 while ( item )
00062 {
00063 if ( item->isOn() != checked )
00064 {
00065 item->_clicked = false;
00066 item->setOn( checked );
00067 }
00068 item = item->nextSibling();
00069 }
00070 }
00071
00072 #if KDE_VERSION > 305
00073
00074 void ReplaceItem::paintCell( QPainter * p, const QColorGroup & cg, int column, int width, int align )
00075 {
00076 if ( !p )
00077 return;
00078
00079 QListView *lvv = listView();
00080 if ( !lvv )
00081 return;
00082
00083 ReplaceView * lv = static_cast<ReplaceView*>(lvv);
00084
00085 const BackgroundMode bgmode = lv->viewport()->backgroundMode();
00086 const QColorGroup::ColorRole crole = QPalette::backgroundRoleFromMode( bgmode );
00087
00088 if ( cg.brush( crole ) != lv->colorGroup().brush( crole ) )
00089 p->fillRect( 0, 0, width, height(), cg.brush( crole ) );
00090 else
00091 lv->paintEmptyArea( p, QRect( 0, 0, width, height() ) );
00092
00093 QFontMetrics fm( lv->fontMetrics() );
00094 int boxsize = lv->style().pixelMetric(QStyle::PM_CheckListButtonSize, lv);
00095 int marg = lv->itemMargin();
00096 int r = marg;
00097
00098
00099 int styleflags = QStyle::Style_Default;
00100 if ( isOn() )
00101 styleflags |= QStyle::Style_On;
00102 else
00103 styleflags |= QStyle::Style_Off;
00104 if ( isSelected() )
00105 styleflags |= QStyle::Style_Selected;
00106 if ( isEnabled() && lv->isEnabled() )
00107 styleflags |= QStyle::Style_Enabled;
00108
00109 int x = 0;
00110 int y = 0;
00111
00112 x += 3;
00113
00114 if ( align & AlignVCenter )
00115 y = ( ( height() - boxsize ) / 2 ) + marg;
00116
00117 else
00118 y = (fm.height() + 2 + marg - boxsize) / 2;
00119
00120 lv->style().drawPrimitive(QStyle::PE_CheckListIndicator, p,
00121 QRect(x, y, boxsize,
00122 fm.height() + 2 + marg),
00123 cg, styleflags, QStyleOption(this));
00124
00125 r += boxsize + 4;
00126
00127
00128 p->translate( r, 0 );
00129 p->setPen( QPen( cg.text() ) );
00130
00131 QColorGroup mcg = cg;
00132 mcg.setColor( QColorGroup::Text, ( isFile() ? Qt::darkGreen : Qt::blue ) );
00133 mcg.setColor( QColorGroup::HighlightedText, ( isFile() ? Qt::darkGreen : Qt::blue ) );
00134
00135 QListViewItem::paintCell( p, mcg, column, width - r, align );
00136 }
00137 #endif
00138
00139 void ReplaceItem::activate( int, QPoint const & localPos )
00140 {
00141 QListView * lv = listView();
00142 QCheckBox cb(0);
00143 int boxsize = cb.sizeHint().width();
00144
00145 int rightside = lv->itemMargin() + boxsize + ( isFile() ? 0 : lv->treeStepSize() );
00146
00147
00148 _lineclicked = rightside < localPos.x();
00149 }
This file is part of the documentation for KDevelop Version 3.1.2.