1 /* This file is part of the KDE project
2 * Copyright (c) 2010 Sven Langkamp <sven.langkamp@gmail.com>
3 * Copyright 2011 Srikanth Tiyyagura <srikanth.tulasiram@gmail.com>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21 #include "kis_paintop_presets_chooser_popup.h"
22
23 #include <QToolButton>
24 #include <QCompleter>
25 #include <QMenu>
26 #include <QWidgetAction>
27 #include <QSlider>
28
29 #include <resources/KoResource.h>
30 #include <KoResourceItemChooser.h>
31
32 #include <ui_wdgpaintoppresets.h>
33 #include <kis_config.h>
34 #include <KisResourceServerProvider.h>
35 #include <brushengine/kis_paintop_preset.h>
36 #include <kis_icon.h>
37 #include <brushengine/kis_paintop_settings.h>
38
39 struct KisPaintOpPresetsChooserPopup::Private
40 {
41 public:
42 Ui_WdgPaintOpPresets uiWdgPaintOpPresets;
43 bool firstShown;
44 QToolButton *viewModeButton;
45 };
46
KisPaintOpPresetsChooserPopup(QWidget * parent)47 KisPaintOpPresetsChooserPopup::KisPaintOpPresetsChooserPopup(QWidget * parent)
48 : QWidget(parent)
49 , m_d(new Private())
50 {
51 m_d->uiWdgPaintOpPresets.setupUi(this);
52 QMenu* menu = new QMenu(this);
53 menu->setStyleSheet("margin: 6px");
54
55 menu->addSection(i18nc("@title Which elements to display (e.g., thumbnails or details)", "Display"));
56
57 QActionGroup *actionGroup = new QActionGroup(this);
58
59 KisPresetChooser::ViewMode mode = (KisPresetChooser::ViewMode)KisConfig(true).presetChooserViewMode();
60
61 QAction* action = menu->addAction(KisIconUtils::loadIcon("view-preview"), i18n("Thumbnails"), this, SLOT(slotThumbnailMode()));
62 action->setCheckable(true);
63 action->setChecked(mode == KisPresetChooser::THUMBNAIL);
64 action->setActionGroup(actionGroup);
65
66 action = menu->addAction(KisIconUtils::loadIcon("view-list-details"), i18n("Details"), this, SLOT(slotDetailMode()));
67 action->setCheckable(true);
68 action->setChecked(mode == KisPresetChooser::DETAIL);
69 action->setActionGroup(actionGroup);
70
71 // add widget slider to control icon size
72 QSlider* iconSizeSlider = new QSlider(this);
73 iconSizeSlider->setOrientation(Qt::Horizontal);
74 iconSizeSlider->setRange(30, 80);
75 iconSizeSlider->setValue(m_d->uiWdgPaintOpPresets.wdgPresetChooser->iconSize());
76 iconSizeSlider->setMinimumHeight(20);
77 iconSizeSlider->setMinimumWidth(40);
78 iconSizeSlider->setTickInterval(10);
79
80
81 QWidgetAction *sliderAction= new QWidgetAction(this);
82 sliderAction->setDefaultWidget(iconSizeSlider);
83
84 menu->addSection(i18n("Icon Size"));
85 menu->addAction(sliderAction);
86
87
88
89 // setting the view mode
90 m_d->uiWdgPaintOpPresets.wdgPresetChooser->setViewMode(mode);
91 m_d->uiWdgPaintOpPresets.wdgPresetChooser->showTaggingBar(true);
92
93 m_d->uiWdgPaintOpPresets.wdgPresetChooser->itemChooser()->setViewModeButtonVisible(true);
94 m_d->viewModeButton = m_d->uiWdgPaintOpPresets.wdgPresetChooser->itemChooser()->viewModeButton();
95 m_d->viewModeButton->setMenu(menu);
96 m_d->viewModeButton->setIcon(KisIconUtils::loadIcon("configure"));
97
98
99 connect(m_d->uiWdgPaintOpPresets.wdgPresetChooser, SIGNAL(resourceSelected(KoResource*)),
100 this, SIGNAL(resourceSelected(KoResource*)));
101 connect(m_d->uiWdgPaintOpPresets.wdgPresetChooser, SIGNAL(resourceClicked(KoResource*)),
102 this, SIGNAL(resourceClicked(KoResource*))) ;
103
104
105 connect (iconSizeSlider, SIGNAL(sliderMoved(int)),
106 m_d->uiWdgPaintOpPresets.wdgPresetChooser, SLOT(setIconSize(int)));
107 connect( iconSizeSlider, SIGNAL(sliderReleased()),
108 m_d->uiWdgPaintOpPresets.wdgPresetChooser, SLOT(saveIconSize()));
109
110
111 m_d->firstShown = true;
112
113 }
114
~KisPaintOpPresetsChooserPopup()115 KisPaintOpPresetsChooserPopup::~KisPaintOpPresetsChooserPopup()
116 {
117 delete m_d;
118 }
119
slotThumbnailMode()120 void KisPaintOpPresetsChooserPopup::slotThumbnailMode()
121 {
122 KisConfig(false).setPresetChooserViewMode(KisPresetChooser::THUMBNAIL);
123 m_d->uiWdgPaintOpPresets.wdgPresetChooser->setViewMode(KisPresetChooser::THUMBNAIL);
124 }
125
slotDetailMode()126 void KisPaintOpPresetsChooserPopup::slotDetailMode()
127 {
128 KisConfig(false).setPresetChooserViewMode(KisPresetChooser::DETAIL);
129 m_d->uiWdgPaintOpPresets.wdgPresetChooser->setViewMode(KisPresetChooser::DETAIL);
130 }
131
paintEvent(QPaintEvent * event)132 void KisPaintOpPresetsChooserPopup::paintEvent(QPaintEvent* event)
133 {
134 QWidget::paintEvent(event);
135 //Workaround to get the column and row size right
136 if(m_d->firstShown) {
137 m_d->uiWdgPaintOpPresets.wdgPresetChooser->updateViewSettings();
138 m_d->firstShown = false;
139 }
140 }
141
showButtons(bool show)142 void KisPaintOpPresetsChooserPopup::showButtons(bool show)
143 {
144 m_d->uiWdgPaintOpPresets.wdgPresetChooser->showButtons(show);
145 }
146
canvasResourceChanged(KisPaintOpPresetSP preset)147 void KisPaintOpPresetsChooserPopup::canvasResourceChanged(KisPaintOpPresetSP preset)
148 {
149 if (preset) {
150 blockSignals(true);
151 m_d->uiWdgPaintOpPresets.wdgPresetChooser->setCurrentResource(preset.data());
152 blockSignals(false);
153 }
154 m_d->uiWdgPaintOpPresets.wdgPresetChooser->updateViewSettings();
155 }
156
slotThemeChanged()157 void KisPaintOpPresetsChooserPopup::slotThemeChanged()
158 {
159 m_d->viewModeButton->setIcon(KisIconUtils::loadIcon("configure"));
160 }
161
updateViewSettings()162 void KisPaintOpPresetsChooserPopup::updateViewSettings()
163 {
164 m_d->uiWdgPaintOpPresets.wdgPresetChooser->updateViewSettings();
165 }
166