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

The LineEditAction class defines an action with a user text input. More...

#include <TagActions.h>

+ Inheritance diagram for LineEditAction:

Public Member Functions

bool closeParentOnTrigger ()
 
void setCloseParentOnTrigger (bool closeParent)
 
void setIcon (const QIcon &icon)
 
void setPlaceholderText (const QString &clickMessage)
 
void setText (const QString &text)
 
void setVisible (bool showAction)
 
 ~LineEditAction () override
 

Protected Slots

virtual void onTriggered ()
 onTriggered defines additional behaviour for the action
 
void slotActionTriggered ()
 slotActionTriggered defines all behaviour expressed when the widget is triggered
 
QString userText ()
 userText getter for the text inside the edit box
 

Protected Member Functions

 LineEditAction (QObject *parent)
 

Private Attributes

QPushButton * m_AddButton
 
bool m_closeParentOnTrigger
 
QLineEdit * m_editBox
 
QLabel * m_label
 

Detailed Description

The LineEditAction class defines an action with a user text input.

A line edit QWidgetAction. Default behavior: Closes its parent upon triggering. This is a base for all tag/resources actions that needs a user text input (for example create new tag or rename tag)

This is a base for all tag/resources actions that needs a user text input (for example create new tag or rename tag). By default it closes its parent upon triggering and clears the content, but it can be disabled.

Definition at line 72 of file TagActions.h.

Constructor & Destructor Documentation

◆ LineEditAction()

LineEditAction::LineEditAction ( QObject * parent)
protected

Definition at line 49 of file TagActions.cpp.

50 : QWidgetAction(parent)
52{
53 QWidget* pWidget = new QWidget (0);
54 QHBoxLayout* pLayout = new QHBoxLayout();
55 m_label = new QLabel(0);
57 m_editBox->setClearButtonEnabled(true);
58 m_AddButton = new QPushButton();
59 m_AddButton->setIcon(koIcon("list-add"));
60 pLayout->addWidget(m_label);
61 pLayout->addWidget(m_editBox);
62 pLayout->addWidget(m_AddButton);
63 pWidget->setLayout(pLayout);
64 setDefaultWidget(pWidget);
65
66 connect(m_editBox, &QLineEdit::returnPressed, this, &LineEditAction::slotActionTriggered);
67 connect(m_AddButton, &QPushButton::clicked, this, &LineEditAction::slotActionTriggered);
68
69}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
bool m_closeParentOnTrigger
Definition TagActions.h:113
QPushButton * m_AddButton
Definition TagActions.h:116
void slotActionTriggered()
slotActionTriggered defines all behaviour expressed when the widget is triggered
QLabel * m_label
Definition TagActions.h:114
QLineEdit * m_editBox
Definition TagActions.h:115
#define koIcon(name)
Use these macros for icons without any issues.
Definition kis_icon.h:25

References connect(), koIcon, m_AddButton, m_editBox, m_label, and slotActionTriggered().

◆ ~LineEditAction()

LineEditAction::~LineEditAction ( )
override

Definition at line 71 of file TagActions.cpp.

72{
73}

Member Function Documentation

◆ closeParentOnTrigger()

bool LineEditAction::closeParentOnTrigger ( )

Definition at line 86 of file TagActions.cpp.

87{
89}

References m_closeParentOnTrigger.

◆ onTriggered

virtual void LineEditAction::onTriggered ( )
inlineprotectedvirtualslot

onTriggered defines additional behaviour for the action

This function is called in slotActionTriggered() before the widget is closed and cleared.

Definition at line 104 of file TagActions.h.

104{}

◆ setCloseParentOnTrigger()

void LineEditAction::setCloseParentOnTrigger ( bool closeParent)

Definition at line 81 of file TagActions.cpp.

82{
83 m_closeParentOnTrigger = closeParent;
84}

References m_closeParentOnTrigger.

◆ setIcon()

void LineEditAction::setIcon ( const QIcon & icon)

Definition at line 75 of file TagActions.cpp.

76{
77 QPixmap pixmap = QPixmap(icon.pixmap(16,16));
78 m_label->setPixmap(pixmap);
79}

References m_label.

◆ setPlaceholderText()

void LineEditAction::setPlaceholderText ( const QString & clickMessage)

Definition at line 106 of file TagActions.cpp.

107{
108 m_editBox->setPlaceholderText(clickMessage);
109}

References m_editBox.

◆ setText()

void LineEditAction::setText ( const QString & text)

Definition at line 111 of file TagActions.cpp.

112{
113 m_editBox->setText(text);
114}

References m_editBox.

◆ setVisible()

void LineEditAction::setVisible ( bool showAction)

Definition at line 116 of file TagActions.cpp.

117{
118 QLayout* currentLayout = defaultWidget()->layout();
119
120 this->QAction::setVisible(showAction);
121
122 for(int i=0;i<currentLayout->count();i++) {
123 currentLayout->itemAt(i)->widget()->setVisible(showAction);
124 }
125 defaultWidget()->setVisible(showAction);
126}

◆ slotActionTriggered

void LineEditAction::slotActionTriggered ( )
protectedslot

slotActionTriggered defines all behaviour expressed when the widget is triggered

It contains logic for closing the widget and calls onTriggered() to make sure behaviours defined in classes inheriting LineEditAction are called.

Definition at line 92 of file TagActions.cpp.

93{
94 setData(userText());
95 QAction::trigger();
97 if (!m_editBox->text().isEmpty()) {
99 this->parentWidget()->close();
100 m_editBox->clearFocus();
101 m_editBox->clear();
102 }
103 }
104}
virtual void onTriggered()
onTriggered defines additional behaviour for the action
Definition TagActions.h:104
QString userText()
userText getter for the text inside the edit box

References m_closeParentOnTrigger, m_editBox, onTriggered(), and userText().

◆ userText

QString LineEditAction::userText ( )
protectedslot

userText getter for the text inside the edit box

Returns
text inside edit box (user input)

Definition at line 128 of file TagActions.cpp.

129{
130 return m_editBox->text();
131}

References m_editBox.

Member Data Documentation

◆ m_AddButton

QPushButton* LineEditAction::m_AddButton
private

Definition at line 116 of file TagActions.h.

◆ m_closeParentOnTrigger

bool LineEditAction::m_closeParentOnTrigger
private

Definition at line 113 of file TagActions.h.

◆ m_editBox

QLineEdit* LineEditAction::m_editBox
private

Definition at line 115 of file TagActions.h.

◆ m_label

QLabel* LineEditAction::m_label
private

Definition at line 114 of file TagActions.h.


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