search text inside lyric

Carles Pina i Estany carles at pina.cat
Sun Nov 12 21:09:46 UTC 2006


Hi again,

I send attached the last version of the patch.

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.

The unique thing that is not working is the shortcut. I have been
trying, as you maybe already know (I have sent some mails asking about
it) but I haven't done...

The unique needed thing is to assign Shift+/ using something like:

new KAction("lyrics_search_text", KShortcut("Shift+/),ContextBrowser::instance(),SLOT( lyricsSearchTextShow() ), Amarok::actionCollection(), "search_in_lyric");

If there is any more feedback tell me. During the week I will keep
trying to do the shortcut... (and ask to a friend too :-)   )

Thanks,

-- 
Carles Pina i Estany		GPG id: 0x8CBDAE64
	http://pinux.info	Manresa - Barcelona
-------------- next part --------------
Index: contextbrowser.h
===================================================================
--- contextbrowser.h	(revision 604335)
+++ 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; }
@@ -46,13 +48,15 @@
         ContextBrowser( const char *name );
        ~ContextBrowser();
 
-        static ContextBrowser *instance() { return s_instance; }
+	static ContextBrowser *instance() { return s_instance; }
 
         void setFont( const QFont& );
         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();
@@ -61,6 +65,7 @@
         void lyricsChanged( const QString& );
         void lyricsScriptChanged();
         void lyricsResult( QCString cXmlDoc, bool cached = false );
+	void lyricsSearchTextShow();
 
     protected:
         void engineNewMetaData( const MetaBundle&, bool );
@@ -95,6 +100,10 @@
         void lyricsSearch();
         void lyricsRefresh();
         void lyricsExternalPage();
+	void lyricsSearchText( const QString &text );
+	void lyricsSearchTextNext();
+	void lyricsSearchTextHide();
+	void lyricsSearchTextToggle();
 
         void wikiHistoryBack();
         void wikiHistoryForward();
@@ -111,7 +120,7 @@
 
     private:
         enum { CONTEXT_BACK, CONTEXT_FORWARD, CONTEXT_CURRENT, CONTEXT_HOME, CONTEXT_SEARCH };
-        enum { LYRICS_ADD, LYRICS_EDIT, LYRICS_SEARCH, LYRICS_REFRESH, LYRICS_BROWSER };
+        enum { LYRICS_ADD, LYRICS_EDIT, LYRICS_SEARCH, LYRICS_REFRESH, LYRICS_BROWSER, LYRICS_SEARCH_TEXT };
         enum { WIKI_BACK, WIKI_FORWARD, WIKI_ARTIST, WIKI_ALBUM, WIKI_TITLE, WIKI_BROWSER, WIKI_CONFIG };
         typedef enum {SHOW_ALBUM_NORMAL, SHOW_ALBUM_SCORE, SHOW_ALBUM_LEAST_PLAY} T_SHOW_ALBUM_TYPE;
         static const uint WIKI_MAX_HISTORY = 20;
@@ -151,6 +160,10 @@
         QString       m_lyricsBeingEditedUrl;
         QString       m_lyricsBeingEditedArtist;
         QString       m_lyricsBeingEditedTitle;
+	ClickLineEdit * m_lyricsSearchText;
+	KToolBar      * m_lyricsTextBar;
+	bool	      m_lyricsTextBarShowed;
+	//KAction       *m_searchTextLyric;
 
         QString       m_wiki;
         QString       m_wikiLanguages;
Index: contextbrowser.cpp
===================================================================
--- contextbrowser.cpp	(revision 604335)
+++ 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"
@@ -214,7 +215,41 @@
     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") );
+    m_lyricsToolBar->insertButton( Amarok::icon( "search" ), LYRICS_SEARCH_TEXT, true, i18n("Search text in lyric") );
+   
+    { //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())) );
+    } 
+
     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();
@@ -282,6 +317,7 @@
     connect( m_lyricsToolBar->getButton( LYRICS_SEARCH ),  SIGNAL(clicked( int )), SLOT(lyricsSearch()) );
     connect( m_lyricsToolBar->getButton( LYRICS_REFRESH ), SIGNAL(clicked( int )), SLOT(lyricsRefresh()) );
     connect( m_lyricsToolBar->getButton( LYRICS_BROWSER ), SIGNAL(clicked( int )), SLOT(lyricsExternalPage()) );
+    connect( m_lyricsToolBar->getButton( LYRICS_SEARCH_TEXT), SIGNAL(clicked( int )), SLOT(lyricsSearchTextToggle()) );
 
     connect( m_wikiToolBar->getButton( WIKI_BACK    ), SIGNAL(clicked( int )), SLOT(wikiHistoryBack()) );
     connect( m_wikiToolBar->getButton( WIKI_FORWARD ), SIGNAL(clicked( int )), SLOT(wikiHistoryForward()) );
@@ -3153,7 +3189,79 @@
     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_lyricsTextBar->show();
+    m_lyricsTextBarShowed = true;
+    m_lyricsSearchText->setFocus();
+
+    KToolBarButton *k = m_lyricsToolBar->getButton( LYRICS_SEARCH_TEXT );
+    k->setText( i18n ("Hide search text in lyric") );
+}
+
+
+void
+ContextBrowser::lyricsSearchTextHide() //SLOT
+{
+    m_lyricsTextBar->hide();
+    m_lyricsTextBarShowed=false;
+
+    KToolBarButton *k = m_lyricsToolBar->getButton( LYRICS_SEARCH_TEXT );
+    k->setText( i18n ("Search text in lyric") );
+}
+
+
+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)
+        {
+            //m_lyricsSearchText->clear();
+	    m_lyricsTextBar->hide();
+	    m_lyricsTextBarShowed=false;
+        }
+        #undef e
+	break;
+    default:
+        break;
+    }
+    return QWidget::eventFilter( o, e );
+}
+
+
 //////////////////////////////////////////////////////////////////////////////////////////
 // Wikipedia-Tab
 //////////////////////////////////////////////////////////////////////////////////////////


More information about the Amarok mailing list