From 69c3c401ddfedf91fd43d5d8efe107e629a0a07b Mon Sep 17 00:00:00 2001 From: tariq Date: Wed, 8 Feb 2006 18:38:05 +0000 Subject: [PATCH] event handler for MainWindow X-Button git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@39 b624d157-de02-0410-bad0-e51aec6abb33 --- src/lib/GroupView.cpp | 2 +- src/lib/GroupView.h | 9 ++++++--- src/mainwindow.cpp | 14 +++++++++++++- src/mainwindow.h | 3 ++- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/lib/GroupView.cpp b/src/lib/GroupView.cpp index 29e51a5..d61fd69 100644 --- a/src/lib/GroupView.cpp +++ b/src/lib/GroupView.cpp @@ -111,13 +111,13 @@ update(); void KeepassGroupView::dropEvent( QDropEvent * event ){ +emit fileModified(); InsertionMarker=QLine(); if(LastHoverItem){ QFont f=LastHoverItem->font(0); f.setBold(false); LastHoverItem->setFont(0,f); LastHoverItem=NULL; - } GroupViewItem* item=(GroupViewItem*)itemAt(event->pos()); if(item){ diff --git a/src/lib/GroupView.h b/src/lib/GroupView.h index 967c787..b5fbe29 100644 --- a/src/lib/GroupView.h +++ b/src/lib/GroupView.h @@ -21,12 +21,14 @@ #define _GROUP_VIEW_H_ #include +#include #include "../PwManager.h" class GroupViewItem; typedef vector::iterator GroupItemItr; class KeepassGroupView:public QTreeWidget{ +Q_OBJECT public: KeepassGroupView(QWidget* parent=0); void updateItems(); @@ -35,6 +37,10 @@ public: PwDatabase *db; bool ShowSearchGroup; //needs a "updateItems()" after a change! vectorItems; + +signals: + void fileModified(); + protected: virtual void dragEnterEvent ( QDragEnterEvent * event ); virtual void dragMoveEvent ( QDragMoveEvent * event ); @@ -44,15 +50,12 @@ protected: virtual void mouseMoveEvent(QMouseEvent *event); virtual void paintEvent ( QPaintEvent * event ); - private: - QLine InsertionMarker; QPoint DragStartPos; QPixmap DragPixmap; GroupViewItem* DragItem; GroupViewItem* LastHoverItem; - GroupViewItem* getLastSameLevelItem(int level); }; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 798d4ae..8443d20 100755 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -148,6 +148,7 @@ void KeepassMainWindow::setupConnections(){ SLOT(OnEntryItemDoubleClicked(QTreeWidgetItem*,int))); connect(EntryView,SIGNAL(itemSelectionChanged()), this, SLOT(OnEntrySelectionChanged())); connect(GroupView,SIGNAL(itemSelectionChanged()), this, SLOT(OnGroupSelectionChanged())); + connect(GroupView,SIGNAL(fileModified()),this,SLOT(OnFileModified())); connect(QuickSearchEdit,SIGNAL(returnPressed()), this, SLOT(OnQuickSearch())); } @@ -231,7 +232,7 @@ Q_ASSERT(FileOpen); Q_ASSERT(db!=NULL); if(ModFlag){ int r=QMessageBox::question(this,trUtf8("Geänderte Datei speichern?"), - trUtf8("Die aktuell geöffnete Datei wurde verändert. Sollen die Änderungen vor dem Schließen gespeichert werden?"),tr("Ja"),tr("Nein"),tr("Abbrechen"),2,2); + trUtf8("Die aktuell geöffnete Datei wurde verändert. Sollen die Änderungen\nvor dem Schließen gespeichert werden?"),tr("Ja"),tr("Nein"),tr("Abbrechen"),2,2); if(r==2)return false; //Abbrechen if(r==0) //Ja (Datei speichern) if(!OnFileSave())return false; @@ -696,4 +697,15 @@ EntryView->updateItems(); void KeepassMainWindow::OnFileModified(){ setStateFileModified(true); +} + +void KeepassMainWindow::closeEvent(QCloseEvent* e){ +if(FileOpen){ + if(!closeDatabase()) + e->ignore(); + else + e->accept(); +} +else + e->accept(); } \ No newline at end of file diff --git a/src/mainwindow.h b/src/mainwindow.h index e1887da..fb9ace6 100755 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -110,7 +110,8 @@ private: inline CEntry* currentEntry(); QLineEdit* QuickSearchEdit; - +protected: + void closeEvent(QCloseEvent* event);