summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2012-02-05 09:18:04 +0100
committerAndrea Diamantini <adjam7@gmail.com>2012-02-05 09:18:04 +0100
commit2eaf8b2489e834175a67c677521385022422b899 (patch)
tree1ede4db9eec88d3f6194bbb8cf6b22c75ec22504 /src
parentclean up download management (diff)
downloadrekonq-2eaf8b2489e834175a67c677521385022422b899.tar.xz
Make rekonq menu appear inside rekonq's window (as Dolphin does)
BUG:283269
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/mainwindow.cpp6
-rw-r--r--src/mainwindow.h3
-rw-r--r--src/rekonqmenu.cpp96
-rw-r--r--src/rekonqmenu.h61
5 files changed, 165 insertions, 2 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 7f82d28d..82cf6066 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -23,6 +23,7 @@ SET( rekonq_KDEINIT_SRCS
paneltreeview.cpp
previewselectorbar.cpp
protocolhandler.cpp
+ rekonqmenu.cpp
sessionmanager.cpp
sslinfodialog.cpp
tabpreviewpopup.cpp
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index fb5eb0fe..97f4d94e 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -46,6 +46,7 @@
#include "historypanel.h"
#include "iconmanager.h"
#include "mainview.h"
+#include "rekonqmenu.h"
#include "sessionmanager.h"
#include "settingsdialog.h"
#include "stackedurlbar.h"
@@ -555,7 +556,7 @@ void MainWindow::setupTools()
toolsAction->setDelayed(false);
toolsAction->setShortcutConfigurable(true);
toolsAction->setShortcut(KShortcut(Qt::ALT + Qt::Key_T));
- m_rekonqMenu = new KMenu(this);
+ m_rekonqMenu = new RekonqMenu(this);
toolsAction->setMenu(m_rekonqMenu); // dummy menu to have the dropdown arrow
// adding rekonq_tools to rekonq actionCollection
@@ -1526,6 +1527,9 @@ void MainWindow::setupBookmarksAndToolsShortcuts()
if (toolsButton)
{
connect(actionByName(QL1S("rekonq_tools")), SIGNAL(triggered()), toolsButton, SLOT(showMenu()));
+
+ // HACK: set button widget in rekonq menu
+ m_rekonqMenu->setButtonWidget(toolsButton);
}
}
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 0b1380da..789c0c1a 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -45,6 +45,7 @@ class FindBar;
class HistoryPanel;
class MainView;
class NetworkAnalyzerPanel;
+class RekonqMenu;
class WebInspectorPanel;
class WebTab;
class ZoomBar;
@@ -215,7 +216,7 @@ private:
QLabel *m_popup;
QTimer *m_hidePopupTimer;
- KMenu *m_rekonqMenu;
+ RekonqMenu *m_rekonqMenu;
};
#endif // MAINWINDOW_H
diff --git a/src/rekonqmenu.cpp b/src/rekonqmenu.cpp
new file mode 100644
index 00000000..26ea6119
--- /dev/null
+++ b/src/rekonqmenu.cpp
@@ -0,0 +1,96 @@
+/* ============================================================
+*
+* This file is a part of the rekonq project
+*
+* Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com>
+* Copyright (C) 2012 by Andrea Diamantini <adjam7 at gmail dot com>
+*
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License as
+* published by the Free Software Foundation; either version 2 of
+* the License or (at your option) version 3 or any later version
+* accepted by the membership of KDE e.V. (or its successor approved
+* by the membership of KDE e.V.), which shall act as a proxy
+* defined in Section 14 of version 3 of the license.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*
+* ============================================================ */
+
+
+// Self Includes
+#include "rekonqmenu.h"
+#include "rekonqmenu.moc"
+
+// Qt Includes
+#include <QApplication>
+#include <QDesktopWidget>
+#include <QWidget>
+
+
+RekonqMenu::RekonqMenu(QWidget *parent)
+ : KMenu(parent)
+{
+}
+
+
+void RekonqMenu::setButtonWidget(QWidget *w)
+{
+ m_button = w;
+}
+
+
+void RekonqMenu::showEvent(QShowEvent* event)
+{
+ KMenu::showEvent(event);
+
+ // Adjust the position of the menu to be shown within the
+ // rekonq window to reduce the cases that sub-menus might overlap
+ // the right screen border.
+ QPoint pos;
+ if (layoutDirection() == Qt::RightToLeft)
+ {
+ pos = m_button->mapToGlobal(QPoint(0, m_button->height()));
+ }
+ else
+ {
+ pos = m_button->mapToGlobal(QPoint(m_button->width(), m_button->height()));
+ pos.rx() -= width();
+ }
+
+ // Assure that the menu is not shown outside the screen boundaries and
+ // that it does not overlap with the parent button.
+ const QRect screen = QApplication::desktop()->screenGeometry(QCursor::pos());
+ if (pos.x() < screen.x())
+ {
+ pos.rx() = screen.x();
+ }
+ else
+ {
+ if (pos.x() + width() > screen.x() + screen.width())
+ {
+ pos.rx() = screen.x() + screen.width() - width();
+ }
+ }
+
+ if (pos.y() < screen.y())
+ {
+ pos.ry() = screen.y();
+ }
+ else
+ {
+ if (pos.y() + height() > screen.y() + screen.height())
+ {
+ pos.ry() = m_button->mapToGlobal(QPoint(0, 0)).y() + height();
+ }
+ }
+
+ move(pos);
+}
diff --git a/src/rekonqmenu.h b/src/rekonqmenu.h
new file mode 100644
index 00000000..e3d659f7
--- /dev/null
+++ b/src/rekonqmenu.h
@@ -0,0 +1,61 @@
+/* ============================================================
+*
+* This file is a part of the rekonq project
+*
+* Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com>
+* Copyright (C) 2012 by Andrea Diamantini <adjam7 at gmail dot com>
+*
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License as
+* published by the Free Software Foundation; either version 2 of
+* the License or (at your option) version 3 or any later version
+* accepted by the membership of KDE e.V. (or its successor approved
+* by the membership of KDE e.V.), which shall act as a proxy
+* defined in Section 14 of version 3 of the license.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*
+* ============================================================ */
+
+
+
+#ifndef REKONQ_MENU_H
+#define REKONQ_MENU_H
+
+
+// Rekonq Includes
+#include "rekonq_defines.h"
+
+// KDE Includes
+#include <KMenu>
+
+
+/**
+ * Menu shown inside rekonq window.
+ * Inspired by Dolphin solution.
+ *
+ */
+class REKONQ_TESTS_EXPORT RekonqMenu : public KMenu
+{
+ Q_OBJECT
+
+public:
+ RekonqMenu(QWidget *parent);
+
+ void setButtonWidget(QWidget *);
+
+protected:
+ virtual void showEvent(QShowEvent* event);
+
+private:
+ QWidget *m_button;
+};
+
+#endif // REKONQ_MENU_H