mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-01-13 16:30:29 -05:00
Add initial UI for entry editing.
This commit is contained in:
parent
e3da80fcc6
commit
0c91be8eac
@ -35,6 +35,7 @@ set(keepassx_SOURCES
|
||||
format/KeePass2XmlReader.cpp
|
||||
format/KeePass2XmlWriter.cpp
|
||||
gui/DatabaseWidget.cpp
|
||||
gui/EditEntryWidget.cpp
|
||||
gui/EntryModel.cpp
|
||||
gui/EntryView.cpp
|
||||
gui/GroupModel.cpp
|
||||
@ -49,6 +50,9 @@ set(keepassx_SOURCES
|
||||
)
|
||||
|
||||
set(keepassx_FORMS
|
||||
gui/EditEntryWidget.ui
|
||||
gui/EditEntryWidgetMain.ui
|
||||
gui/EditEntryWidgetNotes.ui
|
||||
gui/MainWindow.ui
|
||||
)
|
||||
|
||||
|
@ -20,14 +20,16 @@
|
||||
#include <QtGui/QHBoxLayout>
|
||||
#include <QtGui/QSplitter>
|
||||
|
||||
#include "EditEntryWidget.h"
|
||||
#include "EntryView.h"
|
||||
#include "GroupView.h"
|
||||
|
||||
DatabaseWidget::DatabaseWidget(Database* db, QWidget* parent)
|
||||
: QWidget(parent)
|
||||
: QStackedWidget(parent)
|
||||
{
|
||||
QLayout* layout = new QHBoxLayout(this);
|
||||
QSplitter* splitter = new QSplitter(this);
|
||||
m_mainWidget = new QWidget(this);
|
||||
QLayout* layout = new QHBoxLayout(m_mainWidget);
|
||||
QSplitter* splitter = new QSplitter(m_mainWidget);
|
||||
|
||||
m_groupView = new GroupView(db, splitter);
|
||||
m_entryView = new EntryView(splitter);
|
||||
@ -42,11 +44,31 @@ DatabaseWidget::DatabaseWidget(Database* db, QWidget* parent)
|
||||
policy.setHorizontalStretch(70);
|
||||
m_entryView->setSizePolicy(policy);
|
||||
|
||||
connect(m_groupView, SIGNAL(groupChanged(Group*)), m_entryView, SLOT(setGroup(Group*)));
|
||||
|
||||
splitter->addWidget(m_groupView);
|
||||
splitter->addWidget(m_entryView);
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -18,20 +18,28 @@
|
||||
#ifndef KEEPASSX_DATABASEWIDGET_H
|
||||
#define KEEPASSX_DATABASEWIDGET_H
|
||||
|
||||
#include <QtGui/QWidget>
|
||||
#include <QtGui/QStackedWidget>
|
||||
|
||||
class Database;
|
||||
class EditEntryWidget;
|
||||
class Entry;
|
||||
class EntryView;
|
||||
class GroupView;
|
||||
|
||||
class DatabaseWidget : public QWidget
|
||||
class DatabaseWidget : public QStackedWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DatabaseWidget(Database* db, QWidget* parent = 0);
|
||||
|
||||
private Q_SLOTS:
|
||||
void switchToView();
|
||||
void switchToEdit(Entry* entry);
|
||||
|
||||
private:
|
||||
QWidget* m_mainWidget;
|
||||
EditEntryWidget* m_editWidget;
|
||||
GroupView* m_groupView;
|
||||
EntryView* m_entryView;
|
||||
};
|
||||
|
87
src/gui/EditEntryWidget.cpp
Normal file
87
src/gui/EditEntryWidget.cpp
Normal 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
63
src/gui/EditEntryWidget.h
Normal 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
|
52
src/gui/EditEntryWidget.ui
Normal file
52
src/gui/EditEntryWidget.ui
Normal 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>
|
51
src/gui/EditEntryWidgetMain.ui
Normal file
51
src/gui/EditEntryWidgetMain.ui
Normal 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>
|
28
src/gui/EditEntryWidgetNotes.ui
Normal file
28
src/gui/EditEntryWidgetNotes.ui
Normal 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>
|
@ -27,6 +27,8 @@ EntryView::EntryView(QWidget* parent)
|
||||
|
||||
setUniformRowHeights(true);
|
||||
setRootIsDecorated(false);
|
||||
|
||||
connect(this, SIGNAL(activated(const QModelIndex&)), SLOT(emitEntryActivated(const QModelIndex&)));
|
||||
}
|
||||
|
||||
void EntryView::setGroup(Group* group)
|
||||
|
@ -17,6 +17,8 @@
|
||||
|
||||
#include "GroupView.h"
|
||||
|
||||
#include <QtCore/QMetaObject>
|
||||
|
||||
#include "core/Database.h"
|
||||
#include "core/Group.h"
|
||||
#include "gui/GroupModel.h"
|
||||
@ -26,12 +28,17 @@ GroupView::GroupView(Database* db, QWidget* parent)
|
||||
{
|
||||
m_model = new GroupModel(db, this);
|
||||
QTreeView::setModel(m_model);
|
||||
recInitExpanded(db->rootGroup());
|
||||
setHeaderHidden(true);
|
||||
setUniformRowHeights(true);
|
||||
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user