Add icon selection for groups.

Refs #22
This commit is contained in:
Florian Geyer 2012-05-15 13:31:56 +02:00
parent 1cb64f0c9f
commit 6a1d6e8dd3
4 changed files with 24 additions and 4 deletions

View File

@ -263,7 +263,7 @@ void DatabaseWidget::switchToEntryEdit(Entry* entry, bool create)
void DatabaseWidget::switchToGroupEdit(Group* group, bool create)
{
m_editGroupWidget->loadGroup(group, create);
m_editGroupWidget->loadGroup(group, create, m_db);
setCurrentIndex(2);
}

View File

@ -19,15 +19,19 @@
#include "ui_EditGroupWidgetMain.h"
#include "ui_EditWidget.h"
#include "gui/EditWidgetIcons.h"
EditGroupWidget::EditGroupWidget(QWidget* parent)
: EditWidget(parent)
, m_mainUi(new Ui::EditGroupWidgetMain())
, m_editGroupWidgetMain(new QWidget())
, m_editGroupWidgetIcons(new EditWidgetIcons())
, m_group(0)
{
m_mainUi->setupUi(m_editGroupWidgetMain);
add(tr("Group"), m_editGroupWidgetMain);
add(tr("Icon"), m_editGroupWidgetIcons);
QFont labelHeaderFont = headlineLabel()->font();
labelHeaderFont.setBold(true);
@ -42,7 +46,7 @@ EditGroupWidget::~EditGroupWidget()
{
}
void EditGroupWidget::loadGroup(Group* group, bool create)
void EditGroupWidget::loadGroup(Group* group, bool create, Database* database)
{
m_group = group;
@ -57,6 +61,10 @@ void EditGroupWidget::loadGroup(Group* group, bool create)
m_mainUi->editNotes->setPlainText(m_group->notes());
setCurrentRow(0);
IconStruct iconStruct;
iconStruct.uuid = group->iconUuid();
iconStruct.number = group->iconNumber();
m_editGroupWidgetIcons->load(group->uuid(), database, iconStruct);
m_mainUi->editName->setFocus();
}
@ -66,6 +74,15 @@ void EditGroupWidget::save()
m_group->setName(m_mainUi->editName->text());
m_group->setNotes(m_mainUi->editNotes->toPlainText());
IconStruct iconStruct = m_editGroupWidgetIcons->save();
if (iconStruct.uuid.isNull()) {
m_group->setIcon(iconStruct.number);
}
else {
m_group->setIcon(iconStruct.uuid);
}
m_group = 0;
Q_EMIT editFinished(true);
}

View File

@ -23,6 +23,8 @@
#include "gui/EditWidget.h"
#include "core/Group.h"
class EditWidgetIcons;
namespace Ui {
class EditGroupWidgetMain;
class EditWidget;
@ -36,7 +38,7 @@ public:
explicit EditGroupWidget(QWidget* parent = 0);
~EditGroupWidget();
void loadGroup(Group* group, bool create);
void loadGroup(Group* group, bool create, Database* database);
Q_SIGNALS:
void editFinished(bool accepted);
@ -48,6 +50,7 @@ private Q_SLOTS:
private:
const QScopedPointer<Ui::EditGroupWidgetMain> m_mainUi;
QWidget* const m_editGroupWidgetMain;
EditWidgetIcons* const m_editGroupWidgetIcons;
Group* m_group;
Q_DISABLE_COPY(EditGroupWidget)

View File

@ -47,7 +47,7 @@ public:
~EditWidgetIcons();
IconStruct save();
void load(Database* database, IconStruct iconStruct);
void load(Uuid currentUuid, Database *database, IconStruct iconStruct);
private Q_SLOTS:
void addCustomIcon();