[Kita-svn] [2426] - add ThreadListHeaderView

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2009年 7月 18日 (土) 17:55:03 JST


Revision: 2426
          http://sourceforge.jp/projects/kita/svn/view?view=rev&revision=2426
Author:   nogu
Date:     2009-07-18 17:55:03 +0900 (Sat, 18 Jul 2009)

Log Message:
-----------
- add ThreadListHeaderView
- add TrheadListView::contextMenuEvent()

Modified Paths:
--------------
    kita/branches/KITA-KDE4/kita/src/boardview.cpp
    kita/branches/KITA-KDE4/kita/src/boardview.h
    kita/branches/KITA-KDE4/kita/src/favoritelistview.cpp
    kita/branches/KITA-KDE4/kita/src/favoritelistview.h
    kita/branches/KITA-KDE4/kita/src/threadlistview.cpp
    kita/branches/KITA-KDE4/kita/src/threadlistview.h

Added Paths:
-----------
    kita/branches/KITA-KDE4/kita/src/threadlistheaderview.cpp
    kita/branches/KITA-KDE4/kita/src/threadlistheaderview.h

Modified: kita/branches/KITA-KDE4/kita/src/boardview.cpp
===================================================================
--- kita/branches/KITA-KDE4/kita/src/boardview.cpp	2009-07-18 07:54:35 UTC (rev 2425)
+++ kita/branches/KITA-KDE4/kita/src/boardview.cpp	2009-07-18 08:55:03 UTC (rev 2426)
@@ -13,28 +13,20 @@
 #include <QtCore/QDateTime>
 #include <QtCore/QList>
 #include <QtGui/QApplication>
-#include <QtGui/QClipboard>
 #include <QtGui/QMouseEvent>
 
-#include <kaction.h>
 #include <kconfig.h>
-#include <kmenu.h>
 #include <kmessagebox.h>
-#include <krun.h>
 #include <kstandarddirs.h>
 
 #include "boardtabwidget.h"
 #include "threadlistviewitem.h"
-#include "ui_threadproperty.h"
 #include "viewmediator.h"
 #include "libkita/boardmanager.h"
 #include "libkita/config_xt.h"
 #include "libkita/datmanager.h"
-#include "libkita/favoritethreads.h"
 #include "libkita/kita_misc.h"
 #include "libkita/thread.h"
-#include "libkita/threadindex.h"
-#include "libkita/threadinfo.h"
 
 using namespace Kita;
 
@@ -44,8 +36,6 @@
     m_parent = parent;
     closeButton->setEnabled(true);
 
-    connect(subjectList, SIGNAL(customContextMenuRequested(const QPoint&)),
-             SLOT(slotContextMenuRequested(const QPoint&)));
     connect(subjectList, SIGNAL(returnPressed(QTableWidgetItem*)),
              SLOT(loadThread(QTableWidgetItem*)));
     connect(ReloadButton, SIGNAL(clicked()),
@@ -329,106 +319,6 @@
     }
 }
 
