Commit e669f054 authored by Christian Kandeler's avatar Christian Kandeler Committed by hjk

Utils: Introduce HostOsInfo class.

The class' member functions are intended to be used
instead of the Q_OS_* macros in all contexts where
the latter are not syntactically required.
This lowers the likelihood of changes made on one
platform breaking the build on another, e.g. due to
the code model missing symbols in #ifdef'ed out code
when refactoring.

Change-Id: I4a54788591b4c8f8d589b8368a6c683d4155c9fa
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent b674b59b
......@@ -29,6 +29,9 @@
**************************************************************************/
#include "contextpanewidget.h"
#include <utils/hostosinfo.h>
#include <QToolButton>
#include <QFontComboBox>
#include <QComboBox>
......@@ -49,6 +52,8 @@
#include "customcolordialog.h"
#include "colorbutton.h"
using namespace Utils;
namespace QmlEditorWidgets {
/* XPM */
......@@ -102,12 +107,12 @@ DragWidget::DragWidget(QWidget *parent) : QFrame(parent)
// TODO: The following code should be enabled for OSX
// when QTBUG-23205 is fixed
#ifndef Q_OS_MAC
m_dropShadowEffect = new QGraphicsDropShadowEffect;
m_dropShadowEffect->setBlurRadius(6);
m_dropShadowEffect->setOffset(2, 2);
setGraphicsEffect(m_dropShadowEffect);
#endif
if (!HostOsInfo::isMacHost()) {
m_dropShadowEffect = new QGraphicsDropShadowEffect;
m_dropShadowEffect->setBlurRadius(6);
m_dropShadowEffect->setOffset(2, 2);
setGraphicsEffect(m_dropShadowEffect);
}
}
void DragWidget::mousePressEvent(QMouseEvent * event)
......@@ -127,12 +132,12 @@ void DragWidget::mouseReleaseEvent(QMouseEvent *event)
m_startPos = QPoint(-1, -1);
// TODO: The following code should be enabled for OSX
// when QTBUG-23205 is fixed
#ifndef Q_OS_MAC
m_dropShadowEffect = new QGraphicsDropShadowEffect;
m_dropShadowEffect->setBlurRadius(6);
m_dropShadowEffect->setOffset(2, 2);
setGraphicsEffect(m_dropShadowEffect);
#endif
if (!HostOsInfo::isMacHost()) {
m_dropShadowEffect = new QGraphicsDropShadowEffect;
m_dropShadowEffect->setBlurRadius(6);
m_dropShadowEffect->setOffset(2, 2);
setGraphicsEffect(m_dropShadowEffect);
}
}
QFrame::mouseReleaseEvent(event);
}
......@@ -177,16 +182,14 @@ void DragWidget::protectedMoved()
void DragWidget::leaveEvent(QEvent *)
{
#ifdef Q_OS_MAC
unsetCursor();
#endif
if (HostOsInfo::isMacHost())
unsetCursor();
}
void DragWidget::enterEvent(QEvent *)
{
#ifdef Q_OS_MAC
setCursor(Qt::ArrowCursor);
#endif
if (HostOsInfo::isMacHost())
setCursor(Qt::ArrowCursor);
}
ContextPaneWidget::ContextPaneWidget(QWidget *parent) : DragWidget(parent), m_currentWidget(0)
......@@ -232,9 +235,8 @@ ContextPaneWidget::ContextPaneWidget(QWidget *parent) : DragWidget(parent), m_cu
m_disableAction->setCheckable(true);
connect(m_disableAction.data(), SIGNAL(toggled(bool)), this, SLOT(onDisable(bool)));
m_pinned = false;
#ifdef Q_OS_MAC
setCursor(Qt::ArrowCursor);
#endif
if (HostOsInfo::isMacHost())
setCursor(Qt::ArrowCursor);
}
ContextPaneWidget::~ContextPaneWidget()
......
......@@ -29,6 +29,9 @@
**************************************************************************/
#include "contextpanewidgetimage.h"
#include <utils/hostosinfo.h>
#include "ui_contextpanewidgetimage.h"
#include "ui_contextpanewidgetborderimage.h"
#include <qmljs/qmljspropertyreader.h>
......@@ -611,12 +614,12 @@ PreviewLabel::PreviewLabel(QWidget *parent)
// TODO: The following code should be enabled for OSX
// when QTBUG-23205 is fixed
#ifndef Q_OS_MAC
QGraphicsDropShadowEffect *dropShadowEffect = new QGraphicsDropShadowEffect;
dropShadowEffect->setBlurRadius(4);
dropShadowEffect->setOffset(2, 2);
m_hooverInfo->setGraphicsEffect(dropShadowEffect);
#endif
if (!Utils::HostOsInfo::isMacHost()) {
QGraphicsDropShadowEffect *dropShadowEffect = new QGraphicsDropShadowEffect;
dropShadowEffect->setBlurRadius(4);
dropShadowEffect->setOffset(2, 2);
m_hooverInfo->setGraphicsEffect(dropShadowEffect);
}
m_hooverInfo->setAutoFillBackground(true);
m_hooverInfo->raise();
}
......
......@@ -32,6 +32,8 @@
#include "huecontrol.h"
#include "colorbox.h"
#include <utils/hostosinfo.h>
#include <QHBoxLayout>
#include <QLabel>
#include <QPainter>
......@@ -41,6 +43,8 @@
#include <QDialogButtonBox>
#include <QGraphicsEffect>
using namespace Utils;
namespace QmlEditorWidgets {
CustomColorDialog::CustomColorDialog(QWidget *parent) : QFrame(parent )
......@@ -52,12 +56,12 @@ CustomColorDialog::CustomColorDialog(QWidget *parent) : QFrame(parent )
// TODO: The following code should be enabled for OSX
// when QTBUG-23205 is fixed
#ifndef Q_OS_MAC
QGraphicsDropShadowEffect *dropShadowEffect = new QGraphicsDropShadowEffect;
dropShadowEffect->setBlurRadius(6);
dropShadowEffect->setOffset(2, 2);
setGraphicsEffect(dropShadowEffect);
#endif
if (!HostOsInfo::isMacHost()) {
QGraphicsDropShadowEffect *dropShadowEffect = new QGraphicsDropShadowEffect;
dropShadowEffect->setBlurRadius(6);
dropShadowEffect->setOffset(2, 2);
setGraphicsEffect(dropShadowEffect);
}
setAutoFillBackground(true);
m_hueControl = new HueControl(this);
......@@ -184,16 +188,14 @@ void CustomColorDialog::setupWidgets()
void CustomColorDialog::leaveEvent(QEvent *)
{
#ifdef Q_OS_MAC
unsetCursor();
#endif
if (HostOsInfo::isMacHost())
unsetCursor();
}
void CustomColorDialog::enterEvent(QEvent *)
{
#ifdef Q_OS_MAC
setCursor(Qt::ArrowCursor);
#endif
if (HostOsInfo::isMacHost())
setCursor(Qt::ArrowCursor);
}
......
......@@ -7,5 +7,6 @@ unix:QMAKE_CXXFLAGS_DEBUG += -O3
include(../../qtcreatorlibrary.pri)
include(../qmljs/qmljs.pri)
include(../utils/utils.pri)
include(qmleditorwidgets-lib.pri)
......@@ -19,6 +19,7 @@ QtcLibrary {
Depends { name: "cpp" }
Depends { name: "Qt"; submodules: ["widgets", "quick1", "script"] }
Depends { name: "QmlJS" }
Depends { name: "Utils" }
files: [
"resources.qrc",
......
......@@ -38,8 +38,9 @@
#include <QDateTime>
#include <utils/environment.h>
#include <utils/synchronousprocess.h>
#include <utils/fileutils.h>
#include <utils/hostosinfo.h>
#include <utils/synchronousprocess.h>
#include <QDesktopServices>
#include <QDebug>
......@@ -121,14 +122,13 @@ QString BuildableHelperLibrary::qtVersionForQMake(const QString &qmakePath, bool
QStringList BuildableHelperLibrary::possibleQMakeCommands()
{
// On windows no one has renamed qmake, right?
#ifdef Q_OS_WIN
return QStringList(QLatin1String("qmake.exe"));
#else
if (HostOsInfo::isWindowsHost())
return QStringList(QLatin1String("qmake.exe"));
// On unix some distributions renamed qmake to avoid clashes
QStringList result;
result << QLatin1String("qmake-qt4") << QLatin1String("qmake4") << QLatin1String("qmake");
return result;
#endif
}
// Copy helper source files to a target directory, replacing older files.
......
......@@ -33,6 +33,8 @@
#include "environment.h"
#include "qtcprocess.h"
#include <utils/hostosinfo.h>
#include <QCoreApplication>
#include <QDir>
#include <QSettings>
......@@ -134,12 +136,14 @@ bool ConsoleProcess::start(const QString &program, const QString &args)
}
}
if (Utils::HostOsInfo::isMacHost()) {
xtermArgs << (QCoreApplication::applicationDirPath()
+ QLatin1String("/../Resources/qtcreator_process_stub"));
} else {
xtermArgs << (QCoreApplication::applicationDirPath()
+ QLatin1String("/qtcreator_process_stub"));
}
xtermArgs
#ifdef Q_OS_MAC
<< (QCoreApplication::applicationDirPath() + QLatin1String("/../Resources/qtcreator_process_stub"))
#else
<< (QCoreApplication::applicationDirPath() + QLatin1String("/qtcreator_process_stub"))
#endif
<< modeOption(d->m_mode)
<< d->m_stubServer.fullServerName()
<< msgPromptToClose()
......@@ -279,11 +283,9 @@ void ConsoleProcess::stubExited()
QString ConsoleProcess::defaultTerminalEmulator()
{
#ifdef Q_OS_MAC
return QLatin1String("/usr/X11/bin/xterm");
#else
if (Utils::HostOsInfo::isMacHost())
return QLatin1String("/usr/X11/bin/xterm");
return QLatin1String("xterm");
#endif
}
QString ConsoleProcess::terminalEmulator(const QSettings *settings)
......
......@@ -30,6 +30,7 @@
#include "detailsbutton.h"
#include <utils/hostosinfo.h>
#include <utils/stylehelper.h>
#include <QPropertyAnimation>
......@@ -83,11 +84,9 @@ QSize DetailsButton::sizeHint() const
{
// TODO: Adjust this when icons become available!
const int w = fontMetrics().width(text()) + 32;
#ifdef Q_OS_MAC
return QSize(w, 34);
#else
if (HostOsInfo::isMacHost())
return QSize(w, 34);
return QSize(w, 22);
#endif
}
bool DetailsButton::event(QEvent *e)
......@@ -120,11 +119,10 @@ void DetailsButton::paintEvent(QPaintEvent *e)
QWidget::paintEvent(e);
QPainter p(this);
#ifndef Q_OS_MAC
// draw hover animation
if (!isDown() && m_fader > 0)
if (!HostOsInfo::isMacHost() && !isDown() && m_fader > 0)
p.fillRect(rect().adjusted(1, 1, -2, -2), QColor(255, 255, 255, int(m_fader*180)));
#endif
if (isChecked()) {
if (m_checkedPixmap.isNull() || m_checkedPixmap.size() != contentsRect().size())
......
......@@ -30,6 +30,7 @@
#include "detailswidget.h"
#include "detailsbutton.h"
#include "hostosinfo.h"
#include <QStack>
#include <QPropertyAnimation>
......@@ -143,10 +144,10 @@ QPixmap DetailsWidgetPrivate::cacheBackground(const QSize &size)
QRect topRect(0, 0, size.width(), topHeight);
QRect fullRect(0, 0, size.width(), size.height());
#ifdef Q_OS_MAC
p.fillRect(fullRect, qApp->palette().window().color());
#endif
p.fillRect(fullRect, QColor(255, 255, 255, 40));
if (HostOsInfo::isMacHost())
p.fillRect(fullRect, qApp->palette().window().color());
else
p.fillRect(fullRect, QColor(255, 255, 255, 40));
QLinearGradient lg(topRect.topLeft(), topRect.bottomLeft());
lg.setColorAt(0, QColor(255, 255, 255, 130));
......@@ -188,11 +189,10 @@ void DetailsWidgetPrivate::changeHoverState(bool hovered)
{
if (!m_toolWidget)
return;
#ifdef Q_OS_MAC
m_toolWidget->setOpacity(hovered ? 1.0 : 0);
#else
m_toolWidget->fadeTo(hovered ? 1.0 : 0);
#endif
if (HostOsInfo::isMacHost())
m_toolWidget->setOpacity(hovered ? 1.0 : 0);
else
m_toolWidget->fadeTo(hovered ? 1.0 : 0);
m_hovered = hovered;
}
......@@ -381,9 +381,8 @@ void DetailsWidget::setToolWidget(Utils::FadingPanel *widget)
d->m_toolWidget->adjustSize();
d->m_grid->addWidget(d->m_toolWidget, 0, 1, 1, 1, Qt::AlignRight);
#ifdef Q_OS_MAC
d->m_toolWidget->setOpacity(1.0);
#endif
if (HostOsInfo::isMacHost())
d->m_toolWidget->setOpacity(1.0);
d->changeHoverState(d->m_hovered);
}
......
This diff is collapsed.
......@@ -31,6 +31,7 @@
#include "environmentmodel.h"
#include <utils/environment.h>
#include <utils/hostosinfo.h>
#include <QFont>
......@@ -202,11 +203,8 @@ bool EnvironmentModel::setData(const QModelIndex &index, const QVariant &value,
if (index.column() == 0) {
//fail if a variable with the same name already exists
#if defined(Q_OS_WIN)
const QString &newName = value.toString().toUpper();
#else
const QString &newName = value.toString();
#endif
const QString &newName = HostOsInfo::isWindowsHost()
? value.toString().toUpper() : value.toString();
// Does the new name exist already?
if (d->m_resultEnvironment.hasKey(newName) || newName.isEmpty())
return false;
......
......@@ -31,6 +31,7 @@
#include "fileutils.h"
#include "savefile.h"
#include "hostosinfo.h"
#include "qtcassert.h"
#include <QDir>
......@@ -412,12 +413,8 @@ TempFileSaver::~TempFileSaver()
On windows filenames are compared case insensitively.
*/
#ifdef Q_OS_WIN
Qt::CaseSensitivity FileName::cs = Qt::CaseInsensitive;
#else
Qt::CaseSensitivity FileName::cs = Qt::CaseSensitive;
#endif
const Qt::CaseSensitivity FileName::cs
= HostOsInfo::isWindowsHost() ? Qt::CaseInsensitive : Qt::CaseSensitive;
FileName::FileName()
: QString()
......@@ -581,10 +578,8 @@ FileName &FileName::append(QChar str)
QT_BEGIN_NAMESPACE
uint qHash(const Utils::FileName &a)
{
#ifdef Q_OS_WIN
return qHash(a.toString().toUpper());
#else
if (Utils::HostOsInfo::isWindowsHost())
return qHash(a.toString().toUpper());
return qHash(a.toString());
#endif
}
QT_END_NAMESPACE
......@@ -175,7 +175,7 @@ public:
using QString::isNull;
using QString::clear;
private:
static Qt::CaseSensitivity cs;
static const Qt::CaseSensitivity cs;
FileName(const QString &string);
};
......
......@@ -31,6 +31,8 @@
#include "filewizarddialog.h"
#include "filewizardpage.h"
#include "hostosinfo.h"
#include <QAbstractButton>
/*!
......@@ -49,15 +51,15 @@ FileWizardDialog::FileWizardDialog(QWidget *parent) :
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
setOption(QWizard::NoCancelButton, false);
setOption(QWizard::NoDefaultButton, false);
#ifdef Q_OS_MAC
setButtonLayout(QList<QWizard::WizardButton>()
<< QWizard::CancelButton
<< QWizard::Stretch
<< QWizard::BackButton
<< QWizard::NextButton
<< QWizard::CommitButton
<< QWizard::FinishButton);
#endif
if (HostOsInfo::isMacHost()) {
setButtonLayout(QList<QWizard::WizardButton>()
<< QWizard::CancelButton
<< QWizard::Stretch
<< QWizard::BackButton
<< QWizard::NextButton
<< QWizard::CommitButton
<< QWizard::FinishButton);
}
const int filePageId = addPage(m_filePage);
wizardProgress()->item(filePageId)->setTitle(tr("Location"));
connect(m_filePage, SIGNAL(activated()), button(QWizard::FinishButton), SLOT(animateClick()));
......
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: http://www.qt-project.org/
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**************************************************************************/
#include "hostosinfo.h"
namespace Utils {
HostOsInfo::HostOs HostOsInfo::hostOs()
{
#if defined(Q_OS_WIN)
return HostOsWindows;
#elif defined(Q_OS_LINUX)
return HostOsLinux;
#elif defined(Q_OS_MAC)
return HostOsMac;
#elif defined(Q_OS_UNIX)
return HostOsOtherUnix;
#else
return HostOsOther;
#endif
}
bool HostOsInfo::isAnyUnixHost()
{
#ifdef Q_OS_UNIX
return true;
#else
return false;
#endif
}
} // namespace Utils
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: http://www.qt-project.org/
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**************************************************************************/
#ifndef HOSTOSINFO_H
#define HOSTOSINFO_H
#include "utils_global.h"
namespace Utils {
class QTCREATOR_UTILS_EXPORT HostOsInfo
{
public:
// Add more as needed.
enum HostOs { HostOsWindows, HostOsLinux, HostOsMac, HostOsOtherUnix, HostOsOther };
static HostOs hostOs();
static bool isWindowsHost() { return hostOs() == HostOsWindows; }
static bool isLinuxHost() { return hostOs() == HostOsLinux; }
static bool isMacHost() { return hostOs() == HostOsMac; }
static bool isAnyUnixHost();
};
} // namespace Utils
#endif // HOSTOSINFO_H
......@@ -30,6 +30,8 @@
#include "pathlisteditor.h"
#include "hostosinfo.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QPlainTextEdit>
......@@ -254,12 +256,7 @@ void PathListEditor::slotInsert()
QChar PathListEditor::separator()
{
#ifdef Q_OS_WIN
static const QChar rc(QLatin1Char(';'));
#else
static const QChar rc(QLatin1Char(':'));
#endif
return rc;
return HostOsInfo::isWindowsHost() ? QLatin1Char(';') : QLatin1Char(':');
}
// Add a button "Import from 'Path'"
......
......@@ -30,6 +30,8 @@
#include "stringutils.h"
#include "hostosinfo.h"
#include <QString>
#include <QStringList>
#include <QFileInfo>
......@@ -95,19 +97,17 @@ QTCREATOR_UTILS_EXPORT QString commonPath(const QStringList &files)
lastSeparatorPos = common.lastIndexOf(QLatin1Char('\\'));
if (lastSeparatorPos == -1)
return QString();
#ifdef Q_OS_UNIX
if (lastSeparatorPos == 0) // Unix: "/a", "/b" -> '/'
if (HostOsInfo::isAnyUnixHost() && lastSeparatorPos == 0) // Unix: "/a", "/b" -> '/'