From baac763ff0501f79892efad228b5e3ee6f16daf1 Mon Sep 17 00:00:00 2001 From: tariq Date: Sun, 2 Apr 2006 02:16:47 +0000 Subject: [PATCH] work on custom icons feature git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@67 b624d157-de02-0410-bad0-e51aec6abb33 --- src/Database.h | 2 +- src/PwManager.cpp | 1 + src/PwManager.h | 5 +- src/dialogs/EditGroupDlg.cpp | 9 +- src/dialogs/SelectIconDlg.cpp | 39 +++++++- src/dialogs/SelectIconDlg.h | 12 +++ src/forms/SelectIconDlg.ui | 183 +++++++++++++++++----------------- src/mainwindow.cpp | 1 + 8 files changed, 154 insertions(+), 98 deletions(-) diff --git a/src/Database.h b/src/Database.h index 8e25088..0942847 100644 --- a/src/Database.h +++ b/src/Database.h @@ -77,7 +77,7 @@ static bool UI_ExpandByDefault; #define ALGO_AES 0 #define ALGO_TWOFISH 1 -class Database{ +class Database:public QObject{ public: Database(); virtual ~Database(){}; diff --git a/src/PwManager.cpp b/src/PwManager.cpp index bf72406..106c3c0 100755 --- a/src/PwManager.cpp +++ b/src/PwManager.cpp @@ -343,6 +343,7 @@ return CustomIcons[i-BUILTIN_ICONS]; void PwDatabase::addIcon(const QPixmap& icon){ CustomIcons << icon; +emit modified(); } diff --git a/src/PwManager.h b/src/PwManager.h index 16730b9..1bb3684 100755 --- a/src/PwManager.h +++ b/src/PwManager.h @@ -41,7 +41,7 @@ #include "Database.h" -class PwDatabase:QObject,public Database{ +class PwDatabase:public Database{ Q_OBJECT public: PwDatabase(); @@ -102,6 +102,9 @@ private: QList CustomIcons; QList UnkownMetaStreams; +signals: +void modified(); + }; diff --git a/src/dialogs/EditGroupDlg.cpp b/src/dialogs/EditGroupDlg.cpp index f3e31b8..1559c0e 100755 --- a/src/dialogs/EditGroupDlg.cpp +++ b/src/dialogs/EditGroupDlg.cpp @@ -67,5 +67,12 @@ done(0); void CEditGroupDialog::OnIconDlg(){ CSelectIconDlg dlg(db,this); -dlg.exec(); +int r=dlg.exec(); +if(r!=-1){ + ComboIconPicker->clear(); + for(int i=0;inumIcons();i++) + ComboIconPicker->insertItem(db->icon(i),"",i); + IconID=r; + ComboIconPicker->setCurrentItem(IconID); +} } diff --git a/src/dialogs/SelectIconDlg.cpp b/src/dialogs/SelectIconDlg.cpp index 59d6049..b450608 100644 --- a/src/dialogs/SelectIconDlg.cpp +++ b/src/dialogs/SelectIconDlg.cpp @@ -31,14 +31,24 @@ CSelectIconDlg::CSelectIconDlg(Database* database,QWidget* parent,const char* name, bool modal, Qt::WFlags fl):QDialog(parent,name,modal,fl){ setupUi(this); db=database; - connect(Button_AddIcon, SIGNAL(clicked()), this, SLOT(OnAddIcon())); +connect(Button_PickIcon, SIGNAL(clicked()), this, SLOT(OnPickIcon())); +connect(Button_Cancel, SIGNAL(clicked()), this, SLOT(OnCancel())); +CtxMenu=new QMenu(this); +DeleteAction=CtxMenu->addAction(*Icon_EditDelete,tr("Delete")); +CustomIconsModified=false; +updateView(); +} +void CSelectIconDlg::updateView(){ +List->clear(); for(int i=0; inumIcons(); i++){ + QListWidgetItem* item; if(iaddItem(new QListWidgetItem(QIcon(db->icon(i)),QString::number(i))); + List->addItem(item=new QListWidgetItem(QIcon(db->icon(i)),QString::number(i))); else - List->addItem(new QListWidgetItem(QIcon(db->icon(i)),"["+QString::number(i)+"]")); + List->addItem(item=new QListWidgetItem(QIcon(db->icon(i)),"["+QString::number(i)+"]")); + item->setData(32,i); } } @@ -55,4 +65,27 @@ for(int i=0;iitemAt(List->mapFromParent(event->pos())); + +if(!item)return; +if(item->data(32).toInt()setDisabled(true); +else + DeleteAction->setDisabled(false); +event->accept(); +CtxMenu->popup(event->globalPos()); +} + +void CSelectIconDlg::OnPickIcon(){ +done(List->currentItem()->data(32).toInt()); +} + +void CSelectIconDlg::OnCancel(){ +done(-1); } \ No newline at end of file diff --git a/src/dialogs/SelectIconDlg.h b/src/dialogs/SelectIconDlg.h index 23e640f..ada7199 100644 --- a/src/dialogs/SelectIconDlg.h +++ b/src/dialogs/SelectIconDlg.h @@ -21,6 +21,9 @@ #ifndef _SELECT_ICON_DLG_ #define _SELECT_ICON_DLG_ +#include +#include +#include #include "main.h" #include "Database.h" #include "ui_SelectIconDlg.h" @@ -29,13 +32,22 @@ class CSelectIconDlg:public QDialog, public Ui_SelectIconDlg{ Q_OBJECT public: CSelectIconDlg(Database* db,QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WFlags fl = 0); + bool CustomIconsModified; public slots: void OnAddIcon(); + void OnPickIcon(); + void OnCancel(); + private: Database* db; + void updateView(); + QMenu* CtxMenu; + QAction* DeleteAction; +protected: + virtual void contextMenuEvent(QContextMenuEvent *event); }; diff --git a/src/forms/SelectIconDlg.ui b/src/forms/SelectIconDlg.ui index 7fede46..a8e978f 100644 --- a/src/forms/SelectIconDlg.ui +++ b/src/forms/SelectIconDlg.ui @@ -8,105 +8,104 @@ 0 0 - 468 - 272 + 478 + 280 + + + 5 + 5 + 0 + 0 + + Dialog - - - - 10 - 10 - 451 - 211 - - - - Qt::ScrollBarAlwaysOff - - - QAbstractItemView::ExtendedSelection - - - - 16 - 16 - - - - Qt::ElideRight - - - QListView::Static - - - QListView::LeftToRight - - - - 32 - 44 - - - - QListView::IconMode + + + 9 - - - - - 10 - 230 - 451 - 33 - + + 6 - - - 0 - - - 6 - - - - - Add Custom Icon... - - - - - - - Qt::Horizontal - - - - 131 - 31 - - - - - - - - Pick - - - - - - - Cancel - - - - - + + + + 0 + + + 6 + + + + + Add Custom Icon... + + + + + + + Pick + + + + + + + Cancel + + + + + + + Qt::Horizontal + + + + 131 + 31 + + + + + + + + + 16 + 16 + + + + QListView::Static + + + QListView::LeftToRight + + + true + + + QListView::Adjust + + + + 32 + 44 + + + + QListView::IconMode + + + + + + diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index ab7fcd4..082db63 100755 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -267,6 +267,7 @@ Q_ASSERT(r==1); db = new PwDatabase(); GroupView->db=db; EntryView->db=db; +connect(db,SIGNAL(modified()),this,SLOT(OnFileModified())); if(PasswordDlg.password!="" && PasswordDlg.keyfile=="") db->CalcMasterKeyByPassword(PasswordDlg.password); if(PasswordDlg.password=="" && PasswordDlg.keyfile!="")