-void BoardView::slotContextMenuRequested(const QPoint& point)
-{
-    QTableWidgetItem* item = subjectList->itemAt(point);
-    if (item == 0) {
-        return;
-    }
-
-    QString datURL = subjectList->item(item->row(), ColumnDatUrl)->text();
-    QString threadURL = DatManager::threadURL(datURL);
-    bool isFavorites = FavoriteThreads::getInstance()->contains(datURL);
-
-    // create popup menu.
-    KMenu popup(0);
-
-    KAction* openWithBrowserAct = new KAction(i18n("Open with Web Browser") , this);
-    popup.addAction(openWithBrowserAct);
-
-    KAction* copyURLAct = new KAction(i18n("Copy URL"), this);
-    popup.addAction(copyURLAct);
-
-    KAction* copyTitleAndURLAct = new KAction(i18n("Copy title and URL"), this);
-    popup.addAction(copyTitleAndURLAct);
-
-    KAction* favoritesAct;
-    if (isFavorites) {
-        favoritesAct = new KAction(i18n("Remove from Favorites"), this);
-    } else {
-        favoritesAct = new KAction(i18n("Add to Favorites"), this);
-    }
-    popup.addAction(favoritesAct);
-
-    KAction* deleteLogAct = 0;
-    if (DatManager::getReadNum(datURL)) {
-        popup.addSeparator();
-
-        deleteLogAct = new KAction(i18n("Delete Log"), this);
-        popup.addAction(deleteLogAct);
-    }
-    popup.addSeparator();
-
-    KAction* propertyAct = new KAction(i18n("Property"), this);
-    popup.addAction(propertyAct);
-
-    // exec popup menu.
-    QClipboard* clipboard = QApplication::clipboard();
-    QString cliptxt;
-
-    QAction* action = popup.exec(QCursor::pos());
-    if (!action) {
-        return;
-    }
-    if (action == openWithBrowserAct) {
-        KRun::runUrl(threadURL, "text/html", this);
-    } else if (action == copyURLAct) {
-        clipboard->setText(threadURL, QClipboard::Clipboard);
-        clipboard->setText(threadURL, QClipboard::Selection);
-    } else if (action == copyTitleAndURLAct) {
-        cliptxt = DatManager::threadName(datURL) + '\n' + threadURL;
-        clipboard->setText(cliptxt , QClipboard::Clipboard);
-        clipboard->setText(cliptxt , QClipboard::Selection);
-    } else if (action == favoritesAct) {
-        ViewMediator::getInstance()->bookmark(datURL, !isFavorites);
-    } else if (action == deleteLogAct) {
-        deleteLog(threadURL);
-    } else if (action == propertyAct) {
-            QWidget* widget = new QWidget;
-            Ui::ThreadProperty* propertyWidget
-                = new Ui::ThreadProperty;
-            propertyWidget->setupUi(widget);
-            propertyWidget->threadURLLabel->setText(threadURL);
-            propertyWidget->datURLLabel->setText(datURL);
-
-            propertyWidget->threadNameLabel->
-                setText(DatManager::threadName(datURL));
-            propertyWidget->cachePathLabel->
-                setText(DatManager::getCachePath(datURL));
-            propertyWidget->indexPathLabel->
-                setText(DatManager::getCacheIndexPath(datURL));
-            propertyWidget->resNumLabel->
-                setText(QString::number(DatManager::getResNum(datURL)));
-            propertyWidget->readNumLabel->
-                setText(QString::number(DatManager::getReadNum(datURL)));
-            propertyWidget->viewPosLabel->
-                setText(QString::number(DatManager::getViewPos(datURL)));
-
-            propertyWidget->idx_threadNameWithIndexLabel->
-                setText(ThreadIndex::getSubject(datURL));
-            propertyWidget->idx_resNumLabel->
-                setText(QString::number(ThreadIndex::getResNum(datURL)));
-            propertyWidget->idx_readNumLabel->
-                setText(QString::number(ThreadIndex::getReadNum(datURL)));
-            propertyWidget->idx_viewPosLabel->
-                setText(QString::number(ThreadIndex::getViewPos(datURL)));
-
-            propertyWidget->cache_readNumLabel->
-                setText(QString::number(ThreadInfo::readNum(datURL)));
-            widget->show();
-    }
-}
-
 void BoardView::deleteLog(const KUrl& url)
 {
     if (KMessageBox::warningYesNo(this, i18n("Do you want to delete Log ?"),

Modified: kita/branches/KITA-KDE4/kita/src/boardview.h
===================================================================
--- kita/branches/KITA-KDE4/kita/src/boardview.h	2009-07-18 07:54:35 UTC (rev 2425)
+++ kita/branches/KITA-KDE4/kita/src/boardview.h	2009-07-18 08:55:03 UTC (rev 2426)
@@ -66,7 +66,6 @@
 
     private slots:
         void loadThread(QTableWidgetItem* item);
-        void slotContextMenuRequested(const QPoint&);
         void slotCloseButton();
         void slotSizeChange(int section, int oldSize, int newSize);
 

Modified: kita/branches/KITA-KDE4/kita/src/favoritelistview.cpp
===================================================================
--- kita/branches/KITA-KDE4/kita/src/favoritelistview.cpp	2009-07-18 07:54:35 UTC (rev 2425)
+++ kita/branches/KITA-KDE4/kita/src/favoritelistview.cpp	2009-07-18 08:55:03 UTC (rev 2426)
@@ -38,8 +38,6 @@
 
     connect(subjectList, SIGNAL(cellPressed(int, int)),
              SLOT(loadThread(int, int)));
-    connect(subjectList, SIGNAL(customContextMenuRequested(const QPoint&)),
-             SLOT(slotContextMenuRequested(const QPoint&)));
     connect(ReloadButton, SIGNAL(clicked()),
              SLOT(reload()));
 
@@ -119,53 +117,6 @@
 }
 
 /**
- * show and exec popup menu.
- */
-void FavoriteListView::slotContextMenuRequested(const QPoint& point)
-{
-    QTableWidgetItem* item = subjectList->itemAt(point);
-    if (!item) {
-        return;
-    }
-
-    KMenu popup(0);
-
-    KAction* openWithBrowserAct = new KAction(i18n("Open with Web Browser"), this);
-    popup.addAction(openWithBrowserAct);
-
-    KAction* copyURLAct = new KAction(i18n("Copy URL"), this);
-    popup.addAction(copyURLAct);
-
-    KAction* copyTitleAndURLAct = new KAction(i18n("Copy title and URL"), this);
-    popup.addAction(copyTitleAndURLAct);
-
-    KAction* removeFromFavoritesAct = new KAction(i18n("Remove from Favorites"), this);
-    popup.addAction(removeFromFavoritesAct);
-
-    QString datURL = subjectList->item(item->row(), ColumnDatUrl)->text();
-    QString threadURL = DatManager::threadURL(datURL);
-
-    QClipboard* clipboard = QApplication::clipboard();
-    QString clipText;
-
-    QAction* action = popup.exec(point);
-    if (!action) {
-        return;
-    }
-    if (action == openWithBrowserAct) {
-        KRun::runUrl(DatManager::threadURL(datURL), "text/html", this);
-    } else if (action == copyURLAct) {
-        clipboard->setText(threadURL);
-    } else if (action == copyTitleAndURLAct) {
-        clipText = DatManager::threadName(datURL) + '\n' + threadURL;
-        clipboard->setText(clipText , QClipboard::Clipboard);
-        clipboard->setText(clipText , QClipboard::Selection);
-    } else if (action == removeFromFavoritesAct) {
-        ViewMediator::getInstance()->bookmark(datURL, false);
-    }
-}
-
-/**
  *
  */
 void FavoriteListView::reload()

Modified: kita/branches/KITA-KDE4/kita/src/favoritelistview.h
===================================================================
--- kita/branches/KITA-KDE4/kita/src/favoritelistview.h	2009-07-18 07:54:35 UTC (rev 2425)
+++ kita/branches/KITA-KDE4/kita/src/favoritelistview.h	2009-07-18 08:55:03 UTC (rev 2426)
@@ -28,7 +28,6 @@
 
     private slots:
         void loadThread(int row, int column);
-        void slotContextMenuRequested(const QPoint&);
         void reload();
     };
 }

