search text inside lyric (patch)

Carles Pina i Estany carles at pina.cat
Tue Nov 14 17:42:33 UTC 2006


Hi,

On Nov/13/2006, Seb Ruiz wrote:
> On 13/11/06, Carles Pina i Estany <carles at pina.cat> wrote:
> >Now it has an entry in lyrics toolbar menu, that allows to show or hide.
> >It is also hidden if user is typing in text field and press ESC.
> 
> I don't think a toolbar entry is necessary. What about just popping up
> the search field if Ctrl-F or / is pressed?

Finally I send in this way (using Shift+/ shortcut). 

The patch is attached. I show the field using Shift+/ in any place of
Amarok, and I don't force to change the UI to contextbrowser -> lyrics.

If you prefer to not "show" when is not in contextbrowser -> lyrics, or
to force the UI to contextbrowser -> lyrics when user press Shift+/ tell
me.

Also tell me any other thing...

-- 
Carles Pina i Estany		GPG id: 0x8CBDAE64
	http://pinux.info	Manresa - Barcelona
-------------- next part --------------
Index: src/contextbrowser.h
===================================================================
--- src/contextbrowser.h	(revision 604702)
+++ src/contextbrowser.h	(working copy)
@@ -12,6 +12,7 @@
 #include "engineobserver.h"
 
 #include <ktabwidget.h>
+#include <ktoolbarbutton.h>
 #include <kurl.h>
 
 class CollectionDB;
@@ -28,6 +29,7 @@
 class KTextEdit;
 
 class CueFile;
+class ClickLineEdit;
 
 namespace Browser { class ToolBar; }
 namespace KIO { class Job; class TransferJob; }
@@ -52,7 +54,9 @@
         void reloadStyleSheet();
         static KURL::List expandURL( const KURL &url ); // expand urls (album, compilation, ...)
         static bool hasContextProtocol( const KURL &url ); // is url expandable by context browser?
+	virtual bool eventFilter ( QObject *o, QEvent *e );
 
+
     public slots:
         void openURLRequest(const KURL &url );
         void collectionScanStarted();
@@ -95,6 +99,12 @@
         void lyricsSearch();
         void lyricsRefresh();
         void lyricsExternalPage();
+	
+	void lyricsSearchText( const QString &text );
+	void lyricsSearchTextNext();
+	void lyricsSearchTextHide();
+	void lyricsSearchTextShow();
+	void lyricsSearchTextToggle();
 
         void wikiHistoryBack();
         void wikiHistoryForward();
@@ -151,6 +161,9 @@
         QString       m_lyricsBeingEditedUrl;
         QString       m_lyricsBeingEditedArtist;
         QString       m_lyricsBeingEditedTitle;
+	ClickLineEdit* m_lyricsSearchText;
+	KToolBar*     m_lyricsTextBar;
+	bool	      m_lyricsTextBarShowed;
 
         QString       m_wiki;
         QString       m_wikiLanguages;
Index: src/contextbrowser.cpp
===================================================================
--- src/contextbrowser.cpp	(revision 604702)
+++ src/contextbrowser.cpp	(working copy)
@@ -13,6 +13,7 @@
 #include "app.h"
 #include "browserToolBar.h"
 #include "debug.h"
+#include "clicklineedit.h"
 #include "collectiondb.h"
 #include "collectionbrowser.h"
 #include "colorgenerator.h"
@@ -45,6 +46,7 @@
 #include <qlineedit.h>
 #include <qtooltip.h>
 
+#include <kaction.h>
 #include <kapplication.h> //kapp
 #include <kcalendarsystem.h>  // for Amarok::verboseTimeSince()
 #include <kconfig.h> // suggested/related/favorite box visibility
@@ -214,7 +216,43 @@
     m_lyricsToolBar->insertButton( Amarok::icon( "search" ), LYRICS_SEARCH, true, i18n("Search") );
     m_lyricsToolBar->setIconText( KToolBar::IconOnly, false );
     m_lyricsToolBar->insertButton( Amarok::icon( "external" ), LYRICS_BROWSER, true, i18n("Open in external browser") );
