Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_shade_selector_line_combo_box.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2010 Adam Celarek <kdedev at xibo dot at>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
8
9#include <QApplication>
10#include <QScreen>
11#include <QScreen>
12#include <QResizeEvent>
13#include <QGridLayout>
14#include <QPainter>
15
16#include <klocalizedstring.h>
17#include <qnamespace.h>
18
22
23#include "kis_global.h"
24
25
27 QComboBox(parent),
28 m_popup(new KisShadeSelectorLineComboBoxPopup(this)),
29 m_parentProxy(new KisColorSelectorBaseProxyNoop()),
30 m_currentLine(new KisShadeSelectorLine(0,0,0, m_parentProxy.data(), this))
31{
32 QGridLayout* l = new QGridLayout(this);
33 {
34 int left;
35 l->getContentsMargins(&left, nullptr, nullptr, nullptr);
36 l->setContentsMargins(left, 0, 30, 0);
37
38 }
39 l->addWidget(m_currentLine);
40
41 m_currentLine->setAttribute(Qt::WA_TransparentForMouseEvents);
42
43 KoColor color;
44 color.fromQColor(QColor(190, 50, 50));
45 m_currentLine->setColor(color);
46
48}
49
53
55{
56 QComboBox::hidePopup();
57 m_popup->hide();
58}
59
61{
62 QComboBox::showPopup();
63 m_popup->show();
64
65 const int widgetMargin = 20;
66 QScreen *screen = qApp->screenAt(QCursor::pos());
67 QRect fitRect;
68 if (screen) {
69 fitRect = kisGrowRect(screen->availableGeometry(), -widgetMargin);
70 }
71 else {
72 fitRect = kisGrowRect(QRect(0, 0, 1024, 768), -widgetMargin);
73 }
74 QRect popupRect = m_popup->rect();
75 popupRect.moveTo(mapToGlobal(QPoint()));
76 popupRect = kisEnsureInRect(popupRect, fitRect);
77
78 m_popup->move(popupRect.topLeft());
80}
81
83{
85 update();
86}
87
92
94{
96 for(int i=0; i<m_popup->layout()->count(); i++) {
97 KisShadeSelectorLine* item = dynamic_cast<KisShadeSelectorLine*>(m_popup->layout()->itemAt(i)->widget());
98 if(item!=nullptr) {
99 item->setLineNumber(n);
100 }
101 }
102}
103
105{
106 e->accept();
107
108 m_popup->setMinimumWidth(qMax(280, width()));
109 m_popup->setMaximumWidth(qMax(280, width()));
110}
111
113{
115 for(int i=0; i<m_popup->layout()->count(); i++) {
116 KisShadeSelectorLine* item = dynamic_cast<KisShadeSelectorLine*>(m_popup->layout()->itemAt(i)->widget());
117 if(item!=nullptr) {
118 item->updateSettings();
119 item->m_lineHeight = 30;
120 item->setMaximumHeight(30);
121 item->setMinimumHeight(30);
122 }
123 }
124
126}
127
128
130{
132 for(int i=0; i<m_popup->layout()->count(); i++) {
133 KisShadeSelectorLine* item = dynamic_cast<KisShadeSelectorLine*>(m_popup->layout()->itemAt(i)->widget());
134 if(item!=nullptr) {
135 item->m_gradient=b;
136 }
137 }
138
139 update();
140}
141
143{
145 for(int i=0; i<m_popup->layout()->count(); i++) {
146 KisShadeSelectorLine* item = dynamic_cast<KisShadeSelectorLine*>(m_popup->layout()->itemAt(i)->widget());
147 if(item!=nullptr) {
148 item->m_gradient=!b;
149 }
150 }
151
152 update();
153}
154
156{
158 for(int i=0; i<m_popup->layout()->count(); i++) {
159 KisShadeSelectorLine* item = dynamic_cast<KisShadeSelectorLine*>(m_popup->layout()->itemAt(i)->widget());
160 if(item!=nullptr) {
161 item->m_patchCount=count;
162 }
163 }
164
165 update();
166}
167
169{
171 m_currentLine->setMinimumHeight(height);
172 setMinimumHeight(height+m_popup->spacing);
173
174 update();
175}
KisShadeSelectorLineComboBoxPopup * m_popup
void fromString(const QString &string) override
void setColor(const KoColor &color)
QString toString() const override
void fromQColor(const QColor &c)
Convenient function for converting from a QColor.
Definition KoColor.cpp:213
T kisGrowRect(const T &rect, U offset)
Definition kis_global.h:186
QRect kisEnsureInRect(QRect rc, const QRect &bounds)
Definition kis_global.h:267