MCPcopy Create free account
hub / github.com/Liniyous/ElaWidgetTools / contextMenuEvent

Method contextMenuEvent

ElaWidgetTools/ElaLineEdit.cpp:126–184  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

124 if (!isReadOnly())
125 {
126 action = menu->addElaIconAction(ElaIconType::KnifeKitchen, tr("剪切"), QKeySequence::Cut);
127 action->setEnabled(!isReadOnly() && hasSelectedText() && echoMode() == QLineEdit::Normal);
128 connect(action, &QAction::triggered, this, &ElaLineEdit::cut);
129 }
130
131 action = menu->addElaIconAction(ElaIconType::Copy, tr("复制"), QKeySequence::Copy);
132 action->setEnabled(hasSelectedText() && echoMode() == QLineEdit::Normal);
133 connect(action, &QAction::triggered, this, &ElaLineEdit::copy);
134
135 if (!isReadOnly())
136 {
137 action = menu->addElaIconAction(ElaIconType::Paste, tr("粘贴"), QKeySequence::Paste);
138 action->setEnabled(!isReadOnly() && !QGuiApplication::clipboard()->text().isEmpty());
139 connect(action, &QAction::triggered, this, &ElaLineEdit::paste);
140 }
141#endif
142 if (!isReadOnly())
143 {
144 action = menu->addElaIconAction(ElaIconType::DeleteLeft, tr("删除"));
145 action->setEnabled(!isReadOnly() && !text().isEmpty() && hasSelectedText());
146 connect(action, &QAction::triggered, this, [=](bool checked) {
147 if (hasSelectedText())
148 {
149 int startIndex = selectionStart();
150 int endIndex = selectionEnd();
151 setText(text().remove(startIndex, endIndex - startIndex));
152 }
153 });
154 }
155 if (!menu->isEmpty())
156 {
157 menu->addSeparator();
158 }
159 action = menu->addAction(tr("全选"));
160 action->setShortcut(QKeySequence::SelectAll);
161 action->setEnabled(!text().isEmpty() && !(selectedText() == text()));
162 connect(action, &QAction::triggered, this, &ElaLineEdit::selectAll);
163 menu->popup(event->globalPos());
164}

Callers

nothing calls this directly

Calls 2

setMenuItemHeightMethod · 0.80
addElaIconActionMethod · 0.45

Tested by

no test coverage detected