Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_paintop_presets_chooser_popup.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 * SPDX-FileCopyrightText: 2010 Sven Langkamp <sven.langkamp@gmail.com>
3 * SPDX-FileCopyrightText: 2011 Srikanth Tiyyagura <srikanth.tulasiram@gmail.com>
4 *
5 * SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7
9
10#include <QCompleter>
11#include <QMenu>
12#include <QWidgetAction>
13#include <QSlider>
14#include <QActionGroup>
15
16#include <KoResource.h>
18
19#include <ui_wdgpaintoppresets.h>
20#include <kis_config.h>
23#include <kis_icon.h>
25#include "KisPopupButton.h"
26
28{
29public:
30 Ui_WdgPaintOpPresets uiWdgPaintOpPresets;
31 bool firstShown {true};
32 QSlider* iconSizeSlider {nullptr};
34};
35
37 : QWidget(parent)
38 , m_d(new Private())
39{
40 m_d->uiWdgPaintOpPresets.setupUi(this);
41 QMenu* menu = new QMenu(this);
42 menu->setStyleSheet("margin: 6px");
43
44 menu->addSection(i18nc("@title Which elements to display (e.g., thumbnails or details)", "Display"));
45
46 QActionGroup *actionGroup = new QActionGroup(this);
47
49
50 QAction* action = menu->addAction(KisIconUtils::loadIcon("view-preview"), i18n("Thumbnails"), this, SLOT(slotThumbnailMode()));
51 action->setCheckable(true);
52 action->setChecked(mode == KisPresetChooser::THUMBNAIL);
53 action->setActionGroup(actionGroup);
54
55 action = menu->addAction(KisIconUtils::loadIcon("krita_tool_freehand"), i18n("Strokes"), this, SLOT(slotStrokeMode()));
56 action->setCheckable(true);
57 action->setChecked(mode == KisPresetChooser::STROKE);
58 action->setActionGroup(actionGroup);
59
60 action = menu->addAction(KisIconUtils::loadIcon("krita_tool_freehand"), i18n("Strokes and Thumbnails"), this, SLOT(slotStrokeThumbnailMode()));
61 action->setCheckable(true);
62 action->setChecked(mode == KisPresetChooser::STROKE_THUMBNAIL);
63 action->setActionGroup(actionGroup);
64
65 // add widget slider to control icon size
66 QSlider* iconSizeSlider = new QSlider(this);
67 iconSizeSlider->setOrientation(Qt::Horizontal);
68 iconSizeSlider->setRange(30, 80);
69 iconSizeSlider->setValue(m_d->uiWdgPaintOpPresets.wdgPresetChooser->iconSize());
70 iconSizeSlider->setMinimumHeight(20);
71 iconSizeSlider->setMinimumWidth(40);
72 iconSizeSlider->setTickInterval(10);
73 m_d->iconSizeSlider = iconSizeSlider;
74
75 QWidgetAction *sliderAction= new QWidgetAction(this);
76 sliderAction->setDefaultWidget(iconSizeSlider);
77
78 menu->addSection(i18n("Icon Size"));
79 menu->addAction(sliderAction);
80
81
82
83 // setting the view mode
84 m_d->uiWdgPaintOpPresets.wdgPresetChooser->setViewMode(mode);
85 m_d->uiWdgPaintOpPresets.wdgPresetChooser->showTaggingBar(true);
86
87 m_d->uiWdgPaintOpPresets.wdgPresetChooser->itemChooser()->showViewModeBtn(true);
88 m_d->viewModeButton = m_d->uiWdgPaintOpPresets.wdgPresetChooser->itemChooser()->viewModeButton();
90
91
92 connect(m_d->uiWdgPaintOpPresets.wdgPresetChooser, SIGNAL(resourceSelected(KoResourceSP )),
93 this, SIGNAL(resourceSelected(KoResourceSP )));
94 connect(m_d->uiWdgPaintOpPresets.wdgPresetChooser, SIGNAL(resourceClicked(KoResourceSP )),
95 this, SIGNAL(resourceClicked(KoResourceSP ))) ;
96
97
98 connect(iconSizeSlider, SIGNAL(valueChanged(int)),
99 m_d->uiWdgPaintOpPresets.wdgPresetChooser, SLOT(setIconSize(int)));
100 connect(menu, SIGNAL(aboutToHide()),
101 m_d->uiWdgPaintOpPresets.wdgPresetChooser, SLOT(saveIconSize()));
102 connect(m_d->viewModeButton, SIGNAL(pressed()), this, SLOT(slotUpdateMenu()));
103
104}
105
110
116
122
128
130{
131 QSignalBlocker b(m_d->iconSizeSlider);
132 m_d->iconSizeSlider->setValue(KisConfig(true).presetIconSize());
133}
134
136{
137 QWidget::paintEvent(event);
138 //Workaround to get the column and row size right
139 if(m_d->firstShown) {
140 m_d->uiWdgPaintOpPresets.wdgPresetChooser->updateViewSettings();
141 m_d->firstShown = false;
142 }
143}
144
146{
147 if (preset) {
148 blockSignals(true);
149 m_d->uiWdgPaintOpPresets.wdgPresetChooser->setCurrentResource(preset);
150 blockSignals(false);
151 }
152 m_d->uiWdgPaintOpPresets.wdgPresetChooser->updateViewSettings();
153}
154
156{
157 m_d->viewModeButton->setIcon(KisIconUtils::loadIcon("view-choose"));
158 m_d->uiWdgPaintOpPresets.wdgPresetChooser->itemChooser()->updateView(); // updates other icons
159}
160
162{
163 m_d->uiWdgPaintOpPresets.wdgPresetChooser->updateViewSettings();
164}
165
167{
168 m_d->uiWdgPaintOpPresets.wdgPresetChooser->itemChooser()->setResponsiveness(value);
169}
float value(const T *src, size_t ch)
int presetChooserViewMode(bool defaultValue=false) const
void setPresetChooserViewMode(const int mode) const
void resourceClicked(KoResourceSP resource)
void canvasResourceChanged(KisPaintOpPresetSP preset)
void resourceSelected(KoResourceSP resource)
void setPopupWidget(QWidget *widget)
@ STROKE_THUMBNAIL
Shows thumbnails.
@ STROKE
Shows stroke previews with text and thumbnail.
QIcon loadIcon(const QString &name)