summaryrefslogtreecommitdiff
path: root/libopie2/opieui/olistview.cpp
authormickeyl <mickeyl>2003-05-01 14:00:37 (UTC)
committer mickeyl <mickeyl>2003-05-01 14:00:37 (UTC)
commit95e533a6ac257d3b95cd8905660008fb7dcd33f1 (patch) (side-by-side diff)
treec671954f59eaa70db2285f9abe49fd8b4512dd12 /libopie2/opieui/olistview.cpp
parent1d721ddb247e9000e29fba3150e0cce5f59f543e (diff)
downloadopie-95e533a6ac257d3b95cd8905660008fb7dcd33f1.zip
opie-95e533a6ac257d3b95cd8905660008fb7dcd33f1.tar.gz
opie-95e533a6ac257d3b95cd8905660008fb7dcd33f1.tar.bz2
- restructure opieui example directory
- start work on ONamedListViewItem providing a slightly higher level interface
Diffstat (limited to 'libopie2/opieui/olistview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opieui/olistview.cpp109
1 files changed, 109 insertions, 0 deletions
diff --git a/libopie2/opieui/olistview.cpp b/libopie2/opieui/olistview.cpp
index 2b2f09a..8f97cc6 100644
--- a/libopie2/opieui/olistview.cpp
+++ b/libopie2/opieui/olistview.cpp
@@ -209,89 +209,100 @@ QDataStream& operator>>( QDataStream& s, OListView& lv )
#endif // QT_NO_DATASTREAM
/*======================================================================================
* OListViewItem
*======================================================================================*/
OListViewItem::OListViewItem(QListView *parent)
: QListViewItem(parent)
{
init();
}
+
OListViewItem::OListViewItem(QListViewItem *parent)
: QListViewItem(parent)
{
init();
}
+
OListViewItem::OListViewItem(QListView *parent, QListViewItem *after)
: QListViewItem(parent, after)
{
init();
}
+
OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after)
: QListViewItem(parent, after)
{
init();
}
+
OListViewItem::OListViewItem(QListView *parent,
QString label1, QString label2, QString label3, QString label4,
QString label5, QString label6, QString label7, QString label8)
: QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8)
{
init();
}
+
OListViewItem::OListViewItem(QListViewItem *parent,
QString label1, QString label2, QString label3, QString label4,
QString label5, QString label6, QString label7, QString label8)
: QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8)
{
init();
}
+
OListViewItem::OListViewItem(QListView *parent, QListViewItem *after,
QString label1, QString label2, QString label3, QString label4,
QString label5, QString label6, QString label7, QString label8)
: QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8)
{
init();
}
+
OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after,
QString label1, QString label2, QString label3, QString label4,
QString label5, QString label6, QString label7, QString label8)
: QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8)
{
init();
}
+
OListViewItem::~OListViewItem()
{
}
+
void OListViewItem::init()
{
m_known = false;
}
+
const QColor &OListViewItem::backgroundColor()
{
return isAlternate() ? static_cast<OListView*>(listView())->alternateBackground() :
listView()->viewport()->colorGroup().base();
}
+
bool OListViewItem::isAlternate()
{
OListView *lv = static_cast<OListView*>( listView() );
// check if the item above is an OListViewItem
OListViewItem *above = static_cast<OListViewItem*>( itemAbove() );
/*if (! itemAbove()->inherits( "OListViewItem" )) return false;*/
// check if we have a valid alternate background color
if (!(lv && lv->alternateBackground().isValid())) return false;
m_known = above ? above->m_known : true;
@@ -317,51 +328,54 @@ bool OListViewItem::isAlternate()
while(item)
{
item->m_odd = previous = !previous;
item->m_known = true;
item = static_cast<OListViewItem *>(item->nextSibling());
/* if (!item.inherits( "OListViewItem" ) ) break; */
}
}
return m_odd;
}
+
void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
{
QColorGroup _cg = cg;
const QPixmap *pm = listView()->viewport()->backgroundPixmap();
if (pm && !pm->isNull())
{
_cg.setBrush( QColorGroup::Base, QBrush(backgroundColor(), *pm) );
p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() );
}
else if ( isAlternate() )
{
_cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() );
}
QListViewItem::paintCell( p, _cg, column, width, alignment );
//FIXME: Use styling here!
const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator();
p->setPen( pen );
p->drawLine( width-1, 0, width-1, height() );
}
+
OListViewItem* OListViewItem::childFactory()
{
return new OListViewItem( this );
}
+
#ifndef QT_NO_DATASTREAM
void OListViewItem::serializeTo( QDataStream& s ) const
{
#warning Caution... the binary format is still under construction...
qDebug( "storing OListViewItem..." );
// store item text
for ( int i = 0; i < listView()->columns(); ++i )
{
s << text( i );
}
@@ -376,24 +390,26 @@ void OListViewItem::serializeTo( QDataStream& s ) const
// store number of items and the items itself
s << items;
item = firstChild();
for ( int i = 0; i < items; ++i )
{
s << *static_cast<OListViewItem*>( item );
item = item->nextSibling();
}
qDebug( "OListviewItem stored." );
}
+
+
void OListViewItem::serializeFrom( QDataStream& s )
{
#warning Caution... the binary format is still under construction...
qDebug( "loading OListViewItem..." );
for ( int i = 0; i < listView()->columns(); ++i )
{
QString coltext;
s >> coltext;
qDebug( "read text '%s' for column %d", (const char*) coltext, i );
setText( i, coltext );
}
@@ -402,22 +418,115 @@ void OListViewItem::serializeFrom( QDataStream& s )
s >> items;
qDebug( "read number of items = %d", items );
for ( int i = 0; i < items; ++i )
{
OListViewItem* item = childFactory();
s >> (*item);
}
qDebug( "OListViewItem loaded." );
}
+
QDataStream& operator<<( QDataStream& s, const OListViewItem& lvi )
{
lvi.serializeTo( s );
}
+
QDataStream& operator>>( QDataStream& s, OListViewItem& lvi )
{
lvi.serializeFrom( s );
}
#endif // QT_NO_DATASTREAM
+
+
+/*======================================================================================
+ * ONamedListView
+ *======================================================================================*/
+
+ONamedListView::ONamedListView( QWidget *parent, const char *name )
+ :OListView( parent, name )
+{
+}
+
+
+ONamedListView::~ONamedListView()
+{
+}
+
+
+void ONamedListView::addColumns( const QStringList& columns )
+{
+ for ( QStringList::ConstIterator it = columns.begin(); it != columns.end(); ++it )
+ {
+ qDebug( "adding column %s", (const char*) *it );
+ addColumn( *it );
+ }
+}
+
+
+/*======================================================================================
+ * ONamedListViewItem
+ *======================================================================================*/
+
+ONamedListViewItem::ONamedListViewItem( QListView* parent, const QStringList& texts )
+ :OListViewItem( parent )
+{
+ setText( texts );
+}
+
+
+ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, const QStringList& texts )
+ :OListViewItem( parent )
+{
+ setText( texts );
+}
+
+
+ONamedListViewItem::ONamedListViewItem( QListView* parent, QListViewItem* after, const QStringList& texts )
+ :OListViewItem( parent, after )
+{
+ setText( texts );
+}
+
+
+ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, QListViewItem* after, const QStringList& texts )
+ :OListViewItem( parent, after )
+{
+ setText( texts );
+}
+
+
+ONamedListViewItem::~ONamedListViewItem()
+{
+}
+
+
+void ONamedListViewItem::setText( const QStringList& texts )
+{
+ int col = 0;
+ for ( QStringList::ConstIterator it = texts.begin(); it != texts.end(); ++it )
+ {
+ qDebug( "setting column %d = text %s", col, (const char*) *it );
+ OListViewItem::setText( col++, *it );
+ }
+
+}
+
+
+void ONamedListViewItem::setText( const QString& column, const QString& text )
+{
+ //FIXME: If used excessively, this will slow down performance of updates
+ //FIXME: because of the linear search over all column texts.
+ //FIXME: I will optimize later by using a hash map.
+ for ( int i = 0; i < listView()->columns(); ++i )
+ {
+ if ( listView()->columnText( i ) == column )
+ {
+ OListViewItem::setText( i, text );
+ return;
+ }
+ }
+ qWarning( "ONamedListViewItem::setText(): Warning! Columntext '%s' not found.", (const char*) column );
+}