Add initial UI for entry editing.

This commit is contained in:
Felix Geyer 2010-10-06 19:40:50 +02:00
parent e3da80fcc6
commit 0c91be8eac
10 changed files with 334 additions and 10 deletions

View File

@ -35,6 +35,7 @@ set(keepassx_SOURCES
format/KeePass2XmlReader.cpp format/KeePass2XmlReader.cpp
format/KeePass2XmlWriter.cpp format/KeePass2XmlWriter.cpp
gui/DatabaseWidget.cpp gui/DatabaseWidget.cpp
gui/EditEntryWidget.cpp
gui/EntryModel.cpp gui/EntryModel.cpp
gui/EntryView.cpp gui/EntryView.cpp
gui/GroupModel.cpp gui/GroupModel.cpp
@ -49,6 +50,9 @@ set(keepassx_SOURCES
) )
set(keepassx_FORMS set(keepassx_FORMS
gui/EditEntryWidget.ui
gui/EditEntryWidgetMain.ui
gui/EditEntryWidgetNotes.ui
gui/MainWindow.ui gui/MainWindow.ui
) )

View File

@ -20,14 +20,16 @@
#include <QtGui/QHBoxLayout> #include <QtGui/QHBoxLayout>
#include <QtGui/QSplitter> #include <QtGui/QSplitter>
#include "EditEntryWidget.h"
#include "EntryView.h" #include "EntryView.h"
#include "GroupView.h" #include "GroupView.h"
DatabaseWidget::DatabaseWidget(Database* db, QWidget* parent) DatabaseWidget::DatabaseWidget(Database* db, QWidget* parent)
: QWidget(parent) : QStackedWidget(parent)
{ {
QLayout* layout = new QHBoxLayout(this); m_mainWidget = new QWidget(this);
QSplitter* splitter = new QSplitter(this); QLayout* layout = new QHBoxLayout(m_mainWidget);
QSplitter* splitter = new QSplitter(m_mainWidget);
m_groupView = new GroupView(db, splitter); m_groupView = new GroupView(db, splitter);
m_entryView = new EntryView(splitter); m_entryView = new EntryView(splitter);
@ -42,11 +44,31 @@ DatabaseWidget::DatabaseWidget(Database* db, QWidget* parent)
policy.setHorizontalStretch(70); policy.setHorizontalStretch(70);
m_entryView->setSizePolicy(policy); m_entryView->setSizePolicy(policy);
connect(m_groupView, SIGNAL(groupChanged(Group*)), m_entryView, SLOT(setGroup(Group*)));
splitter->addWidget(m_groupView); splitter->addWidget(m_groupView);
splitter->addWidget(m_entryView); splitter->addWidget(m_entryView);
layout->addWidget(splitter); layout->addWidget(splitter);
setLayout(layout); m_mainWidget->setLayout(layout);
m_editWidget = new EditEntryWidget();
addWidget(m_mainWidget);
addWidget(m_editWidget);
connect(m_groupView, SIGNAL(groupChanged(Group*)), m_entryView, SLOT(setGroup(Group*)));
connect(m_entryView, SIGNAL(entryActivated(Entry*)), SLOT(switchToEdit(Entry*)));
connect(m_editWidget, SIGNAL(editFinished()), SLOT(switchToView()));
setCurrentIndex(0);
}
void DatabaseWidget::switchToView()
{
setCurrentIndex(0);
}
void DatabaseWidget::switchToEdit(Entry* entry)
{
m_editWidget->loadEntry(entry);
setCurrentIndex(1);
} }

View File

@ -18,20 +18,28 @@
#ifndef KEEPASSX_DATABASEWIDGET_H #ifndef KEEPASSX_DATABASEWIDGET_H
#define KEEPASSX_DATABASEWIDGET_H #define KEEPASSX_DATABASEWIDGET_H
#include <QtGui/QWidget> #include <QtGui/QStackedWidget>
class Database; class Database;
class EditEntryWidget;
class Entry;
class EntryView; class EntryView;
class GroupView; class GroupView;
class DatabaseWidget : public QWidget class DatabaseWidget : public QStackedWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit DatabaseWidget(Database* db, QWidget* parent = 0); explicit DatabaseWidget(Database* db, QWidget* parent = 0);
private Q_SLOTS:
void switchToView();
void switchToEdit(Entry* entry);
private: private:
QWidget* m_mainWidget;
EditEntryWidget* m_editWidget;
GroupView* m_groupView; GroupView* m_groupView;
EntryView* m_entryView; EntryView* m_entryView;
}; };

View File

