[go: up one dir, main page]

Menu

[07bac0]: / SelectSavesDialog.cpp  Maximize  Restore  History

Download this file

130 lines (110 with data), 4.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/****************************************************************************
** Hyne Final Fantasy VIII Save Editor
** Copyright (C) 2013 Arzel Jérôme <myst6re@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
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include "SelectSavesDialog.h"
SelectSavesDialog::SelectSavesDialog(const QList<SaveData *> &saveFiles, bool multiSelection, bool onlyFF8, QWidget *parent) :
QDialog(parent, Qt::Dialog | Qt::WindowCloseButtonHint)
{
msg = new HelpWidget(16, this);
fillList(saveFiles);
for(int i=0 ; i<list->count() ; ++i) {
if(!saveFiles.at(i)->isFF8() &&
(onlyFF8 || saveFiles.at(i)->isRaw() || saveFiles.at(i)->isDelete()))
list->item(i)->setFlags(Qt::NoItemFlags);
}
if(multiSelection) {
msg->setText(infoText());
list->setSelectionMode(QAbstractItemView::MultiSelection);
}
else {
msg->setText(tr("Sélectionnez une sauvegarde :"));
}
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok,
Qt::Horizontal, this);
connect(buttonBox, SIGNAL(accepted()), SLOT(accept()));
QVBoxLayout *layout = new QVBoxLayout(this);
layout->addWidget(msg);
layout->addWidget(list);
layout->addWidget(buttonBox);
if(multiSelection)
connect(list, SIGNAL(itemSelectionChanged()), SLOT(controlSelection()));
}
SelectSavesDialog::SelectSavesDialog(const QList<SaveData *> &saveFiles, QWidget *parent) :
QDialog(parent, Qt::Dialog | Qt::WindowCloseButtonHint)
{
msg = new HelpWidget(16, this);
fillList(saveFiles);
msg->setText(tr("Déplacez les éléments à la souris pour modifier l'ordre des saves."));
list->setDragDropMode(QAbstractItemView::InternalMove);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok,
Qt::Horizontal, this);
connect(buttonBox, SIGNAL(accepted()), SLOT(accept()));
QVBoxLayout *layout = new QVBoxLayout(this);
layout->addWidget(msg);
layout->addWidget(list);
layout->addWidget(buttonBox);
}
void SelectSavesDialog::fillList(const QList<SaveData *> &saveFiles)
{
list = new QListWidget(this);
SaveData *save;
QString shortDescription;
for(int i=0 ; i<saveFiles.size() ; ++i) {
save = saveFiles.at(i);
shortDescription = save->shortDescription();
QListWidgetItem *item = new QListWidgetItem(tr("Save %1 (%2)").arg(i+1)
.arg(shortDescription.isEmpty()
? tr("vide")
: shortDescription));
item->setIcon(save->saveIcon().icon());
list->addItem(item);
item->setData(Qt::UserRole, i);
}
}
QString SelectSavesDialog::infoText(bool warn)
{
return tr("Sélectionnez jusqu'à <font color=\"%1\">15 saves</font> :")
.arg(warn ? "red" : "");
}
QList<int> SelectSavesDialog::selectedSaves() const
{
QList<int> selected_saves;
foreach(QListWidgetItem *item, list->selectedItems())
selected_saves.append(list->row(item));
return selected_saves;
}
QList<int> SelectSavesDialog::order() const
{
QList<int> order;
int count = list->count();
for(int row=0 ; row<count ; ++row)
order.append(list->item(row)->data(Qt::UserRole).toInt());
return order;
}
void SelectSavesDialog::controlSelection()
{
QList<QListWidgetItem *> selectedItems = list->selectedItems();
int count = selectedItems.size();
if(count > 15) {
msg->setText(infoText(true));
for(int i=15 ; i<count ; ++i) {
selectedItems.at(i)->setSelected(false);
}
} else if(count < 15) {
msg->setText(infoText());
}
}