OSDN Git Service

change sort order.
authorikemo <ikemo@56b19765-1e22-0410-a548-a0f45d66c51a>
Mon, 19 Jan 2004 14:56:28 +0000 (14:56 +0000)
committerikemo <ikemo@56b19765-1e22-0410-a548-a0f45d66c51a>
Mon, 19 Jan 2004 14:56:28 +0000 (14:56 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/kita/kita/trunk@827 56b19765-1e22-0410-a548-a0f45d66c51a

ChangeLog
kita/src/favoritelistview.cpp
kita/src/kitasubjectview.cpp
kita/src/threadlistview.cpp
kita/src/threadlistview.h

index 65d1fd1..8fe5917 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
 2004-01-19  Hideki Ikemoto  <ikemo@users.sourceforge.jp>
 
        * add 'reload board' button.
+       * ThreadListView.{cpp, h}: change sort order.
 
 2004-01-17  Hideki Ikemoto  <ikemo@users.sourceforge.jp>
 
index fcd8ebe..e390287 100644 (file)
@@ -67,11 +67,11 @@ void FavoriteListView::update()
         int resNum = cache->resNum( thread->datURL() );  // TODO unused variables.
 
         KListViewItem* item = new KListViewItem( subjectList );
-        item->setText( Row_Board, thread->boardName() );
-        item->setText( Row_Subject, thread->name() );
-        item->setText( Row_Read, QString( "%1" ).arg( readNum, 4 ) );
-        item->setText( Row_Since, since.toString( "yy/MM/dd hh:mm" ) );
-        item->setText( Row_DatURL, thread->datURL() );
+        item->setText( Col_Board, thread->boardName() );
+        item->setText( Col_Subject, thread->name() );
+        item->setText( Col_Read, QString( "%1" ).arg( readNum, 4 ) );
+        item->setText( Col_Since, since.toString( "yy/MM/dd hh:mm" ) );
+        item->setText( Col_DatURL, thread->datURL() );
     }
 }
 
@@ -86,7 +86,7 @@ void FavoriteListView::loadThread( QListViewItem* item )
     for ( ; it.current(); ++it ) {
         const Kita::Thread* thread = it.current();
 
-        if ( thread->datURL() == item->text( Row_DatURL ) ) {
+        if ( thread->datURL() == item->text( Col_DatURL ) ) {
             emit signalShowThread( thread );
         }
     }
@@ -95,8 +95,8 @@ void FavoriteListView::loadThread( QListViewItem* item )
 void FavoriteListView::updateThread( const Kita::Thread* updated_thread )
 {
     for ( QListViewItem * item = subjectList->firstChild(); item; item = item->nextSibling() ) {
-        if ( item->text( Row_DatURL ) == updated_thread->datURL() ) {
-            item->setText( Row_ResNum, QString( "%1" ).arg( updated_thread->resNum(), 4 ) );
+        if ( item->text( Col_DatURL ) == updated_thread->datURL() ) {
+            item->setText( Col_ResNum, QString( "%1" ).arg( updated_thread->resNum(), 4 ) );
         }
     }
 }
@@ -113,7 +113,7 @@ void FavoriteListView::slotContextMenuRequested( QListViewItem* item, const QPoi
     popup.insertItem( i18n( "Open with new tab" ), 1 );
     popup.insertItem( i18n( "Copy title and URL" ), 2 );
 
-    Kita::Thread* thread = Kita::Thread::getByURL( item->text( Row_DatURL ) );
+    Kita::Thread* thread = Kita::Thread::getByURL( item->text( Col_DatURL ) );
 
     QClipboard* clipboard = QApplication::clipboard();
 
index ebb6b20..d0245bb 100644 (file)
@@ -78,13 +78,13 @@ void KitaSubjectView::loadThread( QListViewItem* item )
 {
     if ( ! item ) return ;
 
-    KURL datURL = item->text( Row_DatURL );
+    KURL datURL = item->text( Col_DatURL );
 
     Kita::Board::setName( Kita::datToBoard( datURL.url() ), m_board->name() );
-    Kita::Thread::setName( datURL.url(), item->text( Row_Subject ) );
+    Kita::Thread::setName( datURL.url(), item->text( Col_Subject ) );
     Kita::Thread* thread = Kita::Thread::getByURL( datURL.url() );
 
-    KitaThreadInfo::setResNum( datURL.url(), item->text( Row_Read ).toInt() );
+    KitaThreadInfo::setResNum( datURL.url(), item->text( Col_Read ).toInt() );
     emit signalShowThread( thread );
 }
 
@@ -115,22 +115,22 @@ void KitaSubjectView::loadBoard( const Kita::Board* board )
         int readNum = cache->readNum( thread->datURL() );
         int resNum = thread->resNum();
 
-        KListViewItem* item = new KListViewItem( subjectList );
-        item->setText( Row_ID, QString( "%1" ).arg( i + 1, 4 ) );
-        item->setText( Row_Subject, thread->name() );
-        item->setText( Row_ResNum, QString( "%1" ).arg( resNum, 4 ) );
-        item->setText( Row_Read, ( readNum > 0 ) ? QString( "%1" ).arg( readNum, 4 ) : QString( "" ) );
-        item->setText( Row_Unread, ( readNum > 0 && resNum != readNum ) ? QString( "%1" ).arg( resNum - readNum, 4 ) : QString( "" ) );
-        item->setText( Row_Board, thread->boardName() );
-        item->setText( Row_Since, since.toString( "yy/MM/dd hh:mm" ) );
-        item->setText( Row_DatURL, thread->datURL() );
+        Kita::ThreadListViewItem* item = new Kita::ThreadListViewItem( subjectList );
+        item->setText( Col_ID, QString( "%1" ).arg( i + 1, 4 ) );
+        item->setText( Col_Subject, thread->name() );
+        item->setText( Col_ResNum, QString( "%1" ).arg( resNum, 4 ) );
+        item->setText( Col_Read, ( readNum > 0 ) ? QString( "%1" ).arg( readNum, 4 ) : QString( "" ) );
+        item->setText( Col_Unread, ( readNum > 0 && resNum != readNum ) ? QString( "%1" ).arg( resNum - readNum, 4 ) : QString( "" ) );
+        item->setText( Col_Board, thread->boardName() );
+        item->setText( Col_Since, since.toString( "yy/MM/dd hh:mm" ) );
+        item->setText( Col_DatURL, thread->datURL() );
 
         if ( readNum > 0 && resNum != readNum ) {
             // Ì¤Æɤ¢¤ê
-            item->setPixmap( Row_Mark, SmallIcon( "unread" ) );
+            item->setPixmap( Col_Mark, SmallIcon( "unread" ) );
         } else if ( readNum > 0 ) {
             // ´ûÆÉ
-            item->setPixmap( Row_Mark, SmallIcon( "read" ) );
+            item->setPixmap( Col_Mark, SmallIcon( "read" ) );
         }
     }
 
@@ -150,11 +150,11 @@ void KitaSubjectView::setFont( const QFont& font )
 void KitaSubjectView::updateThread( const Kita::Thread* updated_thread )
 {
     for ( QListViewItem * item = subjectList->firstChild(); item; item = item->nextSibling() ) {
-        if ( item->text( Row_DatURL ) == updated_thread->datURL() ) {
-            int resNum = item->text( Row_ResNum ).toInt();
+        if ( item->text( Col_DatURL ) == updated_thread->datURL() ) {
+            int resNum = item->text( Col_ResNum ).toInt();
             int readNum = updated_thread->resNum();
-            item->setText( Row_Read, QString( "%1" ).arg( readNum, 4 ) );
-            item->setText( Row_Unread, readNum > 0 && resNum != readNum ? QString( "%1" ).arg( resNum - readNum, 4 ) : QString( "" ) );
+            item->setText( Col_Read, QString( "%1" ).arg( readNum, 4 ) );
+            item->setText( Col_Unread, readNum > 0 && resNum != readNum ? QString( "%1" ).arg( resNum - readNum, 4 ) : QString( "" ) );
         }
     }
 }
@@ -170,7 +170,7 @@ void KitaSubjectView::slotContextMenuRequested( QListViewItem* item, const QPoin
     popup.insertItem( i18n( "Open with new tab" ), 1 );
     popup.insertItem( i18n( "Copy title and URL" ), 2 );
 
-    Kita::Thread* thread = Kita::Thread::getByURL( item->text( Row_DatURL ) );
+    Kita::Thread* thread = Kita::Thread::getByURL( item->text( Col_DatURL ) );
 
     QClipboard* clipboard = QApplication::clipboard();
 
index 0212e7c..3e9ece4 100644 (file)
@@ -17,6 +17,7 @@
 #include <qtoolbutton.h>
 #include <qcombobox.h>
 #include <qregexp.h>
+#include <qheader.h>
 
 using namespace Kita;
 
@@ -34,11 +35,11 @@ ThreadListView::ThreadListView( QWidget* parent, const char* name )
     subjectList->addColumn( i18n( "ResNum" ) );
     subjectList->addColumn( i18n( "ReadNum" ) );
     subjectList->addColumn( i18n( "Unread" ) );
-    subjectList->addColumn( i18n( "Board" ) );
     subjectList->addColumn( i18n( "Since" ) );
+    subjectList->addColumn( i18n( "Board" ) );
 
-    subjectList->setColumnWidth( Row_Subject, 400 );
-    subjectList->setColumnWidthMode( Row_Subject, QListView::Manual );
+    subjectList->setColumnWidth( Col_Subject, 400 );
+    subjectList->setColumnWidthMode( Col_Subject, QListView::Manual );
 
     connect( SearchButton, SIGNAL( clicked() ),
              SLOT( slotSearchButton() ) );
@@ -62,7 +63,7 @@ void ThreadListView::insertSearchCombo()
 {
     for ( int count = 0; count < SearchCombo->count(); ++count ) {
         if ( SearchCombo->text( count ) == SearchCombo->currentText() ) {
-            return;
+            return ;
         }
     }
     SearchCombo->insertItem( SearchCombo->currentText() );
@@ -83,17 +84,17 @@ QStringList ThreadListView::parseSearchQuery( const QString &input )
 
 void ThreadListView::searchNext( const QStringList &query )
 {
-    if ( query.isEmpty() ) return;
+    if ( query.isEmpty() ) return ;
 
     if ( query != m_prevquery ) {
         searchAll( query );
         slotHideButton( HideButton->isOn() );
         m_nextHitIndex = 0; //A next jump-search target reset to '0'.
-        return;
+        return ;
     }
 
     if ( m_nextHitIndex >= m_hitList.size() ) {
-        return;
+        return ;
     }
 
     KListViewItem* item = m_hitList[ m_nextHitIndex ];
@@ -110,13 +111,13 @@ void ThreadListView::searchAll( const QStringList &query )
 
     QListViewItemIterator listIt( subjectList );
     while ( listIt.current() != 0 ) {
-        KListViewItem* item = static_cast<KListViewItem*>( listIt.current() );
-        item->setPixmap( Row_Icon, 0 );
+        KListViewItem * item = static_cast<KListViewItem*>( listIt.current() );
+        item->setPixmap( Col_Icon, 0 );
 
         QStringList::const_iterator queryIt = query.begin();
         for ( ; queryIt != query.end(); ++queryIt ) {
-            if ( item->text( Row_Subject ).contains( *queryIt, false ) ) {
-                item->setPixmap( Row_Icon, SmallIcon( "find" ) );
+            if ( item->text( Col_Subject ).contains( *queryIt, false ) ) {
+                item->setPixmap( Col_Icon, SmallIcon( "find" ) );
                 m_hitList.append( item );
                 break;
             }
@@ -127,12 +128,12 @@ void ThreadListView::searchAll( const QStringList &query )
 
 void ThreadListView::slotHideButton( bool on )
 {
-    if ( m_hitList.empty() ) return;
+    if ( m_hitList.empty() ) return ;
 
     QListViewItemIterator listIt( subjectList );
     while ( listIt.current() != 0 ) {
-        KListViewItem* item = static_cast<KListViewItem *>( listIt.current() );
-        if ( on && ! item->pixmap( Row_Icon ) ) {
+        KListViewItem * item = static_cast<KListViewItem *>( listIt.current() );
+        if ( on && ! item->pixmap( Col_Icon ) ) {
             item->setVisible( false );
         } else {
             item->setVisible( true );
@@ -141,4 +142,16 @@ void ThreadListView::slotHideButton( bool on )
     }
 }
 
+int ThreadListViewItem::compare( QListViewItem* i, int col, bool ascending ) const
+{
+    switch ( col ) {
+    case Col_ResNum:
+    case Col_Read:
+    case Col_Unread:
+        return QString::localeAwareCompare( i->key( col, ascending ), key( col, ascending ) );
+    default:
+        return QString::localeAwareCompare( key( col, ascending ), i->key( col, ascending ) );
+    }
+}
+
 #include "threadlistview.moc"
index c1abb88..247da95 100644 (file)
 #include <klistview.h>
 
 enum ThreadListViewRows {
-    Row_Mark,
-    Row_ID,
-    Row_Icon,
-    Row_Subject,
-    Row_ResNum,
-    Row_Read,
-    Row_Unread,
-    Row_Board,
-    Row_Since,
-    Row_DatURL
+    Col_Mark,
+    Col_ID,
+    Col_Icon,
+    Col_Subject,
+    Col_ResNum,
+    Col_Read,
+    Col_Unread,
+    Col_Since,
+    Col_Board,
+    Col_DatURL
 };
 
 namespace Kita
@@ -57,6 +57,14 @@ namespace Kita
         void slotSearchButton();
     };
 
+    class ThreadListViewItem : public KListViewItem
+    {
+    public:
+        ThreadListViewItem( QListView* parent ) : KListViewItem( parent ) {};
+        virtual ~ThreadListViewItem() {};
+
+        virtual int compare( QListViewItem* i, int col, bool ascending ) const;
+    };
 };
 
 #endif