summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2011-05-09 10:53:32 +0200
committerAndrea Diamantini <adjam7@gmail.com>2011-05-09 10:53:32 +0200
commitfdf05ba369b62b0c87217f2c2565e7054d4123b6 (patch)
tree7edffba2a96dbfb188e62f8c24daffbd8cb7d5a7
parentNumber the favorites pages to "suggest" numeric shortcut for (diff)
downloadrekonq-fdf05ba369b62b0c87217f2c2565e7054d4123b6.tar.xz
Use of QSignalMapper for switchToTab() method in terms of code unification
Patch by Thomas Murach, thanks ;) RB:101246
-rw-r--r--src/mainview.cpp10
-rw-r--r--src/mainview.h2
-rw-r--r--src/mainwindow.cpp15
3 files changed, 12 insertions, 15 deletions
diff --git a/src/mainview.cpp b/src/mainview.cpp
index 19e4aae7..c7d66fa1 100644
--- a/src/mainview.cpp
+++ b/src/mainview.cpp
@@ -667,15 +667,11 @@ void MainView::openClosedTab()
}
-void MainView::switchToTab()
+void MainView::switchToTab(const int index)
{
- // uses the sender to determine the tab index
- QAction *sender = static_cast<QAction*>(QObject::sender());
- int index = sender->data().toInt();
- index -= 1; // to compensate for off by 1 presented to the user
- if (index < 0 || index >= count())
+ if (index <= 0 || index > count())
return;
- setCurrentIndex(index);
+ setCurrentIndex(index-1);
}
diff --git a/src/mainview.h b/src/mainview.h
index d01bb5b8..2ca3e9e7 100644
--- a/src/mainview.h
+++ b/src/mainview.h
@@ -151,7 +151,7 @@ public Q_SLOTS:
void openLastClosedTab();
void openClosedTab();
- void switchToTab();
+ void switchToTab(const int index);
void loadFavorite(const int index);
// WEB slot actions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 1ded9836..f226c9ee 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -481,28 +481,29 @@ void MainWindow::setupActions()
closedTabsMenu->setDelayed(false);
actionCollection()->addAction(QL1S("closed_tab_menu"), closedTabsMenu);
+ QSignalMapper *tabSignalMapper = new QSignalMapper(this);
// shortcuts for quickly switching to a tab
for (int i = 1; i <= 9; i++)
{
a = new KAction(i18n("Switch to Tab %1", i), this);
a->setShortcut(KShortcut(QString("Alt+%1").arg(i)));
- a->setData(QVariant(i));
actionCollection()->addAction(QL1S(("switch_tab_" + QString::number(i)).toAscii()), a);
- connect(a, SIGNAL(triggered(bool)), m_view, SLOT(switchToTab()));
+ connect(a, SIGNAL(triggered(bool)), tabSignalMapper, SLOT(map()));
+ tabSignalMapper->setMapping(a, i);
}
+ connect(tabSignalMapper, SIGNAL(mapped(const int)), m_view, SLOT(switchToTab(const int)));
// shortcuts for loading favorite pages
- QSignalMapper *signalMapper = new QSignalMapper(this);
+ QSignalMapper *favoritesSignalMapper = new QSignalMapper(this);
for (int i = 1; i <= 9; ++i)
{
a = new KAction(i18n("Switch to Favorite Page %1", i), this);
a->setShortcut(KShortcut(QString("Ctrl+%1").arg(i)));
- a->setData(QVariant(i));
actionCollection()->addAction(QL1S(("switch_favorite_" + QString::number(i)).toAscii()), a);
- connect(a, SIGNAL(triggered(bool)), signalMapper, SLOT(map()));
- signalMapper->setMapping(a, i);
+ connect(a, SIGNAL(triggered(bool)), favoritesSignalMapper, SLOT(map()));
+ favoritesSignalMapper->setMapping(a, i);
}
- connect(signalMapper, SIGNAL(mapped(const int)), m_view, SLOT(loadFavorite(const int)));
+ connect(favoritesSignalMapper, SIGNAL(mapped(const int)), m_view, SLOT(loadFavorite(const int)));
// ============================== Indexed Tab Actions ====================================
a = new KAction(KIcon("tab-close"), i18n("&Close Tab"), this);