+   
+    { //Search text inside lyrics. Code inspired/copied from playlistwindow.cpp
+        m_lyricsTextBar = new KToolBar( m_lyricsTab, "NotMainToolBar" );
+	m_lyricsTextBar->hide();
+	m_lyricsTextBarShowed=false;
 
+        m_lyricsTextBar->setIconSize( 22, false ); //looks more sensible
+        m_lyricsTextBar->setFlat( true ); //removes the ugly frame
+        m_lyricsTextBar->setMovingEnabled( false ); //removes the ugly frame
+
+	m_lyricsTextBar->boxLayout()->addStretch();
+        
+	QWidget *button = new KToolBarButton( "locationbar_erase", 1, m_lyricsTextBar );
+        QLabel *filter_label = new QLabel( i18n("S&earch:") + ' ', m_lyricsTextBar );
+        m_lyricsSearchText = new ClickLineEdit( i18n( "Search text in lyric" ), m_lyricsTextBar );
+        filter_label->setBuddy( m_lyricsSearchText );
+
+        m_lyricsTextBar->setStretchableWidget(m_lyricsSearchText );
+
+        m_lyricsSearchText->setFrame( QFrame::Sunken );
+        m_lyricsSearchText->installEventFilter( this ); //we intercept keyEvents
+
+        connect( button, SIGNAL(clicked()), m_lyricsSearchText, SLOT(clear()) );
+
+        QToolTip::add( button, i18n( "Clear search text in lyric" ) );
+        QString filtertip = i18n( "Write to search this word in lyric, from the begin. Press enter to search next match" );
+
+        QToolTip::add( m_lyricsSearchText, filtertip );
+    
+        connect ( button, SIGNAL(clicked()), m_lyricsSearchText, SLOT(clear()) );
+        connect ( m_lyricsSearchText, SIGNAL(textChanged(const QString &)), this, SLOT(lyricsSearchText(const QString & )) );
+        connect ( m_lyricsSearchText, SIGNAL(returnPressed()), this, (SLOT(lyricsSearchTextNext())) );
+	Amarok::actionCollection()->setAutoConnectShortcuts ( true );
+	new KAction( i18n("Search text in lyric"), KShortcut("Shift+/"), this,SLOT( lyricsSearchTextShow() ), Amarok::actionCollection(), "search_text_lyric");
+	Amarok::actionCollection()->setAutoConnectShortcuts ( false );
+    } 
+
     m_lyricsPage = new HTMLView( m_lyricsTab, "lyrics_page", true /* DNDEnabled */, false /* No JScript */ );
     m_lyricsTextEdit = new KTextEdit ( m_lyricsTab, "lyrics_text_edit");
     m_lyricsTextEdit->hide();
@@ -3153,7 +3191,74 @@
     showLyrics( "reload" );
 }
 
+void
+ContextBrowser::lyricsSearchText(QString const &text) //SLOT
+{
+    m_lyricsPage->findText( text, 0 );
+    lyricsSearchTextNext();
+}
 
+void
+ContextBrowser::lyricsSearchTextNext() //SLOT
+{
+    m_lyricsPage->findTextNext();
+}
+
+void
+ContextBrowser::lyricsSearchTextShow() //SLOT
+{
+    m_lyricsSearchText->setEnabled( true );
+    m_lyricsTextBar->show();
+    m_lyricsTextBarShowed = true;
+    m_lyricsSearchText->setFocus();
+}
+
+
+void
+ContextBrowser::lyricsSearchTextHide() //SLOT
+{
+    m_lyricsSearchText->setText("");
+    m_lyricsSearchText->setEnabled( false );
+    m_lyricsTextBar->hide();
+    m_lyricsTextBarShowed=false;
+}
+
+
+void
+ContextBrowser::lyricsSearchTextToggle() //SLOT
+{
+    if ( m_lyricsTextBarShowed ) 
+    {
+        lyricsSearchTextHide();
+    }
+    else 
+    {
+        lyricsSearchTextShow();
+    }
+}
+
+// Copied from playlistwindow.cpp eventFilter
+bool
+ContextBrowser::eventFilter ( QObject *o, QEvent *e )
+{
+    switch (e->type() )
+    {
+    case 6/*QEvent::KeyPress*/:
+        #define e static_cast<QKeyEvent*>(e)
+
+        if (o == m_lyricsSearchText && e->key() == Key_Escape)
+        {
+            lyricsSearchTextHide();
+        }
+        #undef e
+	break;
+    default:
+        break;
+    }
+    return QWidget::eventFilter( o, e );
+}
+
+
 //////////////////////////////////////////////////////////////////////////////////////////
 // Wikipedia-Tab
 //////////////////////////////////////////////////////////////////////////////////////////


More information about the Amarok mailing list