tools/designer/src/designer/qdesigner_settings.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.
00004 **
00005 ** This file is part of the Qt Designer of the Qt Toolkit.
00006 **
00007 ** This file may be used under the terms of the GNU General Public
00008 ** License version 2.0 as published by the Free Software Foundation
00009 ** and appearing in the file LICENSE.GPL included in the packaging of
00010 ** this file.  Please review the following information to ensure GNU
00011 ** General Public Licensing requirements will be met:
00012 ** http://www.trolltech.com/products/qt/opensource.html
00013 **
00014 ** If you are unsure which license is appropriate for your use, please
00015 ** review the following information:
00016 ** http://www.trolltech.com/products/qt/licensing.html or contact the
00017 ** sales department at sales@trolltech.com.
00018 **
00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
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()) // in workspace
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 //    beginGroup();
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     // Do geometry in a couple of steps
00119     // 1) Make sure the rect is within the specified geometry
00120     // 2) Make sure the bottom right and top left fit on the screen, move them in.
00121     // 3) Check again and resize.
00122 
00123     if (w->isWindow() && g.intersect(screenRect).isEmpty())
00124         g = fallBack;
00125 
00126     // Maybe use center?
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()) // in workspace
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 //    endGroup();
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 

Generated on Thu Mar 15 12:01:20 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1