Added tags to the MessageComposer.

Added context menu to contact list in MessageComposer.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4213 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2011-05-21 16:26:00 +00:00
parent 4c13280fed
commit f14b529009
13 changed files with 807 additions and 423 deletions

View file

@ -53,8 +53,12 @@
#include "gui/common/Emoticons.h"
#include "textformat.h"
#include "util/misc.h"
#include "TagsMenu.h"
#include "gui/common/TagDefs.h"
#include "gui/connect/ConfCertDialog.h"
#define IMAGE_GROUP16 ":/images/user/group16.png"
#define IMAGE_GROUP16 ":/images/user/group16.png"
#define IMAGE_FRIENDINFO ":/images/peerdetails_16x16.png"
#define COLUMN_CONTACT_NAME 0
#define COLUMN_CONTACT_DATA 0
@ -161,6 +165,7 @@ MessageComposer::MessageComposer(QWidget *parent, Qt::WFlags flags)
connect(ui.msgText->document(), SIGNAL(redoAvailable(bool)), actionRedo, SLOT(setEnabled(bool)));
connect(ui.msgFileList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuFileList(QPoint)));
connect(ui.msgSendList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuMsgSendList(QPoint)));
setWindowModified(ui.msgText->document()->isModified());
actionSave->setEnabled(ui.msgText->document()->isModified());
@ -182,11 +187,11 @@ MessageComposer::MessageComposer(QWidget *parent, Qt::WFlags flags)
connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(clipboardDataChanged()));
connect(ui.addToButton, SIGNAL(clicked(void)), this, SLOT(btnClickEvent()));
connect(ui.addCcButton, SIGNAL(clicked(void)), this, SLOT(btnClickEvent()));
connect(ui.addBccButton, SIGNAL(clicked(void)), this, SLOT(btnClickEvent()));
connect(ui.addRecommendButton, SIGNAL(clicked(void)), this, SLOT(recommendButtonClicked()));
connect(ui.msgSendList, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(btnClickEvent()));
connect(ui.addToButton, SIGNAL(clicked(void)), this, SLOT(addTo()));
connect(ui.addCcButton, SIGNAL(clicked(void)), this, SLOT(addCc()));
connect(ui.addBccButton, SIGNAL(clicked(void)), this, SLOT(addBcc()));
connect(ui.addRecommendButton, SIGNAL(clicked(void)), this, SLOT(addRecommend()));
connect(ui.msgSendList, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(addTo()));
connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)), this, SLOT(groupsChanged(int)));
connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(const QString&,int)), this, SLOT(peerStatusChanged(const QString&,int)));
@ -289,6 +294,14 @@ MessageComposer::MessageComposer(QWidget *parent, Qt::WFlags flags)
/* set focus to subject */
ui.titleEdit->setFocus();
// create tag menu
TagsMenu *menu = new TagsMenu (tr("Tags"), this);
connect(menu, SIGNAL(aboutToShow()), this, SLOT(tagAboutToShow()));
connect(menu, SIGNAL(tagSet(int, bool)), this, SLOT(tagSet(int, bool)));
connect(menu, SIGNAL(tagRemoveAll()), this, SLOT(tagRemoveAll()));
ui.tagButton->setMenu(menu);
setAcceptDrops(true);
#ifdef RS_RELEASE_VERSION
@ -473,6 +486,29 @@ void MessageComposer::contextMenuFileList(QPoint)
contextMnu.exec(QCursor::pos());
}
void MessageComposer::contextMenuMsgSendList(QPoint)
{
QMenu contextMnu(this);
int selectedCount = ui.msgSendList->selectedItems().count();
QAction *action = contextMnu.addAction(QIcon(), tr("Add to \"To\""), this, SLOT(addTo()));
action->setEnabled(selectedCount);
action = contextMnu.addAction(QIcon(), tr("Add to \"CC\""), this, SLOT(addCc()));
action->setEnabled(selectedCount);
action = contextMnu.addAction(QIcon(), tr("Add to \"BCC\""), this, SLOT(addBcc()));
action->setEnabled(selectedCount);
action = contextMnu.addAction(QIcon(), tr("Add as Recommend"), this, SLOT(addRecommend()));
action->setEnabled(selectedCount);
contextMnu.addSeparator();
action = contextMnu.addAction(QIcon(IMAGE_FRIENDINFO), tr("Friend Details"), this, SLOT(friendDetails()));
action->setEnabled(selectedCount == 1);
contextMnu.exec(QCursor::pos());
}
void MessageComposer::pasteRecommended()
{
std::vector<RetroShareLink> links;
@ -943,6 +979,12 @@ MessageComposer *MessageComposer::newMsg(const std::string &msgId /*= ""*/)
msgComposer->addRecipient(MessageComposer::BCC, *it, false) ;
}
MsgTagInfo tagInfo;
rsMsgs->getMessageTag(msgId, tagInfo);
msgComposer->m_tagIds = tagInfo.tagIds;
msgComposer->showTagLabels();
msgComposer->ui.msgText->document()->setModified(false);
}
@ -1261,6 +1303,25 @@ bool MessageComposer::sendMessage_internal(bool bDraftbox)
}
}
if (mi.msgId.empty() == false) {
MsgTagInfo tagInfo;
rsMsgs->getMessageTag(mi.msgId, tagInfo);
/* insert new tags */
std::list<uint32_t>::iterator tag;
for (tag = m_tagIds.begin(); tag != m_tagIds.end(); tag++) {
if (std::find(tagInfo.tagIds.begin(), tagInfo.tagIds.end(), *tag) == tagInfo.tagIds.end()) {
rsMsgs->setMessageTag(mi.msgId, *tag, true);
} else {
tagInfo.tagIds.remove(*tag);
}
}
/* remove deleted tags */
for (tag = tagInfo.tagIds.begin(); tag != tagInfo.tagIds.end(); tag++) {
rsMsgs->setMessageTag(mi.msgId, *tag, false);
}
}
ui.msgText->document()->setModified(false);
return true;
}
@ -2302,19 +2363,8 @@ bool MessageComposer::FilterItem(QTreeWidgetItem *pItem, QString &sPattern)
return (bVisible || nVisibleChildCount);
}
void MessageComposer::btnClickEvent()
void MessageComposer::addContact(enumType type)
{
enumType type;
if (QObject::sender() == ui.addToButton || QObject::sender() == ui.msgSendList) {
type = TO;
} else if (QObject::sender() == ui.addCcButton) {
type = CC;
} else if (QObject::sender() == ui.addBccButton) {
type = BCC;
} else {
return;
}
QTreeWidgetItemIterator itemIterator(ui.msgSendList);
QTreeWidgetItem *item;
while ((item = *itemIterator) != NULL) {
@ -2328,7 +2378,22 @@ void MessageComposer::btnClickEvent()
}
}
void MessageComposer::recommendButtonClicked()
void MessageComposer::addTo()
{
addContact(TO);
}
void MessageComposer::addCc()
{
addContact(CC);
}
void MessageComposer::addBcc()
{
addContact(BCC);
}
void MessageComposer::addRecommend()
{
std::list<std::string> gpgIds;
@ -2375,6 +2440,22 @@ void MessageComposer::recommendButtonClicked()
ui.msgText->setFocus(Qt::OtherFocusReason);
}
void MessageComposer::friendDetails()
{
QList<QTreeWidgetItem*> selectedItems = ui.msgSendList->selectedItems();
if (selectedItems.count() != 1) {
return;
}
QTreeWidgetItem *item = selectedItems[0];
if (item->type() == TYPE_GROUP) {
return;
}
std::string id = item->data(COLUMN_CONTACT_DATA, ROLE_CONTACT_ID).toString().toStdString();
ConfCertDialog::showIt(id, ConfCertDialog::PageDetails);
}
void MessageComposer::dragEnterEvent(QDragEnterEvent *event)
{
/* print out mimeType */
@ -2450,3 +2531,78 @@ void MessageComposer::dropEvent(QDropEvent *event)
event->setDropAction(Qt::CopyAction);
event->accept();
}
void MessageComposer::tagAboutToShow()
{
TagsMenu *menu = dynamic_cast<TagsMenu*>(ui.tagButton->menu());
if (menu == NULL) {
return;
}
menu->activateActions(m_tagIds);
}
void MessageComposer::tagRemoveAll()
{
m_tagIds.clear();
showTagLabels();
}
void MessageComposer::tagSet(int tagId, bool set)
{
if (tagId == 0) {
return;
}
std::list<uint32_t>::iterator tag = std::find(m_tagIds.begin(), m_tagIds.end(), tagId);
if (tag == m_tagIds.end()) {
if (set) {
m_tagIds.push_back(tagId);
/* Keep the list sorted */
m_tagIds.sort();
}
} else {
if (set == false) {
m_tagIds.remove(tagId);
}
}
showTagLabels();
}
void MessageComposer::clearTagLabels()
{
/* clear all tags */
while (tagLabels.size()) {
delete tagLabels.front();
tagLabels.pop_front();
}
while (ui.tagLayout->count()) {
delete ui.tagLayout->takeAt(0);
}
}
void MessageComposer::showTagLabels()
{
clearTagLabels();
if (m_tagIds.empty() == false) {
MsgTagType tags;
rsMsgs->getMessageTagTypes(tags);
std::map<uint32_t, std::pair<std::string, uint32_t> >::iterator tag;
for (std::list<uint32_t>::iterator tagId = m_tagIds.begin(); tagId != m_tagIds.end(); tagId++) {
tag = tags.types.find(*tagId);
if (tag != tags.types.end()) {
QLabel *tagLabel = new QLabel(TagDefs::name(tag->first, tag->second.first), this);
tagLabel->setMaximumHeight(16);
tagLabel->setStyleSheet(TagDefs::labelStyleSheet(tag->second.second));
tagLabels.push_back(tagLabel);
ui.tagLayout->addWidget(tagLabel);
ui.tagLayout->addSpacing(3);
}
}
ui.tagLayout->addStretch();
}
}

