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. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18 ***************************************************************************/
21 #include "dialogs/ManageBookmarksDlg.h"
22 #include "dialogs/AddBookmarkDlg.h"
24 ManageBookmarksDlg::ManageBookmarksDlg(QWidget* parent):QDialog(parent)
28 for(int i=0;i<KpxBookmarks::count();i++){
29 QListWidgetItem* item=new QListWidgetItem(ListWidget);
30 item->setData(Qt::UserRole,i);
31 item->setText(KpxBookmarks::title(i));
33 connect(Button_Add,SIGNAL(clicked()),this,SLOT(OnButtonAdd()));
34 connect(Button_Edit,SIGNAL(clicked()),this,SLOT(OnButtonEdit()));
35 connect(Button_Delete,SIGNAL(clicked()),this,SLOT(OnButtonDelete()));
36 connect(Button_Up,SIGNAL(clicked()),this,SLOT(OnButtonUp()));
37 connect(Button_Down,SIGNAL(clicked()),this,SLOT(OnButtonDown()));
38 connect(ListWidget,SIGNAL(itemDoubleClicked(QListWidgetItem*)),this,SLOT(edit(QListWidgetItem*)));
39 connect(buttonBox->button(QDialogButtonBox::Close),SIGNAL(clicked()),this,SLOT(close()));
41 Button_Add->setIcon(getIcon("bookmark_add"));
42 Button_Edit->setIcon(getIcon("bookmark_edit"));
43 Button_Delete->setIcon(getIcon("bookmark_del"));
44 Button_Up->setIcon(getIcon("up"));
45 Button_Down->setIcon(getIcon("down"));
48 void ManageBookmarksDlg::paintEvent(QPaintEvent *event){
49 QDialog::paintEvent(event);
50 QPainter painter(this);
51 painter.setClipRegion(event->region());
52 painter.drawPixmap(QPoint(0,0),BannerPixmap);
55 void ManageBookmarksDlg::resizeEvent(QResizeEvent* event){
56 createBanner(&BannerPixmap,getPixmap("bookmark"),tr("Manage Bookmarks"),width());
57 QDialog::resizeEvent(event);
60 void ManageBookmarksDlg::OnButtonAdd(){
61 AddBookmarkDlg dlg(this);
64 QListWidgetItem* item=new QListWidgetItem(ListWidget);
65 item->setData(Qt::UserRole,i);
66 item->setText(KpxBookmarks::title(i));
71 void ManageBookmarksDlg::OnButtonEdit(){
72 QListWidgetItem* item=ListWidget->currentItem();
77 void ManageBookmarksDlg::OnButtonDelete(){
78 QListWidgetItem* item=ListWidget->currentItem();
80 int index=item->data(Qt::UserRole).toInt();
81 KpxBookmarks::remove(index);
83 for(int i=0;i<ListWidget->count();i++){
84 int itemindex=ListWidget->item(i)->data(Qt::UserRole).toInt();
86 ListWidget->item(i)->setData(Qt::UserRole,itemindex-1);
91 void ManageBookmarksDlg::OnButtonUp(){
92 int row=ListWidget->currentRow();
93 QListWidgetItem* item=ListWidget->currentItem();
94 if(row==-1 || !item || row==0)return;
95 ListWidget->takeItem(row);
97 ListWidget->insertItem(row,item);
98 ListWidget->setCurrentRow(row);
101 void ManageBookmarksDlg::OnButtonDown(){
102 int row=ListWidget->currentRow();
103 QListWidgetItem* item=ListWidget->currentItem();
104 if(row==-1 || !item || row==ListWidget->count()-1)return;
105 ListWidget->takeItem(row);
107 ListWidget->insertItem(row,item);
108 ListWidget->setCurrentRow(row);
113 void ManageBookmarksDlg::edit(QListWidgetItem* item){
114 int i=item->data(Qt::UserRole).toInt();
115 AddBookmarkDlg dlg(this,QString(),i);
117 item->setText(KpxBookmarks::title(i));
122 void ManageBookmarksDlg::closeEvent(QCloseEvent * event){
124 // Creating a list with the new indices
125 // Order[OldIndex]==NewIndex
126 for(int i=0;i<KpxBookmarks::count();i++){
127 Order<<ListWidget->item(i)->data(Qt::UserRole).toInt();
129 KpxBookmarks::resort(Order);