Krita Source Code Documentation
Loading...
Searching...
No Matches
KisSelectionActionsPanel Class Reference

#include <kis_selection_actions_panel.h>

+ Inheritance diagram for KisSelectionActionsPanel:

Classes

struct  Private
 

Public Member Functions

void canvasWidgetChanged (KisCanvasWidgetBase *canvas)
 
void draw (QPainter &painter, const KoColorDisplayRendererInterface *displayRendererInterface)
 
bool eventFilter (QObject *obj, QEvent *event) override
 
 KisSelectionActionsPanel ()=delete
 
 KisSelectionActionsPanel (KisViewManager *viewManager)
 
void setEnabled (bool enabled)
 
void setVisible (bool visible)
 
 ~KisSelectionActionsPanel ()
 

Private Slots

void configureSelectionActionsPanel ()
 
void disableSelectionActionsPanel ()
 
void showContextMenu (const QPoint &pos)
 

Private Member Functions

void drawActionBarBackground (QPainter &gc, const KoColorDisplayRendererInterface *displayRendererInterface) const
 
bool handleMove (QEvent *event, const QPoint &pos)
 
bool handlePress (QEvent *event, const QPoint &pos, Qt::MouseButton button=Qt::LeftButton)
 
bool handleRelease (QEvent *event, const QPoint &pos)
 
QPoint initialDragHandlePosition () const
 
QPoint mouseEventPos (const QMouseEvent *mouseEvent)
 
void movePanelWidgets ()
 Moves all the widgets that are a part of the panel.
 
QPoint tabletEventPos (const QTabletEvent *tabletEvent)
 
bool touchEventPos (const QTouchEvent *touchEvent, QPoint &outPos)
 
QPoint transformHandleCoords (QPoint pos)
 
QPoint updateCanvasBoundaries (QPoint position, QWidget *canvasWidget) const
 

Private Attributes

QScopedPointer< Privated
 

Detailed Description

Definition at line 31 of file kis_selection_actions_panel.h.

Constructor & Destructor Documentation

◆ KisSelectionActionsPanel() [1/2]

KisSelectionActionsPanel::KisSelectionActionsPanel ( )
delete

◆ KisSelectionActionsPanel() [2/2]

KisSelectionActionsPanel::KisSelectionActionsPanel ( KisViewManager * viewManager)

Definition at line 98 of file kis_selection_actions_panel.cpp.

99 : d(new Private)
100{
101 d->m_viewManager = viewManager;
102 d->m_selectionManager = viewManager->selectionManager();
103
104 // Setup buttons...
105 for (const ActionButtonData &buttonData : Private::buttonData()) {
106 KisSelectionActionsPanelButton *button = new KisSelectionActionsPanelButton(buttonData.iconName, buttonData.tooltip, BUTTON_SIZE, viewManager->canvas());
107 connect(button, &QAbstractButton::clicked, d->m_selectionManager, buttonData.slot);
108 connect(button, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showContextMenu(QPoint)));
109 d->m_buttons.append(button);
110 }
111
112 d->m_handleWidget = new KisSelectionActionsPanelHandle(BUTTON_SIZE, viewManager->canvas());
113 connect(d->m_handleWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showContextMenu(QPoint)));
114
115 d->disable_action = new KisAction(i18n("Disable selection actions bar"));
116 connect(d->disable_action, SIGNAL(triggered()), SLOT(disableSelectionActionsPanel()) );
117
118 d->configure_action = viewManager->actionManager()->actionByName("configure_sap");
119 connect(d->configure_action, SIGNAL(triggered()), SLOT(configureSelectionActionsPanel()));
120}
KisAction * actionByName(const QString &name) const
Custom widget for selection actions panel buttons, to prevent them being drawn over the pop-up palett...
KisActionManager * actionManager() const
QWidget * canvas() const
Return the actual widget that is displaying the current image.
KisSelectionManager * selectionManager()
static constexpr int BUTTON_SIZE
QString button(const QWheelEvent &ev)

References KisActionManager::actionByName(), KisViewManager::actionManager(), button(), BUTTON_SIZE, KisSelectionActionsPanel::Private::buttonData(), KisViewManager::canvas(), configureSelectionActionsPanel(), d, disableSelectionActionsPanel(), KisViewManager::selectionManager(), and showContextMenu().

◆ ~KisSelectionActionsPanel()

KisSelectionActionsPanel::~KisSelectionActionsPanel ( )