View file

@ -88,6 +88,7 @@ private slots:
void contextMenu(QPoint);
void pasteLink();
void contextMenuFileList(QPoint);
void contextMenuMsgSendList(QPoint);
void pasteRecommended();
void on_contactsdockWidget_visibilityChanged(bool visible);
void toggleContacts();
@ -135,16 +136,24 @@ private slots:
void titleChanged();
// Add to To/Cc/Bcc address fields
void btnClickEvent();
void recommendButtonClicked();
void addTo();
void addCc();
void addBcc();
void addRecommend();
void editingRecipientFinished();
void friendDetails();
void groupsChanged(int type);
void peerStatusChanged(const QString& peer_id, int status);
void tagAboutToShow();
void tagSet(int tagId, bool set);
void tagRemoveAll();
private:
void processSettings(bool bLoad);
void addContact(enumType type);
void setTextColor(const QColor& col) ;
void setupFileActions();
void setupEditActions();
@ -173,6 +182,9 @@ private:
bool getRecipientFromRow(int row, enumType &type, std::string &id, bool &group);
void setRecipientToRow(int row, enumType type, std::string id, bool group);
void clearTagLabels();
void showTagLabels();
QAction *actionSave,
*actionAlignLeft,
*actionAlignCenter,
@ -201,6 +213,8 @@ private:
std::string m_msgParentId; // parent message id
std::string m_sDraftMsgId; // existing message id
enumMessageType m_msgType;
std::list<uint32_t> m_tagIds;
QList<QLabel*> tagLabels;
/* maps of files */
std::list<AttachFileItem *> mAttachments;

