[SCM] ktp-text-ui packaging branch, master, updated. debian/15.12.1-1-1918-gdf4b0ec
Maximiliano Curia
maxy at moszumanska.debian.org
Sat May 28 00:19:10 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-text-ui.git;a=commitdiff;h=0055195
The following commit has been merged in the master branch:
commit 0055195415449d3a89228a321eac1af7c7176d65
Author: Francesco Nwokeka <francesco.nwokeka at gmail.com>
Date: Sun Mar 27 16:01:50 2011 +0200
Implementation of bug 269052 - Need a method to search within a chat window
Added basic search functionality to the chat UI. Now users can search for text in the current chat they're in
---
app/chat-window.cpp | 21 +++++++
app/chat-window.h | 2 +
lib/CMakeLists.txt | 1 +
lib/chat-search-bar.cpp | 151 ++++++++++++++++++++++++++++++++++++++++++++++++
lib/chat-search-bar.h | 84 +++++++++++++++++++++++++++
lib/chat-widget.cpp | 43 +++++++++++++-
lib/chat-widget.h | 12 ++++
lib/chat-widget.ui | 9 +++
8 files changed, 322 insertions(+), 1 deletion(-)
diff --git a/app/chat-window.cpp b/app/chat-window.cpp
index b3407db..ba3576f 100644
--- a/app/chat-window.cpp
+++ b/app/chat-window.cpp
@@ -43,6 +43,16 @@ ChatWindow::ChatWindow()
KStandardAction::preferences(this, SLOT(showSettingsDialog()), actionCollection());
KStandardAction::configureNotifications(this, SLOT(showNotificationsDialog()), actionCollection());
+ // keyboard shortcut to toggle search bar
+ KAction *toggleSearchBarAction = new KAction(this);
+ toggleSearchBarAction->setIcon(KIcon("edit-find"));
+ toggleSearchBarAction->setShortcut(QKeySequence(QKeySequence::Find));
+
+ connect(toggleSearchBarAction, SIGNAL(triggered(Qt::MouseButtons,Qt::KeyboardModifiers)), this, SLOT(onSearchActionToggled()));
+
+ // add to collection so user can modify shortcut
+ actionCollection()->addAction(i18n("Find text"), toggleSearchBarAction);
+
// set up m_tabWidget
m_tabWidget = new KTabWidget(this);
m_tabWidget->setTabReorderingEnabled(true);
@@ -149,6 +159,17 @@ void ChatWindow::onCurrentIndexChanged(int index)
setWindowIcon(currentChatTab->icon());
}
+void ChatWindow::onSearchActionToggled()
+{
+ ChatTab *currChat = qobject_cast<ChatTab*>(m_tabWidget->currentWidget());
+
+ // This should never happen
+ if(!currChat) {
+ return;
+ }
+ currChat->toggleSearchBar();
+}
+
void ChatWindow::onTabStateChanged()
{
kDebug();
diff --git a/app/chat-window.h b/app/chat-window.h
index cde19e4..aacfcef 100644
--- a/app/chat-window.h
+++ b/app/chat-window.h
@@ -49,8 +49,10 @@ public:
public slots:
void removeTab(QWidget *chatWidget);
+
private slots:
void onCurrentIndexChanged(int index);
+ void onSearchActionToggled();
void onTabStateChanged();
void onTabTextChanged(const QString &newTitle);
void onTabIconChanged(const KIcon &newIcon);
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 1639cfd..89b61c1 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -10,6 +10,7 @@ set(telepathy_chat_handler_lib_SRCS
channel-contact-model.cpp
chat-style-plist-file-reader.cpp
chat-text-edit.cpp
+ chat-search-bar.cpp
)
set(telepathy_chat_handler_lib_HDRS
diff --git a/lib/chat-search-bar.cpp b/lib/chat-search-bar.cpp
new file mode 100644
index 0000000..8fff36e
--- /dev/null
+++ b/lib/chat-search-bar.cpp
@@ -0,0 +1,151 @@
+/***************************************************************************
+ * Copyright (C) 2011 by Francesco Nwokeka <francesco.nwokeka at gmail.com> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
+ ***************************************************************************/
+
+#include "chat-search-bar.h"
+
+#include <KAction>
+#include <KColorScheme>
+#include <KLineEdit>
+#include <KLocale>
+#include <KPushButton>
+
+#include <QCheckBox>
+#include <QDebug>
+#include <QHBoxLayout>
+
+ChatSearchBar::ChatSearchBar(QWidget* parent)
+ : QWidget(parent)
+ , m_searchInput(new KLineEdit(this))
+ , m_closeButton(new KPushButton(this))
+ , m_nextButton(new KPushButton(KIcon("arrow-down"), i18n("&Next"), this))
+ , m_previousButton(new KPushButton(KIcon("arrow-up"), i18n("&Previous"), this))
+ , m_caseSensitive(false)
+{
+ // close button setup
+ m_closeButton->setIcon(KIcon("dialog-close"));
+ connect(m_closeButton, SIGNAL(clicked(bool)), this, SLOT(toggleView(bool)));
+
+ // search line setup
+ m_searchInput->setPlaceholderText(i18n("Insert search text..."));
+
+ // search arrows
+ connect(m_nextButton, SIGNAL(clicked()), this, SLOT(onNextButtonClicked()));
+ connect(m_previousButton, SIGNAL(clicked()), this, SLOT(onPreviousButtonClicked()));
+
+ // options for search criteria
+ QCheckBox *caseSensitiveAction = new QCheckBox(i18n("Case sensitive"), this);
+
+ connect(caseSensitiveAction, SIGNAL(clicked(bool)), this, SLOT(toggleCaseSensitive(bool)));
+
+ // text changed signal
+ connect(m_searchInput, SIGNAL(textChanged(QString)), this, SLOT(textChanged(QString)));
+
+ QHBoxLayout *layout = new QHBoxLayout(this);
+ layout->addWidget(m_closeButton);
+ layout->addWidget(m_searchInput);
+ layout->addWidget(m_nextButton);
+ layout->addWidget(m_previousButton);
+ layout->addWidget(caseSensitiveAction);
+
+ setLayout(layout);
+
+ // start hidden
+ hide();
+}
+
+ChatSearchBar::~ChatSearchBar()
+{
+
+}
+
+QWebPage::FindFlags ChatSearchBar::findFlags()
+{
+ QWebPage::FindFlags flags;
+ flags |= QWebPage::FindWrapsAroundDocument;
+
+ if(m_caseSensitive) {
+ flags |= QWebPage::FindCaseSensitively;
+ }
+ return flags;
+}
+
+KLineEdit* ChatSearchBar::searchBar() const
+{
+ return m_searchInput;
+}
+
+void ChatSearchBar::onNextButtonClicked()
+{
+ emit(findNextSignal(m_searchInput->text(), findFlags()));
+}
+
+void ChatSearchBar::onPreviousButtonClicked()
+{
+ emit(findPreviousSignal(m_searchInput->text(), findFlags()));
+}
+
+void ChatSearchBar::onSearchTextComplete(bool found)
+{
+ if(found || m_searchInput->text().isEmpty()) {
+ KColorScheme scheme(QPalette::Active, KColorScheme::View);
+ QColor background = scheme.background(KColorScheme::NormalBackground).color();
+
+ if(m_searchInput->palette().color(QPalette::Base) != background) {
+ QPalette p = m_searchInput->palette();
+ p.setColor(QPalette::Base, background);
+ m_searchInput->setPalette(p);
+ }
+ } else {
+ KColorScheme scheme(QPalette::Active, KColorScheme::Window);
+ QColor background = scheme.foreground(KColorScheme::ActiveText).color();
+
+ // check for empty text as well. It's not to be considered as "text not found"
+ if(m_searchInput->palette().color(QPalette::Base) != background && !m_searchInput->text().isEmpty()) {
+ QPalette p = m_searchInput->palette();
+ p.setColor(QPalette::Base, background);
+ m_searchInput->setPalette(p);
+ }
+ }
+}
+
+void ChatSearchBar::toggleView(bool toggle)
+{
+ if(!toggle) {
+ m_searchInput->clear();
+ hide();
+ } else {
+ show();
+ m_searchInput->setFocus();
+ }
+}
+
+void ChatSearchBar::textChanged(const QString& text)
+{
+ emit(findTextSignal(text, findFlags()));
+}
+
+void ChatSearchBar::toggleCaseSensitive(bool toggle)
+{
+ m_caseSensitive = toggle;
+ emit(flagsChangedSignal(m_searchInput->text(), findFlags()));
+}
+
+
+
+
diff --git a/lib/chat-search-bar.h b/lib/chat-search-bar.h
new file mode 100644
index 0000000..6bed1b3
--- /dev/null
+++ b/lib/chat-search-bar.h
@@ -0,0 +1,84 @@
+/***************************************************************************
+ * Copyright (C) 2011 by Francesco Nwokeka <francesco.nwokeka at gmail.com> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
+ ***************************************************************************/
+
+#ifndef CHATSEARCHBAR_H
+#define CHATSEARCHBAR_H
+
+#include <QWebPage>
+#include <QWidget>
+
+class KLineEdit;
+class KPushButton;
+
+/**
+ * @brief Input field for user to insert text to look for inside a chat window
+ * @author Francesco Nwokeka <francesco.nwokeka at gmail.com>
+ */
+
+class ChatSearchBar : public QWidget
+{
+ Q_OBJECT
+public:
+ ChatSearchBar(QWidget *parent = 0);
+ virtual ~ChatSearchBar();
+
+ KLineEdit *searchBar() const;
+
+public slots:
+ void onNextButtonClicked();
+ void onPreviousButtonClicked();
+
+ void onSearchTextComplete(bool found);
+
+ /** toggle search bar visibility */
+ void toggleView(bool toggle);
+
+private slots:
+ /** called when user writes in search bar
+ * this emits a signal for chat-window with the text to search for
+ * and the appropriate flags for the search criteria
+ */
+ void textChanged(const QString &text);
+
+ /** search criteria toggle: case sensitivity */
+ void toggleCaseSensitive(bool toggle);
+
+signals:
+ void findTextSignal(const QString &text, QWebPage::FindFlags flags);
+ void findNextSignal(const QString &text, QWebPage::FindFlags flags);
+ void findPreviousSignal(const QString &text, QWebPage::FindFlags flags);
+
+ /** emitted when search criteria is changed by user and updates current view */
+ void flagsChangedSignal(const QString &, QWebPage::FindFlags flags);
+
+private:
+ /** returns selected search criteria chosen by user */
+ QWebPage::FindFlags findFlags();
+
+ KLineEdit *m_searchInput;
+ KPushButton *m_closeButton
+ , *m_nextButton
+ , *m_previousButton;
+
+ // search criteria variables
+ bool m_highlightAll
+ , m_caseSensitive;
+};
+
+#endif // CHATSEARCHBAR_H
\ No newline at end of file
diff --git a/lib/chat-widget.cpp b/lib/chat-widget.cpp
index 5ddf3dd..9083c3d 100644
--- a/lib/chat-widget.cpp
+++ b/lib/chat-widget.cpp
@@ -35,6 +35,7 @@
#include <KComponentData>
#include <KDebug>
#include <KColorScheme>
+#include <KLineEdit>
#include <TelepathyQt4/Message>
#include <TelepathyQt4/Types>
@@ -130,7 +131,7 @@ ChatWidget::ChatWidget(const Tp::TextChannelPtr & channel, QWidget *parent)
d->isGroupChat = false;
d->ui.setupUi(this);
-
+ d->ui.formatToolbar->show();
d->ui.formatColor->setText(QString());
d->ui.formatColor->setIcon(KIcon("format-text-color"));
@@ -233,6 +234,13 @@ ChatWidget::ChatWidget(const Tp::TextChannelPtr & channel, QWidget *parent)
this->window()->installEventFilter(windowEventFilter);
connect(windowEventFilter, SIGNAL(windowActivated()), SLOT(windowActivated()));
+ // find text in chat
+ connect(d->ui.searchBar, SIGNAL(findTextSignal(QString,QWebPage::FindFlags)), this, SLOT(findTextInChat(QString,QWebPage::FindFlags)));
+ connect(d->ui.searchBar, SIGNAL(findNextSignal(QString,QWebPage::FindFlags)), this, SLOT(findNextTextInChat(QString,QWebPage::FindFlags)));
+ connect(d->ui.searchBar, SIGNAL(findPreviousSignal(QString,QWebPage::FindFlags)), this, SLOT(findPreviousTextInChat(QString,QWebPage::FindFlags)));
+ connect(d->ui.searchBar, SIGNAL(flagsChangedSignal(QString,QWebPage::FindFlags)), this, SLOT(findTextInChat(QString,QWebPage::FindFlags)));
+
+ connect(this, SIGNAL(searchTextComplete(bool)), d->ui.searchBar, SLOT(onSearchTextComplete(bool)));
}
ChatWidget::~ChatWidget()
@@ -345,6 +353,15 @@ int ChatWidget::unreadMessageCount() const
return d->unreadMessages;
}
+void ChatWidget::toggleSearchBar()
+{
+ if(d->ui.searchBar->isVisible()) {
+ d->ui.searchBar->toggleView(false);
+ } else {
+ d->ui.searchBar->toggleView(true);
+ }
+}
+
void ChatWidget::incrementUnreadMessageCount()
{
kDebug();
@@ -662,6 +679,30 @@ void ChatWidget::onInputBoxChanged()
}
}
+void ChatWidget::findTextInChat(const QString& text, QWebPage::FindFlags flags)
+{
+ // reset find
+ d->ui.chatArea->findText(QString(), flags);
+
+ if(d->ui.chatArea->findText(text, flags)) {
+ emit(searchTextComplete(true));
+ } else {
+ emit(searchTextComplete(false));
+ }
+}
+
+void ChatWidget::findNextTextInChat(const QString& text, QWebPage::FindFlags flags)
+{
+ d->ui.chatArea->findText(text, flags);
+}
+
+void ChatWidget::findPreviousTextInChat(const QString& text, QWebPage::FindFlags flags)
+{
+ // for "backwards" search
+ flags |= QWebPage::FindBackward;
+ d->ui.chatArea->findText(text, flags);
+}
+
void ChatWidget::onFormatColorReleased()
{
QColor color;
diff --git a/lib/chat-widget.h b/lib/chat-widget.h
index dfdef64..02140f7 100644
--- a/lib/chat-widget.h
+++ b/lib/chat-widget.h
@@ -24,6 +24,7 @@
#include <QtCore/QString>
#include <QtGui/QWidget>
+#include <QWebPage>
#include <KIcon>
#include <KColorScheme>
@@ -56,6 +57,10 @@ public:
int unreadMessageCount() const;
+public slots:
+ /** toggle the search bar visibility */
+ void toggleSearchBar();
+
protected:
void changeEvent(QEvent *e);
void resizeEvent(QResizeEvent *);
@@ -96,6 +101,9 @@ signals:
/** Emmited whenever a message is received in this channel*/
void messageReceived();
+ /** emitted when searching for text */
+ void searchTextComplete(bool found);
+
/** Emitted when another contact in the channel starts/stops typing (if supported by the protocol)*/
void userTypingChanged(bool);
@@ -104,6 +112,10 @@ signals:
void unreadMessagesChanged(int messages);
private slots:
+ /** recieved when user changes search criteria or when searching for text */
+ void findTextInChat(const QString &text, QWebPage::FindFlags flags);
+ void findNextTextInChat(const QString &text, QWebPage::FindFlags flags);
+ void findPreviousTextInChat(const QString &text, QWebPage::FindFlags flags);
void onFormatColorReleased();
void windowActivated();
diff --git a/lib/chat-widget.ui b/lib/chat-widget.ui
index 2dce82f..9d106b5 100644
--- a/lib/chat-widget.ui
+++ b/lib/chat-widget.ui
@@ -115,6 +115,9 @@
</widget>
</item>
<item>
+ <widget class="ChatSearchBar" name="searchBar" native="true"/>
+ </item>
+ <item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="ChatTextEdit" name="sendMessageBox">
@@ -172,6 +175,12 @@
<extends>QTextEdit</extends>
<header>chat-text-edit.h</header>
</customwidget>
+ <customwidget>
+ <class>ChatSearchBar</class>
+ <extends>QWidget</extends>
+ <header location="global">chat-search-bar.h</header>
+ <container>1</container>
+ </customwidget>
</customwidgets>
<resources/>
<connections/>
--
ktp-text-ui packaging
More information about the pkg-kde-commits
mailing list