Copy RsTreeWidget Header ContextMenu to Item ContextMenu.

This commit is contained in:
Phenom 2016-08-05 18:15:21 +02:00
parent d1645e97bd
commit 8a5c07b5e2
5 changed files with 221 additions and 141 deletions

View File

@ -25,6 +25,7 @@
#include <QMessageBox>
#include <QMenu>
#include <QWidgetAction>
#include "IdDialog.h"
#include "ui_IdDialog.h"
@ -224,8 +225,8 @@ IdDialog::IdDialog(QWidget *parent) :
ui->splitter->setSizes(sizes);*/
/* Add filter types */
QMenu *idTWHMenu = new QMenu(tr("Show"), this);
ui->idTreeWidget->addHeaderContextMenuMenu(idTWHMenu);
QMenu *idTWHMenu = new QMenu(tr("Show Items"), this);
ui->idTreeWidget->addContextMenuMenu(idTWHMenu);
QActionGroup *idTWHActionGroup = new QActionGroup(this);
QAction *idTWHAction = new QAction(QIcon(),tr("All"), this);
@ -2052,7 +2053,7 @@ void IdDialog::loadRequest(const TokenQueue * queue, const TokenRequest &req)
void IdDialog::IdListCustomPopupMenu( QPoint )
{
QMenu contextMnu( this );
QMenu *contextMenu = new QMenu(this);
std::list<RsGxsId> own_identities ;
@ -2112,77 +2113,105 @@ void IdDialog::IdListCustomPopupMenu( QPoint )
++n_is_not_a_contact ;
}
if(root_node_present) // don't show menu if some of the root nodes are present
return ;
if(!one_item_owned_by_you)
{
if(n_selected_items == 1) // if only one item is selected, allow to chat with this item
if(!root_node_present) // don't show menu if some of the root nodes are present
{
if(own_identities.size() <= 1)
{
QAction *action = contextMnu.addAction(QIcon(":/images/chat_24.png"), tr("Chat with this person"), this, SLOT(chatIdentity()));
if(own_identities.empty())
action->setEnabled(false) ;
else
action->setData(QString::fromStdString((own_identities.front()).toStdString())) ;
}
else
{
QMenu *mnu = contextMnu.addMenu(QIcon(":/images/chat_24.png"),tr("Chat with this person as...")) ;
if(!one_item_owned_by_you)
{
QWidget *widget = new QWidget(contextMenu);
widget->setStyleSheet( ".QWidget{background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,stop:0 #FEFEFE, stop:1 #E8E8E8); border: 1px solid #CCCCCC;}");
for(std::list<RsGxsId>::const_iterator it=own_identities.begin();it!=own_identities.end();++it)
{
RsIdentityDetails idd ;
rsIdentity->getIdDetails(*it,idd) ;
// create menu header
QHBoxLayout *hbox = new QHBoxLayout(widget);
hbox->setMargin(0);
hbox->setSpacing(6);
QPixmap pixmap ;
QLabel *iconLabel = new QLabel(widget);
QPixmap pix = QPixmap(":/images/user/friends24.png").scaledToHeight(QFontMetricsF(iconLabel->font()).height()*1.5);
iconLabel->setPixmap(pix);
iconLabel->setMaximumSize(iconLabel->frameSize().height() + pix.height(), pix.width());
hbox->addWidget(iconLabel);
if(idd.mAvatar.mSize == 0 || !pixmap.loadFromData(idd.mAvatar.mData, idd.mAvatar.mSize, "PNG"))
pixmap = QPixmap::fromImage(GxsIdDetails::makeDefaultIcon(*it)) ;
QLabel *textLabel = new QLabel("<strong>" + ui->titleBarLabel->text() + "</strong>", widget);
hbox->addWidget(textLabel);
QSpacerItem *spacerItem = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
hbox->addItem(spacerItem);
widget->setLayout(hbox);
QWidgetAction *widgetAction = new QWidgetAction(this);
widgetAction->setDefaultWidget(widget);
contextMenu->addAction(widgetAction);
if(n_selected_items == 1) // if only one item is selected, allow to chat with this item
{
if(own_identities.size() <= 1)
{
QAction *action = contextMenu->addAction(QIcon(":/images/chat_24.png"), tr("Chat with this person"), this, SLOT(chatIdentity()));
if(own_identities.empty())
action->setEnabled(false) ;
else
action->setData(QString::fromStdString((own_identities.front()).toStdString())) ;
}
else
{
QMenu *mnu = contextMenu->addMenu(QIcon(":/images/chat_24.png"),tr("Chat with this person as...")) ;
for(std::list<RsGxsId>::const_iterator it=own_identities.begin();it!=own_identities.end();++it)
{
RsIdentityDetails idd ;
rsIdentity->getIdDetails(*it,idd) ;
QPixmap pixmap ;
if(idd.mAvatar.mSize == 0 || !pixmap.loadFromData(idd.mAvatar.mData, idd.mAvatar.mSize, "PNG"))
pixmap = QPixmap::fromImage(GxsIdDetails::makeDefaultIcon(*it)) ;
QAction *action = mnu->addAction(QIcon(pixmap), QString("%1 (%2)").arg(QString::fromUtf8(idd.mNickname.c_str()), QString::fromStdString((*it).toStdString())), this, SLOT(chatIdentity()));
action->setData(QString::fromStdString((*it).toStdString())) ;
}
}
}
// always allow to send messages
contextMenu->addAction(QIcon(":/images/mail_new.png"), tr("Send message"), this, SLOT(sendMsg()));
contextMenu->addSeparator();
if(n_is_a_contact == 0)
contextMenu->addAction(QIcon(), tr("Add to Contacts"), this, SLOT(addtoContacts()));
if(n_is_not_a_contact == 0)
contextMenu->addAction(QIcon(":/images/cancel.png"), tr("Remove from Contacts"), this, SLOT(removefromContacts()));
contextMenu->addSeparator();
if(n_positive_reputations == 0) // only unban when all items are banned
contextMenu->addAction(QIcon(":/images/vote_up.png"), tr("Set positive opinion"), this, SLOT(positivePerson()));
if(n_neutral_reputations == 0) // only unban when all items are banned
contextMenu->addAction(QIcon(":/images/vote_neutral.png"), tr("Set neutral opinion"), this, SLOT(neutralPerson()));
if(n_negative_reputations == 0)
contextMenu->addAction(QIcon(":/images/vote_down.png"), tr("Set negative opinion"), this, SLOT(negativePerson()));
}
if(one_item_owned_by_you && n_selected_items==1)
{
contextMenu->addSeparator();
contextMenu->addAction(ui->editIdentity);
contextMenu->addAction(ui->removeIdentity);
}
QAction *action = mnu->addAction(QIcon(pixmap), QString("%1 (%2)").arg(QString::fromUtf8(idd.mNickname.c_str()), QString::fromStdString((*it).toStdString())), this, SLOT(chatIdentity()));
action->setData(QString::fromStdString((*it).toStdString())) ;
}
}
}
// always allow to send messages
contextMnu.addAction(QIcon(":/images/mail_new.png"), tr("Send message"), this, SLOT(sendMsg()));
contextMenu = ui->idTreeWidget->createStandardContextMenu(contextMenu);
contextMnu.addSeparator();
if(n_is_a_contact == 0)
contextMnu.addAction(QIcon(), tr("Add to Contacts"), this, SLOT(addtoContacts()));
if(n_is_not_a_contact == 0)
contextMnu.addAction(QIcon(":/images/cancel.png"), tr("Remove from Contacts"), this, SLOT(removefromContacts()));
contextMnu.addSeparator();
if(n_positive_reputations == 0) // only unban when all items are banned
contextMnu.addAction(QIcon(":/images/vote_up.png"), tr("Set positive opinion"), this, SLOT(positivePerson()));
if(n_neutral_reputations == 0) // only unban when all items are banned
contextMnu.addAction(QIcon(":/images/vote_neutral.png"), tr("Set neutral opinion"), this, SLOT(neutralPerson()));
if(n_negative_reputations == 0)
contextMnu.addAction(QIcon(":/images/vote_down.png"), tr("Set negative opinion"), this, SLOT(negativePerson()));
}
if(one_item_owned_by_you && n_selected_items==1)
{
contextMnu.addSeparator();
contextMnu.addAction(ui->editIdentity);
contextMnu.addAction(ui->removeIdentity);
}
contextMnu.addSeparator();
contextMnu.exec(QCursor::pos());
contextMenu->exec(QCursor::pos());
delete contextMenu;
}
void IdDialog::chatIdentity()