Added: kita/branches/KITA-KDE4/kita/src/threadlistheaderview.cpp
===================================================================
--- kita/branches/KITA-KDE4/kita/src/threadlistheaderview.cpp	                        (rev 0)
+++ kita/branches/KITA-KDE4/kita/src/threadlistheaderview.cpp	2009-07-18 08:55:03 UTC (rev 2426)
@@ -0,0 +1,55 @@
+/***************************************************************************
+*   Copyright (C) 2003 by Hideki Ikemoto                                  *
+*   ikemo****@wakab*****                                                       *
+*                                                                         *
+*   This program is free software; you can redistribute it and/or modify  *
+*   it under the terms of the GNU General Public License as published by  *
+*   the Free Software Foundation; either version 2 of the License, or     *
+*   (at your option) any later version.                                   *
+***************************************************************************/
+
+#include "threadlistheaderview.h"
+
+#include "kaction.h"
+#include "klocale.h"
+#include "kmenu.h"
+
+#include "threadlistviewitem.h"
+
+using namespace Kita;
+
+ThreadListHeaderView::ThreadListHeaderView(QWidget* parent)
+        : QHeaderView(Qt::Horizontal, parent)
+{
+}
+
+void ThreadListHeaderView::contextMenuEvent(QContextMenuEvent * /*event*/)
+{
+    KMenu popup;
+    for (int i = ColumnBegin; i <= ColumnEnd; i++) {
+        if (i != ColumnSubject && i != ColumnMarkOrder && i != ColumnIdOrder) {
+            KAction* action = new KAction(""/*s_colAttr[i].itemName*/, this);
+            action->setCheckable(true);
+            action->setChecked(!isSectionHidden(i));
+            action->setData(QVariant(i));
+            popup.addAction(action);
+        }
+    }
+    KAction* autoResizeAct = new KAction(i18n("Auto Resize"), this);
+    autoResizeAct->setCheckable(true);
+//    autoResizeAct->setChecked(autoResize()); TODO
+    popup.addAction(autoResizeAct);
+
+    QAction* action = popup.exec(QCursor::pos());
+    if (!action) {
+        return;
+    }
+    if (action == autoResizeAct) {
+        //setAutoResize(!action->isChecked());TODO
+    } else if (action->isChecked()) {
+        hideSection(action->data().toInt());
+    } else {
+        showSection(action->data().toInt());
+    }
+    //saveHeaderOnOff(); TODO
+}

