1
/****************************************************************************
3
** This file is part of the designer application of the Qt Toolkit.
5
** This file may be distributed under the terms of the Q Public License
6
** as defined by Trolltech AS of Norway and appearing in the file
7
** LICENSE.QPL included in the packaging of this file.
9
** This file may be distributed and/or modified under the terms of the
10
** GNU General Public License version 2 as published by the Free Software
11
** Foundation and appearing in the file LICENSE.GPL included in the
12
** packaging of this file.
14
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
15
** information about Qt Commercial License Agreements.
16
** See http://www.trolltech.com/qpl/ for QPL licensing information.
17
** See http://www.trolltech.com/gpl/ for GPL licensing information.
19
** Contact info@trolltech.com if any conditions of this licensing are
22
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
23
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
25
****************************************************************************/
27
#include "qdesigner.h"
28
#include "qdesigner_settings.h"
29
#include "qdesigner_widgetbox.h"
30
#include "qdesigner_workbench.h"
31
#include "qdesigner_propertyeditor.h"
32
#include "qdesigner_objectinspector.h"
34
#include <QtCore/QVariant>
35
#include <QtCore/QDir>
37
#include <QtGui/QDesktopWidget>
39
#include <QtCore/qdebug.h>
41
QDesignerSettings::QDesignerSettings()
44
m_designerPath = QLatin1String("/.designer");
46
QStringList paths = defaultFormTemplatePaths();
47
foreach (QString path, paths) {
48
if (!QDir::current().exists(path))
49
QDir::current().mkpath(path);
53
QDesignerSettings::~QDesignerSettings()
57
QStringList QDesignerSettings::formTemplatePaths() const
59
return value(QLatin1String("FormTemplatePaths"),
60
defaultFormTemplatePaths()).toStringList();
63
void QDesignerSettings::setFormTemplatePaths(const QStringList &paths)
65
setValue(QLatin1String("FormTemplatePaths"), paths);
68
QString QDesignerSettings::defaultUserWidgetBoxXml() const
70
return QDir::homePath() + m_designerPath + QLatin1String("/widgetbox.xml");
73
QStringList QDesignerSettings::defaultFormTemplatePaths() const
77
QString templatePath = QLatin1String("/templates");
79
paths.append(QDir::homePath() + m_designerPath + templatePath);
80
paths.append(qDesigner->applicationDirPath() + templatePath);
85
void QDesignerSettings::saveGeometryFor(const QWidget *w)
87
Q_ASSERT(w && !w->objectName().isEmpty());
88
saveGeometryHelper(w, w->objectName());
91
void QDesignerSettings::setGeometryFor(QWidget *w, const QRect &fallBack) const
93
Q_ASSERT(w && !w->objectName().isEmpty());
94
setGeometryHelper(w, w->objectName(),
95
fallBack.isNull() ? QRect(QPoint(0, 0), w->sizeHint()) : fallBack);
98
void QDesignerSettings::saveGeometryHelper(const QWidget *w, const QString &key)
101
QPoint pos = w->pos();
102
if (!w->isWindow()) // in workspace
103
pos = w->parentWidget()->pos();
105
setValue(QLatin1String("screen"), QApplication::desktop()->screenNumber(w));
106
setValue(QLatin1String("geometry"), QRect(pos, w->size()));
107
setValue(QLatin1String("visible"), w->isVisible());
108
setValue(QLatin1String("maximized"), w->isMaximized());
112
void QDesignerSettings::setGeometryHelper(QWidget *w, const QString &key,
113
const QRect &fallBack) const
116
int screen = value(key + QLatin1String("/screen"), 0).toInt();
117
QRect g = value(key + QLatin1String("/geometry"), fallBack).toRect();
119
if (w->isWindow() && g.intersect(QApplication::desktop()->availableGeometry(screen)).isEmpty()) {
123
if (value(key + QLatin1String("/maximized"), false).toBool()) {
124
w->setWindowState(w->windowState() | Qt::WindowMaximized);
126
if (!w->isWindow()) // in workspace
127
w->parentWidget()->move(g.topLeft());
129
w->move(g.topLeft());
133
if (value(key + QLatin1String("/visible"), true).toBool())
138
QStringList QDesignerSettings::recentFilesList() const
140
return value(QLatin1String("recentFilesList")).toStringList();
143
void QDesignerSettings::setRecentFilesList(const QStringList &sl)
145
setValue(QLatin1String("recentFilesList"), sl);
148
void QDesignerSettings::setShowNewFormOnStartup(bool showIt)
150
setValue(QLatin1String("newFormDialog/ShowOnStartup"), showIt);
153
bool QDesignerSettings::showNewFormOnStartup() const
155
return value(QLatin1String("newFormDialog/ShowOnStartup"), true).toBool();
158
void QDesignerSettings::setUIMode(int mode)
160
setValue(QLatin1String("UI/currentMode"), mode);
163
int QDesignerSettings::uiMode() const
165
return value(QLatin1String("UI/currentMode"), QDesignerWorkbench::TopLevelMode).toInt();
168
void QDesignerSettings::setUseBigIcons(bool useBig)
170
setValue(QLatin1String("UI/useBigIcons"), useBig);
173
bool QDesignerSettings::useBigIcons() const
175
return value(QLatin1String("UI/useBigIcons"),
184
QByteArray QDesignerSettings::mainWindowState() const
186
return value(QLatin1String("MainWindowState")).toByteArray();
189
void QDesignerSettings::setMainWindowState(const QByteArray &mainWindowState)
191
setValue(QLatin1String("MainWindowState"), mainWindowState);