Commit cb9ac606 authored by Christian Kandeler's avatar Christian Kandeler
Browse files

TextEditor: Minimize use of ifdefs.



Change-Id: Icc924fda429032d8806caac66230c6fc55b96c53
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent 99b2eb1c
......@@ -532,20 +532,29 @@ void GenericProposalWidget::turnOnAutoWidth()
updatePositionAndSize();
}
static bool useCarbonWorkaround()
{
#if (QT_VERSION < 0x050000) && defined(Q_OS_DARWIN) && ! defined(QT_MAC_USE_COCOA)
return true;
#else
return false;
#endif
}
bool GenericProposalWidget::eventFilter(QObject *o, QEvent *e)
{
if (e->type() == QEvent::FocusOut) {
abort();
#if (QT_VERSION < 0x050000) && defined(Q_OS_DARWIN) && ! defined(QT_MAC_USE_COCOA)
QFocusEvent *fe = static_cast<QFocusEvent *>(e);
if (fe->reason() == Qt::OtherFocusReason) {
// Qt/carbon workaround
// focus out is received before the key press event.
if (d->m_completionListView->currentIndex().isValid())
emit proposalItemActivated(d->m_model->proposalItem(
d->m_completionListView->currentIndex().row()));
if (useCarbonWorkaround()) {
QFocusEvent *fe = static_cast<QFocusEvent *>(e);
if (fe->reason() == Qt::OtherFocusReason) {
// Qt/carbon workaround
// focus out is received before the key press event.
if (d->m_completionListView->currentIndex().isValid())
emit proposalItemActivated(d->m_model->proposalItem(
d->m_completionListView->currentIndex().row()));
}
}
#endif
if (d->m_infoFrame)
d->m_infoFrame->close();
return true;
......@@ -583,12 +592,12 @@ bool GenericProposalWidget::eventFilter(QObject *o, QEvent *e)
case Qt::Key_Tab:
case Qt::Key_Return:
#if (QT_VERSION >= 0x050000) || (defined(QT_MAC_USE_COCOA) || !defined(Q_OS_DARWIN))
abort();
if (d->m_completionListView->currentIndex().isValid())
emit proposalItemActivated(d->m_model->proposalItem(
d->m_completionListView->currentIndex().row()));
#endif
if (!useCarbonWorkaround()) {
abort();
if (d->m_completionListView->currentIndex().isValid())
emit proposalItemActivated(d->m_model->proposalItem(
d->m_completionListView->currentIndex().row()));
}
return true;
case Qt::Key_Up:
......
......@@ -31,6 +31,7 @@
#include "fontsettingspage.h"
#include "texteditorconstants.h"
#include <utils/hostosinfo.h>
#include <utils/qtcassert.h>
#include <coreplugin/icore.h>
......@@ -51,16 +52,6 @@ static const char schemeFileNameKey[] = "ColorScheme";
namespace {
static const bool DEFAULT_ANTIALIAS = true;
#ifdef Q_OS_MAC
enum { DEFAULT_FONT_SIZE = 12 };
static const char DEFAULT_FONT_FAMILY[] = "Monaco";
#elif defined(Q_OS_UNIX)
enum { DEFAULT_FONT_SIZE = 9 };
static const char DEFAULT_FONT_FAMILY[] = "Monospace";
#else
enum { DEFAULT_FONT_SIZE = 10 };
static const char DEFAULT_FONT_FAMILY[] = "Courier";
#endif
} // anonymous namespace
namespace TextEditor {
......@@ -68,7 +59,7 @@ namespace TextEditor {
// -- FontSettings
FontSettings::FontSettings() :
m_family(defaultFixedFontFamily()),
m_fontSize(DEFAULT_FONT_SIZE),
m_fontSize(defaultFontSize()),
m_fontZoom(100),
m_antialias(DEFAULT_ANTIALIAS)
{
......@@ -77,7 +68,7 @@ FontSettings::FontSettings() :
void FontSettings::clear()
{
m_family = defaultFixedFontFamily();
m_fontSize = DEFAULT_FONT_SIZE;
m_fontSize = defaultFontSize();
m_fontZoom = 100;
m_antialias = DEFAULT_ANTIALIAS;
m_scheme.clear();
......@@ -90,7 +81,7 @@ void FontSettings::toSettings(const QString &category,
if (m_family != defaultFixedFontFamily() || s->contains(QLatin1String(fontFamilyKey)))
s->setValue(QLatin1String(fontFamilyKey), m_family);
if (m_fontSize != DEFAULT_FONT_SIZE || s->contains(QLatin1String(fontSizeKey)))
if (m_fontSize != defaultFontSize() || s->contains(QLatin1String(fontSizeKey)))
s->setValue(QLatin1String(fontSizeKey), m_fontSize);
if (m_fontZoom!= 100 || s->contains(QLatin1String(fontZoomKey)))
......@@ -336,11 +327,20 @@ void FontSettings::setColorScheme(const ColorScheme &scheme)
m_scheme = scheme;
}
static QString defaultFontFamily()
{
if (Utils::HostOsInfo::isMacHost())
return QLatin1String("Monaco");
if (Utils::HostOsInfo::isAnyUnixHost())
return QLatin1String("Monospace");
return QLatin1String("Courier");
}
QString FontSettings::defaultFixedFontFamily()
{
static QString rc;
if (rc.isEmpty()) {
QFont f = QFont(QLatin1String(DEFAULT_FONT_FAMILY));
QFont f = QFont(defaultFontFamily());
f.setStyleHint(QFont::TypeWriter);
rc = f.family();
}
......@@ -349,7 +349,11 @@ QString FontSettings::defaultFixedFontFamily()
int FontSettings::defaultFontSize()
{
return DEFAULT_FONT_SIZE;
if (Utils::HostOsInfo::isMacHost())
return 12;
if (Utils::HostOsInfo::isAnyUnixHost())
return 9;
return 10;
}
/**
......
......@@ -30,16 +30,15 @@
#include "highlightersettings.h"
#include <coreplugin/icore.h>
#include <utils/hostosinfo.h>
#include <QSettings>
#include <QLatin1String>
#include <QLatin1Char>
#include <QDir>
#include <QFile>
#include <QStringList>
#ifdef Q_OS_UNIX
#include <QProcess>
#endif
#include <QStringList>
namespace TextEditor {
namespace Internal {
......@@ -49,45 +48,45 @@ QString findFallbackDefinitionsLocation()
QDir dir;
dir.setNameFilters(QStringList(QLatin1String("*.xml")));
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
static const QLatin1String kateSyntax[] = {
QLatin1String("/share/apps/katepart/syntax"),
QLatin1String("/share/kde4/apps/katepart/syntax")
};
static const int kateSyntaxCount =
sizeof(kateSyntax) / sizeof(kateSyntax[0]);
// Some wild guesses.
for (int i = 0; i < kateSyntaxCount; ++i) {
QStringList paths;
paths << QLatin1String("/usr") + kateSyntax[i]
<< QLatin1String("/usr/local") + kateSyntax[i]
<< QLatin1String("/opt") + kateSyntax[i];
foreach (const QString &path, paths) {
dir.setPath(path);
if (dir.exists() && !dir.entryInfoList().isEmpty())
return dir.path();
}
}
// Try kde-config.
QStringList programs;
programs << QLatin1String("kde-config") << QLatin1String("kde4-config");
foreach (const QString &program, programs) {
QProcess process;
process.start(program, QStringList(QLatin1String("--prefix")));
if (process.waitForStarted(5000)) {
process.waitForFinished(5000);
QString output = QString::fromLocal8Bit(process.readAllStandardOutput());
output.remove(QLatin1Char('\n'));
for (int i = 0; i < kateSyntaxCount; ++i) {
dir.setPath(output + kateSyntax[i]);
if (Utils::HostOsInfo::isAnyUnixHost() && !Utils::HostOsInfo::isMacHost()) {
static const QLatin1String kateSyntax[] = {
QLatin1String("/share/apps/katepart/syntax"),
QLatin1String("/share/kde4/apps/katepart/syntax")
};
static const int kateSyntaxCount =
sizeof(kateSyntax) / sizeof(kateSyntax[0]);
// Some wild guesses.
for (int i = 0; i < kateSyntaxCount; ++i) {
QStringList paths;
paths << QLatin1String("/usr") + kateSyntax[i]
<< QLatin1String("/usr/local") + kateSyntax[i]
<< QLatin1String("/opt") + kateSyntax[i];
foreach (const QString &path, paths) {
dir.setPath(path);
if (dir.exists() && !dir.entryInfoList().isEmpty())
return dir.path();
}
}
// Try kde-config.
QStringList programs;
programs << QLatin1String("kde-config") << QLatin1String("kde4-config");
foreach (const QString &program, programs) {
QProcess process;
process.start(program, QStringList(QLatin1String("--prefix")));
if (process.waitForStarted(5000)) {
process.waitForFinished(5000);
QString output = QString::fromLocal8Bit(process.readAllStandardOutput());
output.remove(QLatin1Char('\n'));
for (int i = 0; i < kateSyntaxCount; ++i) {
dir.setPath(output + kateSyntax[i]);
if (dir.exists() && !dir.entryInfoList().isEmpty())
return dir.path();
}
}
}
}
#endif
dir.setPath(Core::ICore::resourcePath() + QLatin1String("/generic-highlighter"));
if (dir.exists() && !dir.entryInfoList().isEmpty())
......
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