diff options
Diffstat (limited to 'src/tabwindow')
-rw-r--r-- | src/tabwindow/rekonqwindow.cpp | 461 | ||||
-rw-r--r-- | src/tabwindow/rekonqwindow.h | 130 | ||||
-rw-r--r-- | src/tabwindow/rwindow.cpp | 397 | ||||
-rw-r--r-- | src/tabwindow/rwindow.h | 131 | ||||
-rw-r--r-- | src/tabwindow/tabbar.cpp | 19 | ||||
-rw-r--r-- | src/tabwindow/tabwidget.cpp (renamed from src/tabwindow/tabwindow.cpp) | 219 | ||||
-rw-r--r-- | src/tabwindow/tabwidget.h (renamed from src/tabwindow/tabwindow.h) | 26 |
7 files changed, 837 insertions, 546 deletions
diff --git a/src/tabwindow/rekonqwindow.cpp b/src/tabwindow/rekonqwindow.cpp index ee37eba9..a14dcf15 100644 --- a/src/tabwindow/rekonqwindow.cpp +++ b/src/tabwindow/rekonqwindow.cpp @@ -2,7 +2,7 @@ * * This file is a part of the rekonq project * -* Copyright (C) 2012 by Andrea Diamantini <adjam7 at gmail dot com> +* Copyright (C) 2013 by Andrea Diamantini <adjam7 at gmail dot com> * * * This program is free software; you can redistribute it and/or @@ -27,422 +27,163 @@ // Self Includes #include "rekonqwindow.h" #include "rekonqwindow.moc" -#include <rekonq.h> - -// KDE Includes -#include <KApplication> -#include <KCmdLineArgs> -#include <KSessionManager> - -// Qt Includes -#include <QCloseEvent> -#include <QDesktopWidget> - - -static bool s_no_query_exit = false; - - -class KRWSessionManager : public KSessionManager -{ - -public: - KRWSessionManager() - { - } - - ~KRWSessionManager() - { - } - - bool dummyInit() - { - return true; - } - - bool saveState(QSessionManager&) - { - KConfig* config = KApplication::kApplication()->sessionConfig(); - int n = 0; - Q_FOREACH(RekonqWindow * rw, RekonqWindow::windowList()) - { - n++; - rw->savePropertiesInternal(config, n); - } - - KConfigGroup group(config, "Number"); - group.writeEntry("NumberOfWindows", n); - return true; - } - - bool commitData(QSessionManager& sm) - { - // not really a fast method but the only compatible one - if (sm.allowsInteraction()) - { - bool canceled = false; - ::s_no_query_exit = true; - - Q_FOREACH(RekonqWindow * window, RekonqWindow::windowList()) - { - if (!window->testAttribute(Qt::WA_WState_Hidden)) - { - QCloseEvent e; - QApplication::sendEvent(window, &e); - canceled = !e.isAccepted(); - if (canceled) - break; - } - } - ::s_no_query_exit = false; - if (canceled) - return false; - - return true; - } - - // the user wants it, the user gets it - return true; - } -}; +// Auto Includes +#include "rekonq.h" -K_GLOBAL_STATIC(KRWSessionManager, ktwsm) -K_GLOBAL_STATIC(QList<RekonqWindow*>, sWindowList) +// Local Includes +#include "application.h" +#include "tabwidget.h" +#include "tabbar.h" -// ---------------------------------------------------------------------------------------------------- +#include "webpage.h" +#include "webwindow.h" +// KDE Includes +#include <KUrl> +#include <KLocalizedString> -RekonqWindow::RekonqWindow(QWidget* parent) - : KTabWidget(parent) -{ - // This has to be a window... - setWindowFlags(Qt::Window); - - // Setting attributes (just to be sure...) - setAttribute(Qt::WA_DeleteOnClose, true); - setAttribute(Qt::WA_QuitOnClose, true); - - ktwsm->dummyInit(); - sWindowList->append(this); - - QString geometry; - KCmdLineArgs *args = KCmdLineArgs::parsedArgs("kde"); - if (args && args->isSet("geometry")) - geometry = args->getOption("geometry"); - - if (geometry.isNull()) // if there is no geometry, it doesn't matter - { - KSharedConfig::Ptr cf = KGlobal::config(); - KConfigGroup cg(cf, QL1S("TabWindow")); - restoreWindowSize(cg); - } - else - { - parseGeometry(); - } - - setWindowTitle(KGlobal::caption()); -} - - -RekonqWindow::~RekonqWindow() -{ - sWindowList->removeAll(this); - - KSharedConfig::Ptr cf = KGlobal::config(); - KConfigGroup cg(cf, QL1S("TabWindow")); - saveWindowSize(cg); -} - +// Qt Includes +#include <QVBoxLayout> +#include <QSizePolicy> -QSize RekonqWindow::sizeHint() const -{ - QRect desktopRect = QApplication::desktop()->screenGeometry(); - QSize size = desktopRect.size() * 0.8; - return size; -} -QList<RekonqWindow*> RekonqWindow::windowList() +RekonqWindow::RekonqWindow(bool withTab, bool privateBrowsingMode, QWidget *parent) + : RWindow(parent) + , _tabWidget(new TabWidget(withTab, privateBrowsingMode, this)) + , _splitter(new QSplitter(this)) { - return *sWindowList; + init(); } -void RekonqWindow::savePropertiesInternal(KConfig *config, int number) +RekonqWindow::RekonqWindow(WebPage *pg, QWidget *parent) + : RWindow(parent) + , _tabWidget(new TabWidget(pg, this)) + , _splitter(new QSplitter(this)) { - QString s; - s.setNum(number); - s.prepend(QL1S("WindowProperties")); - KConfigGroup cg(config, s); - - // store objectName, className, Width and Height for later restoring - // (Only useful for session management) - cg.writeEntry(QL1S("ObjectName"), objectName()); - cg.writeEntry(QL1S("ClassName"), metaObject()->className()); - - saveWindowSize(cg); - - s.setNum(number); - cg = KConfigGroup(config, s); - saveProperties(cg); + init(); } -bool RekonqWindow::readPropertiesInternal(KConfig *config, int number) +RekonqWindow::~RekonqWindow() { - // in order they are in toolbar list - QString s; - s.setNum(number); - s.prepend(QL1S("WindowProperties")); - - KConfigGroup cg(config, s); - - // restore the object name (window role) - if (cg.hasKey(QL1S("ObjectName"))) - setObjectName(cg.readEntry("ObjectName").toLatin1()); // latin1 is right here - - restoreWindowSize(cg); - - s.setNum(number); - KConfigGroup grp(config, s); - readProperties(grp); - - return true; } -void RekonqWindow::restoreWindowSize(const KConfigGroup & _cg) +void RekonqWindow::init() { - int scnum = QApplication::desktop()->screenNumber(window()); - QRect desktopRect = QApplication::desktop()->screenGeometry(scnum); + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - KConfigGroup cg(_cg); + QVBoxLayout *l = new QVBoxLayout(this); + l->setMargin(0); + l->setSpacing(0); - QString geometryKey = QString::fromLatin1("geometry-%1-%2").arg(desktopRect.width()).arg(desktopRect.height()); - QByteArray geometry = cg.readEntry(geometryKey, QByteArray()); + if (ReKonfig::showBookmarksPanel()) + showBookmarksPanel(true); + + if (ReKonfig::showHistoryPanel()) + showHistoryPanel(true); - // if first time run, center window: resize && move.. - if (!restoreGeometry(QByteArray::fromBase64(geometry))) - { - QSize defaultSize = desktopRect.size() * 0.8; - resize(defaultSize); + _splitter->addWidget(_tabWidget); + _tabWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - move((desktopRect.width() - width()) / 2, (desktopRect.height() - height()) / 2); - } + l->addWidget(_splitter); - checkPosition(); + + // fix focus handling + setFocusProxy(_tabWidget); } - -void RekonqWindow::saveWindowSize(const KConfigGroup & _cg) const -{ - int scnum = QApplication::desktop()->screenNumber(window()); - QRect desktopRect = QApplication::desktop()->screenGeometry(scnum); - - int w, h; - if (isMaximized()) - { - w = desktopRect.width() + 1; - h = desktopRect.height() + 1; - } - else - { - w = width(); - h = height(); - } - - KConfigGroup cg(_cg); - - QString widthString = QString::fromLatin1("Width %1").arg(desktopRect.width()); - cg.writeEntry(widthString, w); - - QString heightString = QString::fromLatin1("Height %1").arg(desktopRect.height()); - cg.writeEntry(heightString, h); - - // geometry is saved separately for each resolution - QString geometryKey = QString::fromLatin1("geometry-%1-%2").arg(desktopRect.width()).arg(desktopRect.height()); - QByteArray geometry = saveGeometry(); - cg.writeEntry(geometryKey, geometry.toBase64()); -} +// -------------------------------------------------------------------------------------------------- -void RekonqWindow::parseGeometry() +TabWidget *RekonqWindow::tabWidget() { - QString cmdlineGeometry; - KCmdLineArgs *args = KCmdLineArgs::parsedArgs("kde"); - if (args->isSet("geometry")) - cmdlineGeometry = args->getOption("geometry"); - - Q_ASSERT(!cmdlineGeometry.isNull()); - -// #if defined Q_WS_X11 -// int x, y; -// int w, h; -// int m = XParseGeometry( cmdlineGeometry.toLatin1(), &x, &y, (unsigned int*)&w, (unsigned int*)&h); -// if (parsewidth) { -// const QSize minSize = minimumSize(); -// const QSize maxSize = maximumSize(); -// if ( !(m & WidthValue) ) -// w = width(); -// if ( !(m & HeightValue) ) -// h = height(); -// w = qMin(w,maxSize.width()); -// h = qMin(h,maxSize.height()); -// w = qMax(w,minSize.width()); -// h = qMax(h,minSize.height()); -// resize(w, h); -// } else { -// if ( (m & XNegative) ) -// x = KApplication::desktop()->width() + x - w; -// else if ( (m & XValue) ) -// x = geometry().x(); -// if ( (m & YNegative) ) -// y = KApplication::desktop()->height() + y - h; -// else if ( (m & YValue) ) -// y = geometry().y(); -// -// move(x, y); -// } -// #endif + return _tabWidget; } -void RekonqWindow::resizeEvent(QResizeEvent *event) +TabBar *RekonqWindow::tabBar() { - if (!isFullScreen()) - saveAutoSaveSettings(); - KTabWidget::resizeEvent(event); + return _tabWidget->tabBar(); } -void RekonqWindow::saveAutoSaveSettings() +WebWindow *RekonqWindow::currentWebWindow() const { - kDebug() << "AUTO SAVING SETTINGS..."; - - KSharedConfig::Ptr cf = KGlobal::config(); - KConfigGroup cg(cf, QL1S("TabWindow")); - saveWindowSize(cg); + return _tabWidget->currentWebWindow(); } -bool RekonqWindow::canBeRestored(int number) -{ - if (!qApp->isSessionRestored()) - return false; - KConfig *config = kapp->sessionConfig(); - if (!config) - return false; - - KConfigGroup group(config, "Number"); - const int n = group.readEntry("NumberOfWindows", 1); - return number >= 1 && number <= n; -} +// -------------------------------------------------------------------------------------------------- -bool RekonqWindow::restore(int number, bool show) +void RekonqWindow::loadUrl(const KUrl &url, Rekonq::OpenType type, TabHistory *history) { - if (!canBeRestored(number)) - return false; - KConfig *config = kapp->sessionConfig(); - if (readPropertiesInternal(config, number)) + switch (type) { - if (show) - RekonqWindow::show(); - return true; - } - return false; -} - - -// NOTE: For internal purpose only ------------------------------------------------------ - - -int RekonqWindow::addTab(QWidget *page, const QString &label) -{ - setUpdatesEnabled(false); - int i = KTabWidget::addTab(page, label); - setUpdatesEnabled(true); - - return i; -} - - -int RekonqWindow::addTab(QWidget *page, const QIcon &icon, const QString &label) -{ - setUpdatesEnabled(false); - int i = KTabWidget::addTab(page, icon, label); - setUpdatesEnabled(true); - - return i; -} - - -int RekonqWindow::insertTab(int index, QWidget *page, const QString &label) -{ - if (! ReKonfig::openNewTabsNextToCurrent()) - index = -1; - setUpdatesEnabled(false); - int i = KTabWidget::insertTab(index, page, label); - setUpdatesEnabled(true); + case Rekonq::NewWindow: + case Rekonq::NewPrivateWindow: + rApp->loadUrl(url, type); + return; - return i; + case Rekonq::NewTab: + case Rekonq::NewBackGroundTab: + case Rekonq::NewFocusedTab: + case Rekonq::CurrentTab: + default: + _tabWidget->loadUrl(url, type, history); + break; + }; } -int RekonqWindow::insertTab(int index, QWidget *page, const QIcon &icon, const QString &label) +void RekonqWindow::showBookmarksPanel(bool on) { - if (! ReKonfig::openNewTabsNextToCurrent()) - index = -1; - setUpdatesEnabled(false); - int i = KTabWidget::insertTab(index, page, icon, label); - setUpdatesEnabled(true); + if (on) + { + if (_bookmarksPanel.isNull()) + { + _bookmarksPanel = new BookmarksPanel(i18n("Bookmarks Panel"), this); + connect(_bookmarksPanel.data(), SIGNAL(openUrl(KUrl, Rekonq::OpenType)), this, SLOT(loadUrl(KUrl, Rekonq::OpenType))); - return i; + QAction *a = _tabWidget->actionByName(QL1S("show_bookmarks_panel")); + connect(_bookmarksPanel.data(), SIGNAL(visibilityChanged(bool)), a, SLOT(setChecked(bool))); + } + _splitter->insertWidget(0, _bookmarksPanel.data()); + _bookmarksPanel.data()->show(); + } + else + { + _bookmarksPanel.data()->hide(); + delete _bookmarksPanel.data(); + _bookmarksPanel.clear(); + } } -// -------------------------------------------------------------------------------------- - - -void RekonqWindow::checkPosition() +void RekonqWindow::showHistoryPanel(bool on) { - // no need to check trivial positions... - if (isMaximized()) - return; - - QList<RekonqWindow*> wList = RekonqWindow::windowList(); - int wNumber = wList.count(); - - // no need to check first window... - if (wNumber <= 1) - return; - - int div = wNumber % 4; - - int scnum = QApplication::desktop()->screenNumber(window()); - QRect desktopRect = QApplication::desktop()->screenGeometry(scnum); + if (on) + { + if (_historyPanel.isNull()) + { + _historyPanel = new HistoryPanel(i18n("History Panel"), this); + connect(_historyPanel.data(), SIGNAL(openUrl(KUrl, Rekonq::OpenType)), this, SLOT(loadUrl(KUrl, Rekonq::OpenType))); + + QAction *a = _tabWidget->actionByName(QL1S("show_history_panel")); + connect(_historyPanel.data(), SIGNAL(visibilityChanged(bool)), a, SLOT(setChecked(bool))); - switch (div) + } + _splitter->insertWidget(0, _historyPanel.data()); + _historyPanel.data()->show(); + } + else { - case 2: - // left down - move(desktopRect.width() - width(), desktopRect.height() - height()); - break; - case 3: - // right down - move(0, desktopRect.height() - height()); - break; - case 0: - // left top - move(desktopRect.width() - width(), 0); - break; - case 1: - // right top - move(0, 0); - break; - default: - kDebug() << "OOPS...THIS SHOULD NEVER HAPPEN!!"; - break; + _historyPanel.data()->hide(); + delete _historyPanel.data(); + _historyPanel.clear(); } } diff --git a/src/tabwindow/rekonqwindow.h b/src/tabwindow/rekonqwindow.h index ed018e4a..1d46faeb 100644 --- a/src/tabwindow/rekonqwindow.h +++ b/src/tabwindow/rekonqwindow.h @@ -2,7 +2,7 @@ * * This file is a part of the rekonq project * -* Copyright (C) 2012 by Andrea Diamantini <adjam7 at gmail dot com> +* Copyright (C) 2013 by Andrea Diamantini <adjam7 at gmail dot com> * * * This program is free software; you can redistribute it and/or @@ -32,109 +32,55 @@ // Rekonq Includes #include "rekonq_defines.h" -// KDE Includes -#include <KTabWidget> -#include <KConfig> -#include <KConfigGroup> +// Local Includes +#include "rwindow.h" +#include "tabwidget.h" + +#include "bookmarkspanel.h" +#include "historypanel.h" // Qt Includes -#include <QTimer> - -/** - * This is rekonq (re)implementation of KMainWindow, - * given that we'd like to NOT use a "real" xMainWindow - * but a widget with the nice mainwindow properties - * (eg: session management, auto save dimension, etc) but - * NOT its peculiar containers (eg: toolbars, menubar, statusbar, - * central widget...) - * - */ -class RekonqWindow : public KTabWidget -{ - friend class KRWSessionManager; +#include <QSplitter> +#include <QWeakPointer> + +// Forward Declarations +class TabBar; + +class WebPage; +class WebWindow; + +class RekonqWindow : public RWindow +{ Q_OBJECT public: - explicit RekonqWindow(QWidget* parent = 0); + explicit RekonqWindow(bool withTab = true, bool PrivateBrowsingMode = false, QWidget *parent = 0); + explicit RekonqWindow(WebPage *pg, QWidget *parent = 0); virtual ~RekonqWindow(); - QSize sizeHint() const; - - /** - * List of members of RekonqWindow class. - */ - static QList<RekonqWindow*> windowList(); - - /** - * If the session did contain so high a @p number, @p true is returned, - * else @p false. - * @see restore() - **/ - static bool canBeRestored(int number); - - /** - * Try to restore the toplevel widget as defined by @p number (1..X). - * - * You should call canBeRestored() first. - * - **/ - bool restore(int number, bool show = true); - - // NOTE: For internal purpose only ------------------------------------------------------ - int addTab(QWidget *page, const QString &label); - int addTab(QWidget *page, const QIcon &icon, const QString &label); - - int insertTab(int index, QWidget *page, const QString &label); - int insertTab(int index, QWidget *page, const QIcon &icon, const QString &label); - // -------------------------------------------------------------------------------------- - -protected: - /** - * Save your instance-specific properties. The function is - * invoked when the session manager requests your application - * to save its state. - * - * Please reimplement these function in childclasses. - * - * Note: No user interaction is allowed - * in this function! - * - */ - virtual void saveProperties(KConfigGroup &) {} - - /** - * Read your instance-specific properties. - * - * Is called indirectly by restore(). - */ - virtual void readProperties(const KConfigGroup &) {} - - void savePropertiesInternal(KConfig*, int); - bool readPropertiesInternal(KConfig*, int); - - /** - * For inherited classes - */ - void saveWindowSize(const KConfigGroup &config) const; - /** - * For inherited classes - * Note that a -geometry on the command line has priority. - */ - void restoreWindowSize(const KConfigGroup & config); - - /// parse the geometry from the geometry command line argument - void parseGeometry(); - - virtual void resizeEvent(QResizeEvent *); + TabWidget *tabWidget(); + TabBar *tabBar(); + WebWindow *currentWebWindow() const; -private Q_SLOTS: - void saveAutoSaveSettings(); +private: + void init(); + +public Q_SLOTS: + void loadUrl(const KUrl &, Rekonq::OpenType type = Rekonq::CurrentTab, TabHistory *history = 0); +private Q_SLOTS: + void showBookmarksPanel(bool); + void showHistoryPanel(bool); + private: - /// This has been added to just fix window position && not let them be overlying - void checkPosition(); + TabWidget *_tabWidget; + + QSplitter *_splitter; + + QWeakPointer<HistoryPanel> _historyPanel; + QWeakPointer<BookmarksPanel> _bookmarksPanel; }; #endif // REKONQ_WINDOW_H diff --git a/src/tabwindow/rwindow.cpp b/src/tabwindow/rwindow.cpp new file mode 100644 index 00000000..f7304da5 --- /dev/null +++ b/src/tabwindow/rwindow.cpp @@ -0,0 +1,397 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2012-2013 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 "rwindow.h" +#include "rwindow.moc" + +// KDE Includes +#include <KApplication> +#include <KCmdLineArgs> +#include <KSessionManager> + +// Qt Includes +#include <QCloseEvent> +#include <QDesktopWidget> + + +static bool s_no_query_exit = false; + + +class KRWSessionManager : public KSessionManager +{ + +public: + KRWSessionManager() + { + } + + ~KRWSessionManager() + { + } + + bool dummyInit() + { + return true; + } + + bool saveState(QSessionManager&) + { + KConfig* config = KApplication::kApplication()->sessionConfig(); + int n = 0; + Q_FOREACH(RWindow * rw, RWindow::windowList()) + { + n++; + rw->savePropertiesInternal(config, n); + } + + KConfigGroup group(config, "Number"); + group.writeEntry("NumberOfWindows", n); + return true; + } + + bool commitData(QSessionManager& sm) + { + // not really a fast method but the only compatible one + if (sm.allowsInteraction()) + { + bool canceled = false; + ::s_no_query_exit = true; + + Q_FOREACH(RWindow * window, RWindow::windowList()) + { + if (!window->testAttribute(Qt::WA_WState_Hidden)) + { + QCloseEvent e; + QApplication::sendEvent(window, &e); + canceled = !e.isAccepted(); + if (canceled) + break; + } + } + ::s_no_query_exit = false; + if (canceled) + return false; + + return true; + } + + // the user wants it, the user gets it + return true; + } +}; + + +K_GLOBAL_STATIC(KRWSessionManager, ktwsm) +K_GLOBAL_STATIC(QList<RWindow*>, sWindowList) + + +// ---------------------------------------------------------------------------------------------------- + + +RWindow::RWindow(QWidget* parent) + : QWidget(parent) +{ + // This has to be a window... + setWindowFlags(Qt::Window); + + // Setting attributes (just to be sure...) + setAttribute(Qt::WA_DeleteOnClose, true); + setAttribute(Qt::WA_QuitOnClose, true); + + ktwsm->dummyInit(); + sWindowList->append(this); + + QString geometry; + KCmdLineArgs *args = KCmdLineArgs::parsedArgs("kde"); + if (args && args->isSet("geometry")) + geometry = args->getOption("geometry"); + + if (geometry.isNull()) // if there is no geometry, it doesn't matter + { + KSharedConfig::Ptr cf = KGlobal::config(); + KConfigGroup cg(cf, QL1S("RekonqWindow")); + restoreWindowSize(cg); + } + else + { + parseGeometry(); + } + + setWindowTitle(KGlobal::caption()); +} + + +RWindow::~RWindow() +{ + sWindowList->removeAll(this); + + KSharedConfig::Ptr cf = KGlobal::config(); + KConfigGroup cg(cf, QL1S("RekonqWindow")); + saveWindowSize(cg); +} + + +QSize RWindow::sizeHint() const +{ + QRect desktopRect = QApplication::desktop()->screenGeometry(); + QSize size = desktopRect.size() * 0.8; + return size; +} + +QList<RWindow*> RWindow::windowList() +{ + return *sWindowList; +} + + +void RWindow::savePropertiesInternal(KConfig *config, int number) +{ + QString s; + s.setNum(number); + s.prepend(QL1S("WindowProperties")); + KConfigGroup cg(config, s); + + // store objectName, className, Width and Height for later restoring + // (Only useful for session management) + cg.writeEntry(QL1S("ObjectName"), objectName()); + cg.writeEntry(QL1S("ClassName"), metaObject()->className()); + + saveWindowSize(cg); + + s.setNum(number); + cg = KConfigGroup(config, s); + saveProperties(cg); +} + + +bool RWindow::readPropertiesInternal(KConfig *config, int number) +{ + // in order they are in toolbar list + QString s; + s.setNum(number); + s.prepend(QL1S("WindowProperties")); + + KConfigGroup cg(config, s); + + // restore the object name (window role) + if (cg.hasKey(QL1S("ObjectName"))) + setObjectName(cg.readEntry("ObjectName").toLatin1()); // latin1 is right here + + restoreWindowSize(cg); + + s.setNum(number); + KConfigGroup grp(config, s); + readProperties(grp); + + return true; +} + + +void RWindow::restoreWindowSize(const KConfigGroup & _cg) +{ + int scnum = QApplication::desktop()->screenNumber(window()); + QRect desktopRect = QApplication::desktop()->screenGeometry(scnum); + + KConfigGroup cg(_cg); + + QString geometryKey = QString::fromLatin1("geometry-%1-%2").arg(desktopRect.width()).arg(desktopRect.height()); + QByteArray geometry = cg.readEntry(geometryKey, QByteArray()); + + // if first time run, center window: resize && move.. + if (!restoreGeometry(QByteArray::fromBase64(geometry))) + { + QSize defaultSize = desktopRect.size() * 0.8; + resize(defaultSize); + + move((desktopRect.width() - width()) / 2, (desktopRect.height() - height()) / 2); + } + + checkPosition(); +} + + +void RWindow::saveWindowSize(const KConfigGroup & _cg) const +{ + int scnum = QApplication::desktop()->screenNumber(window()); + QRect desktopRect = QApplication::desktop()->screenGeometry(scnum); + + int w, h; + if (isMaximized()) + { + w = desktopRect.width() + 1; + h = desktopRect.height() + 1; + } + else + { + w = width(); + h = height(); + } + + KConfigGroup cg(_cg); + + QString widthString = QString::fromLatin1("Width %1").arg(desktopRect.width()); + cg.writeEntry(widthString, w); + + QString heightString = QString::fromLatin1("Height %1").arg(desktopRect.height()); + cg.writeEntry(heightString, h); + + // geometry is saved separately for each resolution + QString geometryKey = QString::fromLatin1("geometry-%1-%2").arg(desktopRect.width()).arg(desktopRect.height()); + QByteArray geometry = saveGeometry(); + cg.writeEntry(geometryKey, geometry.toBase64()); +} + + +void RWindow::parseGeometry() +{ + QString cmdlineGeometry; + KCmdLineArgs *args = KCmdLineArgs::parsedArgs("kde"); + if (args->isSet("geometry")) + cmdlineGeometry = args->getOption("geometry"); + + Q_ASSERT(!cmdlineGeometry.isNull()); + +// #if defined Q_WS_X11 +// int x, y; +// int w, h; +// int m = XParseGeometry( cmdlineGeometry.toLatin1(), &x, &y, (unsigned int*)&w, (unsigned int*)&h); +// if (parsewidth) { +// const QSize minSize = minimumSize(); +// const QSize maxSize = maximumSize(); +// if ( !(m & WidthValue) ) +// w = width(); +// if ( !(m & HeightValue) ) +// h = height(); +// w = qMin(w,maxSize.width()); +// h = qMin(h,maxSize.height()); +// w = qMax(w,minSize.width()); +// h = qMax(h,minSize.height()); +// resize(w, h); +// } else { +// if ( (m & XNegative) ) +// x = KApplication::desktop()->width() + x - w; +// else if ( (m & XValue) ) +// x = geometry().x(); +// if ( (m & YNegative) ) +// y = KApplication::desktop()->height() + y - h; +// else if ( (m & YValue) ) +// y = geometry().y(); +// +// move(x, y); +// } +// #endif +} + + +void RWindow::resizeEvent(QResizeEvent *event) +{ + if (!isFullScreen()) + saveAutoSaveSettings(); + QWidget::resizeEvent(event); +} + + +void RWindow::saveAutoSaveSettings() +{ + kDebug() << "AUTO SAVING SETTINGS..."; + + KSharedConfig::Ptr cf = KGlobal::config(); + KConfigGroup cg(cf, QL1S("RekonqWindow")); + saveWindowSize(cg); +} + + +bool RWindow::canBeRestored(int number) +{ + if (!qApp->isSessionRestored()) + return false; + KConfig *config = kapp->sessionConfig(); + if (!config) + return false; + + KConfigGroup group(config, "Number"); + const int n = group.readEntry("NumberOfWindows", 1); + return number >= 1 && number <= n; +} + + +bool RWindow::restore(int number, bool show) +{ + if (!canBeRestored(number)) + return false; + KConfig *config = kapp->sessionConfig(); + if (readPropertiesInternal(config, number)) + { + if (show) + RWindow::show(); + return true; + } + return false; +} + + +void RWindow::checkPosition() +{ + // no need to check trivial positions... + if (isMaximized()) + return; + + QList<RWindow*> wList = RWindow::windowList(); + int wNumber = wList.count(); + + // no need to check first window... + if (wNumber <= 1) + return; + + int div = wNumber % 4; + + int scnum = QApplication::desktop()->screenNumber(window()); + QRect desktopRect = QApplication::desktop()->screenGeometry(scnum); + + switch (div) + { + case 2: + // left down + move(desktopRect.width() - width(), desktopRect.height() - height()); + break; + case 3: + // right down + move(0, desktopRect.height() - height()); + break; + case 0: + // left top + move(desktopRect.width() - width(), 0); + break; + case 1: + // right top + move(0, 0); + break; + default: + kDebug() << "OOPS...THIS SHOULD NEVER HAPPEN!!"; + break; + } +} diff --git a/src/tabwindow/rwindow.h b/src/tabwindow/rwindow.h new file mode 100644 index 00000000..871d3788 --- /dev/null +++ b/src/tabwindow/rwindow.h @@ -0,0 +1,131 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2012-2013 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 R_WINDOW_H +#define R_WINDOW_H + + +// Rekonq Includes +#include "rekonq_defines.h" + +// KDE Includes +#include <KConfig> +#include <KConfigGroup> + +// Qt Includes +#include <QWidget> + +/** + * This is rekonq (re)implementation of KMainWindow, + * given that we'd like to NOT use a "real" xMainWindow + * but a widget with the nice mainwindow properties + * (eg: session management, auto save dimension, etc) but + * NOT its peculiar containers (eg: toolbars, menubar, statusbar, + * central widget...) + * + */ +class RWindow : public QWidget +{ + friend class KRWSessionManager; + + Q_OBJECT + +public: + explicit RWindow(QWidget* parent = 0); + + virtual ~RWindow(); + + QSize sizeHint() const; + + /** + * List of members of RekonqWindow class. + */ + static QList<RWindow*> windowList(); + + /** + * If the session did contain so high a @p number, @p true is returned, + * else @p false. + * @see restore() + **/ + static bool canBeRestored(int number); + + /** + * Try to restore the toplevel widget as defined by @p number (1..X). + * + * You should call canBeRestored() first. + * + **/ + bool restore(int number, bool show = true); + +protected: + /** + * Save your instance-specific properties. The function is + * invoked when the session manager requests your application + * to save its state. + * + * Please reimplement these function in childclasses. + * + * Note: No user interaction is allowed + * in this function! + * + */ + virtual void saveProperties(KConfigGroup &) {} + + /** + * Read your instance-specific properties. + * + * Is called indirectly by restore(). + */ + virtual void readProperties(const KConfigGroup &) {} + + void savePropertiesInternal(KConfig*, int); + bool readPropertiesInternal(KConfig*, int); + + /** + * For inherited classes + */ + void saveWindowSize(const KConfigGroup &config) const; + /** + * For inherited classes + * Note that a -geometry on the command line has priority. + */ + void restoreWindowSize(const KConfigGroup & config); + + /// parse the geometry from the geometry command line argument + void parseGeometry(); + + virtual void resizeEvent(QResizeEvent *); + +private Q_SLOTS: + void saveAutoSaveSettings(); + +private: + /// This has been added to just fix window position && not let them be overlying + void checkPosition(); +}; + +#endif // R_WINDOW_H diff --git a/src/tabwindow/tabbar.cpp b/src/tabwindow/tabbar.cpp index bdd07573..7363d965 100644 --- a/src/tabwindow/tabbar.cpp +++ b/src/tabwindow/tabbar.cpp @@ -33,7 +33,8 @@ #include "rekonq.h" // Local Includes -#include "tabwindow.h" +#include "tabwidget.h" + #include "tabhighlighteffect.h" #include "tabpreviewpopup.h" #include "webwindow.h" @@ -186,7 +187,7 @@ void TabBar::detachTab() void TabBar::contextMenu(int tabIndex, const QPoint &pos) { - TabWindow *w = qobject_cast<TabWindow *>(parent()); + TabWidget *w = qobject_cast<TabWidget *>(parent()); QAction *a; @@ -262,7 +263,7 @@ void TabBar::contextMenu(int tabIndex, const QPoint &pos) void TabBar::emptyAreaContextMenu(const QPoint &pos) { - TabWindow *w = qobject_cast<TabWindow *>(parent()); + TabWidget *w = qobject_cast<TabWidget *>(parent()); QAction *a; @@ -355,7 +356,7 @@ void TabBar::tabInserted(int index) if (index < availableIndex) { - TabWindow *w = qobject_cast<TabWindow *>(parent()); + TabWidget *w = qobject_cast<TabWidget *>(parent()); w->moveTab(index, availableIndex); } @@ -446,7 +447,7 @@ void TabBar::mouseReleaseEvent(QMouseEvent *event) { if (!tabData(i).toBool()) { - TabWindow *w = qobject_cast<TabWindow *>(parent()); + TabWidget *w = qobject_cast<TabWidget *>(parent()); w->moveTab(i, pinnedTabs); w->setCurrentIndex(pinnedTabs); } @@ -457,7 +458,7 @@ void TabBar::mouseReleaseEvent(QMouseEvent *event) { if (tabData(i).toBool()) { - TabWindow *w = qobject_cast<TabWindow *>(parent()); + TabWidget *w = qobject_cast<TabWidget *>(parent()); w->moveTab(i, pinnedTabs - 1); w->setCurrentIndex(pinnedTabs - 1); } @@ -482,7 +483,7 @@ void TabBar::showTabPreview() delete m_previewPopup.data(); m_previewPopup.clear(); - TabWindow *tabW = qobject_cast<TabWindow *>(parent()); + TabWidget *tabW = qobject_cast<TabWidget *>(parent()); WebWindow *indexedTab = tabW->webWindow(m_currentTabPreviewIndex); WebWindow *currentTab = tabW->webWindow(currentIndex()); @@ -546,7 +547,7 @@ void TabBar::pinTab() } } - TabWindow *w = qobject_cast<TabWindow *>(parent()); + TabWidget *w = qobject_cast<TabWidget *>(parent()); w->moveTab(index, availableIndex); index = availableIndex; @@ -593,7 +594,7 @@ void TabBar::unpinTab() } } - TabWindow *w = qobject_cast<TabWindow *>(parent()); + TabWidget *w = qobject_cast<TabWidget *>(parent()); w->moveTab(index, availableIndex); index = availableIndex; diff --git a/src/tabwindow/tabwindow.cpp b/src/tabwindow/tabwidget.cpp index 2ade757b..bb62ca27 100644 --- a/src/tabwindow/tabwindow.cpp +++ b/src/tabwindow/tabwidget.cpp @@ -25,14 +25,16 @@ // Self Includes -#include "tabwindow.h" -#include "tabwindow.moc" +#include "tabwidget.h" +#include "tabwidget.moc" // Auto Includes #include "rekonq.h" // Local Includes #include "application.h" +#include "rekonqwindow.h" + #include "webpage.h" #include "webwindow.h" #include "tabbar.h" @@ -70,8 +72,8 @@ #include <QWebSettings> -TabWindow::TabWindow(bool withTab, bool PrivateBrowsingMode, QWidget *parent) - : RekonqWindow(parent) +TabWidget::TabWidget(bool withTab, bool PrivateBrowsingMode, QWidget *parent) + : KTabWidget(parent) , _addTabButton(new QToolButton(this)) , _openedTabsCounter(0) , _isPrivateBrowsing(PrivateBrowsingMode) @@ -79,7 +81,7 @@ TabWindow::TabWindow(bool withTab, bool PrivateBrowsingMode, QWidget *parent) { init(); - // NOTE: we usually create TabWindow with AT LEAST one tab, but + // NOTE: we usually create TabWidget with AT LEAST one tab, but // in one important case... if (withTab) { @@ -90,8 +92,8 @@ TabWindow::TabWindow(bool withTab, bool PrivateBrowsingMode, QWidget *parent) } -TabWindow::TabWindow(WebPage *pg, QWidget *parent) - : RekonqWindow(parent) +TabWidget::TabWidget(WebPage *pg, QWidget *parent) + : KTabWidget(parent) , _addTabButton(new QToolButton(this)) , _openedTabsCounter(0) , _isPrivateBrowsing(false) @@ -105,7 +107,7 @@ TabWindow::TabWindow(WebPage *pg, QWidget *parent) } -void TabWindow::init() +void TabWidget::init() { setContentsMargins(0, 0, 0, 0); @@ -184,6 +186,22 @@ void TabWindow::init() connect(this, SIGNAL(currentChanged(int)), this, SLOT(currentChanged(int))); // ---------------------------------------------------------------------------------------------- + RekonqWindow *rw = qobject_cast<RekonqWindow *>(parent()); + // setup bookmarks panel action + a = new KAction(KIcon("bookmarks-organize"), i18n("Bookmarks Panel"), this); + a->setShortcut(KShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_B)); + actionCollection()->addAction(QL1S("show_bookmarks_panel"), a); + a->setCheckable(true); + connect(a, SIGNAL(triggered(bool)), rw, SLOT(showBookmarksPanel(bool))); + + // setup history panel action + a = new KAction(KIcon("view-history"), i18n("History Panel"), this); + a->setShortcut(KShortcut(Qt::CTRL + Qt::Key_H)); + actionCollection()->addAction(QL1S("show_history_panel"), a); + a->setCheckable(true); + connect(a, SIGNAL(triggered(bool)), rw, SLOT(showHistoryPanel(bool))); + + // ---------------------------------------------------------------------------------------------- // shortcuts for quickly switching to a tab QSignalMapper *tabSignalMapper = new QSignalMapper(this); for (int i = 0; i < 9; i++) @@ -211,7 +229,7 @@ void TabWindow::init() _ac->readSettings(); // ---------------------------------------------------------------------------------------------- - int n = rApp->tabWindowList().count() + 1; + int n = rApp->rekonqWindowList().count() + 1; QList<TabHistory> list = SessionManager::self()->closedSitesForWindow( QL1S("win") + QString::number(n) ); Q_FOREACH(const TabHistory & tab, list) { @@ -226,32 +244,32 @@ void TabWindow::init() // ---------------------------------------------------------------------------------------------------- -KActionCollection *TabWindow::actionCollection() const +KActionCollection *TabWidget::actionCollection() const { return _ac; } -QAction *TabWindow::actionByName(const QString &name) +QAction *TabWidget::actionByName(const QString &name) { return actionCollection()->action(name); } -TabBar *TabWindow::tabBar() const +TabBar *TabWidget::tabBar() const { TabBar *tabBar = qobject_cast<TabBar *>(QTabWidget::tabBar()); return tabBar; } -WebWindow *TabWindow::currentWebWindow() const +WebWindow *TabWidget::currentWebWindow() const { return webWindow(currentIndex()); } -WebWindow *TabWindow::webWindow(int index) const +WebWindow *TabWidget::webWindow(int index) const { WebWindow *tab = qobject_cast<WebWindow *>(this->widget(index)); if (tab) @@ -264,13 +282,39 @@ WebWindow *TabWindow::webWindow(int index) const } -QList<TabHistory> TabWindow::recentlyClosedTabs() +QList<TabHistory> TabWidget::recentlyClosedTabs() { return m_recentlyClosedTabs; } -WebWindow *TabWindow::prepareNewTab(WebPage *page) +void TabWidget::newTab(WebPage *page) +{ + WebWindow *tab = prepareNewTab(page); + addTab(tab, i18n("new tab")); + setCurrentWidget(tab); + + // no need to load an url if we already have a page... + if (page) + return; + + switch (ReKonfig::newTabsBehaviour()) + { + case 0: // new tab page + tab->load(KUrl("about:home")); + break; + case 2: // homepage + tab->load(KUrl(ReKonfig::homePage())); + break; + case 1: // blank page + default: + tab->load(KUrl("about:blank")); + break; + } +} + + +WebWindow *TabWidget::prepareNewTab(WebPage *page) { WebWindow *tab = new WebWindow(this, _isPrivateBrowsing, page); @@ -289,7 +333,7 @@ WebWindow *TabWindow::prepareNewTab(WebPage *page) } -void TabWindow::loadUrl(const KUrl &url, Rekonq::OpenType type, TabHistory *history) +void TabWidget::loadUrl(const KUrl &url, Rekonq::OpenType type, TabHistory *history) { WebWindow *tab = 0; switch (type) @@ -336,34 +380,7 @@ void TabWindow::loadUrl(const KUrl &url, Rekonq::OpenType type, TabHistory *hist } -void TabWindow::newTab(WebPage *page) -{ - WebWindow *tab = prepareNewTab(page); - addTab(tab, i18n("new tab")); - setCurrentWidget(tab); - - // no need to load an url if we already have a page... - if (page) - return; - - switch (ReKonfig::newTabsBehaviour()) - { - case 0: // new tab page - tab->load(KUrl("about:home")); - break; - case 2: // homepage - tab->load(KUrl(ReKonfig::homePage())); - break; - case 1: // blank page - default: - tab->load(KUrl("about:blank")); - break; - } - -} - - -void TabWindow::pageCreated(WebPage *page) +void TabWidget::pageCreated(WebPage *page) { WebWindow *tab = prepareNewTab(page); @@ -375,7 +392,7 @@ void TabWindow::pageCreated(WebPage *page) } -void TabWindow::currentChanged(int newIndex) +void TabWidget::currentChanged(int newIndex) { _openedTabsCounter = 0; @@ -396,7 +413,7 @@ void TabWindow::currentChanged(int newIndex) } -void TabWindow::updateNewTabButtonPosition() +void TabWidget::updateNewTabButtonPosition() { if (isFullScreen()) return; @@ -421,7 +438,7 @@ void TabWindow::updateNewTabButtonPosition() } -void TabWindow::tabTitleChanged(const QString &title) +void TabWidget::tabTitleChanged(const QString &title) { WebWindow *tab = qobject_cast<WebWindow *>(sender()); if (!tab) @@ -451,7 +468,7 @@ void TabWindow::tabTitleChanged(const QString &title) } -void TabWindow::tabUrlChanged(const QUrl &url) +void TabWidget::tabUrlChanged(const QUrl &url) { WebWindow *tab = qobject_cast<WebWindow *>(sender()); if (!tab) @@ -463,7 +480,7 @@ void TabWindow::tabUrlChanged(const QUrl &url) } -void TabWindow::tabIconChanged() +void TabWidget::tabIconChanged() { WebWindow *tab = qobject_cast<WebWindow *>(sender()); if (!tab) @@ -490,7 +507,7 @@ void TabWindow::tabIconChanged() } -void TabWindow::tabLoadStarted() +void TabWidget::tabLoadStarted() { WebWindow *tab = qobject_cast<WebWindow *>(sender()); if (!tab) @@ -528,7 +545,7 @@ void TabWindow::tabLoadStarted() } -void TabWindow::tabLoadFinished(bool ok) +void TabWidget::tabLoadFinished(bool ok) { Q_UNUSED(ok); @@ -575,7 +592,7 @@ void TabWindow::tabLoadFinished(bool ok) } -void TabWindow::cloneTab(int index) +void TabWidget::cloneTab(int index) { if (index < 0) index = currentIndex(); @@ -590,7 +607,7 @@ void TabWindow::cloneTab(int index) } -void TabWindow::closeTab(int index, bool del) +void TabWidget::closeTab(int index, bool del) { if (index < 0) index = currentIndex(); @@ -635,7 +652,7 @@ void TabWindow::closeTab(int index, bool del) } -void TabWindow::closeOtherTabs(int index) +void TabWidget::closeOtherTabs(int index) { if (index < 0) index = currentIndex(); @@ -654,7 +671,7 @@ void TabWindow::closeOtherTabs(int index) } -void TabWindow::detachTab(int index, TabWindow *toWindow) +void TabWidget::detachTab(int index, RekonqWindow *toWindow) { if (index < 0) index = currentIndex(); @@ -673,13 +690,15 @@ void TabWindow::detachTab(int index, TabWindow *toWindow) closeTab(index, false); - TabWindow *w = 0; + RekonqWindow *w = 0; w = (toWindow == 0) - ? new TabWindow(false) + ? new RekonqWindow(false) : toWindow; - w->addTab(tab, tab->title()); - w->setCurrentWidget(tab); + TabWidget *hostTabWidget = w->tabWidget(); + + hostTabWidget->addTab(tab, tab->title()); + hostTabWidget->setCurrentWidget(tab); // disconnect signals from old tabwindow // WARNING: Code copied from prepareNewTab method. @@ -693,17 +712,17 @@ void TabWindow::detachTab(int index, TabWindow *toWindow) // reconnect signals to new tabwindow // WARNING: Code copied from prepareNewTab method. // Any new changes there should be applied here... - connect(tab, SIGNAL(titleChanged(QString)), w, SLOT(tabTitleChanged(QString))); - connect(tab, SIGNAL(iconChanged()), w, SLOT(tabIconChanged())); - connect(tab, SIGNAL(loadStarted()), w, SLOT(tabLoadStarted())); - connect(tab, SIGNAL(loadFinished(bool)), w, SLOT(tabLoadFinished(bool))); - connect(tab, SIGNAL(pageCreated(WebPage*)), w, SLOT(pageCreated(WebPage*))); + connect(tab, SIGNAL(titleChanged(QString)), hostTabWidget, SLOT(tabTitleChanged(QString))); + connect(tab, SIGNAL(iconChanged()), hostTabWidget, SLOT(tabIconChanged())); + connect(tab, SIGNAL(loadStarted()), hostTabWidget, SLOT(tabLoadStarted())); + connect(tab, SIGNAL(loadFinished(bool)), hostTabWidget, SLOT(tabLoadFinished(bool))); + connect(tab, SIGNAL(pageCreated(WebPage*)), hostTabWidget, SLOT(pageCreated(WebPage*))); w->show(); } -void TabWindow::reloadTab(int index) +void TabWidget::reloadTab(int index) { // When index is -1 index chooses the current tab if (index < 0) @@ -718,7 +737,7 @@ void TabWindow::reloadTab(int index) } -void TabWindow::reloadAllTabs() +void TabWidget::reloadAllTabs() { for (int i = 0; i < count(); ++i) { @@ -727,7 +746,7 @@ void TabWindow::reloadAllTabs() } -void TabWindow::bookmarkAllTabs() +void TabWidget::bookmarkAllTabs() { KBookmarkGroup rGroup = BookmarkManager::self()->rootGroup(); KBookmarkGroup folderGroup = rGroup.createNewFolder(i18n("Bookmarked tabs: ") + QDate::currentDate().toString()); @@ -739,13 +758,13 @@ void TabWindow::bookmarkAllTabs() } -void TabWindow::restoreLastClosedTab() +void TabWidget::restoreLastClosedTab() { restoreClosedTab(0); } -void TabWindow::restoreClosedTab(int index, bool inNewTab) +void TabWidget::restoreClosedTab(int index, bool inNewTab) { if (m_recentlyClosedTabs.isEmpty()) return; @@ -783,7 +802,7 @@ void TabWindow::restoreClosedTab(int index, bool inNewTab) } -void TabWindow::nextTab() +void TabWidget::nextTab() { int next = currentIndex() + 1; if (next == count()) @@ -792,7 +811,7 @@ void TabWindow::nextTab() } -void TabWindow::previousTab() +void TabWidget::previousTab() { int next = currentIndex() - 1; if (next < 0) @@ -801,7 +820,7 @@ void TabWindow::previousTab() } -void TabWindow::setFullScreen(bool makeFullScreen) +void TabWidget::setFullScreen(bool makeFullScreen) { tabBar()->setVisible(!makeFullScreen); _addTabButton->setVisible(!makeFullScreen); @@ -813,13 +832,13 @@ void TabWindow::setFullScreen(bool makeFullScreen) } -bool TabWindow::isPrivateBrowsingWindowMode() +bool TabWidget::isPrivateBrowsingWindowMode() { return _isPrivateBrowsing; } -void TabWindow::loadFavorite(const int index) +void TabWidget::loadFavorite(const int index) { QStringList urls = ReKonfig::previewUrls(); if (index < 0 || index > urls.length()) @@ -829,3 +848,53 @@ void TabWindow::loadFavorite(const int index) loadUrl(url); currentWebWindow()->setFocus(); } + + +// NOTE: For internal purpose only ------------------------------------------------------ + + +int TabWidget::addTab(QWidget *page, const QString &label) +{ + setUpdatesEnabled(false); + int i = KTabWidget::addTab(page, label); + setUpdatesEnabled(true); + + return i; +} + + +int TabWidget::addTab(QWidget *page, const QIcon &icon, const QString &label) +{ + setUpdatesEnabled(false); + int i = KTabWidget::addTab(page, icon, label); + setUpdatesEnabled(true); + + return i; +} + + +int TabWidget::insertTab(int index, QWidget *page, const QString &label) +{ + if (! ReKonfig::openNewTabsNextToCurrent()) + index = -1; + setUpdatesEnabled(false); + int i = KTabWidget::insertTab(index, page, label); + setUpdatesEnabled(true); + + return i; +} + + +int TabWidget::insertTab(int index, QWidget *page, const QIcon &icon, const QString &label) +{ + if (! ReKonfig::openNewTabsNextToCurrent()) + index = -1; + setUpdatesEnabled(false); + int i = KTabWidget::insertTab(index, page, icon, label); + setUpdatesEnabled(true); + + return i; +} + + +// -------------------------------------------------------------------------------------- diff --git a/src/tabwindow/tabwindow.h b/src/tabwindow/tabwidget.h index c72c252b..9c79df11 100644 --- a/src/tabwindow/tabwindow.h +++ b/src/tabwindow/tabwidget.h @@ -24,16 +24,13 @@ * ============================================================ */ -#ifndef TAB_WINDOW -#define TAB_WINDOW +#ifndef TAB_WIDGET +#define TAB_WIDGET // Rekonq Includes #include "rekonq_defines.h" -// Local Includes -#include "rekonqwindow.h" - // KDE Includes #include <KTabWidget> #include <KActionCollection> @@ -51,17 +48,18 @@ class TabBar; class WebPage; class WebWindow; +class RekonqWindow; // -------------------------------------------------------------------------------------- -class TabWindow : public RekonqWindow +class TabWidget : public KTabWidget { Q_OBJECT public: - explicit TabWindow(bool withTab = true, bool PrivateBrowsingMode = false, QWidget *parent = 0); - explicit TabWindow(WebPage *pg, QWidget *parent = 0); + explicit TabWidget(bool withTab = true, bool PrivateBrowsingMode = false, QWidget *parent = 0); + explicit TabWidget(WebPage *pg, QWidget *parent = 0); WebWindow* currentWebWindow() const; WebWindow* webWindow(int index) const; @@ -76,6 +74,14 @@ public: QList<TabHistory> recentlyClosedTabs(); void restoreClosedTab(int index, bool inNewTab = true); + // NOTE: For internal purpose only ------------------------------------------------------ + int addTab(QWidget *page, const QString &label); + int addTab(QWidget *page, const QIcon &icon, const QString &label); + + int insertTab(int index, QWidget *page, const QString &label); + int insertTab(int index, QWidget *page, const QIcon &icon, const QString &label); + // -------------------------------------------------------------------------------------- + public Q_SLOTS: void loadUrl(const KUrl &, Rekonq::OpenType type = Rekonq::CurrentTab, TabHistory *history = 0); void newTab(WebPage *page = 0); @@ -109,7 +115,7 @@ private Q_SLOTS: void cloneTab(int index = -1); void closeTab(int index = -1, bool del = true); void closeOtherTabs(int index = -1); - void detachTab(int index = -1, TabWindow *toWindow = 0); + void detachTab(int index = -1, RekonqWindow *toWindow = 0); void reloadTab(int index = -1); void reloadAllTabs(); @@ -137,4 +143,4 @@ private: KActionCollection *_ac; }; -#endif // TAB_WINDOW +#endif // TAB_WIDGET |