View File

@ -140,7 +140,7 @@ FriendList::FriendList(QWidget *parent) :
mActionSortByState = new QAction(tr("Sort by state"), this);
mActionSortByState->setCheckable(true);
connect(mActionSortByState, SIGNAL(toggled(bool)), this, SLOT(sortByState(bool)));
ui->peerTreeWidget->addHeaderContextMenuAction(mActionSortByState);
ui->peerTreeWidget->addContextMenuAction(mActionSortByState);
/* Set sort */
sortByColumn(COLUMN_NAME, Qt::AscendingOrder);
@ -282,9 +282,9 @@ void FriendList::peerTreeWidgetCustomPopupMenu()
{
QTreeWidgetItem *c = getCurrentPeer();
QMenu contextMnu(this);
QMenu *contextMenu = new QMenu(this);
QWidget *widget = new QWidget(&contextMnu);
QWidget *widget = new QWidget(contextMenu);
widget->setStyleSheet( ".QWidget{background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,stop:0 #FEFEFE, stop:1 #E8E8E8); border: 1px solid #CCCCCC;}");
// create menu header
@ -293,8 +293,9 @@ void FriendList::peerTreeWidgetCustomPopupMenu()
hbox->setSpacing(6);
QLabel *iconLabel = new QLabel(widget);
iconLabel->setPixmap(QPixmap(":/images/user/friends24.png"));
iconLabel->setMaximumSize(iconLabel->frameSize().height() + 24, 24);
QPixmap pix = QPixmap(":/images/user/friends24.png").scaledToHeight(QFontMetricsF(iconLabel->font()).height()*1.5);
iconLabel->setPixmap(pix);
iconLabel->setMaximumSize(iconLabel->frameSize().height() + pix.height(), pix.width());
hbox->addWidget(iconLabel);
QLabel *textLabel = new QLabel("<strong>RetroShare</strong>", widget);
@ -307,7 +308,7 @@ void FriendList::peerTreeWidgetCustomPopupMenu()
QWidgetAction *widgetAction = new QWidgetAction(this);
widgetAction->setDefaultWidget(widget);
contextMnu.addAction(widgetAction);
contextMenu->addAction(widgetAction);
// create menu entries
if (c)
@ -337,23 +338,23 @@ void FriendList::peerTreeWidgetCustomPopupMenu()
{
bool standard = c->data(COLUMN_DATA, ROLE_STANDARD).toBool();
contextMnu.addAction(QIcon(IMAGE_MSG), tr("Send message to whole group"), this, SLOT(msgfriend()));
contextMnu.addSeparator();
contextMnu.addAction(QIcon(IMAGE_EDIT), tr("Edit Group"), this, SLOT(editGroup()));
contextMenu->addAction(QIcon(IMAGE_MSG), tr("Send message to whole group"), this, SLOT(msgfriend()));
contextMenu->addSeparator();
contextMenu->addAction(QIcon(IMAGE_EDIT), tr("Edit Group"), this, SLOT(editGroup()));
QAction *action = contextMnu.addAction(QIcon(IMAGE_REMOVE), tr("Remove Group"), this, SLOT(removeGroup()));
QAction *action = contextMenu->addAction(QIcon(IMAGE_REMOVE), tr("Remove Group"), this, SLOT(removeGroup()));
action->setDisabled(standard);
}
break;
case TYPE_GPG:
{
contextMnu.addAction(QIcon(IMAGE_CHAT), tr("Chat"), this, SLOT(chatfriendproxy()));
contextMnu.addAction(QIcon(IMAGE_MSG), tr("Send message"), this, SLOT(msgfriend()));
contextMenu->addAction(QIcon(IMAGE_CHAT), tr("Chat"), this, SLOT(chatfriendproxy()));
contextMenu->addAction(QIcon(IMAGE_MSG), tr("Send message"), this, SLOT(msgfriend()));
contextMnu.addSeparator();
contextMenu->addSeparator();
contextMnu.addAction(QIcon(IMAGE_FRIENDINFO), tr("Details"), this, SLOT(configurefriend()));
contextMnu.addAction(QIcon(IMAGE_DENYFRIEND), tr("Deny"), this, SLOT(removefriend()));
contextMenu->addAction(QIcon(IMAGE_FRIENDINFO), tr("Details"), this, SLOT(configurefriend()));
contextMenu->addAction(QIcon(IMAGE_DENYFRIEND), tr("Deny"), this, SLOT(removefriend()));
if(mShowGroups)
{
@ -375,7 +376,7 @@ void FriendList::peerTreeWidgetCustomPopupMenu()
if (std::find(groupIt->peerIds.begin(), groupIt->peerIds.end(), gpgId) == groupIt->peerIds.end()) {
if (parent) {
if (addToGroupMenu == NULL) {
addToGroupMenu = new QMenu(tr("Add to group"), &contextMnu);
addToGroupMenu = new QMenu(tr("Add to group"), contextMenu);
}
QAction* addToGroupAction = new QAction(GroupDefs::name(*groupIt), addToGroupMenu);
addToGroupAction->setData(QString::fromStdString(groupIt->id.toStdString()));
@ -384,7 +385,7 @@ void FriendList::peerTreeWidgetCustomPopupMenu()
}
if (moveToGroupMenu == NULL) {
moveToGroupMenu = new QMenu(tr("Move to group"), &contextMnu);
moveToGroupMenu = new QMenu(tr("Move to group"), contextMenu);
}
QAction* moveToGroupAction = new QAction(GroupDefs::name(*groupIt), moveToGroupMenu);
moveToGroupAction->setData(QString::fromStdString(groupIt->id.toStdString()));
@ -395,7 +396,7 @@ void FriendList::peerTreeWidgetCustomPopupMenu()
}
}
QMenu *groupsMenu = contextMnu.addMenu(QIcon(IMAGE_GROUP16), tr("Groups"));
QMenu *groupsMenu = contextMenu->addMenu(QIcon(IMAGE_GROUP16), tr("Groups"));
groupsMenu->addAction(QIcon(IMAGE_EXPAND), tr("Create new group"), this, SLOT(createNewGroup()));
if (addToGroupMenu || moveToGroupMenu || foundGroup) {
@ -427,40 +428,43 @@ void FriendList::peerTreeWidgetCustomPopupMenu()
case TYPE_SSL:
{
contextMnu.addAction(QIcon(IMAGE_CHAT), tr("Chat"), this, SLOT(chatfriendproxy()));
contextMnu.addAction(QIcon(IMAGE_MSG), tr("Send message"), this, SLOT(msgfriend()));
contextMenu->addAction(QIcon(IMAGE_CHAT), tr("Chat"), this, SLOT(chatfriendproxy()));
contextMenu->addAction(QIcon(IMAGE_MSG), tr("Send message"), this, SLOT(msgfriend()));
contextMnu.addSeparator();
contextMenu->addSeparator();
contextMnu.addAction(QIcon(IMAGE_FRIENDINFO), tr("Details"), this, SLOT(configurefriend()));
contextMenu->addAction(QIcon(IMAGE_FRIENDINFO), tr("Details"), this, SLOT(configurefriend()));
if (type == TYPE_GPG || type == TYPE_SSL) {
contextMnu.addAction(QIcon(IMAGE_EXPORTFRIEND), tr("Recommend this Friend to..."), this, SLOT(recommendfriend()));
contextMenu->addAction(QIcon(IMAGE_EXPORTFRIEND), tr("Recommend this Friend to..."), this, SLOT(recommendfriend()));
}
contextMnu.addAction(QIcon(IMAGE_CONNECT), tr("Attempt to connect"), this, SLOT(connectfriend()));
contextMenu->addAction(QIcon(IMAGE_CONNECT), tr("Attempt to connect"), this, SLOT(connectfriend()));
contextMnu.addAction(QIcon(IMAGE_COPYLINK), tr("Copy certificate link"), this, SLOT(copyFullCertificate()));
contextMenu->addAction(QIcon(IMAGE_COPYLINK), tr("Copy certificate link"), this, SLOT(copyFullCertificate()));
//this is a SSL key
contextMnu.addAction(QIcon(IMAGE_REMOVEFRIEND), tr("Remove Friend Node"), this, SLOT(removefriend()));
//this is a SSL key
contextMenu->addAction(QIcon(IMAGE_REMOVEFRIEND), tr("Remove Friend Node"), this, SLOT(removefriend()));
}
}
}
contextMnu.addSeparator();
contextMenu->addSeparator();
QAction *action = contextMnu.addAction(QIcon(IMAGE_PASTELINK), tr("Paste certificate link"), this, SLOT(pastePerson()));
if (RSLinkClipboard::empty(RetroShareLink::TYPE_CERTIFICATE))
action->setDisabled(true);
QAction *action = contextMenu->addAction(QIcon(IMAGE_PASTELINK), tr("Paste certificate link"), this, SLOT(pastePerson()));
if (RSLinkClipboard::empty(RetroShareLink::TYPE_CERTIFICATE))
action->setDisabled(true);
contextMnu.addAction(QIcon(IMAGE_EXPAND), tr("Expand all"), ui->peerTreeWidget, SLOT(expandAll()));
contextMnu.addAction(QIcon(IMAGE_COLLAPSE), tr("Collapse all"), ui->peerTreeWidget, SLOT(collapseAll()));
contextMenu->addAction(QIcon(IMAGE_EXPAND), tr("Expand all"), ui->peerTreeWidget, SLOT(expandAll()));
contextMenu->addAction(QIcon(IMAGE_COLLAPSE), tr("Collapse all"), ui->peerTreeWidget, SLOT(collapseAll()));
contextMnu.exec(QCursor::pos());
contextMenu = ui->peerTreeWidget->createStandardContextMenu(contextMenu);
contextMenu->exec(QCursor::pos());
delete contextMenu;
}
void FriendList::createNewGroup()
@ -2284,16 +2288,16 @@ void FriendList::addPeerToExpand(const std::string &gpgId)
void FriendList::createDisplayMenu()
{
QMenu *displayMenu = new QMenu(tr("Show"), this);
QMenu *displayMenu = new QMenu(tr("Show Items"), this);
connect(displayMenu, SIGNAL(aboutToShow()), this, SLOT(updateMenu()));
displayMenu->addAction(ui->actionHideOfflineFriends);
displayMenu->addAction(ui->actionShowState);
displayMenu->addAction(ui->actionShowGroups);
ui->peerTreeWidget->addHeaderContextMenuMenu(displayMenu);
ui->peerTreeWidget->addHeaderContextMenuAction(ui->actionExportFriendlist);
ui->peerTreeWidget->addHeaderContextMenuAction(ui->actionImportFriendlist);
ui->peerTreeWidget->addContextMenuMenu(displayMenu);
ui->peerTreeWidget->addContextMenuAction(ui->actionExportFriendlist);
ui->peerTreeWidget->addContextMenuAction(ui->actionImportFriendlist);
}
void FriendList::updateMenu()

