aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornils <nils@34ebc366-c3a9-4b3c-9f84-69acf7962910>2012-09-21 20:08:04 +0000
committernils <nils@34ebc366-c3a9-4b3c-9f84-69acf7962910>2012-09-21 20:08:04 +0000
commit63a36b85a1d24d8e59e9ec119e1fede7e7bcba70 (patch)
tree929e840046354916dc194c03a24cf373fc1374d0
parentadded find action (but has to be improved) (diff)
downloadgpg4usb-63a36b85a1d24d8e59e9ec119e1fede7e7bcba70.tar.gz
gpg4usb-63a36b85a1d24d8e59e9ec119e1fede7e7bcba70.zip
added findwidget files
git-svn-id: http://cpunk.de/svn/src/gpg4usb/trunk@961 34ebc366-c3a9-4b3c-9f84-69acf7962910
-rw-r--r--findwidget.cpp48
-rw-r--r--findwidget.h36
2 files changed, 84 insertions, 0 deletions
diff --git a/findwidget.cpp b/findwidget.cpp
new file mode 100644
index 0000000..343ee5e
--- /dev/null
+++ b/findwidget.cpp
@@ -0,0 +1,48 @@
+
+#include "findwidget.h"
+
+FindWidget::FindWidget(QWidget *parent, QTextEdit *edit) :
+ QWidget(parent)
+{
+ mTextpage = edit;
+ findEdit = new QLineEdit(this);
+
+ QHBoxLayout *notificationWidgetLayout = new QHBoxLayout(this);
+ notificationWidgetLayout->setContentsMargins(10,0,0,0);
+ notificationWidgetLayout->addWidget(new QLabel(tr("Find:")));
+ notificationWidgetLayout->addWidget(findEdit,2);
+ this->setLayout(notificationWidgetLayout);
+ connect(findEdit,SIGNAL(textChanged(QString)),this,SLOT(find()));
+ connect(findEdit,SIGNAL(returnPressed()),this,SLOT(findNext()));
+
+ QTimer::singleShot(0, findEdit, SLOT(setFocus()));
+ haveHit = false;
+}
+
+void FindWidget::findNext()
+{
+ cursor = mTextpage->document()->find(findEdit->text(), cursor, QTextDocument::FindCaseSensitively);
+
+ qDebug() << "cursor: " << cursor.position();
+ qDebug() << "anchor: " << cursor.anchor();
+}
+
+void FindWidget::find()
+{
+ if (cursor.anchor() == -1) {
+ cursor = mTextpage->document()->find(findEdit->text(), cursor, QTextDocument::FindCaseSensitively);
+ } else {
+ cursor = mTextpage->document()->find(findEdit->text(), cursor.anchor(), QTextDocument::FindCaseSensitively);
+ }
+ qDebug() << "cursor: " << cursor.position();
+ qDebug() << "anchor: " << cursor.anchor();
+}
+
+void FindWidget::keyPressEvent( QKeyEvent* e )
+{
+ switch ( e->key() )
+ {
+ case Qt::Key_Escape:
+ this->close();
+ }
+}
diff --git a/findwidget.h b/findwidget.h
new file mode 100644
index 0000000..28f0d74
--- /dev/null
+++ b/findwidget.h
@@ -0,0 +1,36 @@
+
+#ifndef FINDWIDGET_H
+#define FINDWIDGET_H
+
+#include "editorpage.h"
+
+#include <QWidget>
+
+/**
+ * @brief Class for handling the find widget shown at buttom of a textedit-page
+ */
+class FindWidget : public QWidget
+{
+ Q_OBJECT
+
+public:
+ /**
+ * @brief
+ *
+ * @param parent The parent widget
+ */
+ explicit FindWidget(QWidget *parent, QTextEdit *edit);
+
+private:
+ QTextEdit *mTextpage; /** Textedit associated to the notification */
+ QLineEdit *findEdit; /** Label holding the text shown in verifyNotification */
+ bool haveHit;
+ int start;
+ void keyPressEvent( QKeyEvent* e );
+ QTextCursor cursor;
+
+private slots:
+ void findNext();
+ void find();
+};
+#endif // FINDWIDGET_H