Added: kita/branches/KITA-KDE4/kita/src/threadlistheaderview.h
===================================================================
--- kita/branches/KITA-KDE4/kita/src/threadlistheaderview.h	                        (rev 0)
+++ kita/branches/KITA-KDE4/kita/src/threadlistheaderview.h	2009-07-18 08:55:03 UTC (rev 2426)
@@ -0,0 +1,30 @@
+/***************************************************************************
+*   Copyright (C) 2003 by Hideki Ikemoto                                  *
+*   ikemo****@wakab*****                                                       *
+*                                                                         *
+*   This program is free software; you can redistribute it and/or modify  *
+*   it under the terms of the GNU General Public License as published by  *
+*   the Free Software Foundation; either version 2 of the License, or     *
+*   (at your option) any later version.                                   *
+***************************************************************************/
+#ifndef KITATHREADLISTHEADERVIEW_H
+#define KITATHREADLISTHEADERVIEW_H
+
+#include <QtGui/QHeaderView>
+
+namespace Kita
+{
+    class ThreadListHeaderView : public QHeaderView
+    {
+        Q_OBJECT
+
+    public:
+        explicit ThreadListHeaderView(QWidget* parent = 0);
+
+    private:
+        void contextMenuEvent(QContextMenuEvent *event);
+
+    };
+}
+
+#endif

Modified: kita/branches/KITA-KDE4/kita/src/threadlistview.cpp
===================================================================
--- kita/branches/KITA-KDE4/kita/src/threadlistview.cpp	2009-07-18 07:54:35 UTC (rev 2425)
+++ kita/branches/KITA-KDE4/kita/src/threadlistview.cpp	2009-07-18 08:55:03 UTC (rev 2426)
@@ -10,14 +10,24 @@
 
 #include "threadlistview.h"
 
+#include <QtGui/QClipboard>
+#include <QtGui/QContextMenuEvent>
 #include <QtGui/QHeaderView>
 
+#include <kaction.h>
+#include <kmenu.h>
+#include <krun.h>
 #include <kurl.h>
 
 #include "threadlistheaderview.h"
 #include "threadlistviewitem.h"
+#include "ui_threadproperty.h"
 #include "viewmediator.h"
+#include "libkita/datmanager.h"
+#include "libkita/favoritethreads.h"
 #include "libkita/kita_misc.h"
+#include "libkita/threadindex.h"
+#include "libkita/threadinfo.h"
 
 using namespace Kita;
 
@@ -51,7 +61,6 @@
     ThreadListHeaderView* header = new ThreadListHeaderView;
 
     subjectList->setColumnCount(ColumnEnd - ColumnBegin + 1);
-    subjectList->setContextMenuPolicy(Qt::CustomContextMenu);
     subjectList->setHorizontalHeader(header);
     subjectList->setShowGrid(false);
     subjectList->setSortingEnabled(true);
@@ -178,4 +187,104 @@
     subjectList->showColumn(col);
 }
 
