aboutsummaryrefslogtreecommitdiff
path: root/src/browsertab.cpp
diff options
context:
space:
mode:
authorMike Skec <skec@protonmail.ch>2021-01-04 13:02:40 +1100
committerFelix Queißner <felix@ib-queissner.de>2021-01-04 11:17:12 +0100
commit3d795469818177c5b9932df3577bb6e9c1d0ab2e (patch)
treeda974e41296f5084ca6b0c1567d741196cab696c /src/browsertab.cpp
parent7ec3ed15aa99148f1c8df86bb49202da67d6813d (diff)
downloadkristall-3d795469818177c5b9932df3577bb6e9c1d0ab2e.tar.gz
New popup when adding to favourites!
Diffstat (limited to 'src/browsertab.cpp')
-rw-r--r--src/browsertab.cpp36
1 files changed, 35 insertions, 1 deletions
diff --git a/src/browsertab.cpp b/src/browsertab.cpp
index e8b8443..c8fc307 100644
--- a/src/browsertab.cpp
+++ b/src/browsertab.cpp
@@ -21,6 +21,7 @@
#include "ioutil.hpp"
#include "kristall.hpp"
+#include "widgets/favouritepopup.hpp"
#include <cassert>
#include <QTabWidget>
@@ -109,6 +110,14 @@ BrowserTab::BrowserTab(MainWindow *mainWindow) : QWidget(nullptr),
QShortcut * sc = new QShortcut(QKeySequence("Escape"), this->ui->search_bar);
connect(sc, &QShortcut::activated, this, &BrowserTab::on_close_search_clicked);
}
+
+ FavouritePopup * popup_menu = new FavouritePopup(this->ui->fav_button, this);
+ connect(popup_menu, &FavouritePopup::unfavourited, this, [this]() {
+ this->ui->fav_button->setChecked(false);
+ kristall::favourites.removeUrl(this->current_location);
+ });
+ this->ui->fav_button->setPopupMode(QToolButton::DelayedPopup);
+ this->ui->fav_button->setMenu(popup_menu);
}
BrowserTab::~BrowserTab()
@@ -864,9 +873,29 @@ void BrowserTab::pushToHistory(const QUrl &url)
this->updateUI();
}
+void BrowserTab::addToFavouritesPopup()
+{
+ // We add it to favourites immediately.
+ kristall::favourites.addUnsorted(this->current_location, this->page_title);
+
+ // Show menu, this will block thread
+ this->ui->fav_button->setChecked(true);
+ FavouritePopup *popup = static_cast<FavouritePopup*>(this->ui->fav_button->menu());
+ popup->fav_title->setText(
+ kristall::favourites.getFavourite(this->current_location).title
+ );
+ popup->setFocus(Qt::PopupFocusReason);
+ popup->fav_title->setFocus(Qt::PopupFocusReason);
+ popup->fav_title->selectAll();
+ this->ui->fav_button->showMenu();
+
+ // Update the favourites entry with what user inputted into menu
+ kristall::favourites.editFavouriteTitle(this->current_location, popup->fav_title->text());
+}
+
void BrowserTab::on_fav_button_clicked()
{
- toggleIsFavourite(this->ui->fav_button->isChecked());
+ this->addToFavouritesPopup();
}
void BrowserTab::on_text_browser_anchorClicked(const QUrl &url, bool open_in_new_tab)
@@ -1106,6 +1135,11 @@ void BrowserTab::updateUI()
this->ui->refresh_button->setVisible(not in_progress);
this->ui->stop_button->setVisible(in_progress);
+ this->refreshFavButton();
+}
+
+void BrowserTab::refreshFavButton()
+{
this->ui->fav_button->setEnabled(this->successfully_loaded);
this->ui->fav_button->setChecked(kristall::favourites.containsUrl(this->current_location));
}