diff --git a/libs/widgets/CMakeLists.txt b/libs/widgets/CMakeLists.txt index 658f203a1b..e678aba10f 100644 --- a/libs/widgets/CMakeLists.txt +++ b/libs/widgets/CMakeLists.txt @@ -1,126 +1,125 @@ add_subdirectory( tests ) include_directories(${CMAKE_CURRENT_BINARY_DIR}) set(kritawidgets_LIB_SRCS KoGradientEditWidget.cpp KoVBox.cpp KoDialog.cpp KoZoomWidget.cpp KoAspectButton.cpp KoPagePreviewWidget.cpp KoSliderCombo.cpp KoColorPopupButton.cpp KoConfigAuthorPage.cpp KoUnitDoubleSpinBox.cpp KoZoomAction.cpp KoZoomController.cpp KoZoomInput.cpp KoZoomHandler.cpp KoZoomMode.cpp KoDpi.cpp KoColorPatch.cpp KoColorPopupAction.cpp KoColorSetWidget.cpp KoColorSlider.cpp KoTriangleColorSelector.cpp KoResourcePopupAction.cpp KoResourceTagStore.cpp KoRuler.cpp KoResourceServerProvider.cpp KoLineStyleSelector.cpp KoLineStyleItemDelegate.cpp KoLineStyleModel.cpp - KoResourceFiltering.cpp KoTitledTabWidget.cpp KoToolBoxButton.cpp KoToolBox.cpp KoToolBoxDocker.cpp KoToolBoxFactory.cpp KoToolDocker.cpp KoPageLayoutWidget.cpp KoPageLayoutDialog.cpp KoShadowConfigWidget.cpp KoMarkerSelector.cpp KoMarkerModel.cpp KoMarkerItemDelegate.cpp KoDocumentInfoDlg.cpp WidgetsDebug.cpp kis_file_name_requester.cpp kis_double_parse_spin_box.cpp kis_double_parse_unit_spin_box.cpp kis_int_parse_spin_box.cpp KisColorSelectorInterface.cpp KoAnchorSelectionWidget.cpp KisGradientSlider.cpp KisGradientSliderWidget.cpp kis_color_input.cpp # classes used by internal color selector kis_spinbox_color_selector.cpp KisVisualColorSelector.cpp KisVisualColorSelectorShape.cpp KisVisualEllipticalSelectorShape.cpp KisVisualRectangleSelectorShape.cpp KisVisualTriangleSelectorShape.cpp KisScreenColorPickerBase.cpp KisDlgInternalColorSelector.cpp KisPaletteModel.cpp KisPaletteDelegate.cpp kis_palette_view.cpp KisPaletteListWidget.cpp KisPaletteComboBox.cpp kis_popup_button.cc kis_color_button.cpp ) ki18n_wrap_ui( kritawidgets_LIB_SRCS KoConfigAuthorPage.ui koDocumentInfoAboutWidget.ui koDocumentInfoAuthorWidget.ui wdg_file_name_requester.ui KoPageLayoutWidget.ui KoShadowConfigWidget.ui WdgDlgInternalColorSelector.ui WdgPaletteListWidget.ui ) add_library(kritawidgets SHARED ${kritawidgets_LIB_SRCS}) generate_export_header(kritawidgets BASE_NAME kritawidgets) target_link_libraries(kritawidgets kritaodf kritaglobal kritaflake kritapigment kritawidgetutils kritaresources kritaresourcewidgets Qt5::PrintSupport KF5::CoreAddons KF5::ConfigGui KF5::GuiAddons KF5::WidgetsAddons KF5::ConfigCore KF5::Completion ) if(X11_FOUND) target_link_libraries(kritawidgets Qt5::X11Extras ${X11_LIBRARIES}) endif() set_target_properties(kritawidgets PROPERTIES VERSION ${GENERIC_KRITA_LIB_VERSION} SOVERSION ${GENERIC_KRITA_LIB_SOVERSION} ) install(TARGETS kritawidgets ${INSTALL_TARGETS_DEFAULT_ARGS}) diff --git a/libs/widgets/KoResourceFiltering.cpp b/libs/widgets/KoResourceFiltering.cpp deleted file mode 100644 index d86ab1334d..0000000000 --- a/libs/widgets/KoResourceFiltering.cpp +++ /dev/null @@ -1,261 +0,0 @@ -/* This file is part of the KDE project - - Copyright (c) 2013 Sascha Suelzer - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "KoResourceFiltering.h" - -#include "KoResourceServer.h" - -#include -#include - - -class Q_DECL_HIDDEN KoResourceFiltering::Private -{ -public: - Private() - : isTag("\\[([\\w\\s]+)\\]") - , isExactMatch("\"([\\w\\s]+)\"") - , searchTokenizer("\\s*,+\\s*") - , hasNewFilters(false) - , name(true) - , filename(true) - , resourceServer(0) - {} - QRegExp isTag; - QRegExp isExactMatch; - QRegExp searchTokenizer; - bool hasNewFilters; - bool name,filename; - KoResourceServerBase *resourceServer; - QStringList tagSetFilenames; - QStringList includedNames; - QStringList excludedNames; - QString currentTag; -}; - -KoResourceFiltering::KoResourceFiltering() : d(new Private()) -{} - -KoResourceFiltering::~KoResourceFiltering() -{ - delete d; -} - -void KoResourceFiltering::configure(int filterType, bool enable) { - switch (filterType) { - case 0: - d->name=true; - d->filename=enable; - break; - case 1: - d->name=enable; - break; - case 2: - d->filename=enable; - break; - } -} - -void KoResourceFiltering::setChanged() -{ - d->hasNewFilters = true; -} - -void KoResourceFiltering::setTagSetFilenames(const QStringList& filenames) -{ - d->tagSetFilenames = filenames; - d->excludedNames.clear(); - d->includedNames.clear(); - setChanged(); -} - -bool KoResourceFiltering::matchesResource(const QStringList &filteredList,const QStringList &filterList) const -{ - Qt::CaseSensitivity sensitivity = Qt::CaseInsensitive; - foreach (QString filter, filterList) { - if (!filter.startsWith('"')) { - foreach (QString filtered, filteredList) { - if (filtered.contains(filter,sensitivity)) { - return true; - } - } - } - else if (d->name) { - filter.remove('"'); - if (!filteredList.at(0).compare(filter)) { - return true; - } - } - } - return false; -} - -void KoResourceFiltering::sanitizeExclusionList() -{ - if(!d->includedNames.isEmpty()) { - - foreach (const QString &exclusion, d->excludedNames) { - if (!excludeFilterIsValid(exclusion)) - d->excludedNames.removeAll(exclusion); - } - } -} - -QStringList KoResourceFiltering::tokenizeSearchString(const QString& searchString) const -{ - return searchString.split(d->searchTokenizer, QString::SkipEmptyParts); -} - -void KoResourceFiltering::populateIncludeExcludeFilters(const QStringList& filteredNames) -{ - foreach (QString name, filteredNames) { - QStringList* target; - - if(name.startsWith('!')) { - name.remove('!'); - target = &d->excludedNames; - } else { - target = &d->includedNames; - } - - if(!name.isEmpty()) { - if (name.startsWith('[')) { - if (d->isTag.exactMatch(name) && d->resourceServer) { - name = d->isTag.cap(1); - (*target) += d->resourceServer->queryResources(name); - } - } - else if (name.startsWith('"')) { - if (d->isExactMatch.exactMatch(name)) { - target->push_back(name); - } - } - else { - target->push_back(name); - } - } - } - sanitizeExclusionList(); -} - -bool KoResourceFiltering::hasFilters() const -{ - return (!d->tagSetFilenames.isEmpty() || !d->includedNames.isEmpty() || !d->excludedNames.isEmpty()); -} - -bool KoResourceFiltering::filtersHaveChanged() const -{ - return d->hasNewFilters; -} - -void KoResourceFiltering::setFilters(const QString &searchString) -{ - d->excludedNames.clear(); - d->includedNames.clear(); - QStringList filteredNames = tokenizeSearchString(searchString); - populateIncludeExcludeFilters(filteredNames); - setChanged(); -} - -bool KoResourceFiltering::presetMatchesSearch(KoResourceSP resource) const -{ - QList filteredList; - - QString resourceFileName = resource->shortFilename(); - QString resourceName = resource->name(); - - if (d->name) { - filteredList.push_front(resourceName); - } - - if (d->filename) { - filteredList.push_back(resourceFileName); - } - - if (matchesResource(filteredList,d->excludedNames)) { - return false; - } - - if (matchesResource(filteredList,d->includedNames)) { - return true; - } - - foreach (const QString &filter, d->tagSetFilenames) { - if (!resourceFileName.compare(filter) || !resourceName.compare(filter)) { - return true; - } - } - - return false; -} - -void KoResourceFiltering::setInclusions(const QStringList &inclusions) -{ - d->includedNames = inclusions; - setChanged(); -} - -void KoResourceFiltering::setExclusions(const QStringList &exclusions) -{ - d->excludedNames = exclusions; - setChanged(); -} - -bool KoResourceFiltering::excludeFilterIsValid(const QString &exclusion) -{ - Q_FOREACH (const QString &inclusion, d->includedNames) { - if ((inclusion.startsWith(exclusion) && exclusion.size() <= inclusion.size())) { - return false; - } - } - return true; -} - -QList< KoResourceSP > KoResourceFiltering::filterResources(QList< KoResourceSP > resources) -{ - - Q_FOREACH (KoResourceSP resource, resources) { - if(!presetMatchesSearch(resource)) { - resources.removeAll(resource); - } - } - setDoneFiltering(); - return resources; -} - -void KoResourceFiltering::setDoneFiltering() -{ - d->hasNewFilters = false; -} - -void KoResourceFiltering::rebuildCurrentTagFilenames() -{ - d->tagSetFilenames = d->resourceServer->queryResources(d->currentTag); -} - -void KoResourceFiltering::setCurrentTag(const QString& tagSet) -{ - d->currentTag = tagSet; - rebuildCurrentTagFilenames(); -} - -void KoResourceFiltering::setResourceServer(KoResourceServerBase* resourceServer) -{ - d->resourceServer = resourceServer; -} diff --git a/libs/widgets/KoResourceFiltering.h b/libs/widgets/KoResourceFiltering.h deleted file mode 100644 index e53d83f7a1..0000000000 --- a/libs/widgets/KoResourceFiltering.h +++ /dev/null @@ -1,68 +0,0 @@ - -/* This file is part of the KDE project - - Copyright (c) 2013 Sascha Suelzer - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef KORESOURCEFILTER_H -#define KORESOURCEFILTER_H - -#include "kritawidgets_export.h" - -#include - -#include - -class KoResourceServerBase; -class QStringList; -class QString; - -class KRITAWIDGETS_EXPORT KoResourceFiltering -{ - -public: - KoResourceFiltering(); - virtual ~KoResourceFiltering(); - void configure(int filterType, bool enable); - bool hasFilters() const; - bool filtersHaveChanged() const; - void setTagSetFilenames(const QStringList& filenames); - void setCurrentTag(const QString& tagSet); - void rebuildCurrentTagFilenames(); - void setResourceServer(KoResourceServerBase *resourceServer); - void setFilters(const QString& searchString); - QList filterResources(QList< KoResourceSP > resources); - void setInclusions(const QStringList &inclusions); - void setExclusions(const QStringList &exclusions); - -private: - - void setDoneFiltering(); - bool presetMatchesSearch(KoResourceSP resource) const; - void setChanged(); - bool excludeFilterIsValid(const QString &exclusion); - bool matchesResource(const QStringList& filtered,const QStringList &filterList) const; - void populateIncludeExcludeFilters(const QStringList& filteredNames); - void sanitizeExclusionList(); - QStringList tokenizeSearchString(const QString& searchString) const; - - class Private; - Private * const d; - -}; - -#endif // KORESOURCEFILTER_H