Krita Source Code Documentation
Loading...
Searching...
No Matches
SvgSymbolCollectionDocker Class Reference

#include <SvgSymbolCollectionDocker.h>

+ Inheritance diagram for SvgSymbolCollectionDocker:

Public Slots

void slotScrollerStateChanged (QScroller::State state)
 

Public Member Functions

void setCanvas (KoCanvasBase *canvas) override
 reimplemented
 
 SvgSymbolCollectionDocker (QWidget *parent=0)
 
void unsetCanvas () override
 
 ~SvgSymbolCollectionDocker ()
 
- Public Member Functions inherited from KoCanvasObserverBase
 KoCanvasObserverBase ()
 
KoCanvasBaseobservedCanvas () const
 
virtual QString observerName ()
 
void setObservedCanvas (KoCanvasBase *canvas)
 
void unsetObservedCanvas ()
 
virtual ~KoCanvasObserverBase ()
 

Private Slots

void collectionActivated (int index)
 
void slotChangeDisplay ()
 
void slotResourceModelAboutToBeReset ()
 
void slotResourceModelReset ()
 
void slotSetIconSize ()
 

Private Member Functions

void clearModels ()
 

Private Attributes

QMap< int, SvgCollectionModel * > m_collectionsModelsCache
 
KConfigGroup m_configGroup
 
QRadioButton * m_detailsRadioButton {0}
 
QSlider * m_iconSizeSlider {0}
 
int m_rememberedSvgCollectionId {-1}
 
KisResourceModelm_resourceModel {0}
 
QRadioButton * m_thumbnailsRadioButton {0}
 
QScopedPointer< Ui_WdgSvgCollection > m_wdgSvgCollection
 

Additional Inherited Members

Detailed Description

Definition at line 62 of file SvgSymbolCollectionDocker.h.

Constructor & Destructor Documentation

◆ SvgSymbolCollectionDocker()

SvgSymbolCollectionDocker::SvgSymbolCollectionDocker ( QWidget * parent = 0)
explicit

Definition at line 167 of file SvgSymbolCollectionDocker.cpp.

168 : QDockWidget(parent)
169 , m_wdgSvgCollection(new Ui_WdgSvgCollection())
170{
171 setWindowTitle(i18n("Symbol Libraries"));
172 QWidget* mainWidget = new QWidget(this);
173 setWidget(mainWidget);
174 m_wdgSvgCollection->setupUi(mainWidget);
175
176 connect(m_wdgSvgCollection->cmbCollections, SIGNAL(activated(int)), SLOT(collectionActivated(int)));
177
179
180 m_wdgSvgCollection->cmbCollections->setModel(m_resourceModel);
181 m_wdgSvgCollection->cmbCollections->setModelColumn(KisAbstractResourceModel::Name);
182
183 m_wdgSvgCollection->listCollection->setDragEnabled(true);
184 m_wdgSvgCollection->listCollection->setDragDropMode(QAbstractItemView::DragOnly);
185 m_wdgSvgCollection->listCollection->setSelectionMode(QListView::SingleSelection);
186
187 QScroller *scroller = KisKineticScroller::createPreconfiguredScroller(m_wdgSvgCollection->listCollection);
188 if (scroller) {
189 connect(scroller, SIGNAL(stateChanged(QScroller::State)),
190 this, SLOT(slotScrollerStateChanged(QScroller::State)));
191 }
192
193 // thumbnail icon changer
194 QMenu* configureMenu = new QMenu(this);
195 configureMenu->setStyleSheet("margin: 6px");
196 m_wdgSvgCollection->vectorPresetsConfigureButton->setIcon(KisIconUtils::loadIcon("view-choose"));
197 m_wdgSvgCollection->vectorPresetsConfigureButton->setPopupMode(QToolButton::InstantPopup);
198 m_wdgSvgCollection->vectorPresetsConfigureButton->setAutoRaise(true);
199
200
201 m_configGroup = KSharedConfig::openConfig()->group("SvgSymbolCollection");
202
203 // add horizontal slider for changing the icon size
204 m_iconSizeSlider = new QSlider(this);
205 m_iconSizeSlider->setOrientation(Qt::Horizontal);
206 m_iconSizeSlider->setRange(20, 80);
207 m_iconSizeSlider->setValue(m_configGroup.readEntry<int>("iconSize", 20)); // defaults to small icon size
208 m_iconSizeSlider->setMinimumHeight(20);
209 m_iconSizeSlider->setMinimumWidth(40);
210 m_iconSizeSlider->setTickInterval(10);
211
212
213 QWidgetAction *sliderAction= new QWidgetAction(this);
214 sliderAction->setDefaultWidget(m_iconSizeSlider);
215
216 m_thumbnailsRadioButton = new QRadioButton("Thumbnails", this);
217 m_detailsRadioButton = new QRadioButton("Details", this);
218
219
220 QWidgetAction *thumbnailsAction = new QWidgetAction(this);
221 thumbnailsAction->setDefaultWidget(m_thumbnailsRadioButton);
222
223 QWidgetAction *detailsAction = new QWidgetAction(this);
224 detailsAction->setDefaultWidget(m_detailsRadioButton);
225
226 bool displayThumbnails = m_configGroup.readEntry<bool>("displayThumbnails", false);
227 if (displayThumbnails) {
228 m_thumbnailsRadioButton->setChecked(true);
229 } else {
230 m_detailsRadioButton->setChecked(true);
231 }
232
233
234 configureMenu->addSection(i18n("Display"));
235 configureMenu->addAction(detailsAction);
236 configureMenu->addAction(thumbnailsAction);
237
238 configureMenu->addSection(i18n("Icon Size"));
239 configureMenu->addAction(sliderAction);
240
241 m_wdgSvgCollection->vectorPresetsConfigureButton->setMenu(configureMenu);
242 connect(m_iconSizeSlider, SIGNAL(sliderReleased()), this, SLOT(slotSetIconSize())); // resizing while sliding is too heavy of an operation
243 connect(m_thumbnailsRadioButton, SIGNAL(toggled(bool)), this, SLOT(slotChangeDisplay()));
244 connect(m_detailsRadioButton, SIGNAL(toggled(bool)), this, SLOT(slotChangeDisplay()));
245
246 int i = m_configGroup.readEntry("currentCollection", 0);
247 if (i > m_wdgSvgCollection->cmbCollections->count()) {
248 i = 0;
249 }
250 m_wdgSvgCollection->cmbCollections->setCurrentIndex(i);
252
253 connect(m_resourceModel, SIGNAL(modelAboutToBeReset()), this, SLOT(slotResourceModelAboutToBeReset()));
254 connect(m_resourceModel, SIGNAL(modelReset()), this, SLOT(slotResourceModelReset()));
255
256 m_wdgSvgCollection->listCollection->setResizeMode(QListView::Adjust);
257
258
259
262
263}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
The KisResourceModel class provides the main access to resources. It is possible to filter the resour...
QScopedPointer< Ui_WdgSvgCollection > m_wdgSvgCollection
void slotScrollerStateChanged(QScroller::State state)
QIcon loadIcon(const QString &name)
KRITAWIDGETUTILS_EXPORT QScroller * createPreconfiguredScroller(QAbstractScrollArea *target)
const QString Symbols

References collectionActivated(), connect(), KisKineticScroller::createPreconfiguredScroller(), KisIconUtils::loadIcon(), m_configGroup, m_detailsRadioButton, m_iconSizeSlider, m_resourceModel, m_thumbnailsRadioButton, m_wdgSvgCollection, KisAbstractResourceModel::Name, slotChangeDisplay(), slotResourceModelAboutToBeReset(), slotResourceModelReset(), slotScrollerStateChanged(), slotSetIconSize(), and ResourceType::Symbols.

◆ ~SvgSymbolCollectionDocker()

SvgSymbolCollectionDocker::~SvgSymbolCollectionDocker ( )

Definition at line 265 of file SvgSymbolCollectionDocker.cpp.

References clearModels().

Member Function Documentation

◆ clearModels()

void SvgSymbolCollectionDocker::clearModels ( )
private

Definition at line 373 of file SvgSymbolCollectionDocker.cpp.

374{
375 Q_FOREACH(int key, m_collectionsModelsCache.keys()) {
376 delete m_collectionsModelsCache.value(key);
377 }
379}
QMap< int, SvgCollectionModel * > m_collectionsModelsCache

