[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    =?utf-8?q?=5Bknipptasch=5D_/=3A_Move_CategoryComboBox_from_gui/_?=
From:       Stefan_Böhmann <kde () hilefoks ! org>
Date:       2011-01-31 23:37:23
Message-ID: 20110131233723.34502A60CE () git ! kde ! org
[Download RAW message or body]

Git commit 9253b28d599bbc31c2066ab25491177619b76d0e by Stefan Böhmann.
Pushed by sboehmann into branch 'master'.

Move CategoryComboBox from gui/ to core/widgets

M  +2    -0    core/CMakeLists.txt     
A  +1    -0    core/include/Knipptasch/CategoryComboBox         [License: UNKNOWN]
A  +223  -0    core/widgets/categorycombobox.cpp         [License: GPL (v2+)]
A  +77   -0    core/widgets/categorycombobox.h         [License: GPL (v2+)]
M  +0    -2    gui/CMakeLists.txt     
D  +0    -226  gui/categorycombobox.cpp     
D  +0    -75   gui/categorycombobox.h     
M  +9    -4    gui/delegate/categorydelegate.cpp     

http://commits.kde.org/knipptasch/9253b28d599bbc31c2066ab25491177619b76d0e

diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt
index 053f74a..e06a3a2 100644
--- a/core/CMakeLists.txt
+++ b/core/CMakeLists.txt
@@ -26,6 +26,7 @@ set( knipptasch_core_SOURCES
     widgets/dateedit.cpp
     widgets/datevalidator.cpp
     widgets/datepickerpopup.cpp
+    widgets/categorycombobox.cpp
 
     backend/object.cpp
     backend/category.cpp
@@ -53,6 +54,7 @@ set( knipptasch_core_HEADERS
     widgets/dateedit.h
     widgets/datevalidator.h
     widgets/datepickerpopup.h
+    widgets/categorycombobox.h
 
     backend/object.h
     backend/category.h
diff --git a/core/include/Knipptasch/CategoryComboBox \
b/core/include/Knipptasch/CategoryComboBox new file mode 100644
index 0000000..0318436
--- /dev/null
+++ b/core/include/Knipptasch/CategoryComboBox
@@ -0,0 +1 @@
+#include "widgets/categorycombobox.h"
diff --git a/core/widgets/categorycombobox.cpp b/core/widgets/categorycombobox.cpp
new file mode 100644
index 0000000..d588d06
--- /dev/null
+++ b/core/widgets/categorycombobox.cpp
@@ -0,0 +1,223 @@
+/*
+ * Copyright 2010, 2011 by Stefan Böhmann <kde@hilefoks.org>
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#include "categorycombobox.h"
+
+#include "backend/account.h"
+#include "backend/category.h"
+
+#include <QMouseEvent>
+#include <QTreeView>
+#include <QHeaderView>
+#include <QStandardItemModel>
+#include <QStandardItem>
+#include <QLineEdit>
+#include <QPainter>
+
+
+
+CategoryComboBox::CategoryComboBox(const Account *account, QWidget* parent)
+  : KComboBox( parent ),
+    m_view( new QTreeView( this ) ),
+    m_model( new QStandardItemModel( this ) ),
+    m_account( 0 ),
+    m_skipNextHide( false ),
+    m_selectedCategory( -1 )
+{
+    m_view->header()->hide();
+    m_view->setRootIsDecorated( false );
+    m_view->setAnimated( true );
+    m_view->setUniformRowHeights( true );
+    m_view->setEditTriggers( QAbstractItemView::NoEditTriggers );
+    m_view->setSelectionBehavior( QAbstractItemView::SelectRows );
+
+    setView( m_view );
+    setModel( m_model );
+
+    view()->viewport()->installEventFilter( this );
+
+    setAccount( account );
+}
+
+
+const Account* CategoryComboBox::account() const
+{
+    return m_account;
+}
+
+
+void CategoryComboBox::setAccount(const Account *account)
+{
+    Q_ASSERT( m_model );
+
+    m_selectedCategory = -1;
+    m_account = account;
+
+    m_items.clear();
+    m_model->clear();
+
+    if( !m_account ) {
+        return;
+    }
+
+    Q_ASSERT( m_account->rootCategory() );
+
+    QStandardItem *item = new QStandardItem( tr( "None" ) );
+    item->setData( -1, Qt::UserRole );
+
+    for(int i = 0; i < m_account->rootCategory()->countCategories(); ++i) {
+        addCategory( item, m_account->rootCategory()->category( i ) );
+    }
+
+    m_model->appendRow( item );
+    m_items.insert( item );
+
+    m_view->expandToDepth( 3 );
+}
+
+
+const Category* CategoryComboBox::selectedCategory() const
+{
+    Object *object = account()->objectByIdentifier( m_selectedCategory );
+    if( object ) {
+        Category *category = qobject_cast<Category*>( object );
+        Q_ASSERT( category );
+
+        return category;
+    }
+
+    return 0;
+}
+
+
+Category* CategoryComboBox::selectedCategory()
+{
+    Object *object = account()->objectByIdentifier( m_selectedCategory );
+    if( object ) {
+        Category *category = qobject_cast<Category*>( object );
+        Q_ASSERT( category );
+
+        return category;
+    }
+
+    return 0;
+}
+
+
+void CategoryComboBox::setSelectedCategory(const Category *category)
+{
+    m_selectedCategory = account()->identifierByObject( category );
+}
+
+
+bool CategoryComboBox::eventFilter(QObject *object, QEvent *event)
+{
+    if( event->type() == QEvent::MouseButtonPress ) {
+        if( object == view()->viewport() ) {
+            QMouseEvent* mouseEvent = static_cast<QMouseEvent*>( event );
+
+            QModelIndex index = view()->indexAt( mouseEvent->pos() );
+            if( !view()->visualRect( index ).contains( mouseEvent->pos() ) ) {
+                m_skipNextHide = true;
+            }
+        }
+    }
+
+    return false;
+}
+
+
+void CategoryComboBox::showPopup()
+{
+    QModelIndex index;
+    if( m_selectedCategory >= 0 ) {
+        foreach(QStandardItem *item, m_items) {
+            bool ok;
+            int itemid = item->data( Qt::UserRole ).toInt( &ok );
+            Q_ASSERT( ok );
+
+            if( itemid == m_selectedCategory ) {
+                index = m_model->indexFromItem( item );
+                Q_ASSERT( index.isValid() );
+
+                break;
+            }
+        }
+    }
+
+    QComboBox::showPopup();
+
+    m_view->setCurrentIndex( index );
+    m_view->scrollTo( index );
+}
+
+
+void CategoryComboBox::hidePopup()
+{
+    if( m_skipNextHide ) {
+        m_skipNextHide = false;
+        return;
+    }
+
+    if( m_view->currentIndex().isValid() ) {
+        bool ok;
+        int id = m_model->itemFromIndex( m_view->currentIndex() )
+                        ->data( Qt::UserRole ).toInt( &ok );
+        Q_ASSERT( ok );
+
+        m_selectedCategory = id;
+    }
+
+    QComboBox::hidePopup();
+}
+
+
+void CategoryComboBox::addCategory(QStandardItem *parent, const Category *cat)
+{
+    Q_ASSERT( parent );
+    Q_ASSERT( cat );
+
+    QStandardItem *item = new QStandardItem( renderCategoryIcon( cat ), cat->name() \
); +    item->setData( account()->identifierByObject( cat ), Qt::UserRole );
+
+    parent->appendRow( item );
+    m_items.insert( item );
+
+    for(int i = 0; i < cat->countCategories(); ++i) {
+        addCategory( item, cat->category( i ) );
+    }
+}
+
+
+QIcon CategoryComboBox::renderCategoryIcon(const Category *category)
+{
+    if( category && category->color().isValid() ) {
+        QPixmap pix( 128, 128 );
+
+        QPainter painter( &pix );
+        painter.setPen( QPen( palette().color( QPalette::Dark ), 10 ) );
+        painter.setBrush( category->color() );
+        painter.drawRect( pix.rect() );
+
+        return QIcon( pix );
+    }
+
+    return QIcon();
+}
+
+
+// kate: word-wrap off; encoding utf-8; indent-width 4; tab-width 4; line-numbers \
on; mixed-indent off; remove-trailing-space-save on; replace-tabs-save on; \
replace-tabs on; space-indent on; +// vim:set spell et sw=4 ts=4 nowrap \
                cino=l1,cs,U1:
diff --git a/core/widgets/categorycombobox.h b/core/widgets/categorycombobox.h
new file mode 100644
index 0000000..dfccb9c
--- /dev/null
+++ b/core/widgets/categorycombobox.h
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2010, 2011 by Stefan Böhmann <kde@hilefoks.org>
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef CATEGORYCOMBOBOX_H
+#define CATEGORYCOMBOBOX_H
+
+#include "knipptasch_core_export.h"
+
+#include <KComboBox>
+#include <QSet>
+
+class QTreeView;
+class QEvent;
+class QStandardItem;
+class QStandardItemModel;
+class QStandardItem;
+
+class Category;
+class Account;
+
+
+/**
+ * @class CategoryComboBox
+ * @brief
+ *
+ * @author Stefan Böhmann <kde@hilefoks.org>
+ */
+class KNIPPTASCH_CORE_EXPORT CategoryComboBox : public KComboBox
+{
+    Q_OBJECT
+
+    public:
+        CategoryComboBox(const Account *account, QWidget *parent = 0);
+
+        const Account* account() const;
+        void setAccount(const Account *account);
+
+        const Category* selectedCategory() const;
+        Category* selectedCategory();
+        void setSelectedCategory(const Category *category);
+
+        bool eventFilter(QObject *object, QEvent *event);
+
+        void showPopup();
+        void hidePopup();
+
+    private:
+        void addCategory(QStandardItem *parent, const Category *category);
+        QIcon renderCategoryIcon(const Category *category);
+
+    private:
+        QTreeView *m_view;
+        QStandardItemModel *m_model;
+        QSet<QStandardItem*> m_items;
+        const Account *m_account;
+        bool m_skipNextHide;
+        int m_selectedCategory;
+};
+
+
+#endif
+
+// kate: word-wrap off; encoding utf-8; indent-width 4; tab-width 4; line-numbers \
on; mixed-indent off; remove-trailing-space-save on; replace-tabs-save on; \
replace-tabs on; space-indent on; +// vim:set spell et sw=4 ts=4 nowrap \
                cino=l1,cs,U1:
diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt
index 90db1e1..82a9374 100644
--- a/gui/CMakeLists.txt
+++ b/gui/CMakeLists.txt
@@ -10,7 +10,6 @@ set(knipptasch_SOURCES
     quickreportpopup.cpp
     quickreportwidget.cpp
     passworddialog.cpp
-    categorycombobox.cpp
     main.cpp
 
     config/configdialog.cpp
@@ -45,7 +44,6 @@ set( knipptasch_HEADERS
     quickreportpopup.h
     quickreportwidget.h
     passworddialog.h
-    categorycombobox.h
 
     config/configdialog.h
     config/configwidget.h
diff --git a/gui/categorycombobox.cpp b/gui/categorycombobox.cpp
deleted file mode 100644
index 0906612..0000000
--- a/gui/categorycombobox.cpp
+++ /dev/null
@@ -1,226 +0,0 @@
-/*
- * Copyright 2010  Stefan Böhmann <kde@hilefoks.org>
- *
- * 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.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-#include "categorycombobox.h"
-
-#include "backend/account.h"
-#include "backend/category.h"
-#include "preferences.h"
-
-#include <QMouseEvent>
-#include <QTreeView>
-#include <QHeaderView>
-#include <QStandardItemModel>
-#include <QStandardItem>
-#include <QLineEdit>
-#include <QPainter>
-
-#include <QDebug>
-
-
-CategoryComboBox::CategoryComboBox(const Account *account, QWidget* parent)
-  : KComboBox( parent ),
-    m_view( new QTreeView( this ) ),
-    m_model( new QStandardItemModel( this ) ),
-    m_account( 0 ),
-    m_skipNextHide( false ),
-    m_selectedCategory( -1 )
-{
-    m_view->header()->hide();
-    m_view->setMinimumSize( Preferences::self()->minimumCategoryComboBoxPopupSize() \
                );
-    m_view->setRootIsDecorated( false );
-    m_view->setAnimated( true );
-    m_view->setUniformRowHeights( true );
-    m_view->setEditTriggers( QAbstractItemView::NoEditTriggers );
-    m_view->setSelectionBehavior( QAbstractItemView::SelectRows );
-
-    setView( m_view );
-    setModel( m_model );
-
-    view()->viewport()->installEventFilter( this );
-
-    setAccount( account );
-}
-
-
-const Account* CategoryComboBox::account() const
-{
-    return m_account;
-}
-
-
-void CategoryComboBox::setAccount(const Account *account)
-{
-    Q_ASSERT( m_model );
-
-    m_selectedCategory = -1;
-    m_account = account;
-
-    m_items.clear();
-    m_model->clear();
-
-    if( !m_account ) {
-        return;
-    }
-
-    Q_ASSERT( m_account->rootCategory() );
-
-    QStandardItem *item = new QStandardItem( tr( "None" ) );
-    item->setData( -1, Qt::UserRole );
-
-    for(int i = 0; i < m_account->rootCategory()->countCategories(); ++i) {
-        addCategory( item, m_account->rootCategory()->category( i ) );
-    }
-
-    m_model->appendRow( item );
-    m_items.insert( item );
-
-    m_view->expandToDepth( 3 );
-}
-
-
-const Category* CategoryComboBox::selectedCategory() const
-{
-    Object *object = account()->objectByIdentifier( m_selectedCategory );
-    if( object ) {
-        Category *category = qobject_cast<Category*>( object );
-        Q_ASSERT( category );
-
-        return category;
-    }
-
-    return 0;
-}
-
-
-Category* CategoryComboBox::selectedCategory()
-{
-    Object *object = account()->objectByIdentifier( m_selectedCategory );
-    if( object ) {
-        Category *category = qobject_cast<Category*>( object );
-        Q_ASSERT( category );
-
-        return category;
-    }
-
-    return 0;
-}
-
-
-void CategoryComboBox::setSelectedCategory(const Category *category)
-{
-    m_selectedCategory = account()->identifierByObject( category );
-}
-
-
-bool CategoryComboBox::eventFilter(QObject *object, QEvent *event)
-{
-    if( event->type() == QEvent::MouseButtonPress ) {
-        if( object == view()->viewport() ) {
-            QMouseEvent* mouseEvent = static_cast<QMouseEvent*>( event );
-
-            QModelIndex index = view()->indexAt( mouseEvent->pos() );
-            if( !view()->visualRect( index ).contains( mouseEvent->pos() ) ) {
-                m_skipNextHide = true;
-            }
-        }
-    }
-
-    return false;
-}
-
-
-void CategoryComboBox::showPopup()
-{
-    QModelIndex index;
-    if( m_selectedCategory >= 0 ) {
-        foreach(QStandardItem *item, m_items) {
-            bool ok;
-            int itemid = item->data( Qt::UserRole ).toInt( &ok );
-            Q_ASSERT( ok );
-
-            if( itemid == m_selectedCategory ) {
-                index = m_model->indexFromItem( item );
-                Q_ASSERT( index.isValid() );
-
-                break;
-            }
-        }
-    }
-
-    QComboBox::showPopup();
-
-    m_view->setCurrentIndex( index );
-    m_view->scrollTo( index );
-}
-
-
-void CategoryComboBox::hidePopup()
-{
-    if( m_skipNextHide ) {
-        m_skipNextHide = false;
-        return;
-    }
-
-    if( m_view->currentIndex().isValid() ) {
-        bool ok;
-        int id = m_model->itemFromIndex( m_view->currentIndex() )
-                        ->data( Qt::UserRole ).toInt( &ok );
-        Q_ASSERT( ok );
-
-        m_selectedCategory = id;
-    }
-
-    QComboBox::hidePopup();
-}
-
-
-void CategoryComboBox::addCategory(QStandardItem *parent, const Category *cat)
-{
-    Q_ASSERT( parent );
-    Q_ASSERT( cat );
-
-    QStandardItem *item = new QStandardItem( renderCategoryIcon( cat ), cat->name() \
                );
-    item->setData( account()->identifierByObject( cat ), Qt::UserRole );
-
-    parent->appendRow( item );
-    m_items.insert( item );
-
-    for(int i = 0; i < cat->countCategories(); ++i) {
-        addCategory( item, cat->category( i ) );
-    }
-}
-
-
-QIcon CategoryComboBox::renderCategoryIcon(const Category *category)
-{
-    if( category && category->color().isValid() ) {
-        QPixmap pix( 128, 128 );
-
-        QPainter painter( &pix );
-        painter.setPen( QPen( palette().color( QPalette::Dark ), 10 ) );
-        painter.setBrush( category->color() );
-        painter.drawRect( pix.rect() );
-
-        return QIcon( pix );
-    }
-
-    return QIcon();
-}
-
-
-// kate: word-wrap off; encoding utf-8; indent-width 4; tab-width 4; line-numbers \
on; mixed-indent off; remove-trailing-space-save on; replace-tabs-save on; \
                replace-tabs on; space-indent on;
-// vim:set spell et sw=4 ts=4 nowrap cino=l1,cs,U1:
diff --git a/gui/categorycombobox.h b/gui/categorycombobox.h
deleted file mode 100644
index 99716ad..0000000
--- a/gui/categorycombobox.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright 2010 by Stefan Böhmann <kde@hilefoks.org>
- *
- * 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.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-#ifndef CATEGORYCOMBOBOX_H
-#define CATEGORYCOMBOBOX_H
-
-#include <KComboBox>
-#include <QSet>
-
-class QTreeView;
-class QEvent;
-class QStandardItem;
-class QStandardItemModel;
-class QStandardItem;
-
-class Category;
-class Account;
-
-
-/**
- * @class CategoryComboBox
- * @brief
- *
- * @author Stefan Böhmann <kde@hilefoks.org>
- */
-class CategoryComboBox : public KComboBox
-{
-    Q_OBJECT
-
-    public:
-        CategoryComboBox(const Account *account, QWidget *parent = 0);
-
-        const Account* account() const;
-        void setAccount(const Account *account);
-
-        const Category* selectedCategory() const;
-        Category* selectedCategory();
-        void setSelectedCategory(const Category *category);
-
-        bool eventFilter(QObject *object, QEvent *event);
-
-        void showPopup();
-        void hidePopup();
-
-    private:
-        void addCategory(QStandardItem *parent, const Category *category);
-        QIcon renderCategoryIcon(const Category *category);
-
-    private:
-        QTreeView *m_view;
-        QStandardItemModel *m_model;
-        QSet<QStandardItem*> m_items;
-        const Account *m_account;
-        bool m_skipNextHide;
-        int m_selectedCategory;
-};
-
-
-#endif
-
-// kate: word-wrap off; encoding utf-8; indent-width 4; tab-width 4; line-numbers \
on; mixed-indent off; remove-trailing-space-save on; replace-tabs-save on; \
                replace-tabs on; space-indent on;
-// vim:set spell et sw=4 ts=4 nowrap cino=l1,cs,U1:
diff --git a/gui/delegate/categorydelegate.cpp b/gui/delegate/categorydelegate.cpp
index b76b1c1..adc2ed8 100644
--- a/gui/delegate/categorydelegate.cpp
+++ b/gui/delegate/categorydelegate.cpp
@@ -15,17 +15,21 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 #include "categorydelegate.h"
-#include "categorycombobox.h"
 
-#include "backend/account.h"
-#include "backend/posting.h"
-#include "backend/category.h"
+#include <Knipptasch/CategoryComboBox>
+
+#include <Knipptasch/Account>
+#include <Knipptasch/Posting>
+#include <Knipptasch/Category>
 
 #include "accountsortfilterproxymodel.h"
 
+#include "preferences.h"
+
 #include <QPainter>
 #include <QApplication>
 #include <QStandardItemModel>
+#include <QAbstractItemView>
 
 
 
@@ -46,6 +50,7 @@ QWidget* CategoryDelegate::createEditor(QWidget *parent, const \
QStyleOptionViewI  
     CategoryComboBox *input = new CategoryComboBox( model->account(), parent );
     input->setFrame( false );
+    input->view()->setMinimumSize( \
Preferences::self()->minimumCategoryComboBoxPopupSize() );  
     return input;
 }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic