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