彻底改版2.0
This commit is contained in:
429
third/designer/form/appfontdialog.cpp
Normal file
429
third/designer/form/appfontdialog.cpp
Normal file
@@ -0,0 +1,429 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the Qt Designer of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial Usage
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "appfontdialog.h"
|
||||
|
||||
#include <iconloader_p.h>
|
||||
#include <abstractsettings_p.h>
|
||||
|
||||
#include <QtGui/QTreeView>
|
||||
#include <QtGui/QToolButton>
|
||||
#include <QtGui/QHBoxLayout>
|
||||
#include <QtGui/QVBoxLayout>
|
||||
#include <QtGui/QSpacerItem>
|
||||
#include <QtGui/QFileDialog>
|
||||
#include <QtGui/QStandardItemModel>
|
||||
#include <QtGui/QMessageBox>
|
||||
#include <QtGui/QFontDatabase>
|
||||
#include <QtGui/QDialogButtonBox>
|
||||
|
||||
#include <QtCore/QSettings>
|
||||
#include <QtCore/QCoreApplication>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QFileInfo>
|
||||
#include <QtCore/QtAlgorithms>
|
||||
#include <QtCore/QVector>
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
enum {FileNameRole = Qt::UserRole + 1, IdRole = Qt::UserRole + 2 };
|
||||
enum { debugAppFontWidget = 0 };
|
||||
|
||||
static const char fontFileKeyC[] = "fontFiles";
|
||||
|
||||
// AppFontManager: Singleton that maintains the mapping of loaded application font
|
||||
// ids to the file names (which are not stored in QFontDatabase)
|
||||
// and provides API for loading/unloading fonts as well for saving/restoring settings.
|
||||
|
||||
class AppFontManager
|
||||
{
|
||||
Q_DISABLE_COPY(AppFontManager)
|
||||
AppFontManager();
|
||||
public:
|
||||
static AppFontManager &instance();
|
||||
|
||||
void save(QDesignerSettingsInterface *s, const QString &prefix) const;
|
||||
void restore(const QDesignerSettingsInterface *s, const QString &prefix);
|
||||
|
||||
// Return id or -1
|
||||
int add(const QString &fontFile, QString *errorMessage);
|
||||
|
||||
bool remove(int id, QString *errorMessage);
|
||||
bool remove(const QString &fontFile, QString *errorMessage);
|
||||
bool removeAt(int index, QString *errorMessage);
|
||||
|
||||
// Store loaded fonts as pair of file name and Id
|
||||
typedef QPair<QString,int> FileNameFontIdPair;
|
||||
typedef QList<FileNameFontIdPair> FileNameFontIdPairs;
|
||||
const FileNameFontIdPairs &fonts() const;
|
||||
|
||||
private:
|
||||
FileNameFontIdPairs m_fonts;
|
||||
};
|
||||
|
||||
AppFontManager::AppFontManager()
|
||||
{
|
||||
}
|
||||
|
||||
AppFontManager &AppFontManager::instance()
|
||||
{
|
||||
static AppFontManager rc;
|
||||
return rc;
|
||||
}
|
||||
|
||||
void AppFontManager::save(QDesignerSettingsInterface *s, const QString &prefix) const
|
||||
{
|
||||
// Store as list of file names
|
||||
QStringList fontFiles;
|
||||
const FileNameFontIdPairs::const_iterator cend = m_fonts.constEnd();
|
||||
for (FileNameFontIdPairs::const_iterator it = m_fonts.constBegin(); it != cend; ++it)
|
||||
fontFiles.push_back(it->first);
|
||||
|
||||
s->beginGroup(prefix);
|
||||
s->setValue(QLatin1String(fontFileKeyC), fontFiles);
|
||||
s->endGroup();
|
||||
|
||||
if (debugAppFontWidget)
|
||||
qDebug() << "AppFontManager::saved" << fontFiles.size() << "fonts under " << prefix;
|
||||
}
|
||||
|
||||
void AppFontManager::restore(const QDesignerSettingsInterface *s, const QString &prefix)
|
||||
{
|
||||
QString key = prefix;
|
||||
key += QLatin1Char('/');
|
||||
key += QLatin1String(fontFileKeyC);
|
||||
const QStringList fontFiles = s->value(key, QStringList()).toStringList();
|
||||
|
||||
if (debugAppFontWidget)
|
||||
qDebug() << "AppFontManager::restoring" << fontFiles.size() << "fonts from " << prefix;
|
||||
if (!fontFiles.empty()) {
|
||||
QString errorMessage;
|
||||
const QStringList::const_iterator cend = fontFiles.constEnd();
|
||||
for (QStringList::const_iterator it = fontFiles.constBegin(); it != cend; ++it)
|
||||
if (add(*it, &errorMessage) == -1)
|
||||
qWarning("%s", qPrintable(errorMessage));
|
||||
}
|
||||
}
|
||||
|
||||
int AppFontManager::add(const QString &fontFile, QString *errorMessage)
|
||||
{
|
||||
const QFileInfo inf(fontFile);
|
||||
if (!inf.isFile()) {
|
||||
*errorMessage = QCoreApplication::translate("AppFontManager", "'%1' is not a file.").arg(fontFile);
|
||||
return -1;
|
||||
}
|
||||
if (!inf.isReadable()) {
|
||||
*errorMessage = QCoreApplication::translate("AppFontManager", "The font file '%1' does not have read permissions.").arg(fontFile);
|
||||
return -1;
|
||||
}
|
||||
const QString fullPath = inf.absoluteFilePath();
|
||||
// Check if already loaded
|
||||
const FileNameFontIdPairs::const_iterator cend = m_fonts.constEnd();
|
||||
for (FileNameFontIdPairs::const_iterator it = m_fonts.constBegin(); it != cend; ++it) {
|
||||
if (it->first == fullPath) {
|
||||
*errorMessage = QCoreApplication::translate("AppFontManager", "The font file '%1' is already loaded.").arg(fontFile);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
const int id = QFontDatabase::addApplicationFont(fullPath);
|
||||
if (id == -1) {
|
||||
*errorMessage = QCoreApplication::translate("AppFontManager", "The font file '%1' could not be loaded.").arg(fontFile);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (debugAppFontWidget)
|
||||
qDebug() << "AppFontManager::add" << fontFile << id;
|
||||
m_fonts.push_back(FileNameFontIdPair(fullPath, id));
|
||||
return id;
|
||||
}
|
||||
|
||||
bool AppFontManager::remove(int id, QString *errorMessage)
|
||||
{
|
||||
const int count = m_fonts.size();
|
||||
for (int i = 0; i < count; i++)
|
||||
if (m_fonts[i].second == id)
|
||||
return removeAt(i, errorMessage);
|
||||
|
||||
*errorMessage = QCoreApplication::translate("AppFontManager", "'%1' is not a valid font id.").arg(id);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AppFontManager::remove(const QString &fontFile, QString *errorMessage)
|
||||
{
|
||||
const int count = m_fonts.size();
|
||||
for (int i = 0; i < count; i++)
|
||||
if (m_fonts[i].first == fontFile)
|
||||
return removeAt(i, errorMessage);
|
||||
|
||||
*errorMessage = QCoreApplication::translate("AppFontManager", "There is no loaded font matching the id '%1'.").arg(fontFile);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AppFontManager::removeAt(int index, QString *errorMessage)
|
||||
{
|
||||
Q_ASSERT(index >= 0 && index < m_fonts.size());
|
||||
|
||||
const QString fontFile = m_fonts[index].first;
|
||||
const int id = m_fonts[index].second;
|
||||
|
||||
if (debugAppFontWidget)
|
||||
qDebug() << "AppFontManager::removeAt" << index << '(' << fontFile << id << ')';
|
||||
|
||||
if (!QFontDatabase::removeApplicationFont(id)) {
|
||||
*errorMessage = QCoreApplication::translate("AppFontManager", "The font '%1' (%2) could not be unloaded.").arg(fontFile).arg(id);
|
||||
return false;
|
||||
}
|
||||
m_fonts.removeAt(index);
|
||||
return true;
|
||||
}
|
||||
|
||||
const AppFontManager::FileNameFontIdPairs &AppFontManager::fonts() const
|
||||
{
|
||||
return m_fonts;
|
||||
}
|
||||
|
||||
// ------------- AppFontModel
|
||||
class AppFontModel : public QStandardItemModel {
|
||||
Q_DISABLE_COPY(AppFontModel)
|
||||
public:
|
||||
AppFontModel(QObject *parent = 0);
|
||||
|
||||
void init(const AppFontManager &mgr);
|
||||
void add(const QString &fontFile, int id);
|
||||
int idAt(const QModelIndex &idx) const;
|
||||
};
|
||||
|
||||
AppFontModel::AppFontModel(QObject * parent) :
|
||||
QStandardItemModel(parent)
|
||||
{
|
||||
setHorizontalHeaderLabels(QStringList(AppFontWidget::tr("Fonts")));
|
||||
}
|
||||
|
||||
void AppFontModel::init(const AppFontManager &mgr)
|
||||
{
|
||||
typedef AppFontManager::FileNameFontIdPairs FileNameFontIdPairs;
|
||||
|
||||
const FileNameFontIdPairs &fonts = mgr.fonts();
|
||||
const FileNameFontIdPairs::const_iterator cend = fonts.constEnd();
|
||||
for (FileNameFontIdPairs::const_iterator it = fonts.constBegin(); it != cend; ++it)
|
||||
add(it->first, it->second);
|
||||
}
|
||||
|
||||
void AppFontModel::add(const QString &fontFile, int id)
|
||||
{
|
||||
const QFileInfo inf(fontFile);
|
||||
// Root item with base name
|
||||
QStandardItem *fileItem = new QStandardItem(inf.completeBaseName());
|
||||
const QString fullPath = inf.absoluteFilePath();
|
||||
fileItem->setData(fullPath, FileNameRole);
|
||||
fileItem->setToolTip(fullPath);
|
||||
fileItem->setData(id, IdRole);
|
||||
fileItem->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled);
|
||||
|
||||
appendRow(fileItem);
|
||||
const QStringList families = QFontDatabase::applicationFontFamilies(id);
|
||||
const QStringList::const_iterator cend = families.constEnd();
|
||||
for (QStringList::const_iterator it = families.constBegin(); it != cend; ++it) {
|
||||
QStandardItem *familyItem = new QStandardItem(*it);
|
||||
familyItem->setToolTip(fullPath);
|
||||
familyItem->setFont(QFont(*it));
|
||||
familyItem->setFlags(Qt::ItemIsEnabled);
|
||||
fileItem->appendRow(familyItem);
|
||||
}
|
||||
}
|
||||
|
||||
int AppFontModel::idAt(const QModelIndex &idx) const
|
||||
{
|
||||
if (const QStandardItem *item = itemFromIndex(idx))
|
||||
return item->data(IdRole).toInt();
|
||||
return -1;
|
||||
}
|
||||
|
||||
// ------------- AppFontWidget
|
||||
AppFontWidget::AppFontWidget(QWidget *parent) :
|
||||
QGroupBox(parent),
|
||||
m_view(new QTreeView),
|
||||
m_addButton(new QToolButton),
|
||||
m_removeButton(new QToolButton),
|
||||
m_removeAllButton(new QToolButton),
|
||||
m_model(new AppFontModel(this))
|
||||
{
|
||||
m_model->init(AppFontManager::instance());
|
||||
m_view->setModel(m_model);
|
||||
m_view->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||
m_view->expandAll();
|
||||
connect(m_view->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(selectionChanged(QItemSelection,QItemSelection)));
|
||||
|
||||
m_addButton->setToolTip(tr("Add font files"));
|
||||
m_addButton->setIcon(qdesigner_internal::createIconSet(QString::fromUtf8("plus.png")));
|
||||
connect(m_addButton, SIGNAL(clicked()), this, SLOT(addFiles()));
|
||||
|
||||
m_removeButton->setEnabled(false);
|
||||
m_removeButton->setToolTip(tr("Remove current font file"));
|
||||
m_removeButton->setIcon(qdesigner_internal::createIconSet(QString::fromUtf8("minus.png")));
|
||||
connect(m_removeButton, SIGNAL(clicked()), this, SLOT(slotRemoveFiles()));
|
||||
|
||||
m_removeAllButton->setToolTip(tr("Remove all font files"));
|
||||
m_removeAllButton->setIcon(qdesigner_internal::createIconSet(QString::fromUtf8("editdelete.png")));
|
||||
connect(m_removeAllButton, SIGNAL(clicked()), this, SLOT(slotRemoveAll()));
|
||||
|
||||
QHBoxLayout *hLayout = new QHBoxLayout;
|
||||
hLayout->addWidget(m_addButton);
|
||||
hLayout->addWidget(m_removeButton);
|
||||
hLayout->addWidget(m_removeAllButton);
|
||||
hLayout->addItem(new QSpacerItem(0, 0,QSizePolicy::MinimumExpanding));
|
||||
|
||||
QVBoxLayout *vLayout = new QVBoxLayout;
|
||||
vLayout->addWidget(m_view);
|
||||
vLayout->addLayout(hLayout);
|
||||
setLayout(vLayout);
|
||||
}
|
||||
|
||||
void AppFontWidget::addFiles()
|
||||
{
|
||||
const QStringList files =
|
||||
QFileDialog::getOpenFileNames(this, tr("Add Font Files"), QString(),
|
||||
tr("Font files (*.ttf)"));
|
||||
if (files.empty())
|
||||
return;
|
||||
|
||||
QString errorMessage;
|
||||
|
||||
AppFontManager &fmgr = AppFontManager::instance();
|
||||
const QStringList::const_iterator cend = files.constEnd();
|
||||
for (QStringList::const_iterator it = files.constBegin(); it != cend; ++it) {
|
||||
const int id = fmgr.add(*it, &errorMessage);
|
||||
if (id != -1) {
|
||||
m_model->add(*it, id);
|
||||
} else {
|
||||
QMessageBox::critical(this, tr("Error Adding Fonts"), errorMessage);
|
||||
}
|
||||
}
|
||||
m_view->expandAll();
|
||||
}
|
||||
|
||||
static void removeFonts(const QModelIndexList &selectedIndexes, AppFontModel *model, QWidget *dialogParent)
|
||||
{
|
||||
if (selectedIndexes.empty())
|
||||
return;
|
||||
|
||||
// Reverse sort top level rows and remove
|
||||
AppFontManager &fmgr = AppFontManager::instance();
|
||||
QVector<int> rows;
|
||||
rows.reserve(selectedIndexes.size());
|
||||
|
||||
QString errorMessage;
|
||||
const QModelIndexList::const_iterator cend = selectedIndexes.constEnd();
|
||||
for (QModelIndexList::const_iterator it = selectedIndexes.constBegin(); it != cend; ++it) {
|
||||
const int id = model->idAt(*it);
|
||||
if (id != -1) {
|
||||
if (fmgr.remove(id, &errorMessage)) {
|
||||
rows.push_back(it->row());
|
||||
} else {
|
||||
QMessageBox::critical(dialogParent, AppFontWidget::tr("Error Removing Fonts"), errorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
qStableSort(rows.begin(), rows.end());
|
||||
for (int i = rows.size() - 1; i >= 0; i--)
|
||||
model->removeRow(rows[i]);
|
||||
}
|
||||
|
||||
void AppFontWidget::slotRemoveFiles()
|
||||
{
|
||||
removeFonts(m_view->selectionModel()->selectedIndexes(), m_model, this);
|
||||
}
|
||||
|
||||
void AppFontWidget::slotRemoveAll()
|
||||
{
|
||||
const int count = m_model->rowCount();
|
||||
if (!count)
|
||||
return;
|
||||
|
||||
const QMessageBox::StandardButton answer =
|
||||
QMessageBox::question(this, tr("Remove Fonts"), tr("Would you like to remove all fonts?"),
|
||||
QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
|
||||
if (answer == QMessageBox::No)
|
||||
return;
|
||||
|
||||
QModelIndexList topLevels;
|
||||
for (int i = 0; i < count; i++)
|
||||
topLevels.push_back(m_model->index(i, 0));
|
||||
removeFonts(topLevels, m_model, this);
|
||||
}
|
||||
|
||||
void AppFontWidget::selectionChanged(const QItemSelection &selected, const QItemSelection & /*deselected*/)
|
||||
{
|
||||
m_removeButton->setEnabled(!selected.indexes().empty());
|
||||
}
|
||||
|
||||
void AppFontWidget::save(QDesignerSettingsInterface *s, const QString &prefix)
|
||||
{
|
||||
AppFontManager::instance().save(s, prefix);
|
||||
}
|
||||
|
||||
void AppFontWidget::restore(const QDesignerSettingsInterface *s, const QString &prefix)
|
||||
{
|
||||
AppFontManager::instance().restore(s, prefix);
|
||||
}
|
||||
|
||||
// ------------ AppFontDialog
|
||||
AppFontDialog::AppFontDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
m_appFontWidget(new AppFontWidget)
|
||||
{
|
||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
setWindowTitle(tr("Additional Fonts"));
|
||||
setModal(false);
|
||||
QVBoxLayout *vl = new QVBoxLayout;
|
||||
vl->addWidget(m_appFontWidget);
|
||||
|
||||
QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close);
|
||||
QDialog::connect(bb, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
vl->addWidget(bb);
|
||||
setLayout(vl);
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
101
third/designer/form/appfontdialog.h
Normal file
101
third/designer/form/appfontdialog.h
Normal file
@@ -0,0 +1,101 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the Qt Designer of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial Usage
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QDESIGNER_APPFONTWIDGET_H
|
||||
#define QDESIGNER_APPFONTWIDGET_H
|
||||
|
||||
#include <QtGui/QGroupBox>
|
||||
#include <QtGui/QDialog>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class AppFontModel;
|
||||
|
||||
class QTreeView;
|
||||
class QToolButton;
|
||||
class QItemSelection;
|
||||
class QDesignerSettingsInterface;
|
||||
|
||||
// AppFontWidget: Manages application fonts which the user can load and
|
||||
// provides API for saving/restoring them.
|
||||
|
||||
class AppFontWidget : public QGroupBox
|
||||
{
|
||||
Q_DISABLE_COPY(AppFontWidget)
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit AppFontWidget(QWidget *parent = 0);
|
||||
|
||||
QStringList fontFiles() const;
|
||||
|
||||
static void save(QDesignerSettingsInterface *s, const QString &prefix);
|
||||
static void restore(const QDesignerSettingsInterface *s, const QString &prefix);
|
||||
|
||||
private slots:
|
||||
void addFiles();
|
||||
void slotRemoveFiles();
|
||||
void slotRemoveAll();
|
||||
void selectionChanged(const QItemSelection & selected, const QItemSelection & deselected);
|
||||
|
||||
private:
|
||||
QTreeView *m_view;
|
||||
QToolButton *m_addButton;
|
||||
QToolButton *m_removeButton;
|
||||
QToolButton *m_removeAllButton;
|
||||
AppFontModel *m_model;
|
||||
};
|
||||
|
||||
// AppFontDialog: Non modal dialog for AppFontWidget which has Qt::WA_DeleteOnClose set.
|
||||
|
||||
class AppFontDialog : public QDialog
|
||||
{
|
||||
Q_DISABLE_COPY(AppFontDialog)
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit AppFontDialog(QWidget *parent = 0);
|
||||
|
||||
private:
|
||||
AppFontWidget *m_appFontWidget;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QDESIGNER_APPFONTWIDGET_H
|
||||
175
third/designer/form/assistantclient.cpp
Normal file
175
third/designer/form/assistantclient.cpp
Normal file
@@ -0,0 +1,175 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the Qt Designer of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial Usage
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "assistantclient.h"
|
||||
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QProcess>
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QLibraryInfo>
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtCore/QFileInfo>
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QTextStream>
|
||||
#include <QtCore/QCoreApplication>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
enum { debugAssistantClient = 0 };
|
||||
|
||||
AssistantClient::AssistantClient() :
|
||||
m_process(0)
|
||||
{
|
||||
}
|
||||
|
||||
AssistantClient::~AssistantClient()
|
||||
{
|
||||
if (isRunning()) {
|
||||
m_process->terminate();
|
||||
m_process->waitForFinished();
|
||||
}
|
||||
delete m_process;
|
||||
}
|
||||
|
||||
bool AssistantClient::showPage(const QString &path, QString *errorMessage)
|
||||
{
|
||||
QString cmd = QLatin1String("SetSource ");
|
||||
cmd += path;
|
||||
return sendCommand(cmd, errorMessage);
|
||||
}
|
||||
|
||||
bool AssistantClient::activateIdentifier(const QString &identifier, QString *errorMessage)
|
||||
{
|
||||
QString cmd = QLatin1String("ActivateIdentifier ");
|
||||
cmd += identifier;
|
||||
return sendCommand(cmd, errorMessage);
|
||||
}
|
||||
|
||||
bool AssistantClient::activateKeyword(const QString &keyword, QString *errorMessage)
|
||||
{
|
||||
QString cmd = QLatin1String("ActivateKeyword ");
|
||||
cmd += keyword;
|
||||
return sendCommand(cmd, errorMessage);
|
||||
}
|
||||
|
||||
bool AssistantClient::sendCommand(const QString &cmd, QString *errorMessage)
|
||||
{
|
||||
if (debugAssistantClient)
|
||||
qDebug() << "sendCommand " << cmd;
|
||||
if (!ensureRunning(errorMessage))
|
||||
return false;
|
||||
if (!m_process->isWritable() || m_process->bytesToWrite() > 0) {
|
||||
*errorMessage = QCoreApplication::translate("AssistantClient", "Unable to send request: Assistant is not responding.");
|
||||
return false;
|
||||
}
|
||||
QTextStream str(m_process);
|
||||
str << cmd << QLatin1Char('\n') << endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AssistantClient::isRunning() const
|
||||
{
|
||||
return m_process && m_process->state() != QProcess::NotRunning;
|
||||
}
|
||||
|
||||
QString AssistantClient::binary()
|
||||
{
|
||||
QString app = QLibraryInfo::location(QLibraryInfo::BinariesPath) + QDir::separator();
|
||||
#if !defined(Q_OS_MAC)
|
||||
app += QLatin1String("assistant");
|
||||
#else
|
||||
app += QLatin1String("Assistant.app/Contents/MacOS/Assistant");
|
||||
#endif
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
app += QLatin1String(".exe");
|
||||
#endif
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
bool AssistantClient::ensureRunning(QString *errorMessage)
|
||||
{
|
||||
if (isRunning())
|
||||
return true;
|
||||
|
||||
if (!m_process)
|
||||
m_process = new QProcess;
|
||||
|
||||
const QString app = binary();
|
||||
if (!QFileInfo(app).isFile()) {
|
||||
*errorMessage = QCoreApplication::translate("AssistantClient", "The binary '%1' does not exist.").arg(app);
|
||||
return false;
|
||||
}
|
||||
if (debugAssistantClient)
|
||||
qDebug() << "Running " << app;
|
||||
// run
|
||||
QStringList args(QLatin1String("-enableRemoteControl"));
|
||||
m_process->start(app, args);
|
||||
if (!m_process->waitForStarted()) {
|
||||
*errorMessage = QCoreApplication::translate("AssistantClient", "Unable to launch assistant (%1).").arg(app);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
QString AssistantClient::documentUrl(const QString &prefix, int qtVersion)
|
||||
{
|
||||
if (qtVersion == 0)
|
||||
qtVersion = QT_VERSION;
|
||||
QString rc;
|
||||
QTextStream(&rc) << QLatin1String("qthelp://com.trolltech.") << prefix << QLatin1Char('.')
|
||||
<< (qtVersion >> 16) << ((qtVersion >> 8) & 0xFF) << (qtVersion & 0xFF)
|
||||
<< QLatin1String("/qdoc/");
|
||||
return rc;
|
||||
}
|
||||
|
||||
QString AssistantClient::designerManualUrl(int qtVersion)
|
||||
{
|
||||
return documentUrl(QLatin1String("designer"), qtVersion);
|
||||
}
|
||||
|
||||
QString AssistantClient::qtReferenceManualUrl(int qtVersion)
|
||||
{
|
||||
return documentUrl(QLatin1String("qt"), qtVersion);
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
83
third/designer/form/assistantclient.h
Normal file
83
third/designer/form/assistantclient.h
Normal file
@@ -0,0 +1,83 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the Qt Designer of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial Usage
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef ASSISTANTCLIENT_H
|
||||
#define ASSISTANTCLIENT_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QProcess;
|
||||
class QString;
|
||||
|
||||
class AssistantClient
|
||||
{
|
||||
AssistantClient(const AssistantClient &);
|
||||
AssistantClient &operator=(const AssistantClient &);
|
||||
|
||||
public:
|
||||
AssistantClient();
|
||||
~AssistantClient();
|
||||
|
||||
bool showPage(const QString &path, QString *errorMessage);
|
||||
bool activateIdentifier(const QString &identifier, QString *errorMessage);
|
||||
bool activateKeyword(const QString &keyword, QString *errorMessage);
|
||||
|
||||
bool isRunning() const;
|
||||
|
||||
static QString documentUrl(const QString &prefix, int qtVersion = 0);
|
||||
// Root of the Qt Designer documentation
|
||||
static QString designerManualUrl(int qtVersion = 0);
|
||||
// Root of the Qt Reference documentation
|
||||
static QString qtReferenceManualUrl(int qtVersion = 0);
|
||||
|
||||
private:
|
||||
static QString binary();
|
||||
bool sendCommand(const QString &cmd, QString *errorMessage);
|
||||
bool ensureRunning(QString *errorMessage);
|
||||
|
||||
QProcess *m_process;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // ASSISTANTCLIENT_H
|
||||
308
third/designer/form/fontpanel.cpp
Normal file
308
third/designer/form/fontpanel.cpp
Normal file
@@ -0,0 +1,308 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the tools applications of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial Usage
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "fontpanel.h"
|
||||
|
||||
#include <QtGui/QLabel>
|
||||
#include <QtGui/QComboBox>
|
||||
#include <QtGui/QFormLayout>
|
||||
#include <QtGui/QSpacerItem>
|
||||
#include <QtGui/QFontComboBox>
|
||||
#include <QtCore/QTimer>
|
||||
#include <QtGui/QLineEdit>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
FontPanel::FontPanel(QWidget *parentWidget) :
|
||||
QGroupBox(parentWidget),
|
||||
m_previewLineEdit(new QLineEdit),
|
||||
m_writingSystemComboBox(new QComboBox),
|
||||
m_familyComboBox(new QFontComboBox),
|
||||
m_styleComboBox(new QComboBox),
|
||||
m_pointSizeComboBox(new QComboBox),
|
||||
m_previewFontUpdateTimer(0)
|
||||
{
|
||||
setTitle(tr("Font"));
|
||||
|
||||
QFormLayout *formLayout = new QFormLayout(this);
|
||||
// writing systems
|
||||
m_writingSystemComboBox->setEditable(false);
|
||||
|
||||
QList<QFontDatabase::WritingSystem> writingSystems = m_fontDatabase.writingSystems();
|
||||
writingSystems.push_front(QFontDatabase::Any);
|
||||
foreach (QFontDatabase::WritingSystem ws, writingSystems)
|
||||
m_writingSystemComboBox->addItem(QFontDatabase::writingSystemName(ws), QVariant(ws));
|
||||
connect(m_writingSystemComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotWritingSystemChanged(int)));
|
||||
formLayout->addRow(tr("&Writing system"), m_writingSystemComboBox);
|
||||
|
||||
connect(m_familyComboBox, SIGNAL(currentFontChanged(QFont)), this, SLOT(slotFamilyChanged(QFont)));
|
||||
formLayout->addRow(tr("&Family"), m_familyComboBox);
|
||||
|
||||
m_styleComboBox->setEditable(false);
|
||||
connect(m_styleComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotStyleChanged(int)));
|
||||
formLayout->addRow(tr("&Style"), m_styleComboBox);
|
||||
|
||||
m_pointSizeComboBox->setEditable(false);
|
||||
connect(m_pointSizeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotPointSizeChanged(int)));
|
||||
formLayout->addRow(tr("&Point size"), m_pointSizeComboBox);
|
||||
|
||||
m_previewLineEdit->setReadOnly(true);
|
||||
formLayout->addRow(m_previewLineEdit);
|
||||
|
||||
setWritingSystem(QFontDatabase::Any);
|
||||
}
|
||||
|
||||
QFont FontPanel::selectedFont() const
|
||||
{
|
||||
QFont rc = m_familyComboBox->currentFont();
|
||||
const QString family = rc.family();
|
||||
rc.setPointSize(pointSize());
|
||||
const QString styleDescription = styleString();
|
||||
if (styleDescription.contains(QLatin1String("Italic")))
|
||||
rc.setStyle(QFont::StyleItalic);
|
||||
else if (styleDescription.contains(QLatin1String("Oblique")))
|
||||
rc.setStyle(QFont::StyleOblique);
|
||||
else
|
||||
rc.setStyle(QFont::StyleNormal);
|
||||
rc.setBold(m_fontDatabase.bold(family, styleDescription));
|
||||
|
||||
// Weight < 0 asserts...
|
||||
const int weight = m_fontDatabase.weight(family, styleDescription);
|
||||
if (weight >= 0)
|
||||
rc.setWeight(weight);
|
||||
return rc;
|
||||
}
|
||||
|
||||
void FontPanel::setSelectedFont(const QFont &f)
|
||||
{
|
||||
m_familyComboBox->setCurrentFont(f);
|
||||
if (m_familyComboBox->currentIndex() < 0) {
|
||||
// family not in writing system - find the corresponding one?
|
||||
QList<QFontDatabase::WritingSystem> familyWritingSystems = m_fontDatabase.writingSystems(f.family());
|
||||
if (familyWritingSystems.empty())
|
||||
return;
|
||||
|
||||
setWritingSystem(familyWritingSystems.front());
|
||||
m_familyComboBox->setCurrentFont(f);
|
||||
}
|
||||
|
||||
updateFamily(family());
|
||||
|
||||
const int pointSizeIndex = closestPointSizeIndex(f.pointSize());
|
||||
m_pointSizeComboBox->setCurrentIndex( pointSizeIndex);
|
||||
|
||||
const QString styleString = m_fontDatabase.styleString(f);
|
||||
const int styleIndex = m_styleComboBox->findText(styleString);
|
||||
m_styleComboBox->setCurrentIndex(styleIndex);
|
||||
slotUpdatePreviewFont();
|
||||
}
|
||||
|
||||
|
||||
QFontDatabase::WritingSystem FontPanel::writingSystem() const
|
||||
{
|
||||
const int currentIndex = m_writingSystemComboBox->currentIndex();
|
||||
if ( currentIndex == -1)
|
||||
return QFontDatabase::Latin;
|
||||
return static_cast<QFontDatabase::WritingSystem>(m_writingSystemComboBox->itemData(currentIndex).toInt());
|
||||
}
|
||||
|
||||
QString FontPanel::family() const
|
||||
{
|
||||
const int currentIndex = m_familyComboBox->currentIndex();
|
||||
return currentIndex != -1 ? m_familyComboBox->currentFont().family() : QString();
|
||||
}
|
||||
|
||||
int FontPanel::pointSize() const
|
||||
{
|
||||
const int currentIndex = m_pointSizeComboBox->currentIndex();
|
||||
return currentIndex != -1 ? m_pointSizeComboBox->itemData(currentIndex).toInt() : 9;
|
||||
}
|
||||
|
||||
QString FontPanel::styleString() const
|
||||
{
|
||||
const int currentIndex = m_styleComboBox->currentIndex();
|
||||
return currentIndex != -1 ? m_styleComboBox->itemText(currentIndex) : QString();
|
||||
}
|
||||
|
||||
void FontPanel::setWritingSystem(QFontDatabase::WritingSystem ws)
|
||||
{
|
||||
m_writingSystemComboBox->setCurrentIndex(m_writingSystemComboBox->findData(QVariant(ws)));
|
||||
updateWritingSystem(ws);
|
||||
}
|
||||
|
||||
|
||||
void FontPanel::slotWritingSystemChanged(int)
|
||||
{
|
||||
updateWritingSystem(writingSystem());
|
||||
delayedPreviewFontUpdate();
|
||||
}
|
||||
|
||||
void FontPanel::slotFamilyChanged(const QFont &)
|
||||
{
|
||||
updateFamily(family());
|
||||
delayedPreviewFontUpdate();
|
||||
}
|
||||
|
||||
void FontPanel::slotStyleChanged(int)
|
||||
{
|
||||
updatePointSizes(family(), styleString());
|
||||
delayedPreviewFontUpdate();
|
||||
}
|
||||
|
||||
void FontPanel::slotPointSizeChanged(int)
|
||||
{
|
||||
delayedPreviewFontUpdate();
|
||||
}
|
||||
|
||||
void FontPanel::updateWritingSystem(QFontDatabase::WritingSystem ws)
|
||||
{
|
||||
|
||||
m_previewLineEdit->setText(QFontDatabase::writingSystemSample(ws));
|
||||
m_familyComboBox->setWritingSystem (ws);
|
||||
// Current font not in WS ... set index 0.
|
||||
if (m_familyComboBox->currentIndex() < 0) {
|
||||
m_familyComboBox->setCurrentIndex(0);
|
||||
updateFamily(family());
|
||||
}
|
||||
}
|
||||
|
||||
void FontPanel::updateFamily(const QString &family)
|
||||
{
|
||||
// Update styles and trigger update of point sizes.
|
||||
// Try to maintain selection or select normal
|
||||
const QString oldStyleString = styleString();
|
||||
|
||||
const QStringList styles = m_fontDatabase.styles(family);
|
||||
const bool hasStyles = !styles.empty();
|
||||
|
||||
m_styleComboBox->setCurrentIndex(-1);
|
||||
m_styleComboBox->clear();
|
||||
m_styleComboBox->setEnabled(hasStyles);
|
||||
|
||||
int normalIndex = -1;
|
||||
const QString normalStyle = QLatin1String("Normal");
|
||||
|
||||
if (hasStyles) {
|
||||
foreach (const QString &style, styles) {
|
||||
// try to maintain selection or select 'normal' preferably
|
||||
const int newIndex = m_styleComboBox->count();
|
||||
m_styleComboBox->addItem(style);
|
||||
if (oldStyleString == style) {
|
||||
m_styleComboBox->setCurrentIndex(newIndex);
|
||||
} else {
|
||||
if (oldStyleString == normalStyle)
|
||||
normalIndex = newIndex;
|
||||
}
|
||||
}
|
||||
if (m_styleComboBox->currentIndex() == -1 && normalIndex != -1)
|
||||
m_styleComboBox->setCurrentIndex(normalIndex);
|
||||
}
|
||||
updatePointSizes(family, styleString());
|
||||
}
|
||||
|
||||
int FontPanel::closestPointSizeIndex(int desiredPointSize) const
|
||||
{
|
||||
// try to maintain selection or select closest.
|
||||
int closestIndex = -1;
|
||||
int closestAbsError = 0xFFFF;
|
||||
|
||||
const int pointSizeCount = m_pointSizeComboBox->count();
|
||||
for (int i = 0; i < pointSizeCount; i++) {
|
||||
const int itemPointSize = m_pointSizeComboBox->itemData(i).toInt();
|
||||
const int absError = qAbs(desiredPointSize - itemPointSize);
|
||||
if (absError < closestAbsError) {
|
||||
closestIndex = i;
|
||||
closestAbsError = absError;
|
||||
if (closestAbsError == 0)
|
||||
break;
|
||||
} else { // past optimum
|
||||
if (absError > closestAbsError) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return closestIndex;
|
||||
}
|
||||
|
||||
|
||||
void FontPanel::updatePointSizes(const QString &family, const QString &styleString)
|
||||
{
|
||||
const int oldPointSize = pointSize();
|
||||
|
||||
QList<int> pointSizes = m_fontDatabase.pointSizes(family, styleString);
|
||||
if (pointSizes.empty())
|
||||
pointSizes = QFontDatabase::standardSizes();
|
||||
|
||||
const bool hasSizes = !pointSizes.empty();
|
||||
m_pointSizeComboBox->clear();
|
||||
m_pointSizeComboBox->setEnabled(hasSizes);
|
||||
m_pointSizeComboBox->setCurrentIndex(-1);
|
||||
|
||||
// try to maintain selection or select closest.
|
||||
if (hasSizes) {
|
||||
QString n;
|
||||
foreach (int pointSize, pointSizes)
|
||||
m_pointSizeComboBox->addItem(n.setNum(pointSize), QVariant(pointSize));
|
||||
const int closestIndex = closestPointSizeIndex(oldPointSize);
|
||||
if (closestIndex != -1)
|
||||
m_pointSizeComboBox->setCurrentIndex(closestIndex);
|
||||
}
|
||||
}
|
||||
|
||||
void FontPanel::slotUpdatePreviewFont()
|
||||
{
|
||||
m_previewLineEdit->setFont(selectedFont());
|
||||
}
|
||||
|
||||
void FontPanel::delayedPreviewFontUpdate()
|
||||
{
|
||||
if (!m_previewFontUpdateTimer) {
|
||||
m_previewFontUpdateTimer = new QTimer(this);
|
||||
connect(m_previewFontUpdateTimer, SIGNAL(timeout()), this, SLOT(slotUpdatePreviewFont()));
|
||||
m_previewFontUpdateTimer->setInterval(0);
|
||||
m_previewFontUpdateTimer->setSingleShot(true);
|
||||
}
|
||||
if (m_previewFontUpdateTimer->isActive())
|
||||
return;
|
||||
m_previewFontUpdateTimer->start();
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
108
third/designer/form/fontpanel.h
Normal file
108
third/designer/form/fontpanel.h
Normal file
@@ -0,0 +1,108 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the tools applications of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial Usage
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
// -------------
|
||||
//
|
||||
// This file is not part of the Qt API. It exists for the convenience
|
||||
// of the Qt tools. This header
|
||||
// file may change from version to version without notice, or even be removed.
|
||||
//
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
#ifndef FONTPANEL_H
|
||||
#define FONTPANEL_H
|
||||
|
||||
#include <QtGui/QGroupBox>
|
||||
#include <QtGui/QFont>
|
||||
#include <QtGui/QFontDatabase>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QComboBox;
|
||||
class QFontComboBox;
|
||||
class QTimer;
|
||||
class QLineEdit;
|
||||
|
||||
class FontPanel: public QGroupBox
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
FontPanel(QWidget *parentWidget = 0);
|
||||
|
||||
QFont selectedFont() const;
|
||||
void setSelectedFont(const QFont &);
|
||||
|
||||
QFontDatabase::WritingSystem writingSystem() const;
|
||||
void setWritingSystem(QFontDatabase::WritingSystem ws);
|
||||
|
||||
private slots:
|
||||
void slotWritingSystemChanged(int);
|
||||
void slotFamilyChanged(const QFont &);
|
||||
void slotStyleChanged(int);
|
||||
void slotPointSizeChanged(int);
|
||||
void slotUpdatePreviewFont();
|
||||
|
||||
private:
|
||||
QString family() const;
|
||||
QString styleString() const;
|
||||
int pointSize() const;
|
||||
int closestPointSizeIndex(int ps) const;
|
||||
|
||||
void updateWritingSystem(QFontDatabase::WritingSystem ws);
|
||||
void updateFamily(const QString &family);
|
||||
void updatePointSizes(const QString &family, const QString &style);
|
||||
void delayedPreviewFontUpdate();
|
||||
|
||||
QFontDatabase m_fontDatabase;
|
||||
QLineEdit *m_previewLineEdit;
|
||||
QComboBox *m_writingSystemComboBox;
|
||||
QFontComboBox* m_familyComboBox;
|
||||
QComboBox *m_styleComboBox;
|
||||
QComboBox *m_pointSizeComboBox;
|
||||
QTimer *m_previewFontUpdateTimer;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // FONTPANEL_H
|
||||
26
third/designer/form/form.pri
Normal file
26
third/designer/form/form.pri
Normal file
@@ -0,0 +1,26 @@
|
||||
FORMS += \
|
||||
$$PWD/preferencesdialog.ui \
|
||||
$$PWD/qttoolbardialog.ui \
|
||||
$$PWD/saveformastemplate.ui
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/appfontdialog.h \
|
||||
$$PWD/assistantclient.h \
|
||||
$$PWD/fontpanel.h \
|
||||
$$PWD/mainwindow.h \
|
||||
$$PWD/newform.h \
|
||||
$$PWD/preferencesdialog.h \
|
||||
$$PWD/qttoolbardialog.h \
|
||||
$$PWD/saveformastemplate.h \
|
||||
$$PWD/versiondialog.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/appfontdialog.cpp \
|
||||
$$PWD/assistantclient.cpp \
|
||||
$$PWD/fontpanel.cpp \
|
||||
$$PWD/mainwindow.cpp \
|
||||
$$PWD/newform.cpp \
|
||||
$$PWD/preferencesdialog.cpp \
|
||||
$$PWD/qttoolbardialog.cpp \
|
||||
$$PWD/saveformastemplate.cpp \
|
||||
$$PWD/versiondialog.cpp
|
||||
419
third/designer/form/mainwindow.cpp
Normal file
419
third/designer/form/mainwindow.cpp
Normal file
@@ -0,0 +1,419 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the Qt Designer of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial Usage
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "qdesigner.h"
|
||||
#include "qdesigner_actions.h"
|
||||
#include "qdesigner_workbench.h"
|
||||
#include "qdesigner_formwindow.h"
|
||||
#include "qdesigner_toolwindow.h"
|
||||
#include "qdesigner_settings.h"
|
||||
#include "qttoolbardialog.h"
|
||||
|
||||
#include <QtDesigner/QDesignerFormWindowInterface>
|
||||
|
||||
#include <QtGui/QAction>
|
||||
#include <QtGui/QCloseEvent>
|
||||
#include <QtGui/QToolBar>
|
||||
#include <QtGui/QMdiSubWindow>
|
||||
#include <QtGui/QStatusBar>
|
||||
#include <QtGui/QMenu>
|
||||
#include <QtGui/QLayout>
|
||||
#include <QtGui/QDockWidget>
|
||||
|
||||
#include <QtCore/QUrl>
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
static const char *uriListMimeFormatC = "text/uri-list";
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
typedef QList<QAction *> ActionList;
|
||||
|
||||
// Helpers for creating toolbars and menu
|
||||
|
||||
static void addActionsToToolBar(const ActionList &actions, QToolBar *t)
|
||||
{
|
||||
const ActionList::const_iterator cend = actions.constEnd();
|
||||
for (ActionList::const_iterator it = actions.constBegin(); it != cend; ++it) {
|
||||
QAction *action = *it;
|
||||
if (action->property(QDesignerActions::defaultToolbarPropertyName).toBool())
|
||||
t->addAction(action);
|
||||
}
|
||||
}
|
||||
static QToolBar *createToolBar(const QString &title, const QString &objectName, const ActionList &actions)
|
||||
{
|
||||
QToolBar *rc = new QToolBar;
|
||||
rc->setObjectName(objectName);
|
||||
rc->setWindowTitle(title);
|
||||
addActionsToToolBar(actions, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
// ---------------- MainWindowBase
|
||||
|
||||
MainWindowBase::MainWindowBase(QWidget *parent, Qt::WindowFlags flags) :
|
||||
QMainWindow(parent, flags),
|
||||
m_policy(AcceptCloseEvents)
|
||||
{
|
||||
#ifndef Q_WS_MAC
|
||||
setWindowIcon(qDesigner->windowIcon());
|
||||
#endif
|
||||
}
|
||||
|
||||
void MainWindowBase::closeEvent(QCloseEvent *e)
|
||||
{
|
||||
switch (m_policy) {
|
||||
case AcceptCloseEvents:
|
||||
QMainWindow::closeEvent(e);
|
||||
break;
|
||||
case EmitCloseEventSignal:
|
||||
emit closeEventReceived(e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QList<QToolBar *> MainWindowBase::createToolBars(const QDesignerActions *actions, bool singleToolBar)
|
||||
{
|
||||
// Note that whenever you want to add a new tool bar here, you also have to update the default
|
||||
// action groups added to the toolbar manager in the mainwindow constructor
|
||||
QList<QToolBar *> rc;
|
||||
if (singleToolBar) {
|
||||
//: Not currently used (main tool bar)
|
||||
QToolBar *main = createToolBar(tr("Main"), QLatin1String("mainToolBar"), actions->fileActions()->actions());
|
||||
addActionsToToolBar(actions->editActions()->actions(), main);
|
||||
addActionsToToolBar(actions->toolActions()->actions(), main);
|
||||
addActionsToToolBar(actions->formActions()->actions(), main);
|
||||
rc.push_back(main);
|
||||
} else {
|
||||
rc.push_back(createToolBar(tr("File"), QLatin1String("fileToolBar"), actions->fileActions()->actions()));
|
||||
rc.push_back(createToolBar(tr("Edit"), QLatin1String("editToolBar"), actions->editActions()->actions()));
|
||||
rc.push_back(createToolBar(tr("Tools"), QLatin1String("toolsToolBar"), actions->toolActions()->actions()));
|
||||
rc.push_back(createToolBar(tr("Form"), QLatin1String("formToolBar"), actions->formActions()->actions()));
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
QString MainWindowBase::mainWindowTitle()
|
||||
{
|
||||
return tr("Qt Designer");
|
||||
}
|
||||
|
||||
// Use the minor Qt version as settings versions to avoid conflicts
|
||||
int MainWindowBase::settingsVersion()
|
||||
{
|
||||
const int version = QT_VERSION;
|
||||
return (version & 0x00FF00) >> 8;
|
||||
}
|
||||
|
||||
// ----------------- DockedMdiArea
|
||||
|
||||
DockedMdiArea::DockedMdiArea(const QString &extension, QWidget *parent) :
|
||||
QMdiArea(parent),
|
||||
m_extension(extension)
|
||||
{
|
||||
setAcceptDrops(true);
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
}
|
||||
|
||||
QStringList DockedMdiArea::uiFiles(const QMimeData *d) const
|
||||
{
|
||||
// Extract dropped UI files from Mime data.
|
||||
QStringList rc;
|
||||
if (!d->hasFormat(QLatin1String(uriListMimeFormatC)))
|
||||
return rc;
|
||||
const QList<QUrl> urls = d->urls();
|
||||
if (urls.empty())
|
||||
return rc;
|
||||
const QList<QUrl>::const_iterator cend = urls.constEnd();
|
||||
for (QList<QUrl>::const_iterator it = urls.constBegin(); it != cend; ++it) {
|
||||
const QString fileName = it->toLocalFile();
|
||||
if (!fileName.isEmpty() && fileName.endsWith(m_extension))
|
||||
rc.push_back(fileName);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
bool DockedMdiArea::event(QEvent *event)
|
||||
{
|
||||
// Listen for desktop file manager drop and emit a signal once a file is
|
||||
// dropped.
|
||||
switch (event->type()) {
|
||||
case QEvent::DragEnter: {
|
||||
QDragEnterEvent *e = static_cast<QDragEnterEvent*>(event);
|
||||
if (!uiFiles(e->mimeData()).empty()) {
|
||||
e->acceptProposedAction();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case QEvent::Drop: {
|
||||
QDropEvent *e = static_cast<QDropEvent*>(event);
|
||||
const QStringList files = uiFiles(e->mimeData());
|
||||
const QStringList::const_iterator cend = files.constEnd();
|
||||
for (QStringList::const_iterator it = files.constBegin(); it != cend; ++it) {
|
||||
emit fileDropped(*it);
|
||||
}
|
||||
e->acceptProposedAction();
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return QMdiArea::event(event);
|
||||
}
|
||||
|
||||
// ------------- ToolBarManager:
|
||||
|
||||
static void addActionsToToolBarManager(const ActionList &al, const QString &title, QtToolBarManager *tbm)
|
||||
{
|
||||
const ActionList::const_iterator cend = al.constEnd();
|
||||
for (ActionList::const_iterator it = al.constBegin(); it != cend; ++it)
|
||||
tbm->addAction(*it, title);
|
||||
}
|
||||
|
||||
ToolBarManager::ToolBarManager(QMainWindow *configureableMainWindow,
|
||||
QWidget *parent,
|
||||
QMenu *toolBarMenu,
|
||||
const QDesignerActions *actions,
|
||||
const QList<QToolBar *> &toolbars,
|
||||
const QList<QDesignerToolWindow*> &toolWindows) :
|
||||
QObject(parent),
|
||||
m_configureableMainWindow(configureableMainWindow),
|
||||
m_parent(parent),
|
||||
m_toolBarMenu(toolBarMenu),
|
||||
m_manager(new QtToolBarManager(this)),
|
||||
m_configureAction(new QAction(tr("Configure Toolbars..."), this)),
|
||||
m_toolbars(toolbars)
|
||||
{
|
||||
m_configureAction->setMenuRole(QAction::NoRole);
|
||||
m_configureAction->setObjectName(QLatin1String("__qt_configure_tool_bars_action"));
|
||||
connect(m_configureAction, SIGNAL(triggered()), this, SLOT(configureToolBars()));
|
||||
|
||||
m_manager->setMainWindow(configureableMainWindow);
|
||||
|
||||
foreach(QToolBar *tb, m_toolbars) {
|
||||
const QString title = tb->windowTitle();
|
||||
m_manager->addToolBar(tb, title);
|
||||
addActionsToToolBarManager(tb->actions(), title, m_manager);
|
||||
}
|
||||
|
||||
addActionsToToolBarManager(actions->windowActions()->actions(), tr("Window"), m_manager);
|
||||
addActionsToToolBarManager(actions->helpActions()->actions(), tr("Help"), m_manager);
|
||||
|
||||
// Filter out the device profile preview actions which have int data().
|
||||
ActionList previewActions = actions->styleActions()->actions();
|
||||
ActionList::iterator it = previewActions.begin();
|
||||
for ( ; (*it)->isSeparator() || (*it)->data().type() == QVariant::Int; ++it) ;
|
||||
previewActions.erase(previewActions.begin(), it);
|
||||
addActionsToToolBarManager(previewActions, tr("Style"), m_manager);
|
||||
|
||||
const QString dockTitle = tr("Dock views");
|
||||
foreach (QDesignerToolWindow *tw, toolWindows) {
|
||||
if (QAction *action = tw->action())
|
||||
m_manager->addAction(action, dockTitle);
|
||||
}
|
||||
|
||||
QString category(tr("File"));
|
||||
foreach(QAction *action, actions->fileActions()->actions())
|
||||
m_manager->addAction(action, category);
|
||||
|
||||
category = tr("Edit");
|
||||
foreach(QAction *action, actions->editActions()->actions())
|
||||
m_manager->addAction(action, category);
|
||||
|
||||
category = tr("Tools");
|
||||
foreach(QAction *action, actions->toolActions()->actions())
|
||||
m_manager->addAction(action, category);
|
||||
|
||||
category = tr("Form");
|
||||
foreach(QAction *action, actions->formActions()->actions())
|
||||
m_manager->addAction(action, category);
|
||||
|
||||
m_manager->addAction(m_configureAction, tr("Toolbars"));
|
||||
updateToolBarMenu();
|
||||
}
|
||||
|
||||
// sort function for sorting tool bars alphabetically by title [non-static since called from template]
|
||||
|
||||
bool toolBarTitleLessThan(const QToolBar *t1, const QToolBar *t2)
|
||||
{
|
||||
return t1->windowTitle() < t2->windowTitle();
|
||||
}
|
||||
|
||||
void ToolBarManager::updateToolBarMenu()
|
||||
{
|
||||
// Sort tool bars alphabetically by title
|
||||
qStableSort(m_toolbars.begin(), m_toolbars.end(), toolBarTitleLessThan);
|
||||
// add to menu
|
||||
m_toolBarMenu->clear();
|
||||
foreach (QToolBar *tb, m_toolbars)
|
||||
m_toolBarMenu->addAction(tb->toggleViewAction());
|
||||
m_toolBarMenu->addAction(m_configureAction);
|
||||
}
|
||||
|
||||
void ToolBarManager::configureToolBars()
|
||||
{
|
||||
// QtToolBarDialog dlg(m_parent);
|
||||
// dlg.setWindowFlags(dlg.windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
// dlg.setToolBarManager(m_manager);
|
||||
// dlg.exec();
|
||||
// updateToolBarMenu();
|
||||
}
|
||||
|
||||
QByteArray ToolBarManager::saveState(int version) const
|
||||
{
|
||||
return m_manager->saveState(version);
|
||||
}
|
||||
|
||||
bool ToolBarManager::restoreState(const QByteArray &state, int version)
|
||||
{
|
||||
return m_manager->restoreState(state, version);
|
||||
}
|
||||
|
||||
// ---------- DockedMainWindow
|
||||
|
||||
DockedMainWindow::DockedMainWindow(QDesignerWorkbench *wb,
|
||||
QMenu *toolBarMenu,
|
||||
const QList<QDesignerToolWindow*> &toolWindows) :
|
||||
m_toolBarManager(0)
|
||||
{
|
||||
setObjectName(QLatin1String("MDIWindow"));
|
||||
setWindowTitle(mainWindowTitle());
|
||||
|
||||
const QList<QToolBar *> toolbars = createToolBars(wb->actionManager(), false);
|
||||
foreach (QToolBar *tb, toolbars)
|
||||
addToolBar(tb);
|
||||
DockedMdiArea *dma = new DockedMdiArea(wb->actionManager()->uiExtension());
|
||||
connect(dma, SIGNAL(fileDropped(QString)),
|
||||
this, SIGNAL(fileDropped(QString)));
|
||||
connect(dma, SIGNAL(subWindowActivated(QMdiSubWindow*)),
|
||||
this, SLOT(slotSubWindowActivated(QMdiSubWindow*)));
|
||||
setCentralWidget(dma);
|
||||
|
||||
QStatusBar *sb = statusBar();
|
||||
Q_UNUSED(sb)
|
||||
|
||||
m_toolBarManager = new ToolBarManager(this, this, toolBarMenu, wb->actionManager(), toolbars, toolWindows);
|
||||
}
|
||||
|
||||
QMdiArea *DockedMainWindow::mdiArea() const
|
||||
{
|
||||
return static_cast<QMdiArea *>(centralWidget());
|
||||
}
|
||||
|
||||
void DockedMainWindow::slotSubWindowActivated(QMdiSubWindow* subWindow)
|
||||
{
|
||||
if (subWindow) {
|
||||
QWidget *widget = subWindow->widget();
|
||||
if (QDesignerFormWindow *fw = qobject_cast<QDesignerFormWindow*>(widget)) {
|
||||
emit formWindowActivated(fw);
|
||||
mdiArea()->setActiveSubWindow(subWindow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create a MDI subwindow for the form.
|
||||
QMdiSubWindow *DockedMainWindow::createMdiSubWindow(QWidget *fw, Qt::WindowFlags f, const QKeySequence &designerCloseActionShortCut)
|
||||
{
|
||||
QMdiSubWindow *rc = mdiArea()->addSubWindow(fw, f);
|
||||
// Make action shortcuts respond only if focused to avoid conflicts with
|
||||
// designer menu actions
|
||||
if (designerCloseActionShortCut == QKeySequence(QKeySequence::Close)) {
|
||||
const ActionList systemMenuActions = rc->systemMenu()->actions();
|
||||
if (!systemMenuActions.empty()) {
|
||||
const ActionList::const_iterator cend = systemMenuActions.constEnd();
|
||||
for (ActionList::const_iterator it = systemMenuActions.constBegin(); it != cend; ++it) {
|
||||
if ( (*it)->shortcut() == designerCloseActionShortCut) {
|
||||
(*it)->setShortcutContext(Qt::WidgetShortcut);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
DockedMainWindow::DockWidgetList DockedMainWindow::addToolWindows(const DesignerToolWindowList &tls)
|
||||
{
|
||||
DockWidgetList rc;
|
||||
foreach (QDesignerToolWindow *tw, tls) {
|
||||
QDockWidget *dockWidget = new QDockWidget;
|
||||
dockWidget->setObjectName(tw->objectName() + QLatin1String("_dock"));
|
||||
dockWidget->setWindowTitle(tw->windowTitle());
|
||||
addDockWidget(tw->dockWidgetAreaHint(), dockWidget);
|
||||
dockWidget->setWidget(tw);
|
||||
rc.push_back(dockWidget);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
// Settings consist of MainWindow state and tool bar manager state
|
||||
void DockedMainWindow::restoreSettings(const QDesignerSettings &s, const DockWidgetList &dws, const QRect &desktopArea)
|
||||
{
|
||||
const int version = settingsVersion();
|
||||
m_toolBarManager->restoreState(s.toolBarsState(DockedMode), version);
|
||||
|
||||
// If there are no old geometry settings, show the window maximized
|
||||
s.restoreGeometry(this, QRect(desktopArea.topLeft(), QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX)));
|
||||
|
||||
const QByteArray mainWindowState = s.mainWindowState(DockedMode);
|
||||
const bool restored = !mainWindowState.isEmpty() && restoreState(mainWindowState, version);
|
||||
if (!restored) {
|
||||
// Default: Tabify less relevant windows bottom/right.
|
||||
tabifyDockWidget(dws.at(QDesignerToolWindow::SignalSlotEditor),
|
||||
dws.at(QDesignerToolWindow::ActionEditor));
|
||||
tabifyDockWidget(dws.at(QDesignerToolWindow::ActionEditor),
|
||||
dws.at(QDesignerToolWindow::ResourceEditor));
|
||||
}
|
||||
}
|
||||
|
||||
void DockedMainWindow::saveSettings(QDesignerSettings &s) const
|
||||
{
|
||||
const int version = settingsVersion();
|
||||
s.setToolBarsState(DockedMode, m_toolBarManager->saveState(version));
|
||||
s.saveGeometryFor(this);
|
||||
s.setMainWindowState(DockedMode, saveState(version));
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
187
third/designer/form/mainwindow.h
Normal file
187
third/designer/form/mainwindow.h
Normal file
@@ -0,0 +1,187 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the Qt Designer of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial Usage
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QtGui/QMainWindow>
|
||||
#include <QtCore/QList>
|
||||
#include <QtGui/QMdiArea>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QDesignerActions;
|
||||
class QDesignerWorkbench;
|
||||
class QDesignerToolWindow;
|
||||
class QDesignerFormWindow;
|
||||
class QDesignerSettings;
|
||||
|
||||
class QtToolBarManager;
|
||||
class QToolBar;
|
||||
class QMdiArea;
|
||||
class QMenu;
|
||||
class QByteArray;
|
||||
class QMimeData;
|
||||
|
||||
/* A main window that has a configureable policy on handling close events. If
|
||||
* enabled, it can forward the close event to external handlers.
|
||||
* Base class for windows that can switch roles between tool windows
|
||||
* and main windows. */
|
||||
|
||||
class MainWindowBase: public QMainWindow
|
||||
{
|
||||
Q_DISABLE_COPY(MainWindowBase)
|
||||
Q_OBJECT
|
||||
protected:
|
||||
explicit MainWindowBase(QWidget *parent = 0, Qt::WindowFlags flags = Qt::Window);
|
||||
|
||||
public:
|
||||
enum CloseEventPolicy {
|
||||
/* Always accept close events */
|
||||
AcceptCloseEvents,
|
||||
/* Emit a signal with the event, have it handled elsewhere */
|
||||
EmitCloseEventSignal };
|
||||
|
||||
CloseEventPolicy closeEventPolicy() const { return m_policy; }
|
||||
void setCloseEventPolicy(CloseEventPolicy pol) { m_policy = pol; }
|
||||
|
||||
static QList<QToolBar *> createToolBars(const QDesignerActions *actions, bool singleToolBar);
|
||||
static QString mainWindowTitle();
|
||||
|
||||
// Use the minor Qt version as settings versions to avoid conflicts
|
||||
static int settingsVersion();
|
||||
|
||||
signals:
|
||||
void closeEventReceived(QCloseEvent *e);
|
||||
|
||||
protected:
|
||||
virtual void closeEvent(QCloseEvent *e);
|
||||
private:
|
||||
CloseEventPolicy m_policy;
|
||||
};
|
||||
|
||||
/* An MdiArea that listens for desktop file manager file drop events and emits
|
||||
* a signal to open a dropped file. */
|
||||
class DockedMdiArea : public QMdiArea
|
||||
{
|
||||
Q_DISABLE_COPY(DockedMdiArea)
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DockedMdiArea(const QString &extension, QWidget *parent = 0);
|
||||
|
||||
signals:
|
||||
void fileDropped(const QString &);
|
||||
|
||||
protected:
|
||||
bool event (QEvent *event);
|
||||
|
||||
private:
|
||||
QStringList uiFiles(const QMimeData *d) const;
|
||||
|
||||
const QString m_extension;
|
||||
};
|
||||
|
||||
// Convenience class that manages a QtToolBarManager and an action to trigger
|
||||
// it on a mainwindow.
|
||||
class ToolBarManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(ToolBarManager)
|
||||
public:
|
||||
explicit ToolBarManager(QMainWindow *configureableMainWindow,
|
||||
QWidget *parent,
|
||||
QMenu *toolBarMenu,
|
||||
const QDesignerActions *actions,
|
||||
const QList<QToolBar *> &toolbars,
|
||||
const QList<QDesignerToolWindow*> &toolWindows);
|
||||
|
||||
QByteArray saveState(int version = 0) const;
|
||||
bool restoreState(const QByteArray &state, int version = 0);
|
||||
|
||||
private slots:
|
||||
void configureToolBars();
|
||||
void updateToolBarMenu();
|
||||
|
||||
private:
|
||||
QMainWindow *m_configureableMainWindow;
|
||||
QWidget *m_parent;
|
||||
QMenu *m_toolBarMenu;
|
||||
QtToolBarManager *m_manager;
|
||||
QAction *m_configureAction;
|
||||
QList<QToolBar *> m_toolbars;
|
||||
};
|
||||
|
||||
/* Main window to be used for docked mode */
|
||||
class DockedMainWindow : public MainWindowBase {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(DockedMainWindow)
|
||||
public:
|
||||
typedef QList<QDesignerToolWindow*> DesignerToolWindowList;
|
||||
typedef QList<QDockWidget *> DockWidgetList;
|
||||
|
||||
explicit DockedMainWindow(QDesignerWorkbench *wb,
|
||||
QMenu *toolBarMenu,
|
||||
const DesignerToolWindowList &toolWindows);
|
||||
|
||||
// Create a MDI subwindow for the form.
|
||||
QMdiSubWindow *createMdiSubWindow(QWidget *fw, Qt::WindowFlags f, const QKeySequence &designerCloseActionShortCut);
|
||||
|
||||
QMdiArea *mdiArea() const;
|
||||
|
||||
DockWidgetList addToolWindows(const DesignerToolWindowList &toolWindows);
|
||||
|
||||
void restoreSettings(const QDesignerSettings &s, const DockWidgetList &dws, const QRect &desktopArea);
|
||||
void saveSettings(QDesignerSettings &) const;
|
||||
|
||||
signals:
|
||||
void fileDropped(const QString &);
|
||||
void formWindowActivated(QDesignerFormWindow *);
|
||||
|
||||
private slots:
|
||||
void slotSubWindowActivated(QMdiSubWindow*);
|
||||
|
||||
private:
|
||||
ToolBarManager *m_toolBarManager;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
229
third/designer/form/newform.cpp
Normal file
229
third/designer/form/newform.cpp
Normal file
@@ -0,0 +1,229 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the Qt Designer of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial Usage
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "newform.h"
|
||||
#include "qdesigner_workbench.h"
|
||||
#include "qdesigner_actions.h"
|
||||
#include "qdesigner_formwindow.h"
|
||||
#include "qdesigner_settings.h"
|
||||
|
||||
#include <newformwidget_p.h>
|
||||
|
||||
#include <QtDesigner/QDesignerFormEditorInterface>
|
||||
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QFileInfo>
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QTemporaryFile>
|
||||
|
||||
#include <QtGui/QApplication>
|
||||
#include <QtGui/QVBoxLayout>
|
||||
#include <QtGui/QPushButton>
|
||||
#include <QtGui/QDialogButtonBox>
|
||||
#include <QtGui/QMenu>
|
||||
#include <QtGui/QCheckBox>
|
||||
#include <QtGui/QFrame>
|
||||
#include <QtGui/QMessageBox>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
NewForm::NewForm(QDesignerWorkbench *workbench, QWidget *parentWidget, const QString &fileName)
|
||||
: QDialog(parentWidget,
|
||||
#ifdef Q_WS_MAC
|
||||
Qt::Tool |
|
||||
#endif
|
||||
Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
|
||||
m_fileName(fileName),
|
||||
m_newFormWidget(QDesignerNewFormWidgetInterface::createNewFormWidget(workbench->core())),
|
||||
m_workbench(workbench),
|
||||
m_chkShowOnStartup(new QCheckBox(tr("Show this Dialog on Startup"))),
|
||||
m_createButton(new QPushButton(QApplication::translate("NewForm", "C&reate", 0, QApplication::UnicodeUTF8))),
|
||||
m_recentButton(new QPushButton(QApplication::translate("NewForm", "Recent", 0, QApplication::UnicodeUTF8))),
|
||||
m_buttonBox(0)
|
||||
{
|
||||
setWindowTitle(tr("New Form"));
|
||||
QDesignerSettings settings(m_workbench->core());
|
||||
|
||||
QVBoxLayout *vBoxLayout = new QVBoxLayout;
|
||||
|
||||
connect(m_newFormWidget, SIGNAL(templateActivated()), this, SLOT(slotTemplateActivated()));
|
||||
connect(m_newFormWidget, SIGNAL(currentTemplateChanged(bool)), this, SLOT(slotCurrentTemplateChanged(bool)));
|
||||
vBoxLayout->addWidget(m_newFormWidget);
|
||||
|
||||
QFrame *horizontalLine = new QFrame;
|
||||
horizontalLine->setFrameShape(QFrame::HLine);
|
||||
horizontalLine->setFrameShadow(QFrame::Sunken);
|
||||
vBoxLayout->addWidget(horizontalLine);
|
||||
|
||||
m_chkShowOnStartup->setChecked(settings.showNewFormOnStartup());
|
||||
vBoxLayout->addWidget(m_chkShowOnStartup);
|
||||
|
||||
m_buttonBox = createButtonBox();
|
||||
vBoxLayout->addWidget(m_buttonBox);
|
||||
setLayout(vBoxLayout);
|
||||
|
||||
resize(500, 400);
|
||||
slotCurrentTemplateChanged(m_newFormWidget->hasCurrentTemplate());
|
||||
}
|
||||
|
||||
QDialogButtonBox *NewForm::createButtonBox()
|
||||
{
|
||||
// Dialog buttons with 'recent files'
|
||||
QDialogButtonBox *buttonBox = new QDialogButtonBox;
|
||||
buttonBox->addButton(QApplication::translate("NewForm", "&Close", 0,
|
||||
QApplication::UnicodeUTF8), QDialogButtonBox::RejectRole);
|
||||
buttonBox->addButton(m_createButton, QDialogButtonBox::AcceptRole);
|
||||
buttonBox->addButton(QApplication::translate("NewForm", "&Open...", 0,
|
||||
QApplication::UnicodeUTF8), QDialogButtonBox::ActionRole);
|
||||
buttonBox->addButton(m_recentButton, QDialogButtonBox::ActionRole);
|
||||
|
||||
QDesignerActions *da = m_workbench->actionManager();
|
||||
|
||||
QMenu *recentFilesMenu = new QMenu(tr("&Recent Forms"), m_recentButton);
|
||||
// Pop the "Recent Files" stuff in here.
|
||||
const QList<QAction *> recentActions = da->recentFilesActions()->actions();
|
||||
if (!recentActions.empty()) {
|
||||
const QList<QAction *>::const_iterator acend = recentActions.constEnd();
|
||||
for (QList<QAction *>::const_iterator it = recentActions.constBegin(); it != acend; ++it) {
|
||||
recentFilesMenu->addAction(*it);
|
||||
connect(*it, SIGNAL(triggered()), this, SLOT(recentFileChosen()));
|
||||
}
|
||||
}
|
||||
m_recentButton->setMenu(recentFilesMenu);
|
||||
connect(buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(slotButtonBoxClicked(QAbstractButton*)));
|
||||
return buttonBox;
|
||||
}
|
||||
|
||||
NewForm::~NewForm()
|
||||
{
|
||||
QDesignerSettings settings (m_workbench->core());
|
||||
settings.setShowNewFormOnStartup(m_chkShowOnStartup->isChecked());
|
||||
}
|
||||
|
||||
void NewForm::recentFileChosen()
|
||||
{
|
||||
QAction *action = qobject_cast<QAction *>(sender());
|
||||
if (!action)
|
||||
return;
|
||||
if (action->objectName() == QLatin1String("__qt_action_clear_menu_"))
|
||||
return;
|
||||
close();
|
||||
}
|
||||
|
||||
void NewForm::slotCurrentTemplateChanged(bool templateSelected)
|
||||
{
|
||||
if (templateSelected) {
|
||||
m_createButton->setEnabled(true);
|
||||
m_createButton->setDefault(true);
|
||||
} else {
|
||||
m_createButton->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
void NewForm::slotTemplateActivated()
|
||||
{
|
||||
m_createButton->animateClick(0);
|
||||
}
|
||||
|
||||
void NewForm::slotButtonBoxClicked(QAbstractButton *btn)
|
||||
{
|
||||
switch (m_buttonBox->buttonRole(btn)) {
|
||||
case QDialogButtonBox::RejectRole:
|
||||
reject();
|
||||
break;
|
||||
case QDialogButtonBox::ActionRole:
|
||||
if (btn != m_recentButton) {
|
||||
m_fileName.clear();
|
||||
if (m_workbench->actionManager()->openForm(this))
|
||||
accept();
|
||||
}
|
||||
break;
|
||||
case QDialogButtonBox::AcceptRole: {
|
||||
QString errorMessage;
|
||||
if (openTemplate(&errorMessage)) {
|
||||
accept();
|
||||
} else {
|
||||
QMessageBox::warning(this, tr("Read error"), errorMessage);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool NewForm::openTemplate(QString *ptrToErrorMessage)
|
||||
{
|
||||
const QString contents = m_newFormWidget->currentTemplate(ptrToErrorMessage);
|
||||
if (contents.isEmpty())
|
||||
return false;
|
||||
// Write to temporary file and open
|
||||
QString tempPattern = QDir::tempPath();
|
||||
if (!tempPattern.endsWith(QDir::separator())) // platform-dependant
|
||||
tempPattern += QDir::separator();
|
||||
tempPattern += QLatin1String("XXXXXX.ui");
|
||||
QTemporaryFile tempFormFile(tempPattern);
|
||||
|
||||
tempFormFile.setAutoRemove(true);
|
||||
if (!tempFormFile.open()) {
|
||||
*ptrToErrorMessage = tr("A temporary form file could not be created in %1.").arg(QDir::tempPath());
|
||||
return false;
|
||||
}
|
||||
const QString tempFormFileName = tempFormFile.fileName();
|
||||
tempFormFile.write(contents.toUtf8());
|
||||
if (!tempFormFile.flush()) {
|
||||
*ptrToErrorMessage = tr("The temporary form file %1 could not be written.").arg(tempFormFileName);
|
||||
return false;
|
||||
}
|
||||
tempFormFile.close();
|
||||
return m_workbench->openTemplate(tempFormFileName, m_fileName, ptrToErrorMessage);
|
||||
}
|
||||
|
||||
QImage NewForm::grabForm(QDesignerFormEditorInterface *core,
|
||||
QIODevice &file,
|
||||
const QString &workingDir,
|
||||
const qdesigner_internal::DeviceProfile &dp)
|
||||
{
|
||||
return qdesigner_internal::NewFormWidget::grabForm(core, file, workingDir, dp);
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
104
third/designer/form/newform.h
Normal file
104
third/designer/form/newform.h
Normal file
@@ -0,0 +1,104 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the Qt Designer of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial Usage
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef NEWFORM_H
|
||||
#define NEWFORM_H
|
||||
|
||||
#include <QtGui/QDialog>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
namespace qdesigner_internal {
|
||||
class DeviceProfile;
|
||||
}
|
||||
|
||||
class QDesignerFormEditorInterface;
|
||||
class QDesignerNewFormWidgetInterface;
|
||||
class QDesignerWorkbench;
|
||||
|
||||
class QCheckBox;
|
||||
class QAbstractButton;
|
||||
class QPushButton;
|
||||
class QDialogButtonBox;
|
||||
class QImage;
|
||||
class QIODevice;
|
||||
|
||||
class NewForm: public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(NewForm)
|
||||
|
||||
public:
|
||||
NewForm(QDesignerWorkbench *workbench,
|
||||
QWidget *parentWidget,
|
||||
// Use that file name instead of a temporary one
|
||||
const QString &fileName = QString());
|
||||
|
||||
virtual ~NewForm();
|
||||
|
||||
// Convenience for implementing file dialogs with preview
|
||||
static QImage grabForm(QDesignerFormEditorInterface *core,
|
||||
QIODevice &file,
|
||||
const QString &workingDir,
|
||||
const qdesigner_internal::DeviceProfile &dp);
|
||||
|
||||
private slots:
|
||||
void slotButtonBoxClicked(QAbstractButton *btn);
|
||||
void recentFileChosen();
|
||||
void slotCurrentTemplateChanged(bool templateSelected);
|
||||
void slotTemplateActivated();
|
||||
|
||||
private:
|
||||
QDialogButtonBox *createButtonBox();
|
||||
bool openTemplate(QString *ptrToErrorMessage);
|
||||
|
||||
QString m_fileName;
|
||||
QDesignerNewFormWidgetInterface *m_newFormWidget;
|
||||
QDesignerWorkbench *m_workbench;
|
||||
QCheckBox *m_chkShowOnStartup;
|
||||
QPushButton *m_createButton;
|
||||
QPushButton *m_recentButton;
|
||||
QDialogButtonBox *m_buttonBox;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // NEWFORM_H
|
||||
118
third/designer/form/preferencesdialog.cpp
Normal file
118
third/designer/form/preferencesdialog.cpp
Normal file
@@ -0,0 +1,118 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the Qt Designer of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial Usage
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "preferencesdialog.h"
|
||||
#include "ui_preferencesdialog.h"
|
||||
#include "qdesigner_appearanceoptions.h"
|
||||
|
||||
#include <QtDesigner/private/abstractoptionspage_p.h>
|
||||
|
||||
#include <QtDesigner/QDesignerFormEditorInterface>
|
||||
#include <QtGui/QFileDialog>
|
||||
#include <QtGui/QPushButton>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
PreferencesDialog::PreferencesDialog(QDesignerFormEditorInterface *core, QWidget *parentWidget) :
|
||||
QDialog(parentWidget),
|
||||
m_ui(new Ui::PreferencesDialog()),
|
||||
m_core(core)
|
||||
{
|
||||
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
m_ui->setupUi(this);
|
||||
|
||||
m_optionsPages = core->optionsPages();
|
||||
|
||||
m_ui->m_optionTabWidget->clear();
|
||||
foreach (QDesignerOptionsPageInterface *optionsPage, m_optionsPages) {
|
||||
QWidget *page = optionsPage->createPage(this);
|
||||
m_ui->m_optionTabWidget->addTab(page, optionsPage->name());
|
||||
if (QDesignerAppearanceOptionsWidget *appearanceWidget = qobject_cast<QDesignerAppearanceOptionsWidget *>(page))
|
||||
connect(appearanceWidget, SIGNAL(uiModeChanged(bool)), this, SLOT(slotUiModeChanged(bool)));
|
||||
}
|
||||
|
||||
connect(m_ui->m_dialogButtonBox, SIGNAL(rejected()), this, SLOT(slotRejected()));
|
||||
connect(m_ui->m_dialogButtonBox, SIGNAL(accepted()), this, SLOT(slotAccepted()));
|
||||
connect(applyButton(), SIGNAL(clicked()), this, SLOT(slotApply()));
|
||||
}
|
||||
|
||||
PreferencesDialog::~PreferencesDialog()
|
||||
{
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
QPushButton *PreferencesDialog::applyButton() const
|
||||
{
|
||||
return m_ui->m_dialogButtonBox->button(QDialogButtonBox::Apply);
|
||||
}
|
||||
|
||||
void PreferencesDialog::slotApply()
|
||||
{
|
||||
foreach (QDesignerOptionsPageInterface *optionsPage, m_optionsPages)
|
||||
optionsPage->apply();
|
||||
}
|
||||
|
||||
void PreferencesDialog::slotAccepted()
|
||||
{
|
||||
slotApply();
|
||||
closeOptionPages();
|
||||
accept();
|
||||
}
|
||||
|
||||
void PreferencesDialog::slotRejected()
|
||||
{
|
||||
closeOptionPages();
|
||||
reject();
|
||||
}
|
||||
|
||||
void PreferencesDialog::slotUiModeChanged(bool modified)
|
||||
{
|
||||
// Cannot "apply" a ui mode change (destroy the dialogs parent)
|
||||
applyButton()->setEnabled(!modified);
|
||||
}
|
||||
|
||||
void PreferencesDialog::closeOptionPages()
|
||||
{
|
||||
foreach (QDesignerOptionsPageInterface *optionsPage, m_optionsPages)
|
||||
optionsPage->finish();
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
82
third/designer/form/preferencesdialog.h
Normal file
82
third/designer/form/preferencesdialog.h
Normal file
@@ -0,0 +1,82 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the Qt Designer of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial Usage
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef PREFERENCESDIALOG_H
|
||||
#define PREFERENCESDIALOG_H
|
||||
|
||||
#include <QtGui/QDialog>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QPushButton;
|
||||
class QDesignerFormEditorInterface;
|
||||
class QDesignerOptionsPageInterface;
|
||||
|
||||
namespace Ui {
|
||||
class PreferencesDialog;
|
||||
}
|
||||
|
||||
class PreferencesDialog: public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit PreferencesDialog(QDesignerFormEditorInterface *core, QWidget *parentWidget = 0);
|
||||
~PreferencesDialog();
|
||||
|
||||
|
||||
private slots:
|
||||
void slotAccepted();
|
||||
void slotRejected();
|
||||
void slotApply();
|
||||
void slotUiModeChanged(bool modified);
|
||||
|
||||
private:
|
||||
QPushButton *applyButton() const;
|
||||
void closeOptionPages();
|
||||
|
||||
Ui::PreferencesDialog *m_ui;
|
||||
QDesignerFormEditorInterface *m_core;
|
||||
QList<QDesignerOptionsPageInterface*> m_optionsPages;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // PREFERENCESDIALOG_H
|
||||
91
third/designer/form/preferencesdialog.ui
Normal file
91
third/designer/form/preferencesdialog.ui
Normal file
@@ -0,0 +1,91 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>PreferencesDialog</class>
|
||||
<widget class="QDialog" name="PreferencesDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>474</width>
|
||||
<height>304</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Preferences</string>
|
||||
</property>
|
||||
<property name="modal">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QTabWidget" name="m_optionTabWidget">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab_2">
|
||||
<attribute name="title">
|
||||
<string notr="true">Tab 1</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="m_dialogButtonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Apply|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>m_dialogButtonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>PreferencesDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>m_dialogButtonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>PreferencesDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
1871
third/designer/form/qttoolbardialog.cpp
Normal file
1871
third/designer/form/qttoolbardialog.cpp
Normal file
File diff suppressed because it is too large
Load Diff
138
third/designer/form/qttoolbardialog.h
Normal file
138
third/designer/form/qttoolbardialog.h
Normal file
@@ -0,0 +1,138 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the tools applications of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial Usage
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
// -------------
|
||||
//
|
||||
// This file is not part of the Qt API. It exists for the convenience
|
||||
// of Qt Designer. This header
|
||||
// file may change from version to version without notice, or even be removed.
|
||||
//
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
#ifndef QTTOOLBARDIALOG_H
|
||||
#define QTTOOLBARDIALOG_H
|
||||
|
||||
#include <QtGui/QDialog>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QMainWindow;
|
||||
class QAction;
|
||||
class QToolBar;
|
||||
|
||||
class QtToolBarManagerPrivate;
|
||||
|
||||
class QtToolBarManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
explicit QtToolBarManager(QObject *parent = 0);
|
||||
~QtToolBarManager();
|
||||
|
||||
void setMainWindow(QMainWindow *mainWindow);
|
||||
QMainWindow *mainWindow() const;
|
||||
|
||||
void addAction(QAction *action, const QString &category);
|
||||
void removeAction(QAction *action);
|
||||
|
||||
void addToolBar(QToolBar *toolBar, const QString &category);
|
||||
void removeToolBar(QToolBar *toolBar);
|
||||
|
||||
QList<QToolBar *> toolBars() const;
|
||||
|
||||
QByteArray saveState(int version = 0) const;
|
||||
bool restoreState(const QByteArray &state, int version = 0);
|
||||
|
||||
private:
|
||||
|
||||
friend class QtToolBarDialog;
|
||||
QScopedPointer<QtToolBarManagerPrivate> d_ptr;
|
||||
Q_DECLARE_PRIVATE(QtToolBarManager)
|
||||
Q_DISABLE_COPY(QtToolBarManager)
|
||||
};
|
||||
|
||||
class QtToolBarDialogPrivate;
|
||||
|
||||
class QtToolBarDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
explicit QtToolBarDialog(QWidget *parent = 0, Qt::WindowFlags flags = 0);
|
||||
~QtToolBarDialog();
|
||||
|
||||
void setToolBarManager(QtToolBarManager *toolBarManager);
|
||||
|
||||
protected:
|
||||
|
||||
void showEvent(QShowEvent *event);
|
||||
void hideEvent(QHideEvent *event);
|
||||
|
||||
private:
|
||||
|
||||
QScopedPointer<QtToolBarDialogPrivate> d_ptr;
|
||||
Q_DECLARE_PRIVATE(QtToolBarDialog)
|
||||
Q_DISABLE_COPY(QtToolBarDialog)
|
||||
|
||||
Q_PRIVATE_SLOT(d_func(), void newClicked())
|
||||
Q_PRIVATE_SLOT(d_func(), void removeClicked())
|
||||
Q_PRIVATE_SLOT(d_func(), void defaultClicked())
|
||||
Q_PRIVATE_SLOT(d_func(), void okClicked())
|
||||
Q_PRIVATE_SLOT(d_func(), void applyClicked())
|
||||
Q_PRIVATE_SLOT(d_func(), void cancelClicked())
|
||||
Q_PRIVATE_SLOT(d_func(), void upClicked())
|
||||
Q_PRIVATE_SLOT(d_func(), void downClicked())
|
||||
Q_PRIVATE_SLOT(d_func(), void leftClicked())
|
||||
Q_PRIVATE_SLOT(d_func(), void rightClicked())
|
||||
Q_PRIVATE_SLOT(d_func(), void renameClicked())
|
||||
Q_PRIVATE_SLOT(d_func(), void toolBarRenamed(QListWidgetItem *))
|
||||
Q_PRIVATE_SLOT(d_func(), void currentActionChanged(QTreeWidgetItem *))
|
||||
Q_PRIVATE_SLOT(d_func(), void currentToolBarChanged(QListWidgetItem *))
|
||||
Q_PRIVATE_SLOT(d_func(), void currentToolBarActionChanged(QListWidgetItem *))
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif
|
||||
207
third/designer/form/qttoolbardialog.ui
Normal file
207
third/designer/form/qttoolbardialog.ui
Normal file
@@ -0,0 +1,207 @@
|
||||
<ui version="4.0" >
|
||||
<class>QtToolBarDialog</class>
|
||||
<widget class="QDialog" name="QtToolBarDialog" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>583</width>
|
||||
<height>508</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle" >
|
||||
<string>Customize Toolbars</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" >
|
||||
<property name="margin" >
|
||||
<number>8</number>
|
||||
</property>
|
||||
<property name="spacing" >
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item rowspan="3" row="1" column="0" >
|
||||
<widget class="QTreeWidget" name="actionTree" >
|
||||
<column>
|
||||
<property name="text" >
|
||||
<string>1</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" >
|
||||
<widget class="QLabel" name="label" >
|
||||
<property name="text" >
|
||||
<string>Actions</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" colspan="2" >
|
||||
<layout class="QHBoxLayout" >
|
||||
<property name="spacing" >
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="margin" >
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2" >
|
||||
<property name="text" >
|
||||
<string>Toolbars</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="newButton" >
|
||||
<property name="toolTip" >
|
||||
<string>Add new toolbar</string>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>New</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="removeButton" >
|
||||
<property name="toolTip" >
|
||||
<string>Remove selected toolbar</string>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>Remove</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="renameButton" >
|
||||
<property name="toolTip" >
|
||||
<string>Rename toolbar</string>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>Rename</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="3" column="1" >
|
||||
<layout class="QVBoxLayout" >
|
||||
<property name="spacing" >
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="margin" >
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QToolButton" name="upButton" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy vsizetype="Fixed" hsizetype="Minimum" >
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip" >
|
||||
<string>Move action up</string>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>Up</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="leftButton" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy vsizetype="Fixed" hsizetype="Minimum" >
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip" >
|
||||
<string>Remove action from toolbar</string>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string><-</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="rightButton" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy vsizetype="Fixed" hsizetype="Minimum" >
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip" >
|
||||
<string>Add action to toolbar</string>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>-></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="downButton" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy vsizetype="Fixed" hsizetype="Minimum" >
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip" >
|
||||
<string>Move action down</string>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>Down</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer>
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0" >
|
||||
<size>
|
||||
<width>29</width>
|
||||
<height>16</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="3" column="2" >
|
||||
<widget class="QListWidget" name="currentToolBarList" />
|
||||
</item>
|
||||
<item row="2" column="1" colspan="2" >
|
||||
<widget class="QLabel" name="label_3" >
|
||||
<property name="text" >
|
||||
<string>Current Toolbar Actions</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1" colspan="2" >
|
||||
<widget class="QListWidget" name="toolBarList" />
|
||||
</item>
|
||||
<item row="5" column="0" colspan="3" >
|
||||
<widget class="QDialogButtonBox" name="buttonBox" >
|
||||
<property name="standardButtons" >
|
||||
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::RestoreDefaults</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>newButton</tabstop>
|
||||
<tabstop>removeButton</tabstop>
|
||||
<tabstop>renameButton</tabstop>
|
||||
<tabstop>toolBarList</tabstop>
|
||||
<tabstop>upButton</tabstop>
|
||||
<tabstop>leftButton</tabstop>
|
||||
<tabstop>rightButton</tabstop>
|
||||
<tabstop>downButton</tabstop>
|
||||
<tabstop>currentToolBarList</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
173
third/designer/form/saveformastemplate.cpp
Normal file
173
third/designer/form/saveformastemplate.cpp
Normal file
@@ -0,0 +1,173 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the Qt Designer of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial Usage
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "saveformastemplate.h"
|
||||
#include "qdesigner_settings.h"
|
||||
|
||||
#include <QtCore/QFile>
|
||||
#include <QtGui/QFileDialog>
|
||||
#include <QtGui/QMessageBox>
|
||||
#include <QtGui/QPushButton>
|
||||
|
||||
#include <QtDesigner/abstractformeditor.h>
|
||||
#include <QtDesigner/abstractformwindow.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
SaveFormAsTemplate::SaveFormAsTemplate(QDesignerFormEditorInterface *core,
|
||||
QDesignerFormWindowInterface *formWindow,
|
||||
QWidget *parent)
|
||||
: QDialog(parent, Qt::Sheet),
|
||||
m_core(core),
|
||||
m_formWindow(formWindow)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
|
||||
ui.templateNameEdit->setText(formWindow->mainContainer()->objectName());
|
||||
ui.templateNameEdit->selectAll();
|
||||
|
||||
ui.templateNameEdit->setFocus();
|
||||
|
||||
QStringList paths = QDesignerSettings(m_core).formTemplatePaths();
|
||||
ui.categoryCombo->addItems(paths);
|
||||
ui.categoryCombo->addItem(tr("Add path..."));
|
||||
m_addPathIndex = ui.categoryCombo->count() - 1;
|
||||
connect(ui.templateNameEdit, SIGNAL(textChanged(QString)),
|
||||
this, SLOT(updateOKButton(QString)));
|
||||
connect(ui.categoryCombo, SIGNAL(activated(int)), this, SLOT(checkToAddPath(int)));
|
||||
}
|
||||
|
||||
SaveFormAsTemplate::~SaveFormAsTemplate()
|
||||
{
|
||||
}
|
||||
|
||||
void SaveFormAsTemplate::accept()
|
||||
{
|
||||
QString templateFileName = ui.categoryCombo->currentText();
|
||||
templateFileName += QLatin1Char('/');
|
||||
const QString name = ui.templateNameEdit->text();
|
||||
templateFileName += name;
|
||||
const QString extension = QLatin1String(".ui");
|
||||
if (!templateFileName.endsWith(extension))
|
||||
templateFileName.append(extension);
|
||||
QFile file(templateFileName);
|
||||
|
||||
if (file.exists()) {
|
||||
QMessageBox msgBox(QMessageBox::Information, tr("Template Exists"),
|
||||
tr("A template with the name %1 already exists.\n"
|
||||
"Do you want overwrite the template?").arg(name), QMessageBox::Cancel, m_formWindow);
|
||||
msgBox.setDefaultButton(QMessageBox::Cancel);
|
||||
QPushButton *overwriteButton = msgBox.addButton(tr("Overwrite Template"), QMessageBox::AcceptRole);
|
||||
msgBox.exec();
|
||||
if (msgBox.clickedButton() != overwriteButton)
|
||||
return;
|
||||
}
|
||||
|
||||
while (!file.open(QFile::WriteOnly)) {
|
||||
if (QMessageBox::information(m_formWindow, tr("Open Error"),
|
||||
tr("There was an error opening template %1 for writing. Reason: %2").arg(name).arg(file.errorString()),
|
||||
QMessageBox::Retry|QMessageBox::Cancel, QMessageBox::Cancel) == QMessageBox::Cancel) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const QString origName = m_formWindow->fileName();
|
||||
// ensure m_formWindow->contents() will convert properly resource paths to relative paths
|
||||
// (relative to template location, not to the current form location)
|
||||
m_formWindow->setFileName(templateFileName);
|
||||
QByteArray ba = m_formWindow->contents().toUtf8();
|
||||
m_formWindow->setFileName(origName);
|
||||
while (file.write(ba) != ba.size()) {
|
||||
if (QMessageBox::information(m_formWindow, tr("Write Error"),
|
||||
tr("There was an error writing the template %1 to disk. Reason: %2").arg(name).arg(file.errorString()),
|
||||
QMessageBox::Retry|QMessageBox::Cancel, QMessageBox::Cancel) == QMessageBox::Cancel) {
|
||||
file.close();
|
||||
file.remove();
|
||||
return;
|
||||
}
|
||||
file.reset();
|
||||
}
|
||||
// update the list of places too...
|
||||
QStringList sl;
|
||||
for (int i = 0; i < m_addPathIndex; ++i)
|
||||
sl << ui.categoryCombo->itemText(i);
|
||||
|
||||
QDesignerSettings(m_core).setFormTemplatePaths(sl);
|
||||
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
void SaveFormAsTemplate::updateOKButton(const QString &str)
|
||||
{
|
||||
QPushButton *okButton = ui.buttonBox->button(QDialogButtonBox::Ok);
|
||||
okButton->setEnabled(!str.isEmpty());
|
||||
}
|
||||
|
||||
QString SaveFormAsTemplate::chooseTemplatePath(QWidget *parent)
|
||||
{
|
||||
QString rc = QFileDialog::getExistingDirectory(parent,
|
||||
tr("Pick a directory to save templates in"));
|
||||
if (rc.isEmpty())
|
||||
return rc;
|
||||
|
||||
if (rc.endsWith(QDir::separator()))
|
||||
rc.remove(rc.size() - 1, 1);
|
||||
return rc;
|
||||
}
|
||||
|
||||
void SaveFormAsTemplate::checkToAddPath(int itemIndex)
|
||||
{
|
||||
if (itemIndex != m_addPathIndex)
|
||||
return;
|
||||
|
||||
const QString dir = chooseTemplatePath(this);
|
||||
if (dir.isEmpty()) {
|
||||
ui.categoryCombo->setCurrentIndex(0);
|
||||
return;
|
||||
}
|
||||
|
||||
ui.categoryCombo->insertItem(m_addPathIndex, dir);
|
||||
ui.categoryCombo->setCurrentIndex(m_addPathIndex);
|
||||
++m_addPathIndex;
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
77
third/designer/form/saveformastemplate.h
Normal file
77
third/designer/form/saveformastemplate.h
Normal file
@@ -0,0 +1,77 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the Qt Designer of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial Usage
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef SAVEFORMASTEMPLATE_H
|
||||
#define SAVEFORMASTEMPLATE_H
|
||||
|
||||
#include "ui_saveformastemplate.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QDesignerFormEditorInterface;
|
||||
class QDesignerFormWindowInterface;
|
||||
|
||||
class SaveFormAsTemplate: public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SaveFormAsTemplate(QDesignerFormEditorInterface *m_core,
|
||||
QDesignerFormWindowInterface *formWindow,
|
||||
QWidget *parent = 0);
|
||||
virtual ~SaveFormAsTemplate();
|
||||
|
||||
private slots:
|
||||
void accept();
|
||||
void updateOKButton(const QString &str);
|
||||
void checkToAddPath(int itemIndex);
|
||||
|
||||
private:
|
||||
static QString chooseTemplatePath(QWidget *parent);
|
||||
|
||||
Ui::SaveFormAsTemplate ui;
|
||||
QDesignerFormEditorInterface *m_core;
|
||||
QDesignerFormWindowInterface *m_formWindow;
|
||||
int m_addPathIndex;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // SAVEFORMASTEMPLATE_H
|
||||
166
third/designer/form/saveformastemplate.ui
Normal file
166
third/designer/form/saveformastemplate.ui
Normal file
@@ -0,0 +1,166 @@
|
||||
<ui version="4.0" >
|
||||
<comment>*********************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the Qt Designer of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial Usage
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
*********************************************************************</comment>
|
||||
<class>SaveFormAsTemplate</class>
|
||||
<widget class="QDialog" name="SaveFormAsTemplate" >
|
||||
<property name="windowTitle" >
|
||||
<string>Save Form As Template</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" >
|
||||
<item>
|
||||
<layout class="QFormLayout" >
|
||||
<item row="0" column="0" >
|
||||
<widget class="QLabel" name="label" >
|
||||
<property name="frameShape" >
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow" >
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>&Name:</string>
|
||||
</property>
|
||||
<property name="textFormat" >
|
||||
<enum>Qt::AutoText</enum>
|
||||
</property>
|
||||
<property name="buddy" >
|
||||
<cstring>templateNameEdit</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" >
|
||||
<widget class="QLineEdit" name="templateNameEdit" >
|
||||
<property name="minimumSize" >
|
||||
<size>
|
||||
<width>222</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string/>
|
||||
</property>
|
||||
<property name="echoMode" >
|
||||
<enum>QLineEdit::Normal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" >
|
||||
<widget class="QLabel" name="label_2" >
|
||||
<property name="frameShape" >
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow" >
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>&Category:</string>
|
||||
</property>
|
||||
<property name="textFormat" >
|
||||
<enum>Qt::AutoText</enum>
|
||||
</property>
|
||||
<property name="buddy" >
|
||||
<cstring>categoryCombo</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1" >
|
||||
<widget class="QComboBox" name="categoryCombo" />
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="horizontalLine" >
|
||||
<property name="frameShape" >
|
||||
<enum>QFrame::HLine</enum>
|
||||
</property>
|
||||
<property name="frameShadow" >
|
||||
<enum>QFrame::Sunken</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox" >
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons" >
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>SaveFormAsTemplate</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel" >
|
||||
<x>256</x>
|
||||
<y>124</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel" >
|
||||
<x>113</x>
|
||||
<y>143</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>SaveFormAsTemplate</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel" >
|
||||
<x>332</x>
|
||||
<y>127</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel" >
|
||||
<x>372</x>
|
||||
<y>147</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
191
third/designer/form/versiondialog.cpp
Normal file
191
third/designer/form/versiondialog.cpp
Normal file
@@ -0,0 +1,191 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the Qt Designer of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial Usage
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtCore/QVector>
|
||||
#include <QtGui/QMouseEvent>
|
||||
#include <QtGui/QGridLayout>
|
||||
#include <QtGui/QLabel>
|
||||
#include <QtGui/QPushButton>
|
||||
#include <QtGui/QDialogButtonBox>
|
||||
#include <QtGui/QPainter>
|
||||
#include <QtGui/QPainterPath>
|
||||
#include <QtGui/QStyleOption>
|
||||
#include "versiondialog.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class VersionLabel : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
VersionLabel(QWidget *parent = 0);
|
||||
|
||||
signals:
|
||||
void triggered();
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *me);
|
||||
void mouseMoveEvent(QMouseEvent *me);
|
||||
void mouseReleaseEvent(QMouseEvent *me);
|
||||
void paintEvent(QPaintEvent *pe);
|
||||
private:
|
||||
QVector<QPoint> hitPoints;
|
||||
QVector<QPoint> missPoints;
|
||||
QPainterPath m_path;
|
||||
bool secondStage;
|
||||
bool m_pushed;
|
||||
};
|
||||
|
||||
VersionLabel::VersionLabel(QWidget *parent)
|
||||
: QLabel(parent), secondStage(false), m_pushed(false)
|
||||
{
|
||||
setPixmap(QPixmap(QLatin1String(":/trolltech/designer/images/designer.png")));
|
||||
hitPoints.append(QPoint(56, 25));
|
||||
hitPoints.append(QPoint(29, 55));
|
||||
hitPoints.append(QPoint(56, 87));
|
||||
hitPoints.append(QPoint(82, 55));
|
||||
hitPoints.append(QPoint(58, 56));
|
||||
|
||||
secondStage = false;
|
||||
m_pushed = false;
|
||||
}
|
||||
|
||||
void VersionLabel::mousePressEvent(QMouseEvent *me)
|
||||
{
|
||||
if (me->button() == Qt::LeftButton) {
|
||||
if (!secondStage) {
|
||||
m_path = QPainterPath(me->pos());
|
||||
} else {
|
||||
m_pushed = true;
|
||||
update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void VersionLabel::mouseMoveEvent(QMouseEvent *me)
|
||||
{
|
||||
if (me->buttons() & Qt::LeftButton)
|
||||
if (!secondStage)
|
||||
m_path.lineTo(me->pos());
|
||||
}
|
||||
|
||||
void VersionLabel::mouseReleaseEvent(QMouseEvent *me)
|
||||
{
|
||||
if (me->button() == Qt::LeftButton) {
|
||||
if (!secondStage) {
|
||||
m_path.lineTo(me->pos());
|
||||
bool gotIt = true;
|
||||
foreach(const QPoint &pt, hitPoints) {
|
||||
if (!m_path.contains(pt)) {
|
||||
gotIt = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (gotIt) {
|
||||
foreach(const QPoint &pt, missPoints) {
|
||||
if (m_path.contains(pt)) {
|
||||
gotIt = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (gotIt && !secondStage) {
|
||||
secondStage = true;
|
||||
m_path = QPainterPath();
|
||||
update();
|
||||
}
|
||||
} else {
|
||||
m_pushed = false;
|
||||
update();
|
||||
emit triggered();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void VersionLabel::paintEvent(QPaintEvent *pe)
|
||||
{
|
||||
if (secondStage) {
|
||||
QPainter p(this);
|
||||
QStyleOptionButton opt;
|
||||
opt.init(this);
|
||||
if (!m_pushed)
|
||||
opt.state |= QStyle::State_Raised;
|
||||
else
|
||||
opt.state |= QStyle::State_Sunken;
|
||||
opt.state &= ~QStyle::State_HasFocus;
|
||||
style()->drawControl(QStyle::CE_PushButtonBevel, &opt, &p, this);
|
||||
}
|
||||
QLabel::paintEvent(pe);
|
||||
}
|
||||
|
||||
VersionDialog::VersionDialog(QWidget *parent)
|
||||
: QDialog(parent
|
||||
#ifdef Q_WS_MAC
|
||||
, Qt::Tool
|
||||
#endif
|
||||
)
|
||||
{
|
||||
setWindowFlags((windowFlags() & ~Qt::WindowContextHelpButtonHint) | Qt::MSWindowsFixedSizeDialogHint);
|
||||
QGridLayout *layout = new QGridLayout(this);
|
||||
VersionLabel *label = new VersionLabel;
|
||||
QLabel *lbl = new QLabel;
|
||||
QString version = tr("<h3>%1</h3><br/><br/>Version %2");
|
||||
version = version.arg(tr("Qt Designer")).arg(QLatin1String(QT_VERSION_STR));
|
||||
version.append(tr("<br/>Qt Designer is a graphical user interface designer for Qt applications.<br/>"));
|
||||
|
||||
lbl->setText(tr("%1"
|
||||
"<br/>Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)."
|
||||
).arg(version));
|
||||
|
||||
lbl->setWordWrap(true);
|
||||
lbl->setOpenExternalLinks(true);
|
||||
|
||||
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
|
||||
connect(buttonBox , SIGNAL(rejected()), this, SLOT(reject()));
|
||||
connect(label, SIGNAL(triggered()), this, SLOT(accept()));
|
||||
layout->addWidget(label, 0, 0, 1, 1);
|
||||
layout->addWidget(lbl, 0, 1, 4, 4);
|
||||
layout->addWidget(buttonBox, 4, 2, 1, 1);
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#include "versiondialog.moc"
|
||||
58
third/designer/form/versiondialog.h
Normal file
58
third/designer/form/versiondialog.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the Qt Designer of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial Usage
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** If you have questions regarding the use of this file, please contact
|
||||
** Nokia at qt-info@nokia.com.
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef VERSIONDIALOG_H
|
||||
#define VERSIONDIALOG_H
|
||||
|
||||
#include <QtGui/QDialog>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class VersionDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit VersionDialog(QWidget *parent);
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user