File indexing completed on 2024-10-27 04:51:00
0001 /* 0002 SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-only 0005 */ 0006 0007 #include "kmcomposerglobalaction.h" 0008 #include "kmcomposerwin.h" 0009 0010 #include <PimCommon/LineEditWithAutoCorrection> 0011 0012 #include <KLineEdit> 0013 0014 #include "editor/kmcomposereditorng.h" 0015 0016 KMComposerGlobalAction::KMComposerGlobalAction(KMComposerWin *composerWin, QObject *parent) 0017 : QObject(parent) 0018 , mComposerWin(composerWin) 0019 { 0020 } 0021 0022 KMComposerGlobalAction::~KMComposerGlobalAction() = default; 0023 0024 void KMComposerGlobalAction::slotUndo() 0025 { 0026 QWidget *fw = mComposerWin->focusWidget(); 0027 if (!fw) { 0028 return; 0029 } 0030 0031 if (::qobject_cast<PimCommon::LineEditWithAutoCorrection *>(fw)) { 0032 static_cast<PimCommon::LineEditWithAutoCorrection *>(fw)->undo(); 0033 } else if (::qobject_cast<KMComposerEditorNg *>(fw)) { 0034 static_cast<QTextEdit *>(fw)->undo(); 0035 } else if (::qobject_cast<KLineEdit *>(fw)) { 0036 static_cast<KLineEdit *>(fw)->undo(); 0037 } 0038 } 0039 0040 void KMComposerGlobalAction::slotRedo() 0041 { 0042 QWidget *fw = mComposerWin->focusWidget(); 0043 if (!fw) { 0044 return; 0045 } 0046 0047 if (::qobject_cast<PimCommon::LineEditWithAutoCorrection *>(fw)) { 0048 static_cast<PimCommon::LineEditWithAutoCorrection *>(fw)->redo(); 0049 } else if (::qobject_cast<KMComposerEditorNg *>(fw)) { 0050 static_cast<QTextEdit *>(fw)->redo(); 0051 } else if (::qobject_cast<KLineEdit *>(fw)) { 0052 static_cast<KLineEdit *>(fw)->redo(); 0053 } 0054 } 0055 0056 void KMComposerGlobalAction::slotCut() 0057 { 0058 QWidget *fw = mComposerWin->focusWidget(); 0059 if (!fw) { 0060 return; 0061 } 0062 0063 if (::qobject_cast<PimCommon::LineEditWithAutoCorrection *>(fw)) { 0064 static_cast<PimCommon::LineEditWithAutoCorrection *>(fw)->cut(); 0065 } else if (::qobject_cast<KMComposerEditorNg *>(fw)) { 0066 static_cast<QTextEdit *>(fw)->cut(); 0067 } else if (::qobject_cast<KLineEdit *>(fw)) { 0068 static_cast<KLineEdit *>(fw)->cut(); 0069 } 0070 } 0071 0072 void KMComposerGlobalAction::slotCopy() 0073 { 0074 QWidget *fw = mComposerWin->focusWidget(); 0075 if (!fw) { 0076 return; 0077 } 0078 0079 if (::qobject_cast<PimCommon::LineEditWithAutoCorrection *>(fw)) { 0080 static_cast<PimCommon::LineEditWithAutoCorrection *>(fw)->copy(); 0081 } else if (::qobject_cast<KMComposerEditorNg *>(fw)) { 0082 static_cast<QTextEdit *>(fw)->copy(); 0083 } else if (::qobject_cast<KLineEdit *>(fw)) { 0084 static_cast<KLineEdit *>(fw)->copy(); 0085 } 0086 } 0087 0088 void KMComposerGlobalAction::slotPaste() 0089 { 0090 QWidget *const fw = mComposerWin->focusWidget(); 0091 if (!fw) { 0092 return; 0093 } 0094 if (::qobject_cast<PimCommon::LineEditWithAutoCorrection *>(fw)) { 0095 static_cast<PimCommon::LineEditWithAutoCorrection *>(fw)->paste(); 0096 } else if (::qobject_cast<KMComposerEditorNg *>(fw)) { 0097 static_cast<QTextEdit *>(fw)->paste(); 0098 } else if (::qobject_cast<KLineEdit *>(fw)) { 0099 static_cast<KLineEdit *>(fw)->paste(); 0100 } 0101 } 0102 0103 void KMComposerGlobalAction::slotMarkAll() 0104 { 0105 QWidget *fw = mComposerWin->focusWidget(); 0106 if (!fw) { 0107 return; 0108 } 0109 0110 if (::qobject_cast<PimCommon::LineEditWithAutoCorrection *>(fw)) { 0111 static_cast<PimCommon::LineEditWithAutoCorrection *>(fw)->selectAll(); 0112 } else if (::qobject_cast<KLineEdit *>(fw)) { 0113 static_cast<KLineEdit *>(fw)->selectAll(); 0114 } else if (::qobject_cast<KMComposerEditorNg *>(fw)) { 0115 static_cast<QTextEdit *>(fw)->selectAll(); 0116 } 0117 } 0118 0119 void KMComposerGlobalAction::slotInsertEmoticon(const QString &str) 0120 { 0121 QWidget *fw = mComposerWin->focusWidget(); 0122 if (!fw) { 0123 return; 0124 } 0125 0126 if (::qobject_cast<PimCommon::LineEditWithAutoCorrection *>(fw)) { 0127 static_cast<PimCommon::LineEditWithAutoCorrection *>(fw)->insertPlainText(str); 0128 } else if (::qobject_cast<KMComposerEditorNg *>(fw)) { 0129 static_cast<QTextEdit *>(fw)->insertPlainText(str); 0130 } 0131 //} else if (::qobject_cast<KLineEdit *>(fw)) { 0132 // Don't insert emoticon in mail linedit 0133 // static_cast<KLineEdit *>(fw)->insert(str); 0134 } 0135 0136 void KMComposerGlobalAction::slotInsertText(const QString &str) 0137 { 0138 QWidget *fw = mComposerWin->focusWidget(); 0139 if (!fw) { 0140 return; 0141 } 0142 0143 if (::qobject_cast<PimCommon::LineEditWithAutoCorrection *>(fw)) { 0144 static_cast<PimCommon::LineEditWithAutoCorrection *>(fw)->insertPlainText(str); 0145 } else if (::qobject_cast<KMComposerEditorNg *>(fw)) { 0146 static_cast<QTextEdit *>(fw)->insertPlainText(str); 0147 } 0148 // Don't insert text in mail linedit 0149 //} else if (::qobject_cast<KLineEdit *>(fw)) { 0150 } 0151 0152 #include "moc_kmcomposerglobalaction.cpp"