10#include <QApplication>
16#include <QButtonGroup>
20#include <QStylePainter>
21#include <QGraphicsDropShadowEffect>
38 QVBoxLayout *layout =
new QVBoxLayout(
this);
39 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
42 textFilter->setPlaceholderText(i18n(
"Filter by name..."));
49 QMenu* menu =
dynamic_cast<QMenu*
>(parentWidget());
57 QWidget* buttonContainer =
new QWidget(
this);
59 buttonContainer->setToolTip(i18n(
"Filter by color label..."));
60 buttonContainer->installEventFilter(mouseEater);
63 QHBoxLayout *subLayout =
new QHBoxLayout(buttonContainer);
64 subLayout->setContentsMargins(0,0,0,0);
65 subLayout->setSpacing(2);
66 subLayout->setAlignment(Qt::AlignLeft);
71 for (
int id = 0;
id < colors.count();
id++) {
75 subLayout->addWidget(btn);
81 resetButton =
new QPushButton(i18n(
"Reset Filters"),
this);
89 layout->addWidget(buttonContainer);
108 QSet<int> colorLabels;
119 return isFilteringText || isFilteringColors;
145 if (viableButtons.count() > 1) {
146 return viableButtons[0]->sizeHint().height() +
textFilter->minimumHeight() +
resetButton->minimumHeight();
166 QMenu *parentMenu =
dynamic_cast<QMenu*
>(parentWidget());
169 const int widthBefore = parentMenu->width();
170 const int rightEdgeThreshold = 5;
177 QResizeEvent
event = QResizeEvent(
sizeHint(), parentMenu->size());
180 parentMenu->adjustSize();
181 qApp->sendEvent(parentMenu, &event);
182 QScreen *screen = QGuiApplication::screenAt(parentMenu->mapToGlobal(parentMenu->pos()));
183 QRect screenGeometry = screen ? screen->geometry() : parentMenu->parentWidget()->window()->geometry();
184 const bool onRightEdge = (parentMenu->pos().x() + widthBefore + rightEdgeThreshold) > screenGeometry.width();
185 const int widthAfter = parentMenu->width();
189 if (widthAfter > widthBefore) {
190 const QRect newGeo =
kisEnsureInRect( parentMenu->geometry(), screenGeometry );
191 const int xShift = newGeo.x() - parentMenu->pos().x();
192 parentMenu->move(parentMenu->pos().x() + xShift, parentMenu->pos().y() + 0);
194 const int xShift = widthBefore - widthAfter;
195 parentMenu->move(parentMenu->pos().x() + xShift, parentMenu->pos().y() + 0);
199 QWidget::showEvent(show);
203 : QToolButton(parent)
210 : QToolButton(rhs.parentWidget())
211 , m_textFilter(rhs.m_textFilter)
212 , m_selectedColors(rhs.m_selectedColors)
238 QStylePainter paint(
this);
239 QStyleOptionToolButton opt;
240 initStyleOption(&opt);
242 paint.drawComplexControl(QStyle::CC_ToolButton, opt);
243 const QSize halfIconSize = this->
iconSize() / 2;
244 const QSize halfButtonSize = this->size() / 2;
245 const QRect editRect =
kisGrowRect(QRect(QPoint(halfButtonSize.width() - halfIconSize.width(), halfButtonSize.height() - halfIconSize.height()),this->iconSize()), -1);
246 const int size = qMin(editRect.width(), editRect.height());
248 if( validColorFilter )
252 if (!opt.icon.isNull()) {
253 QRadialGradient radGradient = QRadialGradient(editRect.center(), size);
254 QColor shadowTransparent =
palette().shadow().color();
255 shadowTransparent.setAlpha(96);
256 radGradient.setColorAt(0.0f, shadowTransparent);
257 shadowTransparent.setAlpha(0);
258 radGradient.setColorAt(1.0f, shadowTransparent);
259 paint.setBrush(radGradient);
260 paint.setPen(Qt::NoPen);
261 paint.drawEllipse(editRect.center(), size, size);
262 opt.icon.paint(&paint, editRect);
277 (event->type() == QEvent::MouseButtonPress ||
278 event->type() == QEvent::MouseButtonDblClick ||
279 event->type() == QEvent::MouseButtonRelease)) {
280 event->setAccepted(
true);
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
int iconSize(qreal width, qreal height)
static void paintColorPie(QStylePainter &painter, const QPalette &palette, const QList< int > &selectedColors, const QRect &rect, const int &baseSize)
int countViableButtons() const
void setViableLabels(const QSet< int > &buttons)
QList< QAbstractButton * > viableButtons() const
QSet< int > getActiveLabels() const
QVector< QColor > allColorLabels() const
bool eventFilter(QObject *obj, QEvent *event) override
MouseClickIgnore(QObject *parent=nullptr)
T kisGrowRect(const T &rect, U offset)
QRect kisEnsureInRect(QRect rc, const QRect &bounds)
QIcon loadIcon(const QString &name)
rgba palette[MAX_PALETTE]
int colorLabelIndex() const
KisNodeSP firstChild() const
KisNodeSP nextSibling() const