View file

@ -17,7 +17,7 @@
<string>Compose</string>
</property>
<property name="windowIcon">
<iconset resource="../images.qrc">
<iconset>
<normaloff>:/images/folder-draft.png</normaloff>:/images/folder-draft.png</iconset>
</property>
<property name="styleSheet">
@ -168,6 +168,9 @@ border-image: url(:/images/closepressed.png)
<height>0</height>
</size>
</property>
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
@ -394,7 +397,7 @@ border: 1px solid #CCCCCC;}</string>
<string/>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<iconset>
<normaloff>:/images/textedit/format_font_size_more.png</normaloff>:/images/textedit/format_font_size_more.png</iconset>
</property>
<property name="iconSize">
@ -426,7 +429,7 @@ border: 1px solid #CCCCCC;}</string>
<string/>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<iconset>
<normaloff>:/images/textedit/format_font_size_less.png</normaloff>:/images/textedit/format_font_size_less.png</iconset>
</property>
<property name="iconSize">
@ -464,7 +467,7 @@ border: 1px solid #CCCCCC;}</string>
<string/>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<iconset>
<normaloff>:/images/textedit/textbold.png</normaloff>:/images/textedit/textbold.png</iconset>
</property>
<property name="iconSize">
@ -505,7 +508,7 @@ border: 1px solid #CCCCCC;}</string>
<string/>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<iconset>
<normaloff>:/images/textedit/textitalic.png</normaloff>:/images/textedit/textitalic.png</iconset>
</property>
<property name="iconSize">
@ -611,7 +614,7 @@ border: 1px solid #CCCCCC;}</string>
<string/>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<iconset>
<normaloff>:/images/add_image24.png</normaloff>:/images/add_image24.png</iconset>
</property>
<property name="iconSize">
@ -637,7 +640,7 @@ border: 1px solid #CCCCCC;}</string>
<string/>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<iconset>
<normaloff>:/images/textedit/hi22-action-format-text-code.png</normaloff>:/images/textedit/hi22-action-format-text-code.png</iconset>
</property>
<property name="iconSize">
@ -670,7 +673,7 @@ border: 1px solid #CCCCCC;}</string>
<enum>Qt::NoFocus</enum>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<iconset>
<normaloff>:/images/emoticons/kopete/kopete020.png</normaloff>:/images/emoticons/kopete/kopete020.png</iconset>
</property>
<property name="iconSize">
@ -708,7 +711,7 @@ border: 1px solid #CCCCCC;}</string>
<string/>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<iconset>
<normaloff>:/images/textedit/textunder.png</normaloff>:/images/textedit/textunder.png</iconset>
</property>
<property name="iconSize">
@ -746,33 +749,6 @@ border: 1px solid #CCCCCC;}</string>
</property>
</widget>
</item>
<item row="2" column="0" rowspan="2">
<layout class="QHBoxLayout" name="SubjectHLayout" stretch="0,0">
<property name="spacing">
<number>6</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetNoConstraint</enum>
</property>
<item>
<widget class="QLabel" name="label_3">
<property name="font">
<font>
<pointsize>10</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Subject:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="titleEdit"/>
</item>
</layout>
</item>
<item row="0" column="0">
<widget class="QTableWidget" name="recipientWidget">
<property name="sizePolicy">
@ -819,6 +795,72 @@ border: 1px solid #CCCCCC;}</string>
</attribute>
</widget>
</item>
<item row="2" column="0" rowspan="2">
<layout class="QGridLayout" name="gridLayout_6">
<property name="sizeConstraint">
<enum>QLayout::SetNoConstraint</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Subject:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1" colspan="5">
<widget class="QLineEdit" name="titleEdit"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Tags:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="tagButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Tags</string>
</property>
<property name="icon">
<iconset>
<normaloff>:/images/tag24.png</normaloff>:/images/tag24.png</iconset>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="3">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="2">
<layout class="QHBoxLayout" name="tagLayout"/>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="layoutWidget_1">
@ -964,7 +1006,7 @@ border: 1px solid #CCCCCC;}</string>
</widget>
<action name="actionSend">
<property name="icon">
<iconset resource="../images.qrc">
<iconset>
<normaloff>:/images/send24.png</normaloff>:/images/send24.png</iconset>
</property>
<property name="text">
@ -976,7 +1018,7 @@ border: 1px solid #CCCCCC;}</string>
</action>
<action name="actionReply">
<property name="icon">
<iconset resource="../images.qrc">
<iconset>
<normaloff>:/images/replymail24.png</normaloff>:/images/replymail24.png</iconset>
</property>
<property name="text">
@ -985,7 +1027,7 @@ border: 1px solid #CCCCCC;}</string>
</action>
<action name="actionContactsView">
<property name="icon">
<iconset resource="../images.qrc">
<iconset>
<normaloff>:/images/contacts24.png</normaloff>:/images/contacts24.png</iconset>
</property>
<property name="text">
@ -997,7 +1039,7 @@ border: 1px solid #CCCCCC;}</string>
</action>
<action name="actionSaveas">
<property name="icon">
<iconset resource="../images.qrc">
<iconset>
<normaloff>:/images/save24.png</normaloff>:/images/save24.png</iconset>
</property>
<property name="text">
@ -1009,7 +1051,7 @@ border: 1px solid #CCCCCC;}</string>
</action>
<action name="actionAttach">
<property name="icon">
<iconset resource="../images.qrc">
<iconset>
<normaloff>:/images/attach.png</normaloff>:/images/attach.png</iconset>
</property>
<property name="text">
@ -1024,7 +1066,7 @@ border: 1px solid #CCCCCC;}</string>
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<iconset>
<normaloff>:/images/quote_24.png</normaloff>:/images/quote_24.png</iconset>
</property>
<property name="text">
@ -1051,8 +1093,6 @@ border: 1px solid #CCCCCC;}</string>
<tabstop>comboFont</tabstop>
<tabstop>hashBox</tabstop>
</tabstops>
<resources>
<include location="../images.qrc"/>
</resources>
<resources/>
<connections/>
</ui>

