diff MainWindow.py @ 33:f371d02fa09d

mark unread feed entries bold. Add a menu item to toggle between read/unread
author Dirk Olmes <dirk@xanthippe.ping.de>
date Fri, 30 Apr 2010 06:22:33 +0200
parents 5bb57caa8f66
children 22214d79ed41
line wrap: on
line diff
--- a/MainWindow.py	Fri Apr 30 06:02:06 2010 +0200
+++ b/MainWindow.py	Fri Apr 30 06:22:33 2010 +0200
@@ -25,22 +25,26 @@
         self.ui.feedList.update()
 
     def initFeedEntryList(self):
-        pass
-#        self.ui.feedEntryList.setItemDelegate()
-        #        self.ui.feedList.setItemDelegate(CustomItemDelegate(self))
+        self.ui.feedEntryList.setItemDelegate(FeedEntryItemDelegate())
 
     def feedSelected(self, index):
         self.selectedFeed = self.allFeeds[index.row()]
-        sortedEntries = self.selectedFeed.entriesSortedByUpdateDate()
-        model = DisplayModel(self, sortedEntries, FeedEntry.userPresentableString)
+        self.sortedEntries = self.selectedFeed.entriesSortedByUpdateDate()
+        model = DisplayModel(self, self.sortedEntries, FeedEntry.userPresentableString)
         self.ui.feedEntryList.setModel(model)
+        self.ui.feedEntryList.itemDelegate().entries = self.sortedEntries
         self.ui.feedEntryList.update()
         
     def feedEntrySelected(self, index):
         row = index.row()
-        entry = self.selectedFeed.entries[row]
-        baseUrl = QUrl(entry.link) # TODO this is the wrong base url, figure out the correct one
-        self.ui.webView.setHtml(entry.summary, baseUrl)
+        self.selectedEntry = self.sortedEntries[row]
+        baseUrl = QUrl(self.selectedEntry.link) # TODO this is the wrong base url, figure out the correct one
+        self.ui.webView.setHtml(self.selectedEntry.summary, baseUrl)
+    
+    def toggleReadOnSelectedEntry(self):
+        self.selectedEntry.toggleRead()
+        self.session.commit()
+        self.ui.feedList.update()
     
     def addFeed(self):
         addFeed = AddFeed(self.session)
@@ -51,11 +55,15 @@
             # TODO get status from feedUpdater and display in status area of the main window
             self.updateFeedList()
 
-class CustomItemDelegate(QtGui.QStyledItemDelegate):
-    def __init__(self, parent):
-        print("init")
-        QtGui.QStyledItemDelegate.__init__(self, parent)
+class FeedEntryItemDelegate(QtGui.QStyledItemDelegate):
+    def __init__(self):
+        QtGui.QStyledItemDelegate.__init__(self, None)
     
     def paint(self, painter, style, index):
-        style.font.setWeight(QFont.Bold)
+        row = index.row()
+        entry = self.entries[row]
+        if entry.read:
+            style.font.setWeight(QFont.Normal)
+        else:
+            style.font.setWeight(QFont.Bold)
         QtGui.QStyledItemDelegate.paint(self, painter, style, index)