Commit 1a9ff3b3 authored by Bryant Mairs's avatar Bryant Mairs

Removed Utils library as it's no longer used.

parent 0ce13bb0
......@@ -302,16 +302,8 @@ DEFINES += NOMINMAX
#
# [REQUIRED] OPMapControl library from OpenPilot. Provides 2D mapping functionality.
#
include(libs/utils/utils_external.pri)
include(libs/opmapcontrol/opmapcontrol_external.pri)
DEPENDPATH += \
libs/utils \
libs/utils/src \
libs/opmapcontrol \
libs/opmapcontrol/src \
libs/opmapcontrol/src/mapwidget
INCLUDEPATH += \
libs/utils \
libs \
......
......@@ -25,7 +25,6 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "cache.h"
#include "utils/pathutils.h"
#include <QSettings>
namespace core {
......
/**
******************************************************************************
*
* @file abstractprocess.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef ABSTRACTPROCESS_H
#define ABSTRACTPROCESS_H
#include "utils_global.h"
#include <QtCore/QStringList>
namespace Utils {
class QTCREATOR_UTILS_EXPORT AbstractProcess
{
public:
AbstractProcess() {}
virtual ~AbstractProcess() {}
QString workingDirectory() const { return m_workingDir; }
void setWorkingDirectory(const QString &dir) { m_workingDir = dir; }
QStringList environment() const { return m_environment; }
void setEnvironment(const QStringList &env) { m_environment = env; }
virtual bool start(const QString &program, const QStringList &args) = 0;
virtual void stop() = 0;
virtual bool isRunning() const = 0;
virtual qint64 applicationPID() const = 0;
virtual int exitCode() const = 0;
//signals:
virtual void processError(const QString &error) = 0;
#ifdef Q_OS_WIN
// Add PATH and SystemRoot environment variables in case they are missing
static QStringList fixWinEnvironment(const QStringList &env);
// Quote a Windows command line correctly for the "CreateProcess" API
static QString createWinCommandline(const QString &program, const QStringList &args);
// Create a bytearray suitable to be passed on as environment
// to the "CreateProcess" API (0-terminated UTF 16 strings).
static QByteArray createWinEnvironment(const QStringList &env);
#endif
private:
QString m_workingDir;
QStringList m_environment;
};
} //namespace Utils
#endif // ABSTRACTPROCESS_H
/**
******************************************************************************
*
* @file abstractprocess_win.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "abstractprocess.h"
#include <windows.h>
namespace Utils {
QStringList AbstractProcess::fixWinEnvironment(const QStringList &env)
{
QStringList envStrings = env;
// add PATH if necessary (for DLL loading)
if (envStrings.filter(QRegExp(QLatin1String("^PATH="),Qt::CaseInsensitive)).isEmpty()) {
QByteArray path = qgetenv("PATH");
if (!path.isEmpty())
envStrings.prepend(QString(QLatin1String("PATH=%1")).arg(QString::fromLocal8Bit(path)));
}
// add systemroot if needed
if (envStrings.filter(QRegExp(QLatin1String("^SystemRoot="),Qt::CaseInsensitive)).isEmpty()) {
QByteArray systemRoot = qgetenv("SystemRoot");
if (!systemRoot.isEmpty())
envStrings.prepend(QString(QLatin1String("SystemRoot=%1")).arg(QString::fromLocal8Bit(systemRoot)));
}
return envStrings;
}
QString AbstractProcess::createWinCommandline(const QString &program, const QStringList &args)
{
const QChar doubleQuote = QLatin1Char('"');
const QChar blank = QLatin1Char(' ');
const QChar backSlash = QLatin1Char('\\');
QString programName = program;
if (!programName.startsWith(doubleQuote) && !programName.endsWith(doubleQuote) && programName.contains(blank)) {
programName.insert(0, doubleQuote);
programName.append(doubleQuote);
}
// add the prgram as the first arrg ... it works better
programName.replace(QLatin1Char('/'), backSlash);
QString cmdLine = programName;
if (args.empty())
return cmdLine;
cmdLine += blank;
for (int i = 0; i < args.size(); ++i) {
QString tmp = args.at(i);
// in the case of \" already being in the string the \ must also be escaped
tmp.replace(QLatin1String("\\\""), QLatin1String("\\\\\""));
// escape a single " because the arguments will be parsed
tmp.replace(QString(doubleQuote), QLatin1String("\\\""));
if (tmp.isEmpty() || tmp.contains(blank) || tmp.contains('\t')) {
// The argument must not end with a \ since this would be interpreted
// as escaping the quote -- rather put the \ behind the quote: e.g.
// rather use "foo"\ than "foo\"
QString endQuote(doubleQuote);
int i = tmp.length();
while (i > 0 && tmp.at(i - 1) == backSlash) {
--i;
endQuote += backSlash;
}
cmdLine += QLatin1String(" \"");
cmdLine += tmp.left(i);
cmdLine += endQuote;
} else {
cmdLine += blank;
cmdLine += tmp;
}
}
return cmdLine;
}
QByteArray AbstractProcess::createWinEnvironment(const QStringList &env)
{
QByteArray envlist;
int pos = 0;
foreach (const QString &tmp, env) {
const uint tmpSize = sizeof(TCHAR) * (tmp.length() + 1);
envlist.resize(envlist.size() + tmpSize);
memcpy(envlist.data() + pos, tmp.utf16(), tmpSize);
pos += tmpSize;
}
envlist.resize(envlist.size() + 2);
envlist[pos++] = 0;
envlist[pos++] = 0;
return envlist;
}
} //namespace Utils
/**
******************************************************************************
*
* @file basevalidatinglineedit.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "basevalidatinglineedit.h"
#include <QtCore/QDebug>
enum { debug = 0 };
namespace Utils {
struct BaseValidatingLineEditPrivate {
explicit BaseValidatingLineEditPrivate(const QWidget *w);
const QColor m_okTextColor;
QColor m_errorTextColor;
BaseValidatingLineEdit::State m_state;
QString m_errorMessage;
QString m_initialText;
bool m_firstChange;
};
BaseValidatingLineEditPrivate::BaseValidatingLineEditPrivate(const QWidget *w) :
m_okTextColor(BaseValidatingLineEdit::textColor(w)),
m_errorTextColor(Qt::red),
m_state(BaseValidatingLineEdit::Invalid),
m_firstChange(true)
{
}
BaseValidatingLineEdit::BaseValidatingLineEdit(QWidget *parent) :
QLineEdit(parent),
m_bd(new BaseValidatingLineEditPrivate(this))
{
// Note that textChanged() is also triggered automagically by
// QLineEdit::setText(), no need to trigger manually.
connect(this, SIGNAL(textChanged(QString)), this, SLOT(slotChanged(QString)));
}
BaseValidatingLineEdit::~BaseValidatingLineEdit()
{
delete m_bd;
}
QString BaseValidatingLineEdit::initialText() const
{
return m_bd->m_initialText;
}
void BaseValidatingLineEdit::setInitialText(const QString &t)
{
if (m_bd->m_initialText != t) {
m_bd->m_initialText = t;
m_bd->m_firstChange = true;
setText(t);
}
}
QColor BaseValidatingLineEdit::errorColor() const
{
return m_bd->m_errorTextColor;
}
void BaseValidatingLineEdit::setErrorColor(const QColor &c)
{
m_bd->m_errorTextColor = c;
}
QColor BaseValidatingLineEdit::textColor(const QWidget *w)
{
return w->palette().color(QPalette::Active, QPalette::Text);
}
void BaseValidatingLineEdit::setTextColor(QWidget *w, const QColor &c)
{
QPalette palette = w->palette();
palette.setColor(QPalette::Active, QPalette::Text, c);
w->setPalette(palette);
}
BaseValidatingLineEdit::State BaseValidatingLineEdit::state() const
{
return m_bd->m_state;
}
bool BaseValidatingLineEdit::isValid() const
{
return m_bd->m_state == Valid;
}
QString BaseValidatingLineEdit::errorMessage() const
{
return m_bd->m_errorMessage;
}
void BaseValidatingLineEdit::slotChanged(const QString &t)
{
m_bd->m_errorMessage.clear();
// Are we displaying the initial text?
const bool isDisplayingInitialText = !m_bd->m_initialText.isEmpty() && t == m_bd->m_initialText;
const State newState = isDisplayingInitialText ?
DisplayingInitialText :
(validate(t, &m_bd->m_errorMessage) ? Valid : Invalid);
setToolTip(m_bd->m_errorMessage);
if (debug)
qDebug() << Q_FUNC_INFO << t << "State" << m_bd->m_state << "->" << newState << m_bd->m_errorMessage;
// Changed..figure out if valid changed. DisplayingInitialText is not valid,
// but should not show error color. Also trigger on the first change.
if (newState != m_bd->m_state || m_bd->m_firstChange) {
const bool validHasChanged = (m_bd->m_state == Valid) != (newState == Valid);
m_bd->m_state = newState;
m_bd->m_firstChange = false;
setTextColor(this, newState == Invalid ? m_bd->m_errorTextColor : m_bd->m_okTextColor);
if (validHasChanged) {
emit validChanged(newState == Valid);
emit validChanged();
}
}
}
void BaseValidatingLineEdit::slotReturnPressed()
{
if (isValid())
emit validReturnPressed();
}
void BaseValidatingLineEdit::triggerChanged()
{
slotChanged(text());
}
} // namespace Utils
/**
******************************************************************************
*
* @file basevalidatinglineedit.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef BASEVALIDATINGLINEEDIT_H
#define BASEVALIDATINGLINEEDIT_H
#include "utils_global.h"
#include <QtGui/QLineEdit>
namespace Utils {
struct BaseValidatingLineEditPrivate;
/**
* Base class for validating line edits that performs validation in a virtual
* validate() function to be implemented in derived classes.
* When invalid, the text color will turn red and a tooltip will
* contain the error message. This approach is less intrusive than a
* QValidator which will prevent the user from entering certain characters.
*
* The widget has a concept of an "initialText" which can be something like
* "<Enter name here>". This results in state 'DisplayingInitialText', which
* is not valid, but is not marked red.
*/
class QTCREATOR_UTILS_EXPORT BaseValidatingLineEdit : public QLineEdit
{
Q_OBJECT
Q_DISABLE_COPY(BaseValidatingLineEdit)
Q_PROPERTY(QString initialText READ initialText WRITE setInitialText DESIGNABLE true)
Q_PROPERTY(QColor errorColor READ errorColor WRITE setErrorColor DESIGNABLE true)
public:
enum State { Invalid, DisplayingInitialText, Valid };
explicit BaseValidatingLineEdit(QWidget *parent = 0);
virtual ~BaseValidatingLineEdit();
State state() const;
bool isValid() const;
QString errorMessage() const;
QString initialText() const;
void setInitialText(const QString &);
QColor errorColor() const;
void setErrorColor(const QColor &);
// Trigger an update (after changing settings)
void triggerChanged();
static QColor textColor(const QWidget *w);
static void setTextColor(QWidget *w, const QColor &c);
signals:
void validChanged();
void validChanged(bool validState);
void validReturnPressed();
protected:
virtual bool validate(const QString &value, QString *errorMessage) const = 0;
protected slots:
// Custom behaviour can be added here. The base implementation must
// be called.
virtual void slotReturnPressed();
virtual void slotChanged(const QString &t);
private:
BaseValidatingLineEditPrivate *m_bd;
};
} // namespace Utils
#endif // BASEVALIDATINGLINEEDIT_H
/**
******************************************************************************
*
* @file checkablemessagebox.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "checkablemessagebox.h"
#include "ui_checkablemessagebox.h"
#include <QtGui/QPushButton>
#include <QtCore/QDebug>
namespace Utils {
struct CheckableMessageBoxPrivate {
CheckableMessageBoxPrivate() : clickedButton(0) {}
Ui::CheckableMessageBox ui;
QAbstractButton *clickedButton;
};
CheckableMessageBox::CheckableMessageBox(QWidget *parent) :
QDialog(parent),
m_d(new CheckableMessageBoxPrivate)
{
setModal(true);
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
m_d->ui.setupUi(this);
m_d->ui.pixmapLabel->setVisible(false);
connect(m_d->ui.buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(m_d->ui.buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
connect(m_d->ui.buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(slotClicked(QAbstractButton*)));
}
CheckableMessageBox::~CheckableMessageBox()
{
delete m_d;
}
void CheckableMessageBox::slotClicked(QAbstractButton *b)
{
m_d->clickedButton = b;
}
QAbstractButton *CheckableMessageBox::clickedButton() const
{
return m_d->clickedButton;
}
QDialogButtonBox::StandardButton CheckableMessageBox::clickedStandardButton() const
{
if (m_d->clickedButton)
return m_d->ui.buttonBox->standardButton(m_d->clickedButton);
return QDialogButtonBox::NoButton;
}
QString CheckableMessageBox::text() const
{
return m_d->ui.messageLabel->text();
}
void CheckableMessageBox::setText(const QString &t)
{
m_d->ui.messageLabel->setText(t);
}
QPixmap CheckableMessageBox::iconPixmap() const
{
if (const QPixmap *p = m_d->ui.pixmapLabel->pixmap())
return QPixmap(*p);
return QPixmap();
}
void CheckableMessageBox::setIconPixmap(const QPixmap &p)
{
m_d->ui.pixmapLabel->setPixmap(p);
m_d->ui.pixmapLabel->setVisible(!p.isNull());
}
bool CheckableMessageBox::isChecked() const
{
return m_d->ui.checkBox->isChecked();
}
void CheckableMessageBox::setChecked(bool s)
{
m_d->ui.checkBox->setChecked(s);
}
QString CheckableMessageBox::checkBoxText() const
{
return m_d->ui.checkBox->text();
}
void CheckableMessageBox::setCheckBoxText(const QString &t)
{
m_d->ui.checkBox->setText(t);
}
QDialogButtonBox::StandardButtons CheckableMessageBox::standardButtons() const
{
return m_d->ui.buttonBox->standardButtons();
}
void CheckableMessageBox::setStandardButtons(QDialogButtonBox::StandardButtons s)
{
m_d->ui.buttonBox->setStandardButtons(s);
}
QDialogButtonBox::StandardButton CheckableMessageBox::defaultButton() const
{
foreach (QAbstractButton *b, m_d->ui.buttonBox->buttons())
if (QPushButton *pb = qobject_cast<QPushButton *>(b))
if (pb->isDefault())
return m_d->ui.buttonBox->standardButton(pb);
return QDialogButtonBox::NoButton;
}
void CheckableMessageBox::setDefaultButton(QDialogButtonBox::StandardButton s)
{
if (QPushButton *b = m_d->ui.buttonBox->button(s)) {
b->setDefault(true);
b->setFocus();
}
}
QDialogButtonBox::StandardButton
CheckableMessageBox::question(QWidget *parent,
const QString &title,
const QString &question,
const QString &checkBoxText,
bool *checkBoxSetting,
QDialogButtonBox::StandardButtons buttons,
QDialogButtonBox::StandardButton defaultButton)
{
CheckableMessageBox mb(parent);
mb.setWindowTitle(title);
mb.setIconPixmap(QMessageBox::standardIcon(QMessageBox::Question));
mb.setText(question);
mb.setCheckBoxText(checkBoxText);
mb.setChecked(*checkBoxSetting);
mb.setStandardButtons(buttons);
mb.setDefaultButton(defaultButton);
mb.exec();
*checkBoxSetting = mb.isChecked();
return mb.clickedStandardButton();
}
QMessageBox::StandardButton CheckableMessageBox::dialogButtonBoxToMessageBoxButton(QDialogButtonBox::StandardButton db)
{
return static_cast<QMessageBox::StandardButton>(int(db));
}
} // namespace Utils
/**
******************************************************************************
*
* @file checkablemessagebox.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef CHECKABLEMESSAGEBOX_H
#define CHECKABLEMESSAGEBOX_H
#include "utils_global.h"
#include <QtGui/QDialogButtonBox>
#include <QtGui/QMessageBox>
#include <QtGui/QDialog>
namespace Utils {
struct CheckableMessageBoxPrivate;
/* A messagebox suitable for questions with a
* "Do not ask me again" checkbox. Emulates the QMessageBox API with
* static conveniences. */
class QTCREATOR_UTILS_EXPORT CheckableMessageBox : public QDialog
{
Q_OBJECT
Q_PROPERTY(QString text READ text WRITE setText)
Q_PROPERTY(QPixmap iconPixmap READ iconPixmap WRITE setIconPixmap)
Q_PROPERTY(bool isChecked READ isChecked WRITE setChecked)
Q_PROPERTY(QString checkBoxText READ checkBoxText WRITE setCheckBoxText)
Q_PROPERTY(QDialogButtonBox::StandardButtons buttons READ standardButtons WRITE setStandardButtons)
Q_PROPERTY(QDialogButtonBox::StandardButton defaultButton READ defaultButton WRITE setDefaultButton)
public:
explicit CheckableMessageBox(QWidget *parent);
virtual ~CheckableMessageBox();
static QDialogButtonBox::StandardButton
question(QWidget *parent,
const QString &title,
const QString &question,
const QString &checkBoxText,
bool *checkBoxSetting,
QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Yes|QDialogButtonBox::No,
QDialogButtonBox::StandardButton defaultButton = QDialogButtonBox::No);
QString text() const;
void setText(const QString &);
bool isChecked() const;
void setChecked(bool s);
QString checkBoxText() const;
void setCheckBoxText(const QString &);
QDialogButtonBox::StandardButtons standardButtons() const;
void setStandardButtons(QDialogButtonBox::StandardButtons s);
QDialogButtonBox::StandardButton defaultButton() const;
void setDefaultButton(QDialogButtonBox::StandardButton s);
// see static QMessageBox::standardPixmap()
QPixmap iconPixmap() const;
void setIconPixmap (const QPixmap &p);
// Query the result
QAbstractButton *clickedButton() const;
QDialogButtonBox::StandardButton clickedStandardButton() const;
// Conversion convenience
static QMessageBox::StandardButton dialogButtonBoxToMessageBoxButton(QDialogButtonBox::StandardButton);
private slots:
void slotClicked(QAbstractButton *b);
private:
CheckableMessageBoxPrivate *m_d;
};
} // namespace Utils
#endif // CHECKABLEMESSAGEBOX_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Utils::CheckableMessageBox</class>
<widget class="QDialog" name="Utils::CheckableMessageBox">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>195</width>
<height>107</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="pixmapLabel"/>
</item>
<item>
<spacer name="pixmapSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>5</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="messageLabel">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="checkBoxLeftSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>CheckBox</string>
</property>
</widget>
</item>
<item>
<spacer name="checkBoxRightSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="buttonSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Minimum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>5</height>
</size>
</property>
</spacer>
</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>
<property name="centerButtons">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Utils::CheckableMessageBox</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>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Utils::CheckableMessageBox</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>
/**
******************************************************************************
*
* @file classnamevalidatinglineedit.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "classnamevalidatinglineedit.h"
#include <utils/qtcassert.h>
#include <QtCore/QDebug>
#include <QtCore/QRegExp>
namespace Utils {
struct ClassNameValidatingLineEditPrivate {
ClassNameValidatingLineEditPrivate();
const QRegExp m_nameRegexp;
const QString m_namespaceDelimiter;
bool m_namespacesEnabled;
bool m_lowerCaseFileName;
};
// Match something like "Namespace1::Namespace2::ClassName".
ClassNameValidatingLineEditPrivate:: ClassNameValidatingLineEditPrivate() :
m_nameRegexp(QLatin1String("[a-zA-Z_][a-zA-Z0-9_]*(::[a-zA-Z_][a-zA-Z0-9_]*)*")),
m_namespaceDelimiter(QLatin1String("::")),
m_namespacesEnabled(false),
m_lowerCaseFileName(true)
{
QTC_ASSERT(m_nameRegexp.isValid(), return);
}
// --------------------- ClassNameValidatingLineEdit
ClassNameValidatingLineEdit::ClassNameValidatingLineEdit(QWidget *parent) :
Utils::BaseValidatingLineEdit(parent),
m_d(new ClassNameValidatingLineEditPrivate)
{
}
ClassNameValidatingLineEdit::~ClassNameValidatingLineEdit()
{
delete m_d;
}
bool ClassNameValidatingLineEdit::namespacesEnabled() const
{
return m_d->m_namespacesEnabled;
}
void ClassNameValidatingLineEdit::setNamespacesEnabled(bool b)
{
m_d->m_namespacesEnabled = b;
}
bool ClassNameValidatingLineEdit::validate(const QString &value, QString *errorMessage) const
{
if (!m_d->m_namespacesEnabled && value.contains(QLatin1Char(':'))) {
if (errorMessage)
*errorMessage = tr("The class name must not contain namespace delimiters.");
return false;
} else if (value.isEmpty()) {
if (errorMessage)
*errorMessage = tr("Please enter a class name.");
return false;
} else if (!m_d->m_nameRegexp.exactMatch(value)) {
if (errorMessage)
*errorMessage = tr("The class name contains invalid characters.");
return false;
}
return true;
}
void ClassNameValidatingLineEdit::slotChanged(const QString &t)
{
Utils::BaseValidatingLineEdit::slotChanged(t);
if (isValid()) {
// Suggest file names, strip namespaces
QString fileName = m_d->m_lowerCaseFileName ? t.toLower() : t;
if (m_d->m_namespacesEnabled) {
const int namespaceIndex = fileName.lastIndexOf(m_d->m_namespaceDelimiter);
if (namespaceIndex != -1)
fileName.remove(0, namespaceIndex + m_d->m_namespaceDelimiter.size());
}
emit updateFileName(fileName);
}
}
QString ClassNameValidatingLineEdit::createClassName(const QString &name)
{
// Remove spaces and convert the adjacent characters to uppercase
QString className = name;
QRegExp spaceMatcher(QLatin1String(" +(\\w)"), Qt::CaseSensitive, QRegExp::RegExp2);
QTC_ASSERT(spaceMatcher.isValid(), /**/);
int pos;
while ((pos = spaceMatcher.indexIn(className)) != -1) {
className.replace(pos, spaceMatcher.matchedLength(),
spaceMatcher.cap(1).toUpper());
}
// Filter out any remaining invalid characters
className.remove(QRegExp(QLatin1String("[^a-zA-Z0-9_]")));
// If the first character is numeric, prefix the name with a "_"
if (className.at(0).isNumber()) {
className.prepend(QLatin1Char('_'));
} else {
// Convert the first character to uppercase
className.replace(0, 1, className.left(1).toUpper());
}
return className;
}
bool ClassNameValidatingLineEdit::lowerCaseFileName() const
{
return m_d->m_lowerCaseFileName;
}
void ClassNameValidatingLineEdit::setLowerCaseFileName(bool v)
{
m_d->m_lowerCaseFileName = v;
}
} // namespace Utils
/**
******************************************************************************
*
* @file classnamevalidatinglineedit.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef CLASSNAMEVALIDATINGLINEEDIT_H
#define CLASSNAMEVALIDATINGLINEEDIT_H
#include "utils_global.h"
#include "basevalidatinglineedit.h"
namespace Utils {
struct ClassNameValidatingLineEditPrivate;
/* A Line edit that validates a C++ class name and emits a signal
* to derive suggested file names from it. */
class QTCREATOR_UTILS_EXPORT ClassNameValidatingLineEdit
: public Utils::BaseValidatingLineEdit
{
Q_DISABLE_COPY(ClassNameValidatingLineEdit)
Q_PROPERTY(bool namespacesEnabled READ namespacesEnabled WRITE setNamespacesEnabled DESIGNABLE true)
Q_PROPERTY(bool lowerCaseFileName READ lowerCaseFileName WRITE setLowerCaseFileName)
Q_OBJECT
public:
explicit ClassNameValidatingLineEdit(QWidget *parent = 0);
virtual ~ClassNameValidatingLineEdit();
bool namespacesEnabled() const;
void setNamespacesEnabled(bool b);
bool lowerCaseFileName() const;
void setLowerCaseFileName(bool v);
// Clean an input string to get a valid class name.
static QString createClassName(const QString &name);
signals:
// Will be emitted with a suggestion for a base name of the
// source/header file of the class.
void updateFileName(const QString &t);
protected:
virtual bool validate(const QString &value, QString *errorMessage) const;
virtual void slotChanged(const QString &t);
private:
ClassNameValidatingLineEditPrivate *m_d;
};
} // namespace Utils
#endif // CLASSNAMEVALIDATINGLINEEDIT_H
/**
******************************************************************************
*
* @file codegeneration.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "codegeneration.h"
#include <QtCore/QTextStream>
#include <QtCore/QStringList>
#include <QtCore/QFileInfo>
namespace Utils {
QTCREATOR_UTILS_EXPORT QString fileNameToCppIdentifier(const QString &s)
{
QString rc;
const int len = s.size();
const QChar underscore = QLatin1Char('_');
const QChar dot = QLatin1Char('.');
for (int i = 0; i < len; i++) {
const QChar c = s.at(i);
if (c == underscore || c.isLetterOrNumber())
rc += c;
else if (c == dot)
rc += underscore;
}
return rc;
}
QTCREATOR_UTILS_EXPORT QString headerGuard(const QString &file)
{
const QFileInfo fi(file);
QString rc = fileNameToCppIdentifier(fi.completeBaseName()).toUpper();
rc += QLatin1Char('_');
rc += fileNameToCppIdentifier(fi.suffix()).toUpper();
return rc;
}
QTCREATOR_UTILS_EXPORT
void writeIncludeFileDirective(const QString &file, bool globalInclude,
QTextStream &str)
{
const QChar opening = globalInclude ? QLatin1Char('<') : QLatin1Char('"');
const QChar closing = globalInclude ? QLatin1Char('>') : QLatin1Char('"');
str << QLatin1String("#include ") << opening << file << closing << QLatin1Char('\n');
}
QTCREATOR_UTILS_EXPORT
QString writeOpeningNameSpaces(const QStringList &l, const QString &indent,
QTextStream &str)
{
const int count = l.size();
QString rc;
if (count) {
str << '\n';
for (int i = 0; i < count; i++) {
str << rc << "namespace " << l.at(i) << " {\n";
rc += indent;
}
}
return rc;
}
QTCREATOR_UTILS_EXPORT
void writeClosingNameSpaces(const QStringList &l, const QString &indent,
QTextStream &str)
{
if (!l.empty())
str << '\n';
for (int i = l.size() - 1; i >= 0; i--) {
if (i)
str << QString(indent.size() * i, QLatin1Char(' '));
str << "} // namespace " << l.at(i) << '\n';
}
}
} // namespace Utils
/**
******************************************************************************
*
* @file codegeneration.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef CODEGENERATION_H
#define CODEGENERATION_H
#include "utils_global.h"
#include <QtCore/QString>
QT_BEGIN_NAMESPACE
class QTextStream;
class QStringList;
QT_END_NAMESPACE
namespace Utils {
// Convert a file name to a Cpp identifier (stripping invalid characters
// or replacing them by an underscore).
QTCREATOR_UTILS_EXPORT QString fileNameToCppIdentifier(const QString &s);
QTCREATOR_UTILS_EXPORT QString headerGuard(const QString &file);
QTCREATOR_UTILS_EXPORT
void writeIncludeFileDirective(const QString &file,
bool globalInclude,
QTextStream &str);
// Write opening namespaces and return an indentation string to be used
// in the following code if there are any.
QTCREATOR_UTILS_EXPORT
QString writeOpeningNameSpaces(const QStringList &namespaces,
const QString &indent,
QTextStream &str);
// Close namespacesnamespaces
QTCREATOR_UTILS_EXPORT
void writeClosingNameSpaces(const QStringList &namespaces,
const QString &indent,
QTextStream &str);
} // namespace Utils
#endif // CODEGENERATION_H
/**
******************************************************************************
*
* @file consoleprocess.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "consoleprocess.h"
namespace Utils {
QString ConsoleProcess::modeOption(Mode m)
{
switch (m) {
case Debug:
return QLatin1String("debug");
case Suspend:
return QLatin1String("suspend");
case Run:
break;
}
return QLatin1String("run");
}
QString ConsoleProcess::msgCommChannelFailed(const QString &error)
{
return tr("Cannot set up communication channel: %1").arg(error);
}
QString ConsoleProcess::msgPromptToClose()
{
//! Showed in a terminal which might have
//! a different character set on Windows.
return tr("Press <RETURN> to close this window...");
}
QString ConsoleProcess::msgCannotCreateTempFile(const QString &why)
{
return tr("Cannot create temporary file: %1").arg(why);
}
QString ConsoleProcess::msgCannotCreateTempDir(const QString & dir, const QString &why)
{
return tr("Cannot create temporary directory '%1': %2").arg(dir, why);
}
QString ConsoleProcess::msgUnexpectedOutput()
{
return tr("Unexpected output from helper program.");
}
QString ConsoleProcess::msgCannotChangeToWorkDir(const QString & dir, const QString &why)
{
return tr("Cannot change to working directory '%1': %2").arg(dir, why);
}
QString ConsoleProcess::msgCannotExecute(const QString & p, const QString &why)
{
return tr("Cannot execute '%1': %2").arg(p, why);
}
}
/**
******************************************************************************
*
* @file consoleprocess.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef CONSOLEPROCESS_H
#define CONSOLEPROCESS_H
#include "abstractprocess.h"
#include <QtCore/QObject>
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QProcess>
#include <QtNetwork/QLocalServer>
#ifdef Q_OS_WIN
#include <windows.h>
QT_BEGIN_NAMESPACE
class QWinEventNotifier;
QT_END_NAMESPACE
#endif
QT_BEGIN_NAMESPACE
class QSettings;
class QTemporaryFile;
QT_END_NAMESPACE
namespace Utils {
class QTCREATOR_UTILS_EXPORT ConsoleProcess : public QObject, public AbstractProcess
{
Q_OBJECT
public:
enum Mode { Run, Debug, Suspend };
ConsoleProcess(QObject *parent = 0);
~ConsoleProcess();
bool start(const QString &program, const QStringList &args);
void stop();
void setMode(Mode m) { m_mode = m; }
Mode mode() const { return m_mode; }
bool isRunning() const; // This reflects the state of the console+stub
qint64 applicationPID() const { return m_appPid; }
int exitCode() const { return m_appCode; } // This will be the signal number if exitStatus == CrashExit
QProcess::ExitStatus exitStatus() const { return m_appStatus; }
#ifdef Q_OS_UNIX
void setSettings(QSettings *settings) { m_settings = settings; }
static QString defaultTerminalEmulator();
static QString terminalEmulator(const QSettings *settings);
static void setTerminalEmulator(QSettings *settings, const QString &term);
#endif
signals:
void processError(const QString &error);
// These reflect the state of the actual client process
void processStarted();
void processStopped();
// These reflect the state of the console+stub
void wrapperStarted();
void wrapperStopped();
private slots:
void stubConnectionAvailable();
void readStubOutput();
void stubExited();
#ifdef Q_OS_WIN
void inferiorExited();
#endif
private:
static QString modeOption(Mode m);
static QString msgCommChannelFailed(const QString &error);
static QString msgPromptToClose();
static QString msgCannotCreateTempFile(const QString &why);
static QString msgCannotCreateTempDir(const QString & dir, const QString &why);
static QString msgUnexpectedOutput();
static QString msgCannotChangeToWorkDir(const QString & dir, const QString &why);
static QString msgCannotExecute(const QString & p, const QString &why);
QString stubServerListen();
void stubServerShutdown();
#ifdef Q_OS_WIN
void cleanupStub();
void cleanupInferior();
#endif
Mode m_mode;
qint64 m_appPid;
int m_appCode;
QString m_executable;
QProcess::ExitStatus m_appStatus;
QLocalServer m_stubServer;
QLocalSocket *m_stubSocket;
QTemporaryFile *m_tempFile;
#ifdef Q_OS_WIN
PROCESS_INFORMATION *m_pid;
HANDLE m_hInferior;
QWinEventNotifier *inferiorFinishedNotifier;
QWinEventNotifier *processFinishedNotifier;
#else
QProcess m_process;
QByteArray m_stubServerDir;
QSettings *m_settings;
#endif
};
} //namespace Utils
#endif
/**
******************************************************************************
*
* @file consoleprocess_unix.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "consoleprocess.h"
#include <QtCore/QCoreApplication>
#include <QtCore/QDir>
#include <QtCore/QSettings>
#include <QtCore/QTemporaryFile>
#include <QtNetwork/QLocalSocket>
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
using namespace Utils;
ConsoleProcess::ConsoleProcess(QObject *parent) :
QObject(parent),
m_mode(Run),
m_appPid(0),
m_stubSocket(0),
m_settings(0)
{
connect(&m_stubServer, SIGNAL(newConnection()), SLOT(stubConnectionAvailable()));
m_process.setProcessChannelMode(QProcess::ForwardedChannels);
connect(&m_process, SIGNAL(finished(int, QProcess::ExitStatus)),
SLOT(stubExited()));
}
ConsoleProcess::~ConsoleProcess()
{
stop();
}
bool ConsoleProcess::start(const QString &program, const QStringList &args)
{
if (isRunning())
return false;
const QString err = stubServerListen();
if (!err.isEmpty()) {
emit processError(msgCommChannelFailed(err));
return false;
}
if (!environment().isEmpty()) {
m_tempFile = new QTemporaryFile();
if (!m_tempFile->open()) {
stubServerShutdown();
emit processError(msgCannotCreateTempFile(m_tempFile->errorString()));
delete m_tempFile;
m_tempFile = 0;
return false;
}
foreach (const QString &var, environment()) {
m_tempFile->write(var.toLocal8Bit());
m_tempFile->write("", 1);
}
m_tempFile->flush();
}
QStringList xtermArgs = terminalEmulator(m_settings).split(QLatin1Char(' ')); // FIXME: quoting
xtermArgs
#ifdef Q_OS_MAC
<< (QCoreApplication::applicationDirPath() + QLatin1String("/../Resources/qtcreator_process_stub"))
#else
<< (QCoreApplication::applicationDirPath() + QLatin1String("/qtcreator_process_stub"))
#endif
<< modeOption(m_mode)
<< m_stubServer.fullServerName()
<< msgPromptToClose()
<< workingDirectory()
<< (m_tempFile ? m_tempFile->fileName() : 0)
<< program << args;
QString xterm = xtermArgs.takeFirst();
m_process.start(xterm, xtermArgs);
if (!m_process.waitForStarted()) {
stubServerShutdown();
emit processError(tr("Cannot start the terminal emulator '%1'.").arg(xterm));
delete m_tempFile;
m_tempFile = 0;
return false;
}
m_executable = program;
emit wrapperStarted();
return true;
}
void ConsoleProcess::stop()
{
if (!isRunning())
return;
stubServerShutdown();
m_appPid = 0;
m_process.terminate();
if (!m_process.waitForFinished(1000))
m_process.kill();
m_process.waitForFinished();
}
bool ConsoleProcess::isRunning() const
{
return m_process.state() != QProcess::NotRunning;
}
QString ConsoleProcess::stubServerListen()
{
// We need to put the socket in a private directory, as some systems simply do not
// check the file permissions of sockets.
QString stubFifoDir;
forever {
{
QTemporaryFile tf;
if (!tf.open())
return msgCannotCreateTempFile(tf.errorString());
stubFifoDir = QFile::encodeName(tf.fileName());
}
// By now the temp file was deleted again
m_stubServerDir = QFile::encodeName(stubFifoDir);
if (!::mkdir(m_stubServerDir.constData(), 0700))
break;
if (errno != EEXIST)
return msgCannotCreateTempDir(stubFifoDir, QString::fromLocal8Bit(strerror(errno)));
}
const QString stubServer = stubFifoDir + "/stub-socket";
if (!m_stubServer.listen(stubServer)) {
::rmdir(m_stubServerDir.constData());
return tr("Cannot create socket '%1': %2").arg(stubServer, m_stubServer.errorString());
}
return QString();
}
void ConsoleProcess::stubServerShutdown()
{
delete m_stubSocket;
m_stubSocket = 0;
if (m_stubServer.isListening()) {
m_stubServer.close();
::rmdir(m_stubServerDir.constData());
}
}
void ConsoleProcess::stubConnectionAvailable()
{
m_stubSocket = m_stubServer.nextPendingConnection();
connect(m_stubSocket, SIGNAL(readyRead()), SLOT(readStubOutput()));
}
static QString errorMsg(int code)
{
return QString::fromLocal8Bit(strerror(code));
}
void ConsoleProcess::readStubOutput()
{
while (m_stubSocket->canReadLine()) {
QByteArray out = m_stubSocket->readLine();
out.chop(1); // \n
if (out.startsWith("err:chdir ")) {
emit processError(msgCannotChangeToWorkDir(workingDirectory(), errorMsg(out.mid(10).toInt())));
} else if (out.startsWith("err:exec ")) {
emit processError(msgCannotExecute(m_executable, errorMsg(out.mid(9).toInt())));
} else if (out.startsWith("pid ")) {
// Will not need it any more
delete m_tempFile;
m_tempFile = 0;
m_appPid = out.mid(4).toInt();
emit processStarted();
} else if (out.startsWith("exit ")) {
m_appStatus = QProcess::NormalExit;
m_appCode = out.mid(5).toInt();
m_appPid = 0;
emit processStopped();
} else if (out.startsWith("crash ")) {
m_appStatus = QProcess::CrashExit;
m_appCode = out.mid(6).toInt();
m_appPid = 0;
emit processStopped();
} else {
emit processError(msgUnexpectedOutput());
m_process.terminate();
break;
}
}
}
void ConsoleProcess::stubExited()
{
// The stub exit might get noticed before we read the error status.
if (m_stubSocket && m_stubSocket->state() == QLocalSocket::ConnectedState)
m_stubSocket->waitForDisconnected();
stubServerShutdown();
delete m_tempFile;
m_tempFile = 0;
if (m_appPid) {
m_appStatus = QProcess::CrashExit;
m_appCode = -1;
m_appPid = 0;
emit processStopped(); // Maybe it actually did not, but keep state consistent
}
emit wrapperStopped();
}
QString ConsoleProcess::defaultTerminalEmulator()
{
// FIXME: enable this once runInTerminal works nicely
#if 0 //def Q_OS_MAC
return QDir::cleanPath(QCoreApplication::applicationDirPath()
+ QLatin1String("/../Resources/runInTerminal.command"));
#else
return QLatin1String("xterm");
#endif
}
QString ConsoleProcess::terminalEmulator(const QSettings *settings)
{
const QString dflt = defaultTerminalEmulator() + QLatin1String(" -e");
if (!settings)
return dflt;
return settings->value(QLatin1String("General/TerminalEmulator"), dflt).toString();
}
void ConsoleProcess::setTerminalEmulator(QSettings *settings, const QString &term)
{
return settings->setValue(QLatin1String("General/TerminalEmulator"), term);
}
/**
******************************************************************************
*
* @file consoleprocess_win.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "consoleprocess.h"
#include "winutils.h"
#include <QtCore/QCoreApplication>
#include <QtCore/QDir>
#include <QtCore/QTemporaryFile>
#include <QtCore/QAbstractEventDispatcher>
#include "qwineventnotifier_p.h"
#include <QtNetwork/QLocalSocket>
#include <stdlib.h>
using namespace Utils;
ConsoleProcess::ConsoleProcess(QObject *parent) :
QObject(parent),
m_mode(Run),
m_appPid(0),
m_stubSocket(0),
m_tempFile(0),
m_pid(0),
m_hInferior(NULL),
inferiorFinishedNotifier(0),
processFinishedNotifier(0)
{
connect(&m_stubServer, SIGNAL(newConnection()), SLOT(stubConnectionAvailable()));
}
ConsoleProcess::~ConsoleProcess()
{
stop();
}
bool ConsoleProcess::start(const QString &program, const QStringList &args)
{
if (isRunning())
return false;
const QString err = stubServerListen();
if (!err.isEmpty()) {
emit processError(msgCommChannelFailed(err));
return false;
}
if (!environment().isEmpty()) {
m_tempFile = new QTemporaryFile();
if (!m_tempFile->open()) {
stubServerShutdown();
emit processError(msgCannotCreateTempFile(m_tempFile->errorString()));
delete m_tempFile;
m_tempFile = 0;
return false;
}
QTextStream out(m_tempFile);
out.setCodec("UTF-16LE");
out.setGenerateByteOrderMark(false);
foreach (const QString &var, fixWinEnvironment(environment()))
out << var << QChar(0);
out << QChar(0);
}
STARTUPINFO si;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
m_pid = new PROCESS_INFORMATION;
ZeroMemory(m_pid, sizeof(PROCESS_INFORMATION));
QString workDir = QDir::toNativeSeparators(workingDirectory());
if (!workDir.isEmpty() && !workDir.endsWith('\\'))
workDir.append('\\');
QStringList stubArgs;
stubArgs << modeOption(m_mode)
<< m_stubServer.fullServerName()
<< workDir
<< (m_tempFile ? m_tempFile->fileName() : 0)
<< createWinCommandline(program, args)
<< msgPromptToClose();
const QString cmdLine = createWinCommandline(
QCoreApplication::applicationDirPath() + QLatin1String("/qtcreator_process_stub.exe"), stubArgs);
bool success = CreateProcessW(0, (WCHAR*)cmdLine.utf16(),
0, 0, FALSE, CREATE_NEW_CONSOLE,
0, 0,
&si, m_pid);
if (!success) {
delete m_pid;
m_pid = 0;
delete m_tempFile;
m_tempFile = 0;
stubServerShutdown();
emit processError(tr("The process '%1' could not be started: %2").arg(cmdLine, winErrorMessage(GetLastError())));
return false;
}
processFinishedNotifier = new QWinEventNotifier(m_pid->hProcess, this);
connect(processFinishedNotifier, SIGNAL(activated(HANDLE)), SLOT(stubExited()));
emit wrapperStarted();
return true;
}
void ConsoleProcess::stop()
{
if (m_hInferior != NULL) {
TerminateProcess(m_hInferior, (unsigned)-1);
cleanupInferior();
}
if (m_pid) {
TerminateProcess(m_pid->hProcess, (unsigned)-1);
WaitForSingleObject(m_pid->hProcess, INFINITE);
cleanupStub();
}
}
bool ConsoleProcess::isRunning() const
{
return m_pid != 0;
}
QString ConsoleProcess::stubServerListen()
{
if (m_stubServer.listen(QString::fromLatin1("creator-%1-%2")
.arg(QCoreApplication::applicationPid())
.arg(rand())))
return QString();
return m_stubServer.errorString();
}
void ConsoleProcess::stubServerShutdown()
{
delete m_stubSocket;
m_stubSocket = 0;
if (m_stubServer.isListening())
m_stubServer.close();
}
void ConsoleProcess::stubConnectionAvailable()
{
m_stubSocket = m_stubServer.nextPendingConnection();
connect(m_stubSocket, SIGNAL(readyRead()), SLOT(readStubOutput()));
}
void ConsoleProcess::readStubOutput()
{
while (m_stubSocket->canReadLine()) {
QByteArray out = m_stubSocket->readLine();
out.chop(2); // \r\n
if (out.startsWith("err:chdir ")) {
emit processError(msgCannotChangeToWorkDir(workingDirectory(), winErrorMessage(out.mid(10).toInt())));
} else if (out.startsWith("err:exec ")) {
emit processError(msgCannotExecute(m_executable, winErrorMessage(out.mid(9).toInt())));
} else if (out.startsWith("pid ")) {
// Wil not need it any more
delete m_tempFile;
m_tempFile = 0;
m_appPid = out.mid(4).toInt();
m_hInferior = OpenProcess(
SYNCHRONIZE | PROCESS_QUERY_INFORMATION | PROCESS_TERMINATE,
FALSE, m_appPid);
if (m_hInferior == NULL) {
emit processError(tr("Cannot obtain a handle to the inferior: %1")
.arg(winErrorMessage(GetLastError())));
// Uhm, and now what?
continue;
}
inferiorFinishedNotifier = new QWinEventNotifier(m_hInferior, this);
connect(inferiorFinishedNotifier, SIGNAL(activated(HANDLE)), SLOT(inferiorExited()));
emit processStarted();
} else {
emit processError(msgUnexpectedOutput());
TerminateProcess(m_pid->hProcess, (unsigned)-1);
break;
}
}
}
void ConsoleProcess::cleanupInferior()
{
delete inferiorFinishedNotifier;
inferiorFinishedNotifier = 0;
CloseHandle(m_hInferior);
m_hInferior = NULL;
m_appPid = 0;
}
void ConsoleProcess::inferiorExited()
{
DWORD chldStatus;
if (!GetExitCodeProcess(m_hInferior, &chldStatus))
emit processError(tr("Cannot obtain exit status from inferior: %1")
.arg(winErrorMessage(GetLastError())));
cleanupInferior();
m_appStatus = QProcess::NormalExit;
m_appCode = chldStatus;
emit processStopped();
}
void ConsoleProcess::cleanupStub()
{
stubServerShutdown();
delete processFinishedNotifier;
processFinishedNotifier = 0;
CloseHandle(m_pid->hThread);
CloseHandle(m_pid->hProcess);
delete m_pid;
m_pid = 0;
delete m_tempFile;
m_tempFile = 0;
}
void ConsoleProcess::stubExited()
{
// The stub exit might get noticed before we read the pid for the kill.
if (m_stubSocket && m_stubSocket->state() == QLocalSocket::ConnectedState)
m_stubSocket->waitForDisconnected();
cleanupStub();
if (m_hInferior != NULL) {
TerminateProcess(m_hInferior, (unsigned)-1);
cleanupInferior();
m_appStatus = QProcess::CrashExit;
m_appCode = -1;
emit processStopped();
}
emit wrapperStopped();
}
/**
******************************************************************************
*
* @file coordinateconversions.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief General conversions with different coordinate systems.
* - all angles in deg
* - distances in meters
* - altitude above WGS-84 elipsoid
*
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "coordinateconversions.h"
#include <stdint.h>
#include <QDebug>
#include <math.h>
#include <qmath.h>
#define RAD2DEG (180.0/M_PI)
#define DEG2RAD (M_PI/180.0)
namespace Utils {
CoordinateConversions::CoordinateConversions()
{
}
/**
* Get rotation matrix from ECEF to NED for that LLA
* @param[in] LLA Longitude latitude altitude for this location
* @param[out] Rne[3][3] Rotation matrix
*/
void CoordinateConversions::RneFromLLA(double LLA[3], double Rne[3][3]){
float sinLat, sinLon, cosLat, cosLon;
sinLat=(float)sin(DEG2RAD*LLA[0]);
sinLon=(float)sin(DEG2RAD*LLA[1]);
cosLat=(float)cos(DEG2RAD*LLA[0]);
cosLon=(float)cos(DEG2RAD*LLA[1]);
Rne[0][0] = -sinLat*cosLon; Rne[0][1] = -sinLat*sinLon; Rne[0][2] = cosLat;
Rne[1][0] = -sinLon; Rne[1][1] = cosLon; Rne[1][2] = 0;
Rne[2][0] = -cosLat*cosLon; Rne[2][1] = -cosLat*sinLon; Rne[2][2] = -sinLat;
}
/**
* Convert from LLA coordinates to ECEF coordinates
* @param[in] LLA[3] latitude longitude alititude coordinates in
* @param[out] ECEF[3] location in ECEF coordinates
*/
void CoordinateConversions::LLA2ECEF(double LLA[3], double ECEF[3]){
const double a = 6378137.0; // Equatorial Radius
const double e = 8.1819190842622e-2; // Eccentricity
double sinLat, sinLon, cosLat, cosLon;
double N;
sinLat=sin(DEG2RAD*LLA[0]);
sinLon=sin(DEG2RAD*LLA[1]);
cosLat=cos(DEG2RAD*LLA[0]);
cosLon=cos(DEG2RAD*LLA[1]);
N = a / sqrt(1.0 - e*e*sinLat*sinLat); //prime vertical radius of curvature
ECEF[0] = (N+LLA[2])*cosLat*cosLon;
ECEF[1] = (N+LLA[2])*cosLat*sinLon;
ECEF[2] = ((1-e*e)*N + LLA[2]) * sinLat;
}
/**
* Convert from ECEF coordinates to LLA coordinates
* @param[in] ECEF[3] location in ECEF coordinates
* @param[out] LLA[3] latitude longitude alititude coordinates
*/
int CoordinateConversions::ECEF2LLA(double ECEF[3], double LLA[3])
{
const double a = 6378137.0; // Equatorial Radius
const double e = 8.1819190842622e-2; // Eccentricity
double x=ECEF[0], y=ECEF[1], z=ECEF[2];
double Lat, N, NplusH, delta, esLat;
uint16_t iter;
LLA[1] = RAD2DEG*atan2(y,x);
N = a;
NplusH = N;
delta = 1;
Lat = 1;
iter=0;
while (((delta > 1.0e-14)||(delta < -1.0e-14)) && (iter < 100))
{
delta = Lat - atan(z / (sqrt(x*x + y*y)*(1-(N*e*e/NplusH))));
Lat = Lat-delta;
esLat = e*sin(Lat);
N = a / sqrt(1 - esLat*esLat);
NplusH = sqrt(x*x + y*y)/cos(Lat);
iter += 1;
}
LLA[0] = RAD2DEG*Lat;
LLA[2] = NplusH - N;
if (iter==500) return (0);
else return (1);
}
/**
* Get the current location in Longitude, Latitude Altitude (above WSG-48 ellipsoid)
* @param[in] BaseECEF the ECEF of the home location (in cm)
* @param[in] NED the offset from the home location (in m)
* @param[out] position three element double for position in degrees and meters
* @returns
* @arg 0 success
* @arg -1 for failure
*/
int CoordinateConversions::GetLLA(double BaseECEFcm[3], double NED[3], double position[3])
{
int i;
// stored value is in cm, convert to m
double BaseECEFm[3] = {BaseECEFcm[0], BaseECEFcm[1], BaseECEFcm[2]};
double BaseLLA[3];
double ECEF[3];
double Rne [3][3];
// Get LLA address to compute conversion matrix
ECEF2LLA(BaseECEFm, BaseLLA);
RneFromLLA(BaseLLA, Rne);
/* P = ECEF + Rne' * NED */
for(i = 0; i < 3; i++)
ECEF[i] = BaseECEFm[i] + Rne[0][i]*NED[0] + Rne[1][i]*NED[1] + Rne[2][i]*NED[2];
ECEF2LLA(ECEF,position);
return 0;
}
void CoordinateConversions::LLA2Base(double LLA[3], double BaseECEF[3], float Rne[3][3], float NED[3])
{
double ECEF[3];
float diff[3];
LLA2ECEF(LLA, ECEF);
diff[0] = (float)(ECEF[0] - BaseECEF[0]);
diff[1] = (float)(ECEF[1] - BaseECEF[1]);
diff[2] = (float)(ECEF[2] - BaseECEF[2]);
NED[0] = Rne[0][0] * diff[0] + Rne[0][1] * diff[1] + Rne[0][2] * diff[2];
NED[1] = Rne[1][0] * diff[0] + Rne[1][1] * diff[1] + Rne[1][2] * diff[2];
NED[2] = Rne[2][0] * diff[0] + Rne[2][1] * diff[1] + Rne[2][2] * diff[2];
}
// ****** find roll, pitch, yaw from quaternion ********
void CoordinateConversions::Quaternion2RPY(const float q[4], float rpy[3])
{
float R13, R11, R12, R23, R33;
float q0s = q[0] * q[0];
float q1s = q[1] * q[1];
float q2s = q[2] * q[2];
float q3s = q[3] * q[3];
R13 = 2 * (q[1] * q[3] - q[0] * q[2]);
R11 = q0s + q1s - q2s - q3s;
R12 = 2 * (q[1] * q[2] + q[0] * q[3]);
R23 = 2 * (q[2] * q[3] + q[0] * q[1]);
R33 = q0s - q1s - q2s + q3s;
rpy[1] = RAD2DEG * asinf(-R13); // pitch always between -pi/2 to pi/2
rpy[2] = RAD2DEG * atan2f(R12, R11);
rpy[0] = RAD2DEG * atan2f(R23, R33);
//TODO: consider the cases where |R13| ~= 1, |pitch| ~= pi/2
}
// ****** find quaternion from roll, pitch, yaw ********
void CoordinateConversions::RPY2Quaternion(const float rpy[3], float q[4])
{
float phi, theta, psi;
float cphi, sphi, ctheta, stheta, cpsi, spsi;
phi = DEG2RAD * rpy[0] / 2;
theta = DEG2RAD * rpy[1] / 2;
psi = DEG2RAD * rpy[2] / 2;
cphi = cosf(phi);
sphi = sinf(phi);
ctheta = cosf(theta);
stheta = sinf(theta);
cpsi = cosf(psi);
spsi = sinf(psi);
q[0] = cphi * ctheta * cpsi + sphi * stheta * spsi;
q[1] = sphi * ctheta * cpsi - cphi * stheta * spsi;
q[2] = cphi * stheta * cpsi + sphi * ctheta * spsi;
q[3] = cphi * ctheta * spsi - sphi * stheta * cpsi;
if (q[0] < 0) { // q0 always positive for uniqueness
q[0] = -q[0];
q[1] = -q[1];
q[2] = -q[2];
q[3] = -q[3];
}
}
//** Find Rbe, that rotates a vector from earth fixed to body frame, from quaternion **
void CoordinateConversions::Quaternion2R(const float q[4], float Rbe[3][3])
{
float q0s = q[0] * q[0], q1s = q[1] * q[1], q2s = q[2] * q[2], q3s = q[3] * q[3];
Rbe[0][0] = q0s + q1s - q2s - q3s;
Rbe[0][1] = 2 * (q[1] * q[2] + q[0] * q[3]);
Rbe[0][2] = 2 * (q[1] * q[3] - q[0] * q[2]);
Rbe[1][0] = 2 * (q[1] * q[2] - q[0] * q[3]);
Rbe[1][1] = q0s - q1s + q2s - q3s;
Rbe[1][2] = 2 * (q[2] * q[3] + q[0] * q[1]);
Rbe[2][0] = 2 * (q[1] * q[3] + q[0] * q[2]);
Rbe[2][1] = 2 * (q[2] * q[3] - q[0] * q[1]);
Rbe[2][2] = q0s - q1s - q2s + q3s;
}
}
/**
******************************************************************************
*
* @file coordinateconversions.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef COORDINATECONVERSIONS_H
#define COORDINATECONVERSIONS_H
#include "utils_global.h"
#ifndef EXTERNAL_USE
#include "../extensionsystem/pluginmanager.h"
#include "../../plugins/uavobjects/uavobjectmanager.h"
#include "../../plugins/uavobjects/uavobject.h"
#endif
#include "math.h"
namespace Utils {
class QTCREATOR_UTILS_EXPORT CoordinateConversions
{
public:
CoordinateConversions();
int GetLLA(double LLA[3], double NED[3], double position[3]);
void RneFromLLA(double LLA[3], double Rne[3][3]);
void LLA2ECEF(double LLA[3], double ECEF[3]);
int ECEF2LLA(double ECEF[3], double LLA[3]);
void LLA2Base(double LLA[3], double BaseECEF[3], float Rne[3][3], float NED[3]);
void Quaternion2RPY(const float q[4], float rpy[3]);
void RPY2Quaternion(const float rpy[3], float q[4]);
void Quaternion2R(const float q[4], float Rbe[3][3]);
};
}
#endif /* COORDINATECONVERSIONS_H */
/**
******************************************************************************
*
* @file detailsbutton.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "detailsbutton.h"
using namespace Utils;
DetailsButton::DetailsButton(QWidget *parent)
#ifdef Q_OS_MAC
: QPushButton(parent),
#else
: QToolButton(parent),
#endif
m_checked(false)
{
#ifdef Q_OS_MAC
setAttribute(Qt::WA_MacSmallSize);
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
#else
setCheckable(true);
#endif
setText(tr("Show Details"));
connect(this, SIGNAL(clicked()),
this, SLOT(onClicked()));
}
void DetailsButton::onClicked()
{
m_checked = !m_checked;
}
bool DetailsButton::isToggled()
{
return m_checked;
}
/**
******************************************************************************
*
* @file detailsbutton.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef DETAILSBUTTON_H
#define DETAILSBUTTON_H
#include <QtGui/QPushButton>
#include <QtGui/QToolButton>
#include "utils_global.h"
namespace Utils {
class QTCREATOR_UTILS_EXPORT DetailsButton
#ifdef Q_OS_MAC
: public QPushButton
#else
: public QToolButton
#endif
{
Q_OBJECT
public:
DetailsButton(QWidget *parent=0);
bool isToggled();
public slots:
void onClicked();
private:
bool m_checked;
};
}
#endif // DETAILSBUTTON_H
/**
******************************************************************************
*
* @file detailswidget.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "detailswidget.h"
#include "detailsbutton.h"
#include <QtGui/QGridLayout>
#include <QtCore/QStack>
#include <QtGui/QLabel>
#include <QtGui/QGridLayout>
#include <QtGui/QPainter>
using namespace Utils;
DetailsWidget::DetailsWidget(QWidget *parent)
: QWidget(parent),
m_summaryLabel(new QLabel(this)),
m_detailsButton(new DetailsButton(this)),
m_widget(0),
m_toolWidget(0),
m_grid(new QGridLayout(this))
{
m_grid->setContentsMargins(4, 3, 4, 3);
m_summaryLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
m_summaryLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
m_grid->addWidget(m_summaryLabel, 0, 0);
m_grid->addWidget(m_detailsButton, 0, 2, 1, 1, Qt::AlignBottom);
m_dummyWidget = new QWidget(this);
m_dummyWidget->setMaximumHeight(4);
m_dummyWidget->setMaximumHeight(4);
m_dummyWidget->setVisible(false);
m_grid->addWidget(m_dummyWidget, 2, 0, 1, 1);
connect(m_detailsButton, SIGNAL(clicked()),
this, SLOT(detailsButtonClicked()));
}
DetailsWidget::~DetailsWidget()
{
}
void DetailsWidget::paintEvent(QPaintEvent *paintEvent)
{
//TL--> ___________ <-- TR
// | |
//ML-> ______________| <--MM | <--MR
// | |
//BL-> |_________________________| <-- BR
QWidget::paintEvent(paintEvent);
if (!m_detailsButton->isToggled())
return;
const QRect detailsGeometry = m_detailsButton->geometry();
const QRect widgetGeometry = m_widget ? m_widget->geometry() : QRect(x(), y() + height(), width(), 0);
QPoint tl(detailsGeometry.topLeft());
tl += QPoint(-3, -3);
QPoint tr(detailsGeometry.topRight());
tr += QPoint(3, -3);
QPoint mm(detailsGeometry.left() - 3, widgetGeometry.top() - 3);
QPoint ml(1, mm.y());
QPoint mr(tr.x(), mm.y());
int bottom = geometry().height() - 3;
QPoint bl(1, bottom);
QPoint br(tr.x(), bottom);
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing);
p.setPen(Qt::NoPen);
p.setBrush(palette().dark());
p.drawRoundedRect(QRect(tl, br), 5, 5);
p.drawRoundedRect(QRect(ml, br), 5, 5);
}
void DetailsWidget::detailsButtonClicked()
{
bool visible = m_detailsButton->isToggled();
if (m_widget)
m_widget->setVisible(visible);
m_dummyWidget->setVisible(visible);
fixUpLayout();
}
void DetailsWidget::setSummaryText(const QString &text)
{
m_summaryLabel->setText(text);
}
QString DetailsWidget::summaryText() const
{
return m_summaryLabel->text();
}
bool DetailsWidget::expanded() const
{
return m_detailsButton->isToggled();
}
void DetailsWidget::setExpanded(bool v)
{
if (expanded() != v)
m_detailsButton->animateClick();
}
QWidget *DetailsWidget::widget() const
{
return m_widget;
}
void DetailsWidget::setWidget(QWidget *widget)
{
if (m_widget == widget)
return;
if (m_widget) {
m_grid->removeWidget(m_widget);
m_widget = 0;
}
if (widget) {
m_grid->addWidget(widget, 1, 0, 1, 3);
m_widget = widget;
bool visible = m_detailsButton->isToggled();
m_widget->setVisible(visible);
m_dummyWidget->setVisible(visible);
}
}
void DetailsWidget::setToolWidget(QWidget *widget)
{
if (m_toolWidget == widget)
return;
if (m_toolWidget) {
m_grid->removeWidget(m_toolWidget);
m_toolWidget = 0;
}
if (widget) {
m_grid->addWidget(widget, 0, 1, 1, 1, Qt::AlignBottom);
m_toolWidget = widget;
}
}
QWidget *DetailsWidget::toolWidget() const
{
return m_toolWidget;
}
void DetailsWidget::fixUpLayout()
{
if (!m_widget)
return;
QWidget *parent = m_widget;
QStack<QWidget *> widgets;
while((parent = parent->parentWidget()) && parent && parent->layout()) {
widgets.push(parent);
parent->layout()->update();
}
while(!widgets.isEmpty()) {
widgets.pop()->layout()->activate();
}
}
/**
******************************************************************************
*
* @file detailswidget.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef DETAILSWIDGET_H
#define DETAILSWIDGET_H
#include "utils_global.h"
#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
class QLabel;
class QGridLayout;
QT_END_NAMESPACE
namespace Utils {
class DetailsButton;
class QTCREATOR_UTILS_EXPORT DetailsWidget : public QWidget
{
Q_OBJECT
Q_PROPERTY(QString summaryText READ summaryText WRITE setSummaryText DESIGNABLE true)
Q_PROPERTY(bool expanded READ expanded WRITE setExpanded DESIGNABLE true)
public:
DetailsWidget(QWidget *parent = 0);
~DetailsWidget();
void setSummaryText(const QString &text);
QString summaryText() const;
bool expanded() const;
void setExpanded(bool);
void setWidget(QWidget *widget);
QWidget *widget() const;
void setToolWidget(QWidget *widget);
QWidget *toolWidget() const;
protected:
void paintEvent(QPaintEvent *paintEvent);
private slots:
void detailsButtonClicked();
private:
void fixUpLayout();
QLabel *m_summaryLabel;
DetailsButton *m_detailsButton;
QWidget *m_widget;
QWidget *m_toolWidget;
QWidget *m_dummyWidget;
QGridLayout *m_grid;
};
}
#endif // DETAILSWIDGET_H
/**
******************************************************************************
*
* @file fancylineedit.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "fancylineedit.h"
#include <QtCore/QEvent>
#include <QtCore/QDebug>
#include <QtCore/QString>
#include <QtGui/QApplication>
#include <QtGui/QMenu>
#include <QtGui/QMouseEvent>
#include <QtGui/QLabel>
enum { margin = 6 };
namespace Utils {
static inline QString sideToStyleSheetString(FancyLineEdit::Side side)
{
return side == FancyLineEdit::Left ? QLatin1String("left") : QLatin1String("right");
}
// Format style sheet for the label containing the pixmap. It has a margin on
// the outer side of the whole FancyLineEdit.
static QString labelStyleSheet(FancyLineEdit::Side side)
{
QString rc = QLatin1String("QLabel { margin-");
rc += sideToStyleSheetString(side);
rc += QLatin1String(": ");
rc += QString::number(margin);
rc += QLatin1Char('}');
return rc;
}
// --------- FancyLineEditPrivate as QObject with label
// event filter
class FancyLineEditPrivate : public QObject {
public:
explicit FancyLineEditPrivate(QLineEdit *parent);
virtual bool eventFilter(QObject *obj, QEvent *event);
const QString m_leftLabelStyleSheet;
const QString m_rightLabelStyleSheet;
QLineEdit *m_lineEdit;
QPixmap m_pixmap;
QMenu *m_menu;
QLabel *m_menuLabel;
FancyLineEdit::Side m_side;
bool m_useLayoutDirection;
bool m_menuTabFocusTrigger;
QString m_hintText;
bool m_showingHintText;
};
FancyLineEditPrivate::FancyLineEditPrivate(QLineEdit *parent) :
QObject(parent),
m_leftLabelStyleSheet(labelStyleSheet(FancyLineEdit::Left)),
m_rightLabelStyleSheet(labelStyleSheet(FancyLineEdit::Right)),
m_lineEdit(parent),
m_menu(0),
m_menuLabel(0),
m_side(FancyLineEdit::Left),
m_useLayoutDirection(false),
m_menuTabFocusTrigger(false),
m_showingHintText(false)
{
}
bool FancyLineEditPrivate::eventFilter(QObject *obj, QEvent *event)
{
if (!m_menu || obj != m_menuLabel)
return QObject::eventFilter(obj, event);
switch (event->type()) {
case QEvent::MouseButtonPress: {
const QMouseEvent *me = static_cast<QMouseEvent *>(event);
m_menu->exec(me->globalPos());
return true;
}
case QEvent::FocusIn:
if (m_menuTabFocusTrigger) {
m_lineEdit->setFocus();
m_menu->exec(m_menuLabel->mapToGlobal(m_menuLabel->rect().center()));
return true;
}
default:
break;
}
return QObject::eventFilter(obj, event);
}
// --------- FancyLineEdit
FancyLineEdit::FancyLineEdit(QWidget *parent) :
QLineEdit(parent),
m_d(new FancyLineEditPrivate(this))
{
m_d->m_menuLabel = new QLabel(this);
m_d->m_menuLabel->installEventFilter(m_d);
updateMenuLabel();
showHintText();
}
FancyLineEdit::~FancyLineEdit()
{
}
// Position the menu label left or right according to size.
// Called when switching side and from resizeEvent.
void FancyLineEdit::positionMenuLabel()
{
switch (side()) {
case Left:
m_d->m_menuLabel->setGeometry(0, 0, m_d->m_pixmap.width()+margin, height());
break;
case Right:
m_d->m_menuLabel->setGeometry(width() - m_d->m_pixmap.width() - margin, 0,
m_d->m_pixmap.width()+margin, height());
break;
}
}
void FancyLineEdit::updateStyleSheet(Side side)
{
// Udate the LineEdit style sheet. Make room for the label on the
// respective side and set color according to whether we are showing the
// hint text
QString sheet = QLatin1String("QLineEdit{ padding-");
sheet += sideToStyleSheetString(side);
sheet += QLatin1String(": ");
sheet += QString::number(m_d->m_pixmap.width() + margin);
sheet += QLatin1Char(';');
if (m_d->m_showingHintText)
sheet += QLatin1String(" color: #BBBBBB;");
sheet += QLatin1Char('}');
setStyleSheet(sheet);
}
void FancyLineEdit::updateMenuLabel()
{
m_d->m_menuLabel->setPixmap(m_d->m_pixmap);
const Side s = side();
switch (s) {
case Left:
m_d->m_menuLabel->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
m_d->m_menuLabel->setStyleSheet(m_d->m_leftLabelStyleSheet);
break;
case Right:
m_d->m_menuLabel->setAlignment(Qt::AlignVCenter | Qt::AlignRight);
m_d->m_menuLabel->setStyleSheet(m_d->m_rightLabelStyleSheet);
break;
}
updateStyleSheet(s);
positionMenuLabel();
}
void FancyLineEdit::setSide(Side side)
{
m_d->m_side = side;
updateMenuLabel();
}
FancyLineEdit::Side FancyLineEdit::side() const
{
if (m_d->m_useLayoutDirection)
return qApp->layoutDirection() == Qt::LeftToRight ? Left : Right;
return m_d->m_side;
}
void FancyLineEdit::resizeEvent(QResizeEvent *)
{
positionMenuLabel();
}
void FancyLineEdit::setPixmap(const QPixmap &pixmap)
{
m_d->m_pixmap = pixmap;
updateMenuLabel();
}
QPixmap FancyLineEdit::pixmap() const
{
return m_d->m_pixmap;
}
void FancyLineEdit::setMenu(QMenu *menu)
{
m_d->m_menu = menu;
}
QMenu *FancyLineEdit::menu() const
{
return m_d->m_menu;
}
bool FancyLineEdit::useLayoutDirection() const
{
return m_d->m_useLayoutDirection;
}
void FancyLineEdit::setUseLayoutDirection(bool v)
{
m_d->m_useLayoutDirection = v;
}
bool FancyLineEdit::isSideStored() const
{
return !m_d->m_useLayoutDirection;
}
bool FancyLineEdit::hasMenuTabFocusTrigger() const
{
return m_d->m_menuTabFocusTrigger;
}
void FancyLineEdit::setMenuTabFocusTrigger(bool v)
{
if (m_d->m_menuTabFocusTrigger == v)
return;
m_d->m_menuTabFocusTrigger = v;
m_d->m_menuLabel->setFocusPolicy(v ? Qt::TabFocus : Qt::NoFocus);
}
QString FancyLineEdit::hintText() const
{
return m_d->m_hintText;
}
void FancyLineEdit::setHintText(const QString &ht)
{
// Updating magic to make the property work in Designer.
if (ht == m_d->m_hintText)
return;
hideHintText();
m_d->m_hintText = ht;
if (!hasFocus() && !ht.isEmpty())
showHintText();
}
void FancyLineEdit::showHintText()
{
if (!m_d->m_showingHintText && text().isEmpty() && !m_d->m_hintText.isEmpty()) {
m_d->m_showingHintText = true;
setText(m_d->m_hintText);
updateStyleSheet(side());
}
}
void FancyLineEdit::hideHintText()
{
if (m_d->m_showingHintText && !m_d->m_hintText.isEmpty()) {
m_d->m_showingHintText = false;
setText(QString());
updateStyleSheet(side());
}
}
void FancyLineEdit::focusInEvent(QFocusEvent *e)
{
hideHintText();
QLineEdit::focusInEvent(e);
}
void FancyLineEdit::focusOutEvent(QFocusEvent *e)
{
// Focus out: Switch to displaying the hint text unless
// there is user input
showHintText();
QLineEdit::focusOutEvent(e);
}
bool FancyLineEdit::isShowingHintText() const
{
return m_d->m_showingHintText;
}
QString FancyLineEdit::typedText() const
{
return m_d->m_showingHintText ? QString() : text();
}
} // namespace Utils
/**
******************************************************************************
*
* @file fancylineedit.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef FANCYLINEEDIT_H
#define FANCYLINEEDIT_H
#include "utils_global.h"
#include <QtGui/QLineEdit>
namespace Utils {
class FancyLineEditPrivate;
/* A line edit with an embedded pixmap on one side that is connected to
* a menu. Additionally, it can display a grayed hintText (like "Type Here to")
* when not focussed and empty. When connecting to the changed signals and
* querying text, one has to be aware that the text is set to that hint
* text if isShowingHintText() returns true (that is, does not contain
* valid user input).
*/
class QTCREATOR_UTILS_EXPORT FancyLineEdit : public QLineEdit
{
Q_DISABLE_COPY(FancyLineEdit)
Q_OBJECT
Q_ENUMS(Side)
Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap DESIGNABLE true)
Q_PROPERTY(Side side READ side WRITE setSide DESIGNABLE isSideStored STORED isSideStored)
Q_PROPERTY(bool useLayoutDirection READ useLayoutDirection WRITE setUseLayoutDirection DESIGNABLE true)
Q_PROPERTY(bool menuTabFocusTrigger READ hasMenuTabFocusTrigger WRITE setMenuTabFocusTrigger DESIGNABLE true)
Q_PROPERTY(QString hintText READ hintText WRITE setHintText DESIGNABLE true)
public:
enum Side {Left, Right};
explicit FancyLineEdit(QWidget *parent = 0);
~FancyLineEdit();
QPixmap pixmap() const;
void setMenu(QMenu *menu);
QMenu *menu() const;
void setSide(Side side);
Side side() const;
bool useLayoutDirection() const;
void setUseLayoutDirection(bool v);
// Set whether tabbing in will trigger the menu.
bool hasMenuTabFocusTrigger() const;
void setMenuTabFocusTrigger(bool v);
// Hint text that is displayed when no focus is set.
QString hintText() const;
bool isShowingHintText() const;
// Convenience for accessing the text that returns "" in case of isShowingHintText().
QString typedText() const;
public slots:
void setPixmap(const QPixmap &pixmap);
void setHintText(const QString &ht);
void showHintText();
void hideHintText();
protected:
virtual void resizeEvent(QResizeEvent *e);
virtual void focusInEvent(QFocusEvent *e);
virtual void focusOutEvent(QFocusEvent *e);
private:
bool isSideStored() const;
void updateMenuLabel();
void positionMenuLabel();
void updateStyleSheet(Side side);
FancyLineEditPrivate *m_d;
};
} // namespace Utils
#endif // FANCYLINEEDIT_H
/**
******************************************************************************
*
* @file fancymainwindow.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "fancymainwindow.h"
#include <QtGui/QAction>
#include <QtCore/QSettings>
#include <QtGui/QDockWidget>
#include <QtCore/QSettings>
using namespace Utils;
FancyMainWindow::FancyMainWindow(QWidget *parent)
: QMainWindow(parent),
m_locked(true),
m_handleDockVisibilityChanges(true)
{
}
QDockWidget *FancyMainWindow::addDockForWidget(QWidget *widget)
{
QDockWidget *dockWidget = new QDockWidget(widget->windowTitle(), this);
dockWidget->setObjectName(widget->windowTitle());
dockWidget->setWidget(widget);
connect(dockWidget->toggleViewAction(), SIGNAL(triggered()),
this, SLOT(onDockActionTriggered()), Qt::QueuedConnection);
connect(dockWidget, SIGNAL(visibilityChanged(bool)),
this, SLOT(onDockVisibilityChange(bool)));
connect(dockWidget, SIGNAL(topLevelChanged(bool)),
this, SLOT(onTopLevelChanged()));
m_dockWidgets.append(dockWidget);
m_dockWidgetActiveState.append(true);
updateDockWidget(dockWidget);
return dockWidget;
}
void FancyMainWindow::updateDockWidget(QDockWidget *dockWidget)
{
const QDockWidget::DockWidgetFeatures features =
(m_locked) ? QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable
: QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable;
QWidget *titleBarWidget = dockWidget->titleBarWidget();
if (m_locked && !titleBarWidget && !dockWidget->isFloating())
titleBarWidget = new QWidget(dockWidget);
else if ((!m_locked || dockWidget->isFloating()) && titleBarWidget) {
delete titleBarWidget;
titleBarWidget = 0;
}
dockWidget->setTitleBarWidget(titleBarWidget);
dockWidget->setFeatures(features);
}
void FancyMainWindow::onDockActionTriggered()
{
QDockWidget *dw = qobject_cast<QDockWidget *>(sender()->parent());
if (dw) {
if (dw->isVisible())
dw->raise();
}
}
void FancyMainWindow::onDockVisibilityChange(bool visible)
{
if (!m_handleDockVisibilityChanges)
return;
QDockWidget *dockWidget = qobject_cast<QDockWidget *>(sender());
int index = m_dockWidgets.indexOf(dockWidget);
m_dockWidgetActiveState[index] = visible;
}
void FancyMainWindow::onTopLevelChanged()
{
updateDockWidget(qobject_cast<QDockWidget*>(sender()));
}
void FancyMainWindow::setTrackingEnabled(bool enabled)
{
if (enabled) {
m_handleDockVisibilityChanges = true;
for (int i = 0; i < m_dockWidgets.size(); ++i)
m_dockWidgetActiveState[i] = m_dockWidgets[i]->isVisible();
} else {
m_handleDockVisibilityChanges = false;
}
}
void FancyMainWindow::setLocked(bool locked)
{
m_locked = locked;
foreach (QDockWidget *dockWidget, m_dockWidgets) {
updateDockWidget(dockWidget);
}
}
void FancyMainWindow::hideEvent(QHideEvent *event)
{
Q_UNUSED(event)
handleVisibilityChanged(false);
}
void FancyMainWindow::showEvent(QShowEvent *event)
{
Q_UNUSED(event)
handleVisibilityChanged(true);
}
void FancyMainWindow::handleVisibilityChanged(bool visible)
{
m_handleDockVisibilityChanges = false;
for (int i = 0; i < m_dockWidgets.size(); ++i) {
QDockWidget *dockWidget = m_dockWidgets.at(i);
if (dockWidget->isFloating()) {
dockWidget->setVisible(visible && m_dockWidgetActiveState.at(i));
}
}
if (visible)
m_handleDockVisibilityChanges = true;
}
void FancyMainWindow::saveSettings(QSettings *settings) const
{
QHash<QString, QVariant> hash = saveSettings();
QHashIterator<QString, QVariant> it(hash);
while (it.hasNext()) {
it.next();
settings->setValue(it.key(), it.value());
}
}
void FancyMainWindow::restoreSettings(QSettings *settings)
{
QHash<QString, QVariant> hash;
foreach (const QString &key, settings->childKeys()) {
hash.insert(key, settings->value(key));
}
restoreSettings(hash);
}
QHash<QString, QVariant> FancyMainWindow::saveSettings() const
{
QHash<QString, QVariant> settings;
settings["State"] = saveState();
settings["Locked"] = m_locked;
for (int i = 0; i < m_dockWidgetActiveState.count(); ++i) {
settings[m_dockWidgets.at(i)->objectName()] =
m_dockWidgetActiveState.at(i);
}
return settings;
}
void FancyMainWindow::restoreSettings(const QHash<QString, QVariant> &settings)
{
QByteArray ba = settings.value("State", QByteArray()).toByteArray();
if (!ba.isEmpty())
restoreState(ba);
m_locked = settings.value("Locked", true).toBool();
for (int i = 0; i < m_dockWidgetActiveState.count(); ++i) {
m_dockWidgetActiveState[i] = settings.value(m_dockWidgets.at(i)->objectName(), false).toBool();
}
}
/**
******************************************************************************
*
* @file fancymainwindow.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef FANCYMAINWINDOW_H
#define FANCYMAINWINDOW_H
#include "utils_global.h"
#include <QtCore/QList>
#include <QtCore/QHash>
#include <QtGui/QMainWindow>
QT_BEGIN_NAMESPACE
class QSettings;
QT_END_NAMESPACE
namespace Utils {
class QTCREATOR_UTILS_EXPORT FancyMainWindow : public QMainWindow
{
Q_OBJECT
public:
FancyMainWindow(QWidget *parent = 0);
QDockWidget *addDockForWidget(QWidget *widget);
QList<QDockWidget *> dockWidgets() const { return m_dockWidgets; }
void setTrackingEnabled(bool enabled);
bool isLocked() const { return m_locked; }
void saveSettings(QSettings *settings) const;
void restoreSettings(QSettings *settings);
QHash<QString, QVariant> saveSettings() const;
void restoreSettings(const QHash<QString, QVariant> &settings);
public slots:
void setLocked(bool locked);
protected:
void hideEvent(QHideEvent *event);
void showEvent(QShowEvent *event);
private slots:
void onDockActionTriggered();
void onDockVisibilityChange(bool);
void onTopLevelChanged();
private:
void updateDockWidget(QDockWidget *dockWidget);
void handleVisibilityChanged(bool visible);
QList<QDockWidget *> m_dockWidgets;
QList<bool> m_dockWidgetActiveState;
bool m_locked;
bool m_handleDockVisibilityChanges; //todo
};
} // namespace Utils
#endif // FANCYMAINWINDOW_H
/**
******************************************************************************
*
* @file filenamevalidatinglineedit.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "filenamevalidatinglineedit.h"
#include "qtcassert.h"
#include <QtCore/QRegExp>
#include <QtCore/QDebug>
namespace Utils {
#define WINDOWS_DEVICES "CON|AUX|PRN|COM1|COM2|LPT1|LPT2|NUL"
// Naming a file like a device name will break on Windows, even if it is
// "com1.txt". Since we are cross-platform, we generally disallow such file
// names.
static const QRegExp &windowsDeviceNoSubDirPattern()
{
static const QRegExp rc(QLatin1String(WINDOWS_DEVICES),
Qt::CaseInsensitive);
QTC_ASSERT(rc.isValid(), return rc);
return rc;
}
static const QRegExp &windowsDeviceSubDirPattern()
{
static const QRegExp rc(QLatin1String(".*[/\\\\](" WINDOWS_DEVICES ")"), Qt::CaseInsensitive);
QTC_ASSERT(rc.isValid(), return rc);
return rc;
}
// ----------- FileNameValidatingLineEdit
FileNameValidatingLineEdit::FileNameValidatingLineEdit(QWidget *parent) :
BaseValidatingLineEdit(parent),
m_allowDirectories(false),
m_unused(0)
{
}
bool FileNameValidatingLineEdit::allowDirectories() const
{
return m_allowDirectories;
}
void FileNameValidatingLineEdit::setAllowDirectories(bool v)
{
m_allowDirectories = v;
}
/* Validate a file base name, check for forbidden characters/strings. */
#ifdef Q_OS_WIN
# define SLASHES "/\\"
#else
# define SLASHES "/"
#endif
static const char *notAllowedCharsSubDir = "?:&*\"|#%<> ";
static const char *notAllowedCharsNoSubDir = "?:&*\"|#%<> "SLASHES;
static const char *notAllowedSubStrings[] = {".."};
bool FileNameValidatingLineEdit::validateFileName(const QString &name,
bool allowDirectories,
QString *errorMessage /* = 0*/)
{
if (name.isEmpty()) {
if (errorMessage)
*errorMessage = tr("The name must not be empty");
return false;
}
// Characters
const char *notAllowedChars = allowDirectories ? notAllowedCharsSubDir : notAllowedCharsNoSubDir;
for (const char *c = notAllowedChars; *c; c++)
if (name.contains(QLatin1Char(*c))) {
if (errorMessage)
*errorMessage = tr("The name must not contain any of the characters '%1'.").arg(QLatin1String(notAllowedChars));
return false;
}
// Substrings
const int notAllowedSubStringCount = sizeof(notAllowedSubStrings)/sizeof(const char *);
for (int s = 0; s < notAllowedSubStringCount; s++) {
const QLatin1String notAllowedSubString(notAllowedSubStrings[s]);
if (name.contains(notAllowedSubString)) {
if (errorMessage)
*errorMessage = tr("The name must not contain '%1'.").arg(QString(notAllowedSubString));
return false;
}
}
// Windows devices
bool matchesWinDevice = windowsDeviceNoSubDirPattern().exactMatch(name);
if (!matchesWinDevice && allowDirectories)
matchesWinDevice = windowsDeviceSubDirPattern().exactMatch(name);
if (matchesWinDevice) {
if (errorMessage)
*errorMessage = tr("The name must not match that of a MS Windows device. (%1).").
arg(windowsDeviceNoSubDirPattern().pattern().replace(QLatin1Char('|'), QLatin1Char(',')));
return false;
}
return true;
}
bool FileNameValidatingLineEdit::validate(const QString &value, QString *errorMessage) const
{
return validateFileName(value, m_allowDirectories, errorMessage);
}
} // namespace Utils
/**
******************************************************************************
*
* @file filenamevalidatinglineedit.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef FILENAMEVALIDATINGLINEEDIT_H
#define FILENAMEVALIDATINGLINEEDIT_H
#include "basevalidatinglineedit.h"
namespace Utils {
/**
* A control that let's the user choose a file name, based on a QLineEdit. Has
* some validation logic for embedding into QWizardPage.
*/
class QTCREATOR_UTILS_EXPORT FileNameValidatingLineEdit : public BaseValidatingLineEdit
{
Q_OBJECT
Q_DISABLE_COPY(FileNameValidatingLineEdit)
Q_PROPERTY(bool allowDirectories READ allowDirectories WRITE setAllowDirectories)
public:
explicit FileNameValidatingLineEdit(QWidget *parent = 0);
static bool validateFileName(const QString &name,
bool allowDirectories = false,
QString *errorMessage = 0);
/**
* Sets whether entering directories is allowed. This will enable the user
* to enter slashes in the filename. Default is off.
*/
bool allowDirectories() const;
void setAllowDirectories(bool v);
protected:
virtual bool validate(const QString &value, QString *errorMessage) const;
private:
bool m_allowDirectories;
void *m_unused;
};
} // namespace Utils
#endif // FILENAMEVALIDATINGLINEEDIT_H
This diff is collapsed.
/**
******************************************************************************
*
* @file filesearch.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef FILESEARCH_H
#define FILESEARCH_H
#include "utils_global.h"
#include <QtCore/QStringList>
#include <QtCore/QFuture>
#include <QtCore/QMap>
#include <QtGui/QTextDocument>
namespace Utils {
class QTCREATOR_UTILS_EXPORT FileSearchResult
{
public:
FileSearchResult() {}
FileSearchResult(QString fileName, int lineNumber, QString matchingLine, int matchStart, int matchLength)
: fileName(fileName), lineNumber(lineNumber), matchingLine(matchingLine), matchStart(matchStart), matchLength(matchLength)
{
}
QString fileName;
int lineNumber;
QString matchingLine;
int matchStart;
int matchLength;
};
QTCREATOR_UTILS_EXPORT QFuture<FileSearchResult> findInFiles(const QString &searchTerm, const QStringList &files,
QTextDocument::FindFlags flags, QMap<QString, QString> fileToContentsMap = QMap<QString, QString>());
QTCREATOR_UTILS_EXPORT QFuture<FileSearchResult> findInFilesRegExp(const QString &searchTerm, const QStringList &files,
QTextDocument::FindFlags flags, QMap<QString, QString> fileToContentsMap = QMap<QString, QString>());
} // namespace Utils
#endif // FILESEARCH_H
/**
******************************************************************************
*
* @file filewizarddialog.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "filewizarddialog.h"
#include "filewizardpage.h"
#include <QtGui/QAbstractButton>
namespace Utils {
FileWizardDialog::FileWizardDialog(QWidget *parent) :
QWizard(parent),
m_filePage(new FileWizardPage)
{
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
setOption(QWizard::NoCancelButton, false);
setOption(QWizard::NoDefaultButton, false);
setPixmap(QWizard::WatermarkPixmap, QPixmap(QLatin1String(":/core/images/qtwatermark.png")));
addPage(m_filePage);
connect(m_filePage, SIGNAL(activated()), button(QWizard::FinishButton), SLOT(animateClick()));
}
QString FileWizardDialog::name() const
{
return m_filePage->name();
}
QString FileWizardDialog::path() const
{
return m_filePage->path();
}
void FileWizardDialog::setPath(const QString &path)
{
m_filePage->setPath(path);
}
void FileWizardDialog::setName(const QString &name)
{
m_filePage->setName(name);
}
} // namespace Utils
/**
******************************************************************************
*
* @file filewizarddialog.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef FILEWIZARDDIALOG_H
#define FILEWIZARDDIALOG_H
#include "utils_global.h"
#include <QtGui/QWizard>
namespace Utils {
class FileWizardPage;
/*
Standard wizard for a single file letting the user choose name
and path. Custom pages can be added via Core::IWizardExtension.
*/
class QTCREATOR_UTILS_EXPORT FileWizardDialog : public QWizard {
Q_OBJECT
Q_DISABLE_COPY(FileWizardDialog)
public:
explicit FileWizardDialog(QWidget *parent = 0);
QString name() const;
QString path() const;
public slots:
void setPath(const QString &path);
void setName(const QString &name);
private:
FileWizardPage *m_filePage;
};
} // namespace Utils
#endif // FILEWIZARDDIALOG_H
/**
******************************************************************************
*
* @file filewizardpage.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "filewizardpage.h"
#include "ui_filewizardpage.h"
namespace Utils {
struct FileWizardPagePrivate
{
FileWizardPagePrivate();
Ui::WizardPage m_ui;
bool m_complete;
};
FileWizardPagePrivate::FileWizardPagePrivate() :
m_complete(false)
{
}
FileWizardPage::FileWizardPage(QWidget *parent) :
QWizardPage(parent),
m_d(new FileWizardPagePrivate)
{
m_d->m_ui.setupUi(this);
connect(m_d->m_ui.pathChooser, SIGNAL(validChanged()), this, SLOT(slotValidChanged()));
connect(m_d->m_ui.nameLineEdit, SIGNAL(validChanged()), this, SLOT(slotValidChanged()));
connect(m_d->m_ui.pathChooser, SIGNAL(returnPressed()), this, SLOT(slotActivated()));
connect(m_d->m_ui.nameLineEdit, SIGNAL(validReturnPressed()), this, SLOT(slotActivated()));
}
FileWizardPage::~FileWizardPage()
{
delete m_d;
}
QString FileWizardPage::name() const
{
return m_d->m_ui.nameLineEdit->text();
}
QString FileWizardPage::path() const
{
return m_d->m_ui.pathChooser->path();
}
void FileWizardPage::setPath(const QString &path)
{
m_d->m_ui.pathChooser->setPath(path);
}
void FileWizardPage::setName(const QString &name)
{
m_d->m_ui.nameLineEdit->setText(name);
}
void FileWizardPage::changeEvent(QEvent *e)
{
QWizardPage::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
m_d->m_ui.retranslateUi(this);
break;
default:
break;
}
}
bool FileWizardPage::isComplete() const
{
return m_d->m_complete;
}
void FileWizardPage::setNameLabel(const QString &label)
{
m_d->m_ui.nameLabel->setText(label);
}
void FileWizardPage::setPathLabel(const QString &label)
{
m_d->m_ui.pathLabel->setText(label);
}
void FileWizardPage::slotValidChanged()
{
const bool newComplete = m_d->m_ui.pathChooser->isValid() && m_d->m_ui.nameLineEdit->isValid();
if (newComplete != m_d->m_complete) {
m_d->m_complete = newComplete;
emit completeChanged();
}
}
void FileWizardPage::slotActivated()
{
if (m_d->m_complete)
emit activated();
}
bool FileWizardPage::validateBaseName(const QString &name, QString *errorMessage /* = 0*/)
{
return FileNameValidatingLineEdit::validateFileName(name, false, errorMessage);
}
} // namespace Utils
/**
******************************************************************************
*
* @file filewizardpage.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef FILEWIZARDPAGE_H
#define FILEWIZARDPAGE_H
#include "utils_global.h"
#include <QtGui/QWizardPage>
namespace Utils {
struct FileWizardPagePrivate;
/**
* Standard wizard page for a single file letting the user choose name
* and path. Sets the "FileNames" QWizard field.
*
* The name and path labels can be changed. By default they are simply "Name:"
* and "Path:".
*/
class QTCREATOR_UTILS_EXPORT FileWizardPage : public QWizardPage
{
Q_OBJECT
Q_DISABLE_COPY(FileWizardPage)
Q_PROPERTY(QString path READ path WRITE setPath DESIGNABLE true)
Q_PROPERTY(QString name READ name WRITE setName DESIGNABLE true)
public:
explicit FileWizardPage(QWidget *parent = 0);
virtual ~FileWizardPage();
QString name() const;
QString path() const;
virtual bool isComplete() const;
void setNameLabel(const QString &label);
void setPathLabel(const QString &label);
// Validate a base name entry field (potentially containing extension)
static bool validateBaseName(const QString &name, QString *errorMessage = 0);
signals:
void activated();
void pathChanged();
public slots:
void setPath(const QString &path);
void setName(const QString &name);
private slots:
void slotValidChanged();
void slotActivated();
protected:
virtual void changeEvent(QEvent *e);
private:
FileWizardPagePrivate *m_d;
};
} // namespace Utils
#endif // FILEWIZARDPAGE_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Utils::WizardPage</class>
<widget class="QWizardPage" name="Utils::WizardPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>196</width>
<height>68</height>
</rect>
</property>
<property name="title">
<string>Choose the location</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="nameLabel">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Utils::FileNameValidatingLineEdit" name="nameLineEdit"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="pathLabel">
<property name="text">
<string>Path:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="Utils::PathChooser" name="pathChooser" native="true"/>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Utils::PathChooser</class>
<extends>QWidget</extends>
<header>pathchooser.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>Utils::FileNameValidatingLineEdit</class>
<extends>QLineEdit</extends>
<header>filenamevalidatinglineedit.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
/**
******************************************************************************
*
* @file homelocationutil.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Utilities to find the location of openpilot GCS files:
* - Plugins Share directory path
*
* @brief Home location utility functions
*
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "homelocationutil.h"
#include <stdint.h>
#include <QDebug>
#include <QDateTime>
#include "coordinateconversions.h"
#include "worldmagmodel.h"
namespace Utils {
HomeLocationUtil::HomeLocationUtil()
{
// Initialize();
}
// input params: LLA
//
// output params: ECEF, RNE and Be
int HomeLocationUtil::getDetails(double LLA[3], double ECEF[3], double RNE[9], double Be[3])
{
// *************
// check input parms
double latitude = LLA[0];
double longitude = LLA[1];
double altitude = LLA[2];
if (latitude != latitude) return -1; // prevent nan error
if (longitude != longitude) return -2; // prevent nan error
if (altitude != altitude) return -3; // prevent nan error
if (latitude < -90 || latitude > 90) return -4; // range checking
if (longitude < -180 || longitude > 180) return -5; // range checking
// *************
QDateTime dt = QDateTime::currentDateTime().toUTC();
CoordinateConversions().LLA2ECEF(LLA, ECEF);
CoordinateConversions().RneFromLLA(LLA, (double (*)[3])RNE);
if (WorldMagModel().GetMagVector(LLA, dt.date().month(), dt.date().day(), dt.date().year(), Be) < 0)
return -6;
return 0; // OK
}
}
/**
******************************************************************************
*
* @file homelocationutil.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef HOMELOCATIONUTIL_H
#define HOMELOCATIONUTIL_H
#include "utils_global.h"
// ******************************
namespace Utils {
class QTCREATOR_UTILS_EXPORT HomeLocationUtil
{
public:
HomeLocationUtil();
int getDetails(double LLA[3], double ECEF[3], double RNE[9], double Be[3]);
private:
};
}
// ******************************
#endif
/**
******************************************************************************
*
* @file iwelcomepage.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "iwelcomepage.h"
using namespace Utils;
IWelcomePage::IWelcomePage()
{
}
IWelcomePage::~IWelcomePage()
{
}
/**
******************************************************************************
*
* @file iwelcomepage.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef IWELCOMEPAGE_H
#define IWELCOMEPAGE_H
#include "utils_global.h"
#include <QObject>
namespace Utils {
class IWelcomePagePrivate;
class QTCREATOR_UTILS_EXPORT IWelcomePage : public QObject
{
Q_OBJECT
public:
IWelcomePage();
virtual ~IWelcomePage();
virtual QWidget *page() = 0;
virtual QString title() const = 0;
virtual int priority() const { return 0; }
private:
// not used atm
IWelcomePagePrivate *m_d;
};
}
#endif // IWELCOMEPAGE_H
/**
******************************************************************************
*
* @file linecolumnlabel.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "linecolumnlabel.h"
namespace Utils {
LineColumnLabel::LineColumnLabel(QWidget *parent)
: QLabel(parent), m_unused(0)
{
}
LineColumnLabel::~LineColumnLabel()
{
}
void LineColumnLabel::setText(const QString &text, const QString &maxText)
{
QLabel::setText(text);
m_maxText = maxText;
}
QSize LineColumnLabel::sizeHint() const
{
return fontMetrics().boundingRect(m_maxText).size();
}
QString LineColumnLabel::maxText() const
{
return m_maxText;
}
void LineColumnLabel::setMaxText(const QString &maxText)
{
m_maxText = maxText;
}
} // namespace Utils
/**
******************************************************************************
*
* @file linecolumnlabel.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef LINECOLUMNLABEL_H
#define LINECOLUMNLABEL_H
#include "utils_global.h"
#include <QtGui/QLabel>
namespace Utils {
/* A label suitable for displaying cursor positions, etc. with a fixed
* with derived from a sample text. */
class QTCREATOR_UTILS_EXPORT LineColumnLabel : public QLabel
{
Q_DISABLE_COPY(LineColumnLabel)
Q_OBJECT
Q_PROPERTY(QString maxText READ maxText WRITE setMaxText DESIGNABLE true)
public:
explicit LineColumnLabel(QWidget *parent = 0);
virtual ~LineColumnLabel();
void setText(const QString &text, const QString &maxText);
QSize sizeHint() const;
QString maxText() const;
void setMaxText(const QString &maxText);
private:
QString m_maxText;
void *m_unused;
};
} // namespace Utils
#endif // LINECOLUMNLABEL_H
/**
******************************************************************************
*
* @file listutils.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef LISTUTILS_H
#define LISTUTILS_H
#include <QtCore/QList>
namespace Utils {
template <class T1, class T2>
QList<T1> qwConvertList(const QList<T2> &list)
{
QList<T1> convertedList;
foreach (T2 listEntry, list) {
convertedList << qobject_cast<T1>(listEntry);
}
return convertedList;
}
} // namespace Utils
#endif // LISTUTILS_H
This diff is collapsed.
/**
******************************************************************************
*
* @file newclasswidget.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef NEWCLASSWIDGET_H
#define NEWCLASSWIDGET_H
#include "utils_global.h"
#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
class QStringList;
QT_END_NAMESPACE
namespace Utils {
struct NewClassWidgetPrivate;
/**
* NewClassWidget: Utility widget for 'New Class' wizards. Prompts the user
* to enter a class name (optionally derived from some base class) and file
* names for header, source and form files. Has some smart logic to derive
* the file names from the class name.
*/
class QTCREATOR_UTILS_EXPORT NewClassWidget : public QWidget
{
Q_DISABLE_COPY(NewClassWidget)
Q_OBJECT
Q_PROPERTY(bool namespacesEnabled READ namespacesEnabled WRITE setNamespacesEnabled DESIGNABLE true)
Q_PROPERTY(bool baseClassInputVisible READ isBaseClassInputVisible WRITE setBaseClassInputVisible DESIGNABLE true)
Q_PROPERTY(bool baseClassEditable READ isBaseClassEditable WRITE setBaseClassEditable DESIGNABLE false)
Q_PROPERTY(bool formInputVisible READ isFormInputVisible WRITE setFormInputVisible DESIGNABLE true)
Q_PROPERTY(bool pathInputVisible READ isPathInputVisible WRITE setPathInputVisible DESIGNABLE true)
Q_PROPERTY(bool classTypeComboVisible READ isClassTypeComboVisible WRITE setClassTypeComboVisible DESIGNABLE true)
Q_PROPERTY(QString className READ className WRITE setClassName DESIGNABLE true)
Q_PROPERTY(QString baseClassName READ baseClassName WRITE setBaseClassName DESIGNABLE true)
Q_PROPERTY(QString sourceFileName READ sourceFileName DESIGNABLE false)
Q_PROPERTY(QString headerFileName READ headerFileName DESIGNABLE false)
Q_PROPERTY(QString formFileName READ formFileName DESIGNABLE false)
Q_PROPERTY(QString path READ path WRITE setPath DESIGNABLE true)
Q_PROPERTY(QStringList baseClassChoices READ baseClassChoices WRITE setBaseClassChoices DESIGNABLE true)
Q_PROPERTY(QString sourceExtension READ sourceExtension WRITE setSourceExtension DESIGNABLE true)
Q_PROPERTY(QString headerExtension READ headerExtension WRITE setHeaderExtension DESIGNABLE true)
Q_PROPERTY(QString formExtension READ formExtension WRITE setFormExtension DESIGNABLE true)
Q_PROPERTY(bool formInputCheckable READ formInputCheckable WRITE setFormInputCheckable DESIGNABLE true)
Q_PROPERTY(bool formInputChecked READ formInputChecked WRITE setFormInputChecked DESIGNABLE true)
Q_PROPERTY(bool allowDirectories READ allowDirectories WRITE setAllowDirectories)
Q_PROPERTY(bool lowerCaseFiles READ lowerCaseFiles WRITE setLowerCaseFiles)
Q_PROPERTY(ClassType classType READ classType WRITE setClassType)
// Utility "USER" property for wizards containing file names.
Q_PROPERTY(QStringList files READ files DESIGNABLE false USER true)
Q_ENUMS(ClassType)
public:
enum ClassType { NoClassType, ClassInheritsQObject, ClassInheritsQWidget };
explicit NewClassWidget(QWidget *parent = 0);
~NewClassWidget();
bool namespacesEnabled() const;
bool isBaseClassInputVisible() const;
bool isBaseClassEditable() const;
bool isFormInputVisible() const;
bool isPathInputVisible() const;
bool formInputCheckable() const;
bool formInputChecked() const;
QString className() const;
QString baseClassName() const;
QString sourceFileName() const;
QString headerFileName() const;
QString formFileName() const;
QString path() const;
QStringList baseClassChoices() const;
QString sourceExtension() const;
QString headerExtension() const;
QString formExtension() const;
bool allowDirectories() const;
bool lowerCaseFiles() const;
ClassType classType() const;
bool isClassTypeComboVisible() const;
bool isValid(QString *error = 0) const;
QStringList files() const;
signals:
void validChanged();
void activated();
public slots:
void setNamespacesEnabled(bool b);
void setBaseClassInputVisible(bool visible);
void setBaseClassEditable(bool editable);
void setFormInputVisible(bool visible);
void setPathInputVisible(bool visible);
void setFormInputCheckable(bool v);
void setFormInputChecked(bool v);
/**
* The name passed into the new class widget will be reformatted to be a
* valid class name.
*/
void setClassName(const QString &suggestedName);
void setBaseClassName(const QString &);
void setPath(const QString &path);
void setBaseClassChoices(const QStringList &choices);
void setSourceExtension(const QString &e);
void setHeaderExtension(const QString &e);
void setFormExtension(const QString &e);
void setAllowDirectories(bool v);
void setLowerCaseFiles(bool v);
void setClassType(ClassType ct);
void setClassTypeComboVisible(bool v);
/**
* Suggest a class name from the base class by stripping the leading 'Q'
* character. This will happen automagically if the base class combo
* changes until the class line edited is manually edited.
*/
void suggestClassNameFromBase();
public slots:
/** Trigger an update (after changing settings) */
void triggerUpdateFileNames();
private slots:
void slotUpdateFileNames(const QString &t);
void slotValidChanged();
void slotActivated();
void classNameEdited();
void slotFormInputChecked();
private:
void setFormInputCheckable(bool checkable, bool force);
QString fixSuffix(const QString &suffix);
NewClassWidgetPrivate *m_d;
};
} // namespace Utils
#endif // NEWCLASSWIDGET_H
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/**
******************************************************************************
*
* @file pathutils.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef PATHUTILS_H
#define PATHUTILS_H
#include "utils_global.h"
#ifndef EXTERNAL_USE
#include "../extensionsystem/pluginmanager.h"
#endif
#include <QDir>
#include <QApplication>
#include <QSettings>
namespace Utils {
class QTCREATOR_UTILS_EXPORT PathUtils
{
public:
PathUtils();
QString GetDataPath();
QString RemoveDataPath(QString path);
QString InsertDataPath(QString path);
QString GetStoragePath();
QString RemoveStoragePath(QString path);
QString InsertStoragePath(QString path);
};
}
#endif /* PATHUTILS_H */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
<RCC>
<qresource prefix="/utils" >
<file>images/removesubmitfield.png</file>
</qresource>
</RCC>
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment