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("view-list-details"), i18n("Details"), this, SLOT(slotDetailMode()));
56 action->setCheckable(true);
57 action->setChecked(mode == KisPresetChooser::DETAIL);
58 action->setActionGroup(actionGroup);
59
60 // add widget slider to control icon size
61 QSlider* iconSizeSlider = new QSlider(this);
62 iconSizeSlider->setOrientation(Qt::Horizontal);
63 iconSizeSlider->setRange(30, 80);
64 iconSizeSlider->setValue(m_d->uiWdgPaintOpPresets.wdgPresetChooser->iconSize());
65 iconSizeSlider->setMinimumHeight(20);
66 iconSizeSlider->setMinimumWidth(40);
67 iconSizeSlider->setTickInterval(10);
68 m_d->iconSizeSlider = iconSizeSlider;
69
70 QWidgetAction *sliderAction= new QWidgetAction(this);
71 sliderAction->setDefaultWidget(iconSizeSlider);
72
73 menu->addSection(i18n("Icon Size"));
74 menu->addAction(sliderAction);
75
76
77
78 // setting the view mode
79 m_d->uiWdgPaintOpPresets.wdgPresetChooser->setViewMode(mode);
80 m_d->uiWdgPaintOpPresets.wdgPresetChooser->showTaggingBar(true);
81
82 m_d->uiWdgPaintOpPresets.wdgPresetChooser->itemChooser()->showViewModeBtn(true);
83 m_d->viewModeButton = m_d->uiWdgPaintOpPresets.wdgPresetChooser->itemChooser()->viewModeButton();
85
86
87 connect(m_d->uiWdgPaintOpPresets.wdgPresetChooser, SIGNAL(resourceSelected(KoResourceSP )),
88 this, SIGNAL(resourceSelected(KoResourceSP )));
89 connect(m_d->uiWdgPaintOpPresets.wdgPresetChooser, SIGNAL(resourceClicked(KoResourceSP )),
90 this, SIGNAL(resourceClicked(KoResourceSP ))) ;
91
92
93 connect(iconSizeSlider, SIGNAL(valueChanged(int)),
94 m_d->uiWdgPaintOpPresets.wdgPresetChooser, SLOT(setIconSize(int)));
95 connect(menu, SIGNAL(aboutToHide()),
96 m_d->uiWdgPaintOpPresets.wdgPresetChooser, SLOT(saveIconSize()));
97 connect(m_d->viewModeButton, SIGNAL(pressed()), this, SLOT(slotUpdateMenu()));
98
99}
100
105
111
117
119{
120 QSignalBlocker b(m_d->iconSizeSlider);
121 m_d->iconSizeSlider->setValue(KisConfig(true).presetIconSize());
122}
123
125{
126 QWidget::paintEvent(event);
127 //Workaround to get the column and row size right
128 if(m_d->firstShown) {
129 m_d->uiWdgPaintOpPresets.wdgPresetChooser->updateViewSettings();
130 m_d->firstShown = false;
131 }
132}
133
135{
136 if (preset) {
137 blockSignals(true);
138 m_d->uiWdgPaintOpPresets.wdgPresetChooser->setCurrentResource(preset);
139 blockSignals(false);
140 }
141 m_d->uiWdgPaintOpPresets.wdgPresetChooser->updateViewSettings();
142}
143
145{
146 m_d->viewModeButton->setIcon(KisIconUtils::loadIcon("view-choose"));
147 m_d->uiWdgPaintOpPresets.wdgPresetChooser->itemChooser()->updateView(); // updates other icons
148}
149
151{
152 m_d->uiWdgPaintOpPresets.wdgPresetChooser->updateViewSettings();
153}
154
156{
157 m_d->uiWdgPaintOpPresets.wdgPresetChooser->itemChooser()->setResponsiveness(value);
158}
float value(const T *src, size_t ch)
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
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)
@ DETAIL
Shows thumbnails.
QIcon loadIcon(const QString &name)