[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: branches/kdepim/enterprise4/kdepim/kleopatra/utils
From: Marc Mutz <mutz () kde ! org>
Date: 2010-10-29 9:37:53
Message-ID: 20101029093753.9C398AC89B () svn ! kde ! org
[Download RAW message or body]
SVN commit 1190972 by mutz:
KDLogTextWidget: upgrade to version from KDTools v2.2, pt.2: implement alternating \
row colours
M +65 -1 kdlogtextwidget.cpp
M +4 -0 kdlogtextwidget.h
--- branches/kdepim/enterprise4/kdepim/kleopatra/utils/kdlogtextwidget.cpp \
#1190971:1190972 @@ -73,6 +73,11 @@
QPoint scrollOffset() const;
+ QRect lineRect( int idx ) const {
+ assert( !cache.dirty );
+ return QRect( 0, idx * cache.fontMetrics.lineSpacing, \
cache.dimensions.longestLineLength, cache.fontMetrics.lineSpacing-1 ); + }
+
struct Style {
QColor color;
@@ -100,6 +105,8 @@
unsigned int minimumVisibleLines;
unsigned int minimumVisibleColumns;
+ bool alternatingRowColors;
+
QBasicTimer timer;
mutable struct Cache {
@@ -235,6 +242,26 @@
return d->minimumVisibleColumns;
}
+/*!
+ \property KDLogTextWidget::alternatingRowColors
+
+ Specifies whether the background should be drawn using
+ row-alternating colors. The default is \c false.
+
+ Get this property's value using %alternatingRowColors(), and set it
+ using %setAlternatingRowColors().
+*/
+void KDLogTextWidget::setAlternatingRowColors( bool on ) {
+ if ( on == d->alternatingRowColors )
+ return;
+ d->alternatingRowColors = on;
+ update();
+}
+
+bool KDLogTextWidget::alternatingRowColors() const {
+ return d->alternatingRowColors;
+}
+
QSize KDLogTextWidget::minimumSizeHint() const {
d->updateCache();
const QSize base = QAbstractScrollArea::minimumSizeHint();
@@ -309,6 +336,35 @@
const Private::Cache & cache = d->cache;
+ p.setPen( Qt::NoPen );
+
+ p.setBrush( palette().base() );
+
+ if ( d->alternatingRowColors ) {
+
+ p.drawRect( visible );
+
+#if 0 // leaves garbage
+ for ( unsigned int i = visibleLines.first % 2 ? visibleLines.first+1 : \
visibleLines.first, end = visibleLines.second ; i < end ; i+=2 ) + \
p.drawRect( d->lineRect( i ) ); +
+ if ( visibleLines.second >= 0 ) {
+ const int lastY = d->lineRect( visibleLines.second-1 ).y();
+ if ( lastY < visible.bottom() )
+ p.drawRect( 0, lastY+1, cache.dimensions.longestLineLength, \
visible.bottom() - lastY ); + }
+#endif
+
+ p.setBrush( palette().alternateBase() );
+ for ( unsigned int i = visibleLines.first % 2 ? visibleLines.first : \
visibleLines.first+1, end = visibleLines.second ; i < end ; i+=2 ) + \
p.drawRect( d->lineRect( i ) ); +
+ } else {
+
+ p.drawRect( visible );
+
+ }
+
// ### unused optimisation: paint lines by styles to minimise pen changes.
for ( unsigned int i = visibleLines.first, end = visibleLines.second ; i != end \
; ++i ) { const Private::LineItem & li = d->lines[i];
@@ -348,10 +404,18 @@
historySize( 0xFFFFFFFF ),
minimumVisibleLines( 1 ),
minimumVisibleColumns( 1 ),
+ alternatingRowColors( false ),
timer(),
cache()
{
-
+ // PENDING(marc) find all the magic flags we need here...
+ QWidget * const vp = qq->viewport();
+ vp->setBackgroundRole( QPalette::Base );
+ vp->setAttribute( Qt::WA_StaticContents );
+ vp->setAttribute( Qt::WA_NoSystemBackground );
+#ifndef QT_NO_CURSOR
+ vp->setCursor(Qt::IBeamCursor);
+#endif
}
KDLogTextWidget::Private::~Private() {}
--- branches/kdepim/enterprise4/kdepim/kleopatra/utils/kdlogtextwidget.h \
#1190971:1190972 @@ -38,6 +38,7 @@
Q_PROPERTY( QStringList lines READ lines WRITE setLines )
Q_PROPERTY( uint minimumVisibleLines READ minimumVisibleLines WRITE \
setMinimumVisibleLines )
Q_PROPERTY( uint minimumVisibleColumns READ minimumVisibleColumns WRITE \
setMinimumVisibleColumns ) + Q_PROPERTY( bool alternatingRowColors READ \
alternatingRowColors WRITE setAlternatingRowColors ) Q_CLASSINFO( "description", \
"High-speed text display widget" ) public:
explicit KDLogTextWidget( QWidget * parent=0 );
@@ -57,6 +58,9 @@
void setMinimumVisibleColumns( unsigned int num );
unsigned int minimumVisibleColumns() const;
+ void setAlternatingRowColors( bool on );
+ bool alternatingRowColors() const;
+
/*! \reimp */ QSize minimumSizeHint() const;
/*! \reimp */ QSize sizeHint() const;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic