Warning, file /office/calligra/libs/widgets/KoTagFilterWidget.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 "KoTagFilterWidget.h" 0027 0028 #include <QPushButton> 0029 #include <QAction> 0030 #include <QGridLayout> 0031 0032 #include <klineedit.h> 0033 #include <klocalizedstring.h> 0034 0035 #include <KoIcon.h> 0036 0037 class KoTagFilterWidget::Private 0038 { 0039 public: 0040 QString tagSearchBarTooltip_saving_disabled; 0041 QString tagSearchBarTooltip_saving_enabled; 0042 KLineEdit* tagSearchLineEdit; 0043 QPushButton* tagSearchSaveButton; 0044 QGridLayout* filterBarLayout; 0045 }; 0046 0047 KoTagFilterWidget::KoTagFilterWidget(QWidget* parent): QWidget(parent) 0048 ,d( new Private()) 0049 { 0050 d->tagSearchBarTooltip_saving_disabled = i18nc ( 0051 "@info:tooltip", 0052 "<qt>Entering search terms here will add to, or remove resources from the current tag view." 0053 "<para>To filter based on the partial, case insensitive name of a resource:<br>" 0054 "<icode>partialname</icode> or <icode>!partialname</icode>.</para>" 0055 "<para>In-/exclusion of other tag sets:<br>" 0056 "<icode>[Tagname]</icode> or <icode>![Tagname]</icode>.</para>" 0057 "<para>Case sensitive and full name matching in-/exclusion:<br>" 0058 "<icode>\"ExactMatch\"</icode> or <icode>!\"ExactMatch\"</icode>.</para>" 0059 "Filter results cannot be saved for the <interface>All Presets</interface> view.<br>" 0060 "In this view, pressing <interface>Enter</interface> or clearing the filter box will restore all items.<br>" 0061 "Create and/or switch to a different tag if you want to save filtered resources into named sets.</qt>" 0062 ); 0063 0064 d->tagSearchBarTooltip_saving_enabled = i18nc ( 0065 "@info:tooltip", 0066 "<qt>Entering search terms here will add to, or remove resources from the current tag view." 0067 "<para>To filter based on the partial, case insensitive name of a resource:<br>" 0068 "<icode>partialname</icode> or <icode>!partialname</icode>.</para>" 0069 "<para>In-/exclusion of other tag sets:<br>" 0070 "<icode>[Tagname]</icode> or <icode>![Tagname]</icode>.</para>" 0071 "<para>Case sensitive and full name matching in-/exclusion:<br>" 0072 "<icode>\"ExactMatch\"</icode> or <icode>!\"ExactMatch\"</icode>.</para>" 0073 "Pressing <interface>Enter</interface> or clicking the <interface>Save</interface> button will save the changes.</qt>" 0074 ); 0075 0076 QGridLayout* filterBarLayout = new QGridLayout; 0077 0078 0079 d->tagSearchLineEdit = new KLineEdit(this); 0080 d->tagSearchLineEdit->setClearButtonEnabled(true); 0081 d->tagSearchLineEdit->setPlaceholderText(i18n("Enter resource filters here")); 0082 d->tagSearchLineEdit->setToolTip(d->tagSearchBarTooltip_saving_disabled); 0083 d->tagSearchLineEdit->setEnabled(true); 0084 0085 filterBarLayout->setSpacing(0); 0086 filterBarLayout->setMargin(0); 0087 filterBarLayout->setColumnStretch(0, 1); 0088 filterBarLayout->addWidget(d->tagSearchLineEdit, 0, 0); 0089 0090 d->tagSearchSaveButton = new QPushButton(this); 0091 d->tagSearchSaveButton->setIcon(koIcon("media-floppy")); 0092 d->tagSearchSaveButton->setToolTip(i18nc("@info:tooltip", "<qt>Save the currently filtered set as the new members of the current tag.</qt>")); 0093 d->tagSearchSaveButton->setEnabled(false); 0094 0095 filterBarLayout->addWidget(d->tagSearchSaveButton, 0, 1); 0096 0097 connect(d->tagSearchSaveButton, SIGNAL(pressed()), 0098 this, SLOT(onSaveButtonClicked())); 0099 connect(d->tagSearchLineEdit, SIGNAL(returnPressed()), 0100 this, SLOT(onSaveButtonClicked())); 0101 connect(d->tagSearchLineEdit, SIGNAL(textChanged(QString)), 0102 this, SLOT(onTextChanged(QString))); 0103 allowSave(false); 0104 this->setLayout(filterBarLayout); 0105 0106 } 0107 0108 KoTagFilterWidget::~KoTagFilterWidget() 0109 { 0110 delete d; 0111 } 0112 void KoTagFilterWidget::allowSave(bool allow) 0113 { 0114 if (allow) { 0115 d->tagSearchSaveButton->show(); 0116 d->tagSearchLineEdit->setToolTip(d->tagSearchBarTooltip_saving_enabled); 0117 } 0118 else { 0119 d->tagSearchSaveButton->hide(); 0120 d->tagSearchLineEdit->setToolTip(d->tagSearchBarTooltip_saving_disabled); 0121 } 0122 } 0123 0124 void KoTagFilterWidget::clear() 0125 { 0126 d->tagSearchLineEdit->clear(); 0127 d->tagSearchSaveButton->setEnabled(false); 0128 } 0129 0130 void KoTagFilterWidget::onTextChanged(const QString& lineEditText) 0131 { 0132 d->tagSearchSaveButton->setEnabled(!lineEditText.isEmpty()); 0133 emit filterTextChanged(lineEditText); 0134 } 0135 0136 void KoTagFilterWidget::onSaveButtonClicked() 0137 { 0138 emit saveButtonClicked(); 0139 clear(); 0140 }