45 #include "searchbox.h" |
45 #include "searchbox.h" |
46 #include "googlesuggest.h" |
46 #include "googlesuggest.h" |
47 |
47 |
48 #define GSEARCH_URL "http://www.google.com/search?q=%1" |
48 #define GSEARCH_URL "http://www.google.com/search?q=%1" |
49 |
49 |
50 |
50 //! [1] |
51 SearchBox::SearchBox(QWidget *parent): QLineEdit(parent) |
51 SearchBox::SearchBox(QWidget *parent): QLineEdit(parent) |
52 { |
52 { |
53 completer = new GSuggestCompletion(this); |
53 completer = new GSuggestCompletion(this); |
54 |
54 |
55 connect(this, SIGNAL(returnPressed()), SLOT(doSearch())); |
55 connect(this, SIGNAL(returnPressed()),this, SLOT(doSearch())); |
56 |
56 |
57 setWindowTitle("Search with Google"); |
57 setWindowTitle("Search with Google"); |
58 |
58 |
59 adjustSize(); |
59 adjustSize(); |
60 resize(400, height()); |
60 resize(400, height()); |
61 setFocus(); |
61 setFocus(); |
62 } |
62 } |
|
63 //! [1] |
63 |
64 |
|
65 //! [2] |
64 void SearchBox::doSearch() |
66 void SearchBox::doSearch() |
65 { |
67 { |
66 completer->preventSuggest(); |
68 completer->preventSuggest(); |
67 QString url = QString(GSEARCH_URL).arg(text()); |
69 QString url = QString(GSEARCH_URL).arg(text()); |
68 QDesktopServices::openUrl(QUrl(url)); |
70 QDesktopServices::openUrl(QUrl(url)); |
69 } |
71 } |
|
72 //! [2] |