Definition at line 122 of file kis_selection_actions_panel.cpp.

123{
124}

Member Function Documentation

◆ canvasWidgetChanged()

void KisSelectionActionsPanel::canvasWidgetChanged ( KisCanvasWidgetBase * canvas)

Definition at line 256 of file kis_selection_actions_panel.cpp.

257{
258
259 Q_FOREACH(QWidget* btn, d->m_buttons) {
260 btn->setParent(canvas->widget());
261 btn->show();
262 }
263
264 d->m_handleWidget->setParent(canvas->widget());
265 d->m_handleWidget->show();
266}
virtual QWidget * widget()=0

References d, and KisAbstractCanvasWidget::widget().

◆ configureSelectionActionsPanel

void KisSelectionActionsPanel::configureSelectionActionsPanel ( )
privateslot

◆ disableSelectionActionsPanel

void KisSelectionActionsPanel::disableSelectionActionsPanel ( )
privateslot

Definition at line 455 of file kis_selection_actions_panel.cpp.

456{
457 KisConfig cfg(false);
458 cfg.setSelectionActionBar(false);
460}
static KisConfigNotifier * instance()

References KisConfigNotifier::instance(), KisConfigNotifier::notifyConfigChanged(), and KisConfig::setSelectionActionBar().

◆ draw()

void KisSelectionActionsPanel::draw ( QPainter & painter,
const KoColorDisplayRendererInterface * displayRendererInterface )

Definition at line 126 of file kis_selection_actions_panel.cpp.

127{
128 KisSelectionSP selection = d->m_viewManager->selection();
129
130 if (!selection || !d->m_enabled || !d->m_visible) {
131 return;
132 }
133
134 drawActionBarBackground(painter, displayRendererInterface);
135 Q_FOREACH(KisSelectionActionsPanelButton* button, d->m_buttons){
136 button->draw(painter, displayRendererInterface);
137 }
138
139 d->m_handleWidget->draw(painter, displayRendererInterface);
140}
void drawActionBarBackground(QPainter &gc, const KoColorDisplayRendererInterface *displayRendererInterface) const

References button(), d, and drawActionBarBackground().

◆ drawActionBarBackground()

void KisSelectionActionsPanel::drawActionBarBackground ( QPainter & gc,
const KoColorDisplayRendererInterface * displayRendererInterface ) const
private

Definition at line 318 of file kis_selection_actions_panel.cpp.

319{
320 const int cornerRadius = 4;
321 QColor outlineColor = qApp->palette().window().color();
322
323 QColor bgColor = qApp->palette().window().color();
324
325 //Slightly lighten the color, to force `dragColor` to move it in the lighter direction, without this it will always darken the color
327 bgColor = bgColor.lighter(120);
328 }
329
330 KisPaintingTweaks::dragColor(&bgColor, outlineColor, 0.25);
331
332 // Manually convert here, to keep as much consistency as possible.
333 KoColor c;
334 c.fromQColor(bgColor);
335 bgColor = displayRendererInterface->convertColorToDisplayColorSpace(c);
336 c.fromQColor(outlineColor);
337 outlineColor = displayRendererInterface->convertColorToDisplayColorSpace(c);
338
339 QColor bgColorTrans = bgColor;
340 bgColorTrans.setAlpha(80);
341 const int outline_width = 4;
342
343 //an outer 1px wide outline for contrast against the background
344 QRectF contrastOutline(d->m_dragHandle->position - QPoint(outline_width + 1,outline_width + 1), QSize(d->m_actionBarWidth, BUTTON_SIZE) +QSize(outline_width + 1,outline_width + 1) * 2);
345 QRectF midOutline(d->m_dragHandle->position - QPoint(outline_width,outline_width), QSize(d->m_actionBarWidth, BUTTON_SIZE) +QSize(outline_width,outline_width) * 2);
346 //Add a bit of padding here for the icons
347 QRectF centerBackground(d->m_dragHandle->position - QPoint(outline_width,outline_width) / 2, QSize(d->m_actionBarWidth - BUTTON_SIZE, BUTTON_SIZE) +QSize(outline_width,outline_width));
348 QPainterPath bgPath;
349 QPainterPath outlinePath;
350 QPainterPath contrastOutlinePath;
351
352 bgPath.addRoundedRect(centerBackground, cornerRadius, cornerRadius);
353 outlinePath.addRoundedRect(midOutline, cornerRadius, cornerRadius);
354 contrastOutlinePath.addRoundedRect(contrastOutline, cornerRadius, cornerRadius);
355
356 painter.fillPath(contrastOutlinePath, bgColorTrans);
357 painter.fillPath(outlinePath, outlineColor);
358 painter.fillPath(bgPath, bgColor);
359}
virtual QColor convertColorToDisplayColorSpace(const KoColor color) const =0
convertColorToDisplayColorSpace
void fromQColor(const QColor &c)
Convenient function for converting from a QColor.
Definition KoColor.cpp:213
void dragColor(QColor *color, const QColor &baseColor, qreal threshold)

