diff options
Diffstat (limited to '')
| -rw-r--r-- | src/widgets/CommandInput.cpp | 40 | ||||
| -rw-r--r-- | src/widgets/MainWindow.cpp | 11 |
2 files changed, 42 insertions, 9 deletions
diff --git a/src/widgets/CommandInput.cpp b/src/widgets/CommandInput.cpp index 464065a..3ea0f38 100644 --- a/src/widgets/CommandInput.cpp +++ b/src/widgets/CommandInput.cpp @@ -1,23 +1,57 @@ +#include <QCompleter> #include <QHBoxLayout> #include <QKeyEvent> +#include <QLabel> #include <QLineEdit> +#include <QStringListModel> #include <QVBoxLayout> #include <QWidget> +#include <QWidgetAction> #include <QWindow> +#include <QtCore/qnamespace.h> +#include <QtCore/qstringlistmodel.h> +#include <QtWidgets/qboxlayout.h> +#include "completion/CommandsModel.hpp" +#include "completion/Completer.hpp" #include "widgets/CommandInput.hpp" +const char *rootStyles = R"( + background-color: #000; + color: #fff; + border-radius: 0; +)"; + CommandInput::CommandInput(QString defaultInput, QWidget *parentNode) : QWidget(parentNode) { setContentsMargins(0, 0, 0, 0); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - setStyleSheet("background-color: #000; color: #fff; border-radius: 0;"); + setStyleSheet(rootStyles); auto layout = new QVBoxLayout(this); layout->setContentsMargins(0, 0, 0, 0); - input = new QLineEdit(defaultInput, this); + + auto listModel = new CommandsModel(); + auto completer = new Completer(this); + completer->setModel(listModel); + + auto cmdLineBox = new QWidget(); + layout->addWidget(cmdLineBox); + auto cmdLineLayout = new QHBoxLayout(); + cmdLineBox->setLayout(cmdLineLayout); + cmdLineBox->layout()->setContentsMargins(0, 0, 0, 0); + cmdLineLayout->setSpacing(0); + + auto promptPrefix = new QLabel(tr(":")); + promptPrefix->setContentsMargins(0, 0, 0, 0); + input = new QLineEdit(defaultInput); input->setFocusPolicy(Qt::StrongFocus); - layout->addWidget(input); + input->setCompleter(completer); + // input->installEventFilter(completer); + + cmdLineLayout->addWidget(promptPrefix); + cmdLineLayout->addWidget(input); + setFixedHeight(input->sizeHint().height()); } diff --git a/src/widgets/MainWindow.cpp b/src/widgets/MainWindow.cpp index 9ac5f12..3191719 100644 --- a/src/widgets/MainWindow.cpp +++ b/src/widgets/MainWindow.cpp @@ -37,7 +37,7 @@ MainWindow::MainWindow() { luaRuntime = LuaRuntime::instance(); connect(luaRuntime, &LuaRuntime::urlOpenned, this, [this](QString url, OpenType openType) { - this->browserManager->openUrl(QUrl(url), openType); + browserManager->openUrl(QUrl(url), openType); }); } @@ -56,19 +56,18 @@ void MainWindow::showURLInput() { void MainWindow::evaluateCommand(QString command) { hideURLInput(); - // TODO: Temporary hack CommandParser parser; auto cmd = parser.parse(command); switch (cmd.command) { case CommandType::LuaEval: - luaRuntime->evaluate(cmd.args.join(" ").toStdString().c_str()); + luaRuntime->evaluate(cmd.argsString); break; case CommandType::Open: - browserManager->openUrl(cmd.args.first(), OpenType::OpenUrl); + browserManager->openUrl(cmd.argsString, OpenType::OpenUrl); break; case CommandType::TabOpen: - browserManager->openUrl(cmd.args.at(1), OpenType::OpenUrlInTab); + browserManager->openUrl(cmd.argsString, OpenType::OpenUrlInTab); break; case CommandType::TabNext: browserManager->nextWebView(); @@ -88,7 +87,7 @@ void MainWindow::keyPressEvent(QKeyEvent *event) { toggleURLInput(); } else if (combo.key() == Qt::Key_T && combo.keyboardModifiers().testFlag(Qt::ControlModifier)) { - browserManager->createNewWebView(QUrl("https://duckduckgo.com"), true); + browserManager->createNewWebView(QUrl("https://lite.duckduckgo.com"), true); } else if (combo.key() == Qt::Key_J && combo.keyboardModifiers().testFlag(Qt::ControlModifier)) { browserManager->nextWebView(); |
