finished column resize functionality, fixed wrong qmake-project-file

git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@51 b624d157-de02-0410-bad0-e51aec6abb33
master
tariq 19 years ago
parent d6ea6e8971
commit 09ab186b9d
  1. 2
      src/PwmConfig.cpp
  2. 91
      src/lib/EntryView.cpp
  3. 10
      src/lib/EntryView.h
  4. 1
      src/main.cpp
  5. 6
      src/mainwindow.cpp
  6. 2
      src/mainwindow.h
  7. 17
      src/src.pro

@ -163,7 +163,7 @@ if(count > lst.size()){
for(int i=lst.size(); i<count; i++) for(int i=lst.size(); i<count; i++)
values[i]=DEFAULT_INT_VAL;} values[i]=DEFAULT_INT_VAL;}
memcpy(dst,values,count); memcpy(dst,values,count*sizeof(int));
delete [] values; delete [] values;
} }

@ -18,7 +18,7 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#include <math.h>
#include <QDragEnterEvent> #include <QDragEnterEvent>
#include <QDragMoveEvent> #include <QDragMoveEvent>
#include <QDragLeaveEvent> #include <QDragLeaveEvent>
@ -32,14 +32,28 @@
KeepassEntryView::KeepassEntryView(QWidget* parent):QTreeWidget(parent){ KeepassEntryView::KeepassEntryView(QWidget* parent):QTreeWidget(parent){
AutoResizeColumns=true;
int sum=0;
for(int i=0;i<NUM_COLUMNS;i++)
sum+=config.ColumnSizes[i];
for(int i=0;i<NUM_COLUMNS;i++)
ColumnSizes << (float)config.ColumnSizes[i]/(float)sum;
CurrentGroup=0; CurrentGroup=0;
updateColumns(); updateColumns();
header()->setResizeMode(QHeaderView::Interactive); header()->setResizeMode(QHeaderView::Interactive);
header()->setStretchLastSection(false); header()->setStretchLastSection(false);
connect(header(),SIGNAL(sectionResized(int,int,int)),this,SLOT(OnColumnResized(int,int,int)));
ContextMenu=new QMenu(this); ContextMenu=new QMenu(this);
} }
KeepassEntryView::~KeepassEntryView(){
for(int i=0;i<ColumnSizes.size();i++){
config.ColumnSizes[i]=round(ColumnSizes[i]*10000.0f);
}
}
void KeepassEntryView::contextMenuEvent(QContextMenuEvent* e){ void KeepassEntryView::contextMenuEvent(QContextMenuEvent* e){
if(itemAt(e->pos())){ if(itemAt(e->pos())){
@ -69,7 +83,7 @@ ContextMenu->popup(e->globalPos());
} }
void KeepassEntryView::resizeEvent(QResizeEvent* e){ void KeepassEntryView::resizeEvent(QResizeEvent* e){
resizeColumns();
e->accept(); e->accept();
} }
@ -198,7 +212,80 @@ if(config.Columns[8]){
if(config.Columns[9]){ if(config.Columns[9]){
cols << trUtf8("Anhang");} cols << trUtf8("Anhang");}
setHeaderLabels(cols); setHeaderLabels(cols);
resizeColumns();
}
void KeepassEntryView::resizeColumns(){
AutoResizeColumns=false;
for(int i=0;i<NUM_COLUMNS;i++)
if(!config.Columns[i])ColumnSizes[i]=0;
for(int i=0;i<NUM_COLUMNS;i++)
if(config.Columns[i] && ColumnSizes[i]==0)ColumnSizes[i]=0.1f;
float sum=0;
for(int i=0;i<NUM_COLUMNS;i++)
sum+=ColumnSizes[i];
for(int i=0;i<NUM_COLUMNS;i++)
ColumnSizes[i]/=sum;
int w=viewport()->width();
int wx=0; int j=0;
for(int i=0;i<NUM_COLUMNS;i++){
if(!config.Columns[i])continue;
int NewWidth=round(ColumnSizes[i]*(float)w);
wx+=NewWidth;
header()->resizeSection(j++,NewWidth);
//add rounding difference (w-wx) to the last column
if(j==header()->count()){
header()->resizeSection(j-1,header()->sectionSize(j-1)+(w-wx));
} }
}
AutoResizeColumns=true;
}
void KeepassEntryView::OnColumnResized(int index,int Old, int New){
if(!AutoResizeColumns)return;
int i=0; int c=-1;
for(i;i<ColumnSizes.size();i++){
if(config.Columns[i])c++;
if(c==index)break;
}
int j=0; c=-1; bool IsLastColumn=true;
for(j;j<ColumnSizes.size();j++){
if(config.Columns[j])c++;
if(c==(index+1)){IsLastColumn=false; break;}
}
if(IsLastColumn){
j=0; c=-1;
for(j;j<ColumnSizes.size();j++){
if(config.Columns[j])c++;
if(c==(index-1))break;
}
}
int w=viewport()->width();
float div=(float)(New-Old)/(float)w;
if(((ColumnSizes[j]-div)*w > 2)){
ColumnSizes[j]-=div;
ColumnSizes[i]+=div;
}
resizeColumns();
}
void KeepassEntryView::paintEvent(QPaintEvent * event){ void KeepassEntryView::paintEvent(QPaintEvent * event){
QTreeWidget::paintEvent(event); QTreeWidget::paintEvent(event);

@ -23,13 +23,19 @@
#include <QMenu> #include <QMenu>
#include <QTreeWidget> #include <QTreeWidget>
#include <QContextMenuEvent> #include <QContextMenuEvent>
#include <QHeaderView>
#include "../PwManager.h" #include "../PwManager.h"
#define NUM_COLUMNS 10
class EntryViewItem; class EntryViewItem;
class KeepassEntryView:public QTreeWidget{ class KeepassEntryView:public QTreeWidget{
Q_OBJECT
public: public:
KeepassEntryView(QWidget* parent=0); KeepassEntryView(QWidget* parent=0);
~KeepassEntryView();
void updateItems(unsigned int group); void updateItems(unsigned int group);
void refreshItems(); void refreshItems();
void updateColumns(); void updateColumns();
@ -41,10 +47,14 @@ private:
void setEntry(CEntry* entry); void setEntry(CEntry* entry);
int CurrentGroup; int CurrentGroup;
QList<float>ColumnSizes; QList<float>ColumnSizes;
void resizeColumns();
bool AutoResizeColumns;
protected: protected:
virtual void contextMenuEvent(QContextMenuEvent *event); virtual void contextMenuEvent(QContextMenuEvent *event);
virtual void paintEvent(QPaintEvent* event); virtual void paintEvent(QPaintEvent* event);
virtual void resizeEvent(QResizeEvent* event); virtual void resizeEvent(QResizeEvent* event);
public slots:
void OnColumnResized(int index,int OldSize, int NewSize);
}; };

@ -129,6 +129,7 @@ SecString::generateSessionKey();
KeepassMainWindow *mainWin = new KeepassMainWindow(); KeepassMainWindow *mainWin = new KeepassMainWindow();
mainWin->show(); mainWin->show();
int r=app->exec(); int r=app->exec();
delete mainWin;
if(!config.saveToIni(IniFilename)) if(!config.saveToIni(IniFilename))
QMessageBox::warning(NULL,QObject::tr("Warnung"),QObject::trUtf8("Die Konfigurationsdatei konnte nicht gespeichert werden.Stellen Sie sicher, dass\nSie Schreibrechte im Verzeichnis ~/.keepass besitzen."),QObject::tr("OK"),"","",0.0); QMessageBox::warning(NULL,QObject::tr("Warnung"),QObject::trUtf8("Die Konfigurationsdatei konnte nicht gespeichert werden.Stellen Sie sicher, dass\nSie Schreibrechte im Verzeichnis ~/.keepass besitzen."),QObject::tr("OK"),"","",0.0);
delete app; delete app;

@ -36,6 +36,7 @@
#include <QShowEvent> #include <QShowEvent>
#include <QWidget> #include <QWidget>
#include <QFileDialog> #include <QFileDialog>
#include <QStatusBar>
#include "lib/random.h" #include "lib/random.h"
#include "lib/IniReader.h" #include "lib/IniReader.h"
@ -71,6 +72,11 @@ KeepassMainWindow::KeepassMainWindow(QWidget *parent, Qt::WFlags flags):QMainWin
setupConnections(); setupConnections();
FileOpen=false; FileOpen=false;
Clipboard=QApplication::clipboard(); Clipboard=QApplication::clipboard();
setStatusBar(new QStatusBar(this));
StatusBarGeneral=new QLabel(tr("Bereit"),statusBar());
StatusBarSelection=new QLabel(statusBar());
statusBar()->addWidget(StatusBarGeneral,30);
statusBar()->addWidget(StatusBarSelection,70);
} }
void KeepassMainWindow::setupConnections(){ void KeepassMainWindow::setupConnections(){

@ -113,6 +113,8 @@ private:
inline CGroup* currentGroup(); inline CGroup* currentGroup();
inline CEntry* currentEntry(); inline CEntry* currentEntry();
QLineEdit* QuickSearchEdit; QLineEdit* QuickSearchEdit;
QLabel* StatusBarGeneral;
QLabel* StatusBarSelection;
protected: protected:
void closeEvent(QCloseEvent* event); void closeEvent(QCloseEvent* event);

@ -3,8 +3,15 @@
# Unterordner relativ zum Projektordner: ./src # Unterordner relativ zum Projektordner: ./src
# Das Target ist eine Anwendung: ../bin/keepass # Das Target ist eine Anwendung: ../bin/keepass
INSTALLS += Share INSTALLS += target \
Share
Share.files += ../share/keepass/* Share.files += ../share/keepass/*
unix{ target.path = /usr/local/bin
Share.path = /usr/local/share/keepass
}
macx{ target.path = /Applications
Share.path = /Applications/keepass.app/Contents/share/keepass
}
FORMS += forms/EditGroupDlg.ui \ FORMS += forms/EditGroupDlg.ui \
forms/SearchDlg.ui \ forms/SearchDlg.ui \
forms/AboutDlg.ui \ forms/AboutDlg.ui \
@ -100,11 +107,3 @@ thread \
exceptions \ exceptions \
stl stl
TEMPLATE = app TEMPLATE = app
unix{
target.path = /usr/local/bin
Share.path = /usr/local/share/keepass
}
macx{
target.path = /Applications
Share.path = /Applications/keepass.app/Contents/share/keepass
}