@ -0,0 +1,87 @@
/*
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 or (at your option)
* version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "EditEntryWidget.h"
#include "ui_EditEntryWidget.h"
#include "ui_EditEntryWidgetMain.h"
#include "ui_EditEntryWidgetNotes.h"
#include <QtGui/QListWidget>
#include <QtGui/QStackedLayout>
#include "core/Entry.h"
EditEntryWidget::EditEntryWidget(QWidget* parent)
: QWidget(parent)
, m_entry(0)
, m_ui(new Ui::EditEntryWidget())
, m_mainUi(new Ui::EditEntryWidgetMain())
, m_notesUi(new Ui::EditEntryWidgetNotes())
, m_mainWidget(new QWidget(this))
, m_notesWidget(new QWidget(this))
{
m_ui->setupUi(this);
m_ui->categoryList->addItem(tr("Entry"));
m_ui->categoryList->addItem(tr("Description"));
m_mainUi->setupUi(m_mainWidget);
m_ui->stackedWidget->addWidget(m_mainWidget);
m_notesUi->setupUi(m_notesWidget);
m_ui->stackedWidget->addWidget(m_notesWidget);
Q_ASSERT(m_ui->categoryList->model()->rowCount() == m_ui->stackedWidget->count());
connect(m_ui->categoryList, SIGNAL(currentRowChanged(int)), m_ui->stackedWidget, SLOT(setCurrentIndex(int)));
connect(m_ui->buttonBox, SIGNAL(accepted()), SLOT(saveEntry()));
connect(m_ui->buttonBox, SIGNAL(rejected()), SLOT(cancel()));
}
EditEntryWidget::~EditEntryWidget()
{
}
void EditEntryWidget::loadEntry(Entry* entry)
{
m_entry = entry;
m_mainUi->titleEdit->setText(entry->title());
m_mainUi->usernameEdit->setText(entry->username());
m_mainUi->urlEdit->setText(entry->url());
m_notesUi->notesEdit->setPlainText(entry->notes());
m_ui->categoryList->setCurrentRow(0);
}
void EditEntryWidget::saveEntry()
{
m_entry->setTitle(m_mainUi->titleEdit->text());
m_entry->setUsername(m_mainUi->usernameEdit->text());
m_entry->setUrl(m_mainUi->urlEdit->text());
m_entry->setNotes(m_notesUi->notesEdit->toPlainText());
cancel();
}
void EditEntryWidget::cancel()
{
m_entry = 0;
Q_EMIT editFinished();
}

63
src/gui/EditEntryWidget.h Normal file
View File

@ -0,0 +1,63 @@
/*
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 or (at your option)
* version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef KEEPASSX_EDITENTRYWIDGET_H
#define KEEPASSX_EDITENTRYWIDGET_H
#include <QtCore/QScopedPointer>
#include <QtGui/QWidget>
class Entry;
class QListWidget;
class QStackedLayout;
namespace Ui {
class EditEntryWidget;
class EditEntryWidgetMain;
class EditEntryWidgetNotes;
}
class EditEntryWidget : public QWidget
{
Q_OBJECT
public:
explicit EditEntryWidget(QWidget* parent = 0);
~EditEntryWidget();
void loadEntry(Entry* entry);
Q_SIGNALS:
void editFinished();
private Q_SLOTS:
void saveEntry();
void cancel();
private:
Entry* m_entry;
QScopedPointer<Ui::EditEntryWidget> m_ui;
QScopedPointer<Ui::EditEntryWidgetMain> m_mainUi;
QScopedPointer<Ui::EditEntryWidgetNotes> m_notesUi;
QWidget* m_mainWidget;
QWidget* m_notesWidget;
Q_DISABLE_COPY(EditEntryWidget)
};
#endif // KEEPASSX_EDITENTRYWIDGET_H

View File

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>EditEntryWidget</class>
<widget class="QWidget" name="EditEntryWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QListWidget" name="categoryList">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>20</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QStackedWidget" name="stackedWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>80</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="currentIndex">
<number>-1</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>EditEntryWidgetMain</class>
<widget class="QWidget" name="EditEntryWidgetMain">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>372</width>
<height>301</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="titleLabel">
<property name="text">
<string>Title:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="titleEdit"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="usernameLabel">
<property name="text">
<string>Username:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="usernameEdit"/>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="urlEdit"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="urlLabel">
<property name="text">
<string>URL:</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>EditEntryWidgetNotes</class>
<widget class="QWidget" name="EditEntryWidgetNotes">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="notesLabel">
<property name="text">
<string>Notes:</string>
</property>
</widget>
</item>
<item>
<widget class="QPlainTextEdit" name="notesEdit"/>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -27,6 +27,8 @@ EntryView::EntryView(QWidget* parent)
setUniformRowHeights(true); setUniformRowHeights(true);
setRootIsDecorated(false); setRootIsDecorated(false);
connect(this, SIGNAL(activated(const QModelIndex&)), SLOT(emitEntryActivated(const QModelIndex&)));
} }
void EntryView::setGroup(Group* group) void EntryView::setGroup(Group* group)

View File

@ -17,6 +17,8 @@
#include "GroupView.h" #include "GroupView.h"
#include <QtCore/QMetaObject>
#include "core/Database.h" #include "core/Database.h"
#include "core/Group.h" #include "core/Group.h"
#include "gui/GroupModel.h" #include "gui/GroupModel.h"
@ -26,12 +28,17 @@ GroupView::GroupView(Database* db, QWidget* parent)
{ {
m_model = new GroupModel(db, this); m_model = new GroupModel(db, this);
QTreeView::setModel(m_model); QTreeView::setModel(m_model);
recInitExpanded(db->rootGroup());
setHeaderHidden(true); setHeaderHidden(true);
setUniformRowHeights(true);
connect(this, SIGNAL(clicked(const QModelIndex&)), SLOT(emitGroupChanged(const QModelIndex&))); connect(this, SIGNAL(clicked(const QModelIndex&)), SLOT(emitGroupChanged(const QModelIndex&)));
setUniformRowHeights(true); recInitExpanded(db->rootGroup());
setCurrentIndex(m_model->index(0, 0));
// invoke later so the EntryView is connected
QMetaObject::invokeMethod(this, "emitGroupChanged", Qt::QueuedConnection,
Q_ARG(QModelIndex, m_model->index(0, 0)));
} }
void GroupView::expandedChanged(const QModelIndex& index) void GroupView::expandedChanged(const QModelIndex& index)