References BUTTON_SIZE, KoColorDisplayRendererInterface::convertColorToDisplayColorSpace(), d, KisPaintingTweaks::dragColor(), KoColor::fromQColor(), and KisIconUtils::useDarkIcons().

◆ eventFilter()

bool KisSelectionActionsPanel::eventFilter ( QObject * obj,
QEvent * event )
override

Definition at line 193 of file kis_selection_actions_panel.cpp.

194{
195 Q_UNUSED(obj);
196
197 switch (event->type()) {
198 case QEvent::MouseButtonPress: {
199 const QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
200 return handlePress(event, mouseEventPos(mouseEvent), mouseEvent->button());
201 }
202 case QEvent::TabletPress: {
203 const QTabletEvent *tabletEvent = static_cast<QTabletEvent *>(event);
204 return handlePress(event, tabletEventPos(tabletEvent));
205 }
206 case QEvent::TouchBegin: {
207 const QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
208 QPoint pos;
209 if (touchEventPos(touchEvent, pos)) {
210 return handlePress(event, pos);
211 }
212 break;
213 }
214
215 case QEvent::MouseMove:
216 if (d->m_pressed) {
217 const QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
218 return handleMove(event, mouseEventPos(mouseEvent));
219 }
220 break;
221 case QEvent::TabletMove:
222 if (d->m_pressed) {
223 const QTabletEvent *tabletEvent = static_cast<QTabletEvent *>(event);
224 return handleMove(event, tabletEventPos(tabletEvent));
225 }
226 break;
227 case QEvent::TouchUpdate:
228 if (d->m_pressed) {
229 const QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
230 QPoint pos;
231 if (touchEventPos(touchEvent, pos)) {
232 return handleMove(event, pos);
233 }
234 }
235 break;
236
237 case QEvent::MouseButtonRelease:
238 case QEvent::TabletRelease:
239 case QEvent::TouchEnd:
240 case QEvent::TouchCancel:
241 if (d->m_pressed) {
242 d->m_handleWidget->set_held(false);
243 d->m_pressed = false;
244 event->accept();
245 return true;
246 }
247 break;
248
249 default:
250 break;
251 }
252 return false;
253}
bool handlePress(QEvent *event, const QPoint &pos, Qt::MouseButton button=Qt::LeftButton)
QPoint tabletEventPos(const QTabletEvent *tabletEvent)
bool handleMove(QEvent *event, const QPoint &pos)
QPoint mouseEventPos(const QMouseEvent *mouseEvent)
bool touchEventPos(const QTouchEvent *touchEvent, QPoint &outPos)

References d, handleMove(), handlePress(), mouseEventPos(), tabletEventPos(), and touchEventPos().

◆ handleMove()

bool KisSelectionActionsPanel::handleMove ( QEvent * event,
const QPoint & pos )
private

Definition at line 380 of file kis_selection_actions_panel.cpp.

381{
382 QWidget *canvasWidget = d->m_viewManager->canvas();
383 QPoint newPos = pos - d->m_dragHandle->dragOrigin;
384 d->m_dragHandle->position = updateCanvasBoundaries(newPos, canvasWidget);
386 canvasWidget->update();
387 event->accept();
388 return true;
389}
void movePanelWidgets()
Moves all the widgets that are a part of the panel.
QPoint updateCanvasBoundaries(QPoint position, QWidget *canvasWidget) const

References d, movePanelWidgets(), and updateCanvasBoundaries().

◆ handlePress()

bool KisSelectionActionsPanel::handlePress ( QEvent * event,
const QPoint & pos,
Qt::MouseButton button = Qt::LeftButton )
private

Definition at line 361 of file kis_selection_actions_panel.cpp.

