~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to tools/designer/src/designer/qdesigner_settings.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** This file is part of the designer application of the Qt Toolkit.
 
4
**
 
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.
 
8
**
 
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.
 
13
**
 
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.
 
18
**
 
19
** Contact info@trolltech.com if any conditions of this licensing are
 
20
** not clear to you.
 
21
**
 
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.
 
24
**
 
25
****************************************************************************/
 
26
 
 
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"
 
33
 
 
34
#include <QtCore/QVariant>
 
35
#include <QtCore/QDir>
 
36
 
 
37
#include <QtGui/QDesktopWidget>
 
38
 
 
39
#include <QtCore/qdebug.h>
 
40
 
 
41
QDesignerSettings::QDesignerSettings()
 
42
    : QSettings()
 
43
{
 
44
    m_designerPath = QLatin1String("/.designer");
 
45
 
 
46
    QStringList paths = defaultFormTemplatePaths();
 
47
    foreach (QString path, paths) {
 
48
        if (!QDir::current().exists(path))
 
49
            QDir::current().mkpath(path);
 
50
    }
 
51
}
 
52
 
 
53
QDesignerSettings::~QDesignerSettings()
 
54
{
 
55
}
 
56
 
 
57
QStringList QDesignerSettings::formTemplatePaths() const
 
58
{
 
59
    return value(QLatin1String("FormTemplatePaths"),
 
60
                 defaultFormTemplatePaths()).toStringList();
 
61
}
 
62
 
 
63
void QDesignerSettings::setFormTemplatePaths(const QStringList &paths)
 
64
{
 
65
    setValue(QLatin1String("FormTemplatePaths"), paths);
 
66
}
 
67
 
 
68
QString QDesignerSettings::defaultUserWidgetBoxXml() const
 
69
{
 
70
    return QDir::homePath() + m_designerPath + QLatin1String("/widgetbox.xml");
 
71
}
 
72
 
 
73
QStringList QDesignerSettings::defaultFormTemplatePaths() const
 
74
{
 
75
    QStringList paths;
 
76
 
 
77
    QString templatePath = QLatin1String("/templates");
 
78
 
 
79
    paths.append(QDir::homePath() + m_designerPath + templatePath);
 
80
    paths.append(qDesigner->applicationDirPath() + templatePath);
 
81
 
 
82
    return paths;
 
83
}
 
84
 
 
85
void QDesignerSettings::saveGeometryFor(const QWidget *w)
 
86
{
 
87
    Q_ASSERT(w && !w->objectName().isEmpty());
 
88
    saveGeometryHelper(w, w->objectName());
 
89
}
 
90
 
 
91
void QDesignerSettings::setGeometryFor(QWidget *w, const QRect &fallBack) const
 
92
{
 
93
    Q_ASSERT(w && !w->objectName().isEmpty());
 
94
    setGeometryHelper(w, w->objectName(),
 
95
                      fallBack.isNull() ? QRect(QPoint(0, 0), w->sizeHint()) : fallBack);
 
96
}
 
97
 
 
98
void QDesignerSettings::saveGeometryHelper(const QWidget *w, const QString &key)
 
99
{
 
100
    beginGroup(key);
 
101
    QPoint pos = w->pos();
 
102
    if (!w->isWindow()) // in workspace
 
103
        pos = w->parentWidget()->pos();
 
104
 
 
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());
 
109
    endGroup();
 
110
}
 
111
 
 
112
void QDesignerSettings::setGeometryHelper(QWidget *w, const QString &key,
 
113
                                          const QRect &fallBack) const
 
114
{
 
115
//    beginGroup();
 
116
    int screen = value(key + QLatin1String("/screen"), 0).toInt();
 
117
    QRect g = value(key + QLatin1String("/geometry"), fallBack).toRect();
 
118
 
 
119
    if (w->isWindow() && g.intersect(QApplication::desktop()->availableGeometry(screen)).isEmpty()) {
 
120
        g = fallBack;
 
121
    }
 
122
 
 
123
    if (value(key + QLatin1String("/maximized"), false).toBool()) {
 
124
        w->setWindowState(w->windowState() | Qt::WindowMaximized);
 
125
    } else {
 
126
        if (!w->isWindow()) // in workspace
 
127
            w->parentWidget()->move(g.topLeft());
 
128
        else
 
129
            w->move(g.topLeft());
 
130
 
 
131
        w->resize(g.size());
 
132
    }
 
133
    if (value(key + QLatin1String("/visible"), true).toBool())
 
134
        w->show();
 
135
//    endGroup();
 
136
}
 
137
 
 
138
QStringList QDesignerSettings::recentFilesList() const
 
139
{
 
140
    return value(QLatin1String("recentFilesList")).toStringList();
 
141
}
 
142
 
 
143
void QDesignerSettings::setRecentFilesList(const QStringList &sl)
 
144
{
 
145
    setValue(QLatin1String("recentFilesList"), sl);
 
146
}
 
147
 
 
148
void QDesignerSettings::setShowNewFormOnStartup(bool showIt)
 
149
{
 
150
    setValue(QLatin1String("newFormDialog/ShowOnStartup"), showIt);
 
151
}
 
152
 
 
153
bool QDesignerSettings::showNewFormOnStartup() const
 
154
{
 
155
    return value(QLatin1String("newFormDialog/ShowOnStartup"), true).toBool();
 
156
}
 
157
 
 
158
void QDesignerSettings::setUIMode(int mode)
 
159
{
 
160
    setValue(QLatin1String("UI/currentMode"), mode);
 
161
}
 
162
 
 
163
int QDesignerSettings::uiMode() const
 
164
{
 
165
    return value(QLatin1String("UI/currentMode"), QDesignerWorkbench::TopLevelMode).toInt();
 
166
}
 
167
 
 
168
void QDesignerSettings::setUseBigIcons(bool useBig)
 
169
{
 
170
    setValue(QLatin1String("UI/useBigIcons"), useBig);
 
171
}
 
172
 
 
173
bool QDesignerSettings::useBigIcons() const
 
174
{
 
175
    return value(QLatin1String("UI/useBigIcons"),
 
176
#ifdef Q_WS_MAC
 
177
                 true
 
178
#else
 
179
                 false
 
180
#endif
 
181
            ).toBool();
 
182
}
 
183
 
 
184
QByteArray QDesignerSettings::mainWindowState() const
 
185
{
 
186
    return value(QLatin1String("MainWindowState")).toByteArray();
 
187
}
 
188
 
 
189
void QDesignerSettings::setMainWindowState(const QByteArray &mainWindowState)
 
190
{
 
191
    setValue(QLatin1String("MainWindowState"), mainWindowState);
 
192
}
 
193