References m_collectionsModelsCache.

◆ collectionActivated

void SvgSymbolCollectionDocker::collectionActivated ( int index)
privateslot

Definition at line 348 of file SvgSymbolCollectionDocker.cpp.

349{
350 if (index < m_resourceModel->rowCount()) {
351 SvgCollectionModel *model;
352 if (m_collectionsModelsCache.contains(index)) {
353 model = m_collectionsModelsCache.value(index);
354 } else {
355 QModelIndex idx = m_resourceModel->index(index, 0);
357 model = new SvgCollectionModel();
358 model->setSvgSymbolCollectionResource(r);
359 m_collectionsModelsCache.insert(index, model);
360 }
361
362
363 m_configGroup.writeEntry("currentCollection", index);
364
365 m_wdgSvgCollection->listCollection->setModel(model);
366
367 }
368 slotChangeDisplay(); // to ensure the ShowDescription is set to the model
369 slotSetIconSize(); // to ensure the icon size is correct and they are not scaled up or down by the listview
370
371}
KoResourceSP resourceForIndex(QModelIndex index=QModelIndex()) const override
resourceForIndex returns a properly versioned and id'ed resource object

References m_collectionsModelsCache, m_configGroup, m_resourceModel, m_wdgSvgCollection, KisResourceModel::resourceForIndex(), slotChangeDisplay(), and slotSetIconSize().

◆ setCanvas()

void SvgSymbolCollectionDocker::setCanvas ( KoCanvasBase * canvas)
overridevirtual

reimplemented

Implements KoCanvasObserverBase.

Definition at line 338 of file SvgSymbolCollectionDocker.cpp.

339{
340 setEnabled(canvas != 0);
341}

◆ slotChangeDisplay

void SvgSymbolCollectionDocker::slotChangeDisplay ( )
privateslot

Definition at line 282 of file SvgSymbolCollectionDocker.cpp.

283{
284 QAbstractItemModel* model = m_wdgSvgCollection->listCollection->model();
285 SvgCollectionModel* svgModel = 0;
286 if (model) {
287 svgModel = dynamic_cast<SvgCollectionModel*>(model);
288 }
289
290 if (m_thumbnailsRadioButton->isChecked()) {
291 m_wdgSvgCollection->listCollection->setViewMode(QListView::IconMode);
292 if (svgModel) {
293 svgModel->setShowDescription(false);
294 }
295 m_configGroup.writeEntry<bool>("displayThumbnails", true);
296 } else {
297 m_wdgSvgCollection->listCollection->setViewMode(QListView::ListMode);
298 if (svgModel) {
299 svgModel->setShowDescription(true);
300 }
301 m_configGroup.writeEntry<bool>("displayThumbnails", false);
302 }
303}
void setShowDescription(bool showDescription)

References m_configGroup, m_thumbnailsRadioButton, m_wdgSvgCollection, and SvgCollectionModel::setShowDescription().

◆ slotResourceModelAboutToBeReset

void SvgSymbolCollectionDocker::slotResourceModelAboutToBeReset ( )
privateslot

Definition at line 305 of file SvgSymbolCollectionDocker.cpp.

306{
307 int index = m_wdgSvgCollection->cmbCollections->currentIndex();
308 QModelIndex idx = m_resourceModel->index(index, 0);
309 int id = m_resourceModel->data(idx, Qt::UserRole + KisAbstractResourceModel::Id).toInt();
311}

References KisAbstractResourceModel::Id, m_rememberedSvgCollectionId, m_resourceModel, and m_wdgSvgCollection.

◆ slotResourceModelReset

void SvgSymbolCollectionDocker::slotResourceModelReset ( )
privateslot

Definition at line 313 of file SvgSymbolCollectionDocker.cpp.

314{
315 int indexToSet = 0;
317 indexToSet = 0;
318 } else {
319 for (int i = 0; i < m_resourceModel->rowCount(); i++) {
320 QModelIndex idx = m_resourceModel->index(i, 0);
321 int id = m_resourceModel->data(idx, Qt::UserRole + KisAbstractResourceModel::Id).toInt();
322 if (id == m_rememberedSvgCollectionId) {
323 indexToSet = i;
324 break;
325 }
326 }
327 }
328 // remove the current model from the view
329 m_wdgSvgCollection->listCollection->setModel(0);
330 // delete all models
331 clearModels();
332 // setting current index will create and set the model
333 m_wdgSvgCollection->cmbCollections->setCurrentIndex(indexToSet);
334 collectionActivated(indexToSet);
336}