View file

@ -0,0 +1,199 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2006,2007 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.
****************************************************************/
#include <QPainter>
#include <QPaintEvent>
#include <QStyleOptionMenuItem>
#include <algorithm>
#include <retroshare/rsmsgs.h>
#include "TagsMenu.h"
#include "gui/common/TagDefs.h"
#include "gui/settings/NewTag.h"
#include "gui/notifyqt.h"
#define ACTION_TAGSINDEX_SIZE 3
#define ACTION_TAGSINDEX_TYPE "Type"
#define ACTION_TAGSINDEX_ID "ID"
#define ACTION_TAGSINDEX_COLOR "Color"
#define ACTION_TAGS_REMOVEALL 0
#define ACTION_TAGS_TAG 1
#define ACTION_TAGS_NEWTAG 2
TagsMenu::TagsMenu(const QString &title, QWidget *parent)
: QMenu (title, parent)
{
connect(this, SIGNAL(triggered (QAction*)), this, SLOT(tagTriggered(QAction*)));
connect(NotifyQt::getInstance(), SIGNAL(messagesTagsChanged()), this, SLOT(fillTags()));
fillTags();
}
void TagsMenu::paintEvent(QPaintEvent *e)
{
QMenu::paintEvent(e);
QPainter p(this);
QRegion emptyArea = QRegion(rect());
//draw the items with color
foreach (QAction *action, actions()) {
QRect adjustedActionRect = actionGeometry(action);
if (!e->rect().intersects(adjustedActionRect))
continue;
const QMap<QString, QVariant> &values = action->data().toMap();
if (values.size () != ACTION_TAGSINDEX_SIZE) {
continue;
}
if (values [ACTION_TAGSINDEX_TYPE] != ACTION_TAGS_TAG) {
continue;
}
//set the clip region to be extra safe (and adjust for the scrollers)
QRegion adjustedActionReg(adjustedActionRect);
emptyArea -= adjustedActionReg;
p.setClipRegion(adjustedActionReg);
QStyleOptionMenuItem opt;
initStyleOption(&opt, action);
opt.palette.setColor(QPalette::ButtonText, QColor(values [ACTION_TAGSINDEX_COLOR].toInt()));
// needed for Cleanlooks
opt.palette.setColor(QPalette::Text, QColor(values [ACTION_TAGSINDEX_COLOR].toInt()));
opt.rect = adjustedActionRect;
style()->drawControl(QStyle::CE_MenuItem, &opt, &p, this);
}
}
void TagsMenu::fillTags()
{
clear();
MsgTagType tags;
rsMsgs->getMessageTagTypes(tags);
std::map<uint32_t, std::pair<std::string, uint32_t> >::iterator tag;
bool user = false;
QString text;
QAction *action;
QMap<QString, QVariant> values;
if (tags.types.size()) {
action = new QAction(tr("Remove All Tags"), this);
values [ACTION_TAGSINDEX_TYPE] = ACTION_TAGS_REMOVEALL;
values [ACTION_TAGSINDEX_ID] = 0;
values [ACTION_TAGSINDEX_COLOR] = 0;
action->setData (values);
addAction(action);
addSeparator();
for (tag = tags.types.begin(); tag != tags.types.end(); tag++) {
text = TagDefs::name(tag->first, tag->second.first);
action = new QAction(text, this);
values [ACTION_TAGSINDEX_TYPE] = ACTION_TAGS_TAG;
values [ACTION_TAGSINDEX_ID] = tag->first;
values [ACTION_TAGSINDEX_COLOR] = QRgb(tag->second.second);
action->setData (values);
action->setCheckable(true);
if (tag->first >= RS_MSGTAGTYPE_USER && user == false) {
user = true;
addSeparator();
}
addAction(action);
}
addSeparator();
}
action = new QAction(tr("New tag ..."), this);
values [ACTION_TAGSINDEX_TYPE] = ACTION_TAGS_NEWTAG;
values [ACTION_TAGSINDEX_ID] = 0;
values [ACTION_TAGSINDEX_COLOR] = 0;
action->setData (values);
addAction(action);
}
void TagsMenu::activateActions(std::list<uint32_t>& tagIds)
{
foreach(QObject *object, children()) {
QAction *action = qobject_cast<QAction*> (object);
if (action == NULL) {
continue;
}
const QMap<QString, QVariant> &values = action->data().toMap();
if (values.size () != ACTION_TAGSINDEX_SIZE) {
continue;
}
if (values [ACTION_TAGSINDEX_TYPE] != ACTION_TAGS_TAG) {
continue;
}
std::list<uint32_t>::iterator tagId = std::find(tagIds.begin(), tagIds.end(), values [ACTION_TAGSINDEX_ID]);
action->setChecked(tagId != tagIds.end());
}
}
void TagsMenu::tagTriggered(QAction *action)
{
if (action == NULL) {
return;
}
const QMap<QString, QVariant> &values = action->data().toMap();
if (values.size () != ACTION_TAGSINDEX_SIZE) {
return;
}
if (values [ACTION_TAGSINDEX_TYPE] == ACTION_TAGS_REMOVEALL) {
// remove all tags
emit tagRemoveAll();
} else if (values [ACTION_TAGSINDEX_TYPE] == ACTION_TAGS_NEWTAG) {
// new tag
MsgTagType tags;
rsMsgs->getMessageTagTypes(tags);
NewTag tagDlg(tags);
if (tagDlg.exec() == QDialog::Accepted && tagDlg.m_nId) {
std::map<uint32_t, std::pair<std::string, uint32_t> >::iterator tag = tags.types.find(tagDlg.m_nId);
if (tag != tags.types.end()) {
if (rsMsgs->setMessageTagType(tag->first, tag->second.first, tag->second.second)) {
emit tagSet(tagDlg.m_nId, true);
}
}
}
} else if (values [ACTION_TAGSINDEX_TYPE].toInt() == ACTION_TAGS_TAG) {
int tagId = values [ACTION_TAGSINDEX_ID].toInt();
if (tagId) {
emit tagSet(tagId, action->isChecked());
}
}
}

View file

@ -0,0 +1,48 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2007, 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 _TAGSMENU_H
#define _TAGSMENU_H
#include <QMenu>
class TagsMenu : public QMenu
{
Q_OBJECT
public:
TagsMenu(const QString &title, QWidget *parent);
void activateActions(std::list<uint32_t>& tagIds);
signals:
void tagSet(int tagId, bool set);
void tagRemoveAll();
protected:
virtual void paintEvent(QPaintEvent *e);
private slots:
void fillTags();
void tagTriggered(QAction *action);
};
#endif