diff options
-rw-r--r-- | gpg4usb.pro | 6 | ||||
-rw-r--r-- | gpgwin.cpp | 24 | ||||
-rw-r--r-- | gpgwin.h | 6 | ||||
-rw-r--r-- | textedit.cpp | 35 | ||||
-rw-r--r-- | textedit.h | 22 |
5 files changed, 88 insertions, 5 deletions
diff --git a/gpg4usb.pro b/gpg4usb.pro index 301f34b..0971ea6 100644 --- a/gpg4usb.pro +++ b/gpg4usb.pro @@ -25,7 +25,8 @@ HEADERS += attachments.h \ keygenthread.h \ keydetailsdialog.h \ settingsdialog.h \ - attachmenttablemodel.h + attachmenttablemodel.h \ + textedit.h SOURCES += attachments.cpp \ context.cpp \ gpgwin.cpp \ @@ -37,7 +38,8 @@ SOURCES += attachments.cpp \ keygenthread.cpp \ keydetailsdialog.cpp \ settingsdialog.cpp \ - attachmenttablemodel.cpp + attachmenttablemodel.cpp \ + textedit.cpp RC_FILE = gpg4usb.rc # comment out line below for static building @@ -32,7 +32,7 @@ GpgWin::GpgWin() QString appPath = qApp->applicationDirPath(); iconPath = appPath + "/icons/"; - edit = new QPlainTextEdit(); + edit = new TextEdit(); setCentralWidget(edit); // setAcceptDrops(true); @@ -69,6 +69,7 @@ GpgWin::GpgWin() loadFile(args[1]); } } + setAcceptDrops(true); } void GpgWin::restoreSettings() @@ -188,6 +189,10 @@ void GpgWin::createActions() "clipboard")); connect(copyAct, SIGNAL(triggered()), edit, SLOT(copy())); + commentAct = new QAction(tr("Co&mment"), this); + commentAct->setToolTip(tr("Insert > in front of every line")); + connect(commentAct, SIGNAL(triggered()), edit, SLOT(comment())); + selectallAct = new QAction(tr("Select &All"), this); selectallAct->setIcon(QIcon(iconPath + "edit.png")); selectallAct->setShortcut(QKeySequence::SelectAll); @@ -295,6 +300,7 @@ void GpgWin::createMenus() editMenu->addAction(cutAct); editMenu->addAction(pasteAct); editMenu->addAction(selectallAct); + editMenu->addAction(commentAct); editMenu->addSeparator(); editMenu->addAction(openSettingsAct); @@ -795,7 +801,6 @@ void GpgWin::fileEncryption() void GpgWin::openSettingsDialog() { new SettingsDialog(this); -// restoreSettings(); // Iconsize QSize iconSize = settings.value("toolbar/iconsize", QSize(32, 32)).toSize(); this->setIconSize(iconSize); @@ -804,3 +809,18 @@ void GpgWin::openSettingsDialog() Qt::ToolButtonStyle buttonStyle = static_cast<Qt::ToolButtonStyle>(settings.value("toolbar/iconstyle", Qt::ToolButtonTextUnderIcon).toUInt()); this->setToolButtonStyle(buttonStyle); } +void GpgWin::dropEvent(QDropEvent* event) +{ + edit->setPlainText(event->mimeData()->text()); + qDebug() << "drop event main"; + //qDebug() << "hallo"; +// event->acceptProposedAction(); +} + +void GpgWin::dragEnterEvent(QDragEnterEvent *event) +{ + //qDebug() << "hallo"; + qDebug() << event->mimeData()->text(); + if (event->mimeData()->hasFormat("text/plain")) + event->acceptProposedAction(); +} @@ -27,6 +27,7 @@ #include "attachments.h" #include "mime.h" #include "keymgmt.h" +#include "textedit.h" class QMainWindow; class QPlainTextEdit; @@ -61,6 +62,8 @@ public: protected: void closeEvent(QCloseEvent *event); + void dropEvent(QDropEvent* event); + void dragEnterEvent(QDragEnterEvent* event); public slots: void encrypt(); @@ -101,7 +104,7 @@ private: void parseMime(QByteArray *message); QString strippedName(const QString &fullFileName); - QPlainTextEdit *edit; + TextEdit *edit; QMenu *fileMenu; QMenu *editMenu; QMenu *cryptMenu; @@ -132,6 +135,7 @@ private: QAction *appendSelectedKeysAct; QAction *openKeyManagementAct; QAction *copyAct; + QAction *commentAct; QAction *cutAct; QAction *pasteAct; QAction *selectallAct; diff --git a/textedit.cpp b/textedit.cpp new file mode 100644 index 0000000..9615d20 --- /dev/null +++ b/textedit.cpp @@ -0,0 +1,35 @@ +#include "QDebug" +class QString; +#include "textedit.h" +TextEdit::TextEdit(QWidget *parent) +{ + setAcceptDrops(true); +} + +void TextEdit::dragEnterEvent(QDragEnterEvent *event) +{ + if (event->mimeData()->hasFormat("text/plain")) + qDebug() << "enter drag action"; + + //event->acceptProposedAction(); +} + +void TextEdit::dropEvent(QDropEvent* event) +{ + this->setPlainText(event->mimeData()->text()); + + qDebug() << "enter drop action"; + qDebug() << event->mimeData()->text(); + event->acceptProposedAction(); +} + +void TextEdit::comment() +{ + QString test=this->toPlainText(); + qDebug() << "-------------"; + qDebug() << test; + test.replace("\n","\n>",Qt::CaseSensitive); + test.insert(0,QString(">")); + qDebug() << "-------------"; + qDebug() << test; +} diff --git a/textedit.h b/textedit.h new file mode 100644 index 0000000..fe0b395 --- /dev/null +++ b/textedit.h @@ -0,0 +1,22 @@ +#ifndef __TEXTEDIT_H__ +#define __TEXTEDIT_H__ + +#include <QPlainTextEdit> + +class QtGui; +class QApplication; +class QWidget; + +class TextEdit : public QPlainTextEdit +{ + Q_OBJECT +public: + TextEdit(QWidget *parent=0); +public slots: + void comment(); +protected: + void dragEnterEvent(QDragEnterEvent *event); + void dropEvent(QDropEvent* event); + +}; +#endif // TEXTEDIT |