References clearModels(), collectionActivated(), KisAbstractResourceModel::Id, m_rememberedSvgCollectionId, m_resourceModel, and m_wdgSvgCollection.

◆ slotScrollerStateChanged

void SvgSymbolCollectionDocker::slotScrollerStateChanged ( QScroller::State state)
inlineslot

Definition at line 75 of file SvgSymbolCollectionDocker.h.

KRITAWIDGETUTILS_EXPORT void updateCursor(QWidget *source, QScroller::State state)

References KisKineticScroller::updateCursor().

◆ slotSetIconSize

void SvgSymbolCollectionDocker::slotSetIconSize ( )
privateslot

Definition at line 270 of file SvgSymbolCollectionDocker.cpp.

271{
272 int size = m_iconSizeSlider->value();
273 m_configGroup.writeEntry("iconSize", size);
274 m_wdgSvgCollection->listCollection->setIconSize(QSize(size, size));
275 QAbstractItemModel* model = m_wdgSvgCollection->listCollection->model();
276 if (model) {
277 SvgCollectionModel* svgModel = dynamic_cast<SvgCollectionModel*>(model);
278 svgModel->setIconSize(size*devicePixelRatioF());
279 }
280}
int size(const Forest< T > &forest)
Definition KisForest.h:1232

References m_configGroup, m_iconSizeSlider, m_wdgSvgCollection, and SvgCollectionModel::setIconSize().

◆ unsetCanvas()

void SvgSymbolCollectionDocker::unsetCanvas ( )
overridevirtual

Re-implement to notify the observer that its canvas is no longer among the living. The daisies, it is pushing up. This means you don't have to disconnect, it's dead.

The old canvas should be deleted already, so if you stored a pointer to it, don't touch!

Note that currently there is a bug where in certain specific circumstances unsetCanvas can be called when it shouldn't, see for example KWStatisticsDocker for a workaround for this problem.

Implements KoCanvasObserverBase.

Definition at line 343 of file SvgSymbolCollectionDocker.cpp.

344{
345 setEnabled(false);
346}

Member Data Documentation

◆ m_collectionsModelsCache

QMap<int, SvgCollectionModel*> SvgSymbolCollectionDocker::m_collectionsModelsCache
private

Definition at line 92 of file SvgSymbolCollectionDocker.h.

◆ m_configGroup

KConfigGroup SvgSymbolCollectionDocker::m_configGroup
private

Definition at line 101 of file SvgSymbolCollectionDocker.h.

◆ m_detailsRadioButton

QRadioButton* SvgSymbolCollectionDocker::m_detailsRadioButton {0}
private

Definition at line 95 of file SvgSymbolCollectionDocker.h.

95{0};

◆ m_iconSizeSlider

QSlider* SvgSymbolCollectionDocker::m_iconSizeSlider {0}
private

Definition at line 93 of file SvgSymbolCollectionDocker.h.

93{0};

◆ m_rememberedSvgCollectionId

int SvgSymbolCollectionDocker::m_rememberedSvgCollectionId {-1}
private

Definition at line 99 of file SvgSymbolCollectionDocker.h.

99{-1};

◆ m_resourceModel

KisResourceModel* SvgSymbolCollectionDocker::m_resourceModel {0}
private

Definition at line 98 of file SvgSymbolCollectionDocker.h.

98{0};

◆ m_thumbnailsRadioButton

QRadioButton* SvgSymbolCollectionDocker::m_thumbnailsRadioButton {0}
private

Definition at line 94 of file SvgSymbolCollectionDocker.h.

94{0};

◆ m_wdgSvgCollection

QScopedPointer<Ui_WdgSvgCollection> SvgSymbolCollectionDocker::m_wdgSvgCollection
private

Definition at line 91 of file SvgSymbolCollectionDocker.h.


The documentation for this class was generated from the following files: