mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-23 12:07:00 -04:00
Library list pinning behavior
This commit is contained in:
parent
ba6fee9d3f
commit
3b895c6f69
@ -32,7 +32,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
connect(app->getAction(KiwixApp::ToggleFullscreenAction), &QAction::triggered,
|
connect(app->getAction(KiwixApp::ToggleFullscreenAction), &QAction::triggered,
|
||||||
this, &MainWindow::toggleFullScreen);
|
this, &MainWindow::toggleFullScreen);
|
||||||
connect(app->getAction(KiwixApp::ToggleReadingListAction), &QAction::toggled,
|
connect(app->getAction(KiwixApp::ToggleReadingListAction), &QAction::toggled,
|
||||||
this, &MainWindow::when_ReadingList_toggled);
|
this, &MainWindow::readingListToggled);
|
||||||
connect(app->getAction(KiwixApp::AboutAction), &QAction::triggered,
|
connect(app->getAction(KiwixApp::AboutAction), &QAction::triggered,
|
||||||
mp_about, &QDialog::show);
|
mp_about, &QDialog::show);
|
||||||
connect(app->getAction(KiwixApp::DonateAction), &QAction::triggered,
|
connect(app->getAction(KiwixApp::DonateAction), &QAction::triggered,
|
||||||
@ -57,12 +57,11 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
mp_ui->mainToolBar, &TopWidget::updateBackForwardButtons);
|
mp_ui->mainToolBar, &TopWidget::updateBackForwardButtons);
|
||||||
connect(mp_ui->tabBar, &TabBar::tabDisplayed,
|
connect(mp_ui->tabBar, &TabBar::tabDisplayed,
|
||||||
this, [=](TabType tabType) {
|
this, [=](TabType tabType) {
|
||||||
when_libraryPageDisplayed(tabType == TabType::LibraryTab);
|
tabChanged(tabType);
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(mp_ui->tabBar, &TabBar::currentTitleChanged,
|
connect(mp_ui->tabBar, &TabBar::currentTitleChanged,
|
||||||
&(mp_ui->mainToolBar->getSearchBar()), &SearchBar::currentTitleChanged);
|
&(mp_ui->mainToolBar->getSearchBar()), &SearchBar::currentTitleChanged);
|
||||||
|
|
||||||
// This signal emited more often than the history really updated
|
// This signal emited more often than the history really updated
|
||||||
// but for now we have no better signal for it.
|
// but for now we have no better signal for it.
|
||||||
connect(mp_ui->tabBar, &TabBar::currentTitleChanged,
|
connect(mp_ui->tabBar, &TabBar::currentTitleChanged,
|
||||||
@ -120,8 +119,7 @@ bool MainWindow::eventFilter(QObject* /*object*/, QEvent* event)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::readingListToggled(bool state)
|
||||||
void MainWindow::when_ReadingList_toggled(bool state)
|
|
||||||
{
|
{
|
||||||
if (state) {
|
if (state) {
|
||||||
mp_ui->sideBar->setCurrentWidget(mp_ui->readinglistbar);
|
mp_ui->sideBar->setCurrentWidget(mp_ui->readinglistbar);
|
||||||
@ -132,19 +130,16 @@ void MainWindow::when_ReadingList_toggled(bool state)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::when_libraryPageDisplayed(bool showed)
|
void MainWindow::tabChanged(TabType tabType)
|
||||||
{
|
{
|
||||||
auto app = KiwixApp::instance();
|
QAction *readingList = KiwixApp::instance()->getAction(KiwixApp::ToggleReadingListAction);
|
||||||
|
if (tabType == TabType::SettingsTab) {
|
||||||
// When library sidebar appeared, or hidden, reading list is always hidden.
|
mp_ui->sideBar->hide();
|
||||||
app->getAction(KiwixApp::ToggleReadingListAction)->setChecked(false);
|
} else if(tabType == TabType::LibraryTab) {
|
||||||
|
|
||||||
if (showed) {
|
|
||||||
mp_ui->sideBar->setCurrentWidget(mp_ui->contentmanagerside);
|
mp_ui->sideBar->setCurrentWidget(mp_ui->contentmanagerside);
|
||||||
mp_ui->sideBar->show();
|
mp_ui->sideBar->show();
|
||||||
}
|
} else {
|
||||||
else {
|
readingListToggled(readingList->isChecked());
|
||||||
mp_ui->sideBar->hide();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,8 +31,8 @@ protected:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void toggleFullScreen();
|
void toggleFullScreen();
|
||||||
void when_ReadingList_toggled(bool state);
|
void tabChanged(TabBar::TabType);
|
||||||
void when_libraryPageDisplayed(bool showed);
|
void readingListToggled(bool state);
|
||||||
void hideTabAndTop();
|
void hideTabAndTop();
|
||||||
void showTabAndTop();
|
void showTabAndTop();
|
||||||
|
|
||||||
|
@ -13,8 +13,19 @@ ReadingListBar::ReadingListBar(QWidget *parent) :
|
|||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
connect(KiwixApp::instance()->getLibrary(), &Library::bookmarksChanged,
|
connect(KiwixApp::instance()->getLibrary(), &Library::bookmarksChanged,
|
||||||
this, &ReadingListBar::setupList);
|
this, &ReadingListBar::setupList);
|
||||||
|
connect(ui->listWidget, &QListWidget::itemClicked,
|
||||||
|
this, &ReadingListBar::onItemClicked);
|
||||||
|
connect(ui->listWidget, &QListWidget::itemDoubleClicked,
|
||||||
|
this, &ReadingListBar::onItemDoubleClicked);
|
||||||
|
connect(ui->listWidget, &QListWidget::itemPressed,
|
||||||
|
this, [this](QListWidgetItem* item) {
|
||||||
|
onItemPressed(item, QGuiApplication::mouseButtons());
|
||||||
|
});
|
||||||
connect(ui->listWidget, &QListWidget::itemActivated,
|
connect(ui->listWidget, &QListWidget::itemActivated,
|
||||||
this, &ReadingListBar::on_itemActivated);
|
this, [this](QListWidgetItem* item) {
|
||||||
|
onItemActivated(item, QGuiApplication::mouseButtons());
|
||||||
|
});
|
||||||
|
|
||||||
setupList();
|
setupList();
|
||||||
|
|
||||||
ui->label->setText(gt("reading-list-title"));
|
ui->label->setText(gt("reading-list-title"));
|
||||||
@ -25,7 +36,6 @@ ReadingListBar::~ReadingListBar()
|
|||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ReadingListBar::setupList()
|
void ReadingListBar::setupList()
|
||||||
{
|
{
|
||||||
auto library = KiwixApp::instance()->getLibrary();
|
auto library = KiwixApp::instance()->getLibrary();
|
||||||
@ -60,7 +70,41 @@ void ReadingListBar::setupList()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReadingListBar::on_itemActivated(QListWidgetItem* item)
|
// Receives single clicks
|
||||||
|
void ReadingListBar::onItemClicked(QListWidgetItem* item)
|
||||||
|
{
|
||||||
|
clickKind = 1;
|
||||||
|
QTimer::singleShot(QApplication::doubleClickInterval(), [=]() { // Give time for a double click be handled
|
||||||
|
if (clickKind == 1) {
|
||||||
|
openUrl(item, false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Receives double clicks
|
||||||
|
void ReadingListBar::onItemDoubleClicked(QListWidgetItem* item)
|
||||||
|
{
|
||||||
|
clickKind = 2;
|
||||||
|
openUrl(item, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Receives single and middle click
|
||||||
|
void ReadingListBar::onItemPressed(QListWidgetItem* item, Qt::MouseButtons buttons)
|
||||||
|
{
|
||||||
|
if (buttons & Qt::MiddleButton) {
|
||||||
|
openUrl(item, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Receives left clicks and activation key
|
||||||
|
void ReadingListBar::onItemActivated(QListWidgetItem* item, Qt::MouseButtons buttons)
|
||||||
|
{
|
||||||
|
if (!buttons) { // clicks are handled elsewhere, handle only the activation key case
|
||||||
|
openUrl(item, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ReadingListBar::openUrl(QListWidgetItem* item, bool newTab)
|
||||||
{
|
{
|
||||||
int index = ui->listWidget->row(item);
|
int index = ui->listWidget->row(item);
|
||||||
auto bookmark = KiwixApp::instance()->getLibrary()->getBookmarks(true).at(index);
|
auto bookmark = KiwixApp::instance()->getLibrary()->getBookmarks(true).at(index);
|
||||||
@ -68,5 +112,5 @@ void ReadingListBar::on_itemActivated(QListWidgetItem* item)
|
|||||||
url.setScheme("zim");
|
url.setScheme("zim");
|
||||||
url.setHost(QString::fromStdString(bookmark.getBookId())+".zim");
|
url.setHost(QString::fromStdString(bookmark.getBookId())+".zim");
|
||||||
url.setPath(QString::fromStdString(bookmark.getUrl()));
|
url.setPath(QString::fromStdString(bookmark.getUrl()));
|
||||||
KiwixApp::instance()->openUrl(url);
|
KiwixApp::instance()->openUrl(url, newTab);
|
||||||
}
|
}
|
||||||
|
@ -18,9 +18,14 @@ public:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setupList();
|
void setupList();
|
||||||
void on_itemActivated(QListWidgetItem *item);
|
void onItemClicked(QListWidgetItem* item);
|
||||||
|
void onItemDoubleClicked(QListWidgetItem *item);
|
||||||
|
void onItemPressed(QListWidgetItem* item, Qt::MouseButtons buttons);
|
||||||
|
void onItemActivated(QListWidgetItem *item, Qt::MouseButtons buttons);
|
||||||
private:
|
private:
|
||||||
Ui::readinglistbar *ui;
|
Ui::readinglistbar *ui;
|
||||||
|
int clickKind;
|
||||||
|
void openUrl(QListWidgetItem* item, bool newTab);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // READINGLISTBAR_H
|
#endif // READINGLISTBAR_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user