aboutsummaryrefslogtreecommitdiff
path: root/src/mainwindow.cpp
diff options
context:
space:
mode:
authorMike Skec <skec@protonmail.ch>2021-03-17 15:21:00 +1100
committerFelix Queißner <felix@ib-queissner.de>2021-03-17 09:49:58 +0100
commit7321b9078c86d640c0df6120134d9c2a2274e4aa (patch)
treebc92d852b7c6e27746d54875c3f528f54d730893 /src/mainwindow.cpp
parentf60dac9d7ebb5b989aad67d67d5ab3ccef7d278c (diff)
downloadkristall-7321b9078c86d640c0df6120134d9c2a2274e4aa.tar.gz
sessions: restore window tab indices
Diffstat (limited to 'src/mainwindow.cpp')
-rw-r--r--src/mainwindow.cpp46
1 files changed, 28 insertions, 18 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 95e6278..db833fb 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -81,44 +81,43 @@ MainWindow::MainWindow(QApplication * app, QWidget *parent) :
{
std::string prefix = "Alt+";
for (char tab = '0'; tab <= '9'; ++tab) {
- std::string shortcut = prefix + tab;
- QShortcut * sc = new QShortcut(QKeySequence(shortcut.c_str()), this);
- connect(sc, &QShortcut::activated, this,
- [this, tab](){
- // 1-9 goes from the first to the n-th tab, 0 goes to the last one
- this->ui->browser_tabs->
- setCurrentIndex((tab == '0' ?
- this->ui->browser_tabs->count()
- : tab-'0') - 1);
- });
- }
+ std::string shortcut = prefix + tab;
+ QShortcut * sc = new QShortcut(QKeySequence(shortcut.c_str()), this);
+ connect(sc, &QShortcut::activated, this, [this, tab]()
+ {
+ // 1-9 goes from the first to the n-th tab, 0 goes to the last one
+ setCurrentTabIndex((tab == '0'
+ ? this->ui->browser_tabs->count()
+ : tab-'0') - 1);
+ });
+ }
}
{
QShortcut * sc = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_PageDown), this);
connect(sc, &QShortcut::activated, this, [this](){
- int i = this->ui->browser_tabs->currentIndex();
+ int i = this->currentTabIndex();
if (i + 1 >= this->ui->browser_tabs->count())
i = 0;
else
i++;
- this->ui->browser_tabs->setCurrentIndex(i);
+ this->setCurrentTabIndex(i);
});
}
{
QShortcut * sc = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_PageUp), this);
connect(sc, &QShortcut::activated, this, [this](){
- int i = this->ui->browser_tabs->currentIndex();
+ int i = this->currentTabIndex();
if (!i)
i = this->ui->browser_tabs->count() - 1;
else
i--;
- this->ui->browser_tabs->setCurrentIndex(i);
+ this->setCurrentTabIndex(i);
});
}
@@ -148,7 +147,7 @@ BrowserTab * MainWindow::addEmptyTab(bool focus_new, bool load_default)
int index = this->ui->browser_tabs->addTab(tab, "Page");
if(focus_new) {
- this->ui->browser_tabs->setCurrentIndex(index);
+ this->setCurrentTabIndex(index);
}
if(load_default) {
@@ -308,6 +307,17 @@ void MainWindow::applySettings()
this->ui->browser_tabs->tab_bar->new_tab_btn->setVisible(kristall::globals().options.enable_newtab_btn);
}
+int MainWindow::currentTabIndex()
+{
+ return this->ui->browser_tabs->currentIndex();
+}
+
+void MainWindow::setCurrentTabIndex(int index)
+{
+ this->ui->browser_tabs->setCurrentIndex(index);
+}
+
+
void MainWindow::mousePressEvent(QMouseEvent *event)
{
QMainWindow::mousePressEvent(event);
@@ -598,7 +608,7 @@ void MainWindow::on_tab_fileLoaded(DocumentStats const & stats)
if(tab != nullptr) {
int index = this->ui->browser_tabs->indexOf(tab);
assert(index >= 0);
- if(index == this->ui->browser_tabs->currentIndex()) {
+ if(index == this->currentTabIndex()) {
setFileStatus(stats);
this->ui->outline_view->expandAll();
}
@@ -611,7 +621,7 @@ void MainWindow::on_tab_requestStateChanged(RequestState state)
if(tab != nullptr) {
int index = this->ui->browser_tabs->indexOf(tab);
assert(index >= 0);
- if(index == this->ui->browser_tabs->currentIndex()) {
+ if(index == this->currentTabIndex()) {
setRequestState(state);
}
}