summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/mainview.cpp96
-rw-r--r--src/mainview.h12
-rw-r--r--src/mainwindow.cpp4
-rw-r--r--src/tabbar.cpp58
-rw-r--r--src/tabbar.h8
-rw-r--r--src/webpage.cpp49
-rw-r--r--src/webpage.h17
8 files changed, 118 insertions, 127 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4faece61..279d9519 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -64,7 +64,6 @@ TARGET_LINK_LIBRARIES ( rekonq
${QT_LIBRARIES}
${QT_QTNETWORK_LIBRARY}
${QT_QTWEBKIT_LIBRARY}
- ${QT_QTUITOOLS_LIBRARY}
${KDE4_KUTILS_LIBS}
${KDE4_KDEUI_LIBS}
${KDE4_KIO_LIBS}
diff --git a/src/mainview.cpp b/src/mainview.cpp
index 0956e3ff..04ede24c 100644
--- a/src/mainview.cpp
+++ b/src/mainview.cpp
@@ -68,6 +68,7 @@ MainView::MainView(QWidget *parent)
: KTabWidget(parent)
, m_urlBar(new UrlBar(this))
, m_tabBar(new TabBar(this))
+ , m_addTabButton(new QToolButton(this))
, m_currentTabIndex(0)
{
// setting tabbar
@@ -97,13 +98,82 @@ MainView::MainView(QWidget *parent)
// current page index changing
connect(this, SIGNAL(currentChanged(int)), this, SLOT(slotCurrentChanged(int)));
+ QTimer::singleShot(0, this, SLOT(postLaunch()));
+}
+
+
+MainView::~MainView()
+{
+}
+
+
+void MainView::postLaunch()
+{
// Session Manager
connect (this, SIGNAL(tabsChanged()), Application::sessionManager(), SLOT(saveSession()));
+
+ // Find the correct MainWindow of this tab button
+ MainWindowList list = Application::instance()->mainWindowList();
+ Q_FOREACH(QPointer<MainWindow> w, list)
+ {
+ if (w->isAncestorOf(this))
+ {
+ m_addTabButton->setDefaultAction(w->actionByName("new_tab"));
+ break;
+ }
+ }
+
+ m_addTabButton->setAutoRaise(true);
+ m_addTabButton->setToolButtonStyle(Qt::ToolButtonIconOnly);
}
-MainView::~MainView()
+void MainView::updateTabButtonPosition()
{
+ kDebug() << "updating new tab button position..";
+
+ static bool ButtonInCorner = false;
+
+ int tabWidgetWidth = frameSize().width();
+ int tabBarWidth = m_tabBar->tabSizeHint(0).width()*m_tabBar->count();
+
+ if (tabBarWidth + m_addTabButton->width() > tabWidgetWidth)
+ {
+ if(ButtonInCorner)
+ return;
+ setCornerWidget(m_addTabButton);
+ ButtonInCorner = true;
+ }
+ else
+ {
+ if(ButtonInCorner)
+ {
+ setCornerWidget(0);
+ m_addTabButton->show();
+ ButtonInCorner = false;
+ }
+
+ // detecting X position
+ int newPosX = tabBarWidth;
+ int tabWidthHint = m_tabBar->tabSizeHint(0).width();
+ if (tabWidthHint < sizeHint().width()/4)
+ newPosX = tabWidgetWidth - m_addTabButton->width();
+
+ // detecting Y position
+ int newPosY = m_tabBar->height() - m_addTabButton->height();
+ if(newPosY < 0)
+ newPosY = 5; // this hardcoded value is used in just ONE situation:
+ // the first time an user changes the "Always Show Tab Bar" settings
+ // try some better fixes, if you can :D
+
+ m_addTabButton->move(newPosX, newPosY);
+ }
+}
+
+
+QToolButton *MainView::addTabButton() const
+{
+ return m_addTabButton;
}
@@ -138,23 +208,25 @@ void MainView::updateTabBar()
if (m_tabBar->isHidden())
{
m_tabBar->show();
+ m_addTabButton->show();
}
- m_tabBar->updateNewTabButton();
+ updateTabButtonPosition();
+ return;
+ }
+
+ if (m_tabBar->count() == 1)
+ {
+ m_tabBar->hide();
+ m_addTabButton->hide();
}
else
{
- if (m_tabBar->count() == 1)
- {
- m_tabBar->hide();
- }
- else
+ if (m_tabBar->isHidden())
{
- if (m_tabBar->isHidden())
- {
- m_tabBar->show();
- }
- m_tabBar->updateNewTabButton();
+ m_tabBar->show();
+ m_addTabButton->show();
}
+ updateTabButtonPosition();
}
}
diff --git a/src/mainview.h b/src/mainview.h
index c2795048..f0fe183d 100644
--- a/src/mainview.h
+++ b/src/mainview.h
@@ -39,6 +39,9 @@
// KDE Includes
#include <KTabWidget>
+// Qt Includes
+#include <QtGui/QToolButton>
+
// Forward Declarations
class QUrl;
class QWebFrame;
@@ -78,6 +81,8 @@ public:
*
*/
void updateTabBar();
+
+ QToolButton *addTabButton() const;
void clear();
/**
@@ -137,10 +142,14 @@ private slots:
void windowCloseRequested();
+ void postLaunch();
+
protected:
virtual void resizeEvent(QResizeEvent *event);
private:
+ void updateTabButtonPosition();
+
/**
* This function creates (if not exists) and returns a QLabel
* with a loading QMovie.
@@ -158,6 +167,9 @@ private:
QString m_loadingGitPath;
+ // the new tab button
+ QToolButton *m_addTabButton;
+
int m_currentTabIndex;
QList<HistoryItem> m_recentlyClosedTabs;
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index ff33140b..abf82dbf 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -242,7 +242,7 @@ QSize MainWindow::sizeHint() const
}
-KActionCollection *MainWindow::actionCollection () const
+KActionCollection *MainWindow::actionCollection() const
{
return m_ac;
}
@@ -462,7 +462,7 @@ void MainWindow::setupSidePanel()
void MainWindow::slotUpdateConfiguration()
{
// ============== General ==================
- mainView()->updateTabBar();
+ m_view->updateTabBar();
// =========== Fonts ==============
QWebSettings *defaultSettings = QWebSettings::globalSettings();
diff --git a/src/tabbar.cpp b/src/tabbar.cpp
index 65a65f7e..b92c938a 100644
--- a/src/tabbar.cpp
+++ b/src/tabbar.cpp
@@ -64,7 +64,6 @@
TabBar::TabBar(MainView *parent)
: KTabBar(parent)
, m_parent(parent)
- , m_addTabButton(new QToolButton(this))
, m_currentTabPreview(-1)
{
setElideMode(Qt::ElideRight);
@@ -77,8 +76,6 @@ TabBar::TabBar(MainView *parent)
connect(this, SIGNAL(contextMenu(int, const QPoint &)), this, SLOT(slotContextMenuRequested(int, const QPoint &)));
connect(this, SIGNAL(emptyAreaContextMenu(const QPoint &)), this, SLOT(slotEmptyAreaContextMenu(const QPoint &)));
-
- QTimer::singleShot(0, this, SLOT(postLaunch()));
}
@@ -87,27 +84,9 @@ TabBar::~TabBar()
}
-void TabBar::postLaunch()
-{
- // Find the correct MainWindow of this tab button
- MainWindowList list = Application::instance()->mainWindowList();
- Q_FOREACH(QPointer<MainWindow> w, list)
- {
- if (w->isAncestorOf(this))
- {
- m_addTabButton->setDefaultAction(w->actionByName("new_tab"));
- break;
- }
- }
-
- m_addTabButton->setAutoRaise(true);
- m_addTabButton->setToolButtonStyle(Qt::ToolButtonIconOnly);
-}
-
-
QSize TabBar::tabSizeHint(int index) const
{
- int buttonSize = m_addTabButton->size().width();
+ int buttonSize = m_parent->addTabButton()->size().width();
int tabBarWidth = m_parent->size().width() - buttonSize;
int baseWidth = m_parent->sizeHint().width()/BASE_WIDTH_DIVISOR;
int minWidth = m_parent->sizeHint().width()/MIN_WIDTH_DIVISOR;
@@ -243,6 +222,7 @@ void TabBar::leaveEvent(QEvent *event)
KTabBar::leaveEvent(event);
}
+
void TabBar::mousePressEvent(QMouseEvent *event)
{
// just close tab on middle mouse click
@@ -253,40 +233,6 @@ void TabBar::mousePressEvent(QMouseEvent *event)
}
-void TabBar::updateNewTabButton()
-{
- static bool ButtonInCorner = false;
-
- int tabWidgetWidth = m_parent->frameSize().width();
- int tabBarWidth = tabSizeHint(0).width() * count();
-
- if (tabBarWidth + m_addTabButton->width() > tabWidgetWidth)
- {
- if(ButtonInCorner)
- return;
- m_parent->setCornerWidget(m_addTabButton);
- ButtonInCorner = true;
- }
- else
- {
- if(ButtonInCorner)
- {
- m_parent->setCornerWidget(0);
- m_addTabButton->show();
- ButtonInCorner = false;
- }
-
- int newPosX = tabWidgetWidth - m_addTabButton->width();
- int newPosY = height() - m_addTabButton->height();
-
- if (tabBarWidth + m_addTabButton->width() < tabWidgetWidth)
- newPosX = tabBarWidth;
-
- m_addTabButton->move(newPosX, newPosY);
- }
-}
-
-
void TabBar::slotContextMenuRequested(int tab, const QPoint &pos)
{
m_actualIndex = tab;
diff --git a/src/tabbar.h b/src/tabbar.h
index f68528b8..1601b3b6 100644
--- a/src/tabbar.h
+++ b/src/tabbar.h
@@ -42,7 +42,6 @@
// Forward Declarations
class QPoint;
-class QToolButton;
class QMouseEvent;
class QEvent;
@@ -63,7 +62,6 @@ public:
~TabBar();
void showTabPreview(int tab);
- void updateNewTabButton();
signals:
void cloneTab(int index);
@@ -77,6 +75,7 @@ protected:
* Added to fix tab dimension
*/
virtual QSize tabSizeHint(int index) const;
+
virtual void mouseMoveEvent(QMouseEvent *event);
virtual void leaveEvent(QEvent *event);
virtual void mousePressEvent(QMouseEvent *event);
@@ -87,14 +86,13 @@ private slots:
void closeOtherTabs();
void reloadTab();
- void postLaunch();
-
void slotContextMenuRequested(int, const QPoint &);
void slotEmptyAreaContextMenu(const QPoint &);
private:
+ friend class MainView;
+
MainView *m_parent;
- QToolButton *m_addTabButton;
/**
* the index in which we are seeing a Context menu
diff --git a/src/webpage.cpp b/src/webpage.cpp
index 3754444b..01e98dfd 100644
--- a/src/webpage.cpp
+++ b/src/webpage.cpp
@@ -49,12 +49,12 @@
#include <KUrl>
#include <KDebug>
#include <KToolInvocation>
+#include <KProtocolManager>
#include <KDE/KParts/BrowserRun>
#include <KDE/KMimeTypeTrader>
#include <KDE/KRun>
#include <KDE/KFileDialog>
-#include <KDE/KInputDialog>
#include <KDE/KMessageBox>
#include <KDE/KJobUiDelegate>
@@ -65,8 +65,6 @@
#include <QtGui/QClipboard>
#include <QtGui/QKeyEvent>
-#include <QtUiTools/QUiLoader>
-
WebPage::WebPage(QObject *parent)
: QWebPage(parent)
@@ -264,39 +262,6 @@ QString WebPage::errorPage(QNetworkReply *reply)
}
-void WebPage::javaScriptAlert(QWebFrame *frame, const QString &msg)
-{
- KMessageBox::error(frame->page()->view(), msg, i18n("JavaScript"));
-}
-
-
-bool WebPage::javaScriptConfirm(QWebFrame *frame, const QString &msg)
-{
- return (KMessageBox::warningYesNo(frame->page()->view(), msg, i18n("JavaScript"), KStandardGuiItem::ok(), KStandardGuiItem::cancel())
- == KMessageBox::Yes);
-}
-
-
-bool WebPage::javaScriptPrompt(QWebFrame *frame, const QString &msg, const QString &defaultValue, QString *result)
-{
- bool ok = false;
- *result = KInputDialog::getText(i18n("JavaScript"), msg, defaultValue, &ok, frame->page()->view());
- return ok;
-}
-
-
-QObject *WebPage::createPlugin(const QString &classId, const QUrl &url, const QStringList &paramNames, const QStringList &paramValues)
-{
- kDebug() << "create Plugin requested:";
- kDebug() << "classid:" << classId;
- kDebug() << "url:" << url;
- kDebug() << "paramNames:" << paramNames << " paramValues:" << paramValues;
-
- QUiLoader loader;
- return loader.createWidget(classId, view());
-}
-
-
// TODO FIXME: sometimes url.fileName() fails to retrieve url file name
void WebPage::slotDownloadRequested(const QNetworkRequest &request)
{
@@ -310,3 +275,15 @@ void WebPage::slotDownloadRequested(const QNetworkRequest &request)
job->addMetaData("cache", "cache"); // Use entry from cache if available.
job->uiDelegate()->setAutoErrorHandlingEnabled(true);
}
+
+
+QString WebPage::userAgentForUrl(const QUrl& _url) const
+{
+ const KUrl url(_url);
+ QString userAgent = KProtocolManager::userAgentForHost((url.isLocalFile() ? "localhost" : url.host()));
+
+ if (userAgent == KProtocolManager::defaultUserAgent())
+ return QWebPage::userAgentForUrl(_url);
+
+ return userAgent;
+}
diff --git a/src/webpage.h b/src/webpage.h
index 86024a9d..0d9868b9 100644
--- a/src/webpage.h
+++ b/src/webpage.h
@@ -60,22 +60,9 @@ protected:
virtual bool acceptNavigationRequest(QWebFrame *frame,
const QNetworkRequest &request,
NavigationType type);
+
+ virtual QString userAgentForUrl(const QUrl& url) const;
- void javaScriptAlert(QWebFrame *frame,
- const QString &msg);
-
- bool javaScriptConfirm(QWebFrame *frame,
- const QString &msg);
-
- bool javaScriptPrompt(QWebFrame *frame,
- const QString &msg,
- const QString &defaultValue, QString *result);
-
- QObject *createPlugin(const QString &classId,
- const QUrl &url,
- const QStringList &paramNames,
- const QStringList &paramValues);
-
protected Q_SLOTS:
virtual void slotHandleUnsupportedContent(QNetworkReply *reply);
virtual void slotDownloadRequested(const QNetworkRequest &request);