diff --git a/libs/ui/KisResourceBundleManifest.cpp b/libs/ui/KisResourceBundleManifest.cpp index e4f94ca788..83761657d8 100644 --- a/libs/ui/KisResourceBundleManifest.cpp +++ b/libs/ui/KisResourceBundleManifest.cpp @@ -1,233 +1,232 @@ /* This file is part of the KDE project Copyright (C) 2014, Victor Lafon 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, see . */ #include "KisResourceBundleManifest.h" #include #include #include #include #include #include -#include #include #include #include #include #include #include "kis_brush_server.h" #include "kis_resource_server_provider.h" #include #include "kis_workspace_resource.h" QString resourceTypeToManifestType(const QString &type) { if (type.startsWith("ko_")) { return type.mid(3); } else if (type.startsWith("kis_")) { return type.mid(4); } else { return type; } } QString manifestTypeToResourceType(const QString &type) { if (type == "patterns" || type == "gradients" || type == "palettes") { return "ko_" + type; } else { return "kis_" + type; } } KisResourceBundleManifest::KisResourceBundleManifest() { } KisResourceBundleManifest::~KisResourceBundleManifest() { } bool KisResourceBundleManifest::load(QIODevice *device) { m_resources.clear(); if (!device->isOpen()) { if (!device->open(QIODevice::ReadOnly)) { return false; } } KoXmlDocument manifestDocument; QString errorMessage; int errorLine; int errorColumn; if (!manifestDocument.setContent(device, true, &errorMessage, &errorLine, &errorColumn)) { return false; } if (!errorMessage.isEmpty()) { warnKrita << "Error parsing manifest" << errorMessage << "line" << errorLine << "column" << errorColumn; return false; } // First find the manifest:manifest node. KoXmlNode n = manifestDocument.firstChild(); for (; !n.isNull(); n = n.nextSibling()) { if (!n.isElement()) { continue; } if (n.toElement().localName() == "manifest" && n.toElement().namespaceURI() == KoXmlNS::manifest) { break; } } if (n.isNull()) { // "Could not find manifest:manifest"; return false; } // Now loop through the children of the manifest:manifest and // store all the manifest:file-entry elements. const KoXmlElement manifestElement = n.toElement(); for (n = manifestElement.firstChild(); !n.isNull(); n = n.nextSibling()) { if (!n.isElement()) continue; KoXmlElement el = n.toElement(); if (!(el.localName() == "file-entry" && el.namespaceURI() == KoXmlNS::manifest)) continue; QString fullPath = el.attributeNS(KoXmlNS::manifest, "full-path", QString()); QString mediaType = el.attributeNS(KoXmlNS::manifest, "media-type", QString()); QString md5sum = el.attributeNS(KoXmlNS::manifest, "md5sum", QString()); QString version = el.attributeNS(KoXmlNS::manifest, "version", QString()); QStringList tagList; KoXmlNode tagNode = n.firstChildElement().firstChildElement(); while (!tagNode.isNull()) { if (tagNode.firstChild().isText()) { tagList.append(tagNode.firstChild().toText().data()); } tagNode = tagNode.nextSibling(); } // Only if fullPath is valid, should we store this entry. // If not, we don't bother to find out exactly what is wrong, we just skip it. if (!fullPath.isNull() && !mediaType.isEmpty() && !md5sum.isEmpty()) { addResource(mediaType, fullPath, tagList, QByteArray::fromHex(md5sum.toLatin1())); } } return true; } bool KisResourceBundleManifest::save(QIODevice *device) { if (!device->isOpen()) { if (!device->open(QIODevice::WriteOnly)) { return false; } } KoXmlWriter manifestWriter(device); manifestWriter.startDocument("manifest:manifest"); manifestWriter.startElement("manifest:manifest"); manifestWriter.addAttribute("xmlns:manifest", KoXmlNS::manifest); manifestWriter.addAttribute("manifest:version", "1.2"); manifestWriter.addManifestEntry("/", "application/x-krita-resourcebundle"); Q_FOREACH (QString resourceType, m_resources.uniqueKeys()) { Q_FOREACH (const ResourceReference &resource, m_resources[resourceType].values()) { manifestWriter.startElement("manifest:file-entry"); manifestWriter.addAttribute("manifest:media-type", resourceTypeToManifestType(resourceType)); manifestWriter.addAttribute("manifest:full-path", resourceTypeToManifestType(resourceType) + "/" + QFileInfo(resource.resourcePath).fileName()); manifestWriter.addAttribute("manifest:md5sum", QString(resource.md5sum.toHex())); if (!resource.tagList.isEmpty()) { manifestWriter.startElement("manifest:tags"); Q_FOREACH (const QString tag, resource.tagList) { manifestWriter.startElement("manifest:tag"); manifestWriter.addTextNode(tag); manifestWriter.endElement(); } manifestWriter.endElement(); } manifestWriter.endElement(); } } manifestWriter.endElement(); manifestWriter.endDocument(); return true; } void KisResourceBundleManifest::addResource(const QString &fileTypeName, const QString &fileName, const QStringList &fileTagList, const QByteArray &md5) { ResourceReference ref(fileName, fileTagList, fileTypeName, md5); if (!m_resources.contains(fileTypeName)) { m_resources[fileTypeName] = QMap(); } m_resources[fileTypeName].insert(fileName, ref); } QStringList KisResourceBundleManifest::types() const { return m_resources.keys(); } QStringList KisResourceBundleManifest::tags() const { QSet tags; Q_FOREACH (const QString &type, m_resources.keys()) { Q_FOREACH (const ResourceReference &ref, m_resources[type].values()) { tags += ref.tagList.toSet(); } } return QStringList::fromSet(tags); } QList KisResourceBundleManifest::files(const QString &type) const { // If no type is specified we return all the resources if(type.isEmpty()) { QList resources; QList >::iterator i; QList > values = m_resources.values(); for(i = values.begin(); i != values.end(); ++i) { resources.append(i->values()); } return resources; } else if (!m_resources.contains(type)) { return QList(); } return m_resources[type].values(); } void KisResourceBundleManifest::removeFile(QString fileName) { QList tags; Q_FOREACH (const QString &type, m_resources.keys()) { if (m_resources[type].contains(fileName)) { m_resources[type].remove(fileName); } } } diff --git a/libs/ui/input/config/kis_input_configuration_page_item.cpp b/libs/ui/input/config/kis_input_configuration_page_item.cpp index fc7a28c60f..aa95e42b7e 100644 --- a/libs/ui/input/config/kis_input_configuration_page_item.cpp +++ b/libs/ui/input/config/kis_input_configuration_page_item.cpp @@ -1,90 +1,92 @@ /* * This file is part of the KDE project * Copyright (C) 2013 Arjen Hiemstra * * 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 "kis_input_configuration_page_item.h" #include "kis_icon_utils.h" +#include + #include "input/kis_abstract_input_action.h" #include "input/kis_input_profile_manager.h" #include "kis_action_shortcuts_model.h" #include "kis_input_type_delegate.h" #include "kis_input_mode_delegate.h" #include "kis_input_editor_delegate.h" #include "ui_kis_input_configuration_page_item.h" KisInputConfigurationPageItem::KisInputConfigurationPageItem(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f) { ui = new Ui::KisInputConfigurationPageItem; ui->setupUi(this); m_shortcutsModel = new KisActionShortcutsModel(this); ui->shortcutsView->setModel(m_shortcutsModel); ui->shortcutsView->setItemDelegateForColumn(0, new KisInputTypeDelegate(ui->shortcutsView)); ui->shortcutsView->setItemDelegateForColumn(1, new KisInputEditorDelegate(ui->shortcutsView)); ui->shortcutsView->setItemDelegateForColumn(2, new KisInputModeDelegate(ui->shortcutsView)); ui->shortcutsView->header()->setResizeMode(QHeaderView::Stretch); setExpanded(false); QAction *deleteAction = new QAction(KisIconUtils::loadIcon("edit-delete"), i18n("Delete Shortcut"), ui->shortcutsView); connect(deleteAction, SIGNAL(triggered(bool)), SLOT(deleteShortcut())); ui->shortcutsView->addAction(deleteAction); ui->shortcutsView->setContextMenuPolicy(Qt::ActionsContextMenu); connect(ui->collapseButton, SIGNAL(clicked(bool)), SLOT(setExpanded(bool))); } KisInputConfigurationPageItem::~KisInputConfigurationPageItem() { delete ui; } void KisInputConfigurationPageItem::setAction(KisAbstractInputAction *action) { m_action = action; ui->collapseButton->setText(action->name()); ui->descriptionLabel->setText(action->description()); m_shortcutsModel->setProfile(KisInputProfileManager::instance()->currentProfile()); m_shortcutsModel->setAction(action); qobject_cast(ui->shortcutsView->itemDelegateForColumn(2))->setAction(action); } void KisInputConfigurationPageItem::setExpanded(bool expand) { if (expand) { ui->descriptionLabel->setVisible(true); ui->shortcutsView->setVisible(true); ui->collapseButton->setArrowType(Qt::DownArrow); } else { ui->descriptionLabel->setVisible(false); ui->shortcutsView->setVisible(false); ui->collapseButton->setArrowType(Qt::RightArrow); } } void KisInputConfigurationPageItem::deleteShortcut() { int row = ui->shortcutsView->selectionModel()->currentIndex().row(); if (m_shortcutsModel->canRemoveRow(row)) { m_shortcutsModel->removeRow(row, QModelIndex()); } } diff --git a/libs/ui/widgets/kis_paintop_presets_chooser_popup.cpp b/libs/ui/widgets/kis_paintop_presets_chooser_popup.cpp index e791f85e5a..300cb9b49d 100644 --- a/libs/ui/widgets/kis_paintop_presets_chooser_popup.cpp +++ b/libs/ui/widgets/kis_paintop_presets_chooser_popup.cpp @@ -1,156 +1,157 @@ /* This file is part of the KDE project * Copyright (c) 2010 Sven Langkamp * Copyright 2011 Srikanth Tiyyagura * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "kis_paintop_presets_chooser_popup.h" #include #include #include #include +#include #include #include #include #include #include #include #include #include struct KisPaintOpPresetsChooserPopup::Private { public: Ui_WdgPaintOpPresets uiWdgPaintOpPresets; bool firstShown; }; KisPaintOpPresetsChooserPopup::KisPaintOpPresetsChooserPopup(QWidget * parent) : QWidget(parent) , m_d(new Private()) { m_d->uiWdgPaintOpPresets.setupUi(this); QMenu* menu = new QMenu(this); menu->setStyleSheet("margin: 6px"); menu->addSection(i18n("Display")); QActionGroup *actionGroup = new QActionGroup(this); KisPresetChooser::ViewMode mode = (KisPresetChooser::ViewMode)KisConfig().presetChooserViewMode(); QAction* action = menu->addAction(KisIconUtils::loadIcon("view-preview"), i18n("Thumbnails"), this, SLOT(slotThumbnailMode())); action->setCheckable(true); action->setChecked(mode == KisPresetChooser::THUMBNAIL); action->setActionGroup(actionGroup); action = menu->addAction(KisIconUtils::loadIcon("view-list-details"), i18n("Details"), this, SLOT(slotDetailMode())); action->setCheckable(true); action->setChecked(mode == KisPresetChooser::DETAIL); action->setActionGroup(actionGroup); // add widget slider to control icon size QSlider* iconSizeSlider = new QSlider(this); iconSizeSlider->setOrientation(Qt::Horizontal); iconSizeSlider->setRange(30, 80); iconSizeSlider->setValue(m_d->uiWdgPaintOpPresets.wdgPresetChooser->iconSize()); iconSizeSlider->setMinimumHeight(20); iconSizeSlider->setMinimumWidth(40); iconSizeSlider->setTickInterval(10); QWidgetAction *sliderAction= new QWidgetAction(this); sliderAction->setDefaultWidget(iconSizeSlider); menu->addSection(i18n("Icon Size")); menu->addAction(sliderAction); // setting the view mode m_d->uiWdgPaintOpPresets.wdgPresetChooser->setViewMode(mode); m_d->uiWdgPaintOpPresets.wdgPresetChooser->showTaggingBar(true); m_d->uiWdgPaintOpPresets.wdgPresetChooser->itemChooser()->setViewModeButtonVisible(true); QToolButton *viewModeButton = m_d->uiWdgPaintOpPresets.wdgPresetChooser->itemChooser()->viewModeButton(); viewModeButton->setMenu(menu); connect(m_d->uiWdgPaintOpPresets.wdgPresetChooser, SIGNAL(resourceSelected(KoResource*)), this, SIGNAL(resourceSelected(KoResource*))); connect(m_d->uiWdgPaintOpPresets.wdgPresetChooser, SIGNAL(resourceClicked(KoResource*)), this, SIGNAL(resourceClicked(KoResource*))) ; connect (iconSizeSlider, SIGNAL(sliderMoved(int)), m_d->uiWdgPaintOpPresets.wdgPresetChooser, SLOT(setIconSize(int))); connect( iconSizeSlider, SIGNAL(sliderReleased()), m_d->uiWdgPaintOpPresets.wdgPresetChooser, SLOT(saveIconSize())); m_d->firstShown = true; } KisPaintOpPresetsChooserPopup::~KisPaintOpPresetsChooserPopup() { delete m_d; } void KisPaintOpPresetsChooserPopup::slotThumbnailMode() { KisConfig().setPresetChooserViewMode(KisPresetChooser::THUMBNAIL); m_d->uiWdgPaintOpPresets.wdgPresetChooser->setViewMode(KisPresetChooser::THUMBNAIL); } void KisPaintOpPresetsChooserPopup::slotDetailMode() { KisConfig().setPresetChooserViewMode(KisPresetChooser::DETAIL); m_d->uiWdgPaintOpPresets.wdgPresetChooser->setViewMode(KisPresetChooser::DETAIL); } void KisPaintOpPresetsChooserPopup::paintEvent(QPaintEvent* event) { QWidget::paintEvent(event); //Workaround to get the column and row size right if(m_d->firstShown) { m_d->uiWdgPaintOpPresets.wdgPresetChooser->updateViewSettings(); m_d->firstShown = false; } } void KisPaintOpPresetsChooserPopup::showButtons(bool show) { m_d->uiWdgPaintOpPresets.wdgPresetChooser->showButtons(show); } void KisPaintOpPresetsChooserPopup::canvasResourceChanged(KisPaintOpPresetSP preset) { if (preset) { blockSignals(true); m_d->uiWdgPaintOpPresets.wdgPresetChooser->setCurrentResource(preset.data()); blockSignals(false); } m_d->uiWdgPaintOpPresets.wdgPresetChooser->updateViewSettings(); } void KisPaintOpPresetsChooserPopup::updateViewSettings() { m_d->uiWdgPaintOpPresets.wdgPresetChooser->updateViewSettings(); }