This repository has been archived by the owner on Sep 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathSuccessDialog.cpp
246 lines (215 loc) · 7.5 KB
/
SuccessDialog.cpp
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/***************************************************************************//**
* @brief Thumbnail me 3.0
* Thumbnail me is a user interface for Movie thumbnailer.
* Generate thumbnails from any movie is now easier !
*
* @file SuccessDialog.cpp
* @class SuccessDialog
* Cette classe permet la génération de la fenêtre "Succès" lorsque la vignette a été générée avec succès.
*
* @author Quentin Rousseau\n
* @note Copyright (C) 2011-2012 Quentin Rousseau\n
* License: GNU General Public License version 2 (GPLv2) - http://www.gnu.org/licenses/gpl-2.0.html\n
* Site web: www.thumbnailme.com\n
* Email: quentin.rousseau@thumbnailme.com
*
* @since 2.0
* @version 3.0
* @date 2011-2012
*******************************************************************************/
#include "SuccessDialog.h"
#include "ImageShackUploadWidget.h"
#include "ThumbnailListwidget.h"
#include "ThumbnailItem.h"
#include "QtHelper.h"
#include <QDialogButtonBox>
#include <QGridLayout>
#include <QDesktopServices>
/**
*@brief Constructeur.
*@param *parent Widget parent.
*@param openFolderPath Chemin du dossier à ouvrir pour le bouton "Ouvrir le dossier".
*/
SuccessDialog::SuccessDialog(QWidget *parent, QString openFolderPath) : QDialog(parent)
{
this->setWindowTitle(parent->windowTitle());
//this->setWindowFlags(Qt::Dialog | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint);
this->openFolderPath = openFolderPath;
textSaveLabel = new QLabel(this);
openFolderButton = new QPushButton(QIcon(":/sprites/openfolder.png"),QString(),this);
uploadImageShackButton = new QPushButton(QIcon(":/sprites/imageShack_frog.png"),QString(),this);
closeDialogButton = new QPushButton(QIcon(":/sprites/quit.png"),QString(),this);
QLabel *pixmapLabel = new QLabel(this);
pixmapLabel->setPixmap(QPixmap( ":/sprites/thumbnails-folder.png" ));
listWidget = new ThumbnailListWidget(this);
listWidget->setFixedWidth(500);
QDialogButtonBox *buttonBoxDialog = new QDialogButtonBox(this);
buttonBoxDialog->addButton(openFolderButton,QDialogButtonBox::AcceptRole);
buttonBoxDialog->addButton(uploadImageShackButton,QDialogButtonBox::RejectRole);
buttonBoxDialog->addButton(closeDialogButton,QDialogButtonBox::RejectRole);
buttonBoxDialog->setCenterButtons(true);
QVBoxLayout *leftLayout = new QVBoxLayout;
leftLayout->addWidget(textSaveLabel);
leftLayout->addWidget(pixmapLabel);
QHBoxLayout *centerLayout = new QHBoxLayout;
centerLayout->addLayout(leftLayout);
centerLayout->addWidget(listWidget);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(centerLayout);
mainLayout->addWidget(QtHelper::addHSeparator());
mainLayout->addWidget(buttonBoxDialog);
imageShackUploadWidget = new ImageShackUploadWidget(this);
this->setLayout(mainLayout);
this->layout()->setSizeConstraint(QLayout::SetFixedSize);
this->retranslate();
/*Connections*/
connect(openFolderButton, SIGNAL(clicked()), this , SLOT(openFolder()));
connect(uploadImageShackButton, SIGNAL(clicked()), this , SLOT(uploadToImageShack()));
connect(closeDialogButton, SIGNAL(clicked()), this , SLOT(accept()));
connect(listWidget, SIGNAL(itemDoubleClicked (QListWidgetItem*)), this, SLOT(setDoubleClickPathOpenFolder(QListWidgetItem*)));
connect(listWidget, SIGNAL(itemSelectionChanged()), this, SLOT(setSelectionPathOpenFolder()));
connect(listWidget, SIGNAL(itemChanged (QListWidgetItem *)), this, SLOT(enableUploadButton()));
}
/**
*@brief Destructeur.
*/
SuccessDialog::~SuccessDialog()
{
delete imageShackUploadWidget;
}
/**
*@brief Ajoute un item à la ThumbnailListWidget.
*@param item Item à ajouter.
*@return int - Nombre d'item dans la QListWidget.
*/
int SuccessDialog::addItem(ThumbnailItem *item)
{
/*Copie car
Warning: A QListWidgetItem can only be added to a QListWidget once.
Adding the same QListWidgetItem multiple times to a QListWidget will result in undefined behavior.
*/
ThumbnailItem *i = new ThumbnailItem(*item);
i->setText(item->getFilePathOutput().toString(QUrl::RemoveScheme).mid(3));
i->setParent(item);
i->setFlags(item->flags() | Qt::ItemIsUserCheckable);
i->setCheckState(Qt::Checked);
listWidget->addItem(i);
return listWidget->count();
}
/**
*@brief Supprime un item de la ThumbnailListWidget.
*@param item Item à supprimer.
*/
void SuccessDialog::removeItem(ThumbnailItem *item)
{
ThumbnailItem *child = item->findChild<ThumbnailItem *>();
if(child)
delete child;
}
/**
*@brief Retourne la liste des Thumbnails.
*@return ThumbnailListWidget* - ThumbnailListWidget.
*/
ThumbnailListWidget* SuccessDialog::getListWidget()
{
return this->listWidget;
}
/**
*@brief Efface tous les chemins de la QListWidget.
*/
void SuccessDialog::clearListWidget()
{
listWidget->clear();
}
/**
*@brief Fixe le chemin du dossier à ouvrir.
*@param path Chemin.
*/
void SuccessDialog::setPathOpenFolder(QString path)
{
this->openFolderPath = path;
}
/**
*@brief Fixe le chemin du dossier via la double click
*@param item Item sélectionné.
*/
void SuccessDialog::setDoubleClickPathOpenFolder(QListWidgetItem* item)
{
this->openFolderPath = QFileInfo(item->text()).absolutePath();
openFolder();
}
/**
*@brief Fixe le chemin du dossier de l'item courant sélectionné
*/
void SuccessDialog::setSelectionPathOpenFolder()
{
this->openFolderPath = QFileInfo(listWidget->currentItem()->text()).absolutePath();
openFolderButton->setEnabled(true);
}
/**
*@brief Ouvre le dossier de destination dont le chemin est openFolderPath.
*/
void SuccessDialog::openFolder()
{
if(!openFolderPath.isEmpty())
QDesktopServices::openUrl(QUrl::fromLocalFile(openFolderPath));
}
/**
*@brief Appelle la fenêtre d'upload surImageShack.
*/
void SuccessDialog::uploadToImageShack()
{
imageShackUploadWidget->reset();
imageShackUploadWidget->addData(QtHelper::getItemsListWidget(listWidget,Qt::Checked));
this->close();
QtHelper::centerWidget(imageShackUploadWidget);
imageShackUploadWidget->show();
}
/**
*@brief Enable ou Disable le boutton d'upload.
*/
void SuccessDialog::enableUploadButton()
{
//Si aucun item est sélectionné
if(QtHelper::getItemsListWidget(listWidget,Qt::Checked).isEmpty())
uploadImageShackButton->setEnabled(false);
else uploadImageShackButton->setEnabled(true);
}
/**
*@brief ChangeEvent.
*@param *event Evenement.
*/
void SuccessDialog::changeEvent(QEvent* event)
{
if (event->type() == QEvent::LanguageChange)
retranslate();
QWidget::changeEvent(event);
}
/**
*@brief Fonction de traduction dynamique.
*/
void SuccessDialog::retranslate()
{
openFolderButton->setText( tr("Open Folder") );
closeDialogButton->setText( tr("Close") );
}
/**
*@brief Réimplémentation de exec.
*/
int SuccessDialog::exec()
{
if (QtHelper::getItemsListWidget(listWidget).count() == 1)
{
textSaveLabel->setText(tr("<h1>Save file as:</h1>"));
textSaveLabel->setAlignment(Qt::AlignCenter);
uploadImageShackButton->setText(tr("Upload to ImageShack"));
}
else // Si plus de 1
{
textSaveLabel->setText(tr("<h1>Save file(s) as:</h1>"));
textSaveLabel->setAlignment(Qt::AlignCenter);
uploadImageShackButton->setText(tr("Upload these files to ImageShack"));
}
openFolderButton->setDisabled(true);
return QDialog::exec();
}