search inside lyric

Carles Pina i Estany carles at pina.cat
Thu Dec 21 20:30:20 UTC 2006


Hello,

During November I made and we discussed a feature: to search a text
inside the lyric. 
You can check in threads with my name in:
http://mail.kde.org/pipermail/amarok/2006-November/thread.html

I send attached in this mail the last version, modified for current
subversion (my patch was not applying due some changes)

I wonder if there is interest to include the patch in Amarok. If there
isn't I will use only for myself :-) if there is interest but there is
some problem with the implementation, tell me and I will (try to) fix

Thanks,

-- 
Carles Pina i Estany		GPG id: 0x8CBDAE64
	http://pinux.info	Manresa - Barcelona
-------------- next part --------------
Index: amarok/src/contextbrowser.h
===================================================================
--- amarok/src/contextbrowser.h	(revision 615480)
+++ amarok/src/contextbrowser.h	(working copy)
@@ -13,8 +13,10 @@
 #include "engineobserver.h"
 
 #include <ktabwidget.h>
+#include <ktoolbarbutton.h>
 #include <kurl.h>
 
+class ClickLineEdit;
 class CollectionDB;
 class Color;
 class HTMLView;
@@ -101,6 +103,12 @@
         void lyricsRefresh();
         void lyricsExternalPage();
 
+	void lyricsSearchText( const QString &text );
+	void lyricsSearchTextNext();
+	void lyricsSearchTextHide();
+	void lyricsSearchTextShow();
+	void lyricsSearchTextToggle();
+
         void wikiHistoryBack();
         void wikiHistoryForward();
         void wikiBackPopupActivated( int id );
@@ -159,7 +167,11 @@
         QString       m_lyricsBeingEditedUrl;
         QString       m_lyricsBeingEditedArtist;
         QString       m_lyricsBeingEditedTitle;
+	ClickLineEdit* m_lyricsSearchText;
+	KToolBar*     m_lyricsTextBar;
+	bool          m_lyricsTextBarShowed;
 
+
         QString       m_wiki;
         QString       m_wikiLanguages;
         static QString s_wikiLocale;
Index: amarok/src/contextbrowser.cpp
===================================================================
--- amarok/src/contextbrowser.cpp	(revision 615480)
+++ amarok/src/contextbrowser.cpp	(working copy)
@@ -15,6 +15,7 @@
 #include "browserToolBar.h"
 #include "debug.h"
 #include "clicklineedit.h"
+#include "clicklineedit.h"
 #include "collectiondb.h"
 #include "collectionbrowser.h"
 #include "colorgenerator.h"
@@ -50,6 +51,7 @@
 #include <qtimer.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
@@ -222,7 +224,45 @@
     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->setTextFormat( Qt::PlainText );
@@ -3362,8 +3402,52 @@
     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();
+    }
+}
+
 // Wikipedia-Tab
 //////////////////////////////////////////////////////////////////////////////////////////
 
@@ -3615,6 +3699,19 @@
                 return false;
             }
         }
+	if (o == m_lyricsSearchText)
+	{
+	   switch ( e->key() )
+	   {
+	   case Key_Escape:
+	   {
+	   	lyricsSearchTextHide();
+		return true;
+	   }
+	   default:
+	       return false;
+	   }
+       }
 
     default:
         break;


More information about the Amarok mailing list