From e71c22eec2700fa76874788067c0a3dde7c6c785 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Thu, 30 Aug 2012 10:43:47 +0200 Subject: Save & restore window dimension/position Also, fix tabwindow attributes (quit & delete on close on) --- src/tabwindow/tabwindow.cpp | 79 +++++++++++++++++++++++++++++++++++++++------ src/tabwindow/tabwindow.h | 9 ++++-- 2 files changed, 76 insertions(+), 12 deletions(-) diff --git a/src/tabwindow/tabwindow.cpp b/src/tabwindow/tabwindow.cpp index 0aafeb0d..efc3a61a 100644 --- a/src/tabwindow/tabwindow.cpp +++ b/src/tabwindow/tabwindow.cpp @@ -37,12 +37,17 @@ // KDE Includes #include +#include +#include +#include #include #include #include +#include +#include + // Qt Includes -#include #include #include #include @@ -61,6 +66,10 @@ TabWindow::TabWindow(bool withTab, 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); + setContentsMargins(0, 0, 0, 0); setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); @@ -105,20 +114,72 @@ TabWindow::TabWindow(bool withTab, QWidget *parent) setCurrentWidget(tab); } - // FIXME: Manage sizes... - kDebug() << "SIZE: " << size(); - kDebug() << "SIZE HINT: " << sizeHint(); + loadWindowSettings(); +} + + +TabWindow::~TabWindow() +{ + saveWindowSettings(); +} + + +void TabWindow::loadWindowSettings() +{ + KSharedConfig::Ptr config = KGlobal::config(); + KConfigGroup cg = KConfigGroup(config.data(), QL1S("TabWindow")); + + int scnum = QApplication::desktop()->screenNumber(window()); + QRect desktopRect = QApplication::desktop()->screenGeometry(scnum); + + QSize defaultSize = desktopRect.size() * 0.8; - resize(sizeHint()); + QString widthString = QString::fromLatin1("Width %1").arg(desktopRect.width()); + int w = cg.readEntry(widthString, defaultSize.width() ); + QString heightString = QString::fromLatin1("Height %1").arg(desktopRect.height()); + int h = cg.readEntry(heightString, defaultSize.height() ); + + resize(w, h); + + 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 + if (!restoreGeometry( QByteArray::fromBase64(geometry) )) + move( (desktopRect.width()-width())/2, (desktopRect.height()-height())/2 ); } -QSize TabWindow::sizeHint() const +void TabWindow::saveWindowSettings() { - QRect desktopRect = QApplication::desktop()->screenGeometry(); - QSize size = desktopRect.size() * 0.8; - return size; + KSharedConfig::Ptr config = KGlobal::config(); + KConfigGroup cg = KConfigGroup(config.data(), QL1S("TabWindow")); + + 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(); + } + + 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() ); } diff --git a/src/tabwindow/tabwindow.h b/src/tabwindow/tabwindow.h index b247d4d2..c4ba70be 100644 --- a/src/tabwindow/tabwindow.h +++ b/src/tabwindow/tabwindow.h @@ -57,9 +57,8 @@ class TabWindow : public KTabWidget public: TabWindow(bool withTab = true, QWidget *parent = 0); - - virtual QSize sizeHint() const; - + virtual ~TabWindow(); + WebWindow* currentWebWindow() const; WebWindow* webWindow(int index) const; @@ -75,6 +74,10 @@ private: */ WebWindow *prepareNewTab(WebPage *page = 0); + // internal + void loadWindowSettings(); + void saveWindowSettings(); + private Q_SLOTS: /** * Updates new tab button position -- cgit v1.2.1