2017-10-02 16:18:40 +00:00
|
|
|
#include "Omnibar.h"
|
2017-10-01 19:09:42 +00:00
|
|
|
#include "MainWindow.h"
|
2017-03-29 10:18:37 +00:00
|
|
|
|
|
|
|
#include <QStringListModel>
|
|
|
|
#include <QCompleter>
|
|
|
|
#include <QShortcut>
|
2017-04-27 23:48:21 +00:00
|
|
|
#include <QAbstractItemView>
|
|
|
|
|
2017-03-29 10:18:37 +00:00
|
|
|
|
|
|
|
Omnibar::Omnibar(MainWindow *main, QWidget *parent) :
|
2017-04-27 18:59:27 +00:00
|
|
|
QLineEdit(parent),
|
2017-12-21 15:16:43 +00:00
|
|
|
main(main)
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
|
|
|
// QLineEdit basic features
|
|
|
|
this->setMinimumHeight(16);
|
|
|
|
this->setFrame(false);
|
2018-02-03 19:27:00 +00:00
|
|
|
this->setPlaceholderText(tr("Type flag name or address here"));
|
|
|
|
this->setStyleSheet("border-radius: 5px; padding: 0 8px; margin: 5px 0;");
|
2017-03-29 10:18:37 +00:00
|
|
|
this->setTextMargins(10, 0, 0, 0);
|
|
|
|
this->setClearButtonEnabled(true);
|
|
|
|
|
|
|
|
connect(this, SIGNAL(returnPressed()), this, SLOT(on_gotoEntry_returnPressed()));
|
|
|
|
|
|
|
|
// Esc clears omnibar
|
2017-04-09 19:55:06 +00:00
|
|
|
QShortcut *clear_shortcut = new QShortcut(QKeySequence(Qt::Key_Escape), this);
|
2017-04-27 18:59:27 +00:00
|
|
|
connect(clear_shortcut, SIGNAL(activated()), this, SLOT(clear()));
|
2017-05-18 10:20:53 +00:00
|
|
|
clear_shortcut->setContext(Qt::WidgetWithChildrenShortcut);
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 19:55:06 +00:00
|
|
|
void Omnibar::setupCompleter()
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
// Set gotoEntry completer for jump history
|
2017-12-21 15:16:43 +00:00
|
|
|
QCompleter *completer = new QCompleter(flags, this);
|
2017-03-29 10:18:37 +00:00
|
|
|
completer->setMaxVisibleItems(20);
|
|
|
|
completer->setCompletionMode(QCompleter::PopupCompletion);
|
|
|
|
completer->setModelSorting(QCompleter::CaseSensitivelySortedModel);
|
|
|
|
completer->setCaseSensitivity(Qt::CaseInsensitive);
|
|
|
|
completer->setFilterMode(Qt::MatchContains);
|
|
|
|
|
|
|
|
this->setCompleter(completer);
|
|
|
|
}
|
|
|
|
|
2017-04-27 18:59:27 +00:00
|
|
|
void Omnibar::refresh(const QStringList &flagList)
|
|
|
|
{
|
|
|
|
flags = flagList;
|
|
|
|
|
|
|
|
setupCompleter();
|
|
|
|
}
|
|
|
|
|
2017-03-29 10:18:37 +00:00
|
|
|
void Omnibar::restoreCompleter()
|
|
|
|
{
|
|
|
|
QCompleter *completer = this->completer();
|
|
|
|
completer->setFilterMode(Qt::MatchContains);
|
|
|
|
}
|
|
|
|
|
2017-04-27 23:48:21 +00:00
|
|
|
void Omnibar::clear()
|
|
|
|
{
|
|
|
|
QLineEdit::clear();
|
|
|
|
|
|
|
|
// Close the potential shown completer popup
|
|
|
|
clearFocus();
|
|
|
|
setFocus();
|
|
|
|
}
|
|
|
|
|
2017-03-29 10:18:37 +00:00
|
|
|
void Omnibar::on_gotoEntry_returnPressed()
|
|
|
|
{
|
|
|
|
QString str = this->text();
|
2017-12-21 15:16:43 +00:00
|
|
|
if (!str.isEmpty())
|
2017-04-09 19:55:06 +00:00
|
|
|
{
|
2017-12-21 15:16:43 +00:00
|
|
|
Core()->seek(str);
|
2017-04-09 17:09:35 +00:00
|
|
|
}
|
|
|
|
|
2017-03-29 10:18:37 +00:00
|
|
|
this->setText("");
|
|
|
|
this->clearFocus();
|
|
|
|
this->restoreCompleter();
|
|
|
|
}
|