View File

@ -108,7 +108,7 @@ FriendSelectionWidget::FriendSelectionWidget(QWidget *parent)
mActionSortByState = new QAction(tr("Sort by state"), this);
mActionSortByState->setCheckable(true);
connect(mActionSortByState, SIGNAL(toggled(bool)), this, SLOT(sortByState(bool)));
ui->friendList->addHeaderContextMenuAction(mActionSortByState);
ui->friendList->addContextMenuAction(mActionSortByState);
/* initialize list */
ui->friendList->setColumnCount(COLUMN_COUNT);
@ -808,16 +808,16 @@ void FriendSelectionWidget::addContextMenuAction(QAction *action)
void FriendSelectionWidget::contextMenuRequested(const QPoint &/*pos*/)
{
QMenu contextMenu(this);
QMenu *contextMenu = new QMenu(this);
if (mListModus == MODUS_CHECK) {
contextMenu.addAction(QIcon(), tr("Mark all"), this, SLOT(selectAll()));
contextMenu.addAction(QIcon(), tr("Mark none"), this, SLOT(deselectAll()));
contextMenu->addAction(QIcon(), tr("Mark all"), this, SLOT(selectAll()));
contextMenu->addAction(QIcon(), tr("Mark none"), this, SLOT(deselectAll()));
}
if (!mContextMenuActions.isEmpty()) {
bool addSeparator = false;
if (!contextMenu.isEmpty()) {
if (!contextMenu->isEmpty()) {
// Check for visible action
foreach (QAction *action, mContextMenuActions) {
if (action->isVisible()) {
@ -828,17 +828,19 @@ void FriendSelectionWidget::contextMenuRequested(const QPoint &/*pos*/)
}
if (addSeparator) {
contextMenu.addSeparator();
contextMenu->addSeparator();
}
contextMenu.addActions(mContextMenuActions);
contextMenu->addActions(mContextMenuActions);
}
if (contextMenu.isEmpty()) {
return;
contextMenu = ui->friendList->createStandardContextMenu(contextMenu);
if (!contextMenu->isEmpty()) {
contextMenu->exec(QCursor::pos());
}
contextMenu.exec(QCursor::pos());
delete contextMenu;
}
void FriendSelectionWidget::itemDoubleClicked(QTreeWidgetItem *item, int /*column*/)

View File

@ -18,13 +18,16 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include <QPainter>
#include <QMouseEvent>
#include <QHeaderView>
#include <QMenu>
#include "RSTreeWidget.h"
#include <QHBoxLayout>
#include <QHeaderView>
#include <QLabel>
#include <QMenu>
#include <QMouseEvent>
#include <QPainter>
#include <QWidgetAction>
#include "gui/settings/rsharesettings.h"
RSTreeWidget::RSTreeWidget(QWidget *parent) : QTreeWidget(parent)
@ -164,21 +167,54 @@ void RSTreeWidget::setColumnCustomizable(int column, bool customizable)
mColumnCustomizable[column] = customizable;
}
void RSTreeWidget::addHeaderContextMenuAction(QAction *action)
void RSTreeWidget::addContextMenuAction(QAction *action)
{
mHeaderContextMenuActions.push_back(action);
mContextMenuActions.push_back(action);
}
void RSTreeWidget::addHeaderContextMenuMenu(QMenu *menu)
void RSTreeWidget::addContextMenuMenu(QMenu *menu)
{
mHeaderContextMenuMenus.push_back(menu);
mContextMenuMenus.push_back(menu);
}
void RSTreeWidget::headerContextMenuRequested(const QPoint &pos)
QMenu *RSTreeWidget::createStandardContextMenu(QMenu *contextMenu)
{
QMenu contextMenu(this);
if (!contextMenu){
contextMenu = new QMenu(this);
contextMenu->addSeparator();
}
if(!mContextMenuActions.isEmpty() || mEnableColumnCustomize ||!mContextMenuActions.isEmpty() || !mContextMenuMenus.isEmpty()) {
QWidget *widget = new QWidget(contextMenu);
widget->setStyleSheet( ".QWidget{background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,stop:0 #FEFEFE, stop:1 #E8E8E8); border: 1px solid #CCCCCC;}");
// create menu header
QHBoxLayout *hbox = new QHBoxLayout(widget);
hbox->setMargin(0);
hbox->setSpacing(6);
QLabel *iconLabel = new QLabel(widget);
QPixmap pix = QPixmap(":/images/settings.png").scaledToHeight(QFontMetricsF(iconLabel->font()).height()*1.5);
iconLabel->setPixmap(pix);
iconLabel->setMaximumSize(iconLabel->frameSize().height() + pix.height(), pix.width());
hbox->addWidget(iconLabel);
QLabel *textLabel = new QLabel("<strong>" + tr("Tree View Options") + "</strong>", widget);
hbox->addWidget(textLabel);
QSpacerItem *spacerItem = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
hbox->addItem(spacerItem);
widget->setLayout(hbox);
QWidgetAction *widgetAction = new QWidgetAction(this);
widgetAction->setDefaultWidget(widget);
contextMenu->addAction(widgetAction);
}
if (mEnableColumnCustomize) {
QMenu *headerMenu = contextMenu->addMenu(QIcon(),tr("Show Headers"));
QTreeWidgetItem *item = headerItem();
int columnCount = item->columnCount();
for (int column = 0; column < columnCount; ++column) {
@ -186,18 +222,18 @@ void RSTreeWidget::headerContextMenuRequested(const QPoint &pos)
if (it != mColumnCustomizable.end() && *it == false) {
continue;
}
QAction *action = contextMenu.addAction(QIcon(), item->text(column), this, SLOT(columnVisible()));
QAction *action = headerMenu->addAction(QIcon(), item->text(column), this, SLOT(columnVisible()));
action->setCheckable(true);
action->setData(column);
action->setChecked(!isColumnHidden(column));
}
}
if (!mHeaderContextMenuActions.isEmpty()) {
if (!mContextMenuActions.isEmpty()) {
bool addSeparator = false;
if (!contextMenu.isEmpty()) {
if (!contextMenu->isEmpty()) {
// Check for visible action
foreach (QAction *action, mHeaderContextMenuActions) {
foreach (QAction *action, mContextMenuActions) {
if (action->isVisible()) {
addSeparator = true;
break;
@ -206,24 +242,31 @@ void RSTreeWidget::headerContextMenuRequested(const QPoint &pos)
}
if (addSeparator) {
contextMenu.addSeparator();
contextMenu->addSeparator();
}
contextMenu.addActions(mHeaderContextMenuActions);
contextMenu->addActions(mContextMenuActions);
}
if (!mHeaderContextMenuMenus.isEmpty()) {
foreach(QMenu *menu, mHeaderContextMenuMenus) {
contextMenu.addSeparator();
contextMenu.addMenu(menu);
if (!mContextMenuMenus.isEmpty()) {
foreach(QMenu *menu, mContextMenuMenus) {
contextMenu->addSeparator();
contextMenu->addMenu(menu);
}
}
if (contextMenu.isEmpty()) {
return contextMenu;
}
void RSTreeWidget::headerContextMenuRequested(const QPoint &pos)
{
QMenu *contextMenu = createStandardContextMenu(NULL);
if (contextMenu->isEmpty()) {
return;
}
contextMenu.exec(mapToGlobal(pos));
contextMenu->exec(mapToGlobal(pos));
delete contextMenu;
}
void RSTreeWidget::columnVisible()

View File

@ -46,9 +46,11 @@ public:
void resort();
// Add QAction to context menu (action won't be deleted)
void addHeaderContextMenuAction(QAction *action);
void addContextMenuAction(QAction *action);
// Add QMenu to context menu (menu won't be deleted)
void addHeaderContextMenuMenu(QMenu *menu);
void addContextMenuMenu(QMenu *menu);
// Get Default context menu (Columns choice and menus added)
QMenu *createStandardContextMenu(QMenu *menu);
signals:
void signalMouseMiddleButtonClicked(QTreeWidgetItem *item);
@ -70,8 +72,8 @@ private:
bool mEnableColumnCustomize;
quint32 mSettingsVersion;
QMap<int, bool> mColumnCustomizable;
QList<QAction*> mHeaderContextMenuActions;
QList<QMenu*> mHeaderContextMenuMenus;
QList<QAction*> mContextMenuActions;
QList<QMenu*> mContextMenuMenus;
};
#endif