00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <QPoint>
00018 #include <QSize>
00019 #include <QShortcut>
00020 #include <QByteArray>
00021 #include <QKeySequence>
00022 #include <QDesktopWidget>
00023 #include <vidalia.h>
00024 #include "vidaliawindow.h"
00025
00026
00027
00028 VidaliaWindow::VidaliaWindow(const QString &name, QWidget *parent,
00029 Qt::WFlags flags)
00030 : QMainWindow(parent, flags)
00031 {
00032 _name = name;
00033 _settings = new VSettings(name);
00034 }
00035
00036
00037 VidaliaWindow::~VidaliaWindow()
00038 {
00039 saveWindowState();
00040 delete _settings;
00041 }
00042
00043
00044 void
00045 VidaliaWindow::setShortcut(const QString &shortcut, const char *slot)
00046 {
00047 vApp->createShortcut(QKeySequence(shortcut), this, this, slot);
00048 }
00049
00050
00051 void
00052 VidaliaWindow::saveWindowState()
00053 {
00054 #if QT_VERSION >= 0x040200
00055 saveSetting("Geometry", saveGeometry());
00056 #else
00057 saveSetting("Size", size());
00058 saveSetting("Position", pos());
00059 #endif
00060 }
00061
00062
00063 void
00064 VidaliaWindow::restoreWindowState()
00065 {
00066 #if QT_VERSION >= 0x040200
00067 QByteArray geometry = getSetting("Geometry", QByteArray()).toByteArray();
00068 if (geometry.isEmpty())
00069 adjustSize();
00070 else
00071 restoreGeometry(geometry);
00072 #else
00073 QRect screen = QDesktopWidget().availableGeometry();
00074
00075
00076 QSize size = getSetting("Size", QSize()).toSize();
00077 if (!size.isEmpty()) {
00078 size = size.boundedTo(screen.size());
00079 resize(size);
00080 }
00081
00082
00083 QPoint pos = getSetting("Position", QPoint()).toPoint();
00084 if (!pos.isNull() && screen.contains(pos)) {
00085 move(pos);
00086 }
00087 #endif
00088 }
00089
00090
00091
00092 QVariant
00093 VidaliaWindow::getSetting(QString setting, QVariant defaultValue)
00094 {
00095 return _settings->value(setting, defaultValue);
00096 }
00097
00098
00099 void
00100 VidaliaWindow::saveSetting(QString prop, QVariant value)
00101 {
00102 _settings->setValue(prop, value);
00103 }
00104
00105
00106
00107
00108
00109 void
00110 VidaliaWindow::setVisible(bool visible)
00111 {
00112 if (visible) {
00113
00114
00115 if (isVisible()) {
00116 activateWindow();
00117 setWindowState(windowState() & ~Qt::WindowMinimized | Qt::WindowActive);
00118 raise();
00119 } else {
00120 restoreWindowState();
00121 }
00122 } else {
00123
00124 saveWindowState();
00125 }
00126 QMainWindow::setVisible(visible);
00127 }
00128