File indexing completed on 2024-05-05 05:40:58

0001 /***************************************************************************
0002  *   Copyright (C) 2016 by Renaud Guezennec                                *
0003  *   https://rolisteam.org/contact                                      *
0004  *                                                                         *
0005  *   rolisteam is free software; you can redistribute it and/or modify     *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
0019  ***************************************************************************/
0020 #include "persondialog.h"
0021 #include "ui_persondialog.h"
0022 
0023 #include "controller/view_controller/imageselectorcontroller.h"
0024 #include "rwidgets/dialogs/imageselectordialog.h"
0025 
0026 PersonDialog::PersonDialog(QWidget* parent) : QDialog(parent), ui(new Ui::PersonDialog)
0027 {
0028     ui->setupUi(this);
0029 
0030     connect(ui->m_selectCharaterAvatar, SIGNAL(clicked()), this, SLOT(openImage()));
0031     connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(clickOnBar(QAbstractButton*)));
0032 }
0033 
0034 PersonDialog::~PersonDialog()
0035 {
0036     delete ui;
0037 }
0038 QString PersonDialog::getName() const
0039 {
0040     return ui->m_characterName->text();
0041 }
0042 
0043 QColor PersonDialog::getColor() const
0044 {
0045     return ui->m_characterColor->color();
0046 }
0047 QString PersonDialog::getAvatarUri() const
0048 {
0049     return m_avatar;
0050 }
0051 void PersonDialog::openImage()
0052 {
0053     ImageSelectorController ctrl(false, ImageSelectorController::All, ImageSelectorController::Square);
0054     ImageSelectorDialog dialog(&ctrl, this);
0055 
0056     if(QDialog::Accepted != dialog.exec())
0057         return;
0058 
0059     auto data= ctrl.finalImageData();
0060 
0061     if(!data.isEmpty())
0062     {
0063         QPixmap pix;
0064         pix.loadFromData(data);
0065         ui->m_selectCharaterAvatar->setIcon(QIcon(pix));
0066     }
0067 }
0068 int PersonDialog::edit(QString title, QString name, QColor color, QString icon)
0069 {
0070     setWindowTitle(title);
0071     ui->m_characterName->setText(name);
0072     ui->m_characterColor->setColor(color);
0073     m_avatar= icon;
0074     ui->m_selectCharaterAvatar->setIcon(QIcon(icon));
0075 
0076     return exec();
0077 }
0078 void PersonDialog::setVisible(bool visible)
0079 {
0080     ui->m_characterName->selectAll();
0081     QDialog::setVisible(visible);
0082 }
0083 void PersonDialog::clickOnBar(QAbstractButton* btn)
0084 {
0085     if(QDialogButtonBox::ResetRole == ui->buttonBox->buttonRole(btn))
0086     {
0087         reset();
0088     }
0089 }
0090 void PersonDialog::reset()
0091 {
0092     ui->m_selectCharaterAvatar->setIcon(QIcon());
0093     ui->m_characterColor->setColor(QColor());
0094     ui->m_characterName->setText("");
0095 }