362{
363 if (d->m_pressed) {
364 event->accept();
365 return true;
366 }
367
368 if (button == Qt::LeftButton) {
369 d->m_pressed = true;
370 d->m_dragHandle->dragOrigin = pos - d->m_dragHandle->position;
371 d->m_handleWidget->set_held(true);
372
373 event->accept();
374 return true;
375 }
376
377 return false;
378}

References button(), and d.

◆ handleRelease()

bool KisSelectionActionsPanel::handleRelease ( QEvent * event,
const QPoint & pos )
private

◆ initialDragHandlePosition()

QPoint KisSelectionActionsPanel::initialDragHandlePosition ( ) const
private

Definition at line 298 of file kis_selection_actions_panel.cpp.

299{
300 KisSelectionSP selection = d->m_viewManager->selection();
301 KisCanvasWidgetBase *canvas = dynamic_cast<KisCanvasWidgetBase*>(d->m_viewManager->canvas());
302 KIS_ASSERT(selection);
303 KIS_ASSERT(canvas);
304
305 QRectF selectionBounds = selection->selectedRect();
306 int selectionBottom = selectionBounds.bottom();
307 QPointF selectionCenter = selectionBounds.center();
308 QPointF bottomCenter(selectionCenter.x(), selectionBottom);
309
310 QPointF widgetBottomCenter = canvas->coordinatesConverter()->imageToWidget(bottomCenter); // converts current selection's QPointF into canvasWidget's QPointF space
311
312 widgetBottomCenter.setX(widgetBottomCenter.x() - (d->m_actionBarWidth / 2)); // centers toolbar midpoint with the selection center
313 widgetBottomCenter.setY(widgetBottomCenter.y() + BUFFER_SPACE);
314
315 return updateCanvasBoundaries(widgetBottomCenter.toPoint(), d->m_viewManager->canvas());
316}
KisCoordinatesConverter * coordinatesConverter() const
_Private::Traits< T >::Result imageToWidget(const T &obj) const
#define KIS_ASSERT(cond)
Definition kis_assert.h:33
static constexpr int BUFFER_SPACE
QRect selectedRect() const

References BUFFER_SPACE, KisCanvasWidgetBase::coordinatesConverter(), d, KisCoordinatesConverter::imageToWidget(), KIS_ASSERT, KisSelection::selectedRect(), and updateCanvasBoundaries().

◆ mouseEventPos()

QPoint KisSelectionActionsPanel::mouseEventPos ( const QMouseEvent * mouseEvent)
private

Definition at line 405 of file kis_selection_actions_panel.cpp.

406{
407#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
408 return transformHandleCoords(mouseEvent->position().toPoint());
409#else
410 return transformHandleCoords(mouseEvent->pos());
411#endif
412}

References transformHandleCoords().

◆ movePanelWidgets()

void KisSelectionActionsPanel::movePanelWidgets ( )
private

Moves all the widgets that are a part of the panel.

Definition at line 391 of file kis_selection_actions_panel.cpp.

392{
393 d->m_handleWidget->move(d->m_dragHandle->position.x() + d->m_buttons.size() * BUTTON_SIZE, d->m_dragHandle->position.y());
394 d->m_handleWidget->show();
395
396 int i = 0;
397 Q_FOREACH(KisSelectionActionsPanelButton *button, d->m_buttons) {
398 int buttonPosition = i * BUTTON_SIZE;
399 button->move(d->m_dragHandle->position.x() + buttonPosition, d->m_dragHandle->position.y());
400 button->show();
401 i++;
402 }
403}

References button(), BUTTON_SIZE, and d.

◆ setEnabled()

void KisSelectionActionsPanel::setEnabled ( bool enabled)

Definition at line 181 of file kis_selection_actions_panel.cpp.

182{
183 d->configure_action->setVisible(enabled);
184
185 bool configurationChanged = enabled != d->m_enabled;
186 d->m_enabled = enabled;
187 if (configurationChanged) {
188 // Reset visibility when configuration changes
189 setVisible(enabled);
190 }
191}

References d, and setVisible().

◆ setVisible()

void KisSelectionActionsPanel::setVisible ( bool visible)

Definition at line 142 of file kis_selection_actions_panel.cpp.

