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