00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "qdesigner.h"
00025 #include "qdesigner_settings.h"
00026 #include "qdesigner_widgetbox.h"
00027 #include "qdesigner_workbench.h"
00028 #include "qdesigner_propertyeditor.h"
00029 #include "qdesigner_objectinspector.h"
00030
00031 #include <QtCore/QVariant>
00032 #include <QtCore/QDir>
00033
00034 #include <QtGui/QDesktopWidget>
00035 #include <QtGui/QStyle>
00036
00037 #include <QtCore/qdebug.h>
00038
00039 QDesignerSettings::QDesignerSettings()
00040 : QSettings()
00041 {
00042 m_designerPath = QLatin1String("/.designer");
00043
00044 QStringList paths = defaultFormTemplatePaths();
00045 foreach (QString path, paths) {
00046 if (!QDir::current().exists(path))
00047 QDir::current().mkpath(path);
00048 }
00049 }
00050
00051 QDesignerSettings::~QDesignerSettings()
00052 {
00053 }
00054
00055 QStringList QDesignerSettings::formTemplatePaths() const
00056 {
00057 return value(QLatin1String("FormTemplatePaths"),
00058 defaultFormTemplatePaths()).toStringList();
00059 }
00060
00061 void QDesignerSettings::setFormTemplatePaths(const QStringList &paths)
00062 {
00063 setValue(QLatin1String("FormTemplatePaths"), paths);
00064 }
00065
00066 QString QDesignerSettings::defaultUserWidgetBoxXml() const
00067 {
00068 return QDir::homePath() + m_designerPath + QLatin1String("/widgetbox.xml");
00069 }
00070
00071 QStringList QDesignerSettings::defaultFormTemplatePaths() const
00072 {
00073 QStringList paths;
00074
00075 QString templatePath = QLatin1String("/templates");
00076
00077 paths.append(QDir::homePath() + m_designerPath + templatePath);
00078 paths.append(qDesigner->applicationDirPath() + templatePath);
00079
00080 return paths;
00081 }
00082
00083 void QDesignerSettings::saveGeometryFor(const QWidget *w)
00084 {
00085 Q_ASSERT(w && !w->objectName().isEmpty());
00086 saveGeometryHelper(w, w->objectName());
00087 }
00088
00089 void QDesignerSettings::setGeometryFor(QWidget *w, const QRect &fallBack) const
00090 {
00091 Q_ASSERT(w && !w->objectName().isEmpty());
00092 setGeometryHelper(w, w->objectName(),
00093 fallBack.isNull() ? QRect(QPoint(0, 0), w->sizeHint()) : fallBack);
00094 }
00095
00096 void QDesignerSettings::saveGeometryHelper(const QWidget *w, const QString &key)
00097 {
00098 beginGroup(key);
00099 QPoint pos = w->pos();
00100 if (!w->isWindow())
00101 pos = w->parentWidget()->pos();
00102
00103 setValue(QLatin1String("screen"), QApplication::desktop()->screenNumber(w));
00104 setValue(QLatin1String("geometry"), QRect(pos, w->size()));
00105 setValue(QLatin1String("visible"), w->isVisible());
00106 setValue(QLatin1String("maximized"), w->isMaximized());
00107 endGroup();
00108 }
00109
00110 void QDesignerSettings::setGeometryHelper(QWidget *w, const QString &key,
00111 const QRect &fallBack) const
00112 {
00113
00114 int screen = value(key + QLatin1String("/screen"), 0).toInt();
00115 QRect g = value(key + QLatin1String("/geometry"), fallBack).toRect();
00116 QRect screenRect = QApplication::desktop()->availableGeometry(screen);
00117
00118
00119
00120
00121
00122
00123 if (w->isWindow() && g.intersect(screenRect).isEmpty())
00124 g = fallBack;
00125
00126
00127 if (!screenRect.contains(g.bottomRight())) {
00128 g.moveRight(qMax(0 + g.width(), qMin(screenRect.right(), g.right())));
00129 g.moveBottom(qMax(0 + g.height(), qMin(screenRect.bottom(), g.bottom())));
00130 }
00131
00132 if (!screenRect.contains(g.topLeft())) {
00133 g.moveLeft(qMin(screenRect.right() - g.width(), qMax(screenRect.left(), g.left())));
00134 g.moveTop(qMin(screenRect.bottom() - g.height(), qMax(screenRect.top(), g.top())));
00135 }
00136
00137 if (!screenRect.contains(g.bottomRight())) {
00138 g.setRight(qMin(screenRect.right(), g.right()));
00139 g.moveBottom(qMin(screenRect.bottom(), g.bottom()));
00140 }
00141
00142 if (!screenRect.contains(g.topLeft())) {
00143 g.setLeft(qMax(0, qMin(screenRect.left(), g.left())));
00144 g.moveTop(qMax(0, qMin(screenRect.top(), g.top())));
00145 }
00146
00147
00148 if (!w->isWindow())
00149 w->parentWidget()->move(g.topLeft());
00150 else
00151 w->move(g.topLeft());
00152
00153 if (value(key + QLatin1String("/maximized"), false).toBool()) {
00154 w->setWindowState(w->windowState() | Qt::WindowMaximized);
00155 } else {
00156 w->resize(g.size());
00157 }
00158
00159 if (value(key + QLatin1String("/visible"), true).toBool())
00160 w->show();
00161
00162 }
00163
00164 QStringList QDesignerSettings::recentFilesList() const
00165 {
00166 return value(QLatin1String("recentFilesList")).toStringList();
00167 }
00168
00169 void QDesignerSettings::setRecentFilesList(const QStringList &sl)
00170 {
00171 setValue(QLatin1String("recentFilesList"), sl);
00172 }
00173
00174 void QDesignerSettings::setShowNewFormOnStartup(bool showIt)
00175 {
00176 setValue(QLatin1String("newFormDialog/ShowOnStartup"), showIt);
00177 }
00178
00179 bool QDesignerSettings::showNewFormOnStartup() const
00180 {
00181 return value(QLatin1String("newFormDialog/ShowOnStartup"), true).toBool();
00182 }
00183
00184 void QDesignerSettings::setUIMode(int mode)
00185 {
00186 setValue(QLatin1String("UI/currentMode"), mode);
00187 }
00188
00189 int QDesignerSettings::uiMode() const
00190 {
00191 #if defined(Q_WS_WIN)
00192 return value(QLatin1String("UI/currentMode"), QDesignerWorkbench::DockedMode).toInt();
00193 #else
00194 return value(QLatin1String("UI/currentMode"), QDesignerWorkbench::TopLevelMode).toInt();
00195 #endif
00196 }
00197
00198 QByteArray QDesignerSettings::mainWindowState() const
00199 {
00200 return value(QLatin1String("MainWindowState")).toByteArray();
00201 }
00202
00203 void QDesignerSettings::setMainWindowState(const QByteArray &mainWindowState)
00204 {
00205 setValue(QLatin1String("MainWindowState"), mainWindowState);
00206 }
00207