summaryrefslogtreecommitdiffstats
path: root/gui/IconPickerDialog.cpp
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2013-08-27 05:39:49 +0200
committerPetr Mrázek <peterix@gmail.com>2013-08-27 05:39:49 +0200
commit5573ed52e8b68a54330cfee21b853da53d079078 (patch)
tree10eebd4ac4804550441ccc2a591ed00640adb75f /gui/IconPickerDialog.cpp
parente6999b3b62c5b765eff1736477a052f1cfeffd19 (diff)
downloadMultiMC-5573ed52e8b68a54330cfee21b853da53d079078.tar
MultiMC-5573ed52e8b68a54330cfee21b853da53d079078.tar.gz
MultiMC-5573ed52e8b68a54330cfee21b853da53d079078.tar.lz
MultiMC-5573ed52e8b68a54330cfee21b853da53d079078.tar.xz
MultiMC-5573ed52e8b68a54330cfee21b853da53d079078.zip
Add/remove/drag&drop for the icon picker.
Diffstat (limited to 'gui/IconPickerDialog.cpp')
-rw-r--r--gui/IconPickerDialog.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/gui/IconPickerDialog.cpp b/gui/IconPickerDialog.cpp
index d80673a8..d3a33e57 100644
--- a/gui/IconPickerDialog.cpp
+++ b/gui/IconPickerDialog.cpp
@@ -2,6 +2,9 @@
#include "instancedelegate.h"
#include "ui_IconPickerDialog.h"
#include "logic/IconListModel.h"
+#include <QKeyEvent>
+#include <QPushButton>
+#include <QFileDialog>
IconPickerDialog::IconPickerDialog(QWidget *parent) :
QDialog(parent),
@@ -25,9 +28,24 @@ IconPickerDialog::IconPickerDialog(QWidget *parent) :
contentsWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
contentsWidget->setItemDelegate(new ListViewDelegate());
+ //contentsWidget->setAcceptDrops(true);
+ contentsWidget->setDropIndicatorShown(true);
+ contentsWidget->viewport()->setAcceptDrops(true);
+ contentsWidget->setDragDropMode(QAbstractItemView::DropOnly);
+ contentsWidget->setDefaultDropAction(Qt::CopyAction);
+
+ contentsWidget->installEventFilter(this);
+
IconList * list = IconList::instance();
contentsWidget->setModel(list);
+ auto buttonAdd = ui->buttonBox->addButton("Add Icon",QDialogButtonBox::ResetRole);
+ auto buttonRemove = ui->buttonBox->addButton("Remove Icon",QDialogButtonBox::ResetRole);
+
+
+ connect(buttonAdd,SIGNAL(clicked(bool)),SLOT(addNewIcon()));
+ connect(buttonRemove,SIGNAL(clicked(bool)),SLOT(removeSelectedIcon()));
+
connect
(
contentsWidget,
@@ -42,6 +60,43 @@ IconPickerDialog::IconPickerDialog(QWidget *parent) :
SLOT(selectionChanged(QItemSelection,QItemSelection))
);
}
+bool IconPickerDialog::eventFilter ( QObject* obj, QEvent* evt)
+{
+ if(obj != ui->iconView)
+ return QDialog::eventFilter(obj ,evt);
+ if (evt->type() != QEvent::KeyPress)
+ {
+ return QDialog::eventFilter(obj ,evt);
+ }
+ QKeyEvent *keyEvent = static_cast<QKeyEvent*>(evt);
+ IconList * list = IconList::instance();
+ switch(keyEvent->key())
+ {
+ case Qt::Key_Delete:
+ removeSelectedIcon();
+ return true;
+ case Qt::Key_Plus:
+ addNewIcon();
+ return true;
+ default:
+ break;
+ }
+ return QDialog::eventFilter(obj ,evt);
+}
+
+void IconPickerDialog::addNewIcon()
+{
+ QStringList fileNames = QFileDialog::getOpenFileNames(this, "Select Icons", QString(), "Icons (*.png *.jpg *.jpeg)");
+ IconList * list = IconList::instance();
+ list->installIcons(fileNames);
+}
+
+void IconPickerDialog::removeSelectedIcon()
+{
+ IconList * list = IconList::instance();
+ list->deleteIcon(selectedIconKey);
+}
+
void IconPickerDialog::activated ( QModelIndex index )
{