143{
144 d->configure_action->setVisible(p_visible && d->m_enabled);
145
146 QWidget *canvasWidget = dynamic_cast<QWidget *>(d->m_viewManager->canvas());
147 if (!canvasWidget) {
148 return;
149 }
150
151 p_visible &= d->m_enabled;
152
153 const bool VISIBILITY_CHANGED = d->m_visible != p_visible;
154 if (!VISIBILITY_CHANGED) {
155 return;
156 }
157
158 if (d->m_viewManager->selection() && p_visible) { // Now visible!
159 d->m_handleWidget->installEventFilter(this);
160
161 if (!d->m_dragHandle) {
162 d->m_dragHandle.reset(new Private::DragHandle());
163 d->m_dragHandle->position = initialDragHandlePosition();
165 }
166 } else { // Now hidden!
167 d->m_handleWidget->removeEventFilter(this);
168
169 for (KisSelectionActionsPanelButton *button : d->m_buttons) {
170 button->hide();
171 }
172 d->m_handleWidget->hide();
173
174 d->m_pressed = false;
175 d->m_dragHandle.reset();
176 }
177
178 d->m_visible = p_visible;
179}

References button(), d, initialDragHandlePosition(), and movePanelWidgets().

◆ showContextMenu

void KisSelectionActionsPanel::showContextMenu ( const QPoint & pos)
privateslot

Definition at line 447 of file kis_selection_actions_panel.cpp.

448{
449 QMenu menu = QMenu();
450 menu.addAction(d->disable_action);
451 menu.addAction(d->configure_action);
452 menu.exec(pos);
453}

References d.

◆ tabletEventPos()

QPoint KisSelectionActionsPanel::tabletEventPos ( const QTabletEvent * tabletEvent)
private

Definition at line 414 of file kis_selection_actions_panel.cpp.

415{
416#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
417 return transformHandleCoords(tabletEvent->position().toPoint());
418#else
419 return transformHandleCoords(tabletEvent->pos());
420#endif
421}

References transformHandleCoords().

◆ touchEventPos()

bool KisSelectionActionsPanel::touchEventPos ( const QTouchEvent * touchEvent,
QPoint & outPos )
private

Definition at line 423 of file kis_selection_actions_panel.cpp.

424{
425#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
426 if (touchEvent->pointCount() < 1) {
427 return false;
428 } else {
429 outPos = transformHandleCoords(touchEvent->points().first().position().toPoint());
430 return true;
431 }
432#else
433 const QList<QTouchEvent::TouchPoint> &touchPoints = touchEvent->touchPoints();
434 if (touchPoints.isEmpty()) {
435 return false;
436 } else {
437 outPos = transformHandleCoords(touchPoints.first().pos().toPoint());
438 return true;
439 }
440#endif
441}

References transformHandleCoords().

◆ transformHandleCoords()

QPoint KisSelectionActionsPanel::transformHandleCoords ( QPoint pos)
private

Definition at line 443 of file kis_selection_actions_panel.cpp.

443 {
444 return d->m_dragHandle->position + pos;
445}

References d.

◆ updateCanvasBoundaries()

QPoint KisSelectionActionsPanel::updateCanvasBoundaries ( QPoint position,
QWidget * canvasWidget ) const
private

Definition at line 268 of file kis_selection_actions_panel.cpp.

269{
270 QRect canvasBounds = canvasWidget->rect();
271
272 const int ACTION_BAR_WIDTH = d->m_actionBarWidth;
273 const int ACTION_BAR_HEIGHT = BUTTON_SIZE;
274
275 int pos_x_min = canvasBounds.left() + BUFFER_SPACE;
276 int pos_x_max = canvasBounds.right() - ACTION_BAR_WIDTH - BUFFER_SPACE;
277
278 int pos_y_min = canvasBounds.top() + BUFFER_SPACE;
279 int pos_y_max = canvasBounds.bottom() - ACTION_BAR_HEIGHT - BUFFER_SPACE;
280
281 //Ensure that max is always bigger than min
282 //If the window is small enough max could be smaller than min
283 if (pos_x_max < pos_x_min) {
284 pos_x_max = pos_x_min;
285 }
286
287 //It is pretty implausible for it to happen vertically but better safe than sorry
288 if (pos_y_max < pos_y_min) {
289 pos_y_max = pos_y_min;
290 }
291
292 position.setX(qBound(pos_x_min, position.x(), pos_x_max));
293 position.setY(qBound(pos_y_min, position.y(), pos_y_max));
294
295 return position;
296}

References BUFFER_SPACE, BUTTON_SIZE, and d.

Member Data Documentation

◆ d

QScopedPointer<Private> KisSelectionActionsPanel::d
private

Definition at line 72 of file kis_selection_actions_panel.h.


The documentation for this class was generated from the following files: