diff options
Diffstat (limited to 'src/tabwindow/tabwindow.cpp')
-rw-r--r-- | src/tabwindow/tabwindow.cpp | 79 |
1 files changed, 70 insertions, 9 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 <KAction> +#include <KApplication> +#include <KConfig> +#include <KConfigGroup> #include <KLocalizedString> #include <KStandardDirs> #include <KUrl> +#include <KWindowInfo> +#include <KWindowSystem> + // Qt Includes -#include <QApplication> #include <QDesktopWidget> #include <QLabel> #include <QMovie> @@ -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() ); } |