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..."));
48 connect(
textFilter, &QLineEdit::returnPressed,
this, [
this]() {
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);
87 layout->addWidget(buttonContainer);
106 QSet<int> colorLabels;
117 return isFilteringText || isFilteringColors;
143 if (viableButtons.count() > 1) {
144 return viableButtons[0]->sizeHint().height() +
textFilter->minimumHeight() +
resetButton->minimumHeight();
164 QMenu *parentMenu =
dynamic_cast<QMenu*
>(parentWidget());
167 const int widthBefore = parentMenu->width();
168 const int rightEdgeThreshold = 5;
175 QResizeEvent
event = QResizeEvent(
sizeHint(), parentMenu->size());
178 parentMenu->adjustSize();
179 qApp->sendEvent(parentMenu, &event);
180 QScreen *screen = QGuiApplication::screenAt(parentMenu->mapToGlobal(parentMenu->pos()));
181 QRect screenGeometry = screen ? screen->geometry() : parentMenu->parentWidget()->window()->geometry();
182 const bool onRightEdge = (parentMenu->pos().x() + widthBefore + rightEdgeThreshold) > screenGeometry.width();
183 const int widthAfter = parentMenu->width();
187 if (widthAfter > widthBefore) {
188 const QRect newGeo =
kisEnsureInRect( parentMenu->geometry(), screenGeometry );
189 const int xShift = newGeo.x() - parentMenu->pos().x();
190 parentMenu->move(parentMenu->pos().x() + xShift, parentMenu->pos().y() + 0);
192 const int xShift = widthBefore - widthAfter;
193 parentMenu->move(parentMenu->pos().x() + xShift, parentMenu->pos().y() + 0);
197 QWidget::showEvent(show);
201 : QToolButton(parent)
208 : QToolButton(rhs.parentWidget())
209 , m_textFilter(rhs.m_textFilter)
210 , m_selectedColors(rhs.m_selectedColors)
236 QStylePainter paint(
this);
237 QStyleOptionToolButton opt;
238 initStyleOption(&opt);
240 paint.drawComplexControl(QStyle::CC_ToolButton, opt);
241 const QSize halfIconSize = this->
iconSize() / 2;
242 const QSize halfButtonSize = this->size() / 2;
243 const QRect editRect =
kisGrowRect(QRect(QPoint(halfButtonSize.width() - halfIconSize.width(), halfButtonSize.height() - halfIconSize.height()),this->iconSize()), -1);
244 const int size = qMin(editRect.width(), editRect.height());
246 if( validColorFilter )
250 if (!opt.icon.isNull()) {
251 QRadialGradient radGradient = QRadialGradient(editRect.center(), size);
252 QColor shadowTransparent = palette().shadow().color();
253 shadowTransparent.setAlpha(96);
254 radGradient.setColorAt(0.0f, shadowTransparent);
255 shadowTransparent.setAlpha(0);
256 radGradient.setColorAt(1.0f, shadowTransparent);
257 paint.setBrush(radGradient);
258 paint.setPen(Qt::NoPen);
259 paint.drawEllipse(editRect.center(), size, size);
260 opt.icon.paint(&paint, editRect);
275 (event->type() == QEvent::MouseButtonPress ||
276 event->type() == QEvent::MouseButtonDblClick ||
277 event->type() == QEvent::MouseButtonRelease)) {
278 event->setAccepted(
true);
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)
int colorLabelIndex() const
KisNodeSP firstChild() const
KisNodeSP nextSibling() const