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) void DatabaseWidget::switchToGroupEdit(Group* group, bool create)
{ {
m_editGroupWidget->loadGroup(group, create); m_editGroupWidget->loadGroup(group, create, m_db);
setCurrentIndex(2); setCurrentIndex(2);
} }

View File

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

View File

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

View File

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