LocationBar::LocationBar(QupZilla* mainClass) : LineEdit(mainClass) , p_QupZilla(mainClass) , m_webView(0) , m_pasteAndGoAction(0) , m_clearAction(0) , m_rssIconVisible(false) , m_holdingAlt(false) , m_loadProgress(0) , m_progressVisible(false) , m_forcePaintEvent(false) , m_inlineCompletionVisible(false) , m_popupClosed(false) { setObjectName("locationbar"); setDragEnabled(true); m_bookmarkIcon = new BookmarksIcon(this); m_goIcon = new GoIcon(this); m_rssIcon = new RssIcon(this); m_siteIcon = new SiteIcon(p_QupZilla, this); m_autofillIcon = new AutoFillIcon(this); DownIcon* down = new DownIcon(this); // RTL Support // if we don't add 'm_siteIcon' by following code, then we should use suitable padding-left value // but then, when typing RTL text the layout dynamically changed and within RTL layout direction // padding-left is equivalent to padding-right and vice versa, and because style sheet is // not changed dynamically this create padding problems. addWidget(m_siteIcon, LineEdit::LeftSide); addWidget(m_autofillIcon, LineEdit::RightSide); addWidget(m_bookmarkIcon, LineEdit::RightSide); addWidget(m_rssIcon, LineEdit::RightSide); addWidget(m_goIcon, LineEdit::RightSide); addWidget(down, LineEdit::RightSide); m_completer.setLocationBar(this); connect(&m_completer, SIGNAL(showCompletion(QString)), this, SLOT(showCompletion(QString))); connect(&m_completer, SIGNAL(completionActivated()), this, SLOT(urlEnter())); connect(&m_completer, SIGNAL(popupClosed()), this, SLOT(completionPopupClosed())); connect(this, SIGNAL(textEdited(QString)), this, SLOT(textEdit())); connect(m_goIcon, SIGNAL(clicked(QPoint)), this, SLOT(urlEnter())); connect(down, SIGNAL(clicked(QPoint)), &m_completer, SLOT(showMostVisited())); connect(mApp->searchEnginesManager(), SIGNAL(activeEngineChanged()), this, SLOT(updatePlaceHolderText())); connect(mApp->searchEnginesManager(), SIGNAL(defaultEngineChanged()), this, SLOT(updatePlaceHolderText())); connect(mApp, SIGNAL(message(Qz::AppMessageType,bool)), SLOT(onMessage(Qz::AppMessageType,bool))); loadSettings(); clearIcon(); // Hide icons by default hideGoButton(); m_rssIcon->hide(); m_autofillIcon->hide(); QTimer::singleShot(0, this, SLOT(updatePlaceHolderText())); }
//! [9] void GSuggestCompletion::handleNetworkData(QNetworkReply *networkReply) { QUrl url = networkReply->url(); if (!networkReply->error()) { QStringList choices; QStringList hits; QByteArray response(networkReply->readAll()); QXmlStreamReader xml(response); while (!xml.atEnd()) { xml.readNext(); if (xml.tokenType() == QXmlStreamReader::StartElement) if (xml.name() == "suggestion") { QStringRef str = xml.attributes().value("data"); choices << str.toString(); } if (xml.tokenType() == QXmlStreamReader::StartElement) if (xml.name() == "num_queries") { QStringRef str = xml.attributes().value("int"); hits << str.toString(); } } showCompletion(choices, hits); } networkReply->deleteLater(); }
void DictionarySuggestions::autoSuggest() { if(!controller ||!controller->hasHDT() ) { return; } try { QString str = editor->text(); if(str.length()<1) { return; } // If not URI, Literal, Blank if( str.at(0)!='"' && str.at(0)!='_' && str.left(4)!="http") { // Assume literal otherwise str.prepend("\""); } vector<string> choices; // FETCH RESULTS FROM DICTIONARY controller->getHDT()->getDictionary()->getSuggestions(str.toUtf8(), role, choices, NUM_SUGGESTIONS); if(choices.size()==1 && choices[0]==string(str.toUtf8())) { return; } // show showCompletion(choices); } catch (const char *ex) { #ifndef WIN32 } catch (char *ex) { #endif } }
void LocationCompleter::loadRequest(const LoadRequest &request) { closePopup(); // Show url in locationbar emit showCompletion(request.url().toString(), false); // Load request emit loadRequested(request); }
void LocationCompleter::loadUrl(const QUrl &url) { closePopup(); // Show url in locationbar emit showCompletion(url.toEncoded()); // Load url emit loadCompletion(); }
void LocationCompleter::currentChanged(const QModelIndex &index) { QString completion = index.data().toString(); if (completion.isEmpty()) { completion = m_originalText; } emit showCompletion(completion); }
void ArtistSuggest::onGotSearch() { QNetworkReply *reply = static_cast<QNetworkReply *>(sender()); if (reply->error() != QNetworkReply::NoError) { return; } QList<ella::Artist> artists = ella::Artist::list(reply); QStringList choices; for (int i=0; i < artists.size(); ++i) { choices << artists[i].name(); } showCompletion(choices); }
void TrackSuggest::onGotSearch() { QNetworkReply *reply = static_cast<QNetworkReply *>(sender()); if (reply->error() != QNetworkReply::NoError) { return; } QList<ella::Track> tracks = ella::Track::list(reply); QStringList choices; for (int i = 0; i < tracks.size(); ++i) { ella::Track track = tracks[i]; choices << QString("%1 - %2").arg(track.artistName()).arg(track.title()); } showCompletion(choices); }
void System::runOnce(const char *startupBas) { // startupBas must not be _loadPath.c_str() logEntered(); _mainBas = false; bool restart = true; while (restart) { bool success = execute(startupBas); if (_state == kActiveState) { showCompletion(success); } waitForBack(); restart = isRestart(); } }
void LocationCompleter::currentChanged(const QModelIndex &index) { if (m_ignoreCurrentChanged) { return; } QString completion = index.data().toString(); bool completeDomain = index.data(LocationCompleterModel::VisitSearchItemRole).toBool(); // Domain completion was dismissed if (completeDomain && completion == m_originalText) { completeDomain = false; } if (completion.isEmpty()) { completeDomain = true; completion = m_originalText; } emit showCompletion(completion, completeDomain); }
void AutoComplete::suggestionsReady(QStringList suggestions) { if (!enabled) return; showCompletion(suggestions); }
LocationBar::LocationBar(BrowserWindow* window) : LineEdit(window) , m_window(window) , m_webView(0) , m_pasteAndGoAction(0) , m_clearAction(0) , m_holdingAlt(false) , m_loadProgress(0) , m_progressVisible(false) { setObjectName("locationbar"); setDragEnabled(true); // Disable Oxygen QLineEdit transitions, it breaks with setText() && home() setProperty("_kde_no_animations", QVariant(true)); m_bookmarkIcon = new BookmarksIcon(this); m_goIcon = new GoIcon(this); m_rssIcon = new RssIcon(this); m_siteIcon = new SiteIcon(m_window, this); m_autofillIcon = new AutoFillIcon(this); DownIcon* down = new DownIcon(this); addWidget(m_siteIcon, LineEdit::LeftSide); addWidget(m_autofillIcon, LineEdit::RightSide); addWidget(m_bookmarkIcon, LineEdit::RightSide); addWidget(m_rssIcon, LineEdit::RightSide); addWidget(m_goIcon, LineEdit::RightSide); addWidget(down, LineEdit::RightSide); m_completer = new LocationCompleter(this); m_completer->setMainWindow(m_window); m_completer->setLocationBar(this); connect(m_completer, SIGNAL(showCompletion(QString)), this, SLOT(showCompletion(QString))); connect(m_completer, SIGNAL(showDomainCompletion(QString)), this, SLOT(showDomainCompletion(QString))); connect(m_completer, SIGNAL(loadCompletion()), this, SLOT(requestLoadUrl())); connect(m_completer, SIGNAL(clearCompletion()), this, SLOT(clearCompletion())); m_domainCompleterModel = new QStringListModel(this); QCompleter* domainCompleter = new QCompleter(this); domainCompleter->setCompletionMode(QCompleter::InlineCompletion); domainCompleter->setModel(m_domainCompleterModel); setCompleter(domainCompleter); connect(this, SIGNAL(textEdited(QString)), this, SLOT(textEditted())); connect(m_goIcon, SIGNAL(clicked(QPoint)), this, SLOT(requestLoadUrl())); connect(down, SIGNAL(clicked(QPoint)), m_completer, SLOT(showMostVisited())); connect(mApp->searchEnginesManager(), SIGNAL(activeEngineChanged()), this, SLOT(updatePlaceHolderText())); connect(mApp->searchEnginesManager(), SIGNAL(defaultEngineChanged()), this, SLOT(updatePlaceHolderText())); connect(mApp, SIGNAL(settingsReloaded()), SLOT(loadSettings())); loadSettings(); updateSiteIcon(); // Hide icons by default m_goIcon->setVisible(qzSettings->alwaysShowGoIcon); m_rssIcon->hide(); m_autofillIcon->hide(); QTimer::singleShot(0, this, SLOT(updatePlaceHolderText())); }
void System::runMain(const char *mainBasPath) { logEntered(); // activePath provides the program name after termination String activePath = mainBasPath; _loadPath = mainBasPath; _mainBas = true; strcpy(opt_command, "welcome"); bool started = execute(_loadPath); if (!started) { alert("Error", gsb_last_errmsg); _state = kClosingState; } while (!isClosing() && started) { if (isRestart()) { _loadPath = activePath; _state = kActiveState; } else { if (fileExists(_loadPath)) { _mainBas = false; activePath = _loadPath; if (!isEditReady()) { setupPath(_loadPath); } } else { _mainBas = true; _loadPath = mainBasPath; activePath = mainBasPath; } } if (!_mainBas && isEditReady() && loadSource(_loadPath)) { editSource(_loadPath); if (isBack()) { _loadPath.clear(); _state = kActiveState; continue; } else if (isClosing()) { break; } } bool success = execute(_loadPath); bool networkFile = isNetworkLoad(); if (!isBack() && !isClosing() && (success || networkFile || !isEditEnabled())) { // when editing, only pause here when successful, otherwise the editor shows // the error. load the next network file without displaying the previous result if (!_mainBas && !networkFile) { // display an indication the program has completed showCompletion(success); } if (!success) { if (_mainBas) { // unexpected error in main.bas alert("", gsb_last_errmsg); _state = kClosingState; } else { // don't reload _loadPath.clear(); _state = kActiveState; } } if (!_mainBas && !networkFile) { waitForBack(); } } } }
bool CppEditorCompletion::doObjectCompletion( const QString &objName ) { if ( !ths ) return FALSE; QString object( objName ); int i = -1; if ( ( i = object.findRev( "->" ) ) != -1 ) object = object.mid( i + 2 ); if ( ( i = object.findRev( "." ) ) != -1 ) object = object.mid( i + 1 ); object = object.simplifyWhiteSpace(); QObject *obj = 0; if ( ths->name() == object || object == "this" ) { obj = ths; } else { obj = ths->child( object ); } if ( !obj ) return FALSE; QValueList<CompletionEntry> lst; if ( obj->children() ) { for ( QObjectListIt cit( *obj->children() ); cit.current(); ++cit ) { QString s( cit.current()->name() ); if ( s.find( " " ) == -1 && s.find( "qt_" ) == -1 && s.find( "unnamed" ) == -1 ) { CompletionEntry c; c.type = "variable"; c.text = s; c.prefix = ""; lst << c; } } } QStrList props = obj->metaObject()->propertyNames( TRUE ); for ( QPtrListIterator<char> pit( props ); pit.current(); ++pit ) { QString f( pit.current() ); QChar c = f[ 0 ]; f.remove( (uint)0, 1 ); f.prepend( c.upper() ); f.prepend( "set" ); CompletionEntry ce; ce.type = "property"; ce.text = f; ce.postfix = "()"; if ( lst.find( ce ) == lst.end() ) lst << ce; } QStrList slts = obj->metaObject()->slotNames( TRUE ); for ( QPtrListIterator<char> sit( slts ); sit.current(); ++sit ) { QString f( sit.current() ); f = f.left( f.find( "(" ) ); CompletionEntry c; c.type = "slot"; c.text = f; c.postfix = "()"; if ( lst.find( c ) == lst.end() ) lst << c; } if ( lst.isEmpty() ) return FALSE; showCompletion( lst ); return TRUE; }