+void ThreadListView::contextMenuEvent(QContextMenuEvent *event)
+{
+    QTableWidgetItem* item = subjectList->itemAt(event->pos());
+    if (item == 0) {
+        return;
+    }
+
+    QString datURL = subjectList->item(item->row(), ColumnDatUrl)->text();
+    QString threadURL = DatManager::threadURL(datURL);
+    bool isFavorites = FavoriteThreads::getInstance()->contains(datURL);
+
+    // create popup menu.
+    KMenu popup(0);
+
+    KAction* openWithBrowserAct = new KAction(i18n("Open with Web Browser") , this);
+    popup.addAction(openWithBrowserAct);
+
+    KAction* copyURLAct = new KAction(i18n("Copy URL"), this);
+    popup.addAction(copyURLAct);
+
+    KAction* copyTitleAndURLAct = new KAction(i18n("Copy title and URL"), this);
+    popup.addAction(copyTitleAndURLAct);
+
+    KAction* favoritesAct;
+    if (isFavorites) {
+        favoritesAct = new KAction(i18n("Remove from Favorites"), this);
+    } else {
+        favoritesAct = new KAction(i18n("Add to Favorites"), this);
+    }
+    popup.addAction(favoritesAct);
+
+    KAction* deleteLogAct = 0;
+    if (DatManager::getReadNum(datURL)) {
+        popup.addSeparator();
+
+        deleteLogAct = new KAction(i18n("Delete Log"), this);
+        popup.addAction(deleteLogAct);
+    }
+    popup.addSeparator();
+
+    KAction* propertyAct = new KAction(i18n("Property"), this);
+    popup.addAction(propertyAct);
+
+    // exec popup menu.
+    QClipboard* clipboard = QApplication::clipboard();
+    QString cliptxt;
+
+    QAction* action = popup.exec(QCursor::pos());
+    if (!action) {
+        return;
+    }
+    if (action == openWithBrowserAct) {
+        KRun::runUrl(threadURL, "text/html", this);
+    } else if (action == copyURLAct) {
+        clipboard->setText(threadURL, QClipboard::Clipboard);
+        clipboard->setText(threadURL, QClipboard::Selection);
+    } else if (action == copyTitleAndURLAct) {
+        cliptxt = DatManager::threadName(datURL) + '\n' + threadURL;
+        clipboard->setText(cliptxt , QClipboard::Clipboard);
+        clipboard->setText(cliptxt , QClipboard::Selection);
+    } else if (action == favoritesAct) {
+        ViewMediator::getInstance()->bookmark(datURL, !isFavorites);
+    } else if (action == deleteLogAct) {
+        //deleteLog(threadURL); TODO
+    } else if (action == propertyAct) {
+            QWidget* widget = new QWidget;
+            Ui::ThreadProperty* propertyWidget
+                = new Ui::ThreadProperty;
+            propertyWidget->setupUi(widget);
+            propertyWidget->threadURLLabel->setText(threadURL);
+            propertyWidget->datURLLabel->setText(datURL);
+
+            propertyWidget->threadNameLabel
+                ->setText(DatManager::threadName(datURL));
+            propertyWidget->cachePathLabel
+                ->setText(DatManager::getCachePath(datURL));
+            propertyWidget->indexPathLabel
+                ->setText(DatManager::getCacheIndexPath(datURL));
+            propertyWidget->resNumLabel
+                ->setText(QString::number(DatManager::getResNum(datURL)));
+            propertyWidget->readNumLabel
+                ->setText(QString::number(DatManager::getReadNum(datURL)));
+            propertyWidget->viewPosLabel
+                ->setText(QString::number(DatManager::getViewPos(datURL)));
+
+            propertyWidget->idx_threadNameWithIndexLabel
+                ->setText(ThreadIndex::getSubject(datURL));
+            propertyWidget->idx_resNumLabel
+                ->setText(QString::number(ThreadIndex::getResNum(datURL)));
+            propertyWidget->idx_readNumLabel
+                ->setText(QString::number(ThreadIndex::getReadNum(datURL)));
+            propertyWidget->idx_viewPosLabel
+                ->setText(QString::number(ThreadIndex::getViewPos(datURL)));
+
+            propertyWidget->cache_readNumLabel
+                ->setText(QString::number(ThreadInfo::readNum(datURL)));
+            widget->show();
+    }
+}
+
 #include "threadlistview.moc"

Modified: kita/branches/KITA-KDE4/kita/src/threadlistview.h
===================================================================
--- kita/branches/KITA-KDE4/kita/src/threadlistview.h	2009-07-18 07:54:35 UTC (rev 2425)
+++ kita/branches/KITA-KDE4/kita/src/threadlistview.h	2009-07-18 08:55:03 UTC (rev 2426)
@@ -49,6 +49,7 @@
         void clearSearch();
         void hideColumn(int col);
         void showColumn(int col);
+        void contextMenuEvent(QContextMenuEvent* event);
 
     protected slots:
         void slotHideButton(bool on);




Kita-svn メーリングリストの案内
Back to archive index