Warning, file /office/calligra/libs/widgets/KoTagToolButton.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 * This file is part of the KDE project 0003 * Copyright (c) 2002 Patrick Julien <freak@codepimps.org> 0004 * Copyright (c) 2007 Jan Hambrecht <jaham@gmx.net> 0005 * Copyright (c) 2007 Sven Langkamp <sven.langkamp@gmail.com> 0006 * Copyright (C) 2011 Srikanth Tiyyagura <srikanth.tulasiram@gmail.com> 0007 * Copyright (c) 2011 José Luis Vergara <pentalis@gmail.com> 0008 * Copyright (c) 2013 Sascha Suelzer <s.suelzer@gmail.com> 0009 * 0010 * This library is free software; you can redistribute it and/or 0011 * modify it under the terms of the GNU Library General Public 0012 * License as published by the Free Software Foundation; either 0013 * version 2 of the License, or (at your option) any later version. 0014 * 0015 * This library is distributed in the hope that it will be useful, 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0018 * Library General Public License for more details. 0019 * 0020 * You should have received a copy of the GNU Library General Public License 0021 * along with this library; see the file COPYING.LIB. If not, write to 0022 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0023 * Boston, MA 02110-1301, USA. 0024 */ 0025 0026 #include "KoTagToolButton.h" 0027 0028 #include <QToolButton> 0029 #include <QGridLayout> 0030 0031 #include <klocalizedstring.h> 0032 0033 #include <KoIcon.h> 0034 0035 #include "KoResourceItemChooserContextMenu.h" 0036 0037 class KoTagToolButton::Private 0038 { 0039 public: 0040 QToolButton* tagToolButton; 0041 QAction* action_undeleteTag; 0042 QAction* action_deleteTag; 0043 KoLineEditAction* action_renameTag; 0044 QAction* action_purgeTagUndeleteList; 0045 QString undeleteCandidate; 0046 }; 0047 0048 KoTagToolButton::KoTagToolButton(QWidget* parent) 0049 :QWidget(parent), d(new Private()) 0050 { 0051 QGridLayout* buttonLayout = new QGridLayout(this); 0052 buttonLayout->setMargin(0); 0053 buttonLayout->setSpacing(0); 0054 0055 d->tagToolButton = new QToolButton(this); 0056 d->tagToolButton->setIcon(koIcon("list-add")); 0057 d->tagToolButton->setToolTip(i18nc("@info:tooltip", "<qt>Show the tag box options.</qt>")); 0058 d->tagToolButton->setPopupMode(QToolButton::InstantPopup); 0059 d->tagToolButton->setEnabled(true); 0060 0061 QMenu* popup = new QMenu(this); 0062 0063 KoLineEditAction* addTagAction = new KoLineEditAction(popup); 0064 addTagAction->setPlaceholderText(i18n("New tag")); 0065 addTagAction->setIcon(koIcon("document-new")); 0066 addTagAction->closeParentOnTrigger(true); 0067 popup->addAction(addTagAction); 0068 0069 connect(addTagAction, SIGNAL(triggered(QString)), 0070 this, SIGNAL(newTagRequested(QString))); 0071 0072 d->action_renameTag = new KoLineEditAction(popup); 0073 d->action_renameTag->setPlaceholderText(i18n("Rename tag")); 0074 d->action_renameTag->setIcon(koIcon("edit-rename")); 0075 d->action_renameTag->closeParentOnTrigger(true); 0076 popup->addAction(d->action_renameTag); 0077 0078 connect(d->action_renameTag, SIGNAL(triggered(QString)), 0079 this, SIGNAL(renamingOfCurrentTagRequested(QString))); 0080 0081 popup->addSeparator(); 0082 0083 d->action_deleteTag = new QAction(popup); 0084 d->action_deleteTag->setText(i18n("Delete this tag")); 0085 d->action_deleteTag->setIcon(koIcon("edit-delete")); 0086 popup->addAction(d->action_deleteTag); 0087 0088 connect(d->action_deleteTag, SIGNAL(triggered()), 0089 this, SIGNAL(deletionOfCurrentTagRequested())); 0090 0091 popup->addSeparator(); 0092 0093 d->action_undeleteTag = new QAction(popup); 0094 d->action_undeleteTag->setIcon(koIcon("edit-redo")); 0095 d->action_undeleteTag->setVisible(false); 0096 popup->addAction(d->action_undeleteTag); 0097 0098 connect(d->action_undeleteTag, SIGNAL(triggered()), 0099 this, SLOT(onTagUndeleteClicked())); 0100 0101 d->action_purgeTagUndeleteList = new QAction(popup); 0102 d->action_purgeTagUndeleteList->setText(i18n("Clear undelete list")); 0103 d->action_purgeTagUndeleteList->setIcon(koIcon("edit-clear")); 0104 d->action_purgeTagUndeleteList->setVisible(false); 0105 popup->addAction(d->action_purgeTagUndeleteList); 0106 0107 connect(d->action_purgeTagUndeleteList, SIGNAL(triggered()), 0108 this, SIGNAL(purgingOfTagUndeleteListRequested())); 0109 0110 connect(popup, SIGNAL(aboutToShow()), 0111 this, SIGNAL(popupMenuAboutToShow())); 0112 0113 d->tagToolButton->setMenu(popup); 0114 buttonLayout->addWidget(d->tagToolButton); 0115 } 0116 0117 KoTagToolButton::~KoTagToolButton() 0118 { 0119 delete d; 0120 } 0121 0122 void KoTagToolButton::readOnlyMode(bool activate) 0123 { 0124 activate = !activate; 0125 d->action_renameTag->setVisible(activate); 0126 d->action_deleteTag->setVisible(activate); 0127 } 0128 0129 void KoTagToolButton::setUndeletionCandidate(const QString& deletedTagName) 0130 { 0131 d->undeleteCandidate = deletedTagName; 0132 d->action_undeleteTag->setText(i18n("Undelete") +" "+ deletedTagName); 0133 d->action_undeleteTag->setVisible(!deletedTagName.isEmpty()); 0134 d->action_purgeTagUndeleteList->setVisible(!deletedTagName.isEmpty()); 0135 } 0136 0137 void KoTagToolButton::onTagUndeleteClicked() 0138 { 0139 emit undeletionOfTagRequested(d->undeleteCandidate); 0140 } 0141