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 "VidaliaWindow.h"
00018 #include "Vidalia.h"
00019
00020 #include <QPoint>
00021 #include <QSize>
00022 #include <QShortcut>
00023 #include <QByteArray>
00024 #include <QKeySequence>
00025 #include <QDesktopWidget>
00026
00027
00028
00029 VidaliaWindow::VidaliaWindow(const QString &name, QWidget *parent,
00030 Qt::WFlags flags)
00031 : QMainWindow(parent, flags)
00032 {
00033 _name = name;
00034 _settings = new VSettings(name);
00035 }
00036
00037
00038 VidaliaWindow::~VidaliaWindow()
00039 {
00040 saveWindowState();
00041 delete _settings;
00042 }
00043
00044
00045 void
00046 VidaliaWindow::setShortcut(const QString &shortcut, const char *slot)
00047 {
00048 vApp->createShortcut(QKeySequence(shortcut), this, this, slot);
00049 }
00050
00051
00052 void
00053 VidaliaWindow::saveWindowState()
00054 {
00055 #if QT_VERSION >= 0x040200
00056 saveSetting("Geometry", saveGeometry());
00057 #else
00058 saveSetting("Size", size());
00059 saveSetting("Position", pos());
00060 #endif
00061 }
00062
00063
00064 void
00065 VidaliaWindow::restoreWindowState()
00066 {
00067 #if QT_VERSION >= 0x040200
00068 QByteArray geometry = getSetting("Geometry", QByteArray()).toByteArray();
00069 if (geometry.isEmpty())
00070 adjustSize();
00071 else
00072 restoreGeometry(geometry);
00073 #else
00074 QRect screen = QDesktopWidget().availableGeometry();
00075
00076
00077 QSize size = getSetting("Size", QSize()).toSize();
00078 if (!size.isEmpty()) {
00079 size = size.boundedTo(screen.size());
00080 resize(size);
00081 }
00082
00083
00084 QPoint pos = getSetting("Position", QPoint()).toPoint();
00085 if (!pos.isNull() && screen.contains(pos)) {
00086 move(pos);
00087 }
00088 #endif
00089 }
00090
00091
00092
00093 QVariant
00094 VidaliaWindow::getSetting(QString setting, QVariant defaultValue)
00095 {
00096 return _settings->value(setting, defaultValue);
00097 }
00098
00099
00100 void
00101 VidaliaWindow::saveSetting(QString prop, QVariant value)
00102 {
00103 _settings->setValue(prop, value);
00104 }
00105
00106
00107
00108
00109
00110 void
00111 VidaliaWindow::setVisible(bool visible)
00112 {
00113 if (visible) {
00114
00115
00116 if (isVisible()) {
00117 activateWindow();
00118 setWindowState(windowState() & ~Qt::WindowMinimized | Qt::WindowActive);
00119 raise();
00120 } else {
00121 restoreWindowState();
00122 }
00123 } else {
00124
00125 saveWindowState();
00126 }
00127 QMainWindow::setVisible(visible);
00128 }
00129
00130
00131
00132
00133 void
00134 VidaliaWindow::changeEvent(QEvent *e)
00135 {
00136 if (e->type() == QEvent::LanguageChange) {
00137 retranslateUi();
00138 e->accept();
00139 return;
00140 }
00141 QMainWindow::changeEvent(e);
00142 }
00143
00144
00145
00146 void
00147 VidaliaWindow::retranslateUi()
00148 {
00149
00150 }
00151