diff --git a/retroshare-gui/src/gui/settings/NewTag.cpp b/retroshare-gui/src/gui/settings/NewTag.cpp new file mode 100644 index 000000000..89718593a --- /dev/null +++ b/retroshare-gui/src/gui/settings/NewTag.cpp @@ -0,0 +1,135 @@ +/**************************************************************** + * RetroShare is distributed under the following license: + * + * Copyright (C) 2006 - 2009, RetroShre Team + * + * 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 2 + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + ****************************************************************/ +#include "NewTag.h" + +#include + +/** Default constructor */ +NewTag::NewTag(std::map &Items, int nId /*= 0*/, QWidget *parent, Qt::WFlags flags) + : QDialog(parent, flags), m_Items(Items) +{ + /* Invoke Qt Designer generated QObject setup routine */ + ui.setupUi(this); + + m_nId = nId; + + connect(ui.okButton, SIGNAL(clicked()), this, SLOT(OnOK())); + connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(OnCancel())); + connect(ui.colorButton, SIGNAL(clicked()), this, SLOT(setTagColor())); + + connect(ui.lineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(textChanged(const QString &))); + + ui.okButton->setEnabled(false); + + if (m_nId) { + TagItem &Item = m_Items [m_nId]; + ui.lineEdit->setText(Item.text); + m_Color = Item.color; + + if (m_nId < 0) { + // standard tag + ui.lineEdit->setEnabled(false); + } + } else { + m_Color = 0; + } + + showColor (m_Color); +} + +void NewTag::closeEvent (QCloseEvent * event) +{ + QDialog::closeEvent(event); +} + +void NewTag::OnOK() +{ + TagItem Item; + Item.text = ui.lineEdit->text(); + Item.color = m_Color; + + if (m_nId == 0) { + // calculate new id + m_nId = 1; + std::map::iterator Item; + for (Item = m_Items.begin(); Item != m_Items.end(); Item++) { + if (Item->first + 1 > m_nId) { + m_nId = Item->first + 1; + } + } + } + + m_Items [m_nId] = Item; + + setResult(QDialog::Accepted); + hide(); +} + +void NewTag::OnCancel() +{ + setResult(QDialog::Rejected); + hide(); +} + +void NewTag::textChanged(const QString &text) +{ + bool bEnabled = true; + + if (text.isEmpty()) { + bEnabled = false; + } else { + // check for existing text + std::map::iterator Item; + for (Item = m_Items.begin(); Item != m_Items.end(); Item++) { + if (m_nId && Item->first == m_nId) { + continue; + } + + if (Item->second._delete) { + continue; + } + + if (Item->second.text == text) { + bEnabled = false; + break; + } + } + } + + ui.okButton->setEnabled(bEnabled); +} + +void NewTag::setTagColor() +{ + bool ok; + QRgb color = QColorDialog::getRgba(m_Color, &ok, this); + if (ok) { + m_Color = color; + showColor (m_Color); + } +} + +void NewTag::showColor(QRgb color) +{ + QPixmap pxm(16,16); + pxm.fill(QColor(m_Color)); + ui.colorButton->setIcon(pxm); +} diff --git a/retroshare-gui/src/gui/settings/NewTag.h b/retroshare-gui/src/gui/settings/NewTag.h new file mode 100644 index 000000000..d2bdc9a94 --- /dev/null +++ b/retroshare-gui/src/gui/settings/NewTag.h @@ -0,0 +1,75 @@ +/**************************************************************** + * RetroShare is distributed under the following license: + * + * Copyright (C) 2006 - 2010, RetroShare Team + * + * 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 2 + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + ****************************************************************/ + +#ifndef _NEWTAG_H +#define _NEWTAG_H + +#include + +#include "ui_NewTag.h" + +class TagItem +{ +public: + TagItem() + { + _delete = false; + }; + + QString text; + QRgb color; + + bool _delete; // for internal use +}; + +class NewTag : public QDialog +{ + Q_OBJECT + +public: + /** Default constructor */ + NewTag(std::map &Items, int nId = 0, QWidget *parent = 0, Qt::WFlags flags = 0); + + int m_nId; + +protected: + void closeEvent (QCloseEvent * event); + +private slots: + void OnOK(); + void OnCancel(); + + void textChanged(const QString &); + + void setTagColor(); + +private: + void showColor(QRgb color); + + std::map &m_Items; + QRgb m_Color; + + /** Qt Designer generated object */ + Ui::NewTag ui; +}; + +#endif + diff --git a/retroshare-gui/src/gui/settings/NewTag.ui b/retroshare-gui/src/gui/settings/NewTag.ui new file mode 100644 index 000000000..e0a113582 --- /dev/null +++ b/retroshare-gui/src/gui/settings/NewTag.ui @@ -0,0 +1,123 @@ + + + NewTag + + + + 0 + 0 + 320 + 105 + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 367777 + 367777 + + + + New Tag + + + + :/images/rstray3.png:/images/rstray3.png + + + + + + + + + 16777215 + 22 + + + + Tag Name: + + + + + + + + + + + + + + + + + Qt::Horizontal + + + + 135 + 20 + + + + + + + + OK + + + true + + + + + + + Cancel + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + + + + +