aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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