Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 0b2d5353 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Separate KoResourceManager for canvas and document

KoResourceManager was used in two places: the canvas and document
classes. This gave rise to endless confusion about which resource
manager should be used where and contains what. The KoResourceManager
api also contained methods that were only relevant when used from
a document and others that were only relevant when used from a canvas.

This patch splits the resourcemanager into two public and one private
class. The public classes are KoDocumentResourceManager and
KoCanvasResourceManager, the private class is KoResourceManager. The
public classes defer to the private class for code-sharing purposes.

The old KoCanvasResource and KoDocumentResource enums have been taken
into the classes themselves.
parent 10f89a50
......@@ -23,7 +23,6 @@
#include <KoDockFactoryBase.h>
#include <KoDockRegistry.h>
#include <KoResourceManager.h>
#include "kis_color_selector_ng_dock.h"
#include "kis_color_selector_settings.h"
......@@ -82,7 +81,7 @@ ColorSelectorNgPlugin::ColorSelectorNgPlugin(QObject *parent, const QVariantList
ColorSelectorNgPlugin::~ColorSelectorNgPlugin()
{
}
#include "colorselectorng.moc"
......@@ -28,7 +28,7 @@
#include <KGlobal>
#include "kis_canvas2.h"
#include "KoResourceManager.h"
#include "KoCanvasResourceManager.h"
KisColorPatches::KisColorPatches(QString configPrefix, QWidget *parent) :
KisColorSelectorBase(parent), m_allowColorListChangeGuard(true), m_scrollValue(0), m_configPrefix(configPrefix)
......
......@@ -444,7 +444,7 @@ void KisColorSelectorBase::updateColorPreview(const QColor& color)
void KisColorSelectorBase::resourceChanged(int key, const QVariant &v)
{
if (key == KoCanvasResource::ForegroundColor || key == KoCanvasResource::BackgroundColor) {
if (key == KoCanvasResourceManager::ForegroundColor || key == KoCanvasResourceManager::BackgroundColor) {
QColor c = findGeneratingColor(v.value<KoColor>());
updateColorPreview(c);
if(m_colorUpdateAllowed==false)
......
......@@ -27,7 +27,7 @@
#include <KComponentData>
#include <KGlobal>
#include "KoResourceManager.h"
#include "KoCanvasResourceManager.h"
#include "kis_shade_selector_line.h"
......@@ -147,8 +147,8 @@ void KisMinimalShadeSelector::resourceChanged(int key, const QVariant &v)
bool onForeground = cfg.readEntry("shadeSelectorUpdateOnForeground", false);
bool onBackground = cfg.readEntry("shadeSelectorUpdateOnBackground", true);
if ((key == KoCanvasResource::ForegroundColor && onForeground)
|| (key == KoCanvasResource::BackgroundColor && onBackground)) {
if ((key == KoCanvasResourceManager::ForegroundColor && onForeground)
|| (key == KoCanvasResourceManager::BackgroundColor && onBackground)) {
setColor(findGeneratingColor(v.value<KoColor>()));
}
}
......
......@@ -41,7 +41,7 @@
#include "KoColorSpace.h"
#include "KoColorSpaceRegistry.h"
#include "KoColor.h"
#include "KoResourceManager.h"
#include "KoCanvasResourceManager.h"
inline int sqr(int x);
inline qreal sqr2(qreal x);
......@@ -256,8 +256,8 @@ void KisMyPaintShadeSelector::resourceChanged(int key, const QVariant &v)
bool onForeground = cfg.readEntry("shadeSelectorUpdateOnForeground", false);
bool onBackground = cfg.readEntry("shadeSelectorUpdateOnBackground", true);
if ((key == KoCanvasResource::ForegroundColor && onForeground)
|| (key == KoCanvasResource::BackgroundColor && onBackground)) {
if ((key == KoCanvasResourceManager::ForegroundColor && onForeground)
|| (key == KoCanvasResourceManager::BackgroundColor && onBackground)) {
setColor(findGeneratingColor(v.value<KoColor>()));
}
}
......
......@@ -26,8 +26,7 @@
#include <KComponentData>
#include <KGlobal>
#include <KLocale>
#include "KoResourceManager.h"
#include <KoColor.h>
#include "KoColorSpaceRegistry.h"
#include "kis_canvas2.h"
......
......@@ -16,7 +16,7 @@
*/
#include <klocale.h>
#include <KoResourceManager.h>
#include <KoCanvasResourceManager.h>
#include <KoCanvasBase.h>
#include <QWidget>
......@@ -52,27 +52,27 @@ ArtisticColorSelectorDock::ArtisticColorSelectorDock():
m_resetMenu = new QMenu();
m_preferencesUI = new ColorPreferencesPopupUI();
m_selectorUI = new ArtisticColorSelectorUI();
m_resetMenu->addAction(i18n("Reset All Rings"))->setData(ACTION_RESET_EVERY_RING);
m_resetMenu->addAction(i18n("Reset Selected Ring"))->setData(ACTION_RESET_SELECTED_RING);
m_resetMenu->addAction(i18n("Reset Light"))->setData(ACTION_RESET_LIGHT);
m_resetMenu->addAction(i18n("Reset Everything"))->setData(ACTION_RESET_EVERYTHING);
m_selectorUI->bnColorPrefs->setPopupWidget(m_preferencesUI);
m_selectorUI->bnReset->setMenu(m_resetMenu);
m_hsxButtons->addButton(m_preferencesUI->bnHsy, KisColor::HSY);
m_hsxButtons->addButton(m_preferencesUI->bnHsi, KisColor::HSI);
m_hsxButtons->addButton(m_preferencesUI->bnHsl, KisColor::HSL);
m_hsxButtons->addButton(m_preferencesUI->bnHsv, KisColor::HSV);
m_preferencesUI->numPiecesSlider->setRange(1, 48);
m_preferencesUI->numPiecesSlider->setValue(12);
m_preferencesUI->numRingsSlider->setRange(1, 20);
m_preferencesUI->numRingsSlider->setValue(11);
m_preferencesUI->numLightPiecesSlider->setRange(1, 30);
m_preferencesUI->numLightPiecesSlider->setValue(19);
connect(m_preferencesUI->numLightPiecesSlider, SIGNAL(valueChanged(int)) , SLOT(slotPreferenceChanged()));
connect(m_preferencesUI->numPiecesSlider , SIGNAL(valueChanged(int)) , SLOT(slotPreferenceChanged()));
connect(m_preferencesUI->numRingsSlider , SIGNAL(valueChanged(int)) , SLOT(slotPreferenceChanged()));
......@@ -85,7 +85,7 @@ ArtisticColorSelectorDock::ArtisticColorSelectorDock():
connect(m_resetMenu , SIGNAL(triggered(QAction*)) , SLOT(slotMenuActionTriggered(QAction*)));
connect(this , SIGNAL(topLevelChanged(bool)) , SLOT(slotTopLevelChanged(bool)));
connect(this , SIGNAL(dockLocationChanged(Qt::DockWidgetArea)), SLOT(slotDockLocationChanged(Qt::DockWidgetArea)));
setWidget(m_selectorUI);
slotColorSpaceSelected(KisColor::HSY);
slotPreferenceChanged();
......@@ -102,7 +102,7 @@ void ArtisticColorSelectorDock::setCanvas(KoCanvasBase* canvas)
// "Every connection you make emits a signal, so duplicate connections emit two signals"
if(m_canvas)
m_canvas->disconnectCanvasObserver(this);
m_canvas = canvas;
m_selectorUI->colorSelector->setFgColor(m_canvas->resourceManager()->foregroundColor().toQColor());
m_selectorUI->colorSelector->setBgColor(m_canvas->resourceManager()->backgroundColor().toQColor());
......@@ -111,10 +111,10 @@ void ArtisticColorSelectorDock::setCanvas(KoCanvasBase* canvas)
void ArtisticColorSelectorDock::slotResourceChanged(int key, const QVariant& value)
{
if(key == KoCanvasResource::ForegroundColor)
if(key == KoCanvasResourceManager::ForegroundColor)
m_selectorUI->colorSelector->setFgColor(value.value<KoColor>().toQColor());
if(key == KoCanvasResource::BackgroundColor)
if(key == KoCanvasResourceManager::BackgroundColor)
m_selectorUI->colorSelector->setBgColor(value.value<KoColor>().toQColor());
}
......@@ -152,15 +152,15 @@ void ArtisticColorSelectorDock::slotMenuActionTriggered(QAction* action)
case ACTION_RESET_SELECTED_RING:
m_selectorUI->colorSelector->resetSelectedRing();
break;
case ACTION_RESET_EVERY_RING:
m_selectorUI->colorSelector->resetRings();
break;
case ACTION_RESET_LIGHT:
m_selectorUI->colorSelector->resetLight();
break;
case ACTION_RESET_EVERYTHING:
m_selectorUI->colorSelector->resetLight();
m_selectorUI->colorSelector->resetRings();
......@@ -174,12 +174,12 @@ void ArtisticColorSelectorDock::slotResetDefaultSettings()
m_preferencesUI->numRingsSlider->blockSignals(true);
m_preferencesUI->numRingsSlider->setValue(7);
m_preferencesUI->numRingsSlider->blockSignals(false);
m_selectorUI->colorSelector->setNumPieces(12);
m_preferencesUI->numPiecesSlider->blockSignals(true);
m_preferencesUI->numPiecesSlider->setValue(12);
m_preferencesUI->numPiecesSlider->blockSignals(false);
m_selectorUI->colorSelector->setNumLightPieces(9);
m_preferencesUI->numLightPiecesSlider->blockSignals(true);
m_preferencesUI->numLightPiecesSlider->setValue(9);
......@@ -199,7 +199,7 @@ void ArtisticColorSelectorDock::slotDockLocationChanged(Qt::DockWidgetArea area)
else {
if(area & Qt::LeftDockWidgetArea)
m_selectorUI->colorSelector->setLightStripPosition(KisColorSelector::LSP_RIGHT);
if(area & Qt::RightDockWidgetArea)
m_selectorUI->colorSelector->setLightStripPosition(KisColorSelector::LSP_LEFT);
}
......
......@@ -22,7 +22,6 @@
#include <QHeaderView>
#include <klocale.h>
#include <KoResourceManager.h>
#include <KoCanvasBase.h>
#include "channelmodel.h"
#include <kis_view2.h>
......
......@@ -25,7 +25,7 @@
#include <KoResource.h>
#include <KoColorSet.h>
#include <KoColorSetWidget.h>
#include <KoResourceManager.h>
#include <KoCanvasResourceManager.h>
#include <KoColorSpaceRegistry.h>
KisPaletteDocker::KisPaletteDocker()
......
......@@ -27,7 +27,7 @@
#include <KoColorSlider.h>
#include <KoColorPopupAction.h>
#include <KoColorSpaceRegistry.h>
#include <KoResourceManager.h>
#include <KoCanvasResourceManager.h>
#include <KoCanvasBase.h>
class DigitalMixerPatch : public KoColorPatch {
......@@ -39,32 +39,32 @@ class DigitalMixerPatch : public KoColorPatch {
}
};
DigitalMixerDock::DigitalMixerDock( )
DigitalMixerDock::DigitalMixerDock( )
: QDockWidget(i18n("Digital Colors Mixer")), m_canvas(0)
, m_tellCanvas(true)
{
QColor initColors[6] = { Qt::black, Qt::white, Qt::red, Qt::green, Qt::blue, Qt::yellow };
QWidget* widget = new QWidget(this);
QGridLayout* layout = new QGridLayout( widget );
// Current Color
m_currentColorPatch = new KoColorPatch(this);
m_currentColorPatch->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
m_currentColorPatch->setMinimumWidth(12);
layout->addWidget(m_currentColorPatch, 0, 0,3,1);
// Create the sliders
QSignalMapper* signalMapperSelectColor = new QSignalMapper(this);
connect(signalMapperSelectColor, SIGNAL(mapped(int)), SLOT(popupColorChanged(int)));
QSignalMapper* signalMapperColorSlider = new QSignalMapper(this);
connect(signalMapperColorSlider, SIGNAL(mapped(int)), SLOT(colorSliderChanged(int)));
QSignalMapper* signalMapperTargetColor = new QSignalMapper(this);
connect(signalMapperTargetColor, SIGNAL(mapped(int)), SLOT(targetColorChanged(int)));
for(int i = 0; i < 6; ++i)
{
Mixer mixer;
......@@ -77,16 +77,16 @@ DigitalMixerDock::DigitalMixerDock( )
mixer.actionColor->setCurrentColor(initColors[i]);
colorSelector->setDefaultAction(mixer.actionColor);
layout->addWidget(colorSelector, 2, i + 1);
m_mixers.push_back(mixer);
connect(mixer.actionColor, SIGNAL(colorChanged(KoColor)), signalMapperSelectColor, SLOT(map()));
signalMapperSelectColor->setMapping(mixer.actionColor, i);
connect(mixer.targetSlider, SIGNAL(valueChanged(int)), signalMapperColorSlider, SLOT(map()));
signalMapperColorSlider->setMapping(mixer.targetSlider, i);
mixer.targetSlider->setValue(125);
connect(mixer.targetColor, SIGNAL(triggered(KoColorPatch*)), signalMapperTargetColor, SLOT(map()));
signalMapperTargetColor->setMapping(mixer.targetColor, i);
}
......@@ -99,11 +99,11 @@ void DigitalMixerDock::setCanvas(KoCanvasBase * canvas)
if (m_canvas) {
m_canvas->disconnectCanvasObserver(this);
}
m_canvas = canvas;
connect(m_canvas->resourceManager(), SIGNAL(resourceChanged(int, const QVariant&)),
this, SLOT(resourceChanged(int, const QVariant&)));
m_tellCanvas=false;
setCurrentColor(m_canvas->resourceManager()->foregroundColor());
m_tellCanvas=true;
......@@ -145,7 +145,7 @@ void DigitalMixerDock::setCurrentColor(const KoColor& color)
void DigitalMixerDock::resourceChanged(int key, const QVariant& v)
{
m_tellCanvas = false;
if (key == KoCanvasResource::ForegroundColor)
if (key == KoCanvasResourceManager::ForegroundColor)
setCurrentColor(v.value<KoColor>());
m_tellCanvas = true;
}
......
......@@ -21,7 +21,7 @@
#include <klocale.h>
#include <KoResourceManager.h>
#include <KoCanvasResourceManager.h>
#include <KoCanvasBase.h>
......
......@@ -23,7 +23,6 @@
#include <KoDockFactoryBase.h>
#include <KoDockRegistry.h>
#include <KoResourceManager.h>
#include "HistoryDock.h"
......
......@@ -17,7 +17,7 @@
* Boston, MA 02110-1301, USA.
*/
#include "HistoryDock.h"
#include <KoDocumentResourceManager.h>
HistoryDock::HistoryDock() : QDockWidget(), historyCanvas(0) {
undoView = new KisUndoView(this);
setWidget(undoView);
......@@ -26,9 +26,9 @@ HistoryDock::HistoryDock() : QDockWidget(), historyCanvas(0) {
}
void HistoryDock::setCanvas(KoCanvasBase *canvas) {
KisCanvas2* myCanvas = dynamic_cast<KisCanvas2*>( canvas );
KUndo2Stack* undoStack = canvas->shapeController()->resourceManager()->undoStack();
undoView->setStack(undoStack);
......
......@@ -28,7 +28,6 @@
#include <KoShapeController.h>
#include <KoCanvasBase.h>
#include <KoResourceManager.h>
#include "kis_types.h"
#include "kis_canvas2.h"
#include "kis_view2.h"
......
......@@ -20,7 +20,7 @@
#include "kis_image_view.h"
#include <klocale.h>
#include <KoResourceManager.h>
#include <KoCanvasResourceManager.h>
#include <KoCanvasBase.h>
#include <KoColorSpaceRegistry.h>
......@@ -47,19 +47,19 @@ class ImageFilter: public QSortFilterProxyModel
virtual bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const {
QFileSystemModel* model = static_cast<QFileSystemModel*>(sourceModel());
QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
if(model->isDir(index))
return true;
m_reader.setFileName(model->filePath(index));
return m_reader.canRead();
}
virtual bool filterAcceptsColumn(int source_column, const QModelIndex& source_parent) const {
Q_UNUSED(source_parent);
return source_column == 0;
}
mutable QImageReader m_reader;
};
......@@ -75,7 +75,7 @@ class ImageListModel: public QAbstractListModel
QString text;
qint64 id;
};
public:
void addImage(const QPixmap& pixmap, const QString& text, qint64 id) {
Data data;
......@@ -86,12 +86,12 @@ public:
m_data.push_back(data);
emit layoutChanged();
}
qint64 imageID(int index) const { return m_data[index].id; }
void removeImage(qint64 id) {
typedef QList<Data>::iterator Iterator;
for(Iterator data=m_data.begin(); data!=m_data.end(); ++data) {
if(data->id == id) {
emit layoutAboutToBeChanged();
......@@ -101,7 +101,7 @@ public:
}
}
}
int indexFromID(qint64 id) {
for(int i=0; i<m_data.size(); ++i) {
if(m_data[i].id == id)
......@@ -109,12 +109,12 @@ public:
}
return -1;
}
virtual int rowCount(const QModelIndex& parent=QModelIndex()) const {
Q_UNUSED(parent);
return m_data.size();
}
virtual QVariant data(const QModelIndex& index, int role=Qt::DisplayRole) const {
if(index.isValid() && index.row() < m_data.size()) {
switch(role)
......@@ -127,7 +127,7 @@ public:
}
return QVariant();
}
private:
QList<Data> m_data;
};
......@@ -171,7 +171,7 @@ ImageDockerDock::ImageDockerDock():
m_proxyModel = new ImageFilter();
m_proxyModel->setSourceModel(m_model);
m_proxyModel->setDynamicSortFilter(true);
m_ui->bnBack->setIcon(QIcon::fromTheme("go-previous"));
m_ui->bnUp->setIcon(QIcon::fromTheme("go-up"));
m_ui->bnHome->setIcon(QIcon::fromTheme("go-home"));
......@@ -183,21 +183,21 @@ ImageDockerDock::ImageDockerDock():
m_ui->cmbImg->setModel(m_imgListModel);
m_ui->bnPopup->setIcon(QIcon::fromTheme("zoom-original"));
m_ui->bnPopup->setPopupWidget(m_popupUi);
m_popupUi->zoomSlider->setRange(5, 500);
m_popupUi->zoomSlider->setValue(100);
m_zoomButtons->addButton(m_popupUi->bnZoomFit , KisImageView::VIEW_MODE_FIT);
m_zoomButtons->addButton(m_popupUi->bnZoomAdjust, KisImageView::VIEW_MODE_ADJUST);
m_zoomButtons->addButton(m_popupUi->bnZoom25 , 25);
m_zoomButtons->addButton(m_popupUi->bnZoom50 , 50);
m_zoomButtons->addButton(m_popupUi->bnZoom75 , 75);
m_zoomButtons->addButton(m_popupUi->bnZoom100 , 100);
m_model->setRootPath(QDir::rootPath());
m_ui->treeView->setRootIndex(m_proxyModel->mapFromSource(m_model->index(QDir::homePath())));
updatePath(QDir::homePath());
connect(m_ui->treeView , SIGNAL(doubleClicked(const QModelIndex&)) , SLOT(slotItemDoubleClicked(const QModelIndex&)));
connect(m_ui->bnBack , SIGNAL(clicked(bool)) , SLOT(slotBackButtonClicked()));
connect(m_ui->bnHome , SIGNAL(clicked(bool)) , SLOT(slotHomeButtonClicked()));
......@@ -258,29 +258,29 @@ void ImageDockerDock::setCurrentImage(qint64 imageID)
{
if(m_imgInfoMap.contains(m_currImageID))
m_imgInfoMap[m_currImageID].scrollPos = m_ui->imgView->getScrollPos();
m_ui->bnImgClose->setDisabled(imageID < 0);
m_ui->bnPopup->setDisabled(imageID < 0);
if(imageID < 0) {
m_currImageID = -1;
m_ui->imgView->setPixmap(QPixmap());
}
else if(m_imgInfoMap.contains(imageID)) {
ImageInfoIter info = m_imgInfoMap.find(imageID);
m_ui->imgView->blockSignals(true);
m_ui->imgView->setPixmap(info->pixmap);
setZoom(*info);
m_ui->imgView->blockSignals(false);
m_ui->bnImgPrev->setDisabled(info == m_imgInfoMap.begin());
m_ui->bnImgNext->setDisabled((info+1) == m_imgInfoMap.end());
m_ui->cmbImg->blockSignals(true);
m_ui->cmbImg->setCurrentIndex(m_imgListModel->indexFromID(imageID));
m_ui->cmbImg->blockSignals(false);
m_currImageID = imageID;
}
}
......@@ -289,9 +289,9 @@ void ImageDockerDock::setZoom(const ImageInfo& info)
{
m_ui->imgView->setViewMode(info.viewMode, info.scale);
m_ui->imgView->setScrollPos(info.scrollPos);
int zoom = qRound(m_ui->imgView->getScale() * 100.0f);
m_popupUi->zoomSlider->blockSignals(true);
m_popupUi->zoomSlider->setValue(zoom);
m_popupUi->zoomSlider->blockSignals(false);
......@@ -305,7 +305,7 @@ void ImageDockerDock::slotItemDoubleClicked(const QModelIndex& index)
QModelIndex mappedIndex = m_proxyModel->mapToSource(index);
mappedIndex = m_model->index(mappedIndex.row(), 0, mappedIndex.parent());
QString path(m_model->filePath(mappedIndex));
if(m_model->isDir(mappedIndex)) {
addCurrentPathToHistory();
updatePath(path);
......@@ -336,11 +336,11 @@ void ImageDockerDock::slotHomeButtonClicked()
void ImageDockerDock::slotUpButtonClicked()
{
addCurrentPathToHistory();
QModelIndex index = m_proxyModel->mapToSource(m_ui->treeView->rootIndex());
QDir dir(m_model->filePath(index));
dir.makeAbsolute();
if(dir.cdUp()) {
index = m_proxyModel->mapFromSource(m_model->index(dir.path()));
m_ui->treeView->setRootIndex(index);
......@@ -351,7 +351,7 @@ void ImageDockerDock::slotUpButtonClicked()
void ImageDockerDock::slotOpenImage(const QString& path)
{
QPixmap pixmap(path);
if(!pixmap.isNull()) {
QFileInfo fileInfo(path);
ImageInfo imgInfo;
......@@ -362,7 +362,7 @@ void ImageDockerDock::slotOpenImage(const QString& path)
imgInfo.scale = 1.0f;
imgInfo.pixmap = pixmap;
imgInfo.scrollPos = QPoint(0, 0);
m_imgInfoMap[imgInfo.id] = imgInfo;
m_imgListModel->addImage(imgInfo.pixmap, imgInfo.name, imgInfo.id);
setCurrentImage(imgInfo.id);
......@@ -373,21 +373,21 @@ void ImageDockerDock::slotOpenImage(const QString& path)
void ImageDockerDock::slotCloseCurrentImage()
{
ImageInfoIter info = m_imgInfoMap.find(m_currImageID);
if(info != m_imgInfoMap.end()) {
ImageInfoIter next = info + 1;