summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2009-01-19 15:07:57 -0500
committerBen Boeckel <MathStuf@gmail.com>2009-01-19 15:07:57 -0500
commitf29ead61b6d17aa30b6d2400798e8dd063f6df7a (patch)
treee67a58af6ead4e51e811e991dc83aa893e0b30a6
parentf01492862f2055d64b4b0b8cd433a909864eb17d (diff)
Changed Store item editing to use KActionSelector
-rw-r--r--sigmodr/StoreUI.cpp41
-rw-r--r--sigmodr/StoreUI.h5
-rw-r--r--sigmodr/gui/store.ui22
3 files changed, 45 insertions, 23 deletions
diff --git a/sigmodr/StoreUI.cpp b/sigmodr/StoreUI.cpp
index d280d2d3..32642dad 100644
--- a/sigmodr/StoreUI.cpp
+++ b/sigmodr/StoreUI.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2008 Ben Boeckel <MathStuf@gmail.com>
+ * Copyright 2008-2009 Ben Boeckel <MathStuf@gmail.com>
*
* 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
@@ -23,6 +23,9 @@
#include "../sigmod/Sigmod.h"
#include "../sigmod/Store.h"
+// Qt includes
+#include <QtGui/QListWidgetItem>
+
Sigmodr::StoreUI::StoreUI(Sigmod::Store* store, QWidget* parent) :
ObjectUI(parent)
{
@@ -36,25 +39,35 @@ Sigmodr::StoreUI::~StoreUI()
void Sigmodr::StoreUI::refreshGui()
{
- const bool blocked = varItems->blockSignals(true);
- varItems->clear();
+ const bool blockedItems = varItems->blockSignals(true);
+ varItems->availableListWidget()->clear();
+ varItems->selectedListWidget()->clear();
for (int i = 0; i < sigmod()->itemCount(); ++i)
{
const Sigmod::Item* item = sigmod()->item(i);
- QListWidgetItem* widgetItem = new QListWidgetItem(item->name(), varItems);
+ QListWidgetItem* widgetItem = new QListWidgetItem(item->name(), varItems->availableListWidget());
widgetItem->setData(Qt::UserRole, item->id());
}
- varItems->blockSignals(blocked);
+ varItems->blockSignals(blockedItems);
+ varItems->setButtonsEnabled();
}
void Sigmodr::StoreUI::setGui()
{
varName->setText(qobject_cast<Sigmod::Store*>(modified())->name());
- for (int i = 0; i < varItems->count(); ++i)
+ for (int i = 0; i < varItems->availableListWidget()->count(); ++i)
+ {
+ QListWidgetItem* widgetItem = varItems->availableListWidget()->item(i);
+ if (qobject_cast<Sigmod::Store*>(modified())->item(widgetItem->data(Qt::UserRole).toInt()))
+ varItems->selectedListWidget()->addItem(varItems->availableListWidget()->takeItem(i--));
+ }
+ for (int i = 0; i < varItems->selectedListWidget()->count(); ++i)
{
- QListWidgetItem* widgetItem = varItems->item(i);
- widgetItem->setSelected(qobject_cast<Sigmod::Store*>(modified())->item(widgetItem->data(Qt::UserRole).toInt()));
+ QListWidgetItem* widgetItem = varItems->selectedListWidget()->item(i);
+ if (!qobject_cast<Sigmod::Store*>(modified())->item(widgetItem->data(Qt::UserRole).toInt()))
+ varItems->availableListWidget()->addItem(varItems->selectedListWidget()->takeItem(i--));
}
+ varItems->setButtonsEnabled();
}
void Sigmodr::StoreUI::apply()
@@ -77,7 +90,15 @@ void Sigmodr::StoreUI::on_varName_textChanged(const QString& name)
varName->setCursorPosition(cursor);
}
-void Sigmodr::StoreUI::on_varItems_itemClicked(QListWidgetItem* item)
+void Sigmodr::StoreUI::on_varItems_added(QListWidgetItem* item)
{
- qobject_cast<Sigmod::Store*>(modified())->setItem(item->data(Qt::UserRole).toInt(), item->isSelected());
+ qobject_cast<Sigmod::Store*>(modified())->setItem(item->data(Qt::UserRole).toInt(), true);
+ setGui();
}
+
+void Sigmodr::StoreUI::on_varItems_removed(QListWidgetItem* item)
+{
+ qobject_cast<Sigmod::Store*>(modified())->setItem(item->data(Qt::UserRole).toInt(), false);
+ setGui();
+}
+
diff --git a/sigmodr/StoreUI.h b/sigmodr/StoreUI.h
index 154cb24f..53a480e4 100644
--- a/sigmodr/StoreUI.h
+++ b/sigmodr/StoreUI.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2008 Ben Boeckel <MathStuf@gmail.com>
+ * Copyright 2008-2009 Ben Boeckel <MathStuf@gmail.com>
*
* 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
@@ -44,7 +44,8 @@ class StoreUI : public ObjectUI, private Ui::formStore
void discard();
protected slots:
void on_varName_textChanged(const QString& name);
- void on_varItems_itemClicked(QListWidgetItem* item);
+ void on_varItems_added(QListWidgetItem* item);
+ void on_varItems_removed(QListWidgetItem* item);
private slots:
void refreshGui();
void setGui();
diff --git a/sigmodr/gui/store.ui b/sigmodr/gui/store.ui
index b80646ab..20bd64d8 100644
--- a/sigmodr/gui/store.ui
+++ b/sigmodr/gui/store.ui
@@ -28,24 +28,24 @@
</widget>
</item>
<item>
- <widget class="QGroupBox" name="boxHMs" >
+ <widget class="QGroupBox" name="boxItems" >
<property name="title" >
<string>Items</string>
</property>
<property name="toolTip" >
<string>The items for sale at the store</string>
</property>
- <property name="toolTip" >
+ <property name="statusTip" >
<string>The items for sale at the store</string>
</property>
- <property name="toolTip" >
+ <property name="whatsThis" >
<string>The items for sale at the store</string>
</property>
<layout class="QHBoxLayout" >
<item>
- <widget class="KListWidget" name="varItems" >
- <property name="selectionMode" >
- <enum>QAbstractItemView::ExtendedSelection</enum>
+ <widget class="KActionSelector" name="varItems" >
+ <property name="showUpDownButtons" >
+ <bool>false</bool>
</property>
</widget>
</item>
@@ -69,15 +69,15 @@
</widget>
<customwidgets>
<customwidget>
+ <class>KActionSelector</class>
+ <extends>QWidget</extends>
+ <header location="global" >KActionSelector</header>
+ </customwidget>
+ <customwidget>
<class>KLineEdit</class>
<extends>QLineEdit</extends>
<header location="global" >KLineEdit</header>
</customwidget>
- <customwidget>
- <class>KListWidget</class>
- <extends>QListWidget</extends>
- <header location="global" >KListWidget</header>
- </customwidget>
</customwidgets>
<resources/>
<connections/>