summaryrefslogtreecommitdiff
path: root/src/tabwindow
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2012-11-11 09:40:36 +0100
committerAndrea Diamantini <adjam7@gmail.com>2012-12-10 02:48:06 +0100
commit4f1dae7834becb7d7105a0cc9945d9a0c04383b8 (patch)
treebe823d81fe7ab1cc199b11bc5b32823d3cc9bdf7 /src/tabwindow
parentClean up previous commit about adblock and fix enable/disable feature (diff)
downloadrekonq-4f1dae7834becb7d7105a0cc9945d9a0c04383b8.tar.xz
WARNING: BIG COMMIT
This commit reviews and partially fix the Q/K action mess in rekonq code. We now store actions in different actioncollections (one for each tab && one for each window). Related to this code review, you can find also fixes for some triggered actions NOT working (well) before: - fullscreen - bookmark all tabs - new (clean) tab
Diffstat (limited to 'src/tabwindow')
-rw-r--r--src/tabwindow/rekonqwindow.cpp3
-rw-r--r--src/tabwindow/tabbar.cpp49
-rw-r--r--src/tabwindow/tabbar.h1
-rw-r--r--src/tabwindow/tabwindow.cpp91
-rw-r--r--src/tabwindow/tabwindow.h10
5 files changed, 100 insertions, 54 deletions
diff --git a/src/tabwindow/rekonqwindow.cpp b/src/tabwindow/rekonqwindow.cpp
index 8bc96d87..05608954 100644
--- a/src/tabwindow/rekonqwindow.cpp
+++ b/src/tabwindow/rekonqwindow.cpp
@@ -311,7 +311,8 @@ void RekonqWindow::parseGeometry()
void RekonqWindow::resizeEvent(QResizeEvent *event)
{
- saveAutoSaveSettings();
+ if (!isFullScreen())
+ saveAutoSaveSettings();
KTabWidget::resizeEvent(event);
}
diff --git a/src/tabwindow/tabbar.cpp b/src/tabwindow/tabbar.cpp
index 725d1372..70dcd3b1 100644
--- a/src/tabwindow/tabbar.cpp
+++ b/src/tabwindow/tabbar.cpp
@@ -177,56 +177,55 @@ void TabBar::detachTab()
}
-void TabBar::contextMenu(int tab, const QPoint &pos)
+void TabBar::contextMenu(int tabIndex, const QPoint &pos)
{
TabWindow *w = qobject_cast<TabWindow *>(parent());
- KAction *a;
+ QAction *a;
KMenu menu;
- a = new KAction(KIcon("tab-new"), i18n("New &Tab"), this);
- connect(a, SIGNAL(triggered(bool)), w, SLOT(newCleanTab()));
+ a = w->actionByName(QL1S("new_tab"));
menu.addAction(a);
menu.addSeparator(); // ----------------------------------------------------------------
a = new KAction(KIcon("tab-duplicate"), i18n("Clone"), this);
- a->setData(tab);
+ a->setData(tabIndex);
connect(a, SIGNAL(triggered(bool)), this, SLOT(cloneTab()));
menu.addAction(a);
a = new KAction(KIcon("view-refresh"), i18n("Reload"), this);
connect(a, SIGNAL(triggered(bool)), this, SLOT(reloadTab()));
- a->setData(tab);
+ a->setData(tabIndex);
menu.addAction(a);
if (count() > 1)
{
a = new KAction(KIcon("tab-detach"), i18n("Detach"), this);
connect(a, SIGNAL(triggered(bool)), this, SLOT(detachTab()));
- a->setData(tab);
+ a->setData(tabIndex);
menu.addAction(a);
}
- if (tabData(tab).toBool())
+ if (tabData(tabIndex).toBool())
{
a = new KAction(i18n("Unpin Tab"), this);
connect(a, SIGNAL(triggered(bool)), this, SLOT(unpinTab()));
- a->setData(tab);
+ a->setData(tabIndex);
menu.addAction(a);
}
else
{
a = new KAction(i18n("Pin Tab"), this);
connect(a, SIGNAL(triggered(bool)), this, SLOT(pinTab()));
- a->setData(tab);
+ a->setData(tabIndex);
menu.addAction(a);
}
menu.addSeparator(); // ----------------------------------------------------------------
a = new KAction(KIcon("tab-close"), i18n("&Close"), this);
- a->setData(tab);
+ a->setData(tabIndex);
connect(a, SIGNAL(triggered(bool)), this, SLOT(closeTab()));
menu.addAction(a);
@@ -234,26 +233,19 @@ void TabBar::contextMenu(int tab, const QPoint &pos)
{
a = new KAction(KIcon("tab-close-other"), i18n("Close &Other Tabs"), this);
connect(a, SIGNAL(triggered(bool)), this, SLOT(closeOtherTabs()));
- a->setData(tab);
+ a->setData(tabIndex);
menu.addAction(a);
}
menu.addSeparator();
- a = new KAction(KIcon("tab-new"), i18n("Open Last Closed Tab"), this);
- a->setData(0); // last closed tab has index 0!
- connect(a, SIGNAL(triggered(bool)), this, SIGNAL(restoreLastClosedTab()));
+ a = w->actionByName(QL1S("open_last_closed_tab"));
menu.addAction(a);
if (count() > 1)
{
- a = new KAction(KIcon("bookmark-new"), i18n("Bookmarks all tabs"), this);
- menu.addAction(a);
- }
- else
- {
- a = new KAction(KIcon("bookmark-new"), i18n("Bookmark"), this);
+ a = w->actionByName(QL1S("bookmark_all_tabs"));
menu.addAction(a);
}
@@ -265,26 +257,19 @@ void TabBar::emptyAreaContextMenu(const QPoint &pos)
{
TabWindow *w = qobject_cast<TabWindow *>(parent());
- KAction *a;
+ QAction *a;
KMenu menu;
- a = new KAction(KIcon("tab-new"), i18n("New &Tab"), this);
- connect(a, SIGNAL(triggered(bool)), w, SLOT(newCleanTab()));
+ a = w->actionByName(QL1S("new_tab"));
menu.addAction(a);
- a = new KAction(KIcon("tab-new"), i18n("Open Last Closed Tab"), this);
- a->setData(0); // last closed tab has index 0!
+ a = w->actionByName(QL1S("open_last_closed_tab"));
menu.addAction(a);
if (count() > 1)
{
- a = new KAction(KIcon("bookmark-new"), i18n("Bookmarks all tabs"), this);
- menu.addAction(a);
- }
- else
- {
- a = new KAction(KIcon("bookmark-new"), i18n("Bookmark"), this);
+ a = w->actionByName(QL1S("bookmark_all_tabs"));
menu.addAction(a);
}
diff --git a/src/tabwindow/tabbar.h b/src/tabwindow/tabbar.h
index 64fed413..292f3d6d 100644
--- a/src/tabwindow/tabbar.h
+++ b/src/tabwindow/tabbar.h
@@ -70,7 +70,6 @@ Q_SIGNALS:
void closeOtherTabs(int);
void reloadTab(int);
void detachTab(int);
- void restoreLastClosedTab();
void tabLayoutChanged();
private Q_SLOTS:
diff --git a/src/tabwindow/tabwindow.cpp b/src/tabwindow/tabwindow.cpp
index 6e64d7e4..84797f85 100644
--- a/src/tabwindow/tabwindow.cpp
+++ b/src/tabwindow/tabwindow.cpp
@@ -36,6 +36,7 @@
#include "tabhistory.h"
+#include "bookmarkmanager.h"
#include "iconmanager.h"
// KDE Includes
@@ -48,6 +49,9 @@
#include <KUrl>
#include <KToggleFullScreenAction>
+#include <KBookmark>
+#include <KBookmarkGroup>
+
#include <KWindowInfo>
#include <KWindowSystem>
@@ -67,6 +71,7 @@ TabWindow::TabWindow(bool withTab, bool PrivateBrowsingMode, QWidget *parent)
, _addTabButton(new QToolButton(this))
, _openedTabsCounter(0)
, _isPrivateBrowsing(PrivateBrowsingMode)
+ , _ac(new KActionCollection(this))
{
setContentsMargins(0, 0, 0, 0);
@@ -86,7 +91,7 @@ TabWindow::TabWindow(bool withTab, bool PrivateBrowsingMode, QWidget *parent)
connect(tabBar, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int)));
connect(tabBar, SIGNAL(mouseMiddleClick(int)), this, SLOT(closeTab(int)));
- connect(tabBar, SIGNAL(newTabRequest()), this, SLOT(newCleanTab()));
+ connect(tabBar, SIGNAL(newTabRequest()), this, SLOT(newTab()));
connect(tabBar, SIGNAL(cloneTab(int)), this, SLOT(cloneTab(int)));
connect(tabBar, SIGNAL(closeTab(int)), this, SLOT(closeTab(int)));
@@ -94,34 +99,47 @@ TabWindow::TabWindow(bool withTab, bool PrivateBrowsingMode, QWidget *parent)
connect(tabBar, SIGNAL(reloadTab(int)), this, SLOT(reloadTab(int)));
connect(tabBar, SIGNAL(detachTab(int)), this, SLOT(detachTab(int)));
- connect(tabBar, SIGNAL(restoreLastClosedTab()), this, SLOT(restoreLastClosedTab()));
-
connect(tabBar, SIGNAL(tabLayoutChanged()), this, SLOT(updateNewTabButtonPosition()));
- // new tab button
- KAction* a = new KAction(KIcon("tab-new"), i18n("New &Tab"), this);
- _addTabButton->setDefaultAction(a);
- _addTabButton->setAutoRaise(true);
- _addTabButton->raise();
- _addTabButton->setToolButtonStyle(Qt::ToolButtonIconOnly);
- connect(_addTabButton, SIGNAL(triggered(QAction *)), this, SLOT(newCleanTab()));
-
- connect(this, SIGNAL(currentChanged(int)), this, SLOT(currentChanged(int)));
+ // ============================== Tab Window Actions ====================================
+ _ac->addAssociatedWidget(this);
+
+ KAction* a;
- // ----------------------------------------------------------------------------------------------
- KActionCollection *tabActionColl = new KActionCollection(this);
- tabActionColl->addAssociatedWidget(this);
+ a = new KAction(KIcon("tab-new"), i18n("New &Tab"), this);
+ a->setShortcut(KShortcut(Qt::CTRL + Qt::Key_T));
+ actionCollection()->addAction(QL1S("new_tab"), a);
+ connect(a, SIGNAL(triggered(bool)), this, SLOT(newTab()));
a = new KAction(KIcon("tab-new"), i18n("Open Last Closed Tab"), this);
a->setShortcut(KShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_T));
- tabActionColl->addAction(QL1S("open_last_closed_tab"), a);
+ actionCollection()->addAction(QL1S("open_last_closed_tab"), a);
connect(a, SIGNAL(triggered(bool)), this, SLOT(restoreLastClosedTab()));
a = new KAction(KIcon("tab-close"), i18n("&Close Tab"), this);
a->setShortcuts(KStandardShortcut::close());
- tabActionColl->addAction(QL1S("close_tab"), a);
+ actionCollection()->addAction(QL1S("close_tab"), a);
connect(a, SIGNAL(triggered(bool)), this, SLOT(closeTab()));
+
+ a = KStandardAction::fullScreen(this, SLOT(setFullScreen(bool)), this, actionCollection());
+ KShortcut fullScreenShortcut = KStandardShortcut::fullScreen();
+ fullScreenShortcut.setAlternate(Qt::Key_F11);
+ a->setShortcut(fullScreenShortcut);
+ a = new KAction(KIcon("bookmarks"), i18n("Bookmark all tabs"), this);
+ actionCollection()->addAction(QL1S("bookmark_all_tabs"), a);
+ connect(a, SIGNAL(triggered(bool)), this, SLOT(bookmarkAllTabs()));
+
+ // ----------------------------------------------------------------------------------------------
+ // Add Tab Button
+ _addTabButton->setDefaultAction(actionByName(QL1S("new_tab")));
+ _addTabButton->setAutoRaise(true);
+ _addTabButton->raise();
+ _addTabButton->setToolButtonStyle(Qt::ToolButtonIconOnly);
+
+ connect(this, SIGNAL(currentChanged(int)), this, SLOT(currentChanged(int)));
+
+
// NOTE: we usually create TabWindow with AT LEAST one tab, but
// in one important case...
if (withTab)
@@ -133,6 +151,18 @@ TabWindow::TabWindow(bool withTab, bool PrivateBrowsingMode, QWidget *parent)
}
+KActionCollection *TabWindow::actionCollection() const
+{
+ return _ac;
+}
+
+
+QAction *TabWindow::actionByName(const QString &name)
+{
+ return actionCollection()->action(name);
+}
+
+
TabBar *TabWindow::tabBar() const
{
TabBar *tabBar = qobject_cast<TabBar *>(QTabWidget::tabBar());
@@ -218,9 +248,13 @@ void TabWindow::loadUrl(const KUrl &url, Rekonq::OpenType type, TabHistory *hist
}
-void TabWindow::newCleanTab()
+void TabWindow::newTab()
{
- loadUrl(QUrl("about:home"), Rekonq::NewFocusedTab);
+ WebWindow *tab = prepareNewTab();
+ addTab(tab, i18n("new tab"));
+ setCurrentWidget(tab);
+
+ tab->load(KUrl("about:home"));
}
@@ -256,6 +290,9 @@ void TabWindow::currentChanged(int newIndex)
void TabWindow::updateNewTabButtonPosition()
{
+ if (isFullScreen())
+ return;
+
int tabWidgetWidth = frameSize().width();
int tabBarWidth = tabBar()->sizeHint().width();
@@ -529,6 +566,18 @@ void TabWindow::reloadAllTabs()
}
+void TabWindow::bookmarkAllTabs()
+{
+ KBookmarkGroup rGroup = BookmarkManager::self()->rootGroup();
+ KBookmarkGroup folderGroup = rGroup.createNewFolder( i18n("Bookmarked tabs: ") + QDate::currentDate().toString());
+ for (int i = 0; i < count(); ++i)
+ {
+ WebWindow *tab = webWindow(i);
+ KBookmark bk = folderGroup.addBookmark(tab->title(), tab->url());
+ }
+}
+
+
void TabWindow::restoreLastClosedTab()
{
if (m_recentlyClosedTabs.isEmpty())
@@ -549,7 +598,11 @@ void TabWindow::setFullScreen(bool makeFullScreen)
{
tabBar()->setVisible(!makeFullScreen);
_addTabButton->setVisible(!makeFullScreen);
+
KToggleFullScreenAction::setFullScreen(this, makeFullScreen);
+
+ for(int i = 0; i < count(); i++)
+ webWindow(i)->setWidgetsHidden(makeFullScreen);
}
diff --git a/src/tabwindow/tabwindow.h b/src/tabwindow/tabwindow.h
index 65c3e945..dd938af3 100644
--- a/src/tabwindow/tabwindow.h
+++ b/src/tabwindow/tabwindow.h
@@ -36,6 +36,7 @@
// KDE Includes
#include <KTabWidget>
+#include <KActionCollection>
// Forward Declarations
class KUrl;
@@ -68,9 +69,12 @@ public:
bool isPrivateBrowsingWindowMode();
+ virtual KActionCollection *actionCollection() const;
+ QAction *actionByName(const QString &name);
+
public Q_SLOTS:
void loadUrl(const KUrl &, Rekonq::OpenType type = Rekonq::CurrentTab, TabHistory *history = 0);
- void newCleanTab();
+ void newTab();
private:
/**
@@ -99,7 +103,9 @@ private Q_SLOTS:
void closeOtherTabs(int index = -1);
void detachTab(int index = -1, TabWindow *toWindow = 0);
void reloadTab(int index = -1);
+
void reloadAllTabs();
+ void bookmarkAllTabs();
void restoreLastClosedTab();
@@ -114,6 +120,8 @@ private:
QList<TabHistory> m_recentlyClosedTabs;
bool _isPrivateBrowsing;
+
+ KActionCollection *_ac;
};
#endif // TAB_WINDOW