1 /***************************************************************************
2 * Copyright (C) 2007 by Tarek Saidi *
3 * tarek.saidi@arcor.de *
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. *
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. *
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 ***************************************************************************/
21 #include <QTreeWidget>
23 #include <QPaintEvent>
24 #include <QResizeEvent>
26 #include "TrashCanDlg.h"
28 TrashCanDialog::TrashCanDialog(QWidget* parent,IDatabase* database,const QList<IEntryHandle*>& TrashItems):QDialog(parent){
31 for(int i=0;i<Entries.size();i++){
32 QTreeWidgetItem* item=new QTreeWidgetItem(treeWidget);
33 item->setData(0,Qt::UserRole,i);
34 item->setText(0,Entries[i]->group()->title());
35 item->setText(1,Entries[i]->title());
36 item->setText(2,Entries[i]->username());
37 item->setText(3,Entries[i]->expire().dateToString(Qt::LocalDate));
38 item->setIcon(0,database->icon(Entries[i]->group()->image()));
39 item->setIcon(1,database->icon(Entries[i]->image()));
42 connect(treeWidget,SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),this,SLOT(OnItemDoubleClicked(QTreeWidgetItem*)));
43 connect(treeWidget,SIGNAL(customContextMenuRequested(const QPoint&)),this,SLOT(OnContextMenu(const QPoint&)));
44 ContextMenu=new QMenu(this);
45 ContextMenu->addAction(getIcon("restore"),"Restore");
46 ContextMenu->addAction(getIcon("deleteentry"),"Delete");
50 void TrashCanDialog::paintEvent(QPaintEvent* event){
51 QDialog::paintEvent(event);
52 QPainter painter(this);
53 painter.setClipRegion(event->region());
54 painter.drawPixmap(QPoint(0,0),BannerPixmap);
57 void TrashCanDialog::resizeEvent(QResizeEvent* event){
58 createBanner(&BannerPixmap,getPixmap("trashcan"),tr("Recycle Bin"),width());
59 QDialog::resizeEvent(event);
62 void TrashCanDialog::OnItemDoubleClicked(QTreeWidgetItem* item){
63 SelectedEntry=Entries[item->data(0,Qt::UserRole).toInt()];
67 void TrashCanDialog::OnContextMenu(const QPoint& pos){
68 if(treeWidget->itemAt(pos)){
69 QTreeWidgetItem* item=treeWidget->itemAt(pos);
70 if(treeWidget->selectedItems().size()==0){
71 treeWidget->setItemSelected(item,true);
74 if(!treeWidget->isItemSelected(item)){
75 while(treeWidget->selectedItems().size()){
76 treeWidget->setItemSelected(treeWidget->selectedItems()[0],false);
78 treeWidget->setItemSelected(item,true);
84 while(treeWidget->selectedItems().size())
85 treeWidget->setItemSelected(treeWidget->selectedItems()[0],false);
87 ContextMenu->popup(treeWidget->viewport()->mapToGlobal(pos));
92 ///TODO 0.2.3 locale aware string/date compare for correct sorting