Initial commit
[keepassx] / src / lib / GroupView.h
1 /***************************************************************************
2  *   Copyright (C) 2005 by Tarek Saidi                                     *
3  *   tarek.saidi@arcor.de                                                  *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; version 2 of the License.               *
8
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #ifndef _GROUP_VIEW_H_
22 #define _GROUP_VIEW_H_
23
24 #include "Kdb3Database.h"
25
26 class GroupViewItem;
27
28 class KeepassGroupView:public QTreeWidget{
29         Q_OBJECT
30         public:
31                 KeepassGroupView(QWidget* parent=0);
32                 IDatabase *db;
33                 QList<GroupViewItem*>Items;
34                 QMenu *ContextMenu;
35                 QMenu *ContextMenuSearchGroup;
36                 GroupViewItem* SearchResultItem;
37                 void createItems();
38                 void showSearchResults();
39                 void setCurrentGroup(IGroupHandle* group);
40                 void selectFirstGroup();
41                 void retranslateUi();
42         
43         public slots:
44                 void createGroup(const QString& title, quint32 image, GroupViewItem* group=NULL);
45                 
46         private:
47                 virtual void dragEnterEvent(QDragEnterEvent* event);
48                 virtual void dragMoveEvent(QDragMoveEvent* event);
49                 void entryDragMoveEvent(QDragMoveEvent* event);
50                 virtual void dragLeaveEvent(QDragLeaveEvent* event);
51                 virtual void dropEvent(QDropEvent* event);
52                 void entryDropEvent(QDropEvent* event);
53                 virtual void mousePressEvent(QMouseEvent *event);
54                 virtual void mouseMoveEvent(QMouseEvent *event);
55                 virtual void paintEvent (QPaintEvent* event);
56                 virtual void contextMenuEvent(QContextMenuEvent* event);
57                 void addChildren(GroupViewItem* item);
58                 QPoint DragStartPos;
59                 GroupViewItem* DragItem;
60                 GroupViewItem* LastHoverItem;
61                 int InsLinePos;
62                 int InsLineStart;
63                 enum GroupViewDragType{EntryDrag,GroupDrag};
64                 GroupViewDragType DragType;
65                 QList<QTreeWidgetItem*>* EntryDragItems;
66         
67         private slots:
68                 void OnCurrentGroupChanged(QTreeWidgetItem*);
69                 void OnDeleteGroup();
70                 void OnNewGroup();
71                 void OnNewSubgroup();
72                 void OnEditGroup();
73                 void updateIcons();
74                 void OnHideSearchResults();
75                 void OnItemExpanded(QTreeWidgetItem*);
76                 void OnItemCollapsed(QTreeWidgetItem*);
77                 void OnSort();
78                 
79         signals:
80                 void groupChanged(IGroupHandle* NewGroup);
81                 void searchResultsSelected();
82                 void fileModified();
83                 void entriesDropped();
84 };
85
86
87 class GroupViewItem:public QTreeWidgetItem{
88         public:
89                 GroupViewItem();
90                 GroupViewItem(QTreeWidget *parent);
91                 GroupViewItem(QTreeWidget *parent, QTreeWidgetItem * preceding);
92                 GroupViewItem(QTreeWidgetItem *parent);
93                 GroupViewItem(QTreeWidgetItem *parent, QTreeWidgetItem * preceding);
94                 bool operator<(const QTreeWidgetItem& other) const;
95                 IGroupHandle* GroupHandle;
96 };
97
98
99
100 #endif