diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2017-01-30 15:37:30 +0100 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2017-01-30 15:37:30 +0100 |
commit | d6101a83cad797e80ade602662878378ee0f2306 (patch) | |
tree | e4f1627aea8ac370f0b6608dcb134fd18ca174fd /src | |
parent | Added bug reporting section to Contributing (diff) | |
download | smolbote-d6101a83cad797e80ade602662878378ee0f2306.tar.xz |
Added UrlLineEdit class
Address bar should highlight the host name
WebView widget should now be focused on startup instead of the address
bar
Added names to the toolbars to make their context menu useful
Tabs now have a set width of 200
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 2 | ||||
-rw-r--r-- | src/mainwindow.cpp | 17 | ||||
-rw-r--r-- | src/mainwindow.h | 5 | ||||
-rw-r--r-- | src/smolbote.qbs | 2 | ||||
-rw-r--r-- | src/widgets/urllineedit.cpp | 43 | ||||
-rw-r--r-- | src/widgets/urllineedit.h | 23 | ||||
-rw-r--r-- | src/widgets/webviewtabbar.cpp | 6 | ||||
-rw-r--r-- | src/widgets/webviewtabbar.h | 3 |
8 files changed, 87 insertions, 14 deletions
diff --git a/src/main.cpp b/src/main.cpp index d6a6fd0..5b77ba7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -33,7 +33,7 @@ int main(int argc, char *argv[]) app.setWindowIcon(QIcon(QLatin1String(":/icon.svg"))); QCommandLineParser parser; - parser.setApplicationDescription("Test browser using QtWebEngine"); + parser.setApplicationDescription("yet another Qt browser"); parser.addHelpOption(); parser.addVersionOption(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 8413b18..0369d17 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -36,10 +36,10 @@ MainWindow::MainWindow(Browser *instance, QUrl defaultUrl, QWidget *parent) : downloadManager(new DownloadDialog(this)), blocklistManager(new BlockerDialog(this)), ui(new Ui::MainWindow), - navigationToolBar(new QToolBar(this)), - tabToolBar(new QToolBar(this)), + navigationToolBar(new QToolBar(tr("Navigation"), this)), + tabToolBar(new QToolBar(tr("Tab bar"), this)), tabBar(new WebViewTabBar(this)), - urlLineEdit(new QLineEdit(navigationToolBar)) + urlLineEdit(new UrlLineEdit(navigationToolBar)) { browserInstance = instance; Settings settings; @@ -164,10 +164,12 @@ void MainWindow::handleTabChanged(QWebEngineView *view) centralWidget()->setParent(0); disconnect(centralWidget()); setCentralWidget(view); - connect(view, SIGNAL(urlChanged(QUrl)), this, SLOT(handleUrlUpdated(QUrl))); + connect(view, SIGNAL(urlChanged(QUrl)), urlLineEdit, SLOT(setUrl(QUrl))); connect(view, SIGNAL(titleChanged(QString)), this, SLOT(handleTitleUpdated(QString))); - this->handleUrlUpdated(view->url()); + urlLineEdit->setUrl(view->url()); this->handleTitleUpdated(view->title()); + + centralWidget()->setFocus(); } void MainWindow::handleUrlChanged() @@ -175,11 +177,6 @@ void MainWindow::handleUrlChanged() tabBar->currentView()->load(QUrl::fromUserInput(urlLineEdit->text())); } -void MainWindow::handleUrlUpdated(const QUrl &url) -{ - urlLineEdit->setText(url.toString()); -} - void MainWindow::handleTitleUpdated(const QString &title) { // For some reason, the long dash gets garbled if read from the settings diff --git a/src/mainwindow.h b/src/mainwindow.h index e4c1a1f..4a7455a 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -23,7 +23,7 @@ #include <QMainWindow> #include <QToolBar> -#include <QLineEdit> +#include "widgets/urllineedit.h" #include <QWebEngineView> #include "webengine/webengineprofile.h" #include <QUrl> @@ -61,7 +61,6 @@ private slots: void handleNewWindow(const QUrl &url = QUrl("")); void handleTabChanged(QWebEngineView *view); void handleUrlChanged(); - void handleUrlUpdated(const QUrl &url); void handleTitleUpdated(const QString &title); private: @@ -75,7 +74,7 @@ private: Ui::MainWindow *ui; QToolBar *navigationToolBar, *tabToolBar; WebViewTabBar *tabBar; - QLineEdit *urlLineEdit; + UrlLineEdit *urlLineEdit; }; #endif // MAINWINDOW_H diff --git a/src/smolbote.qbs b/src/smolbote.qbs index 1dd603a..c8ecb24 100644 --- a/src/smolbote.qbs +++ b/src/smolbote.qbs @@ -57,6 +57,8 @@ Project { "webengine/urlinterceptor.h", "webengine/webengineprofile.cpp", "webengine/webengineprofile.h", + "widgets/urllineedit.cpp", + "widgets/urllineedit.h", "widgets/webviewtabbar.cpp", "widgets/webviewtabbar.h", ] diff --git a/src/widgets/urllineedit.cpp b/src/widgets/urllineedit.cpp new file mode 100644 index 0000000..25bf157 --- /dev/null +++ b/src/widgets/urllineedit.cpp @@ -0,0 +1,43 @@ +#include "urllineedit.h" +#include <QUrl> + +UrlLineEdit::UrlLineEdit(QWidget *parent) : + QLineEdit(parent) +{ + //setStyleSheet("color: #808080"); +} + +void UrlLineEdit::setUrl(const QUrl &url) +{ + QString urlText = url.toString(); + QString domain = url.host(); + + QTextCharFormat f_host; + + f_host.setFontWeight(QFont::Bold); + //f_host.setForeground(QBrush(QColor::fromRgb(255, 255, 255))); + + QTextLayout::FormatRange fr_tracker; + fr_tracker.start = urlText.indexOf(domain); + fr_tracker.length = domain.length(); + fr_tracker.format = f_host; + + clear(); + clearTextFormat(); + setTextFormat(fr_tracker); + setText(urlText); +} + +void UrlLineEdit::setTextFormat(const QTextLayout::FormatRange &format) +{ + QList<QInputMethodEvent::Attribute> attributes; + attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, format.start, format.length, format.format)); + QInputMethodEvent ev(QString(), attributes); + event(&ev); + +} + +void UrlLineEdit::clearTextFormat() +{ + setTextFormat(QTextLayout::FormatRange()); +} diff --git a/src/widgets/urllineedit.h b/src/widgets/urllineedit.h new file mode 100644 index 0000000..e7dcf36 --- /dev/null +++ b/src/widgets/urllineedit.h @@ -0,0 +1,23 @@ +#ifndef URLLINEEDIT_H +#define URLLINEEDIT_H + +#include <QLineEdit> +#include <QTextLayout> + +class UrlLineEdit : public QLineEdit +{ + Q_OBJECT +public: + explicit UrlLineEdit(QWidget *parent = 0); + +signals: + +public slots: + void setUrl(const QUrl &url); + +private: + void setTextFormat(const QTextLayout::FormatRange &format); + void clearTextFormat(); +}; + +#endif // URLLINEEDIT_H diff --git a/src/widgets/webviewtabbar.cpp b/src/widgets/webviewtabbar.cpp index d3747cc..a050a76 100644 --- a/src/widgets/webviewtabbar.cpp +++ b/src/widgets/webviewtabbar.cpp @@ -70,6 +70,12 @@ QWebEngineView *WebViewTabBar::currentView() return m_views.at(currentIndex()); } +QSize WebViewTabBar::tabSizeHint(int index) const +{ + Q_UNUSED(index) + return QSize(200, this->height()); +} + void WebViewTabBar::handleCurrentChanged(int index) { emit(currentTabChanged(m_views.at(index))); diff --git a/src/widgets/webviewtabbar.h b/src/widgets/webviewtabbar.h index 58d85a8..8b32e7a 100644 --- a/src/widgets/webviewtabbar.h +++ b/src/widgets/webviewtabbar.h @@ -40,6 +40,9 @@ public: signals: void currentTabChanged(QWebEngineView *view); +protected: + QSize tabSizeHint(int index) const; + private slots: void handleCurrentChanged(int index); void handleTabClose(int index); |