From 6a1d6e8dd38b6b2f3e8672369599b352967c16d7 Mon Sep 17 00:00:00 2001 From: Florian Geyer Date: Tue, 15 May 2012 13:31:56 +0200 Subject: [PATCH] Add icon selection for groups. Refs #22 --- src/gui/DatabaseWidget.cpp | 2 +- src/gui/EditGroupWidget.cpp | 19 ++++++++++++++++++- src/gui/EditGroupWidget.h | 5 ++++- src/gui/EditWidgetIcons.h | 2 +- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index 7a2aaf42d..86aa309d1 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -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); } diff --git a/src/gui/EditGroupWidget.cpp b/src/gui/EditGroupWidget.cpp index 0bc0e5753..2011871f9 100644 --- a/src/gui/EditGroupWidget.cpp +++ b/src/gui/EditGroupWidget.cpp @@ -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); } diff --git a/src/gui/EditGroupWidget.h b/src/gui/EditGroupWidget.h index 891a5c679..5b0bf26b5 100644 --- a/src/gui/EditGroupWidget.h +++ b/src/gui/EditGroupWidget.h @@ -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 m_mainUi; QWidget* const m_editGroupWidgetMain; + EditWidgetIcons* const m_editGroupWidgetIcons; Group* m_group; Q_DISABLE_COPY(EditGroupWidget) diff --git a/src/gui/EditWidgetIcons.h b/src/gui/EditWidgetIcons.h index 4921c0cbc..3a3f11e7a 100644 --- a/src/gui/EditWidgetIcons.h +++ b/src/gui/EditWidgetIcons.h @@ -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();